dwmblocks-custom/README.md

122 lines
4.8 KiB
Markdown
Raw Normal View History

2021-10-12 17:07:59 +02:00
# dwmblocks-async
2023-02-05 10:27:14 +01:00
A [`dwm`](https://dwm.suckless.org) status bar that has a modular, async design, so it is always responsive. Imagine `i3blocks`, but for `dwm`.
2021-03-22 06:42:52 +01:00
2022-01-18 18:17:00 +01:00
![A lean config of dwmblocks-async.](preview.png)
2021-03-22 06:42:52 +01:00
## Features
2023-02-05 10:27:14 +01:00
- [Modular](#modifying-the-blocks)
2021-03-22 06:42:52 +01:00
- Lightweight
2023-02-05 10:27:14 +01:00
- [Suckless](https://suckless.org/philosophy)
- Blocks:
- [Clickable](#clickable-blocks)
- Loaded asynchronously
- [Updates can be externally triggered](#signalling-changes)
2021-03-22 06:42:52 +01:00
- Compatible with `i3blocks` scripts
2023-02-05 10:27:14 +01:00
> Additionally, this build of `dwmblocks` is more optimized and fixes the flickering of the status bar when scrolling.
2021-03-22 06:42:52 +01:00
2021-10-12 17:07:59 +02:00
## Why `dwmblocks`?
2023-02-05 10:27:14 +01:00
In `dwm`, you have to set the status bar through an infinite loop, like so:
2021-03-22 06:42:52 +01:00
```sh
while :; do
xsetroot -name "$(date)"
sleep 30
done
```
2023-02-05 10:27:14 +01:00
This is inefficient when running multiple commands that need to be updated at different frequencies. For example, to display an unread mail count and a clock in the status bar:
2021-03-22 06:42:52 +01:00
```sh
while :; do
xsetroot -name "$(mailCount) $(date)"
sleep 60
done
```
2023-02-05 10:27:14 +01:00
Both are executed at the same rate, which is wasteful. Ideally, the mail counter would be updated every thirty minutes, since there's a limit to the number of requests I can make using Gmail's APIs (as a free user).
2021-03-22 06:42:52 +01:00
2023-02-05 10:27:14 +01:00
`dwmblocks` allows you to divide the status bar into multiple blocks, each of which can be updated at its own interval. This effectively addresses the previous issue, because the commands in a block are only executed once within that time frame.
2021-03-22 06:42:52 +01:00
2021-10-12 17:07:59 +02:00
## Why `dwmblocks-async`?
2023-02-05 10:27:14 +01:00
The magic of `dwmblocks-async` is in the `async` part. Since vanilla `dwmblocks` executes the commands of each block sequentially, it leads to annoying freezes. In cases where one block takes several seconds to execute, like in the mail and date blocks example from above, the delay is clearly visible. Fire up a new instance of `dwmblocks` and you'll see!
2021-10-12 17:07:59 +02:00
2023-02-05 10:27:14 +01:00
With `dwmblocks-async`, the computer executes each block asynchronously (simultaneously).
2021-10-12 17:07:59 +02:00
## Installation
2023-02-05 10:27:14 +01:00
Clone this repository, modify `config.h` appropriately, then compile the program:
2021-03-22 06:42:52 +01:00
```sh
2021-10-12 17:07:59 +02:00
git clone https://github.com/UtkarshVerma/dwmblocks-async.git
2023-02-05 10:27:14 +01:00
cd dwmblocks-async
2021-03-22 06:42:52 +01:00
vi config.h
sudo make install
```
2021-10-12 17:07:59 +02:00
## Usage
2023-02-05 10:27:14 +01:00
To set `dwmblocks-async` as your status bar, you need to run it as a background process on startup. One way is to add the following to `~/.xinitrc`:
2021-03-22 06:42:52 +01:00
```sh
2023-02-05 10:27:14 +01:00
# The binary of `dwmblocks-async` is named `dwmblocks`
2021-03-22 06:42:52 +01:00
dwmblocks &
```
2021-10-12 17:07:59 +02:00
### Modifying the blocks
2023-02-05 10:27:14 +01:00
You can define your status bar blocks in `config.h`:
2021-03-22 06:42:52 +01:00
```c
2021-10-17 04:02:31 +02:00
const Block blocks[] = {
2021-03-22 06:42:52 +01:00
...
2022-01-02 19:17:27 +01:00
BLOCK("volume", 0, 5),
BLOCK("date", 1800, 1),
2021-03-22 06:42:52 +01:00
...
}
```
2023-02-05 10:27:14 +01:00
Each block has the following properties:
Property|Description
-|-
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.
Additional parameters can be modified:
2021-03-22 06:42:52 +01:00
```c
2021-10-12 17:07:59 +02:00
// Maximum possible length of output from block, expressed in number of characters.
2021-03-22 06:42:52 +01:00
#define CMDLENGTH 50
2021-03-23 05:15:48 +01:00
2023-02-05 10:27:14 +01:00
// The status bar's delimiter that appears in between each block.
2021-04-17 12:17:40 +02:00
#define DELIMITER " "
2021-10-13 17:58:49 +02:00
2023-02-05 10:27:14 +01:00
// Adds a leading delimiter to the status bar, useful for powerline.
#define LEADING_DELIMITER
2021-10-17 03:58:15 +02:00
2023-02-05 10:27:14 +01:00
// Enable clickability for blocks. See the "Clickable blocks" section below.
2021-10-17 03:58:15 +02:00
#define CLICKABLE_BLOCKS
2021-03-22 06:42:52 +01:00
```
2021-10-12 17:07:59 +02:00
### Signalling changes
2023-02-05 10:27:14 +01:00
Most status bars constantly rerun all scripts every few seconds. This is an option here, but a superior choice is to give your block a signal through which you can indicate it to update on relevant event, rather than have it rerun idly.
2021-03-22 06:42:52 +01:00
2023-02-05 10:27:14 +01:00
For example, the volume block has the update signal `5` by default. I run `kill -39 $(pidof dwmblocks)` alongside my volume shortcuts in `dwm` to only update it when relevant. Just add `34` to your signal number! You could also run `pkill -RTMIN+5 dwmblocks`, but it's slower.
2021-03-22 06:42:52 +01:00
2023-02-05 10:27:14 +01:00
To refresh all the blocks, run `kill -10 $(pidof dwmblocks)` or `pkill -SIGUSR1 dwmblocks`.
2021-03-22 06:42:52 +01:00
2023-02-05 10:27:14 +01:00
> All blocks must have different signal numbers!
2021-10-17 03:58:15 +02:00
### Clickable blocks
2023-02-05 10:27:14 +01:00
Like `i3blocks`, this build allows you to build in additional actions into your scripts in response to click events. You can check out [my status bar scripts](https://github.com/UtkarshVerma/dotfiles/tree/main/.local/bin/statusbar) as references for using the `$BLOCK_BUTTON` variable.
To use this feature, define the `CLICKABLE_BLOCKS` feature macro in your `config.h`:
2021-03-22 06:42:52 +01:00
2021-10-17 03:58:15 +02:00
```c
#define CLICKABLE_BLOCKS
```
Apart from that, you need `dwm` to be patched with [statuscmd](https://dwm.suckless.org/patches/statuscmd/).
2021-03-22 06:42:52 +01:00
2021-10-12 17:07:59 +02:00
## Credits
2021-03-22 06:42:52 +01:00
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/).