blob: e39ce0a55ae168fa1103b6212323c60ab716db1a [file] [log] [blame]
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001/*
2 * Copyright © 2011 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
Daniel Stonec228e232013-05-22 18:03:19 +030023#include "config.h"
Kristian Høgsberg380deee2012-05-21 17:12:41 -040024
25#include <stdlib.h>
26#include <stdio.h>
27#include <string.h>
28#include <sys/socket.h>
29#include <sys/un.h>
30#include <fcntl.h>
31#include <errno.h>
32#include <unistd.h>
33#include <signal.h>
Tiago Vignatti90fada42012-07-16 12:02:08 -040034#include <X11/Xcursor/Xcursor.h>
Kristian Høgsberg380deee2012-05-21 17:12:41 -040035
36#include "xwayland.h"
37
38#include "../../shared/cairo-util.h"
39#include "../compositor.h"
40#include "xserver-server-protocol.h"
41#include "hash.h"
42
43struct motif_wm_hints {
44 uint32_t flags;
45 uint32_t functions;
46 uint32_t decorations;
47 int32_t input_mode;
48 uint32_t status;
49};
50
51#define MWM_HINTS_FUNCTIONS (1L << 0)
52#define MWM_HINTS_DECORATIONS (1L << 1)
53#define MWM_HINTS_INPUT_MODE (1L << 2)
54#define MWM_HINTS_STATUS (1L << 3)
55
56#define MWM_FUNC_ALL (1L << 0)
57#define MWM_FUNC_RESIZE (1L << 1)
58#define MWM_FUNC_MOVE (1L << 2)
59#define MWM_FUNC_MINIMIZE (1L << 3)
60#define MWM_FUNC_MAXIMIZE (1L << 4)
61#define MWM_FUNC_CLOSE (1L << 5)
62
63#define MWM_DECOR_ALL (1L << 0)
64#define MWM_DECOR_BORDER (1L << 1)
65#define MWM_DECOR_RESIZEH (1L << 2)
66#define MWM_DECOR_TITLE (1L << 3)
67#define MWM_DECOR_MENU (1L << 4)
68#define MWM_DECOR_MINIMIZE (1L << 5)
69#define MWM_DECOR_MAXIMIZE (1L << 6)
70
71#define MWM_INPUT_MODELESS 0
72#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
73#define MWM_INPUT_SYSTEM_MODAL 2
74#define MWM_INPUT_FULL_APPLICATION_MODAL 3
75#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
76
77#define MWM_TEAROFF_WINDOW (1L<<0)
78
79#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
80#define _NET_WM_MOVERESIZE_SIZE_TOP 1
81#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
82#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
83#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
84#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
85#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
86#define _NET_WM_MOVERESIZE_SIZE_LEFT 7
87#define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
88#define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
89#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
90#define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */
91
MoD31700122013-06-11 19:58:55 -050092#define SEND_EVENT_MASK (0x80)
93#define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK)
94
Kristian Høgsberg380deee2012-05-21 17:12:41 -040095struct weston_wm_window {
96 struct weston_wm *wm;
97 xcb_window_t id;
98 xcb_window_t frame_id;
99 cairo_surface_t *cairo_surface;
100 struct weston_surface *surface;
101 struct shell_surface *shsurf;
102 struct wl_listener surface_destroy_listener;
103 struct wl_event_source *repaint_source;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400104 struct wl_event_source *configure_source;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400105 int properties_dirty;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300106 int pid;
107 char *machine;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400108 char *class;
109 char *name;
110 struct weston_wm_window *transient_for;
111 uint32_t protocols;
112 xcb_atom_t type;
113 int width, height;
114 int x, y;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500115 int saved_width, saved_height;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400116 int decorate;
Tiago Vignatti771241e2012-06-04 20:01:45 +0300117 int override_redirect;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500118 int fullscreen;
MoD384a11a2013-06-22 11:04:21 -0500119 int has_alpha;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400120};
121
122static struct weston_wm_window *
123get_wm_window(struct weston_surface *surface);
124
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400125static void
126weston_wm_window_schedule_repaint(struct weston_wm_window *window);
127
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400128static int __attribute__ ((format (printf, 1, 2)))
129wm_log(const char *fmt, ...)
130{
131#ifdef WM_DEBUG
132 int l;
133 va_list argp;
134
135 va_start(argp, fmt);
136 l = weston_vlog(fmt, argp);
137 va_end(argp);
138
139 return l;
140#else
141 return 0;
142#endif
143}
144
145static int __attribute__ ((format (printf, 1, 2)))
146wm_log_continue(const char *fmt, ...)
147{
148#ifdef WM_DEBUG
149 int l;
150 va_list argp;
151
152 va_start(argp, fmt);
153 l = weston_vlog_continue(fmt, argp);
154 va_end(argp);
155
156 return l;
157#else
158 return 0;
159#endif
160}
161
162
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400163const char *
164get_atom_name(xcb_connection_t *c, xcb_atom_t atom)
165{
166 xcb_get_atom_name_cookie_t cookie;
167 xcb_get_atom_name_reply_t *reply;
168 xcb_generic_error_t *e;
169 static char buffer[64];
170
171 if (atom == XCB_ATOM_NONE)
172 return "None";
173
174 cookie = xcb_get_atom_name (c, atom);
175 reply = xcb_get_atom_name_reply (c, cookie, &e);
MoD55375b92013-06-11 19:59:42 -0500176
177 if(reply) {
178 snprintf(buffer, sizeof buffer, "%.*s",
179 xcb_get_atom_name_name_length (reply),
180 xcb_get_atom_name_name (reply));
181 } else {
182 snprintf(buffer, sizeof buffer, "(atom %u)", atom);
183 }
184
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400185 free(reply);
186
187 return buffer;
188}
189
Tiago Vignatti90fada42012-07-16 12:02:08 -0400190static xcb_cursor_t
191xcb_cursor_image_load_cursor(struct weston_wm *wm, const XcursorImage *img)
192{
193 xcb_connection_t *c = wm->conn;
194 xcb_screen_iterator_t s = xcb_setup_roots_iterator(xcb_get_setup(c));
195 xcb_screen_t *screen = s.data;
196 xcb_gcontext_t gc;
197 xcb_pixmap_t pix;
198 xcb_render_picture_t pic;
199 xcb_cursor_t cursor;
200 int stride = img->width * 4;
201
202 pix = xcb_generate_id(c);
203 xcb_create_pixmap(c, 32, pix, screen->root, img->width, img->height);
204
205 pic = xcb_generate_id(c);
206 xcb_render_create_picture(c, pic, pix, wm->format_rgba.id, 0, 0);
207
208 gc = xcb_generate_id(c);
209 xcb_create_gc(c, gc, pix, 0, 0);
210
211 xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc,
212 img->width, img->height, 0, 0, 0, 32,
213 stride * img->height, (uint8_t *) img->pixels);
214 xcb_free_gc(c, gc);
215
216 cursor = xcb_generate_id(c);
217 xcb_render_create_cursor(c, cursor, pic, img->xhot, img->yhot);
218
219 xcb_render_free_picture(c, pic);
220 xcb_free_pixmap(c, pix);
221
222 return cursor;
223}
224
225static xcb_cursor_t
226xcb_cursor_images_load_cursor(struct weston_wm *wm, const XcursorImages *images)
227{
228 /* TODO: treat animated cursors as well */
229 if (images->nimage != 1)
230 return -1;
231
232 return xcb_cursor_image_load_cursor(wm, images->images[0]);
233}
234
235static xcb_cursor_t
236xcb_cursor_library_load_cursor(struct weston_wm *wm, const char *file)
237{
238 xcb_cursor_t cursor;
239 XcursorImages *images;
240 char *v = NULL;
241 int size = 0;
242
243 if (!file)
244 return 0;
245
246 v = getenv ("XCURSOR_SIZE");
247 if (v)
248 size = atoi(v);
249
250 if (!size)
251 size = 32;
252
253 images = XcursorLibraryLoadImages (file, NULL, size);
Tiago Vignattiac78bb12012-09-28 16:29:46 +0300254 if (!images)
255 return -1;
256
Tiago Vignatti90fada42012-07-16 12:02:08 -0400257 cursor = xcb_cursor_images_load_cursor (wm, images);
258 XcursorImagesDestroy (images);
259
260 return cursor;
261}
262
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400263void
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400264dump_property(struct weston_wm *wm,
265 xcb_atom_t property, xcb_get_property_reply_t *reply)
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400266{
267 int32_t *incr_value;
268 const char *text_value, *name;
269 xcb_atom_t *atom_value;
270 int width, len;
271 uint32_t i;
272
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400273 width = wm_log_continue("%s: ", get_atom_name(wm->conn, property));
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400274 if (reply == NULL) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400275 wm_log_continue("(no reply)\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400276 return;
277 }
278
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400279 width += wm_log_continue("%s/%d, length %d (value_len %d): ",
280 get_atom_name(wm->conn, reply->type),
281 reply->format,
282 xcb_get_property_value_length(reply),
283 reply->value_len);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400284
285 if (reply->type == wm->atom.incr) {
286 incr_value = xcb_get_property_value(reply);
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400287 wm_log_continue("%d\n", *incr_value);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400288 } else if (reply->type == wm->atom.utf8_string ||
289 reply->type == wm->atom.string) {
290 text_value = xcb_get_property_value(reply);
291 if (reply->value_len > 40)
292 len = 40;
293 else
294 len = reply->value_len;
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400295 wm_log_continue("\"%.*s\"\n", len, text_value);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400296 } else if (reply->type == XCB_ATOM_ATOM) {
297 atom_value = xcb_get_property_value(reply);
298 for (i = 0; i < reply->value_len; i++) {
299 name = get_atom_name(wm->conn, atom_value[i]);
300 if (width + strlen(name) + 2 > 78) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400301 wm_log_continue("\n ");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400302 width = 4;
303 } else if (i > 0) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400304 width += wm_log_continue(", ");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400305 }
306
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400307 width += wm_log_continue("%s", name);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400308 }
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400309 wm_log_continue("\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400310 } else {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400311 wm_log_continue("huh?\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400312 }
313}
314
Tiago Vignatti2d129f12012-11-30 17:19:59 -0200315static void
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400316read_and_dump_property(struct weston_wm *wm,
317 xcb_window_t window, xcb_atom_t property)
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400318{
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400319 xcb_get_property_reply_t *reply;
320 xcb_get_property_cookie_t cookie;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400321
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400322 cookie = xcb_get_property(wm->conn, 0, window,
323 property, XCB_ATOM_ANY, 0, 2048);
324 reply = xcb_get_property_reply(wm->conn, cookie, NULL);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400325
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400326 dump_property(wm, property, reply);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400327
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400328 free(reply);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400329}
330
331/* We reuse some predefined, but otherwise useles atoms */
332#define TYPE_WM_PROTOCOLS XCB_ATOM_CUT_BUFFER0
333#define TYPE_MOTIF_WM_HINTS XCB_ATOM_CUT_BUFFER1
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500334#define TYPE_NET_WM_STATE XCB_ATOM_CUT_BUFFER2
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400335
336static void
337weston_wm_window_read_properties(struct weston_wm_window *window)
338{
339 struct weston_wm *wm = window->wm;
340
341#define F(field) offsetof(struct weston_wm_window, field)
342 const struct {
343 xcb_atom_t atom;
344 xcb_atom_t type;
345 int offset;
346 } props[] = {
347 { XCB_ATOM_WM_CLASS, XCB_ATOM_STRING, F(class) },
348 { XCB_ATOM_WM_NAME, XCB_ATOM_STRING, F(name) },
349 { XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, F(transient_for) },
350 { wm->atom.wm_protocols, TYPE_WM_PROTOCOLS, F(protocols) },
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500351 { wm->atom.net_wm_state, TYPE_NET_WM_STATE },
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400352 { wm->atom.net_wm_window_type, XCB_ATOM_ATOM, F(type) },
353 { wm->atom.net_wm_name, XCB_ATOM_STRING, F(name) },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300354 { wm->atom.net_wm_pid, XCB_ATOM_CARDINAL, F(pid) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400355 { wm->atom.motif_wm_hints, TYPE_MOTIF_WM_HINTS, 0 },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300356 { wm->atom.wm_client_machine, XCB_ATOM_WM_CLIENT_MACHINE, F(machine) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400357 };
358#undef F
359
360 xcb_get_property_cookie_t cookie[ARRAY_LENGTH(props)];
361 xcb_get_property_reply_t *reply;
362 void *p;
363 uint32_t *xid;
364 xcb_atom_t *atom;
365 uint32_t i;
366 struct motif_wm_hints *hints;
367
368 if (!window->properties_dirty)
369 return;
370 window->properties_dirty = 0;
371
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400372 for (i = 0; i < ARRAY_LENGTH(props); i++)
373 cookie[i] = xcb_get_property(wm->conn,
374 0, /* delete */
375 window->id,
376 props[i].atom,
377 XCB_ATOM_ANY, 0, 2048);
378
Tiago Vignatti2ea74d92012-07-20 23:09:53 +0300379 window->decorate = !window->override_redirect;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400380 for (i = 0; i < ARRAY_LENGTH(props); i++) {
381 reply = xcb_get_property_reply(wm->conn, cookie[i], NULL);
382 if (!reply)
383 /* Bad window, typically */
384 continue;
385 if (reply->type == XCB_ATOM_NONE) {
386 /* No such property */
387 free(reply);
388 continue;
389 }
390
391 p = ((char *) window + props[i].offset);
392
393 switch (props[i].type) {
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300394 case XCB_ATOM_WM_CLIENT_MACHINE:
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400395 case XCB_ATOM_STRING:
396 /* FIXME: We're using this for both string and
397 utf8_string */
398 if (*(char **) p)
399 free(*(char **) p);
400
401 *(char **) p =
402 strndup(xcb_get_property_value(reply),
403 xcb_get_property_value_length(reply));
404 break;
405 case XCB_ATOM_WINDOW:
406 xid = xcb_get_property_value(reply);
407 *(struct weston_wm_window **) p =
408 hash_table_lookup(wm->window_hash, *xid);
409 break;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300410 case XCB_ATOM_CARDINAL:
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400411 case XCB_ATOM_ATOM:
412 atom = xcb_get_property_value(reply);
413 *(xcb_atom_t *) p = *atom;
414 break;
415 case TYPE_WM_PROTOCOLS:
416 break;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500417 case TYPE_NET_WM_STATE:
418 window->fullscreen = 0;
419 atom = xcb_get_property_value(reply);
420 for (i = 0; i < reply->value_len; i++)
421 if (atom[i] == wm->atom.net_wm_state_fullscreen)
422 window->fullscreen = 1;
423 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400424 case TYPE_MOTIF_WM_HINTS:
425 hints = xcb_get_property_value(reply);
426 if (hints->flags & MWM_HINTS_DECORATIONS)
427 window->decorate = hints->decorations > 0;
428 break;
429 default:
430 break;
431 }
432 free(reply);
433 }
434}
435
436static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400437weston_wm_window_get_frame_size(struct weston_wm_window *window,
438 int *width, int *height)
439{
440 struct theme *t = window->wm->theme;
441
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500442 if (window->fullscreen) {
443 *width = window->width;
444 *height = window->height;
445 } else if (window->decorate) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400446 *width = window->width + (t->margin + t->width) * 2;
447 *height = window->height +
448 t->margin * 2 + t->width + t->titlebar_height;
449 } else {
450 *width = window->width + t->margin * 2;
451 *height = window->height + t->margin * 2;
452 }
453}
454
455static void
456weston_wm_window_get_child_position(struct weston_wm_window *window,
457 int *x, int *y)
458{
459 struct theme *t = window->wm->theme;
460
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500461 if (window->fullscreen) {
462 *x = 0;
463 *y = 0;
464 } else if (window->decorate) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400465 *x = t->margin + t->width;
466 *y = t->margin + t->titlebar_height;
467 } else {
468 *x = t->margin;
469 *y = t->margin;
470 }
471}
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400472
473static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500474weston_wm_window_send_configure_notify(struct weston_wm_window *window)
475{
476 xcb_configure_notify_event_t configure_notify;
477 struct weston_wm *wm = window->wm;
478 int x, y;
479
480 weston_wm_window_get_child_position(window, &x, &y);
481 configure_notify.response_type = XCB_CONFIGURE_NOTIFY;
482 configure_notify.pad0 = 0;
483 configure_notify.event = window->id;
484 configure_notify.window = window->id;
485 configure_notify.above_sibling = XCB_WINDOW_NONE;
486 configure_notify.x = x;
487 configure_notify.y = y;
488 configure_notify.width = window->width;
489 configure_notify.height = window->height;
490 configure_notify.border_width = 0;
491 configure_notify.override_redirect = 0;
492 configure_notify.pad1 = 0;
493
494 xcb_send_event(wm->conn, 0, window->id,
495 XCB_EVENT_MASK_STRUCTURE_NOTIFY,
496 (char *) &configure_notify);
497}
498
499static void
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400500weston_wm_handle_configure_request(struct weston_wm *wm, xcb_generic_event_t *event)
501{
502 xcb_configure_request_event_t *configure_request =
503 (xcb_configure_request_event_t *) event;
504 struct weston_wm_window *window;
505 uint32_t mask, values[16];
506 int x, y, width, height, i = 0;
507
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400508 wm_log("XCB_CONFIGURE_REQUEST (window %d) %d,%d @ %dx%d\n",
509 configure_request->window,
510 configure_request->x, configure_request->y,
511 configure_request->width, configure_request->height);
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400512
513 window = hash_table_lookup(wm->window_hash, configure_request->window);
514
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500515 if (window->fullscreen) {
516 weston_wm_window_send_configure_notify(window);
517 return;
518 }
519
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400520 if (configure_request->value_mask & XCB_CONFIG_WINDOW_WIDTH)
521 window->width = configure_request->width;
522 if (configure_request->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
523 window->height = configure_request->height;
524
525 weston_wm_window_get_child_position(window, &x, &y);
526 values[i++] = x;
527 values[i++] = y;
528 values[i++] = window->width;
529 values[i++] = window->height;
530 values[i++] = 0;
531 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
532 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
533 XCB_CONFIG_WINDOW_BORDER_WIDTH;
534 if (configure_request->value_mask & XCB_CONFIG_WINDOW_SIBLING) {
535 values[i++] = configure_request->sibling;
536 mask |= XCB_CONFIG_WINDOW_SIBLING;
537 }
538 if (configure_request->value_mask & XCB_CONFIG_WINDOW_STACK_MODE) {
539 values[i++] = configure_request->stack_mode;
540 mask |= XCB_CONFIG_WINDOW_STACK_MODE;
541 }
542
543 xcb_configure_window(wm->conn, window->id, mask, values);
544
545 weston_wm_window_get_frame_size(window, &width, &height);
546 values[0] = width;
547 values[1] = height;
548 mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
549 xcb_configure_window(wm->conn, window->frame_id, mask, values);
550
551 weston_wm_window_schedule_repaint(window);
552}
553
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400554static void
555weston_wm_handle_configure_notify(struct weston_wm *wm, xcb_generic_event_t *event)
556{
557 xcb_configure_notify_event_t *configure_notify =
558 (xcb_configure_notify_event_t *) event;
559 struct weston_wm_window *window;
Tiago Vignattie66fcee2012-07-20 23:09:54 +0300560 int x, y;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400561
562 window = hash_table_lookup(wm->window_hash, configure_notify->window);
563
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400564 wm_log("XCB_CONFIGURE_NOTIFY (%s window %d) %d,%d @ %dx%d\n",
565 configure_notify->window == window->id ? "client" : "frame",
566 configure_notify->window,
567 configure_notify->x, configure_notify->y,
568 configure_notify->width, configure_notify->height);
Tiago Vignattie66fcee2012-07-20 23:09:54 +0300569
570 /* resize falls here */
571 if (configure_notify->window != window->id)
572 return;
573
574 weston_wm_window_get_child_position(window, &x, &y);
575 window->x = configure_notify->x - x;
576 window->y = configure_notify->y - y;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400577}
578
579static void
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300580weston_wm_kill_client(struct wl_listener *listener, void *data)
581{
582 struct weston_surface *surface = data;
583 struct weston_wm_window *window = get_wm_window(surface);
584 char name[1024];
585
586 if (!window)
587 return;
588
589 gethostname(name, 1024);
590
591 /* this is only one heuristic to guess the PID of a client is valid,
592 * assuming it's compliant with icccm and ewmh. Non-compliants and
593 * remote applications of course fail. */
594 if (!strcmp(window->machine, name) && window->pid != 0)
595 kill(window->pid, SIGKILL);
596}
597
598static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400599weston_wm_window_activate(struct wl_listener *listener, void *data)
600{
601 struct weston_surface *surface = data;
602 struct weston_wm_window *window = get_wm_window(surface);
Scott Moreau85ecac02012-05-21 15:49:14 -0600603 struct weston_wm *wm =
604 container_of(listener, struct weston_wm, activate_listener);
605 xcb_client_message_event_t client_message;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400606
Scott Moreau85ecac02012-05-21 15:49:14 -0600607 if (window) {
608 client_message.response_type = XCB_CLIENT_MESSAGE;
609 client_message.format = 32;
610 client_message.window = window->id;
611 client_message.type = wm->atom.wm_protocols;
612 client_message.data.data32[0] = wm->atom.wm_take_focus;
613 client_message.data.data32[1] = XCB_TIME_CURRENT_TIME;
614
615 xcb_send_event(wm->conn, 0, window->id,
616 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
617 (char *) &client_message);
618
619 xcb_set_input_focus (wm->conn, XCB_INPUT_FOCUS_POINTER_ROOT,
620 window->id, XCB_TIME_CURRENT_TIME);
621 } else {
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400622 xcb_set_input_focus (wm->conn,
623 XCB_INPUT_FOCUS_POINTER_ROOT,
624 XCB_NONE,
625 XCB_TIME_CURRENT_TIME);
Scott Moreau85ecac02012-05-21 15:49:14 -0600626 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400627
628 if (wm->focus_window)
629 weston_wm_window_schedule_repaint(wm->focus_window);
630 wm->focus_window = window;
631 if (wm->focus_window)
632 weston_wm_window_schedule_repaint(wm->focus_window);
633}
634
Tiago Vignattifb2adba2013-06-12 15:43:21 -0300635static void
636weston_wm_window_transform(struct wl_listener *listener, void *data)
637{
638 struct weston_surface *surface = data;
639 struct weston_wm_window *window = get_wm_window(surface);
640 struct weston_wm *wm =
641 container_of(listener, struct weston_wm, transform_listener);
642 struct weston_output *output = surface->output;
643 uint32_t mask, values[2];
644 float sxf, syf;
645 int sx, sy;
646 static int old_sx = -1, old_sy = -1;
647
648 if (!window || !wm)
649 return;
650
651 if (!weston_surface_is_mapped(surface))
652 return;
653
654 weston_surface_to_global_float(surface, output->x, output->y,
655 &sxf, &syf);
656
657 sx = (int) sxf;
658 sy = (int) syf;
659
660 if (old_sx == sx && old_sy == sy)
661 return;
662
663 values[0] = sx;
664 values[1] = sy;
665 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y;
666
667 xcb_configure_window(wm->conn, window->frame_id, mask, values);
668 xcb_flush(wm->conn);
669
670 old_sx = sx;
671 old_sy = sy;
672}
673
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400674static int
675our_resource(struct weston_wm *wm, uint32_t id)
676{
677 const xcb_setup_t *setup;
678
679 setup = xcb_get_setup(wm->conn);
680
681 return (id & ~setup->resource_id_mask) == setup->resource_id_base;
682}
683
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -0400684#define ICCCM_WITHDRAWN_STATE 0
685#define ICCCM_NORMAL_STATE 1
686#define ICCCM_ICONIC_STATE 3
687
688static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500689weston_wm_window_set_wm_state(struct weston_wm_window *window, int32_t state)
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -0400690{
691 struct weston_wm *wm = window->wm;
692 uint32_t property[2];
693
694 property[0] = state;
695 property[1] = XCB_WINDOW_NONE;
696
697 xcb_change_property(wm->conn,
698 XCB_PROP_MODE_REPLACE,
699 window->id,
700 wm->atom.wm_state,
701 wm->atom.wm_state,
702 32, /* format */
703 2, property);
704}
705
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400706static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500707weston_wm_window_set_net_wm_state(struct weston_wm_window *window)
708{
709 struct weston_wm *wm = window->wm;
710 uint32_t property[1];
711 int i;
712
713 i = 0;
714 if (window->fullscreen)
715 property[i++] = wm->atom.net_wm_state_fullscreen;
716
717 xcb_change_property(wm->conn,
718 XCB_PROP_MODE_REPLACE,
719 window->id,
720 wm->atom.net_wm_state,
721 XCB_ATOM_ATOM,
722 32, /* format */
723 i, property);
724}
725
726static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400727weston_wm_handle_map_request(struct weston_wm *wm, xcb_generic_event_t *event)
728{
729 xcb_map_request_event_t *map_request =
730 (xcb_map_request_event_t *) event;
731 struct weston_wm_window *window;
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400732 uint32_t values[3];
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400733 int x, y, width, height;
734
735 if (our_resource(wm, map_request->window)) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400736 wm_log("XCB_MAP_REQUEST (window %d, ours)\n",
737 map_request->window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400738 return;
739 }
740
741 window = hash_table_lookup(wm->window_hash, map_request->window);
742
Kristian Høgsbergbc6e1622012-05-30 09:59:56 -0400743 if (window->frame_id)
744 return;
745
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400746 weston_wm_window_read_properties(window);
747
748 weston_wm_window_get_frame_size(window, &width, &height);
749 weston_wm_window_get_child_position(window, &x, &y);
750
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400751 values[0] = wm->screen->black_pixel;
752 values[1] =
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400753 XCB_EVENT_MASK_KEY_PRESS |
754 XCB_EVENT_MASK_KEY_RELEASE |
755 XCB_EVENT_MASK_BUTTON_PRESS |
756 XCB_EVENT_MASK_BUTTON_RELEASE |
Tiago Vignatti236b48d2012-07-16 12:09:19 -0400757 XCB_EVENT_MASK_POINTER_MOTION |
758 XCB_EVENT_MASK_ENTER_WINDOW |
759 XCB_EVENT_MASK_LEAVE_WINDOW |
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400760 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
Kristian Høgsberg44c20132012-05-30 10:09:21 -0400761 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400762 values[2] = wm->colormap;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400763
764 window->frame_id = xcb_generate_id(wm->conn);
765 xcb_create_window(wm->conn,
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400766 32,
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400767 window->frame_id,
768 wm->screen->root,
769 0, 0,
770 width, height,
771 0,
772 XCB_WINDOW_CLASS_INPUT_OUTPUT,
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400773 wm->visual_id,
774 XCB_CW_BORDER_PIXEL |
775 XCB_CW_EVENT_MASK |
776 XCB_CW_COLORMAP, values);
777
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400778 xcb_reparent_window(wm->conn, window->id, window->frame_id, x, y);
779
780 values[0] = 0;
781 xcb_configure_window(wm->conn, window->id,
782 XCB_CONFIG_WINDOW_BORDER_WIDTH, values);
783
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400784 wm_log("XCB_MAP_REQUEST (window %d, %p, frame %d)\n",
785 window->id, window, window->frame_id);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400786
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500787 weston_wm_window_set_wm_state(window, ICCCM_NORMAL_STATE);
788 weston_wm_window_set_net_wm_state(window);
789
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400790 xcb_map_window(wm->conn, map_request->window);
791 xcb_map_window(wm->conn, window->frame_id);
792
793 window->cairo_surface =
794 cairo_xcb_surface_create_with_xrender_format(wm->conn,
795 wm->screen,
796 window->frame_id,
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400797 &wm->format_rgba,
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400798 width, height);
799
800 hash_table_insert(wm->window_hash, window->frame_id, window);
801}
802
803static void
804weston_wm_handle_map_notify(struct weston_wm *wm, xcb_generic_event_t *event)
805{
806 xcb_map_notify_event_t *map_notify = (xcb_map_notify_event_t *) event;
807
808 if (our_resource(wm, map_notify->window)) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400809 wm_log("XCB_MAP_NOTIFY (window %d, ours)\n",
810 map_notify->window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400811 return;
812 }
813
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400814 wm_log("XCB_MAP_NOTIFY (window %d)\n", map_notify->window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400815}
816
817static void
Kristian Høgsberg194ea542012-05-30 10:05:41 -0400818weston_wm_handle_unmap_notify(struct weston_wm *wm, xcb_generic_event_t *event)
819{
820 xcb_unmap_notify_event_t *unmap_notify =
821 (xcb_unmap_notify_event_t *) event;
822 struct weston_wm_window *window;
823
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400824 wm_log("XCB_UNMAP_NOTIFY (window %d, event %d%s)\n",
825 unmap_notify->window,
826 unmap_notify->event,
827 our_resource(wm, unmap_notify->window) ? ", ours" : "");
Kristian Høgsberg194ea542012-05-30 10:05:41 -0400828
829 if (our_resource(wm, unmap_notify->window))
830 return;
831
MoD31700122013-06-11 19:58:55 -0500832 if (unmap_notify->response_type & SEND_EVENT_MASK)
Kristian Høgsbergd64bdf42012-05-31 10:33:43 -0400833 /* We just ignore the ICCCM 4.1.4 synthetic unmap notify
834 * as it may come in after we've destroyed the window. */
Kristian Høgsbergf197e9f2012-05-30 11:46:29 -0400835 return;
Kristian Høgsbergf197e9f2012-05-30 11:46:29 -0400836
Kristian Høgsbergd64bdf42012-05-31 10:33:43 -0400837 window = hash_table_lookup(wm->window_hash, unmap_notify->window);
Kristian Høgsberg194ea542012-05-30 10:05:41 -0400838 if (window->repaint_source)
839 wl_event_source_remove(window->repaint_source);
840 if (window->cairo_surface)
841 cairo_surface_destroy(window->cairo_surface);
842
Kristian Høgsbergbe375b32012-06-05 11:46:08 -0400843 if (window->frame_id) {
844 xcb_reparent_window(wm->conn, window->id, wm->wm_window, 0, 0);
845 xcb_destroy_window(wm->conn, window->frame_id);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500846 weston_wm_window_set_wm_state(window, ICCCM_WITHDRAWN_STATE);
Kristian Høgsbergbe375b32012-06-05 11:46:08 -0400847 hash_table_remove(wm->window_hash, window->frame_id);
848 window->frame_id = XCB_WINDOW_NONE;
849 }
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -0400850
Kristian Høgsberg194ea542012-05-30 10:05:41 -0400851 if (wm->focus_window == window)
852 wm->focus_window = NULL;
Kristian Høgsberg194ea542012-05-30 10:05:41 -0400853 if (window->surface)
854 wl_list_remove(&window->surface_destroy_listener.link);
855 window->surface = NULL;
856}
857
858static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400859weston_wm_window_draw_decoration(void *data)
860{
861 struct weston_wm_window *window = data;
862 struct weston_wm *wm = window->wm;
863 struct theme *t = wm->theme;
864 cairo_t *cr;
865 int x, y, width, height;
866 const char *title;
867 uint32_t flags = 0;
868
869 weston_wm_window_read_properties(window);
870
871 window->repaint_source = NULL;
872
873 weston_wm_window_get_frame_size(window, &width, &height);
874 weston_wm_window_get_child_position(window, &x, &y);
875
876 cairo_xcb_surface_set_size(window->cairo_surface, width, height);
877 cr = cairo_create(window->cairo_surface);
878
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500879 if (window->fullscreen) {
880 /* nothing */
881 } else if (window->decorate) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400882 if (wm->focus_window == window)
883 flags |= THEME_FRAME_ACTIVE;
884
885 if (window->name)
886 title = window->name;
887 else
888 title = "untitled";
889
890 theme_render_frame(t, cr, width, height, title, flags);
891 } else {
892 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
893 cairo_set_source_rgba(cr, 0, 0, 0, 0);
894 cairo_paint(cr);
895
896 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
897 cairo_set_source_rgba(cr, 0, 0, 0, 0.45);
898 tile_mask(cr, t->shadow, 2, 2, width + 8, height + 8, 64, 64);
899 }
900
901 cairo_destroy(cr);
902
903 if (window->surface) {
Scott Moreau76d8fc82012-11-22 15:35:13 -0700904 pixman_region32_fini(&window->surface->pending.opaque);
MoD384a11a2013-06-22 11:04:21 -0500905 if(window->has_alpha) {
906 pixman_region32_init(&window->surface->pending.opaque);
907 } else {
908 /* We leave an extra pixel around the X window area to
909 * make sure we don't sample from the undefined alpha
910 * channel when filtering. */
911 pixman_region32_init_rect(&window->surface->pending.opaque,
912 x - 1, y - 1,
913 window->width + 2,
914 window->height + 2);
915 }
Pekka Paalanenc3ce7382013-03-08 14:56:49 +0200916 weston_surface_geometry_dirty(window->surface);
Kristian Høgsbergd8b617d2013-02-14 21:56:32 -0500917 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400918
Kristian Høgsbergd8b617d2013-02-14 21:56:32 -0500919 if (window->surface && !window->fullscreen) {
Kristian Høgsberg81585e92013-02-14 22:01:58 -0500920 pixman_region32_fini(&window->surface->pending.input);
Kristian Høgsbergd8b617d2013-02-14 21:56:32 -0500921 pixman_region32_init_rect(&window->surface->pending.input,
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400922 t->margin, t->margin,
923 width - 2 * t->margin,
924 height - 2 * t->margin);
925 }
926}
927
928static void
929weston_wm_window_schedule_repaint(struct weston_wm_window *window)
930{
931 struct weston_wm *wm = window->wm;
Pekka Paalanen4f9c07b2012-09-03 16:48:41 +0300932 int width, height;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400933
Kristian Høgsbergc4063f32012-07-22 15:32:45 -0400934 if (window->frame_id == XCB_WINDOW_NONE) {
935 if (window->surface != NULL) {
Pekka Paalanen4f9c07b2012-09-03 16:48:41 +0300936 weston_wm_window_get_frame_size(window, &width, &height);
Scott Moreau76d8fc82012-11-22 15:35:13 -0700937 pixman_region32_fini(&window->surface->pending.opaque);
MoD384a11a2013-06-22 11:04:21 -0500938 if(window->has_alpha) {
939 pixman_region32_init(&window->surface->pending.opaque);
940 } else {
941 pixman_region32_init_rect(&window->surface->pending.opaque, 0, 0,
942 width, height);
943 }
Pekka Paalanenc3ce7382013-03-08 14:56:49 +0200944 weston_surface_geometry_dirty(window->surface);
Kristian Høgsbergc4063f32012-07-22 15:32:45 -0400945 }
946 return;
947 }
948
949 if (window->repaint_source)
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400950 return;
951
952 window->repaint_source =
953 wl_event_loop_add_idle(wm->server->loop,
954 weston_wm_window_draw_decoration,
955 window);
956}
957
958static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400959weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *event)
960{
961 xcb_property_notify_event_t *property_notify =
962 (xcb_property_notify_event_t *) event;
963 struct weston_wm_window *window;
964
965 window = hash_table_lookup(wm->window_hash, property_notify->window);
Rob Bradfordaa521bd2013-01-10 19:48:57 +0000966 if (!window)
967 return;
968
969 window->properties_dirty = 1;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400970
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400971 wm_log("XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
Kristian Høgsberge244cb02012-05-30 11:34:35 -0400972 if (property_notify->state == XCB_PROPERTY_DELETE)
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400973 wm_log("deleted\n");
Kristian Høgsberge244cb02012-05-30 11:34:35 -0400974 else
975 read_and_dump_property(wm, property_notify->window,
976 property_notify->atom);
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400977
978 if (property_notify->atom == wm->atom.net_wm_name ||
979 property_notify->atom == XCB_ATOM_WM_NAME)
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400980 weston_wm_window_schedule_repaint(window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400981}
982
983static void
Kristian Høgsberg029539b2012-05-30 11:28:24 -0400984weston_wm_window_create(struct weston_wm *wm,
Tiago Vignatti771241e2012-06-04 20:01:45 +0300985 xcb_window_t id, int width, int height, int override)
Kristian Høgsberg029539b2012-05-30 11:28:24 -0400986{
987 struct weston_wm_window *window;
988 uint32_t values[1];
MoD384a11a2013-06-22 11:04:21 -0500989 xcb_get_geometry_cookie_t geometry_cookie;
990 xcb_get_geometry_reply_t *geometry_reply;
Kristian Høgsberg029539b2012-05-30 11:28:24 -0400991
992 window = malloc(sizeof *window);
993 if (window == NULL) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400994 wm_log("failed to allocate window\n");
Kristian Høgsberg029539b2012-05-30 11:28:24 -0400995 return;
996 }
997
MoD384a11a2013-06-22 11:04:21 -0500998 geometry_cookie = xcb_get_geometry(wm->conn, id);
999
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001000 values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE;
1001 xcb_change_window_attributes(wm->conn, id, XCB_CW_EVENT_MASK, values);
1002
1003 memset(window, 0, sizeof *window);
1004 window->wm = wm;
1005 window->id = id;
1006 window->properties_dirty = 1;
Tiago Vignatti771241e2012-06-04 20:01:45 +03001007 window->override_redirect = override;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001008 window->width = width;
1009 window->height = height;
1010
MoD384a11a2013-06-22 11:04:21 -05001011 geometry_reply = xcb_get_geometry_reply(wm->conn, geometry_cookie, NULL);
1012 /* technically we should use XRender and check the visual format's
1013 alpha_mask, but checking depth is simpler and works in all known cases */
1014 if(geometry_reply != NULL)
1015 window->has_alpha = geometry_reply->depth == 32;
1016 free(geometry_reply);
1017
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001018 hash_table_insert(wm->window_hash, id, window);
1019}
1020
1021static void
1022weston_wm_window_destroy(struct weston_wm_window *window)
1023{
1024 hash_table_remove(window->wm->window_hash, window->id);
1025 free(window);
1026}
1027
1028static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001029weston_wm_handle_create_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1030{
1031 xcb_create_notify_event_t *create_notify =
1032 (xcb_create_notify_event_t *) event;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001033
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001034 wm_log("XCB_CREATE_NOTIFY (window %d, width %d, height %d%s%s)\n",
1035 create_notify->window,
1036 create_notify->width, create_notify->height,
1037 create_notify->override_redirect ? ", override" : "",
1038 our_resource(wm, create_notify->window) ? ", ours" : "");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001039
1040 if (our_resource(wm, create_notify->window))
1041 return;
1042
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001043 weston_wm_window_create(wm, create_notify->window,
Tiago Vignatti771241e2012-06-04 20:01:45 +03001044 create_notify->width, create_notify->height,
1045 create_notify->override_redirect);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001046}
1047
1048static void
1049weston_wm_handle_destroy_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1050{
1051 xcb_destroy_notify_event_t *destroy_notify =
1052 (xcb_destroy_notify_event_t *) event;
1053 struct weston_wm_window *window;
1054
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001055 wm_log("XCB_DESTROY_NOTIFY, win %d, event %d%s\n",
1056 destroy_notify->window,
1057 destroy_notify->event,
1058 our_resource(wm, destroy_notify->window) ? ", ours" : "");
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001059
1060 if (our_resource(wm, destroy_notify->window))
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001061 return;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001062
1063 window = hash_table_lookup(wm->window_hash, destroy_notify->window);
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001064 weston_wm_window_destroy(window);
1065}
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001066
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001067static void
1068weston_wm_handle_reparent_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1069{
1070 xcb_reparent_notify_event_t *reparent_notify =
1071 (xcb_reparent_notify_event_t *) event;
1072 struct weston_wm_window *window;
Kristian Høgsbergc9571fb2012-05-29 15:35:29 -04001073
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001074 wm_log("XCB_REPARENT_NOTIFY (window %d, parent %d, event %d)\n",
1075 reparent_notify->window,
1076 reparent_notify->parent,
1077 reparent_notify->event);
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001078
1079 if (reparent_notify->parent == wm->screen->root) {
Tiago Vignatti771241e2012-06-04 20:01:45 +03001080 weston_wm_window_create(wm, reparent_notify->window, 10, 10,
1081 reparent_notify->override_redirect);
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001082 } else if (!our_resource(wm, reparent_notify->parent)) {
1083 window = hash_table_lookup(wm->window_hash,
1084 reparent_notify->window);
1085 weston_wm_window_destroy(window);
1086 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001087}
1088
Kristian Høgsberg5ba31892012-08-10 10:06:59 -04001089struct weston_seat *
1090weston_wm_pick_seat(struct weston_wm *wm)
1091{
1092 return container_of(wm->server->compositor->seat_list.next,
1093 struct weston_seat, link);
1094}
1095
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001096static void
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001097weston_wm_window_handle_moveresize(struct weston_wm_window *window,
1098 xcb_client_message_event_t *client_message)
1099{
1100 static const int map[] = {
1101 THEME_LOCATION_RESIZING_TOP_LEFT,
1102 THEME_LOCATION_RESIZING_TOP,
1103 THEME_LOCATION_RESIZING_TOP_RIGHT,
1104 THEME_LOCATION_RESIZING_RIGHT,
1105 THEME_LOCATION_RESIZING_BOTTOM_RIGHT,
1106 THEME_LOCATION_RESIZING_BOTTOM,
1107 THEME_LOCATION_RESIZING_BOTTOM_LEFT,
1108 THEME_LOCATION_RESIZING_LEFT
1109 };
1110
1111 struct weston_wm *wm = window->wm;
Kristian Høgsberg5ba31892012-08-10 10:06:59 -04001112 struct weston_seat *seat = weston_wm_pick_seat(wm);
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001113 int detail;
1114 struct weston_shell_interface *shell_interface =
1115 &wm->server->compositor->shell_interface;
1116
Kristian Høgsberge3148752013-05-06 23:19:49 -04001117 if (seat->pointer->button_count != 1 ||
Kristian Høgsbergfe7aa902013-05-08 09:54:37 -04001118 seat->pointer->focus != window->surface)
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001119 return;
1120
1121 detail = client_message->data.data32[2];
1122 switch (detail) {
1123 case _NET_WM_MOVERESIZE_MOVE:
1124 shell_interface->move(window->shsurf, seat);
1125 break;
1126 case _NET_WM_MOVERESIZE_SIZE_TOPLEFT:
1127 case _NET_WM_MOVERESIZE_SIZE_TOP:
1128 case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT:
1129 case _NET_WM_MOVERESIZE_SIZE_RIGHT:
1130 case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT:
1131 case _NET_WM_MOVERESIZE_SIZE_BOTTOM:
1132 case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT:
1133 case _NET_WM_MOVERESIZE_SIZE_LEFT:
1134 shell_interface->resize(window->shsurf, seat, map[detail]);
1135 break;
1136 case _NET_WM_MOVERESIZE_CANCEL:
1137 break;
1138 }
1139}
1140
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001141#define _NET_WM_STATE_REMOVE 0
1142#define _NET_WM_STATE_ADD 1
1143#define _NET_WM_STATE_TOGGLE 2
1144
1145static int
1146update_state(int action, int *state)
1147{
1148 int new_state, changed;
1149
1150 switch (action) {
1151 case _NET_WM_STATE_REMOVE:
1152 new_state = 0;
1153 break;
1154 case _NET_WM_STATE_ADD:
1155 new_state = 1;
1156 break;
1157 case _NET_WM_STATE_TOGGLE:
1158 new_state = !*state;
1159 break;
1160 default:
1161 return 0;
1162 }
1163
1164 changed = (*state != new_state);
1165 *state = new_state;
1166
1167 return changed;
1168}
1169
1170static void
1171weston_wm_window_configure(void *data);
1172
1173static void
1174weston_wm_window_handle_state(struct weston_wm_window *window,
1175 xcb_client_message_event_t *client_message)
1176{
1177 struct weston_wm *wm = window->wm;
1178 struct weston_shell_interface *shell_interface =
1179 &wm->server->compositor->shell_interface;
1180 uint32_t action, property;
1181
1182 action = client_message->data.data32[0];
1183 property = client_message->data.data32[1];
1184
1185 if (property == wm->atom.net_wm_state_fullscreen &&
1186 update_state(action, &window->fullscreen)) {
1187 weston_wm_window_set_net_wm_state(window);
1188 if (window->fullscreen) {
1189 window->saved_width = window->width;
1190 window->saved_height = window->height;
Kristian Høgsberg762b1662013-02-21 20:18:37 -05001191
1192 if (window->shsurf)
1193 shell_interface->set_fullscreen(window->shsurf,
1194 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
1195 0, NULL);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001196 } else {
1197 shell_interface->set_toplevel(window->shsurf);
1198 window->width = window->saved_width;
1199 window->height = window->saved_height;
1200 weston_wm_window_configure(window);
1201 }
1202 }
1203}
1204
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001205static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001206weston_wm_handle_client_message(struct weston_wm *wm,
1207 xcb_generic_event_t *event)
1208{
1209 xcb_client_message_event_t *client_message =
1210 (xcb_client_message_event_t *) event;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001211 struct weston_wm_window *window;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001212
1213 window = hash_table_lookup(wm->window_hash, client_message->window);
1214
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001215 wm_log("XCB_CLIENT_MESSAGE (%s %d %d %d %d %d win %d)\n",
1216 get_atom_name(wm->conn, client_message->type),
1217 client_message->data.data32[0],
1218 client_message->data.data32[1],
1219 client_message->data.data32[2],
1220 client_message->data.data32[3],
1221 client_message->data.data32[4],
1222 client_message->window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001223
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001224 if (client_message->type == wm->atom.net_wm_moveresize)
1225 weston_wm_window_handle_moveresize(window, client_message);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001226 else if (client_message->type == wm->atom.net_wm_state)
1227 weston_wm_window_handle_state(window, client_message);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001228}
1229
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001230enum cursor_type {
1231 XWM_CURSOR_TOP,
1232 XWM_CURSOR_BOTTOM,
1233 XWM_CURSOR_LEFT,
1234 XWM_CURSOR_RIGHT,
1235 XWM_CURSOR_TOP_LEFT,
1236 XWM_CURSOR_TOP_RIGHT,
1237 XWM_CURSOR_BOTTOM_LEFT,
1238 XWM_CURSOR_BOTTOM_RIGHT,
1239 XWM_CURSOR_LEFT_PTR,
1240};
1241
1242static const char *cursors[] = {
1243 "top_side",
1244 "bottom_side",
1245 "left_side",
1246 "right_side",
1247 "top_left_corner",
1248 "top_right_corner",
1249 "bottom_left_corner",
1250 "bottom_right_corner",
1251 "left_ptr"
1252};
1253
1254static void
1255weston_wm_create_cursors(struct weston_wm *wm)
1256{
1257 int i, count = ARRAY_LENGTH(cursors);
1258
1259 wm->cursors = malloc(count * sizeof(xcb_cursor_t));
1260 for (i = 0; i < count; i++) {
1261 wm->cursors[i] =
1262 xcb_cursor_library_load_cursor(wm, cursors[i]);
1263 }
1264
1265 wm->last_cursor = -1;
1266}
1267
1268static void
1269weston_wm_destroy_cursors(struct weston_wm *wm)
1270{
1271 uint8_t i;
1272
1273 for (i = 0; i < ARRAY_LENGTH(cursors); i++)
1274 xcb_free_cursor(wm->conn, wm->cursors[i]);
1275
1276 free(wm->cursors);
1277}
1278
1279static int
1280get_cursor_for_location(struct theme *t, int width, int height, int x, int y)
1281{
Scott Moreauc6a7e4b2012-09-28 02:45:06 -06001282 int location = theme_get_location(t, x, y, width, height, 0);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001283
1284 switch (location) {
1285 case THEME_LOCATION_RESIZING_TOP:
1286 return XWM_CURSOR_TOP;
1287 case THEME_LOCATION_RESIZING_BOTTOM:
1288 return XWM_CURSOR_BOTTOM;
1289 case THEME_LOCATION_RESIZING_LEFT:
1290 return XWM_CURSOR_LEFT;
1291 case THEME_LOCATION_RESIZING_RIGHT:
1292 return XWM_CURSOR_RIGHT;
1293 case THEME_LOCATION_RESIZING_TOP_LEFT:
1294 return XWM_CURSOR_TOP_LEFT;
1295 case THEME_LOCATION_RESIZING_TOP_RIGHT:
1296 return XWM_CURSOR_TOP_RIGHT;
1297 case THEME_LOCATION_RESIZING_BOTTOM_LEFT:
1298 return XWM_CURSOR_BOTTOM_LEFT;
1299 case THEME_LOCATION_RESIZING_BOTTOM_RIGHT:
1300 return XWM_CURSOR_BOTTOM_RIGHT;
1301 case THEME_LOCATION_EXTERIOR:
1302 case THEME_LOCATION_TITLEBAR:
1303 default:
1304 return XWM_CURSOR_LEFT_PTR;
1305 }
1306}
1307
1308static void
Tiago Vignattic1903232012-07-16 12:15:37 -04001309weston_wm_window_set_cursor(struct weston_wm *wm, xcb_window_t window_id,
1310 int cursor)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001311{
1312 uint32_t cursor_value_list;
1313
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001314 if (wm->last_cursor == cursor)
1315 return;
1316
1317 wm->last_cursor = cursor;
1318
1319 cursor_value_list = wm->cursors[cursor];
Tiago Vignattic1903232012-07-16 12:15:37 -04001320 xcb_change_window_attributes (wm->conn, window_id,
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001321 XCB_CW_CURSOR, &cursor_value_list);
1322 xcb_flush(wm->conn);
1323}
1324
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001325static void
1326weston_wm_handle_button(struct weston_wm *wm, xcb_generic_event_t *event)
1327{
1328 xcb_button_press_event_t *button = (xcb_button_press_event_t *) event;
1329 struct weston_shell_interface *shell_interface =
1330 &wm->server->compositor->shell_interface;
Kristian Høgsberg5ba31892012-08-10 10:06:59 -04001331 struct weston_seat *seat = weston_wm_pick_seat(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001332 struct weston_wm_window *window;
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001333 enum theme_location location;
1334 struct theme *t = wm->theme;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04001335 int width, height;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001336
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001337 wm_log("XCB_BUTTON_%s (detail %d)\n",
1338 button->response_type == XCB_BUTTON_PRESS ?
1339 "PRESS" : "RELEASE", button->detail);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001340
1341 window = hash_table_lookup(wm->window_hash, button->event);
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04001342 weston_wm_window_get_frame_size(window, &width, &height);
1343
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001344 if (button->response_type == XCB_BUTTON_PRESS &&
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001345 button->detail == 1) {
1346 location = theme_get_location(t,
1347 button->event_x,
1348 button->event_y,
Scott Moreauc6a7e4b2012-09-28 02:45:06 -06001349 width, height, 0);
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001350
1351 switch (location) {
1352 case THEME_LOCATION_TITLEBAR:
Kristian Høgsberg5ba31892012-08-10 10:06:59 -04001353 shell_interface->move(window->shsurf, seat);
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001354 break;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04001355 case THEME_LOCATION_RESIZING_TOP:
1356 case THEME_LOCATION_RESIZING_BOTTOM:
1357 case THEME_LOCATION_RESIZING_LEFT:
1358 case THEME_LOCATION_RESIZING_RIGHT:
1359 case THEME_LOCATION_RESIZING_TOP_LEFT:
1360 case THEME_LOCATION_RESIZING_TOP_RIGHT:
1361 case THEME_LOCATION_RESIZING_BOTTOM_LEFT:
1362 case THEME_LOCATION_RESIZING_BOTTOM_RIGHT:
1363 shell_interface->resize(window->shsurf,
Kristian Høgsberg5ba31892012-08-10 10:06:59 -04001364 seat, location);
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04001365 break;
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001366 default:
1367 break;
1368 }
1369 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001370}
1371
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001372static void
1373weston_wm_handle_motion(struct weston_wm *wm, xcb_generic_event_t *event)
1374{
1375 xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *) event;
1376 struct weston_wm_window *window;
1377 int cursor, width, height;
1378
1379 window = hash_table_lookup(wm->window_hash, motion->event);
Tiago Vignatti9134b772012-07-20 19:41:12 +03001380 if (!window || !window->decorate)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001381 return;
1382
1383 weston_wm_window_get_frame_size(window, &width, &height);
1384 cursor = get_cursor_for_location(wm->theme, width, height,
1385 motion->event_x, motion->event_y);
1386
Tiago Vignattic1903232012-07-16 12:15:37 -04001387 weston_wm_window_set_cursor(wm, window->frame_id, cursor);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001388}
1389
1390static void
1391weston_wm_handle_enter(struct weston_wm *wm, xcb_generic_event_t *event)
1392{
1393 xcb_enter_notify_event_t *enter = (xcb_enter_notify_event_t *) event;
1394 struct weston_wm_window *window;
1395 int cursor, width, height;
1396
1397 window = hash_table_lookup(wm->window_hash, enter->event);
Tiago Vignatti9134b772012-07-20 19:41:12 +03001398 if (!window || !window->decorate)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001399 return;
1400
1401 weston_wm_window_get_frame_size(window, &width, &height);
1402 cursor = get_cursor_for_location(wm->theme, width, height,
1403 enter->event_x, enter->event_y);
1404
Tiago Vignattic1903232012-07-16 12:15:37 -04001405 weston_wm_window_set_cursor(wm, window->frame_id, cursor);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001406}
1407
1408static void
1409weston_wm_handle_leave(struct weston_wm *wm, xcb_generic_event_t *event)
1410{
1411 xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *) event;
1412 struct weston_wm_window *window;
1413
1414 window = hash_table_lookup(wm->window_hash, leave->event);
Tiago Vignatti9134b772012-07-20 19:41:12 +03001415 if (!window || !window->decorate)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001416 return;
1417
Tiago Vignattic1903232012-07-16 12:15:37 -04001418 weston_wm_window_set_cursor(wm, window->frame_id, XWM_CURSOR_LEFT_PTR);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001419}
1420
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001421static int
1422weston_wm_handle_event(int fd, uint32_t mask, void *data)
1423{
1424 struct weston_wm *wm = data;
1425 xcb_generic_event_t *event;
1426 int count = 0;
1427
1428 while (event = xcb_poll_for_event(wm->conn), event != NULL) {
1429 if (weston_wm_handle_selection_event(wm, event)) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001430 free(event);
1431 count++;
1432 continue;
1433 }
1434
MoD31700122013-06-11 19:58:55 -05001435 switch (EVENT_TYPE(event)) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001436 case XCB_BUTTON_PRESS:
1437 case XCB_BUTTON_RELEASE:
1438 weston_wm_handle_button(wm, event);
1439 break;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001440 case XCB_ENTER_NOTIFY:
1441 weston_wm_handle_enter(wm, event);
1442 break;
1443 case XCB_LEAVE_NOTIFY:
1444 weston_wm_handle_leave(wm, event);
1445 break;
1446 case XCB_MOTION_NOTIFY:
1447 weston_wm_handle_motion(wm, event);
1448 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001449 case XCB_CREATE_NOTIFY:
1450 weston_wm_handle_create_notify(wm, event);
1451 break;
1452 case XCB_MAP_REQUEST:
1453 weston_wm_handle_map_request(wm, event);
1454 break;
1455 case XCB_MAP_NOTIFY:
1456 weston_wm_handle_map_notify(wm, event);
1457 break;
1458 case XCB_UNMAP_NOTIFY:
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001459 weston_wm_handle_unmap_notify(wm, event);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001460 break;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001461 case XCB_REPARENT_NOTIFY:
1462 weston_wm_handle_reparent_notify(wm, event);
1463 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001464 case XCB_CONFIGURE_REQUEST:
1465 weston_wm_handle_configure_request(wm, event);
1466 break;
1467 case XCB_CONFIGURE_NOTIFY:
1468 weston_wm_handle_configure_notify(wm, event);
1469 break;
1470 case XCB_DESTROY_NOTIFY:
1471 weston_wm_handle_destroy_notify(wm, event);
1472 break;
1473 case XCB_MAPPING_NOTIFY:
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001474 wm_log("XCB_MAPPING_NOTIFY\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001475 break;
1476 case XCB_PROPERTY_NOTIFY:
1477 weston_wm_handle_property_notify(wm, event);
1478 break;
1479 case XCB_CLIENT_MESSAGE:
1480 weston_wm_handle_client_message(wm, event);
1481 break;
1482 }
1483
1484 free(event);
1485 count++;
1486 }
1487
1488 xcb_flush(wm->conn);
1489
1490 return count;
1491}
1492
1493static void
Kristian Høgsbergf9187192013-05-02 13:43:24 -04001494weston_wm_get_visual_and_colormap(struct weston_wm *wm)
1495{
1496 xcb_depth_iterator_t d_iter;
1497 xcb_visualtype_iterator_t vt_iter;
1498 xcb_visualtype_t *visualtype;
1499
1500 d_iter = xcb_screen_allowed_depths_iterator(wm->screen);
1501 visualtype = NULL;
1502 while (d_iter.rem > 0) {
1503 if (d_iter.data->depth == 32) {
1504 vt_iter = xcb_depth_visuals_iterator(d_iter.data);
1505 visualtype = vt_iter.data;
1506 break;
1507 }
1508
1509 xcb_depth_next(&d_iter);
1510 }
1511
1512 if (visualtype == NULL) {
1513 weston_log("no 32 bit visualtype\n");
1514 return;
1515 }
1516
1517 wm->visual_id = visualtype->visual_id;
1518 wm->colormap = xcb_generate_id(wm->conn);
1519 xcb_create_colormap(wm->conn, XCB_COLORMAP_ALLOC_NONE,
1520 wm->colormap, wm->screen->root, wm->visual_id);
1521}
1522
1523static void
Tiago Vignatti9c4ff832012-11-30 17:19:57 -02001524weston_wm_get_resources(struct weston_wm *wm)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001525{
1526
1527#define F(field) offsetof(struct weston_wm, field)
1528
1529 static const struct { const char *name; int offset; } atoms[] = {
1530 { "WM_PROTOCOLS", F(atom.wm_protocols) },
1531 { "WM_TAKE_FOCUS", F(atom.wm_take_focus) },
1532 { "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -04001533 { "WM_STATE", F(atom.wm_state) },
Kristian Høgsberg670b5d32012-06-04 11:00:40 -04001534 { "WM_S0", F(atom.wm_s0) },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03001535 { "WM_CLIENT_MACHINE", F(atom.wm_client_machine) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001536 { "_NET_WM_NAME", F(atom.net_wm_name) },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03001537 { "_NET_WM_PID", F(atom.net_wm_pid) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001538 { "_NET_WM_ICON", F(atom.net_wm_icon) },
1539 { "_NET_WM_STATE", F(atom.net_wm_state) },
1540 { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
1541 { "_NET_WM_USER_TIME", F(atom.net_wm_user_time) },
1542 { "_NET_WM_ICON_NAME", F(atom.net_wm_icon_name) },
1543 { "_NET_WM_WINDOW_TYPE", F(atom.net_wm_window_type) },
1544
1545 { "_NET_WM_WINDOW_TYPE_DESKTOP", F(atom.net_wm_window_type_desktop) },
1546 { "_NET_WM_WINDOW_TYPE_DOCK", F(atom.net_wm_window_type_dock) },
1547 { "_NET_WM_WINDOW_TYPE_TOOLBAR", F(atom.net_wm_window_type_toolbar) },
1548 { "_NET_WM_WINDOW_TYPE_MENU", F(atom.net_wm_window_type_menu) },
1549 { "_NET_WM_WINDOW_TYPE_UTILITY", F(atom.net_wm_window_type_utility) },
1550 { "_NET_WM_WINDOW_TYPE_SPLASH", F(atom.net_wm_window_type_splash) },
1551 { "_NET_WM_WINDOW_TYPE_DIALOG", F(atom.net_wm_window_type_dialog) },
Tiago Vignattibf1e8662012-06-12 14:07:49 +03001552 { "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", F(atom.net_wm_window_type_dropdown) },
1553 { "_NET_WM_WINDOW_TYPE_POPUP_MENU", F(atom.net_wm_window_type_popup) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001554 { "_NET_WM_WINDOW_TYPE_TOOLTIP", F(atom.net_wm_window_type_tooltip) },
1555 { "_NET_WM_WINDOW_TYPE_NOTIFICATION", F(atom.net_wm_window_type_notification) },
1556 { "_NET_WM_WINDOW_TYPE_COMBO", F(atom.net_wm_window_type_combo) },
1557 { "_NET_WM_WINDOW_TYPE_DND", F(atom.net_wm_window_type_dnd) },
1558 { "_NET_WM_WINDOW_TYPE_NORMAL", F(atom.net_wm_window_type_normal) },
1559
1560 { "_NET_WM_MOVERESIZE", F(atom.net_wm_moveresize) },
1561 { "_NET_SUPPORTING_WM_CHECK",
1562 F(atom.net_supporting_wm_check) },
1563 { "_NET_SUPPORTED", F(atom.net_supported) },
1564 { "_MOTIF_WM_HINTS", F(atom.motif_wm_hints) },
1565 { "CLIPBOARD", F(atom.clipboard) },
Kristian Høgsbergcba022a2012-06-04 10:11:45 -04001566 { "CLIPBOARD_MANAGER", F(atom.clipboard_manager) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001567 { "TARGETS", F(atom.targets) },
1568 { "UTF8_STRING", F(atom.utf8_string) },
1569 { "_WL_SELECTION", F(atom.wl_selection) },
1570 { "INCR", F(atom.incr) },
1571 { "TIMESTAMP", F(atom.timestamp) },
1572 { "MULTIPLE", F(atom.multiple) },
1573 { "UTF8_STRING" , F(atom.utf8_string) },
1574 { "COMPOUND_TEXT", F(atom.compound_text) },
1575 { "TEXT", F(atom.text) },
1576 { "STRING", F(atom.string) },
1577 { "text/plain;charset=utf-8", F(atom.text_plain_utf8) },
1578 { "text/plain", F(atom.text_plain) },
1579 };
1580#undef F
1581
1582 xcb_xfixes_query_version_cookie_t xfixes_cookie;
1583 xcb_xfixes_query_version_reply_t *xfixes_reply;
1584 xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
1585 xcb_intern_atom_reply_t *reply;
1586 xcb_render_query_pict_formats_reply_t *formats_reply;
1587 xcb_render_query_pict_formats_cookie_t formats_cookie;
1588 xcb_render_pictforminfo_t *formats;
1589 uint32_t i;
1590
1591 xcb_prefetch_extension_data (wm->conn, &xcb_xfixes_id);
1592
1593 formats_cookie = xcb_render_query_pict_formats(wm->conn);
1594
1595 for (i = 0; i < ARRAY_LENGTH(atoms); i++)
1596 cookies[i] = xcb_intern_atom (wm->conn, 0,
1597 strlen(atoms[i].name),
1598 atoms[i].name);
1599
1600 for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
1601 reply = xcb_intern_atom_reply (wm->conn, cookies[i], NULL);
1602 *(xcb_atom_t *) ((char *) wm + atoms[i].offset) = reply->atom;
1603 free(reply);
1604 }
1605
1606 wm->xfixes = xcb_get_extension_data(wm->conn, &xcb_xfixes_id);
1607 if (!wm->xfixes || !wm->xfixes->present)
Martin Minarik6d118362012-06-07 18:01:59 +02001608 weston_log("xfixes not available\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001609
1610 xfixes_cookie = xcb_xfixes_query_version(wm->conn,
1611 XCB_XFIXES_MAJOR_VERSION,
1612 XCB_XFIXES_MINOR_VERSION);
1613 xfixes_reply = xcb_xfixes_query_version_reply(wm->conn,
1614 xfixes_cookie, NULL);
1615
Martin Minarik6d118362012-06-07 18:01:59 +02001616 weston_log("xfixes version: %d.%d\n",
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001617 xfixes_reply->major_version, xfixes_reply->minor_version);
1618
1619 free(xfixes_reply);
1620
1621 formats_reply = xcb_render_query_pict_formats_reply(wm->conn,
1622 formats_cookie, 0);
1623 if (formats_reply == NULL)
1624 return;
1625
1626 formats = xcb_render_query_pict_formats_formats(formats_reply);
Kristian Høgsberge89cef32012-07-16 11:57:08 -04001627 for (i = 0; i < formats_reply->num_formats; i++) {
1628 if (formats[i].direct.red_mask != 0xff &&
1629 formats[i].direct.red_shift != 16)
1630 continue;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001631 if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT &&
1632 formats[i].depth == 24)
Kristian Høgsberge89cef32012-07-16 11:57:08 -04001633 wm->format_rgb = formats[i];
1634 if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT &&
1635 formats[i].depth == 32 &&
1636 formats[i].direct.alpha_mask == 0xff &&
1637 formats[i].direct.alpha_shift == 24)
1638 wm->format_rgba = formats[i];
1639 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001640
1641 free(formats_reply);
1642}
1643
1644static void
1645weston_wm_create_wm_window(struct weston_wm *wm)
1646{
1647 static const char name[] = "Weston WM";
1648
1649 wm->wm_window = xcb_generate_id(wm->conn);
1650 xcb_create_window(wm->conn,
1651 XCB_COPY_FROM_PARENT,
1652 wm->wm_window,
1653 wm->screen->root,
1654 0, 0,
1655 10, 10,
1656 0,
1657 XCB_WINDOW_CLASS_INPUT_OUTPUT,
1658 wm->screen->root_visual,
1659 0, NULL);
1660
1661 xcb_change_property(wm->conn,
1662 XCB_PROP_MODE_REPLACE,
1663 wm->wm_window,
1664 wm->atom.net_supporting_wm_check,
1665 XCB_ATOM_WINDOW,
1666 32, /* format */
1667 1, &wm->wm_window);
1668
1669 xcb_change_property(wm->conn,
1670 XCB_PROP_MODE_REPLACE,
1671 wm->wm_window,
1672 wm->atom.net_wm_name,
1673 wm->atom.utf8_string,
1674 8, /* format */
1675 strlen(name), name);
1676
1677 xcb_change_property(wm->conn,
1678 XCB_PROP_MODE_REPLACE,
1679 wm->screen->root,
1680 wm->atom.net_supporting_wm_check,
1681 XCB_ATOM_WINDOW,
1682 32, /* format */
1683 1, &wm->wm_window);
1684
Kristian Høgsberg670b5d32012-06-04 11:00:40 -04001685 /* Claim the WM_S0 selection even though we don't suport
1686 * the --replace functionality. */
1687 xcb_set_selection_owner(wm->conn,
1688 wm->wm_window,
1689 wm->atom.wm_s0,
1690 XCB_TIME_CURRENT_TIME);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001691}
1692
1693struct weston_wm *
1694weston_wm_create(struct weston_xserver *wxs)
1695{
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001696 struct weston_wm *wm;
1697 struct wl_event_loop *loop;
1698 xcb_screen_iterator_t s;
Kristian Høgsberg4dec0112012-06-03 09:18:06 -04001699 uint32_t values[1];
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001700 int sv[2];
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001701 xcb_atom_t supported[3];
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001702
1703 wm = malloc(sizeof *wm);
1704 if (wm == NULL)
1705 return NULL;
1706
1707 memset(wm, 0, sizeof *wm);
1708 wm->server = wxs;
1709 wm->window_hash = hash_table_create();
1710 if (wm->window_hash == NULL) {
1711 free(wm);
1712 return NULL;
1713 }
1714
1715 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
Martin Minarik6d118362012-06-07 18:01:59 +02001716 weston_log("socketpair failed\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001717 hash_table_destroy(wm->window_hash);
1718 free(wm);
1719 return NULL;
1720 }
1721
1722 xserver_send_client(wxs->resource, sv[1]);
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05001723 wl_client_flush(wl_resource_get_client(wxs->resource));
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001724 close(sv[1]);
1725
1726 /* xcb_connect_to_fd takes ownership of the fd. */
1727 wm->conn = xcb_connect_to_fd(sv[0], NULL);
1728 if (xcb_connection_has_error(wm->conn)) {
Martin Minarik6d118362012-06-07 18:01:59 +02001729 weston_log("xcb_connect_to_fd failed\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001730 close(sv[0]);
1731 hash_table_destroy(wm->window_hash);
1732 free(wm);
1733 return NULL;
1734 }
1735
1736 s = xcb_setup_roots_iterator(xcb_get_setup(wm->conn));
1737 wm->screen = s.data;
1738
1739 loop = wl_display_get_event_loop(wxs->wl_display);
1740 wm->source =
1741 wl_event_loop_add_fd(loop, sv[0],
1742 WL_EVENT_READABLE,
1743 weston_wm_handle_event, wm);
1744 wl_event_source_check(wm->source);
1745
Tiago Vignatti9c4ff832012-11-30 17:19:57 -02001746 weston_wm_get_resources(wm);
Kristian Høgsbergf9187192013-05-02 13:43:24 -04001747 weston_wm_get_visual_and_colormap(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001748
1749 values[0] =
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001750 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
1751 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
1752 XCB_EVENT_MASK_PROPERTY_CHANGE;
1753 xcb_change_window_attributes(wm->conn, wm->screen->root,
1754 XCB_CW_EVENT_MASK, values);
1755 wm->theme = theme_create();
1756
1757 weston_wm_create_wm_window(wm);
1758
1759 supported[0] = wm->atom.net_wm_moveresize;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001760 supported[1] = wm->atom.net_wm_state;
1761 supported[2] = wm->atom.net_wm_state_fullscreen;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001762 xcb_change_property(wm->conn,
1763 XCB_PROP_MODE_REPLACE,
1764 wm->screen->root,
1765 wm->atom.net_supported,
1766 XCB_ATOM_ATOM,
1767 32, /* format */
1768 ARRAY_LENGTH(supported), supported);
1769
Kristian Høgsberg4dec0112012-06-03 09:18:06 -04001770 weston_wm_selection_init(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001771
1772 xcb_flush(wm->conn);
1773
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001774 wm->activate_listener.notify = weston_wm_window_activate;
1775 wl_signal_add(&wxs->compositor->activate_signal,
1776 &wm->activate_listener);
Tiago Vignattifb2adba2013-06-12 15:43:21 -03001777 wm->transform_listener.notify = weston_wm_window_transform;
1778 wl_signal_add(&wxs->compositor->transform_signal,
1779 &wm->transform_listener);
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03001780 wm->kill_listener.notify = weston_wm_kill_client;
1781 wl_signal_add(&wxs->compositor->kill_signal,
1782 &wm->kill_listener);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001783
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001784 weston_wm_create_cursors(wm);
Tiago Vignattic1903232012-07-16 12:15:37 -04001785 weston_wm_window_set_cursor(wm, wm->screen->root, XWM_CURSOR_LEFT_PTR);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001786
Martin Minarik6d118362012-06-07 18:01:59 +02001787 weston_log("created wm\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001788
1789 return wm;
1790}
1791
1792void
1793weston_wm_destroy(struct weston_wm *wm)
1794{
1795 /* FIXME: Free windows in hash. */
1796 hash_table_destroy(wm->window_hash);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001797 weston_wm_destroy_cursors(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001798 xcb_disconnect(wm->conn);
1799 wl_event_source_remove(wm->source);
1800 wl_list_remove(&wm->selection_listener.link);
1801 wl_list_remove(&wm->activate_listener.link);
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03001802 wl_list_remove(&wm->kill_listener.link);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001803
1804 free(wm);
1805}
1806
1807static void
1808surface_destroy(struct wl_listener *listener, void *data)
1809{
1810 struct weston_wm_window *window =
1811 container_of(listener,
1812 struct weston_wm_window, surface_destroy_listener);
1813
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001814 wm_log("surface for xid %d destroyed\n", window->id);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001815}
1816
1817static struct weston_wm_window *
1818get_wm_window(struct weston_surface *surface)
1819{
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001820 struct wl_listener *listener;
1821
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05001822 listener = wl_signal_get(&surface->destroy_signal, surface_destroy);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001823 if (listener)
1824 return container_of(listener, struct weston_wm_window,
1825 surface_destroy_listener);
1826
1827 return NULL;
1828}
1829
1830static void
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001831weston_wm_window_configure(void *data)
1832{
1833 struct weston_wm_window *window = data;
1834 struct weston_wm *wm = window->wm;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001835 uint32_t values[4];
1836 int x, y, width, height;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001837
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001838 weston_wm_window_get_child_position(window, &x, &y);
1839 values[0] = x;
1840 values[1] = y;
1841 values[2] = window->width;
1842 values[3] = window->height;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001843 xcb_configure_window(wm->conn,
1844 window->id,
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001845 XCB_CONFIG_WINDOW_X |
1846 XCB_CONFIG_WINDOW_Y |
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001847 XCB_CONFIG_WINDOW_WIDTH |
1848 XCB_CONFIG_WINDOW_HEIGHT,
1849 values);
1850
1851 weston_wm_window_get_frame_size(window, &width, &height);
1852 values[0] = width;
1853 values[1] = height;
1854 xcb_configure_window(wm->conn,
1855 window->frame_id,
1856 XCB_CONFIG_WINDOW_WIDTH |
1857 XCB_CONFIG_WINDOW_HEIGHT,
1858 values);
1859
1860 window->configure_source = NULL;
1861
1862 weston_wm_window_schedule_repaint(window);
1863}
1864
1865static void
1866send_configure(struct weston_surface *surface,
1867 uint32_t edges, int32_t width, int32_t height)
1868{
1869 struct weston_wm_window *window = get_wm_window(surface);
1870 struct weston_wm *wm = window->wm;
1871 struct theme *t = window->wm->theme;
1872
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001873 if (window->fullscreen) {
1874 window->width = width;
1875 window->height = height;
1876 } else if (window->decorate) {
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001877 window->width = width - 2 * (t->margin + t->width);
1878 window->height = height - 2 * t->margin -
1879 t->titlebar_height - t->width;
1880 } else {
1881 window->width = width - 2 * t->margin;
1882 window->height = height - 2 * t->margin;
1883 }
1884
1885 if (window->configure_source)
1886 return;
1887
1888 window->configure_source =
1889 wl_event_loop_add_idle(wm->server->loop,
1890 weston_wm_window_configure, window);
1891}
1892
1893static const struct weston_shell_client shell_client = {
1894 send_configure
1895};
1896
1897static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001898xserver_map_shell_surface(struct weston_wm *wm,
1899 struct weston_wm_window *window)
1900{
1901 struct weston_shell_interface *shell_interface =
1902 &wm->server->compositor->shell_interface;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001903 struct theme *t = window->wm->theme;
1904
1905 if (!shell_interface->create_shell_surface)
1906 return;
1907
1908 window->shsurf =
1909 shell_interface->create_shell_surface(shell_interface->shell,
Kristian Høgsberga61ca062012-05-22 16:05:52 -04001910 window->surface,
1911 &shell_client);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001912
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001913 if (window->fullscreen) {
1914 window->saved_width = window->width;
1915 window->saved_height = window->height;
1916 shell_interface->set_fullscreen(window->shsurf,
1917 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
1918 0, NULL);
1919 return;
1920 } else if (!window->override_redirect) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001921 shell_interface->set_toplevel(window->shsurf);
1922 return;
Tiago Vignattifb2adba2013-06-12 15:43:21 -03001923 } else {
1924 shell_interface->set_xwayland(window->shsurf,
1925 window->x + t->margin,
1926 window->y + t->margin,
1927 WL_SHELL_SURFACE_TRANSIENT_INACTIVE);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001928 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001929}
1930
1931static void
1932xserver_set_window_id(struct wl_client *client, struct wl_resource *resource,
1933 struct wl_resource *surface_resource, uint32_t id)
1934{
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05001935 struct weston_xserver *wxs = wl_resource_get_user_data(resource);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001936 struct weston_wm *wm = wxs->wm;
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05001937 struct weston_surface *surface =
1938 wl_resource_get_user_data(surface_resource);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001939 struct weston_wm_window *window;
1940
1941 if (client != wxs->client)
1942 return;
1943
1944 window = hash_table_lookup(wm->window_hash, id);
1945 if (window == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +02001946 weston_log("set_window_id for unknown window %d\n", id);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001947 return;
1948 }
1949
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001950 wm_log("set_window_id %d for surface %p\n", id, surface);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001951
1952 weston_wm_window_read_properties(window);
1953
1954 window->surface = (struct weston_surface *) surface;
1955 window->surface_destroy_listener.notify = surface_destroy;
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05001956 wl_signal_add(&surface->destroy_signal,
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001957 &window->surface_destroy_listener);
1958
1959 weston_wm_window_schedule_repaint(window);
1960 xserver_map_shell_surface(wm, window);
1961}
1962
1963const struct xserver_interface xserver_implementation = {
1964 xserver_set_window_id
1965};