mirror of
https://github.com/mintycube/dwmblocks.git
synced 2024-10-22 14:05:47 +02:00
Add README.md
This commit is contained in:
parent
0fc72ee4b4
commit
1d936dcadd
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
*.o
|
||||
dwmblocks
|
||||
|
||||
dwmblocks
|
101
README.md
Normal file
101
README.md
Normal file
@ -0,0 +1,101 @@
|
||||
# dwmblocks
|
||||
A modular statusbar for `dwm` written in C. You may think of it as `i3blocks`, but for `dwm`.
|
||||
|
||||
## Features
|
||||
- Modular
|
||||
- Lightweight
|
||||
- Suckless
|
||||
- Modules are clickable
|
||||
- Each module can be externally triggered to update itself
|
||||
- Compatible with `i3blocks` scripts
|
||||
|
||||
> Apart from these features, this build of `dwmblocks` is more optimized and fixes the scroll issue due to which the statusbar flickers on scrolling.
|
||||
|
||||
# Why `dwmblocks`?
|
||||
In `dwm`, you have to set the statusbar through an infinite loop like this:
|
||||
|
||||
```sh
|
||||
while :; do
|
||||
xsetroot -name "$(date)"
|
||||
sleep 30
|
||||
done
|
||||
```
|
||||
|
||||
It may not look bad as it is, but it's surely not the most efficient way when you've got to run multiple commands, out of which only few need to be updated as frequently as the others.
|
||||
|
||||
```sh
|
||||
# Displaying an unread mail count in the status bar
|
||||
while :; do
|
||||
xsetroot -name "$(mailCount) $(date)"
|
||||
sleep 60
|
||||
done
|
||||
```
|
||||
|
||||
For example, I display an unread mail count in my statusbar. Ideally, I would want this count to update every thirty minutes, but since I also have a clock in my statusbar which has to be updated every minute, I can't stop the mail count from being updated every minute.
|
||||
|
||||
As you can see, this is wasteful. And since my mail count script uses Gmail's APIs, there's a limit to the number of requests I can make, being a free user.
|
||||
|
||||
What `dwmblocks` does is that it allows you to break up the statusbar into multiple blocks, each of which have their own update interval. The commands in a particular block are only executed once in that interval. Hence, we don't run into our problem anymore.
|
||||
|
||||
What's even better is that you can externally trigger updation of any specific block.
|
||||
|
||||
|
||||
# Installation
|
||||
The installation is simple, just clone this repository, modify `config.h` appropriately, and then do a `sudo make install`.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/UtkarshVerma/dwmblocks.git
|
||||
vi config.h
|
||||
sudo make install
|
||||
```
|
||||
|
||||
|
||||
# Usage
|
||||
To have `dwmblocks` set your statusbar, you need to run it as a background process on startup. One way is by adding the following to `~/.xinitrc`.
|
||||
|
||||
```sh
|
||||
dwmblocks &
|
||||
```
|
||||
|
||||
## Modifying the blocks
|
||||
You can define your statusbar blocks in `config.h`. Each block has the following properties:
|
||||
|
||||
Property|Value
|
||||
-|-
|
||||
Command | The command you wish to execute in your block
|
||||
Update interval | Time in seconds, after which you want the block to update. Setting this to `0` will result in the block never being updated.
|
||||
Update signal | Signal to be used for triggering the block. Must be a positive integer.
|
||||
|
||||
The syntax for defining a block is:
|
||||
```c
|
||||
static const Block blocks[] = {
|
||||
...
|
||||
{"date", 1800, 1},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Apart from that you can also modify the block delimiters and width of each block as shown.
|
||||
```c
|
||||
#define CMDLENGTH 50
|
||||
#define delimiter " "
|
||||
```
|
||||
|
||||
## 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.
|
||||
|
||||
For example, the volume module has the update signal 5 by default. Thus, running `pkill -RTMIN+5 dwmblocks` will update it.
|
||||
|
||||
You can also run `kill -44 $(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.
|
||||
|
||||
Note that all modules must have different signal numbers.
|
||||
|
||||
## Clickable modules
|
||||
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/gentoo/.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/).
|
||||
|
||||
# Credits
|
||||
This work would not have been possible without [Luke's build of dwmblocks](https://github.com/LukeSmithxyz/dwmblocks) and [Daniel Bylinka's statuscmd patch](https://dwm.suckless.org/patches/statuscmd/).
|
13
config.h
13
config.h
@ -2,8 +2,13 @@
|
||||
#define delimiter " "
|
||||
|
||||
static const Block blocks[] = {
|
||||
{"sb-mail", 1800, 1}, {"sb-music", 0, 2}, {"sb-disk", 1800, 4},
|
||||
{"sb-memory", 10, 3}, {"sb-loadavg", 10, 9}, {"sb-volume", 0, 5},
|
||||
{"sb-battery", 5, 6}, {"sb-date", 60, 7}, {"sb-network", 5, 8},
|
||||
{"sb-mail", 1800, 1},
|
||||
{"sb-music", 0, 2},
|
||||
{"sb-disk", 1800, 4},
|
||||
{"sb-memory", 10, 3},
|
||||
{"sb-loadavg", 10, 9},
|
||||
{"sb-volume", 0, 5},
|
||||
{"sb-battery", 5, 6},
|
||||
{"sb-date", 60, 7},
|
||||
{"sb-network", 5, 8},
|
||||
};
|
||||
|
||||
|
15
main.c
15
main.c
@ -35,7 +35,7 @@ static Window root;
|
||||
static char commands[len(blocks)][256];
|
||||
static char statusbar[len(blocks)][CMDLENGTH];
|
||||
static char statusStr[2][len(blocks) * CMDLENGTH +
|
||||
(len(delimiter) - 1) * (len(blocks) - 1) + 1];
|
||||
(len(delimiter) - 1) * (len(blocks) - 1) + 1];
|
||||
static int statusContinue = 1;
|
||||
static void (*writestatus)() = setRoot;
|
||||
|
||||
@ -75,8 +75,8 @@ void setupSignals() {
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGUSR1, &sa, NULL);
|
||||
struct sigaction sigchld_action = {
|
||||
.sa_handler = SIG_DFL,
|
||||
.sa_flags = SA_NOCLDWAIT,
|
||||
.sa_handler = SIG_DFL,
|
||||
.sa_flags = SA_NOCLDWAIT,
|
||||
};
|
||||
sigaction(SIGCHLD, &sigchld_action, NULL);
|
||||
}
|
||||
@ -108,7 +108,7 @@ void getCommands(int time) {
|
||||
for (int i = 0; i < len(blocks); i++) {
|
||||
current = blocks + i;
|
||||
if ((current->interval != 0 && time % current->interval == 0) ||
|
||||
time == -1)
|
||||
time == -1)
|
||||
getCommand(current, statusbar[i]);
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,7 @@ int getStatus(char *new, char *old) {
|
||||
for (int i = 0; i < len(blocks); i++) {
|
||||
strcat(new, statusbar[i]);
|
||||
if (strlen(statusbar[i]) > (blocks[i].signal != 0) &&
|
||||
i != len(blocks) - 1)
|
||||
i != len(blocks) - 1)
|
||||
strcat(new, delimiter);
|
||||
}
|
||||
new[strlen(new)] = '\0';
|
||||
@ -127,7 +127,7 @@ int getStatus(char *new, char *old) {
|
||||
}
|
||||
|
||||
void setRoot() {
|
||||
// Only set root if text has changed.
|
||||
// Only set root if text has changed
|
||||
if (!getStatus(statusStr[0], statusStr[1])) return;
|
||||
|
||||
Display *d = XOpenDisplay(NULL);
|
||||
@ -196,7 +196,7 @@ int main(int argc, char **argv) {
|
||||
const int processID = getpid();
|
||||
for (int i = 0; i < len(blocks); i++)
|
||||
sprintf(commands[i], "%s && kill -%d %d", blocks[i].command,
|
||||
SIGRTMIN + blocks[i].signal, processID);
|
||||
SIGRTMIN + blocks[i].signal, processID);
|
||||
|
||||
for (int i = 0; i < argc; i++)
|
||||
if (!strcmp("-d", argv[i])) writestatus = debug;
|
||||
@ -205,4 +205,3 @@ int main(int argc, char **argv) {
|
||||
signal(SIGINT, termHandler);
|
||||
statusLoop();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user