Re: [hackers] [PATCH slstatus V2] Add basic backlight percentage support
David, Do you mean in bprintf call, so like this: bprintf("%d", ...) ? Yes, thanks. The problem is that util.h actually requires stddef.h (it uses size_t which is is defined there). I think that include should eventually be moved there. Okay then move it to util.h in your patch, forgot that. So even if I add support for FreeBSD you'll refuse it? I know the code, I've already implemented I just need to get a FreeBSD laptop to ensure it still works though :) For now, yes. But please keep your awesome work saved so that we can add it when we port slstatus eventually to FreeBSD! For now, Linux and OpenBSD should be fully ported. Cheers! Aaron -- Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/ Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion GPG: 0x7A65E38D55BE96FE Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE
Re: [hackers] [PATCH slstatus V2] Add basic backlight percentage support
On Mon, May 21, 2018 at 01:09:08PM +0200, Aaron Marcher wrote: > David, > > Thank you very much for your great work! > works great so far but I have just a few things for you to change. > > - Remove the "%" sign from the return Do you mean in bprintf call, so like this: bprintf("%d", ...) ? > - Move in the Linux block as there is no other block to share > code with The problem is that util.h actually requires stddef.h (it uses size_t which is is defined there). I think that include should eventually be moved there. > - Add backlight_perc to config.def.h documentation (with acpi_video0 as > example) > - Add backlight_perc to README > > Also: for now we will add only OpenBSD support as FreeBSD is no port goal > for version 1. So even if I add support for FreeBSD you'll refuse it? I know the code, I've already implemented I just need to get a FreeBSD laptop to ensure it still works though :) Regards, -- David
Re: [hackers] [PATCH slstatus V2] Add basic backlight percentage support
David, Thank you very much for your great work! works great so far but I have just a few things for you to change. - Remove the "%" sign from the return - Fix the indention and spacing between the #ifdefs (see other components) - Move in the Linux block as there is no other block to share code with - Add backlight_perc to config.def.h documentation (with acpi_video0 as example) - Add backlight_perc to README Also: for now we will add only OpenBSD support as FreeBSD is no port goal for version 1. Regards, Aaron -- Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/ Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion GPG: 0x7A65E38D55BE96FE Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE
[hackers] [PATCH slstatus V2] Add basic backlight percentage support
At the moment linux only, but will add support for FreeBSD and OpenBSD as well. --- Makefile | 1 + components/backlight.c | 37 + slstatus.h | 3 +++ 3 files changed, 41 insertions(+) create mode 100644 components/backlight.c diff --git a/Makefile b/Makefile index 0e925cc..8e18969 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ include config.mk REQ = util COM =\ + components/backlight\ components/battery\ components/cpu\ components/datetime\ diff --git a/components/backlight.c b/components/backlight.c new file mode 100644 index 000..9c11fe1 --- /dev/null +++ b/components/backlight.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ + +#include + +#include "../util.h" + +#if defined(__linux__) + +#include + +#define BRIGHTNESS_MAX "/sys/class/backlight/%s/max_brightness" +#define BRIGHTNESS_CUR "/sys/class/backlight/%s/brightness" + +const char * +backlight_perc(const char *card) +{ + char path[PATH_MAX]; + int max, cur; + + if (esnprintf(path, sizeof (path), BRIGHTNESS_MAX, card) < 0 || + pscanf(path, "%d", &max) != 1) { + return NULL; + } + + if (esnprintf(path, sizeof (path), BRIGHTNESS_CUR, card) < 0 || + pscanf(path, "%d", &cur) != 1) { + return NULL; + } + + if (max == 0) { + return NULL; + } + + return bprintf("%d%%", cur * 100 / max); +} + +#endif diff --git a/slstatus.h b/slstatus.h index 8bd8bb5..a18b881 100644 --- a/slstatus.h +++ b/slstatus.h @@ -1,5 +1,8 @@ /* See LICENSE file for copyright and license details. */ +/* backlight */ +const char *backlight_perc(const char *); + /* battery */ const char *battery_perc(const char *); const char *battery_state(const char *); -- 2.17.0