Project

General

Profile

unexist.dev

Assorted tidbits and projects

Hooks » History » Version 41

Christoph Kappel, 01/23/2018 12:07 PM

1 41 Christoph Kappel
h1. Hooks
2 41 Christoph Kappel
3 41 Christoph Kappel
{{>toc}}
4 41 Christoph Kappel
5 41 Christoph Kappel
[[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]]. 
6 41 Christoph Kappel
7 41 Christoph Kappel
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. 
8 41 Christoph Kappel
9 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
10 41 Christoph Kappel
# A hook in the config
11 41 Christoph Kappel
on :client_create do |c|
12 41 Christoph Kappel
  puts c.name #< Name of the client
13 41 Christoph Kappel
end
14 41 Christoph Kappel
15 41 Christoph Kappel
# A hook in a sublet
16 41 Christoph Kappel
on :client_create do |s, c|
17 41 Christoph Kappel
  puts s.name #< Name of the sublet
18 41 Christoph Kappel
  puts c.name #< Name of the client
19 41 Christoph Kappel
end
20 41 Christoph Kappel
</code></pre>
21 41 Christoph Kappel
22 41 Christoph Kappel
h2. Client Hooks
23 41 Christoph Kappel
24 41 Christoph Kappel
h3. client_create
25 41 Christoph Kappel
26 41 Christoph Kappel
Triggers on creation of new clients.
27 41 Christoph Kappel
28 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
29 41 Christoph Kappel
on :client_create do |c|
30 41 Christoph Kappel
  puts c.name
31 41 Christoph Kappel
end
32 41 Christoph Kappel
</code></pre>
33 41 Christoph Kappel
34 41 Christoph Kappel
h3. client_mode
35 41 Christoph Kappel
36 41 Christoph Kappel
Triggers whenever a [[Clients#Modes|mode]] of a [[Clients|client]] is changed.
37 41 Christoph Kappel
38 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
39 41 Christoph Kappel
on :client_mode do |c|
40 41 Christoph Kappel
  puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
41 41 Christoph Kappel
end
42 41 Christoph Kappel
</code></pre>
43 41 Christoph Kappel
44 41 Christoph Kappel
h3. client_gravity
45 41 Christoph Kappel
46 41 Christoph Kappel
Triggers whenever a the [[gravity]] of a [[Clients|client]] is changed.
47 41 Christoph Kappel
48 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
49 41 Christoph Kappel
on :client_focus do |c|
50 41 Christoph Kappel
  puts "client=#{c.instance}, urgent=#{c.is_urgent?}"
51 41 Christoph Kappel
end
52 41 Christoph Kappel
</code></pre>
53 41 Christoph Kappel
54 41 Christoph Kappel
h3. client_focus
55 41 Christoph Kappel
56 41 Christoph Kappel
Triggers whenever a [[Clients|client]] gets focus.
57 41 Christoph Kappel
58 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
59 41 Christoph Kappel
on :client_focus do |c|
60 41 Christoph Kappel
  puts c.name
61 41 Christoph Kappel
end
62 41 Christoph Kappel
</code></pre>
63 41 Christoph Kappel
64 41 Christoph Kappel
{{subforge_needs(r3255)}}
65 41 Christoph Kappel
66 41 Christoph Kappel
h3. client_rename
67 41 Christoph Kappel
68 41 Christoph Kappel
Triggers whenever a [[Clients|client]] is renamed.
69 41 Christoph Kappel
70 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
71 41 Christoph Kappel
on :client_rename do |c|
72 41 Christoph Kappel
  puts c.name
73 41 Christoph Kappel
end
74 41 Christoph Kappel
</code></pre>
75 41 Christoph Kappel
76 41 Christoph Kappel
h3. client_kill
77 41 Christoph Kappel
78 41 Christoph Kappel
Triggers when a [[Clients|client]] is killed.
79 41 Christoph Kappel
80 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
81 41 Christoph Kappel
on :client_kill do |c|
82 41 Christoph Kappel
  puts c.name
83 41 Christoph Kappel
end
84 41 Christoph Kappel
</code></pre>
85 41 Christoph Kappel
86 41 Christoph Kappel
h2. Tag Hooks
87 41 Christoph Kappel
88 41 Christoph Kappel
h3. tag_create
89 41 Christoph Kappel
90 41 Christoph Kappel
Triggers when a [[Tagging|tag]] is created.
91 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
92 41 Christoph Kappel
on :tag_create do |t|
93 41 Christoph Kappel
  puts t.name
94 41 Christoph Kappel
end
95 41 Christoph Kappel
</code></pre>
96 41 Christoph Kappel
97 41 Christoph Kappel
h3. tag_kill
98 41 Christoph Kappel
99 41 Christoph Kappel
Triggers when a [[Tagging|tag]] is killed.
100 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
101 41 Christoph Kappel
on :tag_kill do |t|
102 41 Christoph Kappel
  puts t.name
103 41 Christoph Kappel
end
104 41 Christoph Kappel
</code></pre>
105 41 Christoph Kappel
106 41 Christoph Kappel
h2. View Hooks
107 41 Christoph Kappel
108 41 Christoph Kappel
h3. view_create
109 41 Christoph Kappel
110 41 Christoph Kappel
Triggers on creation of new [[views]].
111 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
112 41 Christoph Kappel
on :view_create do |v|
113 41 Christoph Kappel
  puts v.name
114 41 Christoph Kappel
end
115 41 Christoph Kappel
</code></pre>
116 41 Christoph Kappel
117 41 Christoph Kappel
h3. view_focus
118 41 Christoph Kappel
119 41 Christoph Kappel
Triggers on a switch to a [[Views|view]].
120 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
121 41 Christoph Kappel
on :view_focus do |v|
122 41 Christoph Kappel
  puts v.name
123 41 Christoph Kappel
end
124 41 Christoph Kappel
</code></pre>
125 41 Christoph Kappel
126 41 Christoph Kappel
h3. view_kill
127 41 Christoph Kappel
128 41 Christoph Kappel
Triggers when a [[Views|view]] is killed.
129 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
130 41 Christoph Kappel
on :view_kill do |v|
131 41 Christoph Kappel
  puts v.name
132 41 Christoph Kappel
end
133 41 Christoph Kappel
</code></pre>
134 41 Christoph Kappel
135 41 Christoph Kappel
h2. Other
136 41 Christoph Kappel
137 41 Christoph Kappel
h3. start
138 41 Christoph Kappel
139 41 Christoph Kappel
Triggers on start
140 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
141 41 Christoph Kappel
on :start do
142 41 Christoph Kappel
  puts "Yees"
143 41 Christoph Kappel
end
144 41 Christoph Kappel
</code></pre>
145 41 Christoph Kappel
146 41 Christoph Kappel
h3. exit
147 41 Christoph Kappel
148 41 Christoph Kappel
Triggers on exit
149 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
150 41 Christoph Kappel
on :exit do
151 41 Christoph Kappel
  puts "Nooo"
152 41 Christoph Kappel
end
153 41 Christoph Kappel
</code></pre>
154 41 Christoph Kappel
155 41 Christoph Kappel
h3. tile
156 41 Christoph Kappel
157 41 Christoph Kappel
Triggers whenever tiling would be needed
158 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
159 41 Christoph Kappel
on :tile do 
160 41 Christoph Kappel
  puts "Insert tiling here"
161 41 Christoph Kappel
end
162 41 Christoph Kappel
</code></pre>
163 41 Christoph Kappel
164 41 Christoph Kappel
h3. reload
165 41 Christoph Kappel
166 41 Christoph Kappel
Triggers whenever subtle was reloaded
167 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
168 41 Christoph Kappel
on :reload do 
169 41 Christoph Kappel
  puts "Reloaded config"
170 41 Christoph Kappel
end
171 41 Christoph Kappel
</code></pre>
172 41 Christoph Kappel
173 41 Christoph Kappel
h2. Examples
174 41 Christoph Kappel
175 41 Christoph Kappel
Switch to the first view of new client
176 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
177 41 Christoph Kappel
on :client_create do |c|
178 41 Christoph Kappel
  c.views.first.jump
179 41 Christoph Kappel
end
180 41 Christoph Kappel
</code></pre>
181 41 Christoph Kappel
182 41 Christoph Kappel
Tag a new [[Clients|client]] with the current [[Views|view]] only if it has no other [[Tagging|tags]]
183 41 Christoph Kappel
<pre>{{subforge_hide}}<code class="ruby">
184 41 Christoph Kappel
on :client_create do |c|
185 41 Christoph Kappel
  cur = Subtlext::View.current
186 41 Christoph Kappel
187 41 Christoph Kappel
  # Check for empty tags
188 41 Christoph Kappel
  if(c.tags.empty?)
189 41 Christoph Kappel
    t = Subtlext::Tag[cur.name] rescue nil
190 41 Christoph Kappel
191 41 Christoph Kappel
    # Create new tag
192 41 Christoph Kappel
    if(t.nil?)
193 41 Christoph Kappel
      t = Subtlext::Tag.new(cur.name)
194 41 Christoph Kappel
      t.save
195 41 Christoph Kappel
    end 
196 41 Christoph Kappel
197 41 Christoph Kappel
    c + t
198 41 Christoph Kappel
  end
199 41 Christoph Kappel
end
200 41 Christoph Kappel
</code></pre>