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.
 
 
 
 

33 line
679 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include "../util.h"
  3. #if defined(__linux__)
  4. #include <limits.h>
  5. #define BRIGHTNESS_MAX "/sys/class/backlight/%s/max_brightness"
  6. #define BRIGHTNESS_CUR "/sys/class/backlight/%s/brightness"
  7. const char *
  8. backlight_perc(const char *card)
  9. {
  10. char path[PATH_MAX];
  11. int max, cur;
  12. if (esnprintf(path, sizeof (path), BRIGHTNESS_MAX, card) < 0 ||
  13. pscanf(path, "%d", &max) != 1) {
  14. return NULL;
  15. }
  16. if (esnprintf(path, sizeof (path), BRIGHTNESS_CUR, card) < 0 ||
  17. pscanf(path, "%d", &cur) != 1) {
  18. return NULL;
  19. }
  20. if (max == 0) {
  21. return NULL;
  22. }
  23. return bprintf("%d", cur * 100 / max);
  24. }
  25. #endif