Project

General

Profile

unexist.dev

Assorted tidbits and projects

Hooks

Hooks are small blocks of code (Ruby procs or lambdas) that can be called on certain events of the window manager. Many hooks get a subtlext object matching to the type hook, like a client object for the client_create hook.

Generally all hooks can either be used in the config or in a sublet, just the number of arguments varies: Inside of the config hooks have one argument, a hook inside of a sublets has an additional argument - the instance of the sublet itself and this will always be the first argument.

# A hook in the config
on :client_create do |c|
  puts c.name #< Name of the client
end

# A hook in a sublet
on :client_create do |s, c|
  puts s.name #< Name of the sublet
  puts c.name #< Name of the client
end

Client Hooks

client_create

Triggers on creation of new clients.

on :client_create do |c|
  puts c.name
end

client_mode

Triggers whenever a mode of a client is changed.

on :client_mode do |c|
  puts "client=#{c.instance}, urgent=#{c.is_urgent?}" 
end

client_gravity

Triggers whenever a the gravity of a client is changed.

on :client_focus do |c|
  puts "client=#{c.instance}, urgent=#{c.is_urgent?}" 
end

client_focus

Triggers whenever a client gets focus.

on :client_focus do |c|
  puts c.name
end

Error executing the subforge_needs macro (no implicit conversion of nil into String)

client_rename

Triggers whenever a client is renamed.

on :client_rename do |c|
  puts c.name
end

client_kill

Triggers when a client is killed.

on :client_kill do |c|
  puts c.name
end

Tag Hooks

tag_create

Triggers when a tag is created.

on :tag_create do |t|
  puts t.name
end

tag_kill

Triggers when a tag is killed.

on :tag_kill do |t|
  puts t.name
end

View Hooks

view_create

Triggers on creation of new views.

on :view_create do |v|
  puts v.name
end

view_focus

Triggers on a switch to a view.

on :view_focus do |v|
  puts v.name
end

view_kill

Triggers when a view is killed.

on :view_kill do |v|
  puts v.name
end

Other

start

Triggers on start

on :start do
  puts "Yees" 
end

exit

Triggers on exit

on :exit do
  puts "Nooo" 
end

tile

Triggers whenever tiling would be needed

on :tile do 
  puts "Insert tiling here" 
end

reload

Triggers whenever subtle was reloaded

on :reload do 
  puts "Reloaded config" 
end

Examples

Switch to the first view of new client

on :client_create do |c|
  c.views.first.jump
end

Tag a new client with the current view only if it has no other tags

on :client_create do |c|
  cur = Subtlext::View.current

  # Check for empty tags
  if(c.tags.empty?)
    t = Subtlext::Tag[cur.name] rescue nil

    # Create new tag
    if(t.nil?)
      t = Subtlext::Tag.new(cur.name)
      t.save
    end 

    c + t
  end
end