Hooks » History » Version 42
Version 41 (Christoph Kappel, 01/23/2018 12:07 PM) → Version 42/47 (Christoph Kappel, 01/23/2018 12:08 PM)
h1. Hooks
{{>toc}}nnnnn {{>toc}}
[[Hooks]] are small blocks of code ("Ruby":http://www.ruby-lang.org procs or lambdas) that can be called on certain events of the window manager. Many [[hooks]] get a [[subtlext]] object matching to the type [[hooks|hook]], like a [[Clients|client]] object for the _client_create_ [[hooks|hook]].
Generally all [[hooks]] can either be used in the config or in a [[sublets|sublet]], just the number of arguments varies: Inside of the config [[hooks]] have one argument, a [[hooks|hook]] inside of a [[sublets|sublets]] has an additional argument - the instance of the [[sublets|sublet]] itself and this will always be the first argument.
<pre>{{subforge_hide}}<code class="ruby">
# 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
</code></pre>
h2. Client Hooks
h3. client_create
Triggers on creation of new clients.
<pre>{{subforge_hide}}<code class="ruby">
on :client_create do |c|
puts c.name
end
</code></pre>
h3. client_mode
Triggers whenever a [[Clients#Modes|mode]] of a [[Clients|client]] is changed.
<pre>{{subforge_hide}}<code class="ruby">
on :client_mode do |c|
puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
end
</code></pre>
h3. client_gravity
Triggers whenever a the [[gravity]] of a [[Clients|client]] is changed.
<pre>{{subforge_hide}}<code class="ruby">
on :client_focus do |c|
puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
end
</code></pre>
h3. client_focus
Triggers whenever a [[Clients|client]] gets focus.
<pre>{{subforge_hide}}<code class="ruby">
on :client_focus do |c|
puts c.name
end
</code></pre>
{{subforge_needs(r3255)}}
h3. client_rename
Triggers whenever a [[Clients|client]] is renamed.
<pre>{{subforge_hide}}<code class="ruby">
on :client_rename do |c|
puts c.name
end
</code></pre>
h3. client_kill
Triggers when a [[Clients|client]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on :client_kill do |c|
puts c.name
end
</code></pre>
h2. Tag Hooks
h3. tag_create
Triggers when a [[Tagging|tag]] is created.
<pre>{{subforge_hide}}<code class="ruby">
on :tag_create do |t|
puts t.name
end
</code></pre>
h3. tag_kill
Triggers when a [[Tagging|tag]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on :tag_kill do |t|
puts t.name
end
</code></pre>
h2. View Hooks
h3. view_create
Triggers on creation of new [[views]].
<pre>{{subforge_hide}}<code class="ruby">
on :view_create do |v|
puts v.name
end
</code></pre>
h3. view_focus
Triggers on a switch to a [[Views|view]].
<pre>{{subforge_hide}}<code class="ruby">
on :view_focus do |v|
puts v.name
end
</code></pre>
h3. view_kill
Triggers when a [[Views|view]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on :view_kill do |v|
puts v.name
end
</code></pre>
h2. Other
h3. start
Triggers on start
<pre>{{subforge_hide}}<code class="ruby">
on :start do
puts "Yees"
end
</code></pre>
h3. exit
Triggers on exit
<pre>{{subforge_hide}}<code class="ruby">
on :exit do
puts "Nooo"
end
</code></pre>
h3. tile
Triggers whenever tiling would be needed
<pre>{{subforge_hide}}<code class="ruby">
on :tile do
puts "Insert tiling here"
end
</code></pre>
h3. reload
Triggers whenever subtle was reloaded
<pre>{{subforge_hide}}<code class="ruby">
on :reload do
puts "Reloaded config"
end
</code></pre>
h2. Examples
Switch to the first view of new client
<pre>{{subforge_hide}}<code class="ruby">
on :client_create do |c|
c.views.first.jump
end
</code></pre>
Tag a new [[Clients|client]] with the current [[Views|view]] only if it has no other [[Tagging|tags]]
<pre>{{subforge_hide}}<code class="ruby">
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
</code></pre>
{{>toc}}nnnnn {{>toc}}
[[Hooks]] are small blocks of code ("Ruby":http://www.ruby-lang.org procs or lambdas) that can be called on certain events of the window manager. Many [[hooks]] get a [[subtlext]] object matching to the type [[hooks|hook]], like a [[Clients|client]] object for the _client_create_ [[hooks|hook]].
Generally all [[hooks]] can either be used in the config or in a [[sublets|sublet]], just the number of arguments varies: Inside of the config [[hooks]] have one argument, a [[hooks|hook]] inside of a [[sublets|sublets]] has an additional argument - the instance of the [[sublets|sublet]] itself and this will always be the first argument.
<pre>{{subforge_hide}}<code class="ruby">
# 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
</code></pre>
h2. Client Hooks
h3. client_create
Triggers on creation of new clients.
<pre>{{subforge_hide}}<code class="ruby">
on :client_create do |c|
puts c.name
end
</code></pre>
h3. client_mode
Triggers whenever a [[Clients#Modes|mode]] of a [[Clients|client]] is changed.
<pre>{{subforge_hide}}<code class="ruby">
on :client_mode do |c|
puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
end
</code></pre>
h3. client_gravity
Triggers whenever a the [[gravity]] of a [[Clients|client]] is changed.
<pre>{{subforge_hide}}<code class="ruby">
on :client_focus do |c|
puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
end
</code></pre>
h3. client_focus
Triggers whenever a [[Clients|client]] gets focus.
<pre>{{subforge_hide}}<code class="ruby">
on :client_focus do |c|
puts c.name
end
</code></pre>
{{subforge_needs(r3255)}}
h3. client_rename
Triggers whenever a [[Clients|client]] is renamed.
<pre>{{subforge_hide}}<code class="ruby">
on :client_rename do |c|
puts c.name
end
</code></pre>
h3. client_kill
Triggers when a [[Clients|client]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on :client_kill do |c|
puts c.name
end
</code></pre>
h2. Tag Hooks
h3. tag_create
Triggers when a [[Tagging|tag]] is created.
<pre>{{subforge_hide}}<code class="ruby">
on :tag_create do |t|
puts t.name
end
</code></pre>
h3. tag_kill
Triggers when a [[Tagging|tag]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on :tag_kill do |t|
puts t.name
end
</code></pre>
h2. View Hooks
h3. view_create
Triggers on creation of new [[views]].
<pre>{{subforge_hide}}<code class="ruby">
on :view_create do |v|
puts v.name
end
</code></pre>
h3. view_focus
Triggers on a switch to a [[Views|view]].
<pre>{{subforge_hide}}<code class="ruby">
on :view_focus do |v|
puts v.name
end
</code></pre>
h3. view_kill
Triggers when a [[Views|view]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on :view_kill do |v|
puts v.name
end
</code></pre>
h2. Other
h3. start
Triggers on start
<pre>{{subforge_hide}}<code class="ruby">
on :start do
puts "Yees"
end
</code></pre>
h3. exit
Triggers on exit
<pre>{{subforge_hide}}<code class="ruby">
on :exit do
puts "Nooo"
end
</code></pre>
h3. tile
Triggers whenever tiling would be needed
<pre>{{subforge_hide}}<code class="ruby">
on :tile do
puts "Insert tiling here"
end
</code></pre>
h3. reload
Triggers whenever subtle was reloaded
<pre>{{subforge_hide}}<code class="ruby">
on :reload do
puts "Reloaded config"
end
</code></pre>
h2. Examples
Switch to the first view of new client
<pre>{{subforge_hide}}<code class="ruby">
on :client_create do |c|
c.views.first.jump
end
</code></pre>
Tag a new [[Clients|client]] with the current [[Views|view]] only if it has no other [[Tagging|tags]]
<pre>{{subforge_hide}}<code class="ruby">
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
</code></pre>