Project

General

Profile

unexist.dev

Assorted tidbits and projects

Hooks » History » Version 34

Version 33 (Anonymous, 01/09/2011 04:24 PM) → Version 34/47 (Anonymous, 06/24/2011 04:41 PM)

h1. 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]] an object matching to the type [[hooks|hook]], like a [[Clients|client]] client object for the _client_create_ [[hooks|hook]]. \015\012\015\012Generally Generally all [[hooks]] can be either be used in inside of the config or in a [[sublets|sublet]], just the number [[sublets|sublet]].\015\012\015\012The only difference is that when a [[hooks|hook]] inside of arguments varies: Inside of the config [[hooks]] can 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. \015\012\015\012<pre>{{hide}}<code 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":http://subforge.org/tab/show/subtle?tabid=0.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012# A hook in the config\015\012on :client_create do |c|\015\012 puts c.name #< Name of the client\015\012end\015\012\015\012# A hook in a sublet\015\012on :client_create do |s, c|\015\012 puts s.name #< Name of the sublet\015\012 puts c.name #< Name of the client\015\012end\015\012</code></pre>\015\012\015\012h2. Client Hooks\015\012\015\012h3. client_create\015\012\015\012Triggers on creation of new clients.\015\012\015\012<pre>{{hide}}<code clients.\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_create do |c|\015\012 puts c.name\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.\015\012\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_focus do |c|\015\012 puts "client=#{c.instance}, urgent=#{c.is_urgent?}"\015\012end\015\012</code></pre>\015\012\015\012h3. client_mode\015\012\015\012Triggers whenever a [[Clients#Modes|mode}} mode of a [[Clients|client]] client is changed.\015\012\015\012<pre>{{hide}}<code changed.\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_focus do |c|\015\012 puts "client=#{c.instance}, urgent=#{c.is_urgent?}"\015\012end\015\012</code></pre>\015\012\015\012h3. c.name\015\012end\015\012</code></pre>\015\012\015\012h3. client_focus\015\012\015\012Triggers whenever a [[Clients|client]] client gets focus.\015\012\015\012<pre>{{hide}}<code focus.\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_focus do |c|\015\012 puts c.name\015\012end\015\012</code></pre>\015\012\015\012h3. client_kill\015\012\015\012Triggers when a [[Clients|client]] client is killed.\015\012\015\012<pre>{{hide}}<code killed.\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_kill do |c|\015\012 puts c.name\015\012end\015\012</code></pre>\015\012\015\012h2. Tag Hooks\015\012\015\012h3. tag_create\015\012\015\012Triggers when a [[Tagging|tag]] tag is created.\015\012<pre>{{hide}}<code class="ruby">\015\012on :tag_create do |t|\015\012 puts t.name\015\012end\015\012</code></pre>\015\012\015\012h3. tag_kill\015\012\015\012Triggers when a [[Tagging|tag]] tag is killed.\015\012<pre>{{hide}}<code class="ruby">\015\012on :tag_kill do |t|\015\012 puts t.name\015\012end\015\012</code></pre>\015\012\015\012h2. View Hooks\015\012\015\012h3. view_create\015\012\015\012Triggers on creation of new [[views]].\015\012<pre>{{hide}}<code views.\015\012<pre>{{hide}}<code class="ruby">\015\012on :view_create do |v|\015\012 puts v.name\015\012end\015\012</code></pre>\015\012\015\012h3. view_jump\015\012\015\012Triggers on a jump to a [[Views|view]].\015\012<pre>{{hide}}<code view.\015\012<pre>{{hide}}<code class="ruby">\015\012on :view_jump do |v|\015\012 puts v.name\015\012end\015\012</code></pre>\015\012\015\012h3. view_kill\015\012\015\012Triggers when a [[Views|view]] view is killed.\015\012<pre>{{hide}}<code class="ruby">\015\012on :view_kill do |v|\015\012 puts v.name\015\012end\015\012</code></pre>\015\012\015\012h2. Other\015\012\015\012h3. tile\015\012\015\012Triggers whenever tiling would be needed\015\012<pre>{{hide}}<code class="ruby">\015\012on :tile do \015\012 puts "Insert tiling here"\015\012end\015\012</code></pre>\015\012\015\012h3. reload\015\012\015\012Triggers whenever subtle was reloaded\015\012<pre>{{hide}}<code class="ruby">\015\012on :reload do \015\012 puts "Reloaded config"\015\012end\015\012</code></pre>\015\012\015\012h3. start\015\012\015\012Triggers on start\015\012<pre>{{hide}}<code class="ruby">\015\012on :start do\015\012 puts "Yees"\015\012end\015\012</code></pre>\015\012\015\012h3. exit\015\012\015\012Triggers on exit\015\012<pre>{{hide}}<code class="ruby">\015\012on :exit do\015\012 puts "Nooo"\015\012end\015\012</code></pre>\015\012\015\012h2. Examples\015\012\015\012Switch to the first view of new client\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_create do |c|\015\012 c.views.first.jump\015\012end\015\012</code></pre>\015\012\015\012Tag a new [[Clients|client]] client with the current [[Views|view]] view only if it has no other [[Tagging|tags]]\015\012<pre>{{hide}}<code tags\015\012<pre>{{hide}}<code class="ruby">\015\012on :client_create do |c|\015\012 cur = Subtlext::View.current\015\012\015\012 # Check for empty tags\015\012 if(c.tags.empty?)\015\012 t = Subtlext::Tag[cur.name] rescue nil\015\012\015\012 # Create new tag\015\012 if(t.nil?)\015\012 t = Subtlext::Tag.new(cur.name)\015\012 t.save\015\012 end \015\012\015\012 c + t\015\012 end\015\012end\015\012</code></pre>