From 5f45160b65b733ab76eb8456b1756adc303174a2 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Wed, 22 Nov 2023 15:41:31 +0530 Subject: [PATCH 01/10] fix: Fix command-line argument parsing order --- src/cli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli.c b/src/cli.c index 5aa7df3..1a48863 100644 --- a/src/cli.c +++ b/src/cli.c @@ -15,11 +15,11 @@ int cli_init(cli_arguments *const args, const char *const argv[], case 'd': args->is_debug_mode = true; break; - case 'h': - // fall through case '?': (void)fprintf(stderr, "error: unknown option `-%c'\n", optopt); // fall through + case 'h': + // fall through default: (void)fprintf(stderr, "usage: %s [-d]\n", BINARY); return 1; From 56e6e2ef64ecd33dab2d3ac97a0c37d9192cdc58 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Wed, 22 Nov 2023 12:59:59 +0100 Subject: [PATCH 02/10] fix: Rename headers to allow compilation against musl libc tidy: Format includes --- include/block.h | 2 +- include/signal-handler.h | 2 +- include/watcher.h | 2 +- src/block.c | 3 +-- src/signal-handler.c | 3 +-- src/watcher.c | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/block.h b/include/block.h index bb87bcb..f1c9aff 100644 --- a/include/block.h +++ b/include/block.h @@ -1,8 +1,8 @@ #ifndef BLOCK_H #define BLOCK_H -#include #include +#include #include #include "config.h" diff --git a/include/signal-handler.h b/include/signal-handler.h index dc70433..da2d471 100644 --- a/include/signal-handler.h +++ b/include/signal-handler.h @@ -1,7 +1,7 @@ #ifndef SIGNAL_HANDLER_H #define SIGNAL_HANDLER_H -#include +#include #include "block.h" #include "timer.h" diff --git a/include/watcher.h b/include/watcher.h index 63d3283..ff31809 100644 --- a/include/watcher.h +++ b/include/watcher.h @@ -1,8 +1,8 @@ #ifndef WATCHER_H #define WATCHER_H +#include #include -#include #include "block.h" #include "main.h" diff --git a/src/block.c b/src/block.c index c232d43..5020b02 100644 --- a/src/block.c +++ b/src/block.c @@ -1,9 +1,8 @@ #include "block.h" -#include -#include #include #include +#include #include #include #include diff --git a/src/signal-handler.c b/src/signal-handler.c index f4f5c86..d816dcd 100644 --- a/src/signal-handler.c +++ b/src/signal-handler.c @@ -1,8 +1,7 @@ #include "signal-handler.h" -#include -#include #include +#include #include #include #include diff --git a/src/watcher.c b/src/watcher.c index 972559a..71b6c52 100644 --- a/src/watcher.c +++ b/src/watcher.c @@ -1,9 +1,9 @@ #include "watcher.h" #include +#include #include #include -#include #include "block.h" #include "util.h" From c42a4215c8dc3619f980d659ce3ff360f79dfbe2 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Wed, 22 Nov 2023 18:13:46 +0530 Subject: [PATCH 03/10] tidy: Remove unnecessary newline from Makefile --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index f68eff9..d7d7455 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,6 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c config.h $(PRINTF) "CC" $@ $Q$(COMPILE.c) -o $@ $< - $(BUILD_DIR)/$(BIN): $(OBJS) $(PRINTF) "LD" $@ $Q$(LINK.o) $^ $(LDLIBS) -o $@ From 12d4decdd45015b9b6f1ac50a2bd65c98695f1c3 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Tue, 19 Dec 2023 09:51:41 +0530 Subject: [PATCH 04/10] fix: Fix timer logic for blocks --- include/block.h | 1 - include/cli.h | 3 +-- include/timer.h | 2 ++ src/block.c | 12 ------------ src/cli.c | 15 +++++++++------ src/main.c | 11 ++++++----- src/timer.c | 21 ++++++++++++++++++--- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/include/block.h b/include/block.h index f1c9aff..555549c 100644 --- a/include/block.h +++ b/include/block.h @@ -24,6 +24,5 @@ int block_init(block *const block); int block_deinit(block *const block); int block_execute(block *const block, const uint8_t button); int block_update(block *const block); -bool block_must_run(const block *const block, const unsigned int time); #endif // BLOCK_H diff --git a/include/cli.h b/include/cli.h index 3d2d5a5..2f93f62 100644 --- a/include/cli.h +++ b/include/cli.h @@ -7,7 +7,6 @@ typedef struct { bool is_debug_mode; } cli_arguments; -int cli_init(cli_arguments* const args, const char* const argv[], - const int argc); +cli_arguments cli_parse_arguments(const char* const argv[], const int argc); #endif // CLI_H diff --git a/include/timer.h b/include/timer.h index eccf4a1..1ec7f75 100644 --- a/include/timer.h +++ b/include/timer.h @@ -2,6 +2,7 @@ #define TIMER_H #include +#include #include "block.h" @@ -15,5 +16,6 @@ typedef struct { timer timer_new(const block *const blocks, const unsigned short block_count); int timer_arm(timer *const timer); +bool timer_must_run_block(const timer *const timer, const block *const block); #endif // TIMER_H diff --git a/src/block.c b/src/block.c index 5020b02..0a73af6 100644 --- a/src/block.c +++ b/src/block.c @@ -144,15 +144,3 @@ int block_update(block *const block) { return 0; } - -bool block_must_run(const block *const block, const unsigned int time) { - if (time == 0) { - return true; - } - - if (block->interval == 0) { - return false; - } - - return time % block->interval == 0; -} diff --git a/src/cli.c b/src/cli.c index 1a48863..b1849ec 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1,19 +1,22 @@ #include "cli.h" +#include #include #include #include -int cli_init(cli_arguments *const args, const char *const argv[], - const int argc) { - args->is_debug_mode = false; +cli_arguments cli_parse_arguments(const char *const argv[], const int argc) { + errno = 0; + cli_arguments args = { + .is_debug_mode = false, + }; int opt = -1; opterr = 0; // Suppress getopt's built-in invalid opt message while ((opt = getopt(argc, (char *const *)argv, "dh")) != -1) { switch (opt) { case 'd': - args->is_debug_mode = true; + args.is_debug_mode = true; break; case '?': (void)fprintf(stderr, "error: unknown option `-%c'\n", optopt); @@ -22,9 +25,9 @@ int cli_init(cli_arguments *const args, const char *const argv[], // fall through default: (void)fprintf(stderr, "usage: %s [-d]\n", BINARY); - return 1; + errno = 1; } } - return 0; + return args; } diff --git a/src/main.c b/src/main.c index a858d88..4484f0a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,6 @@ #include "main.h" +#include #include #include @@ -38,10 +39,10 @@ static int deinit_blocks(block *const blocks, static int execute_blocks(block *const blocks, const unsigned short block_count, - const unsigned int time) { + const timer *const timer) { for (unsigned short i = 0; i < block_count; ++i) { block *const block = &blocks[i]; - if (!block_must_run(block, time)) { + if (!timer_must_run_block(timer, block)) { continue; } @@ -55,7 +56,7 @@ static int execute_blocks(block *const blocks, static int trigger_event(block *const blocks, const unsigned short block_count, timer *const timer) { - if (execute_blocks(blocks, block_count, timer->time) != 0) { + if (execute_blocks(blocks, block_count, timer) != 0) { return 1; } @@ -117,8 +118,8 @@ static int event_loop(block *const blocks, const unsigned short block_count, } int main(const int argc, const char *const argv[]) { - cli_arguments cli_args; - if (cli_init(&cli_args, argv, argc) != 0) { + const cli_arguments cli_args = cli_parse_arguments(argv, argc); + if (errno != 0) { return 1; } diff --git a/src/timer.c b/src/timer.c index a9a383c..2454fb9 100644 --- a/src/timer.c +++ b/src/timer.c @@ -1,6 +1,7 @@ #include "timer.h" #include +#include #include #include @@ -32,10 +33,12 @@ static unsigned int compute_reset_value(const block *const blocks, } timer timer_new(const block *const blocks, const unsigned short block_count) { + const unsigned int reset_value = compute_reset_value(blocks, block_count); + timer timer = { - .time = 0, + .time = reset_value, // Initial value to execute all blocks. .tick = compute_tick(blocks, block_count), - .reset_value = compute_reset_value(blocks, block_count), + .reset_value = reset_value, }; return timer; @@ -51,7 +54,19 @@ int timer_arm(timer *const timer) { } // Wrap `time` to the interval [1, reset_value]. - timer->time = (timer->time + timer->tick) % timer->reset_value + 1; + timer->time = (timer->time + timer->tick) % timer->reset_value; return 0; } + +bool timer_must_run_block(const timer *const timer, const block *const block) { + if (timer->time == timer->reset_value) { + return true; + } + + if (block->interval == 0) { + return false; + } + + return timer->time % block->interval == 0; +} From dea248b824f452352f49365b154b970eaf55bdbc Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Tue, 19 Mar 2024 06:52:21 +0530 Subject: [PATCH 05/10] build: Add DEBUG option --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index d7d7455..635673e 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ BUILD_DIR := build SRC_DIR := src INC_DIR := include +DEBUG := 0 VERBOSE := 0 LIBS := xcb-atom @@ -26,6 +27,10 @@ ifeq ($(VERBOSE), 0) Q := @ endif +ifeq ($(DEBUG), 1) + CFLAGS += -g +endif + all: $(BUILD_DIR)/$(BIN) $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c config.h From 8ebe985db8c0818e6316b8b4b82e20d6f680c017 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Tue, 19 Mar 2024 06:53:49 +0530 Subject: [PATCH 06/10] fix: Ensure that all blocks execute on SIGUSR1. (closes #63) --- src/main.c | 2 +- src/timer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 4484f0a..e019765 100644 --- a/src/main.c +++ b/src/main.c @@ -69,7 +69,7 @@ static int trigger_event(block *const blocks, const unsigned short block_count, static int refresh_callback(block *const blocks, const unsigned short block_count) { - if (execute_blocks(blocks, block_count, 0) != 0) { + if (execute_blocks(blocks, block_count, NULL) != 0) { return 1; } diff --git a/src/timer.c b/src/timer.c index 2454fb9..2ee555b 100644 --- a/src/timer.c +++ b/src/timer.c @@ -60,7 +60,7 @@ int timer_arm(timer *const timer) { } bool timer_must_run_block(const timer *const timer, const block *const block) { - if (timer->time == timer->reset_value) { + if (timer == NULL || timer->time == timer->reset_value) { return true; } From fe538a7a2fc52e991a553bd76719735141658844 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Sat, 20 Apr 2024 08:49:01 +0530 Subject: [PATCH 07/10] feat: Add support for block-specific icons Icons can now be specified on a per-block basis. Closes #64. --- README.md | 5 +++-- config.h | 24 ++++++++++++------------ include/block.h | 5 +++-- src/block.c | 5 +++-- src/main.c | 3 ++- src/status.c | 1 + 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 69b72da..1b389f6 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,8 @@ You can define your status bar blocks in `config.h`: ```c #define BLOCKS(X) \ ... - X("volume", 0, 5), \ - X("date", 1800, 1), \ + X(" ", "wpctl get-volume @DEFAULT_AUDIO_SINK@ | cut -d' ' -f2", 0, 5) \ + X("󰥔 ", "date '+%H:%M:%S'", 1, 1) \ ... ``` @@ -99,6 +99,7 @@ Each block has the following properties: | Property | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | +| Icon | An icon you wish to prepend to your block output. | | Command | The command you wish to execute in your block. | | Update interval | Time in seconds, after which you want the block to update. If `0`, the block will never be updated. | | Update signal | Signal to be used for triggering the block. Must be a positive integer. If `0`, a signal won't be set up for the block and it will be unclickable. | diff --git a/config.h b/config.h index a02c0ca..d9d605b 100644 --- a/config.h +++ b/config.h @@ -16,17 +16,17 @@ // Control whether a trailing delimiter should be appended to the status. #define TRAILING_DELIMITER 0 -// Define blocks for the status feed as X(cmd, interval, signal). -#define BLOCKS(X) \ - X("sb-mail", 600, 1) \ - X("sb-music", 0, 2) \ - X("sb-disk", 1800, 3) \ - X("sb-memory", 10, 4) \ - X("sb-loadavg", 5, 5) \ - X("sb-mic", 0, 6) \ - X("sb-record", 0, 7) \ - X("sb-volume", 0, 8) \ - X("sb-battery", 5, 9) \ - X("sb-date", 1, 10) +// Define blocks for the status feed as X(icon, cmd, interval, signal). +#define BLOCKS(X) \ + X("", "sb-mail", 600, 1) \ + X("", "sb-music", 0, 2) \ + X("", "sb-disk", 1800, 3) \ + X("", "sb-memory", 10, 4) \ + X("", "sb-loadavg", 5, 5) \ + X("", "sb-mic", 0, 6) \ + X("", "sb-record", 0, 7) \ + X("", "sb-volume", 0, 8) \ + X("", "sb-battery", 5, 9) \ + X("", "sb-date", 1, 10) #endif // CONFIG_H diff --git a/include/block.h b/include/block.h index 555549c..c4f8d54 100644 --- a/include/block.h +++ b/include/block.h @@ -9,6 +9,7 @@ #include "util.h" typedef struct { + const char *const icon; const char *const command; const unsigned int interval; const int signal; @@ -18,8 +19,8 @@ typedef struct { pid_t fork_pid; } block; -block block_new(const char *const command, const unsigned int interval, - const int signal); +block block_new(const char *const icon, const char *const command, + const unsigned int interval, const int signal); int block_init(block *const block); int block_deinit(block *const block); int block_execute(block *const block, const uint8_t button); diff --git a/src/block.c b/src/block.c index 0a73af6..a6c919d 100644 --- a/src/block.c +++ b/src/block.c @@ -13,9 +13,10 @@ #include "config.h" #include "util.h" -block block_new(const char *const command, const unsigned int interval, - const int signal) { +block block_new(const char *const icon, const char *const command, + const unsigned int interval, const int signal) { block block = { + .icon = icon, .command = command, .interval = interval, .signal = signal, diff --git a/src/main.c b/src/main.c index e019765..747b075 100644 --- a/src/main.c +++ b/src/main.c @@ -128,7 +128,8 @@ int main(const int argc, const char *const argv[]) { return 1; } -#define BLOCK(command, interval, signal) block_new(command, interval, signal), +#define BLOCK(icon, command, interval, signal) \ + block_new(icon, command, interval, signal), block blocks[BLOCK_COUNT] = {BLOCKS(BLOCK)}; #undef BLOCK const unsigned short block_count = LEN(blocks); diff --git a/src/status.c b/src/status.c index a3a4794..cf0911a 100644 --- a/src/status.c +++ b/src/status.c @@ -49,6 +49,7 @@ bool status_update(status *const status) { } #endif + (void)strncat(status->current, block->icon, LEN(block->output)); (void)strncat(status->current, block->output, LEN(block->output)); } } From 38cadc6427db51700b3add3c356da5d41b36f8e0 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Wed, 8 Oct 2025 11:06:48 +0200 Subject: [PATCH 08/10] tidy: address some clang-tidy lints --- src/cli.c | 4 ++-- src/signal-handler.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cli.c b/src/cli.c index b1849ec..8b94cc8 100644 --- a/src/cli.c +++ b/src/cli.c @@ -5,7 +5,7 @@ #include #include -cli_arguments cli_parse_arguments(const char *const argv[], const int argc) { +cli_arguments cli_parse_arguments(const char* const argv[], const int argc) { errno = 0; cli_arguments args = { .is_debug_mode = false, @@ -13,7 +13,7 @@ cli_arguments cli_parse_arguments(const char *const argv[], const int argc) { int opt = -1; opterr = 0; // Suppress getopt's built-in invalid opt message - while ((opt = getopt(argc, (char *const *)argv, "dh")) != -1) { + while ((opt = getopt(argc, (char* const*)argv, "dh")) != -1) { switch (opt) { case 'd': args.is_debug_mode = true; diff --git a/src/signal-handler.c b/src/signal-handler.c index d816dcd..7a1a966 100644 --- a/src/signal-handler.c +++ b/src/signal-handler.c @@ -109,6 +109,8 @@ int signal_handler_process(signal_handler *const handler, timer *const timer) { // fall through case SIGINT: return 1; + default: + break; } for (unsigned short i = 0; i < handler->block_count; ++i) { From 469e6841432693d81a17088706d99ef044a29936 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Sat, 18 Apr 2026 21:43:19 +0200 Subject: [PATCH 09/10] misc: update config --- config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/config.h b/config.h index d9d605b..0dbb2b0 100644 --- a/config.h +++ b/config.h @@ -22,6 +22,7 @@ X("", "sb-music", 0, 2) \ X("", "sb-disk", 1800, 3) \ X("", "sb-memory", 10, 4) \ + X("", "sb-swap", 10, 0) \ X("", "sb-loadavg", 5, 5) \ X("", "sb-mic", 0, 6) \ X("", "sb-record", 0, 7) \ From e365e295f38000d32589f3fa0e8e502d89646801 Mon Sep 17 00:00:00 2001 From: lucy Date: Mon, 29 Jun 2026 23:32:15 +0200 Subject: [PATCH 10/10] add my own script and config --- Makefile | 2 ++ bat.sh | 14 ++++++++++++++ config.h | 18 +++++------------- wp.sh | 11 +++++++++++ 4 files changed, 32 insertions(+), 13 deletions(-) create mode 100755 bat.sh create mode 100755 wp.sh diff --git a/Makefile b/Makefile index 635673e..a70bdb6 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,8 @@ clean: install: $(BUILD_DIR)/$(BIN) $(PRINTF) "INSTALL" $(INSTALL_DIR)/$(BIN) $Qinstall -D -m 755 $< $(INSTALL_DIR)/$(BIN) + cp ./bat.sh /usr/local/bin + cp ./wp.sh /usr/local/bin uninstall: $(PRINTF) "RM" $(INSTALL_DIR)/$(BIN) diff --git a/bat.sh b/bat.sh new file mode 100755 index 0000000..1e01ab5 --- /dev/null +++ b/bat.sh @@ -0,0 +1,14 @@ +status=$(cat /sys/class/power_supply/BAT0/status) +level=$(cat /sys/class/power_supply/BAT0/capacity) + +case $status in + Full) + echo $level%o + ;; + Charging) + echo $level%+ + ;; + Discharging) + echo $level%- + ;; +esac diff --git a/config.h b/config.h index 0dbb2b0..781907b 100644 --- a/config.h +++ b/config.h @@ -2,13 +2,13 @@ #define CONFIG_H // String used to delimit block outputs in the status. -#define DELIMITER " " +#define DELIMITER " " // Maximum number of Unicode characters that a block can output. #define MAX_BLOCK_OUTPUT_LENGTH 45 // Control whether blocks are clickable. -#define CLICKABLE_BLOCKS 1 +#define CLICKABLE_BLOCKS 0 // Control whether a leading delimiter should be prepended to the status. #define LEADING_DELIMITER 0 @@ -18,16 +18,8 @@ // Define blocks for the status feed as X(icon, cmd, interval, signal). #define BLOCKS(X) \ - X("", "sb-mail", 600, 1) \ - X("", "sb-music", 0, 2) \ - X("", "sb-disk", 1800, 3) \ - X("", "sb-memory", 10, 4) \ - X("", "sb-swap", 10, 0) \ - X("", "sb-loadavg", 5, 5) \ - X("", "sb-mic", 0, 6) \ - X("", "sb-record", 0, 7) \ - X("", "sb-volume", 0, 8) \ - X("", "sb-battery", 5, 9) \ - X("", "sb-date", 1, 10) + X(" ", "date +%H:%M:%S", 1, 1) \ + X(" ", "bat.sh", 1, 1) \ + X(" ", "wp.sh", 1, 1) #endif // CONFIG_H diff --git a/wp.sh b/wp.sh new file mode 100755 index 0000000..a141182 --- /dev/null +++ b/wp.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +vol=$(echo "$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk -F' ' '{print $2}') * 100" | bc) +status=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep -q "[MUTED]") + +if wpctl get-volume @DEFAULT_AUDIO_SINK@| grep -q "[MUTED]"; then + echo "mut": $vol% + exit +fi + +echo vol: $vol%