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.
 
 
 
 

44 rader
856 B

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