From c413233d3431041a4a3021837113702408991a83 Mon Sep 17 00:00:00 2001 From: Nikita Langer Date: Mon, 6 Apr 2026 22:11:14 +0200 Subject: initial commit --- patches/slstatus-backlight-4bd78c9.diff | 104 ++++++++++++++++++++++++++ patches/slstatus-icons-1.0.patch | 126 ++++++++++++++++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 patches/slstatus-backlight-4bd78c9.diff create mode 100644 patches/slstatus-icons-1.0.patch (limited to 'patches') diff --git a/patches/slstatus-backlight-4bd78c9.diff b/patches/slstatus-backlight-4bd78c9.diff new file mode 100644 index 0000000..8d55e3d --- /dev/null +++ b/patches/slstatus-backlight-4bd78c9.diff @@ -0,0 +1,104 @@ +diff --git a/Makefile b/Makefile +index 3be46cc..93dc2c5 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 0000000..74f4c08 +--- /dev/null ++++ b/components/backlight.c +@@ -0,0 +1,59 @@ ++/* 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); ++ } ++#elif defined(__OpenBSD__) ++ #include ++ #include ++ #include ++ #include ++ ++ const char * ++ backlight_perc(const char *unused) ++ { ++ int fd, err; ++ struct wsdisplay_param wsd_param = { ++ .param = WSDISPLAYIO_PARAM_BRIGHTNESS ++ }; ++ ++ if ((fd = open("/dev/ttyC0", O_RDONLY)) < 0) { ++ warn("could not open /dev/ttyC0"); ++ return NULL; ++ } ++ if ((err = ioctl(fd, WSDISPLAYIO_GETPARAM, &wsd_param)) < 0) { ++ warn("ioctl 'WSDISPLAYIO_GETPARAM' failed"); ++ return NULL; ++ } ++ return bprintf("%d", wsd_param.curval * 100 / wsd_param.max); ++ } ++#endif +diff --git a/config.def.h b/config.def.h +index 5f6c114..69c5d50 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -12,6 +12,9 @@ static const char unknown_str[] = "n/a"; + /* + * function description argument (example) + * ++ * backlight_perc backlight percentage device name ++ * (intel_backlight) ++ * NULL on OpenBSD + * battery_perc battery percentage battery name (BAT0) + * NULL on OpenBSD/FreeBSD + * battery_state battery charging state battery name (BAT0) +diff --git a/slstatus.h b/slstatus.h +index f3b4979..e1759a0 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 *); diff --git a/patches/slstatus-icons-1.0.patch b/patches/slstatus-icons-1.0.patch new file mode 100644 index 0000000..bdbcc39 --- /dev/null +++ b/patches/slstatus-icons-1.0.patch @@ -0,0 +1,126 @@ +From 9c5d98385f0400f2d423334fd40e321b6ac79528 Mon Sep 17 00:00:00 2001 +From: sewn +Date: Sat, 8 Feb 2025 16:46:25 +0300 +Subject: [PATCH] implement icons for volume and battery + +--- + components/battery.c | 19 +++++++++++++++++++ + components/volume.c | 17 +++++++++++++++++ + config.def.h | 4 ++++ + slstatus.h | 2 ++ + 4 files changed, 42 insertions(+) + +diff --git a/components/battery.c b/components/battery.c +index 1c753f9..7bfd874 100644 +--- a/components/battery.c ++++ b/components/battery.c +@@ -1,10 +1,29 @@ + /* See LICENSE file for copyright and license details. */ + #include ++#include + #include + + #include "../slstatus.h" + #include "../util.h" + ++const char * ++battery_icon(const char *bat) ++{ ++ unsigned long ul_perc; ++ const char *perc, *state; ++ static const char *icons[][11] = { ++ { "󰂎", "󰁺", "󰁻", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󰁹" }, ++ { "󰢟", "󰢜", "󰂆", "󰂇", "󰂈", "󰢝", "󰂉", "󰢞", "󰂊", "󰂋", "󰂅" }, ++ }; ++ ++ if (!(perc = battery_perc(bat)) || !(state = battery_state(bat))) ++ return NULL; ++ ++ ul_perc = strtoul(perc, NULL, 10); ++ ++ return bprintf("%s %d", icons[state[0] == '+'][ul_perc / 10], ul_perc); ++} ++ + #if defined(__linux__) + /* + * https://www.kernel.org/doc/html/latest/power/power_supply_class.html +diff --git a/components/volume.c b/components/volume.c +index 6cec556..5c597b4 100644 +--- a/components/volume.c ++++ b/components/volume.c +@@ -1,6 +1,7 @@ + /* See LICENSE file for copyright and license details. */ + #include + #include ++#include + #include + #include + #include +@@ -8,6 +9,22 @@ + #include "../slstatus.h" + #include "../util.h" + ++const char * ++vol_icon(const char *arg) ++{ ++ char *p; ++ const char *perc; ++ static const char *icons[] = { "󰕿", "󰖀", "󰕾" }; ++ unsigned long ul_perc; ++ ++ if (!(perc = vol_perc(arg))) ++ return NULL; ++ p = strrchr(perc, ' '); ++ ul_perc = strtoul(p ? p + 1 : perc, NULL, 10); ++ ++ return bprintf("%s %d", p ? "󰝟" : icons[ul_perc / 34], ul_perc); ++} ++ + #if defined(__OpenBSD__) | defined(__FreeBSD__) + #include + #include +diff --git a/config.def.h b/config.def.h +index d805331..98dc3a0 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -12,6 +12,8 @@ static const char unknown_str[] = "n/a"; + /* + * function description argument (example) + * ++ * battery_icon battery_perc with an icon battery name (BAT0) ++ * NULL on OpenBSD/FreeBSD + * battery_perc battery percentage battery name (BAT0) + * NULL on OpenBSD/FreeBSD + * battery_remaining battery remaining HH:MM battery name (BAT0) +@@ -58,6 +60,8 @@ static const char unknown_str[] = "n/a"; + * uid UID of current user NULL + * uptime system uptime NULL + * username username of current user NULL ++ * vol_icon vol_perc with an icon mixer file (/dev/mixer) ++ * NULL on OpenBSD/FreeBSD + * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) + * NULL on OpenBSD/FreeBSD + * wifi_essid WiFi ESSID interface name (wlan0) +diff --git a/slstatus.h b/slstatus.h +index 8ef5874..b60c573 100644 +--- a/slstatus.h ++++ b/slstatus.h +@@ -4,6 +4,7 @@ + const char *battery_perc(const char *); + const char *battery_remaining(const char *); + const char *battery_state(const char *); ++const char *battery_icon(const char *); + + /* cat */ + const char *cat(const char *path); +@@ -77,6 +78,7 @@ const char *uid(const char *unused); + const char *username(const char *unused); + + /* volume */ ++const char *vol_icon(const char *card); + const char *vol_perc(const char *card); + + /* wifi */ +-- +2.48.1 + -- cgit