feat: Add support for block-specific icons

Icons can now be specified on a per-block basis. Closes #64.
This commit is contained in:
Utkarsh Verma 2024-04-20 08:49:01 +05:30
parent 8ebe985db8
commit fe538a7a2f
No known key found for this signature in database
GPG Key ID: 7A4885A7162BDF20
6 changed files with 24 additions and 19 deletions

View File

@ -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. |

View File

@ -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

View File

@ -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);

View File

@ -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,

View File

@ -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);

View File

@ -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));
}
}