Tags with logic

Logic, wat?
Added by Christoph Kappel about 5 years ago

Sometimes it can be pretty nasty to add tags, when you just need something stupid to move a certain window to a view. That can be done with a loop, but that also adds lots of tags and there cannot be more than 32 of them.

An easy way to bypass this is to add logic to tags and act differently for certain clients. The latest version of subtle extends the properties with on_match. This can be used to add a Ruby proc to a tag that is called whenever the tag is applied.

The tagging page already contains a simple example, here is a more complex one that I use in my config to tag GIMP windows:

Old way:

 1 tag "gimp_image" do
 2   match    role: "gimp-image-window" 
 3   gravity  :gimp_image
 4 end
 6 tag "gimp_toolbox" do
 7   match    role: "gimp-toolbox$" 
 8   gravity  :gimp_toolbox
 9 end
11 tag "gimp_dock" do
12   match    role: "gimp-dock" 
13   gravity  :gimp_dock
14 end
16 tag "gimp_scum" do
17   match role: "gimp-.*|screenshot" 
18 end

New way:

1 tag "gimp" do
2   match role: "gimp-.*" 
4   on_match do |c|
5     c.gravity = ("gimp_" + c.role.split("-")[1]).to_sym
6   end
7 end

Both basically just sets the gravity of the matching client.