commit 099ce388993818f600c4e41172f71e20520dce7e
parent 3511d7c46c84999c22eaff887698a6a207231e0d
Author: Peter Valach <pvx@gmx.net>
Date: Tue, 10 Feb 2026 17:45:51 +0100
[slstatus][patches][limit] use different format for values above set limit
Adds a numeric limit and alternate format string to the configuration.
When the returned numeric value exceeds this limit, the alternate format
is used instead of the default one. Useful for visual alerts such as
high CPU/memory usage or low battery, e.g. by changing colors in status
bars that support it (such as dwm with color patches).
Diffstat:
2 files changed, 91 insertions(+), 0 deletions(-)
diff --git a/tools.suckless.org/slstatus/patches/limit/index.md b/tools.suckless.org/slstatus/patches/limit/index.md
@@ -0,0 +1,21 @@
+limit
+=====
+
+Description
+-----------
+This diff makes it possible to highlight values in status bar in a simple
+and fully customizable way.
+
+Adds a numeric limit and alternate format string to the configuration.
+When the returned numeric value exceeds the limit, the alternate format
+is used instead of the default one. Useful for visual alerts such as high
+CPU/memory usage or low battery, e.g. by changing colors in status bars
+that support it (such as dwm with color patches).
+
+Download
+--------
+* [slstatus-limit-20260203-49d8b5a.diff](slstatus-limit-20260203-49d8b5a.diff)
+
+Authors
+-------
+* Peter Valach <pvx@gmx.net>
diff --git a/tools.suckless.org/slstatus/patches/limit/slstatus-limit-20260203-49d8b5a.diff b/tools.suckless.org/slstatus/patches/limit/slstatus-limit-20260203-49d8b5a.diff
@@ -0,0 +1,70 @@
+From 49d8b5ad876401a92efbd604d15abe1f54f79790 Mon Sep 17 00:00:00 2001
+From: Peter Valach <pvx@gmx.net>
+Date: Tue, 3 Feb 2026 19:35:03 +0100
+Subject: [slstatus-limit][PATCH] add second format for values above given limit
+
+---
+ config.def.h | 8 ++++++--
+ slstatus.c | 14 +++++++++++++-
+ 2 files changed, 19 insertions(+), 3 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 100093e..655d713 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -65,6 +65,10 @@ static const char unknown_str[] = "n/a";
+ * wifi_perc WiFi signal in percent interface name (wlan0)
+ */
+ static const struct arg args[] = {
+- /* function format argument */
+- { datetime, "%s", "%F %T" },
++ /* function format argument limit limit_format */
++ { datetime, "%s", "%F %T", 0, NULL },
++
++ /* example of different format above limit (both format strings can contain anything your status supports, including icons and colors)
++ { ram_perc, "RAM: %s%%", "", 90, "RAM OVER LIMIT: %s%%" },
++ */
+ };
+diff --git a/slstatus.c b/slstatus.c
+index 16d88fe..7e6f670 100644
+--- a/slstatus.c
++++ b/slstatus.c
+@@ -15,6 +15,8 @@ struct arg {
+ const char *(*func)(const char *);
+ const char *fmt;
+ const char *args;
++ long limit;
++ const char *limit_fmt;
+ };
+
+ char buf[1024];
+@@ -49,6 +51,8 @@ main(int argc, char *argv[])
+ {
+ struct sigaction act;
+ struct timespec start, current, diff, intspec, wait;
++ long val;
++ const char *fmt;
+ size_t i, len;
+ int sflag, ret;
+ char status[MAXLEN];
+@@ -91,8 +95,16 @@ main(int argc, char *argv[])
+ if (!(res = args[i].func(args[i].args)))
+ res = unknown_str;
+
++ if (args[i].limit &&
++ (val = strtol(res, NULL, 10)) > args[i].limit &&
++ args[i].limit_fmt) {
++ fmt = args[i].limit_fmt;
++ } else {
++ fmt = args[i].fmt;
++ }
++
+ if ((ret = esnprintf(status + len, sizeof(status) - len,
+- args[i].fmt, res)) < 0)
++ fmt, res)) < 0)
+ break;
+
+ len += ret;
+--
+2.43.0
+