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