Project

General

Profile

unexist.dev

subtle

Assorted tidbits and projects

Tags with logic

Logic, wat?
Added by Christoph Kappel almost 12 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:

tag "gimp_image" do
  match    role: "gimp-image-window" 
  gravity  :gimp_image
end

tag "gimp_toolbox" do
  match    role: "gimp-toolbox$" 
  gravity  :gimp_toolbox
end

tag "gimp_dock" do
  match    role: "gimp-dock" 
  gravity  :gimp_dock
end

tag "gimp_scum" do
  match role: "gimp-.*|screenshot" 
end


New way:

tag "gimp" do
  match role: "gimp-.*" 

  on_match do |c|
    c.gravity = ("gimp_" + c.role.split("-")[1]).to_sym
  end
end

Both basically just sets the gravity of the matching client.


Comments