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.

Numbers: on /off 1 # A hook in the config
 2 on :client_create do |c|
 3   puts c.name #< Name of the client
 4 end
 5 
 6 # A hook in a sublet
 7 on :client_create do |s, c|
 8   puts s.name #< Name of the sublet
 9   puts c.name #< Name of the client
10 end

Client Hooks

client_create

Triggers on creation of new clients.

Numbers: on /off1 on :client_create do |c|
2   puts c.name
3 end

client_gravity

Triggers whenever a the gravity of a client is changed.

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

r2909

client_mode

Triggers whenever a mode of a client is changed.

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

client_focus

Triggers whenever a client gets focus.

Numbers: on /off1 on :client_focus do |c|
2   puts c.name
3 end

client_kill

Triggers when a client is killed.

Numbers: on /off1 on :client_kill do |c|
2   puts c.name
3 end

Tag Hooks

tag_create

Triggers when a tag is created.

Numbers: on /off1 on :tag_create do |t|
2   puts t.name
3 end

tag_kill

Triggers when a tag is killed.

Numbers: on /off1 on :tag_kill do |t|
2   puts t.name
3 end

View Hooks

view_create

Triggers on creation of new views.

Numbers: on /off1 on :view_create do |v|
2   puts v.name
3 end

view_focus

Triggers on a switch to a view.

Numbers: on /off1 on :view_focus do |v|
2   puts v.name
3 end

view_kill

Triggers when a view is killed.

Numbers: on /off1 on :view_kill do |v|
2   puts v.name
3 end

Other

tile

Triggers whenever tiling would be needed

Numbers: on /off1 on :tile do 
2   puts "Insert tiling here" 
3 end

reload

Triggers whenever subtle was reloaded

Numbers: on /off1 on :reload do 
2   puts "Reloaded config" 
3 end

start

Triggers on start

Numbers: on /off1 on :start do
2   puts "Yees" 
3 end

exit

Triggers on exit

Numbers: on /off1 on :exit do
2   puts "Nooo" 
3 end

Examples

Switch to the first view of new client

Numbers: on /off1 on :client_create do |c|
2   c.views.first.jump
3 end

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

Numbers: on /off 1 on :client_create do |c|
 2   cur = Subtlext::View.current
 3 
 4   # Check for empty tags
 5   if(c.tags.empty?)
 6     t = Subtlext::Tag[cur.name] rescue nil
 7 
 8     # Create new tag
 9     if(t.nil?)
10       t = Subtlext::Tag.new(cur.name)
11       t.save
12     end 
13 
14     c + t
15   end
16 end