My slstatus configuration
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

volume.c 795 B

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