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
367 lines (308 loc) · 10.7 KB
/
Copy pathproperty.c
File metadata and controls
367 lines (308 loc) · 10.7 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
/*
* property.c - property handlers
*
* Copyright © 2008-2009 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "awesome.h"
#include "screen.h"
#include "property.h"
#include "ewmh.h"
#include "xwindow.h"
#include "common/xutil.h"
#include "objects/wibox.h"
#define HANDLE_TEXT_PROPERTY(funcname, atom, setfunc) \
xcb_get_property_cookie_t \
property_get_##funcname(client_t *c) \
{ \
return xcb_get_property(_G_connection, \
false, \
c->window, \
atom, \
XCB_GET_PROPERTY_TYPE_ANY, \
0, \
UINT_MAX); \
} \
void \
property_update_##funcname(client_t *c, xcb_get_property_cookie_t cookie) \
{ \
xcb_get_property_reply_t * reply = \
xcb_get_property_reply(_G_connection, cookie, NULL); \
luaA_object_push(_G_L, c); \
setfunc(_G_L, c, xutil_get_text_property_from_reply(reply)); \
lua_pop(_G_L, 1); \
p_delete(&reply); \
} \
static int \
property_handle_##funcname(uint8_t state, \
xcb_window_t window) \
{ \
client_t *c = client_getbywin(window); \
if(c) \
property_update_##funcname(c, property_get_##funcname(c));\
return 0; \
}
HANDLE_TEXT_PROPERTY(wm_name, XCB_ATOM_WM_NAME, client_set_alt_name)
HANDLE_TEXT_PROPERTY(net_wm_name, _NET_WM_NAME, client_set_name)
HANDLE_TEXT_PROPERTY(wm_icon_name, XCB_ATOM_WM_ICON_NAME, client_set_alt_icon_name)
HANDLE_TEXT_PROPERTY(net_wm_icon_name, _NET_WM_ICON_NAME, client_set_icon_name)
HANDLE_TEXT_PROPERTY(wm_client_machine, XCB_ATOM_WM_CLIENT_MACHINE, client_set_machine)
HANDLE_TEXT_PROPERTY(wm_window_role, WM_WINDOW_ROLE, client_set_role)
#undef HANDLE_TEXT_PROPERTY
#define HANDLE_PROPERTY(name) \
static int \
property_handle_##name(uint8_t state, \
xcb_window_t window) \
{ \
client_t *c = client_getbywin(window); \
if(c) \
property_update_##name(c, property_get_##name(c));\
return 0; \
}
HANDLE_PROPERTY(wm_protocols)
HANDLE_PROPERTY(wm_transient_for)
HANDLE_PROPERTY(wm_client_leader)
HANDLE_PROPERTY(wm_normal_hints)
HANDLE_PROPERTY(wm_hints)
HANDLE_PROPERTY(wm_class)
HANDLE_PROPERTY(net_wm_icon)
HANDLE_PROPERTY(net_wm_pid)
#undef HANDLE_PROPERTY
xcb_get_property_cookie_t
property_get_wm_transient_for(client_t *c)
{
return xcb_get_wm_transient_for_unchecked(_G_connection, c->window);
}
void
property_update_wm_transient_for(client_t *c, xcb_get_property_cookie_t cookie)
{
xcb_window_t trans;
if(!xcb_get_wm_transient_for_reply(_G_connection,
cookie,
&trans, NULL))
return;
ewindow_set_type(_G_L, (ewindow_t *) c, EWINDOW_TYPE_DIALOG);
ewindow_set_above(_G_L, (ewindow_t *) c, false);
luaA_object_push(_G_L, client_getbywin(trans));
client_set_transient_for(_G_L, c, -1);
lua_pop(_G_L, 1);
}
xcb_get_property_cookie_t
property_get_wm_client_leader(client_t *c)
{
return xcb_get_property_unchecked(_G_connection, false, c->window,
WM_CLIENT_LEADER, XCB_ATOM_WINDOW, 1, 32);
}
/** Update leader hint of a client.
* \param c The client.
* \param cookie Cookie returned by property_get_wm_client_leader.
*/
void
property_update_wm_client_leader(client_t *c, xcb_get_property_cookie_t cookie)
{
xcb_get_property_reply_t *reply;
void *data;
reply = xcb_get_property_reply(_G_connection, cookie, NULL);
if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
c->leader_window = *(xcb_window_t *) data;
p_delete(&reply);
}
xcb_get_property_cookie_t
property_get_wm_normal_hints(client_t *c)
{
return xcb_get_wm_normal_hints_unchecked(_G_connection, c->window);
}
/** Update the size hints of a client.
* \param c The client.
* \param cookie Cookie returned by property_get_wm_normal_hints.
*/
void
property_update_wm_normal_hints(client_t *c, xcb_get_property_cookie_t cookie)
{
if(!xcb_get_wm_normal_hints_reply(_G_connection,
cookie,
&c->size_hints, NULL))
return;
c->resizable = !(c->size_hints.flags & XCB_SIZE_HINT_P_MAX_SIZE
&& c->size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE
&& c->size_hints.max_width == c->size_hints.min_width
&& c->size_hints.max_height == c->size_hints.min_height
&& c->size_hints.max_width
&& c->size_hints.max_height);
}
xcb_get_property_cookie_t
property_get_wm_hints(client_t *c)
{
return xcb_get_wm_hints_unchecked(_G_connection, c->window);
}
/** Update the WM hints of a client.
* \param c The client.
* \param cookie Cookie returned by property_get_wm_hints.
*/
void
property_update_wm_hints(client_t *c, xcb_get_property_cookie_t cookie)
{
xcb_wm_hints_t wmh;
if(!xcb_get_wm_hints_reply(_G_connection,
cookie,
&wmh, NULL))
return;
client_set_urgent(_G_L, c, xcb_wm_hints_get_urgency(&wmh));
if(wmh.flags & XCB_WM_HINT_INPUT)
c->focusable = wmh.input;
if(wmh.flags & XCB_WM_HINT_WINDOW_GROUP)
client_set_group_window(_G_L, c, wmh.window_group);
}
xcb_get_property_cookie_t
property_get_wm_class(client_t *c)
{
return xcb_get_wm_class_unchecked(_G_connection, c->window);
}
/** Update WM_CLASS of a client.
* \param c The client.
* \param cookie Cookie returned by property_get_wm_class.
*/
void
property_update_wm_class(client_t *c, xcb_get_property_cookie_t cookie)
{
xcb_get_wm_class_reply_t hint;
if(!xcb_get_wm_class_reply(_G_connection,
cookie,
&hint, NULL))
return;
client_set_class_instance(_G_L, c, hint.class_name, hint.instance_name);
xcb_get_wm_class_reply_wipe(&hint);
}
static int
property_handle_net_wm_strut_partial(uint8_t state,
xcb_window_t window)
{
client_t *c = client_getbywin(window);
if(c)
ewmh_process_client_strut(c);
return 0;
}
xcb_get_property_cookie_t
property_get_net_wm_icon(client_t *c)
{
return ewmh_window_icon_get_unchecked(c->window);
}
void
property_update_net_wm_icon(client_t *c, xcb_get_property_cookie_t cookie)
{
if(ewmh_window_icon_get_reply(cookie))
client_set_icon(_G_L, c, -1);
}
xcb_get_property_cookie_t
property_get_net_wm_pid(client_t *c)
{
return xcb_get_property_unchecked(_G_connection, false, c->window, _NET_WM_PID, XCB_ATOM_CARDINAL, 0L, 1L);
}
void
property_update_net_wm_pid(client_t *c, xcb_get_property_cookie_t cookie)
{
xcb_get_property_reply_t *reply;
reply = xcb_get_property_reply(_G_connection, cookie, NULL);
if(reply && reply->value_len)
{
uint32_t *rdata = xcb_get_property_value(reply);
if(rdata)
client_set_pid(_G_L, c, *rdata);
}
p_delete(&reply);
}
xcb_get_property_cookie_t
property_get_wm_protocols(client_t *c)
{
return xcb_get_wm_protocols_unchecked(_G_connection, c->window, WM_PROTOCOLS);
}
/** Update the list of supported protocols for a client.
* \param c The client.
* \param cookie Cookie from property_get_wm_protocols.
*/
void
property_update_wm_protocols(client_t *c, xcb_get_property_cookie_t cookie)
{
xcb_get_wm_protocols_reply_t protocols;
/* If this fails for any reason, we still got the old value */
if(!xcb_get_wm_protocols_reply(_G_connection,
cookie,
&protocols, NULL))
return;
xcb_get_wm_protocols_reply_wipe(&c->protocols);
memcpy(&c->protocols, &protocols, sizeof(protocols));
}
static int
property_handle_xrootpmap_id(uint8_t state,
xcb_window_t window)
{
#warning rebases are evil
return 0;
}
static int
property_handle_net_wm_opacity(uint8_t state,
xcb_window_t window)
{
ewindow_t *ewindow = ewindow_getbywin(window);
if(ewindow)
ewindow_set_opacity(_G_L, ewindow, xwindow_get_opacity(window));
return 0;
}
/** The property notify event handler.
* \param data Unused data.
* \param connection The connection to the X server.
* \param ev The event.
* \return Status code, 0 if everything's fine.
*/
void
property_handle_propertynotify(xcb_property_notify_event_t *ev)
{
int (*handler)(uint8_t state,
xcb_window_t window) = NULL;
/* Find the correct event handler */
#define HANDLE(atom_, cb) \
if (ev->atom == atom_) \
{ \
handler = cb; \
} else
#define END return
/* ICCCM stuff */
HANDLE(XCB_ATOM_WM_TRANSIENT_FOR, property_handle_wm_transient_for)
HANDLE(WM_CLIENT_LEADER, property_handle_wm_client_leader)
HANDLE(XCB_ATOM_WM_NORMAL_HINTS, property_handle_wm_normal_hints)
HANDLE(XCB_ATOM_WM_HINTS, property_handle_wm_hints)
HANDLE(XCB_ATOM_WM_NAME, property_handle_wm_name)
HANDLE(XCB_ATOM_WM_ICON_NAME, property_handle_wm_icon_name)
HANDLE(XCB_ATOM_WM_CLASS, property_handle_wm_class)
HANDLE(WM_PROTOCOLS, property_handle_wm_protocols)
HANDLE(XCB_ATOM_WM_CLIENT_MACHINE, property_handle_wm_client_machine)
HANDLE(WM_WINDOW_ROLE, property_handle_wm_window_role)
/* EWMH stuff */
HANDLE(_NET_WM_NAME, property_handle_net_wm_name)
HANDLE(_NET_WM_ICON_NAME, property_handle_net_wm_icon_name)
HANDLE(_NET_WM_STRUT_PARTIAL, property_handle_net_wm_strut_partial)
HANDLE(_NET_WM_ICON, property_handle_net_wm_icon)
HANDLE(_NET_WM_PID, property_handle_net_wm_pid)
HANDLE(_NET_WM_WINDOW_OPACITY, property_handle_net_wm_opacity)
/* background change */
HANDLE(_XROOTPMAP_ID, property_handle_xrootpmap_id)
/* If nothing was found, return */
END;
#undef HANDLE
#undef END
(*handler)(ev->state, ev->window);
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80