My slstatus configuration
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

56 lignes
1.1 KiB

  1. #include <limits.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "util.h"
  5. const char *
  6. battery_perc(const char *bat)
  7. {
  8. int perc;
  9. char path[PATH_MAX];
  10. snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", bat, "/capacity");
  11. return (pscanf(path, "%i", &perc) == 1) ?
  12. bprintf("%d", perc) : NULL;
  13. }
  14. const char *
  15. battery_power(const char *bat)
  16. {
  17. int watts;
  18. char path[PATH_MAX];
  19. snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", bat, "/power_now");
  20. return (pscanf(path, "%i", &watts) == 1) ?
  21. bprintf("%d", (watts + 500000) / 1000000) : NULL;
  22. }
  23. const char *
  24. battery_state(const char *bat)
  25. {
  26. struct {
  27. char *state;
  28. char *symbol;
  29. } map[] = {
  30. { "Charging", "+" },
  31. { "Discharging", "-" },
  32. { "Full", "=" },
  33. { "Unknown", "/" },
  34. };
  35. size_t i;
  36. char path[PATH_MAX], state[12];
  37. snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", bat, "/status");
  38. if (pscanf(path, "%12s", state) != 1) {
  39. return NULL;
  40. }
  41. for (i = 0; i < LEN(map); i++) {
  42. if (!strcmp(map[i].state, state)) {
  43. break;
  44. }
  45. }
  46. return (i == LEN(map)) ? "?" : map[i].symbol;
  47. }