simplified and improved vol_perc()
This commit is contained in:
parent
c288663ebd
commit
d144c8de3d
1 changed files with 12 additions and 6 deletions
18
slstatus.c
18
slstatus.c
|
@ -667,17 +667,23 @@ vol_perc(const char *card)
|
||||||
int v, afd, devmask;
|
int v, afd, devmask;
|
||||||
char *vnames[] = SOUND_DEVICE_NAMES;
|
char *vnames[] = SOUND_DEVICE_NAMES;
|
||||||
|
|
||||||
afd = open(card, O_RDONLY);
|
afd = open(card, O_RDONLY | O_NONBLOCK);
|
||||||
if (afd < 0) {
|
if (afd == -1) {
|
||||||
warn("Cannot open %s", card);
|
warn("Cannot open %s", card);
|
||||||
return smprintf(UNKNOWN_STR);
|
return smprintf(UNKNOWN_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
ioctl(afd, MIXER_READ(SOUND_MIXER_DEVMASK), &devmask);
|
if (ioctl(afd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) {
|
||||||
|
warn("Cannot get volume for %s", card);
|
||||||
|
close(afd);
|
||||||
|
return smprintf("%s", UNKNOWN_STR);
|
||||||
|
}
|
||||||
for (i = 0; i < (sizeof(vnames) / sizeof((vnames[0]))); i++) {
|
for (i = 0; i < (sizeof(vnames) / sizeof((vnames[0]))); i++) {
|
||||||
if (devmask & (1 << i)) {
|
if (devmask & (1 << i) && !strcmp("vol", vnames[i])) {
|
||||||
if (!strcmp("vol", vnames[i])) {
|
if (ioctl(afd, MIXER_READ(i), &v) == -1) {
|
||||||
ioctl(afd, MIXER_READ(i), &v);
|
warn("vol_perc: ioctl");
|
||||||
|
close(afd);
|
||||||
|
return smprintf("%s", UNKNOWN_STR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue