forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty.c
More file actions
404 lines (339 loc) · 11.9 KB
/
Copy pathproperty.c
File metadata and controls
404 lines (339 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
* property.c - property handlers
*
* Copyright © 2008 Julien Danjou <julien@danjou.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <xcb/xcb_atom.h>
#include "property.h"
#include "client.h"
#include "widget.h"
#include "ewmh.h"
#include "common/atoms.h"
extern awesome_t globalconf;
void
property_update_wm_transient_for(client_t *c, xcb_get_property_reply_t *reply)
{
xcb_window_t trans;
if(reply)
{
if(!xcb_get_wm_transient_for_from_reply(&trans, reply))
return;
}
else
{
if(!xcb_get_wm_transient_for_reply(globalconf.connection,
xcb_get_wm_transient_for_unchecked(globalconf.connection,
c->win),
&trans, NULL))
return;
}
c->type = WINDOW_TYPE_DIALOG;
c->transient_for = client_getbywin(trans);
}
static int
property_handle_wm_transient_for(void *data,
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
client_t *c = client_getbywin(window);
if(c)
property_update_wm_transient_for(c, reply);
return 0;
}
/** Update leader hint of a client.
* \param c The client.
* \param reply (Optional) An existing reply.
*/
void
property_update_wm_client_leader(client_t *c, xcb_get_property_reply_t *reply)
{
xcb_get_property_cookie_t client_leader_q;
void *data;
bool no_reply = !reply;
if(no_reply)
{
client_leader_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
WM_CLIENT_LEADER, WINDOW, 0, 32);
reply = xcb_get_property_reply(globalconf.connection, client_leader_q, NULL);
}
if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
c->leader_win = *(xcb_window_t *) data;
/* Only free when we created a reply ourselves. */
if(no_reply)
p_delete(&reply);
}
static int
property_handle_wm_client_leader(void *data,
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
client_t *c = client_getbywin(window);
if(c)
property_update_wm_client_leader(c, reply);
return 0;
}
/** Update the size hints of a client.
* \param c The client.
*/
void
property_update_wm_normal_hints(client_t *c, xcb_get_property_reply_t *reply)
{
if(reply)
{
if(!xcb_get_wm_size_hints_from_reply(&c->size_hints, reply))
return;
}
else
{
if(!xcb_get_wm_normal_hints_reply(globalconf.connection,
xcb_get_wm_normal_hints_unchecked(globalconf.connection,
c->win),
&c->size_hints, NULL))
return;
}
}
static int
property_handle_wm_normal_hints(void *data,
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
client_t *c = client_getbywin(window);
if(c)
property_update_wm_normal_hints(c, reply);
return 0;
}
/** Update the WM hints of a client.
* \param c The client.
*/
void
property_update_wm_hints(client_t *c, xcb_get_property_reply_t *reply)
{
xcb_wm_hints_t wmh;
if(reply)
{
if(!xcb_get_wm_hints_from_reply(&wmh, reply))
return;
}
else
{
if(!xcb_get_wm_hints_reply(globalconf.connection,
xcb_get_wm_hints_unchecked(globalconf.connection, c->win),
&wmh, NULL))
return;
}
bool isurgent = xcb_wm_hints_get_urgency(&wmh);
client_seturgent(c, isurgent);
if(wmh.flags & XCB_WM_HINT_STATE &&
wmh.initial_state == XCB_WM_STATE_WITHDRAWN)
client_setborder(c, 0);
if(wmh.flags & XCB_WM_HINT_INPUT)
c->nofocus = !wmh.input;
if(wmh.flags & XCB_WM_HINT_WINDOW_GROUP)
c->group_win = wmh.window_group;
}
static int
property_handle_wm_hints(void *data,
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
client_t *c = client_getbywin(window);
if(c)
property_update_wm_hints(c, reply);
return 0;
}
/** Update client name attribute with its new title.
* \param c The client.
* \param Return true if it has been updated.
*/
void
property_update_wm_name(client_t *c)
{
char *name;
ssize_t len;
if(!xutil_text_prop_get(globalconf.connection, c->win, _NET_WM_NAME, &name, &len))
if(!xutil_text_prop_get(globalconf.connection, c->win, WM_NAME, &name, &len))
return;
p_delete(&c->name);
c->name = name;
/* call hook */
hooks_property(c, "name");
}
/** Update client icon name attribute with its new title.
* \param c The client.
* \param Return true if it has been updated.
*/
void
property_update_wm_icon_name(client_t *c)
{
char *name;
ssize_t len;
if(!xutil_text_prop_get(globalconf.connection, c->win, _NET_WM_ICON_NAME, &name, &len))
if(!xutil_text_prop_get(globalconf.connection, c->win, WM_ICON_NAME, &name, &len))
return;
p_delete(&c->icon_name);
c->icon_name = name;
/* call hook */
hooks_property(c, "icon_name");
}
static int
property_handle_wm_name(void *data,
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
client_t *c = client_getbywin(window);
if(c)
property_update_wm_name(c);
return 0;
}
static int
property_handle_wm_icon_name(void *data,
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
client_t *c = client_getbywin(window);
if(c)
property_update_wm_icon_name(c);
return 0;
}
static int
property_handle_net_wm_strut_partial(void *data,
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
client_t *c = client_getbywin(window);
if(c)
ewmh_process_client_strut(c, reply);
return 0;
}
static int
property_handle_net_wm_icon(void *data,
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
client_t *c = client_getbywin(window);
if(c)
{
image_t *icon;
image_unref(&c->icon);
icon = ewmh_window_icon_from_reply(reply);
c->icon = icon ? image_ref(&icon) : NULL;
/* execute hook */
hooks_property(c, "icon");
}
return 0;
}
/** The property notify event handler.
* \param data currently unused.
* \param connection The connection to the X server.
* \param ev The event.
*/
static int
property_handle_xembed_info(void *data __attribute__ ((unused)),
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
xembed_window_t *emwin = xembed_getbywin(&globalconf.embedded, window);
if(emwin)
xembed_property_update(connection, emwin, reply);
return 0;
}
static int
property_handle_xrootpmap_id(void *data __attribute__ ((unused)),
xcb_connection_t *connection,
uint8_t state,
xcb_window_t window,
xcb_atom_t name,
xcb_get_property_reply_t *reply)
{
if(globalconf.xinerama_is_active)
for(int screen = 0; screen < globalconf.nscreen; screen++)
{
wibox_array_t *w = &globalconf.screens[screen].wiboxes;
for(int i = 0; i < w->len; i++)
w->tab[i]->need_update = true;
}
else
{
int screen = xutil_root2screen(connection, window);
wibox_array_t *w = &globalconf.screens[screen].wiboxes;
for(int i = 0; i < w->len; i++)
w->tab[i]->need_update = true;
}
return 0;
}
void a_xcb_set_property_handlers(void)
{
/* init */
xcb_property_handlers_init(&globalconf.prophs, &globalconf.evenths);
/* Xembed stuff */
xcb_property_set_handler(&globalconf.prophs, _XEMBED_INFO, UINT_MAX,
property_handle_xembed_info, NULL);
/* ICCCM stuff */
xcb_property_set_handler(&globalconf.prophs, WM_TRANSIENT_FOR, UINT_MAX,
property_handle_wm_transient_for, NULL);
xcb_property_set_handler(&globalconf.prophs, WM_CLIENT_LEADER, UINT_MAX,
property_handle_wm_client_leader, NULL);
xcb_property_set_handler(&globalconf.prophs, WM_NORMAL_HINTS, UINT_MAX,
property_handle_wm_normal_hints, NULL);
xcb_property_set_handler(&globalconf.prophs, WM_HINTS, UINT_MAX,
property_handle_wm_hints, NULL);
xcb_property_set_handler(&globalconf.prophs, WM_NAME, UINT_MAX,
property_handle_wm_name, NULL);
xcb_property_set_handler(&globalconf.prophs, WM_ICON_NAME, UINT_MAX,
property_handle_wm_icon_name, NULL);
/* EWMH stuff */
xcb_property_set_handler(&globalconf.prophs, _NET_WM_NAME, UINT_MAX,
property_handle_wm_name, NULL);
xcb_property_set_handler(&globalconf.prophs, _NET_WM_ICON_NAME, UINT_MAX,
property_handle_wm_icon_name, NULL);
xcb_property_set_handler(&globalconf.prophs, _NET_WM_STRUT_PARTIAL, UINT_MAX,
property_handle_net_wm_strut_partial, NULL);
xcb_property_set_handler(&globalconf.prophs, _NET_WM_ICON, UINT_MAX,
property_handle_net_wm_icon, NULL);
/* background change */
xcb_property_set_handler(&globalconf.prophs, _XROOTPMAP_ID, 1,
property_handle_xrootpmap_id, NULL);
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80