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.

1234567891011121314151617181920212223242526272829303132
  1. /* See LICENSE file for copyright and license details. */
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <sys/ioctl.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8. #include <machine/apmvar.h>
  9. #include "../../util.h"
  10. const char *
  11. battery_perc(const char *null)
  12. {
  13. struct apm_power_info apm_info;
  14. int fd;
  15. fd = open("/dev/apm", O_RDONLY);
  16. if (fd < 0) {
  17. fprintf(stderr, "open '/dev/apm': %s\n", strerror(errno));
  18. return NULL;
  19. }
  20. if (ioctl(fd, APM_IOC_GETPOWER, &apm_info) < 0) {
  21. fprintf(stderr, "ioctl 'APM_IOC_GETPOWER': %s\n", strerror(errno));
  22. close(fd);
  23. return NULL;
  24. }
  25. close(fd);
  26. return bprintf("%d", apm_info.battery_life);
  27. }