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