My slstatus configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
902 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #if defined(__OpenBSD__)
  6. #include <soundcard.h>
  7. #else
  8. #include <sys/soundcard.h>
  9. #endif
  10. #include <sys/ioctl.h>
  11. #include <unistd.h>
  12. #include "../util.h"
  13. const char *
  14. vol_perc(const char *card)
  15. {
  16. size_t i;
  17. int v, afd, devmask;
  18. char *vnames[] = SOUND_DEVICE_NAMES;
  19. if ((afd = open(card, O_RDONLY | O_NONBLOCK)) < 0) {
  20. warn("open '%s':", card);
  21. return NULL;
  22. }
  23. if (ioctl(afd, (int)SOUND_MIXER_READ_DEVMASK, &devmask) < 0) {
  24. warn("ioctl 'SOUND_MIXER_READ_DEVMASK':");
  25. close(afd);
  26. return NULL;
  27. }
  28. for (i = 0; i < LEN(vnames); i++) {
  29. if (devmask & (1 << i) && !strcmp("vol", vnames[i])) {
  30. if (ioctl(afd, MIXER_READ(i), &v) < 0) {
  31. warn("ioctl 'MIXER_READ(%ld)':", i);
  32. close(afd);
  33. return NULL;
  34. }
  35. }
  36. }
  37. close(afd);
  38. return bprintf("%d", v & 0xff);
  39. }