Project

General

Profile

unexist.dev

/

subtle

Assorted tidbits and projects

Hooks » History » Version 8

Version 7 (Jonathan Dahan, 11/22/2009 08:26 PM) → Version 8/47 (Jonathan Dahan, 11/22/2009 08:26 PM)

h1. Hooks\015\012\015\012Here is a list of the existing types of [[hooks]], although more are planned. Every feature of [[Subtlext]] can be used inside these [[hooks]] without instantiating a *Subtlext::Subtle* object first:\015\012\015\012<pre><code class="ruby">\015\012clients.each { |c| puts c.name }\015\012\015\012find_tag("subtle")\015\012</code></pre>\015\012\015\012Every [[hooks|hook]] except the *create hook* will be run before the event is actually processed and the return value of the supplied proc will determine if processing continues or not. A return value of *false* will effectively stop processing of the event.\015\012\015\012Following [[hooks]] exist so far:\015\012\015\012{{>toc}}\015\012\015\012h2. Create\015\012\015\012Triggers on creation of new clients.\015\012<pre><code class="ruby">\015\012:HookCreate => lambda { |c| puts c.name }\015\012</code></pre>\015\012\015\012h2. Focus\015\012\015\012Triggers when a client gets focus and has the focussed client as parameter.\015\012<pre><code class="ruby">\015\012:HookFocus => lambda { |c| puts c.name }\015\012</code></pre>\015\012\015\012h2. Gravity\015\012\015\012Triggers when a client gets a new gravtiy.\015\012<pre><code class="ruby">\015\012:HookGravity => lambda { |c| puts c.name }\015\012</code></pre>\015\012\015\012h2. Jump\015\012\015\012Triggers on view jumps and has the active view as parameter.\015\012<pre><code class="ruby">\015\012:HookJump => lambda { |v| puts v.name }\015\012</code></pre>\015\012\015\012\015\012h2. Example Hooks\015\012\015\012Switch to the first view of new client\015\012<pre><code class="ruby">\015\012:HookCreate => 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\012:HookCreate = lamda { |c| c.tag(current_view.name) }\015\012</code></pre>\015\012\015\012Tag }\015\012</code></pre>\015\012\015\012If a new client with doesn't have any tags, add the current view only if it has no other tags\015\012<pre><code tag\015\012<pre><code class="ruby">\015\012:HookCreate => lambda { |c| if(c.tags.empty?); if(!tags.include?(current_view.name)); add_tag(current_view.name); end c.tag(current_view.name); end }\015\012</code></pre>