Hooks » History » Version 41
Version 40 (Anonymous, 12/15/2017 02:41 PM) → Version 41/47 (Christoph Kappel, 01/23/2018 12:07 PM)
h1. Hooks
{{>toc}}
[[Hooks]] Hooks\015\012\015\012{{>toc}}\015\012\015\012[[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 \015\012\015\012Generally 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">
# \015\012\015\012<pre>{{hide}}<code class="ruby">\015\012# A hook in the config
on config\015\012on :client_create do |c|
|c|\015\012 puts c.name #< Name of the client
end
# client\015\012end\015\012\015\012# A hook in a sublet
on sublet\015\012on :client_create do |s, c|
c|\015\012 puts s.name #< Name of the sublet
sublet\015\012 puts c.name #< Name of the client
end
</code></pre>
h2. client\015\012end\015\012</code></pre>\015\012\015\012h2. Client Hooks
h3. client_create
Triggers Hooks\015\012\015\012h3. client_create\015\012\015\012Triggers on creation of new clients.
<pre>{{subforge_hide}}<code class="ruby">
on clients.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_create do |c|
|c|\015\012 puts c.name
end
</code></pre>
h3. client_mode
Triggers c.name\015\012end\015\012</code></pre>\015\012\015\012h3. client_mode\015\012\015\012Triggers whenever a [[Clients#Modes|mode]] of a [[Clients|client]] is changed.
<pre>{{subforge_hide}}<code class="ruby">
on changed.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_mode do |c|
|c|\015\012 puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
end
</code></pre>
h3. client_gravity
Triggers urgent=#{c.is_urgent?}"\015\012end\015\012</code></pre>\015\012\015\012h3. client_gravity\015\012\015\012Triggers whenever a the [[gravity]] of a [[Clients|client]] is changed.
<pre>{{subforge_hide}}<code class="ruby">
on changed.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_focus do |c|
|c|\015\012 puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
end
</code></pre>
h3. client_focus
Triggers urgent=#{c.is_urgent?}"\015\012end\015\012</code></pre>\015\012\015\012h3. client_focus\015\012\015\012Triggers whenever a [[Clients|client]] gets focus.
<pre>{{subforge_hide}}<code class="ruby">
on focus.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_focus do |c|
|c|\015\012 puts c.name
end
</code></pre>
{{subforge_needs(r3255)}}
h3. client_rename
Triggers c.name\015\012end\015\012</code></pre>\015\012\015\012{{needs(r3255)}}\015\012\015\012h3. client_rename\015\012\015\012Triggers whenever a [[Clients|client]] is renamed.
<pre>{{subforge_hide}}<code class="ruby">
on renamed.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_rename do |c|
|c|\015\012 puts c.name
end
</code></pre>
h3. client_kill
Triggers c.name\015\012end\015\012</code></pre>\015\012\015\012h3. client_kill\015\012\015\012Triggers when a [[Clients|client]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on killed.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_kill do |c|
|c|\015\012 puts c.name
end
</code></pre>
h2. c.name\015\012end\015\012</code></pre>\015\012\015\012h2. Tag Hooks
h3. tag_create
Triggers Hooks\015\012\015\012h3. tag_create\015\012\015\012Triggers when a [[Tagging|tag]] is created.
<pre>{{subforge_hide}}<code class="ruby">
on created.\015\012<pre>{{hide}}<code class="ruby">\015\012on :tag_create do |t|
|t|\015\012 puts t.name
end
</code></pre>
h3. tag_kill
Triggers t.name\015\012end\015\012</code></pre>\015\012\015\012h3. tag_kill\015\012\015\012Triggers when a [[Tagging|tag]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on killed.\015\012<pre>{{hide}}<code class="ruby">\015\012on :tag_kill do |t|
|t|\015\012 puts t.name
end
</code></pre>
h2. t.name\015\012end\015\012</code></pre>\015\012\015\012h2. View Hooks
h3. view_create
Triggers Hooks\015\012\015\012h3. view_create\015\012\015\012Triggers on creation of new [[views]].
<pre>{{subforge_hide}}<code class="ruby">
on [[views]].\015\012<pre>{{hide}}<code class="ruby">\015\012on :view_create do |v|
|v|\015\012 puts v.name
end
</code></pre>
h3. view_focus
Triggers v.name\015\012end\015\012</code></pre>\015\012\015\012h3. view_focus\015\012\015\012Triggers on a switch to a [[Views|view]].
<pre>{{subforge_hide}}<code class="ruby">
on [[Views|view]].\015\012<pre>{{hide}}<code class="ruby">\015\012on :view_focus do |v|
|v|\015\012 puts v.name
end
</code></pre>
h3. view_kill
Triggers v.name\015\012end\015\012</code></pre>\015\012\015\012h3. view_kill\015\012\015\012Triggers when a [[Views|view]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on killed.\015\012<pre>{{hide}}<code class="ruby">\015\012on :view_kill do |v|
|v|\015\012 puts v.name
end
</code></pre>
h2. Other
h3. start
Triggers v.name\015\012end\015\012</code></pre>\015\012\015\012h2. Other\015\012\015\012h3. start\015\012\015\012Triggers on start
<pre>{{subforge_hide}}<code class="ruby">
on start\015\012<pre>{{hide}}<code class="ruby">\015\012on :start do
do\015\012 puts "Yees"
end
</code></pre>
h3. exit
Triggers "Yees"\015\012end\015\012</code></pre>\015\012\015\012h3. exit\015\012\015\012Triggers on exit
<pre>{{subforge_hide}}<code class="ruby">
on exit\015\012<pre>{{hide}}<code class="ruby">\015\012on :exit do
do\015\012 puts "Nooo"
end
</code></pre>
h3. tile
Triggers "Nooo"\015\012end\015\012</code></pre>\015\012\015\012h3. tile\015\012\015\012Triggers whenever tiling would be needed
<pre>{{subforge_hide}}<code class="ruby">
on needed\015\012<pre>{{hide}}<code class="ruby">\015\012on :tile do
\015\012 puts "Insert tiling here"
end
</code></pre>
h3. reload
Triggers here"\015\012end\015\012</code></pre>\015\012\015\012h3. reload\015\012\015\012Triggers whenever subtle was reloaded
<pre>{{subforge_hide}}<code class="ruby">
on reloaded\015\012<pre>{{hide}}<code class="ruby">\015\012on :reload do
\015\012 puts "Reloaded config"
end
</code></pre>
h2. Examples
Switch config"\015\012end\015\012</code></pre>\015\012\015\012h2. Examples\015\012\015\012Switch to the first view of new client
<pre>{{subforge_hide}}<code class="ruby">
on client\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_create do |c|
c.views.first.jump
end
</code></pre>
Tag |c|\015\012 c.views.first.jump\015\012end\015\012</code></pre>\015\012\015\012Tag a new [[Clients|client]] with the current [[Views|view]] only if it has no other [[Tagging|tags]]
<pre>{{subforge_hide}}<code class="ruby">
on [[Tagging|tags]]\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_create do |c|
|c|\015\012 cur = Subtlext::View.current
Subtlext::View.current\015\012\015\012 # Check for empty tags
if(c.tags.empty?)
tags\015\012 if(c.tags.empty?)\015\012 t = Subtlext::Tag[cur.name] rescue nil
nil\015\012\015\012 # Create new tag
if(t.nil?)
tag\015\012 if(t.nil?)\015\012 t = Subtlext::Tag.new(cur.name)
t.save
Subtlext::Tag.new(cur.name)\015\012 t.save\015\012 end
\015\012\015\012 c + t
end
end
</code></pre> t\015\012 end\015\012end\015\012</code></pre>
{{>toc}}
[[Hooks]] Hooks\015\012\015\012{{>toc}}\015\012\015\012[[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 \015\012\015\012Generally 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">
# \015\012\015\012<pre>{{hide}}<code class="ruby">\015\012# A hook in the config
on config\015\012on :client_create do |c|
|c|\015\012 puts c.name #< Name of the client
end
# client\015\012end\015\012\015\012# A hook in a sublet
on sublet\015\012on :client_create do |s, c|
c|\015\012 puts s.name #< Name of the sublet
sublet\015\012 puts c.name #< Name of the client
end
</code></pre>
h2. client\015\012end\015\012</code></pre>\015\012\015\012h2. Client Hooks
h3. client_create
Triggers Hooks\015\012\015\012h3. client_create\015\012\015\012Triggers on creation of new clients.
<pre>{{subforge_hide}}<code class="ruby">
on clients.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_create do |c|
|c|\015\012 puts c.name
end
</code></pre>
h3. client_mode
Triggers c.name\015\012end\015\012</code></pre>\015\012\015\012h3. client_mode\015\012\015\012Triggers whenever a [[Clients#Modes|mode]] of a [[Clients|client]] is changed.
<pre>{{subforge_hide}}<code class="ruby">
on changed.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_mode do |c|
|c|\015\012 puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
end
</code></pre>
h3. client_gravity
Triggers urgent=#{c.is_urgent?}"\015\012end\015\012</code></pre>\015\012\015\012h3. client_gravity\015\012\015\012Triggers whenever a the [[gravity]] of a [[Clients|client]] is changed.
<pre>{{subforge_hide}}<code class="ruby">
on changed.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_focus do |c|
|c|\015\012 puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
end
</code></pre>
h3. client_focus
Triggers urgent=#{c.is_urgent?}"\015\012end\015\012</code></pre>\015\012\015\012h3. client_focus\015\012\015\012Triggers whenever a [[Clients|client]] gets focus.
<pre>{{subforge_hide}}<code class="ruby">
on focus.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_focus do |c|
|c|\015\012 puts c.name
end
</code></pre>
{{subforge_needs(r3255)}}
h3. client_rename
Triggers c.name\015\012end\015\012</code></pre>\015\012\015\012{{needs(r3255)}}\015\012\015\012h3. client_rename\015\012\015\012Triggers whenever a [[Clients|client]] is renamed.
<pre>{{subforge_hide}}<code class="ruby">
on renamed.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_rename do |c|
|c|\015\012 puts c.name
end
</code></pre>
h3. client_kill
Triggers c.name\015\012end\015\012</code></pre>\015\012\015\012h3. client_kill\015\012\015\012Triggers when a [[Clients|client]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on killed.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_kill do |c|
|c|\015\012 puts c.name
end
</code></pre>
h2. c.name\015\012end\015\012</code></pre>\015\012\015\012h2. Tag Hooks
h3. tag_create
Triggers Hooks\015\012\015\012h3. tag_create\015\012\015\012Triggers when a [[Tagging|tag]] is created.
<pre>{{subforge_hide}}<code class="ruby">
on created.\015\012<pre>{{hide}}<code class="ruby">\015\012on :tag_create do |t|
|t|\015\012 puts t.name
end
</code></pre>
h3. tag_kill
Triggers t.name\015\012end\015\012</code></pre>\015\012\015\012h3. tag_kill\015\012\015\012Triggers when a [[Tagging|tag]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on killed.\015\012<pre>{{hide}}<code class="ruby">\015\012on :tag_kill do |t|
|t|\015\012 puts t.name
end
</code></pre>
h2. t.name\015\012end\015\012</code></pre>\015\012\015\012h2. View Hooks
h3. view_create
Triggers Hooks\015\012\015\012h3. view_create\015\012\015\012Triggers on creation of new [[views]].
<pre>{{subforge_hide}}<code class="ruby">
on [[views]].\015\012<pre>{{hide}}<code class="ruby">\015\012on :view_create do |v|
|v|\015\012 puts v.name
end
</code></pre>
h3. view_focus
Triggers v.name\015\012end\015\012</code></pre>\015\012\015\012h3. view_focus\015\012\015\012Triggers on a switch to a [[Views|view]].
<pre>{{subforge_hide}}<code class="ruby">
on [[Views|view]].\015\012<pre>{{hide}}<code class="ruby">\015\012on :view_focus do |v|
|v|\015\012 puts v.name
end
</code></pre>
h3. view_kill
Triggers v.name\015\012end\015\012</code></pre>\015\012\015\012h3. view_kill\015\012\015\012Triggers when a [[Views|view]] is killed.
<pre>{{subforge_hide}}<code class="ruby">
on killed.\015\012<pre>{{hide}}<code class="ruby">\015\012on :view_kill do |v|
|v|\015\012 puts v.name
end
</code></pre>
h2. Other
h3. start
Triggers v.name\015\012end\015\012</code></pre>\015\012\015\012h2. Other\015\012\015\012h3. start\015\012\015\012Triggers on start
<pre>{{subforge_hide}}<code class="ruby">
on start\015\012<pre>{{hide}}<code class="ruby">\015\012on :start do
do\015\012 puts "Yees"
end
</code></pre>
h3. exit
Triggers "Yees"\015\012end\015\012</code></pre>\015\012\015\012h3. exit\015\012\015\012Triggers on exit
<pre>{{subforge_hide}}<code class="ruby">
on exit\015\012<pre>{{hide}}<code class="ruby">\015\012on :exit do
do\015\012 puts "Nooo"
end
</code></pre>
h3. tile
Triggers "Nooo"\015\012end\015\012</code></pre>\015\012\015\012h3. tile\015\012\015\012Triggers whenever tiling would be needed
<pre>{{subforge_hide}}<code class="ruby">
on needed\015\012<pre>{{hide}}<code class="ruby">\015\012on :tile do
\015\012 puts "Insert tiling here"
end
</code></pre>
h3. reload
Triggers here"\015\012end\015\012</code></pre>\015\012\015\012h3. reload\015\012\015\012Triggers whenever subtle was reloaded
<pre>{{subforge_hide}}<code class="ruby">
on reloaded\015\012<pre>{{hide}}<code class="ruby">\015\012on :reload do
\015\012 puts "Reloaded config"
end
</code></pre>
h2. Examples
Switch config"\015\012end\015\012</code></pre>\015\012\015\012h2. Examples\015\012\015\012Switch to the first view of new client
<pre>{{subforge_hide}}<code class="ruby">
on client\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_create do |c|
c.views.first.jump
end
</code></pre>
Tag |c|\015\012 c.views.first.jump\015\012end\015\012</code></pre>\015\012\015\012Tag a new [[Clients|client]] with the current [[Views|view]] only if it has no other [[Tagging|tags]]
<pre>{{subforge_hide}}<code class="ruby">
on [[Tagging|tags]]\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_create do |c|
|c|\015\012 cur = Subtlext::View.current
Subtlext::View.current\015\012\015\012 # Check for empty tags
if(c.tags.empty?)
tags\015\012 if(c.tags.empty?)\015\012 t = Subtlext::Tag[cur.name] rescue nil
nil\015\012\015\012 # Create new tag
if(t.nil?)
tag\015\012 if(t.nil?)\015\012 t = Subtlext::Tag.new(cur.name)
t.save
Subtlext::Tag.new(cur.name)\015\012 t.save\015\012 end
\015\012\015\012 c + t
end
end
</code></pre> t\015\012 end\015\012end\015\012</code></pre>