BSPWM rules

In my bspwmrc file, I have the following line

Blockquote
bspec rule -a Gimp desktop=‘^8’ state=floating follow=on
Blockquote

This line is supposed to open Gimp in workspace/desktop 8 among other things. But Gimp opens in my current desktop, not desktop 8.

Looking at man bspc, the first entry after -a should be the <class_name>. Using xprop, the class_name for Gimp is Gimp-2.10. When I change the rule to use Gimp-2.10, then Gimp opens correctly in desktop 8.

I also tried using Gimp-* and Gimp* for class_name, to cater for subsequent gimp updates. That didn’t work. Gimp was back to opening in the current desktop.

I can leave Gimp-2.10 in the bspwmrc, but I would like to have the best of both worlds. How would I modify the class_name so that Gimp-2.10 and Gimp-2.11 open on desktop 8?

PS I am brand new to BSPWM and bspc

Are ’ ’ needed?

Try:

bspc rule -a Gimp desktop=^8 follow=on state=floating

:eye: https://wiki.archlinux.org/title/Bspwm#Rules

Thanks for responding, pebcak.

Changing ‘^8’ to ^8 in the rule line in question does not make the rule work with class_name of Gimp.

There are other rules, like one for firefox that uses ‘^2’ that works as expected. But that rule has the class_name correctly as firefox.

I really think the problem is down to a rule needing the exact class_name, as I haven’t found a way to partial match like Gimp*. I’m hoping there is a way to do that

1 Like

Using an external_rules file is more flexible.
Check this out.

When I find some time, I could post my external_rules file as an example.

Edit: Here you are, although I am no expert and some mistakes might exist. Use after experimentation

#!/bin/bash
## man bspc:  external_rules_command
## Absolute path to the command used to retrieve rule consequences.
## The command will receive the following arguments:
## window ID, class, name, instance name, and intermediate consequences.
## The output of that command must have the following format:
## key1=value1 key2=value2 ...
## (the valid key/value pairs are given in the description of the rule command).

## https://github.com/baskerville/bspwm/issues/1370
winID=$1
class=${2,,}
wname=${3,,}
instance=$4
sequences=$5

# Log for debugging
# echo -en "$winID\t$class\t$wname\t$instance\t$sequences\n" >> .cache/bspwm-session.log

case "$wname" in
  megasync|megasync-*)
    printf 'state=floating\n'
    ;;
  *) if [ "$class" = "megasync" ]; then
      printf 'state=floating\n'
    fi
    ;;
esac

# if the class name is "Qemu-system" or "Qemu-system-something", and the
#  instance name is "qemu", apply `state=floating`
case $class in
  firefox)
    if [ $(xprop -id $winID WM_WINDOW_ROLE | cut -d= -f2 | tr -d [[:punct:]]) = "browser" ] ; then
      printf 'state=tiled\n'
    else
      printf 'state=floating\n'
    fi
    ;;
    qemu-system|qemu-system*)
    [ "$instance" = qemu ] && printf 'state=floating\n'
    ;;
    gimp)
    printf 'state=floating\n'
    ;;
  evolution-alarm-notify)
    printf 'state=floating\n'
    ;;
  pavucontrol)
    printf 'state=floating\n'
    ;;
  megasync|"megasync-"*)
    printf 'state=floating\n'
    ;;
  mplayer2)
    printf 'state=floating\n'
    ;;
  arandr)
    printf 'state=floating\n'
    ;;
  uget)
    printf 'state=floating\n'
    ;;
  yad)
    printf 'state=floating\n'
    ;;
  'kupfer.py')
    printf 'focus=on\n'
    ;;
  screenkey)
    printf 'manage=off\n'
    ;;
esac
2 Likes