-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathproperty.c
More file actions
385 lines (328 loc) · 11.8 KB
/
Copy pathproperty.c
File metadata and controls
385 lines (328 loc) · 11.8 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
/*
* property.c - property handlers
*
* Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
* Copyright © 2024 somewm contributors
*
* 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 "property.h"
#include "objects/client.h"
#include "luaa.h"
#include "globalconf.h"
#include <wayland-server-core.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <string.h>
#include <xcb/xcb.h>
/* ========================================================================
* X11 Property API Stubs (for AwesomeWM compatibility)
* ======================================================================== */
/* X11-only: Handle property notify event from XCB.
* Wayland clients emit toplevel events instead. */
void
property_handle_propertynotify(xcb_property_notify_event_t *ev)
{
(void)ev;
}
/* Macro to generate property_get_* and property_update_* stubs */
#define PROPERTY_STUB(name) \
xcb_get_property_cookie_t \
property_get_##name(client_t *c) \
{ \
(void)c; \
xcb_get_property_cookie_t cookie = {0}; \
return cookie; \
} \
void \
property_update_##name(client_t *c, xcb_get_property_cookie_t cookie) \
{ \
(void)c; \
(void)cookie; \
}
/* X11 property stubs - Wayland gets these from wlr_xdg_toplevel or wlr_xwayland_surface */
PROPERTY_STUB(wm_name)
PROPERTY_STUB(net_wm_name)
PROPERTY_STUB(wm_icon_name)
PROPERTY_STUB(net_wm_icon_name)
PROPERTY_STUB(wm_client_machine)
PROPERTY_STUB(wm_window_role)
PROPERTY_STUB(wm_transient_for)
PROPERTY_STUB(wm_client_leader)
PROPERTY_STUB(wm_normal_hints)
PROPERTY_STUB(wm_hints)
PROPERTY_STUB(wm_class)
PROPERTY_STUB(wm_protocols)
PROPERTY_STUB(net_wm_pid)
PROPERTY_STUB(net_wm_icon)
PROPERTY_STUB(motif_wm_hints)
#undef PROPERTY_STUB
/* ========================================================================
* Wayland Property Handlers (Native Wayland clients)
* ======================================================================== */
/** Handle xdg_toplevel.set_title event
* Called when a native Wayland client changes its window title
* \param listener The wl_listener
* \param data User data (not used, title comes from toplevel)
*/
void
property_handle_toplevel_title(struct wl_listener *listener, void *data)
{
client_t *c;
struct wlr_xdg_toplevel *toplevel;
lua_State *L;
const char *title;
(void)data; /* Unused */
/* Get client from listener */
c = wl_container_of(listener, c, set_title);
if (!c || c->client_type != XDGShell || !c->surface.xdg)
return;
/* Get title from xdg_toplevel */
toplevel = c->surface.xdg->toplevel;
if (!toplevel)
return;
title = toplevel->title;
/* Update client name using proper AwesomeWM setter
* This will emit property::name signal on the client object */
L = globalconf_get_lua_State();
luaA_object_push(L, c);
client_set_name(L, -1, title ? strdup(title) : NULL);
lua_pop(L, 1);
}
/** Handle xdg_toplevel.set_app_id event
* Called when a native Wayland client changes its app_id (equivalent to WM_CLASS)
* \param listener The wl_listener
* \param data User data (not used, app_id comes from toplevel)
*/
void
property_handle_toplevel_app_id(struct wl_listener *listener, void *data)
{
client_t *c;
struct wlr_xdg_toplevel *toplevel;
lua_State *L;
const char *app_id;
(void)data; /* Unused */
/* Get client from listener - note: we reuse set_title listener for app_id
* In practice, app_id changes are rare after initial mapping */
c = wl_container_of(listener, c, set_title);
if (!c || c->client_type != XDGShell || !c->surface.xdg)
return;
/* Get app_id from xdg_toplevel */
toplevel = c->surface.xdg->toplevel;
if (!toplevel)
return;
app_id = toplevel->app_id;
/* Update client class using proper AwesomeWM setter
* This will emit property::class signal on the client object
* Note: Wayland doesn't have "instance" like X11, so we set class only */
L = globalconf_get_lua_State();
luaA_object_push(L, c);
client_set_class_instance(L, -1,
app_id ? app_id : "",
""); /* Empty instance for Wayland clients */
lua_pop(L, 1);
}
/** Update all Wayland properties for a client
* Called during initial client setup to fetch all properties at once
* \param c The client
*/
void
property_update_wayland_properties(client_t *c)
{
struct wlr_xdg_toplevel *toplevel;
struct wlr_surface *surface;
struct wl_client *wl_client;
lua_State *L;
pid_t pid;
if (!c || c->client_type != XDGShell || !c->surface.xdg)
return;
toplevel = c->surface.xdg->toplevel;
if (!toplevel)
return;
L = globalconf_get_lua_State();
luaA_object_push(L, c);
/* Update title */
if (toplevel->title)
client_set_name(L, -1, strdup(toplevel->title));
/* Update app_id (class) */
if (toplevel->app_id) {
client_set_class_instance(L, -1, toplevel->app_id, "");
}
/* Get PID from wl_client */
surface = c->surface.xdg->surface;
if (surface && surface->resource) {
wl_client = wl_resource_get_client(surface->resource);
wl_client_get_credentials(wl_client, &pid, NULL, NULL);
client_set_pid(L, -1, (uint32_t)pid);
}
/* Note: Wayland doesn't have equivalents for:
* - icon_name (no protocol support)
* - role (X11-specific, use window type instead)
* - machine (get via PID if needed)
* - instance (X11-specific WM_CLASS component)
*/
lua_pop(L, 1);
}
/** Register Wayland property listeners for a client
* Attaches listeners to xdg_toplevel events for native Wayland clients
* \param c The client
*/
void
property_register_wayland_listeners(client_t *c)
{
struct wlr_xdg_toplevel *toplevel;
if (!c || c->client_type != XDGShell || !c->surface.xdg)
return;
toplevel = c->surface.xdg->toplevel;
if (!toplevel)
return;
/* Note: The set_title listener is already registered in somewm.c
* via LISTEN(&toplevel->events.set_title, &c->set_title, updatetitle)
* We don't need to register it again here.
*
* XDG shell doesn't have separate events for app_id changes,
* so we handle app_id during initial property fetch.
*/
/* Fetch initial properties */
property_update_wayland_properties(c);
}
/* ========================================================================
* XWayland Property Handling (X11 clients)
* ======================================================================== */
#ifdef XWAYLAND
#include <wlr/xwayland.h>
#include <xcb/xcb_icccm.h>
/** Update all XWayland properties for a client
* Called during initial client setup to fetch all X11 properties at once.
* Uses wlroots' cached XWayland surface properties.
* \param c The client
*/
void
property_update_xwayland_properties(client_t *c)
{
struct wlr_xwayland_surface *xsurface;
lua_State *L;
if (!c || c->client_type != X11)
return;
xsurface = c->surface.xwayland;
if (!xsurface)
return;
L = globalconf_get_lua_State();
luaA_object_push(L, c);
/* Title (WM_NAME or _NET_WM_NAME - wlroots provides best available) */
if (xsurface->title)
client_set_name(L, -1, strdup(xsurface->title));
/* Class and instance (WM_CLASS) */
client_set_class_instance(L, -1,
xsurface->class ? xsurface->class : "",
xsurface->instance ? xsurface->instance : "");
/* PID (_NET_WM_PID) */
if (xsurface->pid > 0)
client_set_pid(L, -1, (uint32_t)xsurface->pid);
/* Role (WM_WINDOW_ROLE) - wlroots exposes this */
if (xsurface->role)
client_set_role(L, -1, strdup(xsurface->role));
/* Size hints (WM_NORMAL_HINTS) */
if (xsurface->size_hints) {
xcb_size_hints_t *hints = xsurface->size_hints;
/* Copy size hints to client structure */
c->size_hints.flags = hints->flags;
c->size_hints.x = hints->x;
c->size_hints.y = hints->y;
c->size_hints.width = hints->width;
c->size_hints.height = hints->height;
c->size_hints.min_width = hints->min_width;
c->size_hints.min_height = hints->min_height;
c->size_hints.max_width = hints->max_width;
c->size_hints.max_height = hints->max_height;
c->size_hints.base_width = hints->base_width;
c->size_hints.base_height = hints->base_height;
c->size_hints.width_inc = hints->width_inc;
c->size_hints.height_inc = hints->height_inc;
c->size_hints.min_aspect_num = hints->min_aspect_num;
c->size_hints.min_aspect_den = hints->min_aspect_den;
c->size_hints.max_aspect_num = hints->max_aspect_num;
c->size_hints.max_aspect_den = hints->max_aspect_den;
c->size_hints.win_gravity = hints->win_gravity;
/* Emit size_hints signal */
luaA_object_emit_signal(L, -1, "property::size_hints", 0);
}
/* WM_HINTS (urgency, input focus, window group, icons)
* These are handled by sethints() listener, but we can set initial values */
if (xsurface->hints) {
xcb_icccm_wm_hints_t *hints = xsurface->hints;
/* Input focus */
if (hints->flags & XCB_ICCCM_WM_HINT_INPUT)
c->nofocus = !hints->input;
/* Window group */
if (hints->flags & XCB_ICCCM_WM_HINT_WINDOW_GROUP)
client_set_group_window(L, -1, hints->window_group);
/* Urgency (use proper API for signal emission) */
client_set_urgent(L, -1, xcb_icccm_wm_hints_get_urgency(hints));
}
/* Transient-for relationship */
if (xsurface->parent) {
c->transient_for_window = xsurface->parent->window_id;
/* client_find_transient_for() will resolve this to client_t* */
client_find_transient_for(c);
}
/* _NET_WM_WINDOW_TYPE - use wlroots cached data (no XCB roundtrip).
* Matches AwesomeWM's ewmh_client_check_hints() window type logic. */
if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DESKTOP))
c->type = WINDOW_TYPE_DESKTOP;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DOCK))
c->type = WINDOW_TYPE_DOCK;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH))
c->type = WINDOW_TYPE_SPLASH;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG))
c->type = WINDOW_TYPE_DIALOG;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY))
c->type = WINDOW_TYPE_UTILITY;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR))
c->type = WINDOW_TYPE_TOOLBAR;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_MENU))
c->type = WINDOW_TYPE_MENU;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DROPDOWN_MENU))
c->type = WINDOW_TYPE_DROPDOWN_MENU;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_POPUP_MENU))
c->type = WINDOW_TYPE_POPUP_MENU;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLTIP))
c->type = WINDOW_TYPE_TOOLTIP;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_NOTIFICATION))
c->type = WINDOW_TYPE_NOTIFICATION;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_COMBO))
c->type = WINDOW_TYPE_COMBO;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DND))
c->type = WINDOW_TYPE_DND;
else if (wlr_xwayland_surface_has_window_type(xsurface,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_NORMAL))
c->type = WINDOW_TYPE_NORMAL;
lua_pop(L, 1);
}
#endif /* XWAYLAND */
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80