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 an object matching to the type hook, like a client object for the client_create hook. Generally all hooks can be either used inside of the config or in a sublet.

The only difference is that when a hook inside of the config can 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. Many Hooks get a subtlext object as argument to interact, but all the subtlext stuff is possible - docs about this can be found in rdoc.

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_configure

Triggers whenever a client is configured.

Numbers: on /off1 on :client_focus do |c|
2   puts c.name
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_configure

Triggers whenever a view is configured.

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

view_jump

Triggers on a jump to a view.

Numbers: on /off1 on :view_jump 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

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 /offcode class="ruby">
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

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