mirror of
https://github.com/mintycube/dwmblocks.git
synced 2024-10-22 14:05:47 +02:00
Make block clickability optional
This commit is contained in:
parent
f12b56e203
commit
3d55e4b10f
26
README.md
26
README.md
@ -84,32 +84,42 @@ static Block blocks[] = {
|
||||
}
|
||||
```
|
||||
|
||||
Apart from that you can also modify the block delimiters and width of each block as shown.
|
||||
Apart from that you can also modify the following parameters to suit your needs.
|
||||
```c
|
||||
// Maximum possible length of output from block, expressed in number of characters.
|
||||
#define CMDLENGTH 50
|
||||
|
||||
// The status bar's delimiter which appears in between each block.
|
||||
#define DELIMITER " "
|
||||
|
||||
// Adds a trailing delimiter to the statusbar, useful for powerline
|
||||
// Adds a trailing delimiter to the statusbar, useful for powerline.
|
||||
#define TRAILING_DELIMITER
|
||||
|
||||
// Enable clickability for blocks. Needs `dwm` to be patched appropriately.
|
||||
// See the "Clickable blocks" section below.
|
||||
#define CLICKABLE_BLOCKS
|
||||
```
|
||||
|
||||
### Signalling changes
|
||||
Most statusbars constantly rerun every script every several seconds to update. This is an option here, but a superior choice is giving your module a signal that you can signal to it to update on a relevant event, rather than having it rerun idly.
|
||||
Most statusbars constantly rerun every script every several seconds to update. This is an option here, but a superior choice is giving your block a signal that you can signal to it to update on a relevant event, rather than having it rerun idly.
|
||||
|
||||
For example, the volume module has the update signal 5 by default. Thus, running `pkill -RTMIN+5 dwmblocks` will update it.
|
||||
For example, the volume block has the update signal 5 by default. Thus, running `pkill -RTMIN+5 dwmblocks` will update it.
|
||||
|
||||
You can also run `kill -39 $(pidof dwmblocks)` which will have the same effect, but is faster. Just add 34 to your typical signal number.
|
||||
|
||||
My volume module *never* updates on its own, instead I have this command run along side my volume shortcuts in `dwm` to only update it when relevant.
|
||||
My volume block *never* updates on its own, instead I have this command run along side my volume shortcuts in `dwm` to only update it when relevant.
|
||||
|
||||
Note that all modules must have different signal numbers.
|
||||
Note that all blocks must have different signal numbers.
|
||||
|
||||
### Clickable modules
|
||||
### Clickable blocks
|
||||
Like `i3blocks`, this build allows you to build in additional actions into your scripts in response to click events. You can check out [my statusbar scripts](https://github.com/UtkarshVerma/dotfiles/tree/main/.local/bin/statusbar) as references for using the `$BLOCK_BUTTON` variable.
|
||||
|
||||
For this feature to work, you need `dwm` to be patched with [statuscmd](https://dwm.suckless.org/patches/statuscmd/).
|
||||
To use this feature, define the `CLICKABLE_BLOCKS` feature macro in your `config.h`.
|
||||
```c
|
||||
#define CLICKABLE_BLOCKS
|
||||
```
|
||||
|
||||
Apart from that, you need `dwm` to be patched with [statuscmd](https://dwm.suckless.org/patches/statuscmd/).
|
||||
|
||||
Because `dwmblocks-async` creates a child process, it messes up the way the original `statuscmd` patch gets the PID of statusbar. It is necessary to modify the following lines in the definition of `getstatusbarpid()`.
|
||||
|
||||
|
1
config.h
1
config.h
@ -1,6 +1,7 @@
|
||||
#define CMDLENGTH 50
|
||||
#define DELIMITER "<"
|
||||
#define TRAILING_DELIMITER
|
||||
#define CLICKABLE_BLOCKS
|
||||
|
||||
const Block blocks[] = {
|
||||
BLOCK("sb-mail", 1800, 17)
|
||||
|
18
main.c
18
main.c
@ -12,7 +12,7 @@
|
||||
|
||||
#define POLL_INTERVAL 50
|
||||
#define LEN(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
#define BLOCK(cmd, interval, signal) {"echo \"_$(" cmd ")\"", interval, signal},
|
||||
#define BLOCK(cmd, interval, signal) {"echo \"$(" cmd ")\"", interval, signal},
|
||||
typedef struct {
|
||||
const char* command;
|
||||
const unsigned int interval;
|
||||
@ -20,11 +20,19 @@ typedef struct {
|
||||
} Block;
|
||||
#include "config.h"
|
||||
|
||||
#ifdef CLICKABLE_BLOCKS
|
||||
#undef CLICKABLE_BLOCKS
|
||||
#define CLICKABLE_BLOCKS 1
|
||||
#else
|
||||
#undef CLICKABLE_BLOCKS
|
||||
#define CLICKABLE_BLOCKS 0
|
||||
#endif
|
||||
|
||||
static Display* dpy;
|
||||
static int screen;
|
||||
static Window root;
|
||||
static unsigned short int statusContinue = 1;
|
||||
static char outputs[LEN(blocks)][CMDLENGTH + 2];
|
||||
static char outputs[LEN(blocks)][CMDLENGTH + 1 + CLICKABLE_BLOCKS];
|
||||
static char statusBar[2][LEN(blocks) * ((LEN(outputs[0]) - 1) + (LEN(DELIMITER) - 1)) + 1];
|
||||
static struct epoll_event event, events[LEN(blocks) + 2];
|
||||
static int pipes[LEN(blocks)][2];
|
||||
@ -93,17 +101,19 @@ void updateBlock(int i) {
|
||||
char ch;
|
||||
while (read(pipes[i][0], &ch, 1) == 1 && ch != '\n')
|
||||
;
|
||||
} else if (bytesRead == 2) {
|
||||
} else if (bytesRead == 1) {
|
||||
output[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
#if CLICKABLE_BLOCKS
|
||||
if (blocks[i].signal > 0) {
|
||||
output[0] = blocks[i].signal;
|
||||
output++;
|
||||
}
|
||||
#endif
|
||||
|
||||
strcpy(output, buffer + 1);
|
||||
strcpy(output, buffer);
|
||||
}
|
||||
|
||||
void debug() {
|
||||
|
Loading…
Reference in New Issue
Block a user