Hooks » History » Version 43
    « Previous - 
    Version 43/47
    (diff) - 
    Next » - 
    Current version
    
    Christoph Kappel, 01/23/2018 12:12 PM 
    
    
Hooks¶
{{>toc}}nnnnn
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.
{{subforge_toggle_numbers}}# 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.
{{subforge_toggle_numbers}}on :client_create do |c|
  puts c.name
end
	
client_mode¶
Triggers whenever a mode of a client is changed.
{{subforge_toggle_numbers}}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.
{{subforge_toggle_numbers}}on :client_focus do |c|
  puts "client=#{c.instance}, urgent=#{c.is_urgent?}" 
end
	
client_focus¶
Triggers whenever a client gets focus.
{{subforge_toggle_numbers}}on :client_focus do |c|
  puts c.name
end
	client_rename¶
Triggers whenever a client is renamed.
{{subforge_toggle_numbers}}on :client_rename do |c|
  puts c.name
end
	
client_kill¶
Triggers when a client is killed.
{{subforge_toggle_numbers}}on :client_kill do |c|
  puts c.name
end
	
Tag Hooks¶
tag_create¶
Triggers when a tag is created.
{{subforge_toggle_numbers}}on :tag_create do |t|
  puts t.name
end
	
tag_kill¶
Triggers when a tag is killed.
{{subforge_toggle_numbers}}on :tag_kill do |t|
  puts t.name
end
	
View Hooks¶
view_create¶
Triggers on creation of new views.
{{subforge_toggle_numbers}}on :view_create do |v|
  puts v.name
end
	
view_focus¶
Triggers on a switch to a view.
{{subforge_toggle_numbers}}on :view_focus do |v|
  puts v.name
end
	
view_kill¶
Triggers when a view is killed.
{{subforge_toggle_numbers}}on :view_kill do |v|
  puts v.name
end
	
Other¶
start¶
Triggers on start
{{subforge_toggle_numbers}}on :start do
  puts "Yees" 
end
	
exit¶
Triggers on exit
{{subforge_toggle_numbers}}on :exit do
  puts "Nooo" 
end
	
tile¶
Triggers whenever tiling would be needed
{{subforge_toggle_numbers}}on :tile do 
  puts "Insert tiling here" 
end
	
reload¶
Triggers whenever subtle was reloaded
{{subforge_toggle_numbers}}on :reload do 
  puts "Reloaded config" 
end
	
Examples¶
Switch to the first view of new client
{{subforge_toggle_numbers}}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
{{subforge_toggle_numbers}}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