Hooks » History » Version 20
Version 19 (Anonymous, 05/24/2010 05:12 PM) → Version 20/47 (Anonymous, 06/10/2010 11:30 PM)
h1. Hooks\015\012\015\012[[Hooks]] are small chunks of code ("Ruby":http://www.ruby-lang.org procs) that are called on certain events of the window manager and can either be used directly in the config or inside of [[sublets]].\015\012\015\012{{>toc}}\015\012\015\012h2. Client Hooks\015\012\015\012h3. client_create\015\012\015\012Triggers ClientCreate\015\012\015\012Triggers on creation of new clients.\015\012<pre><code class="ruby">\015\012on :client_create do |c|\015\012 class="ruby">\015\012:HookClientCreate => lambda { |c| puts c.name\015\012end\015\012</code></pre>\015\012\015\012h3. client_configure\015\012\015\012Triggers c.name }\015\012</code></pre>\015\012\015\012h3. ClientConfigure\015\012\015\012Triggers whenever a client is configured.\015\012<pre><code class="ruby">\015\012on :client_focus do |c|\015\012 class="ruby">\015\012:HookClientFocus => lambda { |c| puts c.name\015\012end\015\012</code></pre>\015\012\015\012h3. client_focus\015\012\015\012Triggers c.name }\015\012</code></pre>\015\012\015\012h3. ClientFocus\015\012\015\012Triggers whenever a client gets focus.\015\012<pre><code class="ruby">\015\012on :client_focus do |c|\015\012 class="ruby">\015\012:HookClientFocus => lambda { |c| puts c.name\015\012end\015\012</code></pre>\015\012\015\012h3. client_kill\015\012\015\012Triggers c.name }\015\012</code></pre>\015\012\015\012h3. ClientKill\015\012\015\012Triggers when a client is killed.\015\012<pre><code class="ruby">\015\012on :client_kill do |c|\015\012 class="ruby">\015\012:HookClientKill => lambda { |c| puts c.name\015\012end\015\012</code></pre>\015\012\015\012h2. c.name }\015\012</code></pre>\015\012\015\012h2. Tag Hooks\015\012\015\012h3. tag_create\015\012\015\012Triggers TagCreate\015\012\015\012Triggers when a tag is created.\015\012<pre><code class="ruby">\015\012on :tag_create do |t|\015\012 class="ruby">\015\012:HookTagKill => lambda { |t| puts t.name\015\012end\015\012</code></pre>\015\012\015\012h3. tag_kill\015\012\015\012Triggers t.name }\015\012</code></pre>\015\012\015\012h3. TagKill\015\012\015\012Triggers when a tag is killed.\015\012<pre><code class="ruby">\015\012on :tag_kill do |t|\015\012 class="ruby">\015\012:HookTagKill => lambda { |t| puts t.name\015\012end\015\012</code></pre>\015\012\015\012h2. t.name }\015\012</code></pre>\015\012\015\012h2. View Hooks\015\012\015\012h3. view_create\015\012\015\012Triggers ViewCreate\015\012\015\012Triggers on creation of new views.\015\012<pre><code class="ruby">\015\012on :view_create do |v|\015\012 class="ruby">\015\012:HookViewCreate => lambda { |v| puts v.name\015\012end\015\012</code></pre>\015\012\015\012h3. view_configure\015\012\015\012Triggers v.name }\015\012</code></pre>\015\012\015\012h3. ViewConfigure\015\012\015\012Triggers whenever a view is configured.\015\012<pre><code class="ruby">\015\012on :view_focus do |v|\015\012 class="ruby">\015\012:HookViewFocus => lambda { |v| puts v.name\015\012end\015\012</code></pre>\015\012\015\012h3. view_jump\015\012\015\012Triggers v.name }\015\012</code></pre>\015\012\015\012h3. ViewJump\015\012\015\012Triggers on a jump to a view.\015\012<pre><code class="ruby">\015\012on :view_jump do |v|\015\012 class="ruby">\015\012:HookViewJump => lambda { |v| puts v.name\015\012end\015\012</code></pre>\015\012\015\012h3. view_kill\015\012\015\012Triggers v.name }\015\012</code></pre>\015\012\015\012h3. ViewKill\015\012\015\012Triggers when a view is killed.\015\012<pre><code class="ruby">\015\012on :view_kill do |v|\015\012 class="ruby">\015\012:HookViewKill => lambda { |v| puts v.name\015\012end\015\012</code></pre>\015\012\015\012h2. v.name }\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><code class="ruby">\015\012on :tile do \015\012 class="ruby">\015\012:HookTile => lambda { puts "Insert tiling here"\015\012end\015\012</code></pre>\015\012\015\012h3. start\015\012\015\012Triggers here" }\015\012</code></pre>\015\012\015\012h3. Exit\015\012\015\012Triggers on start\015\012<pre><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><code class="ruby">\015\012on :exit do\015\012 class="ruby">\015\012:HookExit => lambda { puts "Nooo"\015\012end\015\012</code></pre>\015\012\015\012h2. "Nooo" }\015\012</code></pre>\015\012\015\012h2. Examples\015\012\015\012Switch to the first view of new client\015\012<pre><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 class="ruby">\015\012:HookClientCreate => lambda { |c| c.views.first.jump }\015\012</code></pre>\015\012\015\012Tag a new client with the current view\015\012<pre><code class="ruby">\015\012on :client_create do |c|\015\012 c.tag(current_view.name)\015\012end\015\012</code></pre>\015\012\015\012Tag class="ruby">\015\012:HookClientCreate => lambda { |c| c.tag(current_view.name) }\015\012</code></pre>\015\012\015\012Tag a new client with the current view only if it has no other tags\015\012<pre><code class="ruby">\015\012on :client_create do class="ruby">\015\012:HookClientCreate => lambda { |c| \015\012 if(c.tags.empty?)\015\012 if(!tags.include?(current_view.name))\015\012 add_tag(current_view.name)\015\012 end \015\012 c.tag(current_view.name);\015\012 end\015\012end\015\012</code></pre>\015\012\015\012Display end\015\012}\015\012</code></pre>\015\012\015\012Display information about the currently focused window\015\012<pre><code class="ruby">\015\012:HookClientFocus => { |c| find_sublet("client").data = "%s (%s)" % [ c.name, c.class ] }\015\012</code></pre>\015\012\015\012