I cannot leave tiling window managers anymore!
Tags: dwm, tiling, linux, desktop
Published: 2022-09-21 16:12:13

## Intro:

I have used gnome-shell for a very long time until taking tiling widow managers seriously. As a vim user I am already used to suffer a while until creating muscle memory and having my thoughts becoming actions in terminal...

## The first attempt:

Bspwm. Using a post from "[Terminal root](https://terminalroot.com.br/2021/06/como-instalar-e-configurar-o-bspwm-com-temas-para-polybar.html)" (Marcos Oliveira), the recipe was quite easy to follow and I started tweaking my shortcuts and so on. 

## The awesom and dwm

I became curious about other tiling window managers and started using awesome, at this time I already had my suckless terminal build and gradually became more prone to use dwm, of course I miss some desktop features, but in general it's worth paying the price, loosing some desktop features, even because new scripts and tips are appearing all the time. 

## The PopOS gnome-shell extension

For now I will continue to use my dwm and once in a while I will try the [PopOS solution](https://github.com/pop-os/shell) to see if they can convince me to get back to gnome-shell.  

## See my dotfiles here:
[https://bitbucket.org/sergio/dotfiles/src/main/](https://bitbucket.org/sergio/dotfiles/src/main/)


The st I am using is a copy of st-bonk, there is a copy of it on my dotfiles. 

## Eventually this article will grow 
I am thinking in gradually share some of my ideas, some of them would be considered craziness but some could inspire you (possibly). 

The first one is istalling a package called <span style="color: red;">lsd</span> `cargo install lsd` it adds icons to folders and files as you type ls, this way it becomes easy to know what whe have in our terminal, even when you are changing your terminal colors at every 5 minutes with a crontab like this:

```sh
# crontab -e
# >/dev/null 2>&1 <- used to preven sending e-mail's
# in order to get your DISPLAY run the command below
# env | grep -i display
# If you do not set this variable feh will not change your wallpaper
# source: https://superuser.com/a/1122245/45032
DISPLAY=':0'
SHELL=/bin/sh
HOME=/home/sergio
PATH=/sbin:/bin:/usr/sbin:/usr/bin:$HOME/.local/bin
MAILTO=""
HOME=/home/sergio

*/5 * * * * /home/sergio/.local/bin/wal -qi /home/sergio/.dotfiles/backgrounds >/dev/null 2>&1
* */1 * * * /bin/newsboat -x reload  # reload hourly
* * * * *  /home/sergio/.dotfiles/bin/checkbattery.sh >/dev/null
```

You can download the above code (raw) at [this link](https://bitbucket.org/!api/2.0/snippets/sergio/6EGAq8/eb484cd831274bbc87d361b02d799dd8cf8b5758/files/crontab.sh)

The `lsd` (ls with icons) in action


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0uci8tdqgfii68dgt5t3.png)

One of my wallpapers, because I am used to collect good images:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aivn5d3jn826l6ujsnmk.png)

## Check battery state:

Notice that we have one line in our crontab that call the bellow script

```sh
#!/bin/bash
# File: /home/sergio/.dotfiles/bin/checkbattery.sh
# Last Change: Mon, 26 Sep 2022 16:40:52
#
# https://www.2daygeek.com/linux-low-full-charging-discharging-battery-notification/
# crontab example where you can use this script:
# https://pastebin.com/Jn36y4sW

# battery_status=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | awk '/state:/ {print $2}')
# battery_level=$(acpi -b | grep -P -o '[0-9]+(?=%)')
battery_status=$(cat /sys/class/power_supply/BAT0/status)
battery_level=$(cat /sys/class/power_supply/BAT0/capacity)

if [ $battery_level -ge 95 ]; then
    if [[ "$battery_status" == "Charging" ]]; then
        dunstify -i "battery-charging" -r 1245 --urgency=LOW  "Battery Full" "Level: ${battery_level}%"
        #paplay /usr/share/sounds/freedesktop/stereo/complete.oga
    fi
elif [ $battery_level -le 20 ]; then
    if [[ "$battery_status" == "Discharging" ]]; then
        dunstify -i "alert" -r 1245 --urgency=CRITICAL "Battery Low" "Level: ${battery_level}%"
        # paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga
    fi
fi
```

## Notification system

I am using dunst, here on voidlinux I had to uninstall xfce4 so it does not mess things up. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2t8l1g18tf5vvn8m3jk.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/utsmmtgxhmo6943e35w2.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ozchdi87wjjop9ztydp1.png)

All my dunst configuration is [here](https://bitbucket.org/sergio/dotfiles/src/main/dunst/) the only thing you have to do is change `/home/sergio` in the dunstrc. 

## xautolock

During idle time we can activate our lock screen, and xautolock does more than that, it has a `-corners` option where you can say:

1 - (0) Do nothing
2 - (-) Do not lock screen while over this corner
3 - (+) After some seconds here we are going to lock your screen

The xautolock corners follows this order: Top left, top right, bottom left, bottom right.

My corners option is this: `-corners "++--"` and my entire xautolock command is this:

```sh
pgrep -x xautolock >/dev/null ||  xautolock -time 5 -locker slock -nowlocker slock -detectsleep -corners ++-- -cornerdelay 3 -notify 5 -notifier "/home/sergio/.dotfiles/bin/lockscreen-notify.sh" &
```

The **lockscreen-notify.sh** below:

```sh
#!/bin/sh
# File: /home/sergio/.dotfiles/bin/lockscreen-notify.sh
# Last Change: Thu, 06 Oct 2022 13:33:31
# References:
# https://dev.to/ccoveille/lock-screen-notifier-4o1h
# https://stackoverflow.com/a/8743103/2571881
# tags: [screensaver, dunst, dunstify,  notification, xautolock, x11]

set -e

# gets mouse x coordinate
mousex (){
    echo "$(xdotool getmouselocation --shell | awk -F= 'NR==1 {print $2}')"
}

pos=$( mousex )

for p in $(seq 0 2 100); do

    dunstify --icon screensaver \
        -h int:value:"$p" \
        -h 'string:hlcolor:#ff4444' \
        -h string:x-dunst-stack-tag:progress-lock \
        --timeout=500 "about to lock screen ..." "move or use corners"
    sleep 0.05

    if [ "$pos" != "$(mousex )" ] ; then
       dunstctl close
       exit 1
    fi

done
```


## dmenu record script

In this link at [paste.bin](https://pastebin.com/27r9pYwe)

## The st-bonk build 
I have added transparency to the [st-bonk](https://github.com/feloniousBonk/st-bonk), in my dotfiles I have a copy of it with the mentioned patch applyed, hence it will be easy for you to remap your gnome-terminal in gnome-shell, for instance, and have a decent transparent terminal. 

## Patches list on my dwm:

These are the patches I am using:

```sh
dwm-alwayscenter
dwm-attachbottom
dwm-autostart
dwm-cfacts
dwm-pertag
dwm-rotatestack
dwm-scratchpad
dwm-switchtotag
dwm-uselessgap
```

Of course this is the hardest part, figuring out what patches attend better your needs but at the end you will get the hang of it. Some chages do not even need the patch command, for example the "[shiftview.c](https://lists.suckless.org/dev/1104/7590.html)", the `c` file we map to jump to the next tag like `MODKEY + ]`

```c
/* add this line before keys[] */
#include "shiftview.c"
```

```c
/* the shiftview.c file */
/** Function to shift the current view to the left/right
 *
 * @param: "arg->i" stores the number of tags to shift right (positive value)
 *          or left (negative value)
 */
void
shiftview(const Arg *arg) {
	Arg shifted;

	if(arg->i > 0) // left circular shift
		shifted.ui = (selmon->tagset[selmon->seltags] << arg->i)
		   | (selmon->tagset[selmon->seltags] >> (LENGTH(tags) - arg->i));

	else // right circular shift
		shifted.ui = selmon->tagset[selmon->seltags] >> (- arg->i)
		   | selmon->tagset[selmon->seltags] << (LENGTH(tags) + arg->i);

	view(&shifted);
}
```

Now at the key table put these lines:

```c
{ MODKEY,   XK_bracketleft,     shiftview,   {.i = -1} },
{ MODKEY,   XK_bracketright,    shiftview,   {.i = +1} },
```

## Rules to tame your windows:

Specially for firefox download windows I figured out a solution (I have the switchtotag patch installed):

For scratchpad terminals I have a patch and of course the rules also are listed here.

```c
static const Rule rules[] = {
	/* xprop(1):
	 *	WM_CLASS(STRING) = instance, class
	 *	WM_NAME(STRING) = title
	 */

	/* class              instance    title       tags mask     switchtotag    isfloating   monitor */
	{ "Gimp",             NULL,       NULL,       0,            0,             1,           -1 },
	{ "Firefox",          NULL,       NULL,       2 << 0,       1,             0,           -1 },
	{ "TelegramDesktop",  NULL,       NULL,       1 << 4,       1,             0,           -1 },
	{ "ranger",           NULL,       NULL,       4 << 0,       1,             0,           -1 },
	{ "pulse",            NULL,       NULL,       0,            0,             1,           -1 },
	{ "St",               NULL,       NULL,       1 << 0,       1,             0,           -1 },
	{ "term2",            NULL,       NULL,       0,            0,             0,           -1 },
	{ "htop",             NULL,       NULL,       0,            0,             1,           -1 },
	{ "scratchpad",       NULL,       NULL,       0,            0,             1,           -1 },
	{ "scratchy",         NULL,       NULL,       0,            0,             1,           -1 },
	{ "nvim",             NULL,       NULL,       1 << 8,       1,             0,           -1 },
	{ "newsboat",         NULL,       NULL,       1 << 5,       1,             1,           -1 },
	{ "Nemo",             NULL,       NULL,       1 << 7,       1,             0,           -1 },
	{ "Firefox",          "Places",   "Library",  0,            0,             1,           -1 },
};
```

The last line has the solution for the problem

## The terminal font:

[Iosevka Mayukai Original](https://github.com/Iosevka-Mayukai/Iosevka-Mayukai) 

![My backgrounds folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6y9ccntmreatmtnn5bq.png)

## My wallpapers

If you want to create thumbnails easily read [this article](https://dev.to/voyeg3r/creating-thumbnails-with-parallel-and-imagemagick-22gd)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cw6cs6bfuqi1gin515t2.png)

## Tweking rofi to get awesome dialogs:

I have discovered an amazing rofi setting collection [here](https://github.com/adi1090x/rofi)

`https://github.com/adi1090x/rofi`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cn9dnk84xetqvsv65qrn.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/756czp089dwgubdvhz5w.png)