From 3c47701aea6bdb1e27c9b2039c07321077764f45 Mon Sep 17 00:00:00 2001 From: NRK Date: Sat, 27 Aug 2022 20:40:20 +0600 Subject: [PATCH 01/43] Fix keyboard_indicators() prototype according to both the function definition and the comment in config.def.h, keyboard_indicators() should take a format string. --- slstatus.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slstatus.h b/slstatus.h index b0f2564..362ca7c 100644 --- a/slstatus.h +++ b/slstatus.h @@ -32,7 +32,7 @@ const char *ipv6(const char *interface); const char *kernel_release(void); /* keyboard_indicators */ -const char *keyboard_indicators(void); +const char *keyboard_indicators(const char *fmt); /* keymap */ const char *keymap(void); From 77bfb76a971ed8d114fc12db70d8bfeef923510e Mon Sep 17 00:00:00 2001 From: "michaelbuch12@gmail.com" Date: Fri, 1 Jan 2021 17:04:36 +0100 Subject: [PATCH 02/43] Fix RAM component on FreeBSD The current implementation uses the wrong type for given sysctl calls leading to overflow and incorrectly reported RAM usage. The fix is to use 'unsigned int' which is what FreeBSD expects. --- components/ram.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/ram.c b/components/ram.c index 47e6fda..6040e56 100644 --- a/components/ram.c +++ b/components/ram.c @@ -178,7 +178,7 @@ const char * ram_total(void) { - long npages; + unsigned int npages; size_t len; len = sizeof(npages); @@ -191,8 +191,8 @@ const char * ram_perc(void) { - long npages; - long active; + unsigned int npages; + unsigned int active; size_t len; len = sizeof(npages); @@ -209,7 +209,7 @@ const char * ram_used(void) { - long active; + unsigned int active; size_t len; len = sizeof(active); From 798809ce02528d5954e0b1d524f44c29503a7407 Mon Sep 17 00:00:00 2001 From: "michaelbuch12@gmail.com" Date: Fri, 1 Jan 2021 16:52:57 +0100 Subject: [PATCH 03/43] Make volume component work on FreeBSD - Edit compile instructions - Reuse OpenBSD sndio implementation --- components/volume.c | 2 +- config.def.h | 2 +- config.mk | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/volume.c b/components/volume.c index b6665da..32f7817 100644 --- a/components/volume.c +++ b/components/volume.c @@ -7,7 +7,7 @@ #include "../util.h" -#if defined(__OpenBSD__) +#if defined(__OpenBSD__) | defined(__FreeBSD__) #include #include #include diff --git a/config.def.h b/config.def.h index 93a875a..f76b60c 100644 --- a/config.def.h +++ b/config.def.h @@ -59,7 +59,7 @@ static const char unknown_str[] = "n/a"; * uptime system uptime NULL * username username of current user NULL * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) - * NULL on OpenBSD + * NULL on OpenBSD/FreeBSD * wifi_perc WiFi signal in percent interface name (wlan0) * wifi_essid WiFi ESSID interface name (wlan0) */ diff --git a/config.mk b/config.mk index 2516e6e..6cce683 100644 --- a/config.mk +++ b/config.mk @@ -15,7 +15,7 @@ CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os LDFLAGS = -L$(X11LIB) -s # OpenBSD: add -lsndio -# FreeBSD: add -lkvm +# FreeBSD: add -lkvm -lsndio LDLIBS = -lX11 # compiler and linker From 3b699c127db745b32002c14d59a6de4ebcc0b7db Mon Sep 17 00:00:00 2001 From: Ingo Feinerer Date: Mon, 15 Feb 2021 12:56:42 +0100 Subject: [PATCH 04/43] Reset sndiod initialization flag on disconnects If the connection is lost to the sndiod(8) daemon reset the initialization to allow for a graceful restart. --- components/volume.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/volume.c b/components/volume.c index 32f7817..c94f872 100644 --- a/components/volume.c +++ b/components/volume.c @@ -161,6 +161,7 @@ if (sioctl_revents(hdl, pfds) & POLLHUP) { warn("sndio: disconnected"); cleanup(); + initialized = 0; return NULL; } } From 1881569f6ce822f5baec4c7ceb9a8695f7e6a3ef Mon Sep 17 00:00:00 2001 From: drkhsh Date: Thu, 20 Oct 2022 01:24:08 +0200 Subject: [PATCH 05/43] Update LICENSE --- LICENSE | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index b88a9cb..70b9fb3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ ISC License -Copyright 2016-2020 Aaron Marcher +Copyright 2016-2022 Aaron Marcher Copyright 2016 Roy Freytag Copyright 2016 Vincent Loupmon @@ -16,16 +16,17 @@ Copyright 2018 Darron Anderson Copyright 2018 Josuah Demangeon Copyright 2018 Tobias Tschinkowitz Copyright 2018 David Demelier -Copyright 2018-2019 Michael Buch +Copyright 2018-2012 Michael Buch Copyright 2018 Ian Remmler Copyright 2016-2019 Joerg Jung Copyright 2019 Ryan Kes Copyright 2019 Cem Keylan Copyright 2019 dsp -Copyright 2019-2020 Ingo Feinerer +Copyright 2019-2022 Ingo Feinerer Copyright 2020 Alexandre Ratchov Copyright 2020 Mart Lubbers Copyright 2020 Daniel Moch +Copyright 2022 NRK Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above From 0aacce1c527749ccb85bd661a596af52dfb562cc Mon Sep 17 00:00:00 2001 From: drkhsh Date: Wed, 26 Oct 2022 12:57:12 +0200 Subject: [PATCH 06/43] Add comment about mixer oss module to README --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index 86fe988..cebad30 100644 --- a/README +++ b/README @@ -35,6 +35,9 @@ Requirements Currently slstatus works on FreeBSD, Linux and OpenBSD. In order to build slstatus you need the Xlib header files. +For volume percentage on Linux the kernel module `snd-mixer-oss` must be +loaded. + Installation ------------ From f29aa9ab0656c938ad0c0d4a6136ff25bd82ebf9 Mon Sep 17 00:00:00 2001 From: Spenser Truex Date: Wed, 26 Oct 2022 21:34:47 +0200 Subject: [PATCH 07/43] Add 'Not charging' status support Exists on various ThinkPads. Seems to be both a synonym for "full". Tested on: - ThinkPad T500 (Spenser Truex Date: Thu, 27 Oct 2022 02:14:53 +0600 Subject: [PATCH 08/43] components/*.c: include slstatus.h this gives the compiler a chance to check weather the prototype and definiton matches or not, which would catch issues like 3c47701. --- Makefile | 2 +- components/battery.c | 1 + components/cpu.c | 1 + components/datetime.c | 1 + components/disk.c | 1 + components/entropy.c | 1 + components/hostname.c | 1 + components/ip.c | 1 + components/kernel_release.c | 1 + components/keyboard_indicators.c | 1 + components/keymap.c | 1 + components/load_avg.c | 1 + components/netspeeds.c | 1 + components/num_files.c | 1 + components/ram.c | 1 + components/run_command.c | 1 + components/separator.c | 1 + components/swap.c | 1 + components/temperature.c | 1 + components/uptime.c | 1 + components/user.c | 1 + components/volume.c | 1 + components/wifi.c | 1 + 23 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2f93b87..542b1f0 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ COM =\ all: slstatus -$(COM:=.o): config.mk $(REQ:=.h) +$(COM:=.o): config.mk $(REQ:=.h) slstatus.h slstatus.o: slstatus.c slstatus.h arg.h config.h config.mk $(REQ:=.h) .c.o: diff --git a/components/battery.c b/components/battery.c index a36132d..b7a2ec6 100644 --- a/components/battery.c +++ b/components/battery.c @@ -3,6 +3,7 @@ #include #include "../util.h" +#include "../slstatus.h" #if defined(__linux__) #include diff --git a/components/cpu.c b/components/cpu.c index 9e28003..a5fabf8 100644 --- a/components/cpu.c +++ b/components/cpu.c @@ -4,6 +4,7 @@ #include #include "../util.h" +#include "../slstatus.h" #if defined(__linux__) const char * diff --git a/components/datetime.c b/components/datetime.c index c3efae3..cf9fbba 100644 --- a/components/datetime.c +++ b/components/datetime.c @@ -3,6 +3,7 @@ #include #include "../util.h" +#include "../slstatus.h" const char * datetime(const char *fmt) diff --git a/components/disk.c b/components/disk.c index 15a221b..64e2105 100644 --- a/components/disk.c +++ b/components/disk.c @@ -3,6 +3,7 @@ #include #include "../util.h" +#include "../slstatus.h" const char * disk_free(const char *path) diff --git a/components/entropy.c b/components/entropy.c index 2a485de..cf60bc3 100644 --- a/components/entropy.c +++ b/components/entropy.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include "../slstatus.h" #if defined(__linux__) #include #include diff --git a/components/hostname.c b/components/hostname.c index 23da677..8627a88 100644 --- a/components/hostname.c +++ b/components/hostname.c @@ -3,6 +3,7 @@ #include #include "../util.h" +#include "../slstatus.h" const char * hostname(void) diff --git a/components/ip.c b/components/ip.c index 70724eb..6d1da68 100644 --- a/components/ip.c +++ b/components/ip.c @@ -12,6 +12,7 @@ #endif #include "../util.h" +#include "../slstatus.h" static const char * ip(const char *interface, unsigned short sa_family) diff --git a/components/kernel_release.c b/components/kernel_release.c index 0457301..76a3827 100644 --- a/components/kernel_release.c +++ b/components/kernel_release.c @@ -3,6 +3,7 @@ #include #include "../util.h" +#include "../slstatus.h" const char * kernel_release(void) diff --git a/components/keyboard_indicators.c b/components/keyboard_indicators.c index b35eba1..5f482e8 100644 --- a/components/keyboard_indicators.c +++ b/components/keyboard_indicators.c @@ -5,6 +5,7 @@ #include #include "../util.h" +#include "../slstatus.h" /* * fmt consists of uppercase or lowercase 'c' for caps lock and/or 'n' for num diff --git a/components/keymap.c b/components/keymap.c index ddf7a15..87036db 100644 --- a/components/keymap.c +++ b/components/keymap.c @@ -6,6 +6,7 @@ #include #include "../util.h" +#include "../slstatus.h" static int valid_layout_or_variant(char *sym) diff --git a/components/load_avg.c b/components/load_avg.c index 5c2e252..2b523e7 100644 --- a/components/load_avg.c +++ b/components/load_avg.c @@ -3,6 +3,7 @@ #include #include "../util.h" +#include "../slstatus.h" const char * load_avg(void) diff --git a/components/netspeeds.c b/components/netspeeds.c index 0029177..f7bac2e 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -3,6 +3,7 @@ #include #include "../util.h" +#include "../slstatus.h" #if defined(__linux__) #include diff --git a/components/num_files.c b/components/num_files.c index fb55df9..3911da7 100644 --- a/components/num_files.c +++ b/components/num_files.c @@ -4,6 +4,7 @@ #include #include "../util.h" +#include "../slstatus.h" const char * num_files(const char *path) diff --git a/components/ram.c b/components/ram.c index 6040e56..3fa78af 100644 --- a/components/ram.c +++ b/components/ram.c @@ -2,6 +2,7 @@ #include #include "../util.h" +#include "../slstatus.h" #if defined(__linux__) #include diff --git a/components/run_command.c b/components/run_command.c index e00b478..be7d9e2 100644 --- a/components/run_command.c +++ b/components/run_command.c @@ -3,6 +3,7 @@ #include #include "../util.h" +#include "../slstatus.h" const char * run_command(const char *cmd) diff --git a/components/separator.c b/components/separator.c index 40fec52..39a594a 100644 --- a/components/separator.c +++ b/components/separator.c @@ -2,6 +2,7 @@ #include #include "../util.h" +#include "../slstatus.h" const char * separator(const char *separator) diff --git a/components/swap.c b/components/swap.c index 2509db1..98983ee 100644 --- a/components/swap.c +++ b/components/swap.c @@ -5,6 +5,7 @@ #include #include "../util.h" +#include "../slstatus.h" #if defined(__linux__) static int diff --git a/components/temperature.c b/components/temperature.c index 8e1f222..306a09f 100644 --- a/components/temperature.c +++ b/components/temperature.c @@ -2,6 +2,7 @@ #include #include "../util.h" +#include "../slstatus.h" #if defined(__linux__) diff --git a/components/uptime.c b/components/uptime.c index 7c23c98..fc3d204 100644 --- a/components/uptime.c +++ b/components/uptime.c @@ -4,6 +4,7 @@ #include #include "../util.h" +#include "../slstatus.h" #if defined(CLOCK_BOOTTIME) #define UPTIME_FLAG CLOCK_BOOTTIME diff --git a/components/user.c b/components/user.c index 71a0c9d..fbe6814 100644 --- a/components/user.c +++ b/components/user.c @@ -5,6 +5,7 @@ #include #include "../util.h" +#include "../slstatus.h" const char * gid(void) diff --git a/components/volume.c b/components/volume.c index c94f872..5c85011 100644 --- a/components/volume.c +++ b/components/volume.c @@ -6,6 +6,7 @@ #include #include "../util.h" +#include "../slstatus.h" #if defined(__OpenBSD__) | defined(__FreeBSD__) #include diff --git a/components/wifi.c b/components/wifi.c index 92c252e..b9957ab 100644 --- a/components/wifi.c +++ b/components/wifi.c @@ -7,6 +7,7 @@ #include #include "../util.h" +#include "../slstatus.h" #define RSSI_TO_PERC(rssi) \ rssi >= -50 ? 100 : \ From 0c2b3e5b5c499b1de566fd4bef49c5e6b5254d1a Mon Sep 17 00:00:00 2001 From: NRK Date: Thu, 27 Oct 2022 02:16:05 +0600 Subject: [PATCH 09/43] do not rely on obsolete feature function prototype with unspecified argument is obsolete since c99. additionally some of these function which don't take any argument were being called with a `const char *` arg, which is UB. fix both these issues by declararing ALL the components to accept a `const char *`, and name the arg "unused" if it's meant to be ignored. --- components/cpu.c | 12 ++++++------ components/entropy.c | 4 ++-- components/hostname.c | 2 +- components/kernel_release.c | 2 +- components/keymap.c | 2 +- components/load_avg.c | 2 +- components/ram.c | 24 +++++++++++------------ components/swap.c | 24 +++++++++++------------ components/uptime.c | 2 +- components/user.c | 6 +++--- config.mk | 2 +- slstatus.c | 2 +- slstatus.h | 38 ++++++++++++++++++------------------- 13 files changed, 61 insertions(+), 61 deletions(-) diff --git a/components/cpu.c b/components/cpu.c index a5fabf8..254f047 100644 --- a/components/cpu.c +++ b/components/cpu.c @@ -8,7 +8,7 @@ #if defined(__linux__) const char * - cpu_freq(void) + cpu_freq(const char *unused) { uintmax_t freq; @@ -22,7 +22,7 @@ } const char * - cpu_perc(void) + cpu_perc(const char *unused) { static long double a[7]; long double b[7], sum; @@ -55,7 +55,7 @@ #include const char * - cpu_freq(void) + cpu_freq(const char *unused) { int freq, mib[2]; size_t size; @@ -75,7 +75,7 @@ } const char * - cpu_perc(void) + cpu_perc(const char *unused) { int mib[2]; static uintmax_t a[CPUSTATES]; @@ -115,7 +115,7 @@ #include const char * - cpu_freq(void) + cpu_freq(const char *unused) { int freq; size_t size; @@ -132,7 +132,7 @@ } const char * - cpu_perc(void) + cpu_perc(const char *unused) { size_t size; static long a[CPUSTATES]; diff --git a/components/entropy.c b/components/entropy.c index cf60bc3..0544749 100644 --- a/components/entropy.c +++ b/components/entropy.c @@ -7,7 +7,7 @@ #include "../util.h" const char * - entropy(void) + entropy(const char *unused) { uintmax_t num; @@ -20,7 +20,7 @@ } #elif defined(__OpenBSD__) | defined(__FreeBSD__) const char * - entropy(void) + entropy(const char *unused) { /* Unicode Character 'INFINITY' (U+221E) */ return "\xe2\x88\x9e"; diff --git a/components/hostname.c b/components/hostname.c index 8627a88..f04a913 100644 --- a/components/hostname.c +++ b/components/hostname.c @@ -6,7 +6,7 @@ #include "../slstatus.h" const char * -hostname(void) +hostname(const char *unused) { if (gethostname(buf, sizeof(buf)) < 0) { warn("gethostbyname:"); diff --git a/components/kernel_release.c b/components/kernel_release.c index 76a3827..e21fefe 100644 --- a/components/kernel_release.c +++ b/components/kernel_release.c @@ -6,7 +6,7 @@ #include "../slstatus.h" const char * -kernel_release(void) +kernel_release(const char *unused) { struct utsname udata; diff --git a/components/keymap.c b/components/keymap.c index 87036db..2a99474 100644 --- a/components/keymap.c +++ b/components/keymap.c @@ -47,7 +47,7 @@ get_layout(char *syms, int grp_num) } const char * -keymap(void) +keymap(const char *unused) { Display *dpy; XkbDescRec *desc; diff --git a/components/load_avg.c b/components/load_avg.c index 2b523e7..ab33fa3 100644 --- a/components/load_avg.c +++ b/components/load_avg.c @@ -6,7 +6,7 @@ #include "../slstatus.h" const char * -load_avg(void) +load_avg(const char *unused) { double avgs[3]; diff --git a/components/ram.c b/components/ram.c index 3fa78af..d90b107 100644 --- a/components/ram.c +++ b/components/ram.c @@ -8,7 +8,7 @@ #include const char * - ram_free(void) + ram_free(const char *unused) { uintmax_t free; @@ -24,7 +24,7 @@ } const char * - ram_perc(void) + ram_perc(const char *unused) { uintmax_t total, free, buffers, cached; @@ -47,7 +47,7 @@ } const char * - ram_total(void) + ram_total(const char *unused) { uintmax_t total; @@ -60,7 +60,7 @@ } const char * - ram_used(void) + ram_used(const char *unused) { uintmax_t total, free, buffers, cached; @@ -102,7 +102,7 @@ } const char * - ram_free(void) + ram_free(const char *unused) { struct uvmexp uvmexp; int free_pages; @@ -117,7 +117,7 @@ } const char * - ram_perc(void) + ram_perc(const char *unused) { struct uvmexp uvmexp; int percent; @@ -131,7 +131,7 @@ } const char * - ram_total(void) + ram_total(const char *unused) { struct uvmexp uvmexp; @@ -145,7 +145,7 @@ } const char * - ram_used(void) + ram_used(const char *unused) { struct uvmexp uvmexp; @@ -164,7 +164,7 @@ #include const char * - ram_free(void) { + ram_free(const char *unused) { struct vmtotal vm_stats; int mib[] = {CTL_VM, VM_TOTAL}; size_t len; @@ -178,7 +178,7 @@ } const char * - ram_total(void) { + ram_total(const char *unused) { unsigned int npages; size_t len; @@ -191,7 +191,7 @@ } const char * - ram_perc(void) { + ram_perc(const char *unused) { unsigned int npages; unsigned int active; size_t len; @@ -209,7 +209,7 @@ } const char * - ram_used(void) { + ram_used(const char *unused) { unsigned int active; size_t len; diff --git a/components/swap.c b/components/swap.c index 98983ee..2e8a6fb 100644 --- a/components/swap.c +++ b/components/swap.c @@ -59,7 +59,7 @@ } const char * - swap_free(void) + swap_free(const char *unused) { long free; @@ -71,7 +71,7 @@ } const char * - swap_perc(void) + swap_perc(const char *unused) { long total, free, cached; @@ -83,7 +83,7 @@ } const char * - swap_total(void) + swap_total(const char *unused) { long total; @@ -95,7 +95,7 @@ } const char * - swap_used(void) + swap_used(const char *unused) { long total, free, cached; @@ -148,7 +148,7 @@ } const char * - swap_free(void) + swap_free(const char *unused) { int total, used; @@ -160,7 +160,7 @@ } const char * - swap_perc(void) + swap_perc(const char *unused) { int total, used; @@ -176,7 +176,7 @@ } const char * - swap_total(void) + swap_total(const char *unused) { int total, used; @@ -188,7 +188,7 @@ } const char * - swap_used(void) + swap_used(const char *unused) { int total, used; @@ -226,7 +226,7 @@ } const char * - swap_free(void) + swap_free(const char *unused) { struct kvm_swap swap_info[1]; long used, total; @@ -241,7 +241,7 @@ } const char * - swap_perc(void) + swap_perc(const char *unused) { struct kvm_swap swap_info[1]; long used, total; @@ -256,7 +256,7 @@ } const char * - swap_total(void) + swap_total(const char *unused) { struct kvm_swap swap_info[1]; long total; @@ -270,7 +270,7 @@ } const char * - swap_used(void) + swap_used(const char *unused) { struct kvm_swap swap_info[1]; long used; diff --git a/components/uptime.c b/components/uptime.c index fc3d204..99d1eda 100644 --- a/components/uptime.c +++ b/components/uptime.c @@ -15,7 +15,7 @@ #endif const char * -uptime(void) +uptime(const char *unused) { char warn_buf[256]; uintmax_t h, m; diff --git a/components/user.c b/components/user.c index fbe6814..770f5af 100644 --- a/components/user.c +++ b/components/user.c @@ -8,13 +8,13 @@ #include "../slstatus.h" const char * -gid(void) +gid(const char *unused) { return bprintf("%d", getgid()); } const char * -username(void) +username(const char *unused) { struct passwd *pw; @@ -27,7 +27,7 @@ username(void) } const char * -uid(void) +uid(const char *unused) { return bprintf("%d", geteuid()); } diff --git a/config.mk b/config.mk index 6cce683..ead1859 100644 --- a/config.mk +++ b/config.mk @@ -12,7 +12,7 @@ X11LIB = /usr/X11R6/lib # flags CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE -CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os +CFLAGS = -std=c99 -pedantic -Wall -Wextra -Wno-unused-parameter -Os LDFLAGS = -L$(X11LIB) -s # OpenBSD: add -lsndio # FreeBSD: add -lkvm -lsndio diff --git a/slstatus.c b/slstatus.c index 64da5cb..8fe5b44 100644 --- a/slstatus.c +++ b/slstatus.c @@ -12,7 +12,7 @@ #include "util.h" struct arg { - const char *(*func)(); + const char *(*func)(const char *); const char *fmt; const char *args; }; diff --git a/slstatus.h b/slstatus.h index 362ca7c..95e52ce 100644 --- a/slstatus.h +++ b/slstatus.h @@ -6,8 +6,8 @@ const char *battery_state(const char *); const char *battery_remaining(const char *); /* cpu */ -const char *cpu_freq(void); -const char *cpu_perc(void); +const char *cpu_freq(const char *unused); +const char *cpu_perc(const char *unused); /* datetime */ const char *datetime(const char *fmt); @@ -19,26 +19,26 @@ const char *disk_total(const char *path); const char *disk_used(const char *path); /* entropy */ -const char *entropy(void); +const char *entropy(const char *unused); /* hostname */ -const char *hostname(void); +const char *hostname(const char *unused); /* ip */ const char *ipv4(const char *interface); const char *ipv6(const char *interface); /* kernel_release */ -const char *kernel_release(void); +const char *kernel_release(const char *unused); /* keyboard_indicators */ const char *keyboard_indicators(const char *fmt); /* keymap */ -const char *keymap(void); +const char *keymap(const char *unused); /* load_avg */ -const char *load_avg(void); +const char *load_avg(const char *unused); /* netspeeds */ const char *netspeed_rx(const char *interface); @@ -48,10 +48,10 @@ const char *netspeed_tx(const char *interface); const char *num_files(const char *path); /* ram */ -const char *ram_free(void); -const char *ram_perc(void); -const char *ram_total(void); -const char *ram_used(void); +const char *ram_free(const char *unused); +const char *ram_perc(const char *unused); +const char *ram_total(const char *unused); +const char *ram_used(const char *unused); /* run_command */ const char *run_command(const char *cmd); @@ -60,21 +60,21 @@ const char *run_command(const char *cmd); const char *separator(const char *separator); /* swap */ -const char *swap_free(void); -const char *swap_perc(void); -const char *swap_total(void); -const char *swap_used(void); +const char *swap_free(const char *unused); +const char *swap_perc(const char *unused); +const char *swap_total(const char *unused); +const char *swap_used(const char *unused); /* temperature */ const char *temp(const char *); /* uptime */ -const char *uptime(void); +const char *uptime(const char *unused); /* user */ -const char *gid(void); -const char *username(void); -const char *uid(void); +const char *gid(const char *unused); +const char *username(const char *unused); +const char *uid(const char *unused); /* volume */ const char *vol_perc(const char *card); From c46c1487a986496dd813ec52e17e5bf9ba10fd84 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Thu, 27 Oct 2022 22:14:20 +0200 Subject: [PATCH 10/43] separator: kill that useless thing Just use the format strings dude. :) --- Makefile | 1 - components/separator.c | 11 ----------- config.def.h | 1 - slstatus.h | 3 --- 4 files changed, 16 deletions(-) delete mode 100644 components/separator.c diff --git a/Makefile b/Makefile index 542b1f0..3be46cc 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,6 @@ COM =\ components/num_files\ components/ram\ components/run_command\ - components/separator\ components/swap\ components/temperature\ components/uptime\ diff --git a/components/separator.c b/components/separator.c deleted file mode 100644 index 39a594a..0000000 --- a/components/separator.c +++ /dev/null @@ -1,11 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include - -#include "../util.h" -#include "../slstatus.h" - -const char * -separator(const char *separator) -{ - return separator; -} diff --git a/config.def.h b/config.def.h index f76b60c..5f6c114 100644 --- a/config.def.h +++ b/config.def.h @@ -45,7 +45,6 @@ static const char unknown_str[] = "n/a"; * ram_total total memory size in GB NULL * ram_used used memory in GB NULL * run_command custom shell command command (echo foo) - * separator string to echo NULL * swap_free free swap in GB NULL * swap_perc swap usage in percent NULL * swap_total total swap size in GB NULL diff --git a/slstatus.h b/slstatus.h index 95e52ce..f3b4979 100644 --- a/slstatus.h +++ b/slstatus.h @@ -56,9 +56,6 @@ const char *ram_used(const char *unused); /* run_command */ const char *run_command(const char *cmd); -/* separator */ -const char *separator(const char *separator); - /* swap */ const char *swap_free(const char *unused); const char *swap_perc(const char *unused); From 69b2487650782f135db76078c4a7fb841cb936ac Mon Sep 17 00:00:00 2001 From: drkhsh Date: Thu, 27 Oct 2022 23:44:52 +0200 Subject: [PATCH 11/43] various: Put paths into defines to avoid line wraps Long, wrapped, multi-line if statements suck to read. This fixes readability in the worst places by packing format strings for paths into defines. --- components/battery.c | 46 ++++++++++++++++++++---------------------- components/cpu.c | 6 +++--- components/entropy.c | 6 +++--- components/netspeeds.c | 13 +++++------- components/wifi.c | 6 +++--- 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/components/battery.c b/components/battery.c index b7a2ec6..0fe70ff 100644 --- a/components/battery.c +++ b/components/battery.c @@ -10,6 +10,13 @@ #include #include + #define POWER_SUPPLY_CAPACITY "/sys/class/power_supply/%s/capacity" + #define POWER_SUPPLY_STATUS "/sys/class/power_supply/%s/status" + #define POWER_SUPPLY_CHARGE "/sys/class/power_supply/%s/charge_now" + #define POWER_SUPPLY_ENERGY "/sys/class/power_supply/%s/energy_now" + #define POWER_SUPPLY_CURRENT "/sys/class/power_supply/%s/current" + #define POWER_SUPPLY_POWER "/sys/class/power_supply/%s/power" + static const char * pick(const char *bat, const char *f1, const char *f2, char *path, size_t length) @@ -33,10 +40,8 @@ int perc; char path[PATH_MAX]; - if (esnprintf(path, sizeof(path), - "/sys/class/power_supply/%s/capacity", bat) < 0) { + if (esnprintf(path, sizeof(path), POWER_SUPPLY_CAPACITY, bat) < 0) return NULL; - } if (pscanf(path, "%d", &perc) != 1) { return NULL; } @@ -59,10 +64,8 @@ size_t i; char path[PATH_MAX], state[12]; - if (esnprintf(path, sizeof(path), - "/sys/class/power_supply/%s/status", bat) < 0) { + if (esnprintf(path, sizeof(path), POWER_SUPPLY_STATUS, bat) < 0) return NULL; - } if (pscanf(path, "%12[a-zA-Z ]", state) != 1) { return NULL; } @@ -82,28 +85,22 @@ double timeleft; char path[PATH_MAX], state[12]; - if (esnprintf(path, sizeof(path), - "/sys/class/power_supply/%s/status", bat) < 0) { + if (esnprintf(path, sizeof(path), POWER_SUPPLY_STATUS, bat) < 0) return NULL; - } if (pscanf(path, "%12[a-zA-Z ]", state) != 1) { return NULL; } - if (!pick(bat, "/sys/class/power_supply/%s/charge_now", - "/sys/class/power_supply/%s/energy_now", path, + if (!pick(bat, POWER_SUPPLY_CHARGE, POWER_SUPPLY_ENERGY, path, sizeof(path)) || - pscanf(path, "%ju", &charge_now) < 0) { + pscanf(path, "%ju", &charge_now) < 0) return NULL; - } if (!strcmp(state, "Discharging")) { - if (!pick(bat, "/sys/class/power_supply/%s/current_now", - "/sys/class/power_supply/%s/power_now", path, + if (!pick(bat, POWER_SUPPLY_CURRENT, POWER_SUPPLY_POWER, path, sizeof(path)) || - pscanf(path, "%ju", ¤t_now) < 0) { + pscanf(path, "%ju", ¤t_now) < 0) return NULL; - } if (current_now == 0) { return NULL; @@ -201,6 +198,10 @@ #elif defined(__FreeBSD__) #include + #define BATTERY_LIFE "hw.acpi.battery.life" + #define BATTERY_STATE "hw.acpi.battery.state" + #define BATTERY_TIME "hw.acpi.battery.time" + const char * battery_perc(const char *unused) { @@ -208,8 +209,7 @@ size_t len; len = sizeof(cap); - if (sysctlbyname("hw.acpi.battery.life", &cap, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname(BATTERY_LIFE, &cap, &len, NULL, 0) < 0 || !len) return NULL; return bprintf("%d", cap); @@ -222,8 +222,7 @@ size_t len; len = sizeof(state); - if (sysctlbyname("hw.acpi.battery.state", &state, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname(BATTERY_STATE, &state, &len, NULL, 0) < 0 || !len) return NULL; switch(state) { @@ -244,9 +243,8 @@ size_t len; len = sizeof(rem); - if (sysctlbyname("hw.acpi.battery.time", &rem, &len, NULL, 0) == -1 - || !len - || rem == -1) + if (sysctlbyname(BATTERY_TIME, &rem, &len, NULL, 0) < 0 || !len + || rem < 0) return NULL; return bprintf("%uh %02um", rem / 60, rem % 60); diff --git a/components/cpu.c b/components/cpu.c index 254f047..28e9a45 100644 --- a/components/cpu.c +++ b/components/cpu.c @@ -7,16 +7,16 @@ #include "../slstatus.h" #if defined(__linux__) + #define CPU_FREQ "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" + const char * cpu_freq(const char *unused) { uintmax_t freq; /* in kHz */ - if (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/" - "scaling_cur_freq", "%ju", &freq) != 1) { + if (pscanf(CPU_FREQ, "%ju", &freq) != 1) return NULL; - } return fmt_human(freq * 1000, 1000); } diff --git a/components/entropy.c b/components/entropy.c index 0544749..66b2e5a 100644 --- a/components/entropy.c +++ b/components/entropy.c @@ -6,15 +6,15 @@ #include "../util.h" + #define ENTROPY_AVAIL "/proc/sys/kernel/random/entropy_avail" + const char * entropy(const char *unused) { uintmax_t num; - if (pscanf("/proc/sys/kernel/random/entropy_avail", "%ju", &num) - != 1) { + if (pscanf(ENTROPY_AVAIL, "%ju", &num) != 1) return NULL; - } return bprintf("%ju", num); } diff --git a/components/netspeeds.c b/components/netspeeds.c index f7bac2e..3a1817b 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -8,6 +8,9 @@ #if defined(__linux__) #include + #define NET_RX_BYTES "/sys/class/net/%s/statistics/rx_bytes" + #define NET_TX_BYTES "/sys/class/net/%s/statistics/tx_bytes" + const char * netspeed_rx(const char *interface) { @@ -18,11 +21,8 @@ oldrxbytes = rxbytes; - if (esnprintf(path, sizeof(path), - "/sys/class/net/%s/statistics/rx_bytes", - interface) < 0) { + if (esnprintf(path, sizeof(path), NET_RX_BYTES, interface) < 0) return NULL; - } if (pscanf(path, "%ju", &rxbytes) != 1) { return NULL; } @@ -44,11 +44,8 @@ oldtxbytes = txbytes; - if (esnprintf(path, sizeof(path), - "/sys/class/net/%s/statistics/tx_bytes", - interface) < 0) { + if (esnprintf(path, sizeof(path), NET_TX_BYTES, interface) < 0) return NULL; - } if (pscanf(path, "%ju", &txbytes) != 1) { return NULL; } diff --git a/components/wifi.c b/components/wifi.c index b9957ab..d097368 100644 --- a/components/wifi.c +++ b/components/wifi.c @@ -18,6 +18,8 @@ #include #include + #define NET_OPERSTATE "/sys/class/net/%s/operstate" + const char * wifi_perc(const char *interface) { @@ -28,10 +30,8 @@ char status[5]; FILE *fp; - if (esnprintf(path, sizeof(path), "/sys/class/net/%s/operstate", - interface) < 0) { + if (esnprintf(path, sizeof(path), NET_OPERSTATE, interface) < 0) return NULL; - } if (!(fp = fopen(path, "r"))) { warn("fopen '%s':", path); return NULL; From 21327e0373189f9e9964f34fb5a15639d00575aa Mon Sep 17 00:00:00 2001 From: drkhsh Date: Fri, 28 Oct 2022 00:15:21 +0200 Subject: [PATCH 12/43] temp: Put sysctl into define to avoid line wraps Long, wrapped, multi-line if statements suck to read. This fixes readability. --- components/temperature.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/temperature.c b/components/temperature.c index 306a09f..01d21b9 100644 --- a/components/temperature.c +++ b/components/temperature.c @@ -53,6 +53,8 @@ #include #include + #define ACPI_TEMP "hw.acpi.thermal.%s.temperature" + const char * temp(const char *zone) { @@ -61,8 +63,8 @@ size_t len; len = sizeof(temp); - snprintf(buf, sizeof(buf), "hw.acpi.thermal.%s.temperature", zone); - if (sysctlbyname(buf, &temp, &len, NULL, 0) == -1 + snprintf(buf, sizeof(buf), ACPI_TEMP, zone); + if (sysctlbyname(buf, &temp, &len, NULL, 0) < 0 || !len) return NULL; From 3b86e4b5efd0f6759b2634b607e74b938af30a60 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Thu, 27 Oct 2022 23:47:01 +0200 Subject: [PATCH 13/43] battery: Refactor remaining on OpenBSD Fixes up overly complicated line, by splitting up logic --- components/battery.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/battery.c b/components/battery.c index 0fe70ff..ee2fe71 100644 --- a/components/battery.c +++ b/components/battery.c @@ -182,12 +182,13 @@ battery_remaining(const char *unused) { struct apm_power_info apm_info; + unsigned int h, m; if (load_apm_power_info(&apm_info)) { if (apm_info.ac_state != APM_AC_ON) { - return bprintf("%uh %02um", - apm_info.minutes_left / 60, - apm_info.minutes_left % 60); + h = apm_info.minutes_left / 60; + m = apm_info.minutes_left % 60; + return bprintf("%uh %02um", h, m); } else { return ""; } From d7ea986299db33e3bce7a8be742c1ecf32e9a76e Mon Sep 17 00:00:00 2001 From: drkhsh Date: Fri, 28 Oct 2022 00:11:15 +0200 Subject: [PATCH 14/43] ram: Refactor Linux perc/used Fixes up overly complicated line, by splitting up logic --- components/ram.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/ram.c b/components/ram.c index d90b107..9a69db8 100644 --- a/components/ram.c +++ b/components/ram.c @@ -27,6 +27,7 @@ ram_perc(const char *unused) { uintmax_t total, free, buffers, cached; + int percent; if (pscanf("/proc/meminfo", "MemTotal: %ju kB\n" @@ -42,8 +43,8 @@ return NULL; } - return bprintf("%d", 100 * ((total - free) - (buffers + cached)) - / total); + percent = 100 * ((total - free) - (buffers + cached)) / total; + return bprintf("%d", percent); } const char * @@ -62,7 +63,7 @@ const char * ram_used(const char *unused) { - uintmax_t total, free, buffers, cached; + uintmax_t total, free, buffers, cached, used; if (pscanf("/proc/meminfo", "MemTotal: %ju kB\n" @@ -70,12 +71,11 @@ "MemAvailable: %ju kB\n" "Buffers: %ju kB\n" "Cached: %ju kB\n", - &total, &free, &buffers, &buffers, &cached) != 5) { + &total, &free, &buffers, &buffers, &cached) != 5) return NULL; - } - return fmt_human((total - free - buffers - cached) * 1024, - 1024); + used = (total - free - buffers - cached); + return fmt_human(used * 1024, 1024); } #elif defined(__OpenBSD__) #include From 826a5dc86202624b00ad2a51d781758a7f7ca1fa Mon Sep 17 00:00:00 2001 From: drkhsh Date: Fri, 28 Oct 2022 00:13:12 +0200 Subject: [PATCH 15/43] ram: Refactor on OpenBSD Fixes up overly complicated lines, by splitting up logic --- components/ram.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/components/ram.c b/components/ram.c index 9a69db8..0cec4b9 100644 --- a/components/ram.c +++ b/components/ram.c @@ -107,13 +107,12 @@ struct uvmexp uvmexp; int free_pages; - if (load_uvmexp(&uvmexp)) { - free_pages = uvmexp.npages - uvmexp.active; - return fmt_human(pagetok(free_pages, uvmexp.pageshift) * - 1024, 1024); - } + if (!load_uvmexp(&uvmexp)) + return NULL; - return NULL; + free_pages = uvmexp.npages - uvmexp.active; + return fmt_human(pagetok(free_pages, uvmexp.pageshift) * + 1024, 1024); } const char * @@ -122,12 +121,11 @@ struct uvmexp uvmexp; int percent; - if (load_uvmexp(&uvmexp)) { - percent = uvmexp.active * 100 / uvmexp.npages; - return bprintf("%d", percent); - } + if (!load_uvmexp(&uvmexp)) + return NULL; - return NULL; + percent = uvmexp.active * 100 / uvmexp.npages; + return bprintf("%d", percent); } const char * @@ -135,13 +133,11 @@ { struct uvmexp uvmexp; - if (load_uvmexp(&uvmexp)) { - return fmt_human(pagetok(uvmexp.npages, - uvmexp.pageshift) * 1024, - 1024); - } + if (!load_uvmexp(&uvmexp)) + return NULL; - return NULL; + return fmt_human(pagetok(uvmexp.npages, + uvmexp.pageshift) * 1024, 1024); } const char * @@ -149,13 +145,11 @@ { struct uvmexp uvmexp; - if (load_uvmexp(&uvmexp)) { - return fmt_human(pagetok(uvmexp.active, - uvmexp.pageshift) * 1024, - 1024); - } + if (!load_uvmexp(&uvmexp)) + return NULL; - return NULL; + return fmt_human(pagetok(uvmexp.active, + uvmexp.pageshift) * 1024, 1024); } #elif defined(__FreeBSD__) #include From 0696635bcbad06770cce7d5a4c9e8e4d76868307 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Thu, 27 Oct 2022 23:18:30 +0200 Subject: [PATCH 16/43] radical re-formatting 0/3: Alphabetic headers Except stated otherwise in comment. Fixes coding style. Formatting commits suck, incoherent coding style sucks more. https://suckless.org/coding_style/ --- components/battery.c | 2 +- components/cpu.c | 4 ++-- components/datetime.c | 2 +- components/disk.c | 2 +- components/hostname.c | 2 +- components/ip.c | 4 ++-- components/kernel_release.c | 4 ++-- components/keyboard_indicators.c | 2 +- components/keymap.c | 2 +- components/load_avg.c | 2 +- components/netspeeds.c | 8 ++++---- components/num_files.c | 2 +- components/ram.c | 2 +- components/run_command.c | 2 +- components/swap.c | 6 +++--- components/temperature.c | 2 +- components/uptime.c | 2 +- components/user.c | 2 +- components/volume.c | 4 ++-- components/wifi.c | 2 +- 20 files changed, 29 insertions(+), 29 deletions(-) diff --git a/components/battery.c b/components/battery.c index ee2fe71..3746095 100644 --- a/components/battery.c +++ b/components/battery.c @@ -2,8 +2,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" #if defined(__linux__) #include diff --git a/components/cpu.c b/components/cpu.c index 28e9a45..20354c0 100644 --- a/components/cpu.c +++ b/components/cpu.c @@ -3,8 +3,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" #if defined(__linux__) #define CPU_FREQ "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" @@ -110,9 +110,9 @@ b[CP_INTR])) / sum); } #elif defined(__FreeBSD__) + #include #include #include - #include const char * cpu_freq(const char *unused) diff --git a/components/datetime.c b/components/datetime.c index cf9fbba..5b10daf 100644 --- a/components/datetime.c +++ b/components/datetime.c @@ -2,8 +2,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" const char * datetime(const char *fmt) diff --git a/components/disk.c b/components/disk.c index 64e2105..0d1c13e 100644 --- a/components/disk.c +++ b/components/disk.c @@ -2,8 +2,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" const char * disk_free(const char *path) diff --git a/components/hostname.c b/components/hostname.c index f04a913..dab8b63 100644 --- a/components/hostname.c +++ b/components/hostname.c @@ -2,8 +2,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" const char * hostname(const char *unused) diff --git a/components/ip.c b/components/ip.c index 6d1da68..a954ae1 100644 --- a/components/ip.c +++ b/components/ip.c @@ -4,15 +4,15 @@ #include #include #if defined(__OpenBSD__) - #include #include + #include #elif defined(__FreeBSD__) #include #include #endif -#include "../util.h" #include "../slstatus.h" +#include "../util.h" static const char * ip(const char *interface, unsigned short sa_family) diff --git a/components/kernel_release.c b/components/kernel_release.c index e21fefe..36a6a44 100644 --- a/components/kernel_release.c +++ b/components/kernel_release.c @@ -1,9 +1,9 @@ /* See LICENSE file for copyright and license details. */ -#include #include +#include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" const char * kernel_release(const char *unused) diff --git a/components/keyboard_indicators.c b/components/keyboard_indicators.c index 5f482e8..4a81539 100644 --- a/components/keyboard_indicators.c +++ b/components/keyboard_indicators.c @@ -4,8 +4,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" /* * fmt consists of uppercase or lowercase 'c' for caps lock and/or 'n' for num diff --git a/components/keymap.c b/components/keymap.c index 2a99474..e2dbc6f 100644 --- a/components/keymap.c +++ b/components/keymap.c @@ -5,8 +5,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" static int valid_layout_or_variant(char *sym) diff --git a/components/load_avg.c b/components/load_avg.c index ab33fa3..f278a40 100644 --- a/components/load_avg.c +++ b/components/load_avg.c @@ -2,8 +2,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" const char * load_avg(const char *unused) diff --git a/components/netspeeds.c b/components/netspeeds.c index 3a1817b..18aa097 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -1,9 +1,9 @@ /* See LICENSE file for copyright and license details. */ -#include #include +#include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" #if defined(__linux__) #include @@ -57,11 +57,11 @@ 1024); } #elif defined(__OpenBSD__) | defined(__FreeBSD__) - #include #include + #include + #include #include #include - #include const char * netspeed_rx(const char *interface) diff --git a/components/num_files.c b/components/num_files.c index 3911da7..8205562 100644 --- a/components/num_files.c +++ b/components/num_files.c @@ -3,8 +3,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" const char * num_files(const char *path) diff --git a/components/ram.c b/components/ram.c index 0cec4b9..518c18c 100644 --- a/components/ram.c +++ b/components/ram.c @@ -1,8 +1,8 @@ /* See LICENSE file for copyright and license details. */ #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" #if defined(__linux__) #include diff --git a/components/run_command.c b/components/run_command.c index be7d9e2..942f3c4 100644 --- a/components/run_command.c +++ b/components/run_command.c @@ -2,8 +2,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" const char * run_command(const char *cmd) diff --git a/components/swap.c b/components/swap.c index 2e8a6fb..49ba3cb 100644 --- a/components/swap.c +++ b/components/swap.c @@ -4,8 +4,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" #if defined(__linux__) static int @@ -199,11 +199,11 @@ return fmt_human(used * 1024, 1024); } #elif defined(__FreeBSD__) + #include + #include #include #include - #include #include - #include static int getswapinfo(struct kvm_swap *swap_info, size_t size) { diff --git a/components/temperature.c b/components/temperature.c index 01d21b9..c61a574 100644 --- a/components/temperature.c +++ b/components/temperature.c @@ -1,8 +1,8 @@ /* See LICENSE file for copyright and license details. */ #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" #if defined(__linux__) diff --git a/components/uptime.c b/components/uptime.c index 99d1eda..d97e5e8 100644 --- a/components/uptime.c +++ b/components/uptime.c @@ -3,8 +3,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" #if defined(CLOCK_BOOTTIME) #define UPTIME_FLAG CLOCK_BOOTTIME diff --git a/components/user.c b/components/user.c index 770f5af..3517495 100644 --- a/components/user.c +++ b/components/user.c @@ -4,8 +4,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" const char * gid(const char *unused) diff --git a/components/volume.c b/components/volume.c index 5c85011..6cec556 100644 --- a/components/volume.c +++ b/components/volume.c @@ -5,14 +5,14 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" #if defined(__OpenBSD__) | defined(__FreeBSD__) - #include #include #include #include + #include struct control { LIST_ENTRY(control) next; diff --git a/components/wifi.c b/components/wifi.c index d097368..d75a613 100644 --- a/components/wifi.c +++ b/components/wifi.c @@ -6,8 +6,8 @@ #include #include -#include "../util.h" #include "../slstatus.h" +#include "../util.h" #define RSSI_TO_PERC(rssi) \ rssi >= -50 ? 100 : \ From 2104dc362ca7336d98499a5945ea2a3d371f7568 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Fri, 28 Oct 2022 00:49:31 +0200 Subject: [PATCH 17/43] radical re-formatting 1/3: Fix spacing Fixes coding style. Formatting commits suck, incoherent coding style sucks more. https://suckless.org/coding_style/ --- arg.h | 4 ++-- components/battery.c | 16 ++++++++-------- components/swap.c | 10 +++++----- components/wifi.c | 2 +- slstatus.c | 16 ++++++++-------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/arg.h b/arg.h index e0adb9f..5f1f408 100644 --- a/arg.h +++ b/arg.h @@ -13,7 +13,7 @@ extern char *argv0; break; \ } \ for (i_ = 1, argused_ = 0; (*argv)[i_]; i_++) { \ - switch((*argv)[i_]) + switch ((*argv)[i_]) #define ARGEND if (argused_) { \ if ((*argv)[i_ + 1]) { \ break; \ @@ -24,7 +24,7 @@ extern char *argv0; } \ } \ } -#define ARGC() ((*argv)[i_]) +#define ARGC() ((*argv)[i_]) #define ARGF_(x) (((*argv)[i_ + 1]) ? (argused_ = 1, &((*argv)[i_ + 1])) : \ (*(argv + 1)) ? (argused_ = 1, *(argv + 1)) : (x)) #define EARGF(x) ARGF_(((x), exit(1), (char *)0)) diff --git a/components/battery.c b/components/battery.c index 3746095..00ae70a 100644 --- a/components/battery.c +++ b/components/battery.c @@ -226,14 +226,14 @@ if (sysctlbyname(BATTERY_STATE, &state, &len, NULL, 0) < 0 || !len) return NULL; - switch(state) { - case 0: - case 2: - return "+"; - case 1: - return "-"; - default: - return "?"; + switch (state) { + case 0: /* FALLTHROUGH */ + case 2: + return "+"; + case 1: + return "-"; + default: + return "?"; } } diff --git a/components/swap.c b/components/swap.c index 49ba3cb..af05e01 100644 --- a/components/swap.c +++ b/components/swap.c @@ -210,7 +210,7 @@ kvm_t *kd; kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, NULL); - if(kd == NULL) { + if (kd == NULL) { warn("kvm_openfiles '/dev/null':"); return 0; } @@ -231,7 +231,7 @@ struct kvm_swap swap_info[1]; long used, total; - if(!getswapinfo(swap_info, 1)) + if (!getswapinfo(swap_info, 1)) return NULL; total = swap_info[0].ksw_total; @@ -246,7 +246,7 @@ struct kvm_swap swap_info[1]; long used, total; - if(!getswapinfo(swap_info, 1)) + if (!getswapinfo(swap_info, 1)) return NULL; total = swap_info[0].ksw_total; @@ -261,7 +261,7 @@ struct kvm_swap swap_info[1]; long total; - if(!getswapinfo(swap_info, 1)) + if (!getswapinfo(swap_info, 1)) return NULL; total = swap_info[0].ksw_total; @@ -275,7 +275,7 @@ struct kvm_swap swap_info[1]; long used; - if(!getswapinfo(swap_info, 1)) + if (!getswapinfo(swap_info, 1)) return NULL; used = swap_info[0].ksw_used; diff --git a/components/wifi.c b/components/wifi.c index d75a613..a20e8d4 100644 --- a/components/wifi.c +++ b/components/wifi.c @@ -257,7 +257,7 @@ fmt = NULL; len = sizeof(ssid); memset(&ssid, 0, len); - if (load_ieee80211req(sockfd, interface, &ssid, IEEE80211_IOC_SSID, &len )) { + if (load_ieee80211req(sockfd, interface, &ssid, IEEE80211_IOC_SSID, &len)) { if (len < sizeof(ssid)) len += 1; else diff --git a/slstatus.c b/slstatus.c index 8fe5b44..a8ac28e 100644 --- a/slstatus.c +++ b/slstatus.c @@ -56,14 +56,14 @@ main(int argc, char *argv[]) sflag = 0; ARGBEGIN { - case '1': - done = 1; - /* fallthrough */ - case 's': - sflag = 1; - break; - default: - usage(); + case '1': + done = 1; + /* FALLTHROUGH */ + case 's': + sflag = 1; + break; + default: + usage(); } ARGEND if (argc) { From 3251e911878b78b0aad8fc09c782f8d81c878f75 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Fri, 28 Oct 2022 00:51:34 +0200 Subject: [PATCH 18/43] radical re-formatting 2/3: Fix blocks Fixes coding style. Formatting commits suck, incoherent coding style sucks more. https://suckless.org/coding_style/ --- components/battery.c | 35 ++++++++++++-------------------- components/cpu.c | 22 ++++++++------------ components/ip.c | 4 ++-- components/keyboard_indicators.c | 11 +++++----- components/keymap.c | 9 +++----- components/netspeeds.c | 32 +++++++++++------------------ components/num_files.c | 4 ++-- components/ram.c | 15 +++++--------- components/run_command.c | 8 ++++---- components/swap.c | 33 ++++++++++-------------------- components/temperature.c | 3 +-- components/wifi.c | 32 ++++++++++++----------------- slstatus.c | 35 ++++++++++++-------------------- util.c | 6 ++---- 14 files changed, 95 insertions(+), 154 deletions(-) diff --git a/components/battery.c b/components/battery.c index 00ae70a..b12c59e 100644 --- a/components/battery.c +++ b/components/battery.c @@ -22,14 +22,12 @@ size_t length) { if (esnprintf(path, length, f1, bat) > 0 && - access(path, R_OK) == 0) { + access(path, R_OK) == 0) return f1; - } if (esnprintf(path, length, f2, bat) > 0 && - access(path, R_OK) == 0) { + access(path, R_OK) == 0) return f2; - } return NULL; } @@ -42,9 +40,8 @@ if (esnprintf(path, sizeof(path), POWER_SUPPLY_CAPACITY, bat) < 0) return NULL; - if (pscanf(path, "%d", &perc) != 1) { + if (pscanf(path, "%d", &perc) != 1) return NULL; - } return bprintf("%d", perc); } @@ -66,15 +63,13 @@ if (esnprintf(path, sizeof(path), POWER_SUPPLY_STATUS, bat) < 0) return NULL; - if (pscanf(path, "%12[a-zA-Z ]", state) != 1) { + if (pscanf(path, "%12[a-zA-Z ]", state) != 1) return NULL; - } - for (i = 0; i < LEN(map); i++) { - if (!strcmp(map[i].state, state)) { + for (i = 0; i < LEN(map); i++) + if (!strcmp(map[i].state, state)) break; - } - } + return (i == LEN(map)) ? "?" : map[i].symbol; } @@ -87,9 +82,8 @@ if (esnprintf(path, sizeof(path), POWER_SUPPLY_STATUS, bat) < 0) return NULL; - if (pscanf(path, "%12[a-zA-Z ]", state) != 1) { + if (pscanf(path, "%12[a-zA-Z ]", state) != 1) return NULL; - } if (!pick(bat, POWER_SUPPLY_CHARGE, POWER_SUPPLY_ENERGY, path, sizeof(path)) || @@ -102,9 +96,8 @@ pscanf(path, "%ju", ¤t_now) < 0) return NULL; - if (current_now == 0) { + if (current_now == 0) return NULL; - } timeleft = (double)charge_now / (double)current_now; h = timeleft; @@ -146,9 +139,8 @@ { struct apm_power_info apm_info; - if (load_apm_power_info(&apm_info)) { + if (load_apm_power_info(&apm_info)) return bprintf("%d", apm_info.battery_life); - } return NULL; } @@ -167,11 +159,10 @@ size_t i; if (load_apm_power_info(&apm_info)) { - for (i = 0; i < LEN(map); i++) { - if (map[i].state == apm_info.ac_state) { + for (i = 0; i < LEN(map); i++) + if (map[i].state == apm_info.ac_state) break; - } - } + return (i == LEN(map)) ? "?" : map[i].symbol; } diff --git a/components/cpu.c b/components/cpu.c index 20354c0..10d25c0 100644 --- a/components/cpu.c +++ b/components/cpu.c @@ -31,19 +31,17 @@ /* cpu user nice system idle iowait irq softirq */ if (pscanf("/proc/stat", "%*s %Lf %Lf %Lf %Lf %Lf %Lf %Lf", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6]) - != 7) { + != 7) return NULL; - } - if (b[0] == 0) { + + if (b[0] == 0) return NULL; - } sum = (b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6]) - (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6]); - if (sum == 0) { + if (sum == 0) return NULL; - } return bprintf("%d", (int)(100 * ((b[0] + b[1] + b[2] + b[5] + b[6]) - @@ -92,16 +90,14 @@ warn("sysctl 'KERN_CPTIME':"); return NULL; } - if (b[0] == 0) { + if (b[0] == 0) return NULL; - } sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE]) - (b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]); - if (sum == 0) { + if (sum == 0) return NULL; - } return bprintf("%d", 100 * ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] + @@ -145,16 +141,14 @@ warn("sysctlbyname 'kern.cp_time':"); return NULL; } - if (b[0] == 0) { + if (b[0] == 0) return NULL; - } sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE]) - (b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]); - if (sum == 0) { + if (sum == 0) return NULL; - } return bprintf("%d", 100 * ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] + diff --git a/components/ip.c b/components/ip.c index a954ae1..9476549 100644 --- a/components/ip.c +++ b/components/ip.c @@ -27,9 +27,9 @@ ip(const char *interface, unsigned short sa_family) } for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (!ifa->ifa_addr) { + if (!ifa->ifa_addr) continue; - } + s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (!strcmp(ifa->ifa_name, interface) && diff --git a/components/keyboard_indicators.c b/components/keyboard_indicators.c index 4a81539..5f62bb7 100644 --- a/components/keyboard_indicators.c +++ b/components/keyboard_indicators.c @@ -33,17 +33,18 @@ keyboard_indicators(const char *fmt) fmtlen = strnlen(fmt, 4); for (i = n = 0; i < fmtlen; i++) { key = tolower(fmt[i]); - if (key != 'c' && key != 'n') { + if (key != 'c' && key != 'n') continue; - } + togglecase = (i + 1 >= fmtlen || fmt[i + 1] != '?'); isset = (state.led_mask & (1 << (key == 'n'))); - if (togglecase) { + + if (togglecase) buf[n++] = isset ? toupper(key) : key; - } else if (isset) { + else if (isset) buf[n++] = fmt[i]; - } } + buf[n] = 0; return buf; } diff --git a/components/keymap.c b/components/keymap.c index e2dbc6f..4740431 100644 --- a/components/keymap.c +++ b/components/keymap.c @@ -15,11 +15,9 @@ valid_layout_or_variant(char *sym) /* invalid symbols from xkb rules config */ static const char *invalid[] = { "evdev", "inet", "pc", "base" }; - for (i = 0; i < LEN(invalid); i++) { - if (!strncmp(sym, invalid[i], strlen(invalid[i]))) { + for (i = 0; i < LEN(invalid); i++) + if (!strncmp(sym, invalid[i], strlen(invalid[i]))) return 0; - } - } return 1; } @@ -80,9 +78,8 @@ keymap(const char *unused) XFree(symbols); end: XkbFreeKeyboard(desc, XkbSymbolsNameMask, 1); - if (XCloseDisplay(dpy)) { + if (XCloseDisplay(dpy)) warn("XCloseDisplay: Failed to close display"); - } return layout; } diff --git a/components/netspeeds.c b/components/netspeeds.c index 18aa097..97e565b 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -23,12 +23,10 @@ if (esnprintf(path, sizeof(path), NET_RX_BYTES, interface) < 0) return NULL; - if (pscanf(path, "%ju", &rxbytes) != 1) { + if (pscanf(path, "%ju", &rxbytes) != 1) return NULL; - } - if (oldrxbytes == 0) { + if (oldrxbytes == 0) return NULL; - } return fmt_human((rxbytes - oldrxbytes) * 1000 / interval, 1024); @@ -46,12 +44,10 @@ if (esnprintf(path, sizeof(path), NET_TX_BYTES, interface) < 0) return NULL; - if (pscanf(path, "%ju", &txbytes) != 1) { + if (pscanf(path, "%ju", &txbytes) != 1) return NULL; - } - if (oldtxbytes == 0) { + if (oldtxbytes == 0) return NULL; - } return fmt_human((txbytes - oldtxbytes) * 1000 / interval, 1024); @@ -80,20 +76,18 @@ return NULL; } rxbytes = 0; - for (ifa = ifal; ifa; ifa = ifa->ifa_next) { + for (ifa = ifal; ifa; ifa = ifa->ifa_next) if (!strcmp(ifa->ifa_name, interface) && - (ifd = (struct if_data *)ifa->ifa_data)) { + (ifd = (struct if_data *)ifa->ifa_data)) rxbytes += ifd->ifi_ibytes, if_ok = 1; - } - } + freeifaddrs(ifal); if (!if_ok) { warn("reading 'if_data' failed"); return NULL; } - if (oldrxbytes == 0) { + if (oldrxbytes == 0) return NULL; - } return fmt_human((rxbytes - oldrxbytes) * 1000 / interval, 1024); @@ -116,20 +110,18 @@ return NULL; } txbytes = 0; - for (ifa = ifal; ifa; ifa = ifa->ifa_next) { + for (ifa = ifal; ifa; ifa = ifa->ifa_next) if (!strcmp(ifa->ifa_name, interface) && - (ifd = (struct if_data *)ifa->ifa_data)) { + (ifd = (struct if_data *)ifa->ifa_data)) txbytes += ifd->ifi_obytes, if_ok = 1; - } - } + freeifaddrs(ifal); if (!if_ok) { warn("reading 'if_data' failed"); return NULL; } - if (oldtxbytes == 0) { + if (oldtxbytes == 0) return NULL; - } return fmt_human((txbytes - oldtxbytes) * 1000 / interval, 1024); diff --git a/components/num_files.c b/components/num_files.c index 8205562..e4b4281 100644 --- a/components/num_files.c +++ b/components/num_files.c @@ -20,9 +20,9 @@ num_files(const char *path) num = 0; while ((dp = readdir(fd))) { - if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { + if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; /* skip self and parent */ - } + num++; } diff --git a/components/ram.c b/components/ram.c index 518c18c..326153f 100644 --- a/components/ram.c +++ b/components/ram.c @@ -16,9 +16,8 @@ "MemTotal: %ju kB\n" "MemFree: %ju kB\n" "MemAvailable: %ju kB\n", - &free, &free, &free) != 3) { + &free, &free, &free) != 3) return NULL; - } return fmt_human(free * 1024, 1024); } @@ -35,13 +34,11 @@ "MemAvailable: %ju kB\n" "Buffers: %ju kB\n" "Cached: %ju kB\n", - &total, &free, &buffers, &buffers, &cached) != 5) { + &total, &free, &buffers, &buffers, &cached) != 5) return NULL; - } - if (total == 0) { + if (total == 0) return NULL; - } percent = 100 * ((total - free) - (buffers + cached)) / total; return bprintf("%d", percent); @@ -53,9 +50,8 @@ uintmax_t total; if (pscanf("/proc/meminfo", "MemTotal: %ju kB\n", &total) - != 1) { + != 1) return NULL; - } return fmt_human(total * 1024, 1024); } @@ -94,9 +90,8 @@ size = sizeof(*uvmexp); - if (sysctl(uvmexp_mib, 2, uvmexp, &size, NULL, 0) >= 0) { + if (sysctl(uvmexp_mib, 2, uvmexp, &size, NULL, 0) >= 0) return 1; - } return 0; } diff --git a/components/run_command.c b/components/run_command.c index 942f3c4..93bf6da 100644 --- a/components/run_command.c +++ b/components/run_command.c @@ -15,17 +15,17 @@ run_command(const char *cmd) warn("popen '%s':", cmd); return NULL; } + p = fgets(buf, sizeof(buf) - 1, fp); if (pclose(fp) < 0) { warn("pclose '%s':", cmd); return NULL; } - if (!p) { + if (!p) return NULL; - } - if ((p = strrchr(buf, '\n'))) { + + if ((p = strrchr(buf, '\n'))) p[0] = '\0'; - } return buf[0] ? buf : NULL; } diff --git a/components/swap.c b/components/swap.c index af05e01..6ae0542 100644 --- a/components/swap.c +++ b/components/swap.c @@ -25,11 +25,9 @@ char *line = NULL; /* get number of fields we want to extract */ - for (i = 0, left = 0; i < LEN(ent); i++) { - if (ent[i].var) { + for (i = 0, left = 0; i < LEN(ent); i++) + if (ent[i].var) left++; - } - } if (!(fp = fopen("/proc/meminfo", "r"))) { warn("fopen '/proc/meminfo':"); @@ -63,9 +61,8 @@ { long free; - if (get_swap_info(NULL, &free, NULL)) { + if (get_swap_info(NULL, &free, NULL)) return NULL; - } return fmt_human(free * 1024, 1024); } @@ -75,9 +72,8 @@ { long total, free, cached; - if (get_swap_info(&total, &free, &cached) || total == 0) { + if (get_swap_info(&total, &free, &cached) || total == 0) return NULL; - } return bprintf("%d", 100 * (total - free - cached) / total); } @@ -87,9 +83,8 @@ { long total; - if (get_swap_info(&total, NULL, NULL)) { + if (get_swap_info(&total, NULL, NULL)) return NULL; - } return fmt_human(total * 1024, 1024); } @@ -99,9 +94,8 @@ { long total, free, cached; - if (get_swap_info(&total, &free, &cached)) { + if (get_swap_info(&total, &free, &cached)) return NULL; - } return fmt_human((total - free - cached) * 1024, 1024); } @@ -152,9 +146,8 @@ { int total, used; - if (getstats(&total, &used)) { + if (getstats(&total, &used)) return NULL; - } return fmt_human((total - used) * 1024, 1024); } @@ -164,13 +157,11 @@ { int total, used; - if (getstats(&total, &used)) { + if (getstats(&total, &used)) return NULL; - } - if (total == 0) { + if (total == 0) return NULL; - } return bprintf("%d", 100 * used / total); } @@ -180,9 +171,8 @@ { int total, used; - if (getstats(&total, &used)) { + if (getstats(&total, &used)) return NULL; - } return fmt_human(total * 1024, 1024); } @@ -192,9 +182,8 @@ { int total, used; - if (getstats(&total, &used)) { + if (getstats(&total, &used)) return NULL; - } return fmt_human(used * 1024, 1024); } diff --git a/components/temperature.c b/components/temperature.c index c61a574..7cf1394 100644 --- a/components/temperature.c +++ b/components/temperature.c @@ -13,9 +13,8 @@ { uintmax_t temp; - if (pscanf(file, "%ju", &temp) != 1) { + if (pscanf(file, "%ju", &temp) != 1) return NULL; - } return bprintf("%ju", temp / 1000); } diff --git a/components/wifi.c b/components/wifi.c index a20e8d4..4543d32 100644 --- a/components/wifi.c +++ b/components/wifi.c @@ -38,27 +38,24 @@ } p = fgets(status, 5, fp); fclose(fp); - if (!p || strcmp(status, "up\n") != 0) { + if (!p || strcmp(status, "up\n") != 0) return NULL; - } if (!(fp = fopen("/proc/net/wireless", "r"))) { warn("fopen '/proc/net/wireless':"); return NULL; } - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) if (!(p = fgets(buf, sizeof(buf) - 1, fp))) break; - } - fclose(fp); - if (i < 2 || !p) { - return NULL; - } - if (!(datastart = strstr(buf, interface))) { + fclose(fp); + if (i < 2 || !p) + return NULL; + + if (!(datastart = strstr(buf, interface))) return NULL; - } datastart = (datastart+(strlen(interface)+1)); sscanf(datastart + 1, " %*d %d %*d %*d\t\t %*d\t " @@ -78,9 +75,8 @@ memset(&wreq, 0, sizeof(struct iwreq)); wreq.u.essid.length = IW_ESSID_MAX_SIZE+1; if (esnprintf(wreq.ifr_name, sizeof(wreq.ifr_name), "%s", - interface) < 0) { + interface) < 0) return NULL; - } if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { warn("socket 'AF_INET':"); @@ -95,9 +91,8 @@ close(sockfd); - if (!strcmp(id, "")) { + if (!strcmp(id, "")) return NULL; - } return id; } @@ -153,11 +148,11 @@ int q; if (load_ieee80211_nodereq(interface, &nr)) { - if (nr.nr_max_rssi) { + if (nr.nr_max_rssi) q = IEEE80211_NODEREQ_RSSI(&nr); - } else { + else q = RSSI_TO_PERC(nr.nr_rssi); - } + return bprintf("%d", q); } @@ -169,9 +164,8 @@ { struct ieee80211_nodereq nr; - if (load_ieee80211_nodereq(interface, &nr)) { + if (load_ieee80211_nodereq(interface, &nr)) return bprintf("%s", nr.nr_nwid); - } return NULL; } diff --git a/slstatus.c b/slstatus.c index a8ac28e..cb54f29 100644 --- a/slstatus.c +++ b/slstatus.c @@ -66,9 +66,8 @@ main(int argc, char *argv[]) usage(); } ARGEND - if (argc) { + if (argc) usage(); - } memset(&act, 0, sizeof(act)); act.sa_handler = terminate; @@ -77,24 +76,22 @@ main(int argc, char *argv[]) act.sa_flags |= SA_RESTART; sigaction(SIGUSR1, &act, NULL); - if (!sflag && !(dpy = XOpenDisplay(NULL))) { + if (!sflag && !(dpy = XOpenDisplay(NULL))) die("XOpenDisplay: Failed to open display"); - } do { - if (clock_gettime(CLOCK_MONOTONIC, &start) < 0) { + if (clock_gettime(CLOCK_MONOTONIC, &start) < 0) die("clock_gettime:"); - } status[0] = '\0'; for (i = len = 0; i < LEN(args); i++) { - if (!(res = args[i].func(args[i].args))) { + if (!(res = args[i].func(args[i].args))) res = unknown_str; - } + if ((ret = esnprintf(status + len, sizeof(status) - len, - args[i].fmt, res)) < 0) { + args[i].fmt, res)) < 0) break; - } + len += ret; } @@ -104,37 +101,31 @@ main(int argc, char *argv[]) if (ferror(stdout)) die("puts:"); } else { - if (XStoreName(dpy, DefaultRootWindow(dpy), status) - < 0) { + if (XStoreName(dpy, DefaultRootWindow(dpy), status) < 0) die("XStoreName: Allocation failed"); - } XFlush(dpy); } if (!done) { - if (clock_gettime(CLOCK_MONOTONIC, ¤t) < 0) { + if (clock_gettime(CLOCK_MONOTONIC, ¤t) < 0) die("clock_gettime:"); - } difftimespec(&diff, ¤t, &start); intspec.tv_sec = interval / 1000; intspec.tv_nsec = (interval % 1000) * 1E6; difftimespec(&wait, &intspec, &diff); - if (wait.tv_sec >= 0) { - if (nanosleep(&wait, NULL) < 0 && - errno != EINTR) { + if (wait.tv_sec >= 0 && + nanosleep(&wait, NULL) < 0 && + errno != EINTR) die("nanosleep:"); - } - } } } while (!done); if (!sflag) { XStoreName(dpy, DefaultRootWindow(dpy), NULL); - if (XCloseDisplay(dpy) < 0) { + if (XCloseDisplay(dpy) < 0) die("XCloseDisplay: Failed to close display"); - } } return 0; diff --git a/util.c b/util.c index 85366bf..d1f6077 100644 --- a/util.c +++ b/util.c @@ -13,9 +13,8 @@ char *argv0; static void verr(const char *fmt, va_list ap) { - if (argv0 && strncmp(fmt, "usage", sizeof("usage") - 1)) { + if (argv0 && strncmp(fmt, "usage", sizeof("usage") - 1)) fprintf(stderr, "%s: ", argv0); - } vfprintf(stderr, fmt, ap); @@ -119,9 +118,8 @@ fmt_human(uintmax_t num, int base) } scaled = num; - for (i = 0; i < prefixlen && scaled >= base; i++) { + for (i = 0; i < prefixlen && scaled >= base; i++) scaled /= base; - } return bprintf("%.1f %s", scaled, prefix[i]); } From cce2e5ecb05cdf68831fbf44c5ab90f4e16364b3 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Fri, 28 Oct 2022 00:21:02 +0200 Subject: [PATCH 19/43] radical re-formatting 3/3: Error checks Check for `< 0` instead of `== -1`. Fixes coding style. Formatting commits suck, incoherent coding style sucks more. https://suckless.org/coding_style/ --- components/cpu.c | 6 ++---- components/netspeeds.c | 4 ++-- components/ram.c | 20 ++++++++++---------- components/swap.c | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/components/cpu.c b/components/cpu.c index 10d25c0..d0d03c7 100644 --- a/components/cpu.c +++ b/components/cpu.c @@ -118,8 +118,7 @@ size = sizeof(freq); /* in MHz */ - if (sysctlbyname("hw.clockrate", &freq, &size, NULL, 0) == -1 - || !size) { + if (sysctlbyname("hw.clockrate", &freq, &size, NULL, 0) < 0 || !size) { warn("sysctlbyname 'hw.clockrate':"); return NULL; } @@ -136,8 +135,7 @@ size = sizeof(a); memcpy(b, a, sizeof(b)); - if (sysctlbyname("kern.cp_time", &a, &size, NULL, 0) == -1 - || !size) { + if (sysctlbyname("kern.cp_time", &a, &size, NULL, 0) < 0 || !size) { warn("sysctlbyname 'kern.cp_time':"); return NULL; } diff --git a/components/netspeeds.c b/components/netspeeds.c index 97e565b..cde6fa9 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -71,7 +71,7 @@ oldrxbytes = rxbytes; - if (getifaddrs(&ifal) == -1) { + if (getifaddrs(&ifal) < 0) { warn("getifaddrs failed"); return NULL; } @@ -105,7 +105,7 @@ oldtxbytes = txbytes; - if (getifaddrs(&ifal) == -1) { + if (getifaddrs(&ifal) < 0) { warn("getifaddrs failed"); return NULL; } diff --git a/components/ram.c b/components/ram.c index 326153f..15c4b74 100644 --- a/components/ram.c +++ b/components/ram.c @@ -159,8 +159,8 @@ size_t len; len = sizeof(struct vmtotal); - if (sysctl(mib, 2, &vm_stats, &len, NULL, 0) == -1 - || !len) + if (sysctl(mib, 2, &vm_stats, &len, NULL, 0) < 0 + || !len) return NULL; return fmt_human(vm_stats.t_free * getpagesize(), 1024); @@ -172,8 +172,8 @@ size_t len; len = sizeof(npages); - if (sysctlbyname("vm.stats.vm.v_page_count", &npages, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname("vm.stats.vm.v_page_count", + &npages, &len, NULL, 0) < 0 || !len) return NULL; return fmt_human(npages * getpagesize(), 1024); @@ -186,12 +186,12 @@ size_t len; len = sizeof(npages); - if (sysctlbyname("vm.stats.vm.v_page_count", &npages, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname("vm.stats.vm.v_page_count", + &npages, &len, NULL, 0) < 0 || !len) return NULL; - if (sysctlbyname("vm.stats.vm.v_active_count", &active, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname("vm.stats.vm.v_active_count", + &active, &len, NULL, 0) < 0 || !len) return NULL; return bprintf("%d", active * 100 / npages); @@ -203,8 +203,8 @@ size_t len; len = sizeof(active); - if (sysctlbyname("vm.stats.vm.v_active_count", &active, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname("vm.stats.vm.v_active_count", + &active, &len, NULL, 0) < 0 || !len) return NULL; return fmt_human(active * getpagesize(), 1024); diff --git a/components/swap.c b/components/swap.c index 6ae0542..f270d93 100644 --- a/components/swap.c +++ b/components/swap.c @@ -204,7 +204,7 @@ return 0; } - if(kvm_getswapinfo(kd, swap_info, size, 0 /* Unused flags */) == -1) { + if (kvm_getswapinfo(kd, swap_info, size, 0 /* Unused flags */) < 0) { warn("kvm_getswapinfo:"); kvm_close(kd); return 0; From 4bd78c94ba90d67a268c092231b85037c94a339a Mon Sep 17 00:00:00 2001 From: drkhsh Date: Fri, 28 Oct 2022 00:47:06 +0200 Subject: [PATCH 20/43] README: Add note about FreeBSD sndio dep --- README | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README b/README index cebad30..4da0756 100644 --- a/README +++ b/README @@ -35,8 +35,9 @@ Requirements Currently slstatus works on FreeBSD, Linux and OpenBSD. In order to build slstatus you need the Xlib header files. -For volume percentage on Linux the kernel module `snd-mixer-oss` must be -loaded. +- For volume percentage on Linux the kernel module `snd-mixer-oss` must be + loaded. +- For volume percentage on FreeBSD, `sndio` must be installed. Installation From 57c6e7340d16b14d61f9e3361ca4940f53dfcafa Mon Sep 17 00:00:00 2001 From: drkhsh Date: Wed, 23 Nov 2022 23:59:51 +0100 Subject: [PATCH 21/43] New component: cat Generically reads an arbitrary file natively. Saves a few layers of execution in comparison to using `run_command` with an argument like `cat ./file`. --- Makefile | 1 + README | 1 + components/cat.c | 32 ++++++++++++++++++++++++++++++++ config.def.h | 1 + slstatus.h | 3 +++ 5 files changed, 38 insertions(+) create mode 100644 components/cat.c diff --git a/Makefile b/Makefile index 3be46cc..7834257 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ include config.mk REQ = util COM =\ components/battery\ + components/cat\ components/cpu\ components/datetime\ components/disk\ diff --git a/README b/README index 4da0756..b3fa7ae 100644 --- a/README +++ b/README @@ -7,6 +7,7 @@ slstatus is a suckless status monitor for window managers that use WM_NAME Features -------- - Battery percentage/state/time left +- Cat (read file) - CPU usage - CPU frequency - Custom shell commands diff --git a/components/cat.c b/components/cat.c new file mode 100644 index 0000000..07944cc --- /dev/null +++ b/components/cat.c @@ -0,0 +1,32 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include + +#include "../slstatus.h" +#include "../util.h" + +const char * +cat(const char *path) +{ + char *f; + FILE *fp; + + if (!(fp = fopen(path, "r"))) { + warn("fopen '%s':", path); + return NULL; + } + + f = fgets(buf, sizeof(buf) - 1, fp); + if (fclose(fp) < 0) { + warn("fclose '%s':", path); + return NULL; + } + if (!f) + return NULL; + + if ((f = strrchr(buf, '\n'))) + f[0] = '\0'; + + return buf[0] ? buf : NULL; +} + diff --git a/config.def.h b/config.def.h index 5f6c114..90b57a1 100644 --- a/config.def.h +++ b/config.def.h @@ -18,6 +18,7 @@ static const char unknown_str[] = "n/a"; * NULL on OpenBSD/FreeBSD * battery_remaining battery remaining HH:MM battery name (BAT0) * NULL on OpenBSD/FreeBSD + * cat read arbitrary file path * cpu_perc cpu usage in percent NULL * cpu_freq cpu frequency in MHz NULL * datetime date and time format string (%F %T) diff --git a/slstatus.h b/slstatus.h index f3b4979..f062e73 100644 --- a/slstatus.h +++ b/slstatus.h @@ -5,6 +5,9 @@ const char *battery_perc(const char *); const char *battery_state(const char *); const char *battery_remaining(const char *); +/* cat */ +const char *cat(const char *path); + /* cpu */ const char *cpu_freq(const char *unused); const char *cpu_perc(const char *unused); From 982eb223a055db01bf03f44bf0203705ca7153e8 Mon Sep 17 00:00:00 2001 From: Patrick Iacob Date: Sat, 26 Nov 2022 20:11:01 -0800 Subject: [PATCH 22/43] battery: Fix remaining on Linux The current version displays the remaining time as 'n/a'. Fixes this regression introduced in 69b2487650782f135db76078c4a7fb841cb936ac where current_now and power_now were incorrectly replaced with current and power when they were moved to a macro. --- components/battery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/battery.c b/components/battery.c index b12c59e..9fa1014 100644 --- a/components/battery.c +++ b/components/battery.c @@ -14,8 +14,8 @@ #define POWER_SUPPLY_STATUS "/sys/class/power_supply/%s/status" #define POWER_SUPPLY_CHARGE "/sys/class/power_supply/%s/charge_now" #define POWER_SUPPLY_ENERGY "/sys/class/power_supply/%s/energy_now" - #define POWER_SUPPLY_CURRENT "/sys/class/power_supply/%s/current" - #define POWER_SUPPLY_POWER "/sys/class/power_supply/%s/power" + #define POWER_SUPPLY_CURRENT "/sys/class/power_supply/%s/current_now" + #define POWER_SUPPLY_POWER "/sys/class/power_supply/%s/power_now" static const char * pick(const char *bat, const char *f1, const char *f2, char *path, From 173b03417d2a21a646c3d0d3d05ba158f9427139 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Mon, 19 Dec 2022 02:41:19 +0100 Subject: [PATCH 23/43] Update README --- README | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README b/README index b3fa7ae..7b50895 100644 --- a/README +++ b/README @@ -65,6 +65,5 @@ source code. This keeps it fast, secure and simple. Upcoming -------- - -A release (v1.0) will come soon... ;) -After a long phase of inactivity, development has been continued! +A first feature-complete release with official packages for common distributions +will come soon. From e22d447684d8b42731871de5b732669a822ddd1a Mon Sep 17 00:00:00 2001 From: planet36 Date: Fri, 5 Mar 2021 14:19:49 -0500 Subject: [PATCH 24/43] config.def.h: Remove stray double quote in comment Signed-off-by: drkhsh --- config.def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 90b57a1..2fc2557 100644 --- a/config.def.h +++ b/config.def.h @@ -24,7 +24,7 @@ static const char unknown_str[] = "n/a"; * datetime date and time format string (%F %T) * disk_free free disk space in GB mountpoint path (/) * disk_perc disk usage in percent mountpoint path (/) - * disk_total total disk space in GB mountpoint path (/") + * disk_total total disk space in GB mountpoint path (/) * disk_used used disk space in GB mountpoint path (/) * entropy available entropy NULL * gid GID of current user NULL From 0e2ff8dc1009dccab4d2e17ed53ba65c4e99450e Mon Sep 17 00:00:00 2001 From: planet36 Date: Fri, 5 Mar 2021 14:20:29 -0500 Subject: [PATCH 25/43] verr: Remove special "usage" case In function verr, remove special case for "usage" string Co-authored-by: drkhsh Signed-off-by: drkhsh --- util.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/util.c b/util.c index d1f6077..bca9b2e 100644 --- a/util.c +++ b/util.c @@ -13,9 +13,6 @@ char *argv0; static void verr(const char *fmt, va_list ap) { - if (argv0 && strncmp(fmt, "usage", sizeof("usage") - 1)) - fprintf(stderr, "%s: ", argv0); - vfprintf(stderr, fmt, ap); if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { From 89f8476110c7bdfb70528da79be328ba0f6490be Mon Sep 17 00:00:00 2001 From: planet36 Date: Fri, 5 Mar 2021 14:28:15 -0500 Subject: [PATCH 26/43] disk: Cast fsblkcnt_t to double instead of float Signed-off-by: drkhsh --- components/disk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/disk.c b/components/disk.c index 0d1c13e..e19a693 100644 --- a/components/disk.c +++ b/components/disk.c @@ -29,7 +29,7 @@ disk_perc(const char *path) } return bprintf("%d", (int)(100 * - (1.0f - ((float)fs.f_bavail / (float)fs.f_blocks)))); + (1 - ((double)fs.f_bavail / (double)fs.f_blocks)))); } const char * From c75cb9ad7af55d16b864b1059fbc1aaa9d9874de Mon Sep 17 00:00:00 2001 From: planet36 Date: Fri, 5 Mar 2021 14:35:24 -0500 Subject: [PATCH 27/43] keymap: Variable "layout" should be const Signed-off-by: drkhsh --- components/keymap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/keymap.c b/components/keymap.c index 4740431..f8a2a47 100644 --- a/components/keymap.c +++ b/components/keymap.c @@ -50,7 +50,8 @@ keymap(const char *unused) Display *dpy; XkbDescRec *desc; XkbStateRec state; - char *symbols, *layout; + char *symbols; + const char *layout; layout = NULL; @@ -74,7 +75,7 @@ keymap(const char *unused) warn("XGetAtomName: Failed to get atom name"); goto end; } - layout = (char *)bprintf("%s", get_layout(symbols, state.group)); + layout = bprintf("%s", get_layout(symbols, state.group)); XFree(symbols); end: XkbFreeKeyboard(desc, XkbSymbolsNameMask, 1); From 40f13be551f0e1a0eaee07dcb64b3b6ab3a68dd9 Mon Sep 17 00:00:00 2001 From: planet36 Date: Thu, 25 Mar 2021 13:05:48 -0400 Subject: [PATCH 28/43] uptime: Use sizeof instead of repeating the size Signed-off-by: drkhsh --- components/uptime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/uptime.c b/components/uptime.c index d97e5e8..6227f73 100644 --- a/components/uptime.c +++ b/components/uptime.c @@ -22,7 +22,7 @@ uptime(const char *unused) struct timespec uptime; if (clock_gettime(UPTIME_FLAG, &uptime) < 0) { - snprintf(warn_buf, 256, "clock_gettime %d", UPTIME_FLAG); + snprintf(warn_buf, sizeof(warn_buf), "clock_gettime %d", UPTIME_FLAG); warn(warn_buf); return NULL; } From d77f216faea5566ba8ebdbf1456c5e6806d2eeb5 Mon Sep 17 00:00:00 2001 From: planet36 Date: Fri, 2 Apr 2021 14:11:00 -0400 Subject: [PATCH 29/43] Sort functions by name Co-authored-by: drkhsh Signed-off-by: drkhsh --- config.def.h | 8 ++++---- slstatus.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config.def.h b/config.def.h index 2fc2557..d805331 100644 --- a/config.def.h +++ b/config.def.h @@ -14,13 +14,13 @@ static const char unknown_str[] = "n/a"; * * battery_perc battery percentage battery name (BAT0) * NULL on OpenBSD/FreeBSD - * battery_state battery charging state battery name (BAT0) - * NULL on OpenBSD/FreeBSD * battery_remaining battery remaining HH:MM battery name (BAT0) * NULL on OpenBSD/FreeBSD + * battery_state battery charging state battery name (BAT0) + * NULL on OpenBSD/FreeBSD * cat read arbitrary file path - * cpu_perc cpu usage in percent NULL * cpu_freq cpu frequency in MHz NULL + * cpu_perc cpu usage in percent NULL * datetime date and time format string (%F %T) * disk_free free disk space in GB mountpoint path (/) * disk_perc disk usage in percent mountpoint path (/) @@ -60,8 +60,8 @@ static const char unknown_str[] = "n/a"; * username username of current user NULL * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) * NULL on OpenBSD/FreeBSD - * wifi_perc WiFi signal in percent interface name (wlan0) * wifi_essid WiFi ESSID interface name (wlan0) + * wifi_perc WiFi signal in percent interface name (wlan0) */ static const struct arg args[] = { /* function format argument */ diff --git a/slstatus.h b/slstatus.h index f062e73..8ef5874 100644 --- a/slstatus.h +++ b/slstatus.h @@ -2,8 +2,8 @@ /* battery */ const char *battery_perc(const char *); -const char *battery_state(const char *); const char *battery_remaining(const char *); +const char *battery_state(const char *); /* cat */ const char *cat(const char *path); @@ -73,12 +73,12 @@ const char *uptime(const char *unused); /* user */ const char *gid(const char *unused); -const char *username(const char *unused); const char *uid(const char *unused); +const char *username(const char *unused); /* volume */ const char *vol_perc(const char *card); /* wifi */ -const char *wifi_perc(const char *interface); const char *wifi_essid(const char *interface); +const char *wifi_perc(const char *interface); From 87c3dd2c36e6d1df577e87fd4d73970fe58a3007 Mon Sep 17 00:00:00 2001 From: planet36 Date: Tue, 6 Apr 2021 12:48:18 -0400 Subject: [PATCH 30/43] battery: Consistent naming for capacity percentage https://www.kernel.org/doc/html/latest/power/power_supply_class.html Co-authored-by: drkhsh Signed-off-by: drkhsh --- components/battery.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/components/battery.c b/components/battery.c index 9fa1014..1c753f9 100644 --- a/components/battery.c +++ b/components/battery.c @@ -6,6 +6,9 @@ #include "../util.h" #if defined(__linux__) +/* + * https://www.kernel.org/doc/html/latest/power/power_supply_class.html + */ #include #include #include @@ -35,15 +38,15 @@ const char * battery_perc(const char *bat) { - int perc; + int cap_perc; char path[PATH_MAX]; if (esnprintf(path, sizeof(path), POWER_SUPPLY_CAPACITY, bat) < 0) return NULL; - if (pscanf(path, "%d", &perc) != 1) + if (pscanf(path, "%d", &cap_perc) != 1) return NULL; - return bprintf("%d", perc); + return bprintf("%d", cap_perc); } const char * @@ -197,14 +200,14 @@ const char * battery_perc(const char *unused) { - int cap; + int cap_perc; size_t len; - len = sizeof(cap); - if (sysctlbyname(BATTERY_LIFE, &cap, &len, NULL, 0) < 0 || !len) + len = sizeof(cap_perc); + if (sysctlbyname(BATTERY_LIFE, &cap_perc, &len, NULL, 0) < 0 || !len) return NULL; - return bprintf("%d", cap); + return bprintf("%d", cap_perc); } const char * From c432c981df97f786c683435a4a06bd58fc9a7b18 Mon Sep 17 00:00:00 2001 From: planet36 Date: Tue, 13 Apr 2021 12:43:18 -0400 Subject: [PATCH 31/43] Make LEN macro consistent with other suckless repos Signed-off-by: drkhsh --- util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util.h b/util.h index 7f1f26c..cf4b027 100644 --- a/util.h +++ b/util.h @@ -3,7 +3,7 @@ extern char buf[1024]; -#define LEN(x) (sizeof (x) / sizeof *(x)) +#define LEN(x) (sizeof(x) / sizeof((x)[0])) extern char *argv0; From 984f45719e8ac9f4451c2d009fb34e28afdfbdb6 Mon Sep 17 00:00:00 2001 From: planet36 Date: Tue, 11 May 2021 22:45:34 -0400 Subject: [PATCH 32/43] num_files: opendir() returns a directory stream opendir() returns a directory stream, not a file descriptor Co-authored-by: drkhsh Signed-off-by: drkhsh --- components/num_files.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/num_files.c b/components/num_files.c index e4b4281..df0acd1 100644 --- a/components/num_files.c +++ b/components/num_files.c @@ -10,23 +10,23 @@ const char * num_files(const char *path) { struct dirent *dp; - DIR *fd; + DIR *dir; int num; - if (!(fd = opendir(path))) { + if (!(dir = opendir(path))) { warn("opendir '%s':", path); return NULL; } num = 0; - while ((dp = readdir(fd))) { + while ((dp = readdir(dir))) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; /* skip self and parent */ num++; } - closedir(fd); + closedir(dir); return bprintf("%d", num); } From c225c4315161a992b9e44dd990d083ee57f7f713 Mon Sep 17 00:00:00 2001 From: planet36 Date: Wed, 26 May 2021 14:29:32 -0400 Subject: [PATCH 33/43] config.mk: Fix PREFIX assignment Signed-off-by: drkhsh --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index ead1859..8f06800 100644 --- a/config.mk +++ b/config.mk @@ -4,7 +4,7 @@ VERSION = 0 # customize below to fit your system # paths -PREFIX = /usr/local +PREFIX ?= /usr/local MANPREFIX = $(PREFIX)/share/man X11INC = /usr/X11R6/include From 581d937e51d10e6e74868d2397081b12952eae07 Mon Sep 17 00:00:00 2001 From: planet36 Date: Fri, 28 Oct 2022 10:49:05 -0500 Subject: [PATCH 34/43] entropy: Use Unicode escape sequence in string Signed-off-by: drkhsh --- components/entropy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/entropy.c b/components/entropy.c index 66b2e5a..65010b0 100644 --- a/components/entropy.c +++ b/components/entropy.c @@ -22,7 +22,8 @@ const char * entropy(const char *unused) { + // https://www.unicode.org/charts/PDF/U2200.pdf /* Unicode Character 'INFINITY' (U+221E) */ - return "\xe2\x88\x9e"; + return "\u221E"; } #endif From 1ae616190cb3f88221571343a284fdf9f55b683f Mon Sep 17 00:00:00 2001 From: drkhsh Date: Mon, 19 Dec 2022 02:40:00 +0100 Subject: [PATCH 35/43] Update LICENSE --- LICENSE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LICENSE b/LICENSE index 70b9fb3..b7e3aa6 100644 --- a/LICENSE +++ b/LICENSE @@ -27,6 +27,8 @@ Copyright 2020 Alexandre Ratchov Copyright 2020 Mart Lubbers Copyright 2020 Daniel Moch Copyright 2022 NRK +Copyright 2022 Patrick Iacob +Copyright 2021-2022 planet36 Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above From 305aa5138add5971456c880219fe859cd4189624 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Mon, 19 Dec 2022 19:26:15 +0100 Subject: [PATCH 36/43] Update LICENSE Real names should be used if possible, as the license is legally binding --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index b7e3aa6..570f450 100644 --- a/LICENSE +++ b/LICENSE @@ -28,7 +28,7 @@ Copyright 2020 Mart Lubbers Copyright 2020 Daniel Moch Copyright 2022 NRK Copyright 2022 Patrick Iacob -Copyright 2021-2022 planet36 +Copyright 2021-2022 Steven Ward Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above From 034c591a95feec885208266a6849c04289a9c4a5 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Mon, 19 Dec 2022 19:26:57 +0100 Subject: [PATCH 37/43] Revert "config.mk: Fix PREFIX assignment" "?=" is not POSIX, packagers should use "make PREFIX=". This reverts commit c225c4315161a992b9e44dd990d083ee57f7f713. --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index 8f06800..ead1859 100644 --- a/config.mk +++ b/config.mk @@ -4,7 +4,7 @@ VERSION = 0 # customize below to fit your system # paths -PREFIX ?= /usr/local +PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man X11INC = /usr/X11R6/include From c919def84fd4f52f501548e5f7705b9d56dd1459 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Mon, 19 Dec 2022 22:03:59 +0100 Subject: [PATCH 38/43] More LICENSE updates Regarding 305aa5138add5971456c880219fe859cd4189624 --- LICENSE | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 570f450..8bee9c8 100644 --- a/LICENSE +++ b/LICENSE @@ -9,7 +9,7 @@ Copyright 2016-2018 Ali H. Fardan Copyright 2016 Jody Leonard Copyright 2016-2018 Quentin Rameau Copyright 2016 Mike Coddington -Copyright 2016-2018 parazyd +Copyright 2016-2018 Ivan J. Copyright 2017 Tobias Stoeckmann Copyright 2017-2018 Laslo Hunhold Copyright 2018 Darron Anderson @@ -21,14 +21,14 @@ Copyright 2018 Ian Remmler Copyright 2016-2019 Joerg Jung Copyright 2019 Ryan Kes Copyright 2019 Cem Keylan -Copyright 2019 dsp +Copyright 2019 Dimitris Papastamos Copyright 2019-2022 Ingo Feinerer Copyright 2020 Alexandre Ratchov Copyright 2020 Mart Lubbers Copyright 2020 Daniel Moch -Copyright 2022 NRK +Copyright 2022 Nickolas Raymond Kaczynski Copyright 2022 Patrick Iacob -Copyright 2021-2022 Steven Ward +Copyright 2021-2022 Steven Ward Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above From ee586cfea9c328932255512077882fa8194b50c2 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Sun, 23 Apr 2023 23:43:14 +0200 Subject: [PATCH 39/43] manpage: Quality improvements Adds signals section to the manpage and generally improves contents and wording --- slstatus.1 | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/slstatus.1 b/slstatus.1 index d802037..bea2a8c 100644 --- a/slstatus.1 +++ b/slstatus.1 @@ -1,17 +1,22 @@ -.Dd 2020-06-23 +.Dd 2023-04-23 .Dt SLSTATUS 1 .Os .Sh NAME .Nm slstatus -.Nd suckless status monitor +.Nd suckless status .Sh SYNOPSIS .Nm .Op Fl s .Op Fl 1 .Sh DESCRIPTION .Nm -is a suckless status monitor for window managers that use WM_NAME (e.g. dwm) or -stdin to fill the status bar. +is a small tool for providing system status information to other programs +over the EWMH +.Em WM_NAME +property of the root window (used by +.Xr dwm 1 ) or standard input/output. It is designed to be as efficient as possible by +only issuing the minimum of system calls required. +.P By default, .Nm outputs to WM_NAME. @@ -26,3 +31,15 @@ Write once to stdout and quit. .Nm can be customized by creating a custom config.h and (re)compiling the source code. This keeps it fast, secure and simple. +.Sh SIGNALS +.Nm +responds to the following signals: +.Pp +.Bl -tag -width TERM -compact +.It USR1 +Triggers an instant redraw. +.El +.Sh AUTHORS +See the LICENSE file for the authors. +.Sh SEE ALSO +.Xr dwm 1 From e0c155e9ab8e8e0cf0ae09dc8cd0a02a460628cf Mon Sep 17 00:00:00 2001 From: drkhsh Date: Sun, 23 Apr 2023 23:48:47 +0200 Subject: [PATCH 40/43] README: Sync description from manpage --- README | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README b/README index 7b50895..a65f4cd 100644 --- a/README +++ b/README @@ -1,7 +1,9 @@ slstatus - suckless status ========================== -slstatus is a suckless status monitor for window managers that use WM_NAME -(e.g. dwm) or stdin to fill the status bar. +slstatus is a small tool for providing system status information to other +programs over the EWMH property of the root window (used by dwm(1)) or +standard input/output. It is designed to be as efficient as possible by +only issuing the minimum of system calls required. Features From 483169021ba996f59a97b4e3b74cee7e43d6ab6f Mon Sep 17 00:00:00 2001 From: drkhsh Date: Mon, 15 May 2023 19:11:39 +0200 Subject: [PATCH 41/43] Fix release tarball to prepare for release Correctly copies components to sub-directory, adds all required files --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7834257..7a18274 100644 --- a/Makefile +++ b/Makefile @@ -44,14 +44,15 @@ slstatus: slstatus.o $(COM:=.o) $(REQ:=.o) $(CC) -o $@ $(LDFLAGS) $(COM:=.o) $(REQ:=.o) slstatus.o $(LDLIBS) clean: - rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o) + rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o) slstatus-${VERSION}.tar.gz dist: rm -rf "slstatus-$(VERSION)" mkdir -p "slstatus-$(VERSION)/components" cp -R LICENSE Makefile README config.mk config.def.h \ - arg.h slstatus.c $(COM:=.c) $(REQ:=.c) $(REQ:=.h) \ + arg.h slstatus.h slstatus.c $(REQ:=.c) $(REQ:=.h) \ slstatus.1 "slstatus-$(VERSION)" + cp -R $(COM:=.c) "slstatus-$(VERSION)/components" tar -cf - "slstatus-$(VERSION)" | gzip -c > "slstatus-$(VERSION).tar.gz" rm -rf "slstatus-$(VERSION)" From 86c7a84c2397e5bbdcebe2a06bada7ee48f0d480 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Mon, 15 May 2023 19:14:52 +0200 Subject: [PATCH 42/43] Add back version flag to prepare for release --- config.mk | 2 +- slstatus.1 | 2 ++ slstatus.c | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config.mk b/config.mk index ead1859..2ba2911 100644 --- a/config.mk +++ b/config.mk @@ -11,7 +11,7 @@ X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib # flags -CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE +CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE -DVERSION=\"${VERSION}\" CFLAGS = -std=c99 -pedantic -Wall -Wextra -Wno-unused-parameter -Os LDFLAGS = -L$(X11LIB) -s # OpenBSD: add -lsndio diff --git a/slstatus.1 b/slstatus.1 index bea2a8c..73e7a60 100644 --- a/slstatus.1 +++ b/slstatus.1 @@ -22,6 +22,8 @@ By default, outputs to WM_NAME. .Sh OPTIONS .Bl -tag -width Ds +.It Fl v +Print version information to stderr, then exit. .It Fl s Write to stdout instead of WM_NAME. .It Fl 1 diff --git a/slstatus.c b/slstatus.c index cb54f29..fd31313 100644 --- a/slstatus.c +++ b/slstatus.c @@ -41,7 +41,7 @@ difftimespec(struct timespec *res, struct timespec *a, struct timespec *b) static void usage(void) { - die("usage: %s [-s] [-1]", argv0); + die("usage: %s [-v] [-s] [-1]", argv0); } int @@ -56,6 +56,8 @@ main(int argc, char *argv[]) sflag = 0; ARGBEGIN { + case 'v': + die("slstatus-"VERSION); case '1': done = 1; /* FALLTHROUGH */ From f68f49273e70b3767b30c549dda04ddd4d25fc91 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Tue, 4 Jul 2023 20:47:18 +0200 Subject: [PATCH 43/43] Release stable 1.0 version --- README | 6 ------ config.mk | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/README b/README index a65f4cd..12d38bf 100644 --- a/README +++ b/README @@ -63,9 +63,3 @@ Configuration ------------- slstatus can be customized by creating a custom config.h and (re)compiling the source code. This keeps it fast, secure and simple. - - -Upcoming --------- -A first feature-complete release with official packages for common distributions -will come soon. diff --git a/config.mk b/config.mk index 2ba2911..07af883 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # slstatus version -VERSION = 0 +VERSION = 1.0 # customize below to fit your system