Bspwm/Sxhkd connoisseurs/newbies

Hello there,
After searching the forum to see what’s already in about Bspwm/Sxhkd I must say that there is just few things here & there but as the archlabs-installer provides it I’d like to bring more material to the Communauty. First there’s a very good youtube playlist about Bspwm, owned by a Debian user who brings also very good scripts related to our subject.
Bspwm seems limited, obscure the first time you launch it, but it’s a lure because after all bspwmrc is just a shell script, so we can with a little persistence, order it to do things the way we want … at least if you take time to read the man-pages. This guy is full of options and the syntax is clear.
So first I post my bspwmrc file witch looks bloated if we compare it with the default one.
Some usefull tools to have: xdo xdotool xtitle xorg-xprop.
I will discuss the different sections over time.

#!/bin/sh

# https://github.com/baskerville/sxhkd
# https://github.com/baskerville/bspwm

#### MONITORS ####

bspc monitor HDMI-1 -d 1 2 3 4 5
bspc monitor DVI-D-1 -d 6 7 8 9 10

#### Desktop layouts ####

bspc desktop 1 -l monocle
bspc desktop 2 -l monocle
bspc desktop 3 -l monocle
bspc desktop 5 -l monocle

#### BSPWM configuration ####

_bc() {
	bspc config "$@"
}

_bc automatic_scheme          spiral
_bc border_width              1
_bc borderless_monocle        true
_bc bottom_padding            0
_bc click_to_focus            true
_bc center_pseudo_tiled       true
_bc focus_follows_pointer     false
_bc gapless_monocle           true
_bc left_padding              0
_bc pointer_modifier          mod1
_bc pointer_follows_monitor   true
_bc pointer_follows_focus     true
_bc pointer_action1           move
_bc pointer_action2           resize_side
_bc pointer_action3           resize_corner
_bc presel_feedback           true
_bc right_padding             0
_bc single_monocle            false
_bc split_ratio               0.50
_bc top_padding               25
_bc window_gap                8

#### BSPWM coloring ####

_bc normal_border_color	      "#1A2833"
_bc active_border_color       "#6D5782"
_bc focused_border_color      "#A39A90"
_bc urgent_border_color       "#00EFFF"
_bc presel_feedback_color     "#6C7480"

#### Applications rules & assignments ####

_br() {
    bspc rule -a "$@"
}

bspc rule -r "*"

declare -a float=(Nm-connection-editor Pavucontrol \
qt5ct Confirm URxvt:scratchpad)

for i in ${float[@]}; do
   bspc rule -a $i state=floating follow=on focus=on; done

# Assign Applications to specific workspaces & monitors
# Monitor 1

_br Geany               desktop='^1'  follow=on
_br firefox             desktop='^2'  follow=on
_br Pcmanfm             desktop='^3'  follow=on
_br File-roller         desktop='^3'  follow=on
_br feh                 desktop='^4'  follow=on
_br Zathura             desktop='^4'  follow=on
_br k3b                 desktop='^4'  follow=on
_br Nitrogen            desktop='^4'  follow=on state=floating
_br Fpm2                desktop='^5'  follow=on state=floating
_br Disks               desktop='^5'  follow=on
_br Gufw.py             desktop='^5'  follow=on state=floating
_br Easytag             desktop='^5'  follow=on
_br Gparted             desktop='^5'  follow=on state=floating
_br Pamac-manager       desktop='^5'  follow=on

# Monitor 2

_br URxvt:URxvt         desktop='^6'  follow=on
_br URxvt:htop          desktop='^6'  follow=on
_br URxvt:newsboat      desktop='^7'  follow=on
_br Five-or-more        desktop='^8'  follow=on state=floating
_br Sol                 desktop='^8'  follow=on state=floating
_br XTerm               desktop='^8'  follow=on
_br VirtualBox          desktop='^8'  follow=on
_br URxvt:ncmpcpp       desktop='^9'  follow=on
_br URxvt:ncpamixer     desktop='^9'  follow=on
_br URxvt:cmus          desktop='^9'  follow=on
_br URxvt:mpsyt         desktop='^10' follow=on
_br mpv                 desktop='^10' follow=on state=floating

_check() {
	command -v "$1" > /dev/null
}

_check bspwm_external_rules && \
    _bc external_rules_command \
        "$(command -v bspwm_external_rules)"

# polybar hidden when video applications get fullscreen.

xdo below -t $(xdo id -n root) $(xdo id -a polybar-bspwm-1-bar_HDMI-1)
xdo below -t $(xdo id -n root) $(xdo id -a polybar-bspwm-2-bar_DVI-D-1)

#### AUTOSTART ####

xsetroot -cursor_name left_ptr    # to get rid of the X cross pointer
sxhkd-start &
bspwm_polybar &

Sxhkd is also provided by the same developer and we can talk about it later if you wish.
Thanks for sharing your files here. :slightly_smiling_face:

Now let 's take a look at some sections:

  • Monitors.

bspc monitor HDMI-1 -d 1 2 3 4 5
bspc monitor DVI-D-1 -d 6 7 8 9 10

We have to define our monitors’ names by using the xrandr command, and the workspaces definition (-d) or desktops. Name can be whatever you want as long as you also list them in your bar config if you use one.

  • Desktop layouts.

bspc desktop 1 -l monocle
bspc desktop 2 -l monocle
bspc desktop 3 -l monocle
bspc desktop 5 -l monocle

Here I want desktops 1, 2, 3 & 5 to use the (-l) layout called ‘monocle’ as default. There is two of them, the other one is ‘tiled’.

  • bspc config

_bc() {
bspc config “$@”
}

This part is where we define general window configuration, easy to read. Again, if you look at the man-pages there is more to enable or disable.

  • bspc rules

_br() {
bspc rule -a “$@”
}

Here you place window rules, for example the size, placement and state. If you want specific assignment for applications on certain desktops.
You can also add more “complex” section for example small windows like: lxappearance, pavucontrol etc…

declare -a float=(Nm-connection-editor Pavucontrol \
qt5ct Confirm URxvt:scratchpad)

for i in ${float[@]}; do
   bspc rule -a $i state=floating follow=on focus=on; done 

But it is also possible to tell bspwm to take into account external rules refering to scripts, this way you can add MORE COMPLEX parts, that is the beauty of it.

_check() {
	command -v "$1" > /dev/null
}

_check bspwm_external_rules && \
    _bc external_rules_command \
        "$(command -v bspwm_external_rules)"

And finaly you can invoke commands (xdo) to manage things like polybar.

# polybar hidden when video applications get fullscreen.

xdo below -t $(xdo id -n root) $(xdo id -a polybar-bspwm-1-bar_HDMI-1)
xdo below -t $(xdo id -n root) $(xdo id -a polybar-bspwm-2-bar_DVI-D-1)

Now let’s talk about Sxhkd, the Simple X Hot Keys Daemon. Witch can be used as an applications launcher with some other window managers, this way we can keep common keybindings.
This tool also looks pretty straight simple and because of this, it is very extensible. For example I have divided its config in two files. The first one is dedicated to launch applications (sxhkdrc) and the second one is for window management (sxhkdrc_bspc). So I do:

sxhkd -c “$HOME”/.config/sxhkd/sxhkdrc{,_bspc} &

There are several ways to launch applications, eg:

super + f
   pcmanfm
super + ctrl + f
   firefox

But we should combine so as not to run out of key if we want to configure a lot of launchers.

super + {_, ctrl + } f
    {pcmanfm, firefox}

Another way is to chain with the semicolon sign. This tell sxhkd to listen our next pressed key, eg:

# URxvt applications
super + u ; {c,h,m,n,p,y}
	{ \
	urxvtc -name cmus -e cmus, \
	urxvtc -name htop -e htop -u archangel, \
	urxvtc -name ncmpcpp -e ncmpcpp -S clock --quiet, \
	urxvtc -name newsboat -e newsboat, \
	urxvtc -name ncpamixer -e ncpamixer, \
	urxvtc -name mpsyt -e mpsyt \
	}

So super + u , release the keys and then c for cmus, h for htop etc…
I also could use the colon signe [:] so sxhkd listens continuously until the Escape key is pressed, this way I launch apps one after the other with only one letter c, h, m, n etc…

All right guys, I hope some of you have been interested. :unamused: :sweat_smile:
As I said higher I will edit this post again with new features.
Feel free to correct me.

3 Likes

Top, thx for sharing @archus

hey altman how are you my dear, nice to see you here :smiley:

Not that bad on my end, nice to see you also !

Nice. I see a couple rules in there I may add.
Thanks for sharing.

Nice thread. I’ve only ever used bspwm in it’s basic form. Some nice ideas presented here.

@archus thanks for this information. It would be really good to see this expanded even further with more tricks from other users etc.