Update xvolkeys to use output.level.

This commit is contained in:
Alexandre Ratchov 2020-01-13 14:53:34 +01:00
parent 74ae9cda72
commit 88eee3e423
1 changed files with 22 additions and 21 deletions

View File

@ -44,8 +44,8 @@
char *dev_name; char *dev_name;
struct pollfd pfds[16]; struct pollfd pfds[16];
struct sioctl_hdl *hdl; struct sioctl_hdl *hdl;
unsigned int master_addr, master_val = SIOCTL_INTMAX; unsigned int output_addr, output_val = SIOCTL_INTMAX;
int master_found = 0; int output_found = 0;
int verbose; int verbose;
/* /*
@ -63,16 +63,17 @@ dev_ondesc(void *unused, struct sioctl_desc *desc, int val)
{ {
if (desc == NULL) if (desc == NULL)
return; return;
if (master_found) if (output_found)
return; return;
if (strcmp(desc->chan0.str, "master") == 0 && if (desc->group[0] == 0 &&
strcmp(desc->chan0.str, "output") == 0 &&
strcmp(desc->func, "level") == 0) { strcmp(desc->func, "level") == 0) {
master_found = 1; output_found = 1;
master_addr = desc->addr; output_addr = desc->addr;
master_val = val; output_val = val;
if (verbose) if (verbose)
fprintf(stderr, "%s: master at addr %u, value = %u\n", fprintf(stderr, "%s: output at addr %u, value = %u\n",
dev_name, master_addr, master_val); dev_name, output_addr, output_val);
} }
} }
@ -82,10 +83,10 @@ dev_ondesc(void *unused, struct sioctl_desc *desc, int val)
static void static void
dev_onval(void *unused, unsigned int addr, unsigned int val) dev_onval(void *unused, unsigned int addr, unsigned int val)
{ {
if (addr == master_addr) { if (addr == output_addr) {
if (verbose) if (verbose)
fprintf(stderr, "master changed %u -> %u\n", master_val, val); fprintf(stderr, "output changed %u -> %u\n", output_val, val);
master_val = val; output_val = val;
} }
} }
@ -118,17 +119,17 @@ dev_connect(void)
dev_name); dev_name);
return 0; return 0;
} }
master_found = 0; output_found = 0;
sioctl_ondesc(hdl, dev_ondesc, NULL); sioctl_ondesc(hdl, dev_ondesc, NULL);
sioctl_onval(hdl, dev_onval, NULL); sioctl_onval(hdl, dev_onval, NULL);
if (!master_found) if (!output_found)
fprintf(stderr, "%s: warning, couldn't find master control\n", fprintf(stderr, "%s: warning, couldn't find output control\n",
dev_name); dev_name);
return 1; return 1;
} }
/* /*
* send master volume message and to the server * send output volume message and to the server
*/ */
static void static void
dev_incrvol(int incr) dev_incrvol(int incr)
@ -137,19 +138,19 @@ dev_incrvol(int incr)
if (!dev_connect()) if (!dev_connect())
return; return;
vol = master_val + incr; vol = output_val + incr;
if (vol > SIOCTL_INTMAX) if (vol > SIOCTL_INTMAX)
vol = SIOCTL_INTMAX; vol = SIOCTL_INTMAX;
if (vol < 0) if (vol < 0)
vol = 0; vol = 0;
if (master_val != (unsigned int)vol) { if (output_val != (unsigned int)vol) {
master_val = vol; output_val = vol;
if (hdl && master_found) { if (hdl && output_found) {
if (verbose) { if (verbose) {
fprintf(stderr, "%s: setting volume to %d\n", fprintf(stderr, "%s: setting volume to %d\n",
dev_name, vol); dev_name, vol);
} }
sioctl_setval(hdl, master_addr, master_val); sioctl_setval(hdl, output_addr, output_val);
dev_disconnect(); dev_disconnect();
} }
} }