From a942bc1bc4dde8ea558004e234e96d89d1ddc1f5 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 9 Nov 2014 19:28:41 +0100 Subject: [PATCH] Ursary: Better client matching logic --- ursaryd/ursaryd.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/ursaryd/ursaryd.c b/ursaryd/ursaryd.c index a127744..bb057e1 100644 --- a/ursaryd/ursaryd.c +++ b/ursaryd/ursaryd.c @@ -99,6 +99,7 @@ struct pulse_sink_input { uns channels; uns volume; uns mute; + int noct_client_idx; // Used by the high-level logic below }; #define HASH_NODE struct pulse_sink_input @@ -447,34 +448,33 @@ static int find_client_by_rotary(int rotary) return -1; } -static bool client_match_sink_input(struct client_map *cm, struct pulse_sink_input *s) -{ - if (s->client_idx < 0 || s->sink_idx < 0) - return 0; - - struct pulse_client *c = pulse_client_lookup(s->client_idx); - if (!c) - return 0; - - return ((!cm->client || !strcmp(cm->client, c->name)) && - (!cm->host || !strcmp(cm->host, c->host))); -} - static void calc_clients(void) { bzero(client_state, sizeof(client_state)); HASH_FOR_ALL(pulse_sink_input, s) { + s->noct_client_idx = -1; + + if (s->client_idx < 0 || s->sink_idx < 0) + continue; + + struct pulse_client *c = pulse_client_lookup(s->client_idx); + if (!c) + continue; + for (uns i=0; i < NUM_CLIENTS; i++) { struct client_map *cm = &client_map[i]; struct client_state *cs = &client_state[i]; - if (client_match_sink_input(cm, s)) + if ((!cm->client || !strcmp(cm->client, c->name)) && + (!cm->host || !strcmp(cm->host, c->host))) { - DBG("@@ Client #%d, sink input #%d -> rotary %d", s->client_idx, s->idx, cm->rotary); + // DBG("@@ Client #%d, sink input #%d -> rotary %d", s->client_idx, s->idx, cm->rotary); + s->noct_client_idx = i; cs->volume = MAX(cs->volume, s->volume); cs->have_muted[!!s->mute] = 1; + break; } } } @@ -592,7 +592,7 @@ static void update_client_from_rotary(int rotary, int delta) HASH_FOR_ALL(pulse_sink_input, s) { - if (client_match_sink_input(cm, s) && s->volume != pavol) + if (s->noct_client_idx == i && s->volume != pavol) { DBG("@@ Client #%d, sink input #%d: setting volume=%u", s->client_idx, s->idx, pavol); pa_cvolume cvol; @@ -649,7 +649,6 @@ static void update_client_from_button(int button, int on) int i = find_client_by_rotary(button); if (i < 0) return; - struct client_map *cm = &client_map[i]; struct client_state *cs = &client_state[i]; calc_clients(); @@ -659,7 +658,7 @@ static void update_client_from_button(int button, int on) HASH_FOR_ALL(pulse_sink_input, s) { - if (client_match_sink_input(cm, s)) + if (s->noct_client_idx == i) { DBG("@@ Client #%d, sink input #%d: setting mute=%u", s->client_idx, s->idx, mute); PULSE_ASYNC_RUN(pa_context_set_sink_input_mute, pulse_ctx, s->idx, mute, pulse_success_cb); -- 2.39.5