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
997 B

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