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.
 
 
 
 

49 lines
1.0 KiB

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