blob: e7d5ee2afacf151f0ce5a98a254018f0e86feb8f [file] [log] [blame]
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001/*
2 * Copyright © 2011 Intel Corporation
3 *
Bryce Harrington0a007dd2015-06-11 16:22:34 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Kristian Høgsberg380deee2012-05-21 17:12:41 -040011 *
Bryce Harrington0a007dd2015-06-11 16:22:34 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Kristian Høgsberg380deee2012-05-21 17:12:41 -040024 */
25
Daniel Stonec228e232013-05-22 18:03:19 +030026#include "config.h"
Kristian Høgsberg380deee2012-05-21 17:12:41 -040027
28#include <stdlib.h>
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030029#include <stdint.h>
Kristian Høgsberg380deee2012-05-21 17:12:41 -040030#include <stdio.h>
31#include <string.h>
32#include <sys/socket.h>
33#include <sys/un.h>
34#include <fcntl.h>
35#include <errno.h>
36#include <unistd.h>
37#include <signal.h>
Tiago Vignatti90fada42012-07-16 12:02:08 -040038#include <X11/Xcursor/Xcursor.h>
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -050039#include <linux/input.h>
Kristian Høgsberg380deee2012-05-21 17:12:41 -040040
Daniel Stone67fe3db2016-10-31 14:51:18 +000041#include "compositor.h"
Kristian Høgsberg380deee2012-05-21 17:12:41 -040042#include "xwayland.h"
Quentin Glidic955cec02016-08-12 10:41:35 +020043#include "xwayland-internal-interface.h"
Kristian Høgsberg380deee2012-05-21 17:12:41 -040044
Kristian Høgsberg2ba10df2013-12-03 16:38:15 -080045#include "cairo-util.h"
Kristian Høgsberg380deee2012-05-21 17:12:41 -040046#include "hash.h"
Jon Cruz35b2eaa2015-06-15 15:37:08 -070047#include "shared/helpers.h"
Kristian Høgsberg380deee2012-05-21 17:12:41 -040048
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -070049struct wm_size_hints {
Bryce Harringtone00554b2015-06-12 10:17:39 -070050 uint32_t flags;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -070051 int32_t x, y;
52 int32_t width, height; /* should set so old wm's don't mess up */
53 int32_t min_width, min_height;
54 int32_t max_width, max_height;
Bryce Harringtone00554b2015-06-12 10:17:39 -070055 int32_t width_inc, height_inc;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -070056 struct {
57 int32_t x;
58 int32_t y;
59 } min_aspect, max_aspect;
60 int32_t base_width, base_height;
61 int32_t win_gravity;
62};
63
64#define USPosition (1L << 0)
65#define USSize (1L << 1)
66#define PPosition (1L << 2)
67#define PSize (1L << 3)
68#define PMinSize (1L << 4)
69#define PMaxSize (1L << 5)
70#define PResizeInc (1L << 6)
71#define PAspect (1L << 7)
72#define PBaseSize (1L << 8)
73#define PWinGravity (1L << 9)
74
Kristian Høgsberg380deee2012-05-21 17:12:41 -040075struct motif_wm_hints {
76 uint32_t flags;
77 uint32_t functions;
78 uint32_t decorations;
79 int32_t input_mode;
80 uint32_t status;
81};
82
83#define MWM_HINTS_FUNCTIONS (1L << 0)
84#define MWM_HINTS_DECORATIONS (1L << 1)
85#define MWM_HINTS_INPUT_MODE (1L << 2)
86#define MWM_HINTS_STATUS (1L << 3)
87
88#define MWM_FUNC_ALL (1L << 0)
89#define MWM_FUNC_RESIZE (1L << 1)
90#define MWM_FUNC_MOVE (1L << 2)
91#define MWM_FUNC_MINIMIZE (1L << 3)
92#define MWM_FUNC_MAXIMIZE (1L << 4)
93#define MWM_FUNC_CLOSE (1L << 5)
94
95#define MWM_DECOR_ALL (1L << 0)
96#define MWM_DECOR_BORDER (1L << 1)
97#define MWM_DECOR_RESIZEH (1L << 2)
98#define MWM_DECOR_TITLE (1L << 3)
99#define MWM_DECOR_MENU (1L << 4)
100#define MWM_DECOR_MINIMIZE (1L << 5)
101#define MWM_DECOR_MAXIMIZE (1L << 6)
102
Dima Ryazanovb0f5a252015-05-03 19:56:37 -0700103#define MWM_DECOR_EVERYTHING \
104 (MWM_DECOR_BORDER | MWM_DECOR_RESIZEH | MWM_DECOR_TITLE | \
105 MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE)
106
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400107#define MWM_INPUT_MODELESS 0
108#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
109#define MWM_INPUT_SYSTEM_MODAL 2
110#define MWM_INPUT_FULL_APPLICATION_MODAL 3
111#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
112
113#define MWM_TEAROFF_WINDOW (1L<<0)
114
115#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
116#define _NET_WM_MOVERESIZE_SIZE_TOP 1
117#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
118#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
119#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
120#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
121#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
122#define _NET_WM_MOVERESIZE_SIZE_LEFT 7
123#define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
124#define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
125#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
126#define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */
127
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400128struct weston_wm_window {
129 struct weston_wm *wm;
130 xcb_window_t id;
131 xcb_window_t frame_id;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500132 struct frame *frame;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400133 cairo_surface_t *cairo_surface;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700134 uint32_t surface_id;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400135 struct weston_surface *surface;
Quentin Glidic955cec02016-08-12 10:41:35 +0200136 struct weston_desktop_xwayland_surface *shsurf;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400137 struct wl_listener surface_destroy_listener;
138 struct wl_event_source *repaint_source;
Kristian Høgsberga61ca062012-05-22 16:05:52 -0400139 struct wl_event_source *configure_source;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400140 int properties_dirty;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300141 int pid;
142 char *machine;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400143 char *class;
144 char *name;
145 struct weston_wm_window *transient_for;
146 uint32_t protocols;
147 xcb_atom_t type;
148 int width, height;
149 int x, y;
Giulio Camuffof05d18f2015-12-11 20:57:05 +0200150 bool pos_dirty;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500151 int saved_width, saved_height;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400152 int decorate;
Tiago Vignatti771241e2012-06-04 20:01:45 +0300153 int override_redirect;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500154 int fullscreen;
MoD384a11a2013-06-22 11:04:21 -0500155 int has_alpha;
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -0700156 int delete_window;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +0200157 int maximized_vert;
158 int maximized_horz;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -0700159 struct wm_size_hints size_hints;
160 struct motif_wm_hints motif_hints;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700161 struct wl_list link;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400162};
163
164static struct weston_wm_window *
165get_wm_window(struct weston_surface *surface);
166
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400167static void
Benoit Gschwind1a42ca12015-09-25 21:26:04 +0200168weston_wm_set_net_active_window(struct weston_wm *wm, xcb_window_t window);
169
170static void
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400171weston_wm_window_schedule_repaint(struct weston_wm_window *window);
172
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700173static void
174xserver_map_shell_surface(struct weston_wm_window *window,
175 struct weston_surface *surface);
176
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400177static int __attribute__ ((format (printf, 1, 2)))
178wm_log(const char *fmt, ...)
179{
180#ifdef WM_DEBUG
181 int l;
182 va_list argp;
183
184 va_start(argp, fmt);
185 l = weston_vlog(fmt, argp);
186 va_end(argp);
187
188 return l;
189#else
190 return 0;
191#endif
192}
193
194static int __attribute__ ((format (printf, 1, 2)))
195wm_log_continue(const char *fmt, ...)
196{
197#ifdef WM_DEBUG
198 int l;
199 va_list argp;
200
201 va_start(argp, fmt);
202 l = weston_vlog_continue(fmt, argp);
203 va_end(argp);
204
205 return l;
206#else
207 return 0;
208#endif
209}
210
Derek Foreman49372142015-04-09 10:51:22 -0500211static bool __attribute__ ((warn_unused_result))
212wm_lookup_window(struct weston_wm *wm, xcb_window_t hash,
213 struct weston_wm_window **window)
214{
215 *window = hash_table_lookup(wm->window_hash, hash);
216 if (*window)
217 return true;
218 return false;
219}
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400220
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400221const char *
222get_atom_name(xcb_connection_t *c, xcb_atom_t atom)
223{
224 xcb_get_atom_name_cookie_t cookie;
225 xcb_get_atom_name_reply_t *reply;
226 xcb_generic_error_t *e;
227 static char buffer[64];
228
229 if (atom == XCB_ATOM_NONE)
230 return "None";
231
232 cookie = xcb_get_atom_name (c, atom);
233 reply = xcb_get_atom_name_reply (c, cookie, &e);
MoD55375b92013-06-11 19:59:42 -0500234
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300235 if (reply) {
MoD55375b92013-06-11 19:59:42 -0500236 snprintf(buffer, sizeof buffer, "%.*s",
237 xcb_get_atom_name_name_length (reply),
238 xcb_get_atom_name_name (reply));
239 } else {
240 snprintf(buffer, sizeof buffer, "(atom %u)", atom);
241 }
242
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400243 free(reply);
244
245 return buffer;
246}
247
Tiago Vignatti90fada42012-07-16 12:02:08 -0400248static xcb_cursor_t
249xcb_cursor_image_load_cursor(struct weston_wm *wm, const XcursorImage *img)
250{
251 xcb_connection_t *c = wm->conn;
252 xcb_screen_iterator_t s = xcb_setup_roots_iterator(xcb_get_setup(c));
253 xcb_screen_t *screen = s.data;
254 xcb_gcontext_t gc;
255 xcb_pixmap_t pix;
256 xcb_render_picture_t pic;
257 xcb_cursor_t cursor;
258 int stride = img->width * 4;
259
260 pix = xcb_generate_id(c);
261 xcb_create_pixmap(c, 32, pix, screen->root, img->width, img->height);
262
263 pic = xcb_generate_id(c);
264 xcb_render_create_picture(c, pic, pix, wm->format_rgba.id, 0, 0);
265
266 gc = xcb_generate_id(c);
267 xcb_create_gc(c, gc, pix, 0, 0);
268
269 xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc,
270 img->width, img->height, 0, 0, 0, 32,
271 stride * img->height, (uint8_t *) img->pixels);
272 xcb_free_gc(c, gc);
273
274 cursor = xcb_generate_id(c);
275 xcb_render_create_cursor(c, cursor, pic, img->xhot, img->yhot);
276
277 xcb_render_free_picture(c, pic);
278 xcb_free_pixmap(c, pix);
279
280 return cursor;
281}
282
283static xcb_cursor_t
284xcb_cursor_images_load_cursor(struct weston_wm *wm, const XcursorImages *images)
285{
286 /* TODO: treat animated cursors as well */
287 if (images->nimage != 1)
288 return -1;
289
290 return xcb_cursor_image_load_cursor(wm, images->images[0]);
291}
292
293static xcb_cursor_t
294xcb_cursor_library_load_cursor(struct weston_wm *wm, const char *file)
295{
296 xcb_cursor_t cursor;
297 XcursorImages *images;
298 char *v = NULL;
299 int size = 0;
300
301 if (!file)
302 return 0;
303
304 v = getenv ("XCURSOR_SIZE");
305 if (v)
306 size = atoi(v);
307
308 if (!size)
309 size = 32;
310
311 images = XcursorLibraryLoadImages (file, NULL, size);
Tiago Vignattiac78bb12012-09-28 16:29:46 +0300312 if (!images)
313 return -1;
314
Tiago Vignatti90fada42012-07-16 12:02:08 -0400315 cursor = xcb_cursor_images_load_cursor (wm, images);
316 XcursorImagesDestroy (images);
317
318 return cursor;
319}
320
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400321void
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400322dump_property(struct weston_wm *wm,
323 xcb_atom_t property, xcb_get_property_reply_t *reply)
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400324{
325 int32_t *incr_value;
326 const char *text_value, *name;
327 xcb_atom_t *atom_value;
328 int width, len;
329 uint32_t i;
330
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400331 width = wm_log_continue("%s: ", get_atom_name(wm->conn, property));
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400332 if (reply == NULL) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400333 wm_log_continue("(no reply)\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400334 return;
335 }
336
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400337 width += wm_log_continue("%s/%d, length %d (value_len %d): ",
338 get_atom_name(wm->conn, reply->type),
339 reply->format,
340 xcb_get_property_value_length(reply),
341 reply->value_len);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400342
343 if (reply->type == wm->atom.incr) {
344 incr_value = xcb_get_property_value(reply);
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400345 wm_log_continue("%d\n", *incr_value);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400346 } else if (reply->type == wm->atom.utf8_string ||
347 reply->type == wm->atom.string) {
348 text_value = xcb_get_property_value(reply);
349 if (reply->value_len > 40)
350 len = 40;
351 else
352 len = reply->value_len;
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400353 wm_log_continue("\"%.*s\"\n", len, text_value);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400354 } else if (reply->type == XCB_ATOM_ATOM) {
355 atom_value = xcb_get_property_value(reply);
356 for (i = 0; i < reply->value_len; i++) {
357 name = get_atom_name(wm->conn, atom_value[i]);
358 if (width + strlen(name) + 2 > 78) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400359 wm_log_continue("\n ");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400360 width = 4;
361 } else if (i > 0) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400362 width += wm_log_continue(", ");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400363 }
364
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400365 width += wm_log_continue("%s", name);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400366 }
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400367 wm_log_continue("\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400368 } else {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400369 wm_log_continue("huh?\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400370 }
371}
372
Tiago Vignatti2d129f12012-11-30 17:19:59 -0200373static void
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400374read_and_dump_property(struct weston_wm *wm,
375 xcb_window_t window, xcb_atom_t property)
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400376{
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400377 xcb_get_property_reply_t *reply;
378 xcb_get_property_cookie_t cookie;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400379
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400380 cookie = xcb_get_property(wm->conn, 0, window,
381 property, XCB_ATOM_ANY, 0, 2048);
382 reply = xcb_get_property_reply(wm->conn, cookie, NULL);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400383
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400384 dump_property(wm, property, reply);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400385
Kristian Høgsberg0273b572012-05-30 09:58:02 -0400386 free(reply);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400387}
388
389/* We reuse some predefined, but otherwise useles atoms */
390#define TYPE_WM_PROTOCOLS XCB_ATOM_CUT_BUFFER0
391#define TYPE_MOTIF_WM_HINTS XCB_ATOM_CUT_BUFFER1
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500392#define TYPE_NET_WM_STATE XCB_ATOM_CUT_BUFFER2
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -0700393#define TYPE_WM_NORMAL_HINTS XCB_ATOM_CUT_BUFFER3
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400394
395static void
396weston_wm_window_read_properties(struct weston_wm_window *window)
397{
398 struct weston_wm *wm = window->wm;
Quentin Glidic955cec02016-08-12 10:41:35 +0200399 const struct weston_desktop_xwayland_interface *xwayland_interface =
400 wm->server->compositor->xwayland_interface;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400401
402#define F(field) offsetof(struct weston_wm_window, field)
403 const struct {
404 xcb_atom_t atom;
405 xcb_atom_t type;
406 int offset;
407 } props[] = {
408 { XCB_ATOM_WM_CLASS, XCB_ATOM_STRING, F(class) },
409 { XCB_ATOM_WM_NAME, XCB_ATOM_STRING, F(name) },
410 { XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, F(transient_for) },
411 { wm->atom.wm_protocols, TYPE_WM_PROTOCOLS, F(protocols) },
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -0700412 { wm->atom.wm_normal_hints, TYPE_WM_NORMAL_HINTS, F(protocols) },
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500413 { wm->atom.net_wm_state, TYPE_NET_WM_STATE },
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400414 { wm->atom.net_wm_window_type, XCB_ATOM_ATOM, F(type) },
415 { wm->atom.net_wm_name, XCB_ATOM_STRING, F(name) },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300416 { wm->atom.net_wm_pid, XCB_ATOM_CARDINAL, F(pid) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400417 { wm->atom.motif_wm_hints, TYPE_MOTIF_WM_HINTS, 0 },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300418 { wm->atom.wm_client_machine, XCB_ATOM_WM_CLIENT_MACHINE, F(machine) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400419 };
420#undef F
421
422 xcb_get_property_cookie_t cookie[ARRAY_LENGTH(props)];
423 xcb_get_property_reply_t *reply;
424 void *p;
425 uint32_t *xid;
426 xcb_atom_t *atom;
427 uint32_t i;
Giulio Camuffoa8e9b412015-01-27 19:10:37 +0200428 char name[1024];
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400429
430 if (!window->properties_dirty)
431 return;
432 window->properties_dirty = 0;
433
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400434 for (i = 0; i < ARRAY_LENGTH(props); i++)
435 cookie[i] = xcb_get_property(wm->conn,
436 0, /* delete */
437 window->id,
438 props[i].atom,
439 XCB_ATOM_ANY, 0, 2048);
440
Dima Ryazanovb0f5a252015-05-03 19:56:37 -0700441 window->decorate = window->override_redirect ? 0 : MWM_DECOR_EVERYTHING;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -0700442 window->size_hints.flags = 0;
443 window->motif_hints.flags = 0;
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -0700444 window->delete_window = 0;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -0700445
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400446 for (i = 0; i < ARRAY_LENGTH(props); i++) {
447 reply = xcb_get_property_reply(wm->conn, cookie[i], NULL);
448 if (!reply)
449 /* Bad window, typically */
450 continue;
451 if (reply->type == XCB_ATOM_NONE) {
452 /* No such property */
453 free(reply);
454 continue;
455 }
456
457 p = ((char *) window + props[i].offset);
458
459 switch (props[i].type) {
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300460 case XCB_ATOM_WM_CLIENT_MACHINE:
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400461 case XCB_ATOM_STRING:
462 /* FIXME: We're using this for both string and
463 utf8_string */
464 if (*(char **) p)
465 free(*(char **) p);
466
467 *(char **) p =
468 strndup(xcb_get_property_value(reply),
469 xcb_get_property_value_length(reply));
470 break;
471 case XCB_ATOM_WINDOW:
472 xid = xcb_get_property_value(reply);
Derek Foreman49372142015-04-09 10:51:22 -0500473 if (!wm_lookup_window(wm, *xid, p))
474 weston_log("XCB_ATOM_WINDOW contains window"
475 " id not found in hash table.\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400476 break;
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300477 case XCB_ATOM_CARDINAL:
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400478 case XCB_ATOM_ATOM:
479 atom = xcb_get_property_value(reply);
480 *(xcb_atom_t *) p = *atom;
481 break;
482 case TYPE_WM_PROTOCOLS:
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -0700483 atom = xcb_get_property_value(reply);
484 for (i = 0; i < reply->value_len; i++)
Derek Foremanb4deec62015-04-07 12:12:13 -0500485 if (atom[i] == wm->atom.wm_delete_window) {
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -0700486 window->delete_window = 1;
Derek Foremanb4deec62015-04-07 12:12:13 -0500487 break;
488 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400489 break;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -0700490 case TYPE_WM_NORMAL_HINTS:
491 memcpy(&window->size_hints,
492 xcb_get_property_value(reply),
493 sizeof window->size_hints);
494 break;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500495 case TYPE_NET_WM_STATE:
496 window->fullscreen = 0;
497 atom = xcb_get_property_value(reply);
Ryo Munakataf3744f52015-03-11 17:36:30 +0900498 for (i = 0; i < reply->value_len; i++) {
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500499 if (atom[i] == wm->atom.net_wm_state_fullscreen)
500 window->fullscreen = 1;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +0200501 if (atom[i] == wm->atom.net_wm_state_maximized_vert)
502 window->maximized_vert = 1;
503 if (atom[i] == wm->atom.net_wm_state_maximized_horz)
504 window->maximized_horz = 1;
Ryo Munakataf3744f52015-03-11 17:36:30 +0900505 }
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500506 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400507 case TYPE_MOTIF_WM_HINTS:
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -0700508 memcpy(&window->motif_hints,
509 xcb_get_property_value(reply),
510 sizeof window->motif_hints);
Dima Ryazanovb0f5a252015-05-03 19:56:37 -0700511 if (window->motif_hints.flags & MWM_HINTS_DECORATIONS) {
512 if (window->motif_hints.decorations & MWM_DECOR_ALL)
513 /* MWM_DECOR_ALL means all except the other values listed. */
514 window->decorate =
515 MWM_DECOR_EVERYTHING & (~window->motif_hints.decorations);
516 else
517 window->decorate =
518 window->motif_hints.decorations;
519 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400520 break;
521 default:
522 break;
523 }
524 free(reply);
525 }
Giulio Camuffo62942ad2013-09-11 18:20:47 +0200526
Giulio Camuffoa8e9b412015-01-27 19:10:37 +0200527 if (window->pid > 0) {
528 gethostname(name, sizeof(name));
529 for (i = 0; i < sizeof(name); i++) {
530 if (name[i] == '\0')
531 break;
532 }
533 if (i == sizeof(name))
534 name[0] = '\0'; /* ignore stupid hostnames */
535
536 /* this is only one heuristic to guess the PID of a client is
537 * valid, assuming it's compliant with icccm and ewmh.
538 * Non-compliants and remote applications of course fail. */
539 if (!window->machine || strcmp(window->machine, name))
540 window->pid = 0;
541 }
542
Giulio Camuffo62942ad2013-09-11 18:20:47 +0200543 if (window->shsurf && window->name)
Quentin Glidic955cec02016-08-12 10:41:35 +0200544 xwayland_interface->set_title(window->shsurf, window->name);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500545 if (window->frame && window->name)
546 frame_set_title(window->frame, window->name);
Giulio Camuffoa8e9b412015-01-27 19:10:37 +0200547 if (window->shsurf && window->pid > 0)
Quentin Glidic955cec02016-08-12 10:41:35 +0200548 xwayland_interface->set_pid(window->shsurf, window->pid);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400549}
550
551static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400552weston_wm_window_get_frame_size(struct weston_wm_window *window,
553 int *width, int *height)
554{
555 struct theme *t = window->wm->theme;
556
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500557 if (window->fullscreen) {
558 *width = window->width;
559 *height = window->height;
Dima Ryazanovcae1f0f2013-11-15 02:02:23 -0800560 } else if (window->decorate && window->frame) {
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500561 *width = frame_width(window->frame);
562 *height = frame_height(window->frame);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400563 } else {
564 *width = window->width + t->margin * 2;
565 *height = window->height + t->margin * 2;
566 }
567}
568
569static void
570weston_wm_window_get_child_position(struct weston_wm_window *window,
571 int *x, int *y)
572{
573 struct theme *t = window->wm->theme;
574
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500575 if (window->fullscreen) {
576 *x = 0;
577 *y = 0;
Dima Ryazanovcae1f0f2013-11-15 02:02:23 -0800578 } else if (window->decorate && window->frame) {
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500579 frame_interior(window->frame, x, y, NULL, NULL);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400580 } else {
581 *x = t->margin;
582 *y = t->margin;
583 }
584}
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400585
586static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500587weston_wm_window_send_configure_notify(struct weston_wm_window *window)
588{
589 xcb_configure_notify_event_t configure_notify;
590 struct weston_wm *wm = window->wm;
591 int x, y;
592
593 weston_wm_window_get_child_position(window, &x, &y);
594 configure_notify.response_type = XCB_CONFIGURE_NOTIFY;
595 configure_notify.pad0 = 0;
596 configure_notify.event = window->id;
597 configure_notify.window = window->id;
598 configure_notify.above_sibling = XCB_WINDOW_NONE;
599 configure_notify.x = x;
600 configure_notify.y = y;
601 configure_notify.width = window->width;
602 configure_notify.height = window->height;
603 configure_notify.border_width = 0;
604 configure_notify.override_redirect = 0;
605 configure_notify.pad1 = 0;
606
Murray Calavera883ac022015-06-06 13:02:22 +0000607 xcb_send_event(wm->conn, 0, window->id,
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500608 XCB_EVENT_MASK_STRUCTURE_NOTIFY,
609 (char *) &configure_notify);
610}
611
612static void
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400613weston_wm_handle_configure_request(struct weston_wm *wm, xcb_generic_event_t *event)
614{
Murray Calavera883ac022015-06-06 13:02:22 +0000615 xcb_configure_request_event_t *configure_request =
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400616 (xcb_configure_request_event_t *) event;
617 struct weston_wm_window *window;
618 uint32_t mask, values[16];
619 int x, y, width, height, i = 0;
620
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400621 wm_log("XCB_CONFIGURE_REQUEST (window %d) %d,%d @ %dx%d\n",
622 configure_request->window,
623 configure_request->x, configure_request->y,
624 configure_request->width, configure_request->height);
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400625
Derek Foreman49372142015-04-09 10:51:22 -0500626 if (!wm_lookup_window(wm, configure_request->window, &window))
627 return;
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400628
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500629 if (window->fullscreen) {
630 weston_wm_window_send_configure_notify(window);
631 return;
632 }
633
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400634 if (configure_request->value_mask & XCB_CONFIG_WINDOW_WIDTH)
635 window->width = configure_request->width;
636 if (configure_request->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
637 window->height = configure_request->height;
638
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500639 if (window->frame)
640 frame_resize_inside(window->frame, window->width, window->height);
641
Kristian Høgsbergeaee7842012-05-22 10:04:20 -0400642 weston_wm_window_get_child_position(window, &x, &y);
643 values[i++] = x;
644 values[i++] = y;
645 values[i++] = window->width;
646 values[i++] = window->height;
647 values[i++] = 0;
648 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
649 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
650 XCB_CONFIG_WINDOW_BORDER_WIDTH;
651 if (configure_request->value_mask & XCB_CONFIG_WINDOW_SIBLING) {
652 values[i++] = configure_request->sibling;
653 mask |= XCB_CONFIG_WINDOW_SIBLING;
654 }
655 if (configure_request->value_mask & XCB_CONFIG_WINDOW_STACK_MODE) {
656 values[i++] = configure_request->stack_mode;
657 mask |= XCB_CONFIG_WINDOW_STACK_MODE;
658 }
659
660 xcb_configure_window(wm->conn, window->id, mask, values);
661
662 weston_wm_window_get_frame_size(window, &width, &height);
663 values[0] = width;
664 values[1] = height;
665 mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
666 xcb_configure_window(wm->conn, window->frame_id, mask, values);
667
668 weston_wm_window_schedule_repaint(window);
669}
670
Kristian Høgsberg00db2ee2013-07-04 02:29:32 -0400671static int
672our_resource(struct weston_wm *wm, uint32_t id)
673{
674 const xcb_setup_t *setup;
675
676 setup = xcb_get_setup(wm->conn);
677
678 return (id & ~setup->resource_id_mask) == setup->resource_id_base;
679}
680
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400681static void
682weston_wm_handle_configure_notify(struct weston_wm *wm, xcb_generic_event_t *event)
683{
Murray Calavera883ac022015-06-06 13:02:22 +0000684 xcb_configure_notify_event_t *configure_notify =
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400685 (xcb_configure_notify_event_t *) event;
686 struct weston_wm_window *window;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400687
Kristian Høgsberg00db2ee2013-07-04 02:29:32 -0400688 wm_log("XCB_CONFIGURE_NOTIFY (window %d) %d,%d @ %dx%d\n",
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400689 configure_notify->window,
690 configure_notify->x, configure_notify->y,
691 configure_notify->width, configure_notify->height);
Tiago Vignattie66fcee2012-07-20 23:09:54 +0300692
Derek Foreman49372142015-04-09 10:51:22 -0500693 if (!wm_lookup_window(wm, configure_notify->window, &window))
694 return;
695
Kristian Høgsberg122877d2013-08-22 16:18:17 -0700696 window->x = configure_notify->x;
697 window->y = configure_notify->y;
Giulio Camuffof05d18f2015-12-11 20:57:05 +0200698 window->pos_dirty = false;
699
Kristian Høgsberg1b6fed42013-08-31 00:00:57 -0700700 if (window->override_redirect) {
701 window->width = configure_notify->width;
702 window->height = configure_notify->height;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500703 if (window->frame)
704 frame_resize_inside(window->frame,
705 window->width, window->height);
Kristian Høgsberg1b6fed42013-08-31 00:00:57 -0700706 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400707}
708
709static void
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300710weston_wm_kill_client(struct wl_listener *listener, void *data)
711{
712 struct weston_surface *surface = data;
713 struct weston_wm_window *window = get_wm_window(surface);
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300714 if (!window)
715 return;
716
Giulio Camuffoa8e9b412015-01-27 19:10:37 +0200717 if (window->pid > 0)
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +0300718 kill(window->pid, SIGKILL);
719}
720
721static void
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700722weston_wm_create_surface(struct wl_listener *listener, void *data)
723{
724 struct weston_surface *surface = data;
725 struct weston_wm *wm =
726 container_of(listener,
727 struct weston_wm, create_surface_listener);
728 struct weston_wm_window *window;
729
730 if (wl_resource_get_client(surface->resource) != wm->server->client)
731 return;
732
733 wl_list_for_each(window, &wm->unpaired_window_list, link)
734 if (window->surface_id ==
735 wl_resource_get_id(surface->resource)) {
736 xserver_map_shell_surface(window, surface);
Kristian Høgsbergba83db22014-04-07 10:16:19 -0700737 window->surface_id = 0;
738 wl_list_remove(&window->link);
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700739 break;
Murray Calavera883ac022015-06-06 13:02:22 +0000740 }
Kristian Høgsberg757d8af2014-03-17 22:33:29 -0700741}
742
743static void
Giulio Camuffob18f7882015-03-29 14:20:23 +0300744weston_wm_send_focus_window(struct weston_wm *wm,
745 struct weston_wm_window *window)
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400746{
Scott Moreau85ecac02012-05-21 15:49:14 -0600747 xcb_client_message_event_t client_message;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400748
Scott Moreau85ecac02012-05-21 15:49:14 -0600749 if (window) {
Jasper St. Pierref30af4e2015-03-22 10:14:49 -0700750 uint32_t values[1];
751
Boyan Dingb9f863c2014-08-30 10:33:23 +0800752 if (window->override_redirect)
753 return;
754
Scott Moreau85ecac02012-05-21 15:49:14 -0600755 client_message.response_type = XCB_CLIENT_MESSAGE;
756 client_message.format = 32;
757 client_message.window = window->id;
758 client_message.type = wm->atom.wm_protocols;
759 client_message.data.data32[0] = wm->atom.wm_take_focus;
760 client_message.data.data32[1] = XCB_TIME_CURRENT_TIME;
761
Murray Calavera883ac022015-06-06 13:02:22 +0000762 xcb_send_event(wm->conn, 0, window->id,
Scott Moreau85ecac02012-05-21 15:49:14 -0600763 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
764 (char *) &client_message);
765
766 xcb_set_input_focus (wm->conn, XCB_INPUT_FOCUS_POINTER_ROOT,
767 window->id, XCB_TIME_CURRENT_TIME);
Jasper St. Pierref30af4e2015-03-22 10:14:49 -0700768
769 values[0] = XCB_STACK_MODE_ABOVE;
770 xcb_configure_window (wm->conn, window->frame_id,
771 XCB_CONFIG_WINDOW_STACK_MODE, values);
Scott Moreau85ecac02012-05-21 15:49:14 -0600772 } else {
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400773 xcb_set_input_focus (wm->conn,
774 XCB_INPUT_FOCUS_POINTER_ROOT,
775 XCB_NONE,
776 XCB_TIME_CURRENT_TIME);
Scott Moreau85ecac02012-05-21 15:49:14 -0600777 }
Giulio Camuffob18f7882015-03-29 14:20:23 +0300778}
779
780static void
781weston_wm_window_activate(struct wl_listener *listener, void *data)
782{
Jonas Ådahlf7deb6a2016-07-22 17:50:26 +0800783 struct weston_surface_activation_data *activation_data = data;
784 struct weston_surface *surface = activation_data->surface;
Giulio Camuffob18f7882015-03-29 14:20:23 +0300785 struct weston_wm_window *window = NULL;
786 struct weston_wm *wm =
787 container_of(listener, struct weston_wm, activate_listener);
788
789 if (surface) {
790 window = get_wm_window(surface);
791 }
792
Benoit Gschwind1a42ca12015-09-25 21:26:04 +0200793 if (window) {
794 weston_wm_set_net_active_window(wm, window->id);
795 } else {
796 weston_wm_set_net_active_window(wm, XCB_WINDOW_NONE);
797 }
798
Giulio Camuffob18f7882015-03-29 14:20:23 +0300799 weston_wm_send_focus_window(wm, window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400800
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500801 if (wm->focus_window) {
Dima Ryazanovb03b87f2013-11-15 02:01:19 -0800802 if (wm->focus_window->frame)
803 frame_unset_flag(wm->focus_window->frame, FRAME_FLAG_ACTIVE);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400804 weston_wm_window_schedule_repaint(wm->focus_window);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500805 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400806 wm->focus_window = window;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500807 if (wm->focus_window) {
Dima Ryazanovb03b87f2013-11-15 02:01:19 -0800808 if (wm->focus_window->frame)
809 frame_set_flag(wm->focus_window->frame, FRAME_FLAG_ACTIVE);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400810 weston_wm_window_schedule_repaint(wm->focus_window);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500811 }
Benoit Gschwind1a42ca12015-09-25 21:26:04 +0200812
813 xcb_flush(wm->conn);
814
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400815}
816
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -0400817#define ICCCM_WITHDRAWN_STATE 0
818#define ICCCM_NORMAL_STATE 1
819#define ICCCM_ICONIC_STATE 3
820
821static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500822weston_wm_window_set_wm_state(struct weston_wm_window *window, int32_t state)
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -0400823{
824 struct weston_wm *wm = window->wm;
825 uint32_t property[2];
826
827 property[0] = state;
828 property[1] = XCB_WINDOW_NONE;
829
830 xcb_change_property(wm->conn,
831 XCB_PROP_MODE_REPLACE,
832 window->id,
833 wm->atom.wm_state,
834 wm->atom.wm_state,
835 32, /* format */
836 2, property);
837}
838
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400839static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500840weston_wm_window_set_net_wm_state(struct weston_wm_window *window)
841{
842 struct weston_wm *wm = window->wm;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +0200843 uint32_t property[3];
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500844 int i;
845
846 i = 0;
847 if (window->fullscreen)
848 property[i++] = wm->atom.net_wm_state_fullscreen;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +0200849 if (window->maximized_vert)
850 property[i++] = wm->atom.net_wm_state_maximized_vert;
851 if (window->maximized_horz)
852 property[i++] = wm->atom.net_wm_state_maximized_horz;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -0500853
854 xcb_change_property(wm->conn,
855 XCB_PROP_MODE_REPLACE,
856 window->id,
857 wm->atom.net_wm_state,
858 XCB_ATOM_ATOM,
859 32, /* format */
860 i, property);
861}
862
863static void
Kristian Høgsberg318ea372013-09-03 16:19:18 -0700864weston_wm_window_create_frame(struct weston_wm_window *window)
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400865{
Kristian Høgsberg318ea372013-09-03 16:19:18 -0700866 struct weston_wm *wm = window->wm;
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400867 uint32_t values[3];
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400868 int x, y, width, height;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +0200869 int buttons = FRAME_BUTTON_CLOSE;
870
871 if (window->decorate & MWM_DECOR_MAXIMIZE)
872 buttons |= FRAME_BUTTON_MAXIMIZE;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400873
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500874 window->frame = frame_create(window->wm->theme,
875 window->width, window->height,
Giulio Camuffo6b4b2412015-01-29 19:06:49 +0200876 buttons, window->name);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -0500877 frame_resize_inside(window->frame, window->width, window->height);
878
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400879 weston_wm_window_get_frame_size(window, &width, &height);
880 weston_wm_window_get_child_position(window, &x, &y);
881
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400882 values[0] = wm->screen->black_pixel;
883 values[1] =
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400884 XCB_EVENT_MASK_KEY_PRESS |
885 XCB_EVENT_MASK_KEY_RELEASE |
886 XCB_EVENT_MASK_BUTTON_PRESS |
887 XCB_EVENT_MASK_BUTTON_RELEASE |
Tiago Vignatti236b48d2012-07-16 12:09:19 -0400888 XCB_EVENT_MASK_POINTER_MOTION |
889 XCB_EVENT_MASK_ENTER_WINDOW |
890 XCB_EVENT_MASK_LEAVE_WINDOW |
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400891 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
Kristian Høgsberg44c20132012-05-30 10:09:21 -0400892 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400893 values[2] = wm->colormap;
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400894
895 window->frame_id = xcb_generate_id(wm->conn);
896 xcb_create_window(wm->conn,
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400897 32,
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400898 window->frame_id,
899 wm->screen->root,
900 0, 0,
901 width, height,
902 0,
903 XCB_WINDOW_CLASS_INPUT_OUTPUT,
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400904 wm->visual_id,
905 XCB_CW_BORDER_PIXEL |
906 XCB_CW_EVENT_MASK |
907 XCB_CW_COLORMAP, values);
908
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400909 xcb_reparent_window(wm->conn, window->id, window->frame_id, x, y);
910
911 values[0] = 0;
912 xcb_configure_window(wm->conn, window->id,
913 XCB_CONFIG_WINDOW_BORDER_WIDTH, values);
914
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400915 window->cairo_surface =
916 cairo_xcb_surface_create_with_xrender_format(wm->conn,
917 wm->screen,
918 window->frame_id,
Kristian Høgsbergf9187192013-05-02 13:43:24 -0400919 &wm->format_rgba,
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400920 width, height);
921
922 hash_table_insert(wm->window_hash, window->frame_id, window);
923}
924
Giulio Camuffoe90ea442014-12-13 18:06:34 +0200925/*
926 * Sets the _NET_WM_DESKTOP property for the window to 'desktop'.
927 * Passing a <0 desktop value deletes the property.
928 */
929static void
930weston_wm_window_set_virtual_desktop(struct weston_wm_window *window,
Bryce Harringtone00554b2015-06-12 10:17:39 -0700931 int desktop)
Giulio Camuffoe90ea442014-12-13 18:06:34 +0200932{
933 if (desktop >= 0) {
934 xcb_change_property(window->wm->conn,
935 XCB_PROP_MODE_REPLACE,
936 window->id,
937 window->wm->atom.net_wm_desktop,
938 XCB_ATOM_CARDINAL,
939 32, /* format */
940 1, &desktop);
941 } else {
942 xcb_delete_property(window->wm->conn,
943 window->id,
944 window->wm->atom.net_wm_desktop);
945 }
946}
947
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400948static void
Kristian Høgsberg318ea372013-09-03 16:19:18 -0700949weston_wm_handle_map_request(struct weston_wm *wm, xcb_generic_event_t *event)
950{
951 xcb_map_request_event_t *map_request =
952 (xcb_map_request_event_t *) event;
953 struct weston_wm_window *window;
954
955 if (our_resource(wm, map_request->window)) {
956 wm_log("XCB_MAP_REQUEST (window %d, ours)\n",
957 map_request->window);
958 return;
959 }
960
Derek Foreman49372142015-04-09 10:51:22 -0500961 if (!wm_lookup_window(wm, map_request->window, &window))
962 return;
Kristian Høgsberg318ea372013-09-03 16:19:18 -0700963
964 weston_wm_window_read_properties(window);
965
966 if (window->frame_id == XCB_WINDOW_NONE)
967 weston_wm_window_create_frame(window);
968
Pekka Paalanen44660c32016-11-14 15:38:43 +0200969 wm_log("XCB_MAP_REQUEST (window %d, %p, frame %d, %dx%d @ %d,%d)\n",
970 window->id, window, window->frame_id,
971 window->width, window->height, window->x, window->y);
Kristian Høgsberg318ea372013-09-03 16:19:18 -0700972
973 weston_wm_window_set_wm_state(window, ICCCM_NORMAL_STATE);
974 weston_wm_window_set_net_wm_state(window);
Giulio Camuffoe90ea442014-12-13 18:06:34 +0200975 weston_wm_window_set_virtual_desktop(window, 0);
Kristian Høgsberg318ea372013-09-03 16:19:18 -0700976
977 xcb_map_window(wm->conn, map_request->window);
978 xcb_map_window(wm->conn, window->frame_id);
979}
980
981static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400982weston_wm_handle_map_notify(struct weston_wm *wm, xcb_generic_event_t *event)
983{
984 xcb_map_notify_event_t *map_notify = (xcb_map_notify_event_t *) event;
985
986 if (our_resource(wm, map_notify->window)) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400987 wm_log("XCB_MAP_NOTIFY (window %d, ours)\n",
988 map_notify->window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400989 return;
990 }
991
Kristian Høgsberg082d58c2013-06-18 01:00:27 -0400992 wm_log("XCB_MAP_NOTIFY (window %d)\n", map_notify->window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -0400993}
994
995static void
Kristian Høgsberg194ea542012-05-30 10:05:41 -0400996weston_wm_handle_unmap_notify(struct weston_wm *wm, xcb_generic_event_t *event)
997{
998 xcb_unmap_notify_event_t *unmap_notify =
999 (xcb_unmap_notify_event_t *) event;
1000 struct weston_wm_window *window;
1001
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001002 wm_log("XCB_UNMAP_NOTIFY (window %d, event %d%s)\n",
1003 unmap_notify->window,
1004 unmap_notify->event,
1005 our_resource(wm, unmap_notify->window) ? ", ours" : "");
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001006
1007 if (our_resource(wm, unmap_notify->window))
1008 return;
1009
MoD31700122013-06-11 19:58:55 -05001010 if (unmap_notify->response_type & SEND_EVENT_MASK)
Kristian Høgsbergd64bdf42012-05-31 10:33:43 -04001011 /* We just ignore the ICCCM 4.1.4 synthetic unmap notify
1012 * as it may come in after we've destroyed the window. */
Kristian Høgsbergf197e9f2012-05-30 11:46:29 -04001013 return;
Kristian Høgsbergf197e9f2012-05-30 11:46:29 -04001014
Derek Foreman49372142015-04-09 10:51:22 -05001015 if (!wm_lookup_window(wm, unmap_notify->window, &window))
1016 return;
1017
Derek Foreman9a0b2b52015-04-09 14:48:22 -05001018 if (window->surface_id) {
1019 /* Make sure we're not on the unpaired surface list or we
1020 * could be assigned a surface during surface creation that
1021 * was mapped before this unmap request.
1022 */
1023 wl_list_remove(&window->link);
1024 window->surface_id = 0;
1025 }
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001026 if (wm->focus_window == window)
1027 wm->focus_window = NULL;
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001028 if (window->surface)
1029 wl_list_remove(&window->surface_destroy_listener.link);
1030 window->surface = NULL;
Giulio Camuffo85739ea2013-09-17 16:43:45 +02001031 window->shsurf = NULL;
Giulio Camuffoe90ea442014-12-13 18:06:34 +02001032
1033 weston_wm_window_set_wm_state(window, ICCCM_WITHDRAWN_STATE);
1034 weston_wm_window_set_virtual_desktop(window, -1);
1035
Kristian Høgsbergab6d6672013-09-03 16:38:51 -07001036 xcb_unmap_window(wm->conn, window->frame_id);
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001037}
1038
1039static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001040weston_wm_window_draw_decoration(void *data)
1041{
1042 struct weston_wm_window *window = data;
1043 struct weston_wm *wm = window->wm;
1044 struct theme *t = wm->theme;
1045 cairo_t *cr;
1046 int x, y, width, height;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001047 int32_t input_x, input_y, input_w, input_h;
Quentin Glidic955cec02016-08-12 10:41:35 +02001048 const struct weston_desktop_xwayland_interface *xwayland_interface =
1049 wm->server->compositor->xwayland_interface;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001050 uint32_t flags = 0;
Giulio Camuffoaa974782015-02-01 16:18:51 +02001051 struct weston_view *view;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001052
1053 weston_wm_window_read_properties(window);
1054
1055 window->repaint_source = NULL;
1056
1057 weston_wm_window_get_frame_size(window, &width, &height);
1058 weston_wm_window_get_child_position(window, &x, &y);
1059
1060 cairo_xcb_surface_set_size(window->cairo_surface, width, height);
1061 cr = cairo_create(window->cairo_surface);
1062
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001063 if (window->fullscreen) {
1064 /* nothing */
1065 } else if (window->decorate) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001066 if (wm->focus_window == window)
1067 flags |= THEME_FRAME_ACTIVE;
1068
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001069 frame_repaint(window->frame, cr);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001070 } else {
1071 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1072 cairo_set_source_rgba(cr, 0, 0, 0, 0);
1073 cairo_paint(cr);
1074
Marek Chalupa0d7fe8d2014-10-29 14:51:22 +01001075 render_shadow(cr, t->shadow, 2, 2, width + 8, height + 8, 64, 64);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001076 }
1077
1078 cairo_destroy(cr);
1079
1080 if (window->surface) {
Scott Moreau76d8fc82012-11-22 15:35:13 -07001081 pixman_region32_fini(&window->surface->pending.opaque);
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001082 if (window->has_alpha) {
MoD384a11a2013-06-22 11:04:21 -05001083 pixman_region32_init(&window->surface->pending.opaque);
1084 } else {
1085 /* We leave an extra pixel around the X window area to
1086 * make sure we don't sample from the undefined alpha
1087 * channel when filtering. */
Murray Calavera883ac022015-06-06 13:02:22 +00001088 pixman_region32_init_rect(&window->surface->pending.opaque,
MoD384a11a2013-06-22 11:04:21 -05001089 x - 1, y - 1,
1090 window->width + 2,
1091 window->height + 2);
1092 }
Giulio Camuffoaa974782015-02-01 16:18:51 +02001093 wl_list_for_each(view, &window->surface->views, surface_link)
1094 weston_view_geometry_dirty(view);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001095
Kristian Høgsberg81585e92013-02-14 22:01:58 -05001096 pixman_region32_fini(&window->surface->pending.input);
Kristian Høgsberg1d75c7d2013-10-30 23:46:08 -07001097
Jasper St. Pierred19e9b02015-03-21 21:24:43 -07001098 if (window->decorate && !window->fullscreen) {
Kristian Høgsberg1d75c7d2013-10-30 23:46:08 -07001099 frame_input_rect(window->frame, &input_x, &input_y,
1100 &input_w, &input_h);
Jasper St. Pierred19e9b02015-03-21 21:24:43 -07001101 } else {
1102 input_x = x;
1103 input_y = y;
1104 input_w = width;
1105 input_h = height;
Kristian Høgsberg1d75c7d2013-10-30 23:46:08 -07001106 }
1107
Kristian Høgsbergd8b617d2013-02-14 21:56:32 -05001108 pixman_region32_init_rect(&window->surface->pending.input,
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001109 input_x, input_y, input_w, input_h);
Jasper St. Pierreccf48fb2014-05-02 10:21:38 -04001110
Quentin Glidic955cec02016-08-12 10:41:35 +02001111 xwayland_interface->set_window_geometry(window->shsurf,
1112 input_x, input_y, input_w, input_h);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001113 }
1114}
1115
1116static void
1117weston_wm_window_schedule_repaint(struct weston_wm_window *window)
1118{
1119 struct weston_wm *wm = window->wm;
Giulio Camuffoaa974782015-02-01 16:18:51 +02001120 struct weston_view *view;
Pekka Paalanen4f9c07b2012-09-03 16:48:41 +03001121 int width, height;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001122
Kristian Høgsbergc4063f32012-07-22 15:32:45 -04001123 if (window->frame_id == XCB_WINDOW_NONE) {
1124 if (window->surface != NULL) {
Pekka Paalanen4f9c07b2012-09-03 16:48:41 +03001125 weston_wm_window_get_frame_size(window, &width, &height);
Scott Moreau76d8fc82012-11-22 15:35:13 -07001126 pixman_region32_fini(&window->surface->pending.opaque);
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001127 if (window->has_alpha) {
MoD384a11a2013-06-22 11:04:21 -05001128 pixman_region32_init(&window->surface->pending.opaque);
1129 } else {
1130 pixman_region32_init_rect(&window->surface->pending.opaque, 0, 0,
1131 width, height);
1132 }
Giulio Camuffoaa974782015-02-01 16:18:51 +02001133 wl_list_for_each(view, &window->surface->views, surface_link)
1134 weston_view_geometry_dirty(view);
Kristian Høgsbergc4063f32012-07-22 15:32:45 -04001135 }
1136 return;
1137 }
1138
1139 if (window->repaint_source)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001140 return;
1141
1142 window->repaint_source =
1143 wl_event_loop_add_idle(wm->server->loop,
1144 weston_wm_window_draw_decoration,
1145 window);
1146}
1147
1148static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001149weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1150{
1151 xcb_property_notify_event_t *property_notify =
1152 (xcb_property_notify_event_t *) event;
1153 struct weston_wm_window *window;
1154
Derek Foreman49372142015-04-09 10:51:22 -05001155 if (!wm_lookup_window(wm, property_notify->window, &window))
Rob Bradfordaa521bd2013-01-10 19:48:57 +00001156 return;
1157
1158 window->properties_dirty = 1;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001159
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001160 wm_log("XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
Kristian Høgsberge244cb02012-05-30 11:34:35 -04001161 if (property_notify->state == XCB_PROPERTY_DELETE)
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001162 wm_log("deleted\n");
Kristian Høgsberge244cb02012-05-30 11:34:35 -04001163 else
1164 read_and_dump_property(wm, property_notify->window,
1165 property_notify->atom);
Kristian Høgsberg0273b572012-05-30 09:58:02 -04001166
1167 if (property_notify->atom == wm->atom.net_wm_name ||
1168 property_notify->atom == XCB_ATOM_WM_NAME)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001169 weston_wm_window_schedule_repaint(window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001170}
1171
1172static void
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001173weston_wm_window_create(struct weston_wm *wm,
Giulio Camuffoca43f092013-09-11 17:49:13 +02001174 xcb_window_t id, int width, int height, int x, int y, int override)
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001175{
1176 struct weston_wm_window *window;
1177 uint32_t values[1];
MoD384a11a2013-06-22 11:04:21 -05001178 xcb_get_geometry_cookie_t geometry_cookie;
1179 xcb_get_geometry_reply_t *geometry_reply;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001180
Peter Huttererf3d62272013-08-08 11:57:05 +10001181 window = zalloc(sizeof *window);
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001182 if (window == NULL) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001183 wm_log("failed to allocate window\n");
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001184 return;
1185 }
1186
MoD384a11a2013-06-22 11:04:21 -05001187 geometry_cookie = xcb_get_geometry(wm->conn, id);
1188
Giulio Camuffob18f7882015-03-29 14:20:23 +03001189 values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE |
1190 XCB_EVENT_MASK_FOCUS_CHANGE;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001191 xcb_change_window_attributes(wm->conn, id, XCB_CW_EVENT_MASK, values);
1192
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001193 window->wm = wm;
1194 window->id = id;
1195 window->properties_dirty = 1;
Tiago Vignatti771241e2012-06-04 20:01:45 +03001196 window->override_redirect = override;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001197 window->width = width;
1198 window->height = height;
Giulio Camuffoca43f092013-09-11 17:49:13 +02001199 window->x = x;
1200 window->y = y;
Giulio Camuffof05d18f2015-12-11 20:57:05 +02001201 window->pos_dirty = false;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001202
MoD384a11a2013-06-22 11:04:21 -05001203 geometry_reply = xcb_get_geometry_reply(wm->conn, geometry_cookie, NULL);
1204 /* technically we should use XRender and check the visual format's
1205 alpha_mask, but checking depth is simpler and works in all known cases */
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001206 if (geometry_reply != NULL)
MoD384a11a2013-06-22 11:04:21 -05001207 window->has_alpha = geometry_reply->depth == 32;
1208 free(geometry_reply);
1209
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001210 hash_table_insert(wm->window_hash, id, window);
1211}
1212
1213static void
1214weston_wm_window_destroy(struct weston_wm_window *window)
1215{
Kristian Høgsbergab6d6672013-09-03 16:38:51 -07001216 struct weston_wm *wm = window->wm;
1217
1218 if (window->repaint_source)
1219 wl_event_source_remove(window->repaint_source);
1220 if (window->cairo_surface)
1221 cairo_surface_destroy(window->cairo_surface);
1222
1223 if (window->frame_id) {
1224 xcb_reparent_window(wm->conn, window->id, wm->wm_window, 0, 0);
1225 xcb_destroy_window(wm->conn, window->frame_id);
1226 weston_wm_window_set_wm_state(window, ICCCM_WITHDRAWN_STATE);
Giulio Camuffoe90ea442014-12-13 18:06:34 +02001227 weston_wm_window_set_virtual_desktop(window, -1);
Kristian Høgsbergab6d6672013-09-03 16:38:51 -07001228 hash_table_remove(wm->window_hash, window->frame_id);
1229 window->frame_id = XCB_WINDOW_NONE;
1230 }
1231
Kristian Høgsbergba83db22014-04-07 10:16:19 -07001232 if (window->surface_id)
1233 wl_list_remove(&window->link);
1234
Derek Foreman9a0b2b52015-04-09 14:48:22 -05001235 if (window->surface)
1236 wl_list_remove(&window->surface_destroy_listener.link);
1237
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001238 hash_table_remove(window->wm->window_hash, window->id);
1239 free(window);
1240}
1241
1242static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001243weston_wm_handle_create_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1244{
1245 xcb_create_notify_event_t *create_notify =
1246 (xcb_create_notify_event_t *) event;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001247
Pekka Paalanen7db6c432016-11-14 14:30:57 +02001248 wm_log("XCB_CREATE_NOTIFY (window %d, at (%d, %d), width %d, height %d%s%s)\n",
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001249 create_notify->window,
Pekka Paalanen7db6c432016-11-14 14:30:57 +02001250 create_notify->x, create_notify->y,
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001251 create_notify->width, create_notify->height,
1252 create_notify->override_redirect ? ", override" : "",
1253 our_resource(wm, create_notify->window) ? ", ours" : "");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001254
1255 if (our_resource(wm, create_notify->window))
1256 return;
1257
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001258 weston_wm_window_create(wm, create_notify->window,
Tiago Vignatti771241e2012-06-04 20:01:45 +03001259 create_notify->width, create_notify->height,
Giulio Camuffoca43f092013-09-11 17:49:13 +02001260 create_notify->x, create_notify->y,
Tiago Vignatti771241e2012-06-04 20:01:45 +03001261 create_notify->override_redirect);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001262}
1263
1264static void
1265weston_wm_handle_destroy_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1266{
1267 xcb_destroy_notify_event_t *destroy_notify =
1268 (xcb_destroy_notify_event_t *) event;
1269 struct weston_wm_window *window;
1270
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001271 wm_log("XCB_DESTROY_NOTIFY, win %d, event %d%s\n",
1272 destroy_notify->window,
1273 destroy_notify->event,
1274 our_resource(wm, destroy_notify->window) ? ", ours" : "");
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001275
1276 if (our_resource(wm, destroy_notify->window))
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001277 return;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001278
Derek Foreman49372142015-04-09 10:51:22 -05001279 if (!wm_lookup_window(wm, destroy_notify->window, &window))
1280 return;
1281
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001282 weston_wm_window_destroy(window);
1283}
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001284
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001285static void
1286weston_wm_handle_reparent_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1287{
1288 xcb_reparent_notify_event_t *reparent_notify =
1289 (xcb_reparent_notify_event_t *) event;
1290 struct weston_wm_window *window;
Kristian Høgsbergc9571fb2012-05-29 15:35:29 -04001291
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001292 wm_log("XCB_REPARENT_NOTIFY (window %d, parent %d, event %d)\n",
1293 reparent_notify->window,
1294 reparent_notify->parent,
1295 reparent_notify->event);
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001296
1297 if (reparent_notify->parent == wm->screen->root) {
Tiago Vignatti771241e2012-06-04 20:01:45 +03001298 weston_wm_window_create(wm, reparent_notify->window, 10, 10,
Giulio Camuffoca43f092013-09-11 17:49:13 +02001299 reparent_notify->x, reparent_notify->y,
Tiago Vignatti771241e2012-06-04 20:01:45 +03001300 reparent_notify->override_redirect);
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001301 } else if (!our_resource(wm, reparent_notify->parent)) {
Derek Foreman49372142015-04-09 10:51:22 -05001302 if (!wm_lookup_window(wm, reparent_notify->window, &window))
1303 return;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001304 weston_wm_window_destroy(window);
1305 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001306}
1307
Kristian Høgsberg5ba31892012-08-10 10:06:59 -04001308struct weston_seat *
1309weston_wm_pick_seat(struct weston_wm *wm)
1310{
Tom Hochsteine7fff212016-11-01 14:14:00 -05001311 struct wl_list *seats = wm->server->compositor->seat_list.next;
1312 if (wl_list_empty(seats))
1313 return NULL;
1314 return container_of(seats, struct weston_seat, link);
Kristian Høgsberg5ba31892012-08-10 10:06:59 -04001315}
1316
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001317static struct weston_seat *
1318weston_wm_pick_seat_for_window(struct weston_wm_window *window)
1319{
1320 struct weston_wm *wm = window->wm;
1321 struct weston_seat *seat, *s;
1322
1323 seat = NULL;
1324 wl_list_for_each(s, &wm->server->compositor->seat_list, link) {
Derek Foreman1281a362015-07-31 16:55:32 -05001325 struct weston_pointer *pointer = weston_seat_get_pointer(s);
1326 struct weston_pointer *old_pointer =
1327 weston_seat_get_pointer(seat);
1328
1329 if (pointer && pointer->focus &&
1330 pointer->focus->surface == window->surface &&
1331 pointer->button_count > 0 &&
1332 (!seat ||
1333 pointer->grab_serial -
1334 old_pointer->grab_serial < (1 << 30)))
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001335 seat = s;
1336 }
1337
1338 return seat;
1339}
1340
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001341static void
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001342weston_wm_window_handle_moveresize(struct weston_wm_window *window,
1343 xcb_client_message_event_t *client_message)
1344{
1345 static const int map[] = {
1346 THEME_LOCATION_RESIZING_TOP_LEFT,
1347 THEME_LOCATION_RESIZING_TOP,
1348 THEME_LOCATION_RESIZING_TOP_RIGHT,
1349 THEME_LOCATION_RESIZING_RIGHT,
1350 THEME_LOCATION_RESIZING_BOTTOM_RIGHT,
1351 THEME_LOCATION_RESIZING_BOTTOM,
1352 THEME_LOCATION_RESIZING_BOTTOM_LEFT,
1353 THEME_LOCATION_RESIZING_LEFT
1354 };
1355
1356 struct weston_wm *wm = window->wm;
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001357 struct weston_seat *seat = weston_wm_pick_seat_for_window(window);
Derek Foreman1281a362015-07-31 16:55:32 -05001358 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001359 int detail;
Quentin Glidic955cec02016-08-12 10:41:35 +02001360 const struct weston_desktop_xwayland_interface *xwayland_interface =
1361 wm->server->compositor->xwayland_interface;
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001362
Derek Foreman1281a362015-07-31 16:55:32 -05001363 if (!pointer || pointer->button_count != 1
1364 || !pointer->focus
1365 || pointer->focus->surface != window->surface)
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001366 return;
1367
1368 detail = client_message->data.data32[2];
1369 switch (detail) {
1370 case _NET_WM_MOVERESIZE_MOVE:
Quentin Glidic955cec02016-08-12 10:41:35 +02001371 xwayland_interface->move(window->shsurf, pointer);
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001372 break;
1373 case _NET_WM_MOVERESIZE_SIZE_TOPLEFT:
1374 case _NET_WM_MOVERESIZE_SIZE_TOP:
1375 case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT:
1376 case _NET_WM_MOVERESIZE_SIZE_RIGHT:
1377 case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT:
1378 case _NET_WM_MOVERESIZE_SIZE_BOTTOM:
1379 case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT:
1380 case _NET_WM_MOVERESIZE_SIZE_LEFT:
Quentin Glidic955cec02016-08-12 10:41:35 +02001381 xwayland_interface->resize(window->shsurf, pointer, map[detail]);
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001382 break;
1383 case _NET_WM_MOVERESIZE_CANCEL:
1384 break;
1385 }
1386}
1387
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001388#define _NET_WM_STATE_REMOVE 0
1389#define _NET_WM_STATE_ADD 1
1390#define _NET_WM_STATE_TOGGLE 2
1391
1392static int
1393update_state(int action, int *state)
1394{
1395 int new_state, changed;
1396
1397 switch (action) {
1398 case _NET_WM_STATE_REMOVE:
1399 new_state = 0;
1400 break;
1401 case _NET_WM_STATE_ADD:
1402 new_state = 1;
1403 break;
1404 case _NET_WM_STATE_TOGGLE:
1405 new_state = !*state;
1406 break;
1407 default:
1408 return 0;
1409 }
1410
1411 changed = (*state != new_state);
1412 *state = new_state;
1413
1414 return changed;
1415}
1416
1417static void
1418weston_wm_window_configure(void *data);
1419
1420static void
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001421weston_wm_window_set_toplevel(struct weston_wm_window *window)
1422{
Quentin Glidic955cec02016-08-12 10:41:35 +02001423 const struct weston_desktop_xwayland_interface *xwayland_interface =
1424 window->wm->server->compositor->xwayland_interface;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001425
Quentin Glidic955cec02016-08-12 10:41:35 +02001426 xwayland_interface->set_toplevel(window->shsurf);
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001427 window->width = window->saved_width;
1428 window->height = window->saved_height;
1429 if (window->frame)
1430 frame_resize_inside(window->frame,
1431 window->width,
1432 window->height);
1433 weston_wm_window_configure(window);
1434}
1435
1436static inline bool
1437weston_wm_window_is_maximized(struct weston_wm_window *window)
1438{
1439 return window->maximized_horz && window->maximized_vert;
1440}
1441
1442static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001443weston_wm_window_handle_state(struct weston_wm_window *window,
1444 xcb_client_message_event_t *client_message)
1445{
1446 struct weston_wm *wm = window->wm;
Quentin Glidic955cec02016-08-12 10:41:35 +02001447 const struct weston_desktop_xwayland_interface *xwayland_interface =
1448 wm->server->compositor->xwayland_interface;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001449 uint32_t action, property;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001450 int maximized = weston_wm_window_is_maximized(window);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001451
1452 action = client_message->data.data32[0];
1453 property = client_message->data.data32[1];
1454
1455 if (property == wm->atom.net_wm_state_fullscreen &&
1456 update_state(action, &window->fullscreen)) {
1457 weston_wm_window_set_net_wm_state(window);
1458 if (window->fullscreen) {
1459 window->saved_width = window->width;
1460 window->saved_height = window->height;
Kristian Høgsberg762b1662013-02-21 20:18:37 -05001461
1462 if (window->shsurf)
Quentin Glidic955cec02016-08-12 10:41:35 +02001463 xwayland_interface->set_fullscreen(window->shsurf,
1464 NULL);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001465 } else {
Andrew Engelbrecht4c5a6f72014-12-02 12:18:44 -05001466 if (window->shsurf)
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001467 weston_wm_window_set_toplevel(window);
1468 }
1469 } else {
1470 if (property == wm->atom.net_wm_state_maximized_vert &&
1471 update_state(action, &window->maximized_vert))
1472 weston_wm_window_set_net_wm_state(window);
1473 if (property == wm->atom.net_wm_state_maximized_horz &&
1474 update_state(action, &window->maximized_horz))
1475 weston_wm_window_set_net_wm_state(window);
Andrew Engelbrecht4c5a6f72014-12-02 12:18:44 -05001476
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001477 if (maximized != weston_wm_window_is_maximized(window)) {
1478 if (weston_wm_window_is_maximized(window)) {
1479 window->saved_width = window->width;
1480 window->saved_height = window->height;
1481
1482 if (window->shsurf)
Quentin Glidic955cec02016-08-12 10:41:35 +02001483 xwayland_interface->set_maximized(window->shsurf);
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001484 } else if (window->shsurf) {
1485 weston_wm_window_set_toplevel(window);
1486 }
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001487 }
1488 }
1489}
1490
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001491static void
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001492surface_destroy(struct wl_listener *listener, void *data)
1493{
1494 struct weston_wm_window *window =
1495 container_of(listener,
1496 struct weston_wm_window, surface_destroy_listener);
1497
1498 wm_log("surface for xid %d destroyed\n", window->id);
1499
1500 /* This should have been freed by the shell.
1501 * Don't try to use it later. */
1502 window->shsurf = NULL;
1503 window->surface = NULL;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001504}
1505
1506static void
1507weston_wm_window_handle_surface_id(struct weston_wm_window *window,
1508 xcb_client_message_event_t *client_message)
1509{
1510 struct weston_wm *wm = window->wm;
1511 struct wl_resource *resource;
1512
1513 if (window->surface_id != 0) {
1514 wm_log("already have surface id for window %d\n", window->id);
1515 return;
1516 }
1517
1518 /* Xwayland will send the wayland requests to create the
1519 * wl_surface before sending this client message. Even so, we
1520 * can end up handling the X event before the wayland requests
1521 * and thus when we try to look up the surface ID, the surface
1522 * hasn't been created yet. In that case put the window on
1523 * the unpaired window list and continue when the surface gets
1524 * created. */
Jason Ekstrand4ff4d922014-07-24 13:16:58 -07001525 uint32_t id = client_message->data.data32[0];
1526 resource = wl_client_get_object(wm->server->client, id);
Tyler Venesscf4c13a2014-07-02 15:00:44 -07001527 if (resource) {
1528 window->surface_id = 0;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001529 xserver_map_shell_surface(window,
1530 wl_resource_get_user_data(resource));
Tyler Venesscf4c13a2014-07-02 15:00:44 -07001531 }
1532 else {
Jason Ekstrand4ff4d922014-07-24 13:16:58 -07001533 window->surface_id = id;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001534 wl_list_insert(&wm->unpaired_window_list, &window->link);
Tyler Venesscf4c13a2014-07-02 15:00:44 -07001535 }
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001536}
1537
1538static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001539weston_wm_handle_client_message(struct weston_wm *wm,
1540 xcb_generic_event_t *event)
1541{
1542 xcb_client_message_event_t *client_message =
1543 (xcb_client_message_event_t *) event;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001544 struct weston_wm_window *window;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001545
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001546 wm_log("XCB_CLIENT_MESSAGE (%s %d %d %d %d %d win %d)\n",
1547 get_atom_name(wm->conn, client_message->type),
1548 client_message->data.data32[0],
1549 client_message->data.data32[1],
1550 client_message->data.data32[2],
1551 client_message->data.data32[3],
1552 client_message->data.data32[4],
1553 client_message->window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001554
Jason Ekstrand0250a742014-07-24 13:17:47 -07001555 /* The window may get created and destroyed before we actually
1556 * handle the message. If it doesn't exist, bail.
1557 */
Derek Foreman49372142015-04-09 10:51:22 -05001558 if (!wm_lookup_window(wm, client_message->window, &window))
Jason Ekstrand0250a742014-07-24 13:17:47 -07001559 return;
1560
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001561 if (client_message->type == wm->atom.net_wm_moveresize)
1562 weston_wm_window_handle_moveresize(window, client_message);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001563 else if (client_message->type == wm->atom.net_wm_state)
1564 weston_wm_window_handle_state(window, client_message);
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001565 else if (client_message->type == wm->atom.wl_surface_id)
1566 weston_wm_window_handle_surface_id(window, client_message);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001567}
1568
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001569enum cursor_type {
1570 XWM_CURSOR_TOP,
1571 XWM_CURSOR_BOTTOM,
1572 XWM_CURSOR_LEFT,
1573 XWM_CURSOR_RIGHT,
1574 XWM_CURSOR_TOP_LEFT,
1575 XWM_CURSOR_TOP_RIGHT,
1576 XWM_CURSOR_BOTTOM_LEFT,
1577 XWM_CURSOR_BOTTOM_RIGHT,
1578 XWM_CURSOR_LEFT_PTR,
1579};
1580
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001581/*
1582 * The following correspondences between file names and cursors was copied
1583 * from: https://bugs.kde.org/attachment.cgi?id=67313
1584 */
1585
1586static const char *bottom_left_corners[] = {
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001587 "bottom_left_corner",
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001588 "sw-resize",
1589 "size_bdiag"
1590};
1591
1592static const char *bottom_right_corners[] = {
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001593 "bottom_right_corner",
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001594 "se-resize",
1595 "size_fdiag"
1596};
1597
1598static const char *bottom_sides[] = {
1599 "bottom_side",
1600 "s-resize",
1601 "size_ver"
1602};
1603
1604static const char *left_ptrs[] = {
1605 "left_ptr",
1606 "default",
1607 "top_left_arrow",
1608 "left-arrow"
1609};
1610
1611static const char *left_sides[] = {
1612 "left_side",
1613 "w-resize",
1614 "size_hor"
1615};
1616
1617static const char *right_sides[] = {
1618 "right_side",
1619 "e-resize",
1620 "size_hor"
1621};
1622
1623static const char *top_left_corners[] = {
1624 "top_left_corner",
1625 "nw-resize",
1626 "size_fdiag"
1627};
1628
1629static const char *top_right_corners[] = {
1630 "top_right_corner",
1631 "ne-resize",
1632 "size_bdiag"
1633};
1634
1635static const char *top_sides[] = {
1636 "top_side",
1637 "n-resize",
1638 "size_ver"
1639};
1640
1641struct cursor_alternatives {
1642 const char **names;
1643 size_t count;
1644};
1645
1646static const struct cursor_alternatives cursors[] = {
1647 {top_sides, ARRAY_LENGTH(top_sides)},
1648 {bottom_sides, ARRAY_LENGTH(bottom_sides)},
1649 {left_sides, ARRAY_LENGTH(left_sides)},
1650 {right_sides, ARRAY_LENGTH(right_sides)},
1651 {top_left_corners, ARRAY_LENGTH(top_left_corners)},
1652 {top_right_corners, ARRAY_LENGTH(top_right_corners)},
1653 {bottom_left_corners, ARRAY_LENGTH(bottom_left_corners)},
1654 {bottom_right_corners, ARRAY_LENGTH(bottom_right_corners)},
1655 {left_ptrs, ARRAY_LENGTH(left_ptrs)},
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001656};
1657
1658static void
1659weston_wm_create_cursors(struct weston_wm *wm)
1660{
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001661 const char *name;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001662 int i, count = ARRAY_LENGTH(cursors);
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001663 size_t j;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001664
1665 wm->cursors = malloc(count * sizeof(xcb_cursor_t));
1666 for (i = 0; i < count; i++) {
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001667 for (j = 0; j < cursors[i].count; j++) {
1668 name = cursors[i].names[j];
1669 wm->cursors[i] =
1670 xcb_cursor_library_load_cursor(wm, name);
1671 if (wm->cursors[i] != (xcb_cursor_t)-1)
1672 break;
1673 }
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001674 }
1675
1676 wm->last_cursor = -1;
1677}
1678
1679static void
1680weston_wm_destroy_cursors(struct weston_wm *wm)
1681{
1682 uint8_t i;
1683
1684 for (i = 0; i < ARRAY_LENGTH(cursors); i++)
1685 xcb_free_cursor(wm->conn, wm->cursors[i]);
1686
1687 free(wm->cursors);
1688}
1689
1690static int
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001691get_cursor_for_location(enum theme_location location)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001692{
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001693 switch (location) {
1694 case THEME_LOCATION_RESIZING_TOP:
1695 return XWM_CURSOR_TOP;
1696 case THEME_LOCATION_RESIZING_BOTTOM:
1697 return XWM_CURSOR_BOTTOM;
1698 case THEME_LOCATION_RESIZING_LEFT:
1699 return XWM_CURSOR_LEFT;
1700 case THEME_LOCATION_RESIZING_RIGHT:
1701 return XWM_CURSOR_RIGHT;
1702 case THEME_LOCATION_RESIZING_TOP_LEFT:
1703 return XWM_CURSOR_TOP_LEFT;
1704 case THEME_LOCATION_RESIZING_TOP_RIGHT:
1705 return XWM_CURSOR_TOP_RIGHT;
1706 case THEME_LOCATION_RESIZING_BOTTOM_LEFT:
1707 return XWM_CURSOR_BOTTOM_LEFT;
1708 case THEME_LOCATION_RESIZING_BOTTOM_RIGHT:
1709 return XWM_CURSOR_BOTTOM_RIGHT;
1710 case THEME_LOCATION_EXTERIOR:
1711 case THEME_LOCATION_TITLEBAR:
1712 default:
1713 return XWM_CURSOR_LEFT_PTR;
1714 }
1715}
1716
1717static void
Tiago Vignattic1903232012-07-16 12:15:37 -04001718weston_wm_window_set_cursor(struct weston_wm *wm, xcb_window_t window_id,
1719 int cursor)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001720{
1721 uint32_t cursor_value_list;
1722
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001723 if (wm->last_cursor == cursor)
1724 return;
1725
1726 wm->last_cursor = cursor;
1727
1728 cursor_value_list = wm->cursors[cursor];
Tiago Vignattic1903232012-07-16 12:15:37 -04001729 xcb_change_window_attributes (wm->conn, window_id,
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001730 XCB_CW_CURSOR, &cursor_value_list);
1731 xcb_flush(wm->conn);
1732}
1733
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001734static void
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -07001735weston_wm_window_close(struct weston_wm_window *window, xcb_timestamp_t time)
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001736{
1737 xcb_client_message_event_t client_message;
1738
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -07001739 if (window->delete_window) {
1740 client_message.response_type = XCB_CLIENT_MESSAGE;
1741 client_message.format = 32;
1742 client_message.window = window->id;
1743 client_message.type = window->wm->atom.wm_protocols;
1744 client_message.data.data32[0] =
1745 window->wm->atom.wm_delete_window;
1746 client_message.data.data32[1] = time;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001747
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -07001748 xcb_send_event(window->wm->conn, 0, window->id,
1749 XCB_EVENT_MASK_NO_EVENT,
1750 (char *) &client_message);
1751 } else {
1752 xcb_kill_client(window->wm->conn, window->id);
1753 }
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001754}
1755
1756static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001757weston_wm_handle_button(struct weston_wm *wm, xcb_generic_event_t *event)
1758{
1759 xcb_button_press_event_t *button = (xcb_button_press_event_t *) event;
Quentin Glidic955cec02016-08-12 10:41:35 +02001760 const struct weston_desktop_xwayland_interface *xwayland_interface =
1761 wm->server->compositor->xwayland_interface;
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001762 struct weston_seat *seat;
Derek Foremane4d6c832015-08-05 14:48:11 -05001763 struct weston_pointer *pointer;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001764 struct weston_wm_window *window;
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001765 enum theme_location location;
Quentin Glidicd8b17bc2016-07-10 11:00:55 +02001766 enum wl_pointer_button_state button_state;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001767 uint32_t button_id;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001768
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001769 wm_log("XCB_BUTTON_%s (detail %d)\n",
1770 button->response_type == XCB_BUTTON_PRESS ?
1771 "PRESS" : "RELEASE", button->detail);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001772
Derek Foreman49372142015-04-09 10:51:22 -05001773 if (!wm_lookup_window(wm, button->event, &window) ||
1774 !window->decorate)
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001775 return;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04001776
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001777 if (button->detail != 1 && button->detail != 2)
1778 return;
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001779
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001780 seat = weston_wm_pick_seat_for_window(window);
Derek Foremane4d6c832015-08-05 14:48:11 -05001781 pointer = weston_seat_get_pointer(seat);
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001782
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001783 button_state = button->response_type == XCB_BUTTON_PRESS ?
Quentin Glidicd8b17bc2016-07-10 11:00:55 +02001784 WL_POINTER_BUTTON_STATE_PRESSED :
1785 WL_POINTER_BUTTON_STATE_RELEASED;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001786 button_id = button->detail == 1 ? BTN_LEFT : BTN_RIGHT;
1787
Kristian Høgsberg8c3c7382014-04-30 16:52:30 -07001788 /* Make sure we're looking at the right location. The frame
1789 * could have received a motion event from a pointer from a
1790 * different wl_seat, but under X it looks like our core
1791 * pointer moved. Move the frame pointer to the button press
1792 * location before deciding what to do. */
1793 location = frame_pointer_motion(window->frame, NULL,
1794 button->event_x, button->event_y);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001795 location = frame_pointer_button(window->frame, NULL,
1796 button_id, button_state);
1797 if (frame_status(window->frame) & FRAME_STATUS_REPAINT)
1798 weston_wm_window_schedule_repaint(window);
1799
1800 if (frame_status(window->frame) & FRAME_STATUS_MOVE) {
Derek Foremane4d6c832015-08-05 14:48:11 -05001801 if (pointer)
Quentin Glidic955cec02016-08-12 10:41:35 +02001802 xwayland_interface->move(window->shsurf, pointer);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001803 frame_status_clear(window->frame, FRAME_STATUS_MOVE);
1804 }
1805
1806 if (frame_status(window->frame) & FRAME_STATUS_RESIZE) {
Derek Foremane4d6c832015-08-05 14:48:11 -05001807 if (pointer)
Quentin Glidic955cec02016-08-12 10:41:35 +02001808 xwayland_interface->resize(window->shsurf, pointer, location);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001809 frame_status_clear(window->frame, FRAME_STATUS_RESIZE);
1810 }
1811
1812 if (frame_status(window->frame) & FRAME_STATUS_CLOSE) {
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -07001813 weston_wm_window_close(window, button->time);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001814 frame_status_clear(window->frame, FRAME_STATUS_CLOSE);
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001815 }
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001816
1817 if (frame_status(window->frame) & FRAME_STATUS_MAXIMIZE) {
1818 window->maximized_horz = !window->maximized_horz;
1819 window->maximized_vert = !window->maximized_vert;
1820 if (weston_wm_window_is_maximized(window)) {
1821 window->saved_width = window->width;
1822 window->saved_height = window->height;
Quentin Glidic955cec02016-08-12 10:41:35 +02001823 xwayland_interface->set_maximized(window->shsurf);
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001824 } else {
1825 weston_wm_window_set_toplevel(window);
1826 }
1827 frame_status_clear(window->frame, FRAME_STATUS_MAXIMIZE);
1828 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001829}
1830
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001831static void
1832weston_wm_handle_motion(struct weston_wm *wm, xcb_generic_event_t *event)
1833{
1834 xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *) event;
1835 struct weston_wm_window *window;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001836 enum theme_location location;
1837 int cursor;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001838
Derek Foreman49372142015-04-09 10:51:22 -05001839 if (!wm_lookup_window(wm, motion->event, &window) ||
1840 !window->decorate)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001841 return;
1842
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001843 location = frame_pointer_motion(window->frame, NULL,
1844 motion->event_x, motion->event_y);
1845 if (frame_status(window->frame) & FRAME_STATUS_REPAINT)
1846 weston_wm_window_schedule_repaint(window);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001847
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001848 cursor = get_cursor_for_location(location);
Tiago Vignattic1903232012-07-16 12:15:37 -04001849 weston_wm_window_set_cursor(wm, window->frame_id, cursor);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001850}
1851
1852static void
1853weston_wm_handle_enter(struct weston_wm *wm, xcb_generic_event_t *event)
1854{
1855 xcb_enter_notify_event_t *enter = (xcb_enter_notify_event_t *) event;
1856 struct weston_wm_window *window;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001857 enum theme_location location;
1858 int cursor;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001859
Derek Foreman49372142015-04-09 10:51:22 -05001860 if (!wm_lookup_window(wm, enter->event, &window) ||
1861 !window->decorate)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001862 return;
1863
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001864 location = frame_pointer_enter(window->frame, NULL,
1865 enter->event_x, enter->event_y);
1866 if (frame_status(window->frame) & FRAME_STATUS_REPAINT)
1867 weston_wm_window_schedule_repaint(window);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001868
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001869 cursor = get_cursor_for_location(location);
Tiago Vignattic1903232012-07-16 12:15:37 -04001870 weston_wm_window_set_cursor(wm, window->frame_id, cursor);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001871}
1872
1873static void
1874weston_wm_handle_leave(struct weston_wm *wm, xcb_generic_event_t *event)
1875{
1876 xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *) event;
1877 struct weston_wm_window *window;
1878
Derek Foreman49372142015-04-09 10:51:22 -05001879 if (!wm_lookup_window(wm, leave->event, &window) ||
1880 !window->decorate)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001881 return;
1882
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001883 frame_pointer_leave(window->frame, NULL);
1884 if (frame_status(window->frame) & FRAME_STATUS_REPAINT)
1885 weston_wm_window_schedule_repaint(window);
1886
Tiago Vignattic1903232012-07-16 12:15:37 -04001887 weston_wm_window_set_cursor(wm, window->frame_id, XWM_CURSOR_LEFT_PTR);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001888}
1889
Giulio Camuffob18f7882015-03-29 14:20:23 +03001890static void
1891weston_wm_handle_focus_in(struct weston_wm *wm, xcb_generic_event_t *event)
1892{
1893 xcb_focus_in_event_t *focus = (xcb_focus_in_event_t *) event;
1894 /* Do not let X clients change the focus behind the compositor's
1895 * back. Reset the focus to the old one if it changed. */
1896 if (!wm->focus_window || focus->event != wm->focus_window->id)
1897 weston_wm_send_focus_window(wm, wm->focus_window);
1898}
1899
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001900static int
1901weston_wm_handle_event(int fd, uint32_t mask, void *data)
1902{
1903 struct weston_wm *wm = data;
1904 xcb_generic_event_t *event;
1905 int count = 0;
1906
1907 while (event = xcb_poll_for_event(wm->conn), event != NULL) {
1908 if (weston_wm_handle_selection_event(wm, event)) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001909 free(event);
1910 count++;
1911 continue;
1912 }
1913
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -07001914 if (weston_wm_handle_dnd_event(wm, event)) {
1915 free(event);
1916 count++;
1917 continue;
1918 }
1919
MoD31700122013-06-11 19:58:55 -05001920 switch (EVENT_TYPE(event)) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001921 case XCB_BUTTON_PRESS:
1922 case XCB_BUTTON_RELEASE:
1923 weston_wm_handle_button(wm, event);
1924 break;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001925 case XCB_ENTER_NOTIFY:
1926 weston_wm_handle_enter(wm, event);
1927 break;
1928 case XCB_LEAVE_NOTIFY:
1929 weston_wm_handle_leave(wm, event);
1930 break;
1931 case XCB_MOTION_NOTIFY:
1932 weston_wm_handle_motion(wm, event);
1933 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001934 case XCB_CREATE_NOTIFY:
1935 weston_wm_handle_create_notify(wm, event);
1936 break;
1937 case XCB_MAP_REQUEST:
1938 weston_wm_handle_map_request(wm, event);
1939 break;
1940 case XCB_MAP_NOTIFY:
1941 weston_wm_handle_map_notify(wm, event);
1942 break;
1943 case XCB_UNMAP_NOTIFY:
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001944 weston_wm_handle_unmap_notify(wm, event);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001945 break;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001946 case XCB_REPARENT_NOTIFY:
1947 weston_wm_handle_reparent_notify(wm, event);
1948 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001949 case XCB_CONFIGURE_REQUEST:
1950 weston_wm_handle_configure_request(wm, event);
1951 break;
1952 case XCB_CONFIGURE_NOTIFY:
1953 weston_wm_handle_configure_notify(wm, event);
1954 break;
1955 case XCB_DESTROY_NOTIFY:
1956 weston_wm_handle_destroy_notify(wm, event);
1957 break;
1958 case XCB_MAPPING_NOTIFY:
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001959 wm_log("XCB_MAPPING_NOTIFY\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001960 break;
1961 case XCB_PROPERTY_NOTIFY:
1962 weston_wm_handle_property_notify(wm, event);
1963 break;
1964 case XCB_CLIENT_MESSAGE:
1965 weston_wm_handle_client_message(wm, event);
1966 break;
Giulio Camuffob18f7882015-03-29 14:20:23 +03001967 case XCB_FOCUS_IN:
1968 weston_wm_handle_focus_in(wm, event);
1969 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001970 }
1971
1972 free(event);
1973 count++;
1974 }
1975
Marek Chalupaa1f3f3c2015-08-12 09:55:12 +02001976 if (count != 0)
1977 xcb_flush(wm->conn);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001978
1979 return count;
1980}
1981
1982static void
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02001983weston_wm_set_net_active_window(struct weston_wm *wm, xcb_window_t window) {
1984 xcb_change_property(wm->conn, XCB_PROP_MODE_REPLACE,
1985 wm->screen->root, wm->atom.net_active_window,
1986 wm->atom.window, 32, 1, &window);
1987}
1988
1989static void
Kristian Høgsbergf9187192013-05-02 13:43:24 -04001990weston_wm_get_visual_and_colormap(struct weston_wm *wm)
1991{
1992 xcb_depth_iterator_t d_iter;
1993 xcb_visualtype_iterator_t vt_iter;
1994 xcb_visualtype_t *visualtype;
1995
1996 d_iter = xcb_screen_allowed_depths_iterator(wm->screen);
1997 visualtype = NULL;
1998 while (d_iter.rem > 0) {
1999 if (d_iter.data->depth == 32) {
2000 vt_iter = xcb_depth_visuals_iterator(d_iter.data);
2001 visualtype = vt_iter.data;
2002 break;
2003 }
2004
2005 xcb_depth_next(&d_iter);
2006 }
2007
2008 if (visualtype == NULL) {
2009 weston_log("no 32 bit visualtype\n");
2010 return;
2011 }
2012
2013 wm->visual_id = visualtype->visual_id;
2014 wm->colormap = xcb_generate_id(wm->conn);
2015 xcb_create_colormap(wm->conn, XCB_COLORMAP_ALLOC_NONE,
2016 wm->colormap, wm->screen->root, wm->visual_id);
2017}
2018
2019static void
Tiago Vignatti9c4ff832012-11-30 17:19:57 -02002020weston_wm_get_resources(struct weston_wm *wm)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002021{
2022
2023#define F(field) offsetof(struct weston_wm, field)
2024
2025 static const struct { const char *name; int offset; } atoms[] = {
2026 { "WM_PROTOCOLS", F(atom.wm_protocols) },
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -07002027 { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002028 { "WM_TAKE_FOCUS", F(atom.wm_take_focus) },
2029 { "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -04002030 { "WM_STATE", F(atom.wm_state) },
Kristian Høgsberg670b5d32012-06-04 11:00:40 -04002031 { "WM_S0", F(atom.wm_s0) },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03002032 { "WM_CLIENT_MACHINE", F(atom.wm_client_machine) },
Kristian Høgsberg69981d92013-08-21 22:14:58 -07002033 { "_NET_WM_CM_S0", F(atom.net_wm_cm_s0) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002034 { "_NET_WM_NAME", F(atom.net_wm_name) },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03002035 { "_NET_WM_PID", F(atom.net_wm_pid) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002036 { "_NET_WM_ICON", F(atom.net_wm_icon) },
2037 { "_NET_WM_STATE", F(atom.net_wm_state) },
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02002038 { "_NET_WM_STATE_MAXIMIZED_VERT", F(atom.net_wm_state_maximized_vert) },
2039 { "_NET_WM_STATE_MAXIMIZED_HORZ", F(atom.net_wm_state_maximized_horz) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002040 { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
2041 { "_NET_WM_USER_TIME", F(atom.net_wm_user_time) },
2042 { "_NET_WM_ICON_NAME", F(atom.net_wm_icon_name) },
Giulio Camuffoe90ea442014-12-13 18:06:34 +02002043 { "_NET_WM_DESKTOP", F(atom.net_wm_desktop) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002044 { "_NET_WM_WINDOW_TYPE", F(atom.net_wm_window_type) },
2045
2046 { "_NET_WM_WINDOW_TYPE_DESKTOP", F(atom.net_wm_window_type_desktop) },
2047 { "_NET_WM_WINDOW_TYPE_DOCK", F(atom.net_wm_window_type_dock) },
2048 { "_NET_WM_WINDOW_TYPE_TOOLBAR", F(atom.net_wm_window_type_toolbar) },
2049 { "_NET_WM_WINDOW_TYPE_MENU", F(atom.net_wm_window_type_menu) },
2050 { "_NET_WM_WINDOW_TYPE_UTILITY", F(atom.net_wm_window_type_utility) },
2051 { "_NET_WM_WINDOW_TYPE_SPLASH", F(atom.net_wm_window_type_splash) },
2052 { "_NET_WM_WINDOW_TYPE_DIALOG", F(atom.net_wm_window_type_dialog) },
Tiago Vignattibf1e8662012-06-12 14:07:49 +03002053 { "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", F(atom.net_wm_window_type_dropdown) },
2054 { "_NET_WM_WINDOW_TYPE_POPUP_MENU", F(atom.net_wm_window_type_popup) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002055 { "_NET_WM_WINDOW_TYPE_TOOLTIP", F(atom.net_wm_window_type_tooltip) },
2056 { "_NET_WM_WINDOW_TYPE_NOTIFICATION", F(atom.net_wm_window_type_notification) },
2057 { "_NET_WM_WINDOW_TYPE_COMBO", F(atom.net_wm_window_type_combo) },
2058 { "_NET_WM_WINDOW_TYPE_DND", F(atom.net_wm_window_type_dnd) },
2059 { "_NET_WM_WINDOW_TYPE_NORMAL", F(atom.net_wm_window_type_normal) },
2060
2061 { "_NET_WM_MOVERESIZE", F(atom.net_wm_moveresize) },
2062 { "_NET_SUPPORTING_WM_CHECK",
2063 F(atom.net_supporting_wm_check) },
2064 { "_NET_SUPPORTED", F(atom.net_supported) },
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002065 { "_NET_ACTIVE_WINDOW", F(atom.net_active_window) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002066 { "_MOTIF_WM_HINTS", F(atom.motif_wm_hints) },
2067 { "CLIPBOARD", F(atom.clipboard) },
Kristian Høgsbergcba022a2012-06-04 10:11:45 -04002068 { "CLIPBOARD_MANAGER", F(atom.clipboard_manager) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002069 { "TARGETS", F(atom.targets) },
2070 { "UTF8_STRING", F(atom.utf8_string) },
2071 { "_WL_SELECTION", F(atom.wl_selection) },
2072 { "INCR", F(atom.incr) },
2073 { "TIMESTAMP", F(atom.timestamp) },
2074 { "MULTIPLE", F(atom.multiple) },
2075 { "UTF8_STRING" , F(atom.utf8_string) },
2076 { "COMPOUND_TEXT", F(atom.compound_text) },
2077 { "TEXT", F(atom.text) },
2078 { "STRING", F(atom.string) },
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002079 { "WINDOW", F(atom.window) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002080 { "text/plain;charset=utf-8", F(atom.text_plain_utf8) },
2081 { "text/plain", F(atom.text_plain) },
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -07002082 { "XdndSelection", F(atom.xdnd_selection) },
2083 { "XdndAware", F(atom.xdnd_aware) },
2084 { "XdndEnter", F(atom.xdnd_enter) },
2085 { "XdndLeave", F(atom.xdnd_leave) },
2086 { "XdndDrop", F(atom.xdnd_drop) },
2087 { "XdndStatus", F(atom.xdnd_status) },
2088 { "XdndFinished", F(atom.xdnd_finished) },
2089 { "XdndTypeList", F(atom.xdnd_type_list) },
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002090 { "XdndActionCopy", F(atom.xdnd_action_copy) },
2091 { "WL_SURFACE_ID", F(atom.wl_surface_id) }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002092 };
2093#undef F
2094
2095 xcb_xfixes_query_version_cookie_t xfixes_cookie;
2096 xcb_xfixes_query_version_reply_t *xfixes_reply;
2097 xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
2098 xcb_intern_atom_reply_t *reply;
2099 xcb_render_query_pict_formats_reply_t *formats_reply;
2100 xcb_render_query_pict_formats_cookie_t formats_cookie;
2101 xcb_render_pictforminfo_t *formats;
2102 uint32_t i;
2103
2104 xcb_prefetch_extension_data (wm->conn, &xcb_xfixes_id);
Kristian Høgsbergbcfd07b2013-10-11 16:48:19 -07002105 xcb_prefetch_extension_data (wm->conn, &xcb_composite_id);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002106
2107 formats_cookie = xcb_render_query_pict_formats(wm->conn);
2108
2109 for (i = 0; i < ARRAY_LENGTH(atoms); i++)
2110 cookies[i] = xcb_intern_atom (wm->conn, 0,
2111 strlen(atoms[i].name),
2112 atoms[i].name);
2113
2114 for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
2115 reply = xcb_intern_atom_reply (wm->conn, cookies[i], NULL);
2116 *(xcb_atom_t *) ((char *) wm + atoms[i].offset) = reply->atom;
2117 free(reply);
2118 }
2119
2120 wm->xfixes = xcb_get_extension_data(wm->conn, &xcb_xfixes_id);
2121 if (!wm->xfixes || !wm->xfixes->present)
Martin Minarik6d118362012-06-07 18:01:59 +02002122 weston_log("xfixes not available\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002123
2124 xfixes_cookie = xcb_xfixes_query_version(wm->conn,
2125 XCB_XFIXES_MAJOR_VERSION,
2126 XCB_XFIXES_MINOR_VERSION);
2127 xfixes_reply = xcb_xfixes_query_version_reply(wm->conn,
2128 xfixes_cookie, NULL);
2129
Martin Minarik6d118362012-06-07 18:01:59 +02002130 weston_log("xfixes version: %d.%d\n",
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002131 xfixes_reply->major_version, xfixes_reply->minor_version);
2132
2133 free(xfixes_reply);
2134
2135 formats_reply = xcb_render_query_pict_formats_reply(wm->conn,
2136 formats_cookie, 0);
2137 if (formats_reply == NULL)
2138 return;
2139
2140 formats = xcb_render_query_pict_formats_formats(formats_reply);
Kristian Høgsberge89cef32012-07-16 11:57:08 -04002141 for (i = 0; i < formats_reply->num_formats; i++) {
2142 if (formats[i].direct.red_mask != 0xff &&
2143 formats[i].direct.red_shift != 16)
2144 continue;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002145 if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT &&
2146 formats[i].depth == 24)
Kristian Høgsberge89cef32012-07-16 11:57:08 -04002147 wm->format_rgb = formats[i];
2148 if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT &&
2149 formats[i].depth == 32 &&
2150 formats[i].direct.alpha_mask == 0xff &&
2151 formats[i].direct.alpha_shift == 24)
2152 wm->format_rgba = formats[i];
2153 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002154
2155 free(formats_reply);
2156}
2157
2158static void
2159weston_wm_create_wm_window(struct weston_wm *wm)
2160{
2161 static const char name[] = "Weston WM";
2162
2163 wm->wm_window = xcb_generate_id(wm->conn);
2164 xcb_create_window(wm->conn,
2165 XCB_COPY_FROM_PARENT,
2166 wm->wm_window,
2167 wm->screen->root,
2168 0, 0,
2169 10, 10,
2170 0,
2171 XCB_WINDOW_CLASS_INPUT_OUTPUT,
2172 wm->screen->root_visual,
2173 0, NULL);
2174
2175 xcb_change_property(wm->conn,
2176 XCB_PROP_MODE_REPLACE,
2177 wm->wm_window,
2178 wm->atom.net_supporting_wm_check,
2179 XCB_ATOM_WINDOW,
2180 32, /* format */
2181 1, &wm->wm_window);
2182
2183 xcb_change_property(wm->conn,
2184 XCB_PROP_MODE_REPLACE,
2185 wm->wm_window,
2186 wm->atom.net_wm_name,
2187 wm->atom.utf8_string,
2188 8, /* format */
2189 strlen(name), name);
2190
2191 xcb_change_property(wm->conn,
2192 XCB_PROP_MODE_REPLACE,
2193 wm->screen->root,
2194 wm->atom.net_supporting_wm_check,
2195 XCB_ATOM_WINDOW,
2196 32, /* format */
2197 1, &wm->wm_window);
2198
Abdur Rehmanb8b150b2017-01-01 19:46:46 +05002199 /* Claim the WM_S0 selection even though we don't support
Kristian Høgsberg670b5d32012-06-04 11:00:40 -04002200 * the --replace functionality. */
2201 xcb_set_selection_owner(wm->conn,
2202 wm->wm_window,
2203 wm->atom.wm_s0,
2204 XCB_TIME_CURRENT_TIME);
Kristian Høgsberg69981d92013-08-21 22:14:58 -07002205
2206 xcb_set_selection_owner(wm->conn,
2207 wm->wm_window,
2208 wm->atom.net_wm_cm_s0,
2209 XCB_TIME_CURRENT_TIME);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002210}
2211
2212struct weston_wm *
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002213weston_wm_create(struct weston_xserver *wxs, int fd)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002214{
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002215 struct weston_wm *wm;
2216 struct wl_event_loop *loop;
2217 xcb_screen_iterator_t s;
Kristian Høgsberg4dec0112012-06-03 09:18:06 -04002218 uint32_t values[1];
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002219 xcb_atom_t supported[6];
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002220
Peter Huttererf3d62272013-08-08 11:57:05 +10002221 wm = zalloc(sizeof *wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002222 if (wm == NULL)
2223 return NULL;
2224
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002225 wm->server = wxs;
2226 wm->window_hash = hash_table_create();
2227 if (wm->window_hash == NULL) {
2228 free(wm);
2229 return NULL;
2230 }
2231
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002232 /* xcb_connect_to_fd takes ownership of the fd. */
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002233 wm->conn = xcb_connect_to_fd(fd, NULL);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002234 if (xcb_connection_has_error(wm->conn)) {
Martin Minarik6d118362012-06-07 18:01:59 +02002235 weston_log("xcb_connect_to_fd failed\n");
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002236 close(fd);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002237 hash_table_destroy(wm->window_hash);
2238 free(wm);
2239 return NULL;
2240 }
2241
2242 s = xcb_setup_roots_iterator(xcb_get_setup(wm->conn));
2243 wm->screen = s.data;
2244
2245 loop = wl_display_get_event_loop(wxs->wl_display);
2246 wm->source =
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002247 wl_event_loop_add_fd(loop, fd,
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002248 WL_EVENT_READABLE,
2249 weston_wm_handle_event, wm);
2250 wl_event_source_check(wm->source);
2251
Tiago Vignatti9c4ff832012-11-30 17:19:57 -02002252 weston_wm_get_resources(wm);
Kristian Høgsbergf9187192013-05-02 13:43:24 -04002253 weston_wm_get_visual_and_colormap(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002254
2255 values[0] =
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002256 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
2257 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
2258 XCB_EVENT_MASK_PROPERTY_CHANGE;
2259 xcb_change_window_attributes(wm->conn, wm->screen->root,
2260 XCB_CW_EVENT_MASK, values);
Kristian Høgsbergbcfd07b2013-10-11 16:48:19 -07002261
2262 xcb_composite_redirect_subwindows(wm->conn, wm->screen->root,
2263 XCB_COMPOSITE_REDIRECT_MANUAL);
2264
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002265 wm->theme = theme_create();
2266
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002267 supported[0] = wm->atom.net_wm_moveresize;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002268 supported[1] = wm->atom.net_wm_state;
2269 supported[2] = wm->atom.net_wm_state_fullscreen;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02002270 supported[3] = wm->atom.net_wm_state_maximized_vert;
2271 supported[4] = wm->atom.net_wm_state_maximized_horz;
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002272 supported[5] = wm->atom.net_active_window;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002273 xcb_change_property(wm->conn,
2274 XCB_PROP_MODE_REPLACE,
2275 wm->screen->root,
2276 wm->atom.net_supported,
2277 XCB_ATOM_ATOM,
2278 32, /* format */
2279 ARRAY_LENGTH(supported), supported);
2280
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002281 weston_wm_set_net_active_window(wm, XCB_WINDOW_NONE);
2282
Kristian Høgsberg4dec0112012-06-03 09:18:06 -04002283 weston_wm_selection_init(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002284
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -07002285 weston_wm_dnd_init(wm);
2286
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002287 xcb_flush(wm->conn);
2288
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002289 wm->create_surface_listener.notify = weston_wm_create_surface;
2290 wl_signal_add(&wxs->compositor->create_surface_signal,
2291 &wm->create_surface_listener);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002292 wm->activate_listener.notify = weston_wm_window_activate;
2293 wl_signal_add(&wxs->compositor->activate_signal,
2294 &wm->activate_listener);
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03002295 wm->kill_listener.notify = weston_wm_kill_client;
2296 wl_signal_add(&wxs->compositor->kill_signal,
2297 &wm->kill_listener);
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002298 wl_list_init(&wm->unpaired_window_list);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002299
Tiago Vignatti236b48d2012-07-16 12:09:19 -04002300 weston_wm_create_cursors(wm);
Tiago Vignattic1903232012-07-16 12:15:37 -04002301 weston_wm_window_set_cursor(wm, wm->screen->root, XWM_CURSOR_LEFT_PTR);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04002302
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002303 /* Create wm window and take WM_S0 selection last, which
2304 * signals to Xwayland that we're done with setup. */
2305 weston_wm_create_wm_window(wm);
2306
2307 weston_log("created wm, root %d\n", wm->screen->root);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002308
2309 return wm;
2310}
2311
2312void
2313weston_wm_destroy(struct weston_wm *wm)
2314{
2315 /* FIXME: Free windows in hash. */
2316 hash_table_destroy(wm->window_hash);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04002317 weston_wm_destroy_cursors(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002318 xcb_disconnect(wm->conn);
2319 wl_event_source_remove(wm->source);
2320 wl_list_remove(&wm->selection_listener.link);
2321 wl_list_remove(&wm->activate_listener.link);
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03002322 wl_list_remove(&wm->kill_listener.link);
Derek Foremanf10e06c2015-02-03 11:05:10 -06002323 wl_list_remove(&wm->create_surface_listener.link);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002324
2325 free(wm);
2326}
2327
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002328static struct weston_wm_window *
2329get_wm_window(struct weston_surface *surface)
2330{
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002331 struct wl_listener *listener;
2332
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05002333 listener = wl_signal_get(&surface->destroy_signal, surface_destroy);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002334 if (listener)
2335 return container_of(listener, struct weston_wm_window,
2336 surface_destroy_listener);
2337
2338 return NULL;
2339}
2340
Quentin Glidic955cec02016-08-12 10:41:35 +02002341static bool
2342is_wm_window(struct weston_surface *surface)
2343{
2344 return get_wm_window(surface) != NULL;
2345}
2346
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002347static void
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002348weston_wm_window_configure(void *data)
2349{
2350 struct weston_wm_window *window = data;
2351 struct weston_wm *wm = window->wm;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002352 uint32_t values[4];
2353 int x, y, width, height;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002354
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002355 weston_wm_window_get_child_position(window, &x, &y);
2356 values[0] = x;
2357 values[1] = y;
2358 values[2] = window->width;
2359 values[3] = window->height;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002360 xcb_configure_window(wm->conn,
2361 window->id,
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002362 XCB_CONFIG_WINDOW_X |
2363 XCB_CONFIG_WINDOW_Y |
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002364 XCB_CONFIG_WINDOW_WIDTH |
2365 XCB_CONFIG_WINDOW_HEIGHT,
2366 values);
2367
2368 weston_wm_window_get_frame_size(window, &width, &height);
2369 values[0] = width;
2370 values[1] = height;
2371 xcb_configure_window(wm->conn,
2372 window->frame_id,
2373 XCB_CONFIG_WINDOW_WIDTH |
2374 XCB_CONFIG_WINDOW_HEIGHT,
2375 values);
2376
2377 window->configure_source = NULL;
2378
2379 weston_wm_window_schedule_repaint(window);
2380}
2381
2382static void
Jasper St. Pierreac985be2014-04-28 11:19:28 -04002383send_configure(struct weston_surface *surface, int32_t width, int32_t height)
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002384{
2385 struct weston_wm_window *window = get_wm_window(surface);
2386 struct weston_wm *wm = window->wm;
2387 struct theme *t = window->wm->theme;
Kristian Høgsbergfa514b42013-07-08 15:00:25 -04002388 int vborder, hborder;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002389
Marek Chalupae9fe4672014-10-29 13:44:44 +01002390 if (window->decorate && !window->fullscreen) {
Jasper St. Pierre8ffd38b2014-08-27 09:38:33 -04002391 hborder = 2 * t->width;
2392 vborder = t->titlebar_height + t->width;
2393 } else {
Kristian Høgsbergfa514b42013-07-08 15:00:25 -04002394 hborder = 0;
2395 vborder = 0;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002396 }
2397
Kristian Høgsbergfa514b42013-07-08 15:00:25 -04002398 if (width > hborder)
2399 window->width = width - hborder;
2400 else
2401 window->width = 1;
2402
2403 if (height > vborder)
2404 window->height = height - vborder;
2405 else
2406 window->height = 1;
2407
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05002408 if (window->frame)
2409 frame_resize_inside(window->frame, window->width, window->height);
2410
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002411 if (window->configure_source)
2412 return;
2413
2414 window->configure_source =
2415 wl_event_loop_add_idle(wm->server->loop,
2416 weston_wm_window_configure, window);
2417}
2418
Giulio Camuffof05d18f2015-12-11 20:57:05 +02002419static void
2420send_position(struct weston_surface *surface, int32_t x, int32_t y)
2421{
2422 struct weston_wm_window *window = get_wm_window(surface);
2423 struct weston_wm *wm;
2424 uint32_t mask, values[2];
2425
2426 if (!window || !window->wm)
2427 return;
2428
2429 wm = window->wm;
2430 /* We use pos_dirty to tell whether a configure message is in flight.
2431 * This is needed in case we send two configure events in a very
2432 * short time, since window->x/y is set in after a roundtrip, hence
2433 * we cannot just check if the current x and y are different. */
2434 if (window->x != x || window->y != y || window->pos_dirty) {
2435 window->pos_dirty = true;
2436 values[0] = x;
2437 values[1] = y;
2438 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y;
2439
2440 xcb_configure_window(wm->conn, window->frame_id, mask, values);
2441 xcb_flush(wm->conn);
2442 }
2443}
2444
Quentin Glidic955cec02016-08-12 10:41:35 +02002445static const struct weston_xwayland_client_interface shell_client = {
Giulio Camuffof05d18f2015-12-11 20:57:05 +02002446 send_configure,
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002447};
2448
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002449static int
2450legacy_fullscreen(struct weston_wm *wm,
2451 struct weston_wm_window *window,
2452 struct weston_output **output_ret)
2453{
2454 struct weston_compositor *compositor = wm->server->compositor;
2455 struct weston_output *output;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -07002456 uint32_t minmax = PMinSize | PMaxSize;
2457 int matching_size;
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002458
2459 /* Heuristics for detecting legacy fullscreen windows... */
2460
2461 wl_list_for_each(output, &compositor->output_list, link) {
2462 if (output->x == window->x &&
2463 output->y == window->y &&
2464 output->width == window->width &&
2465 output->height == window->height &&
2466 window->override_redirect) {
2467 *output_ret = output;
2468 return 1;
2469 }
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -07002470
2471 matching_size = 0;
2472 if ((window->size_hints.flags & (USSize |PSize)) &&
2473 window->size_hints.width == output->width &&
2474 window->size_hints.height == output->height)
2475 matching_size = 1;
2476 if ((window->size_hints.flags & minmax) == minmax &&
2477 window->size_hints.min_width == output->width &&
2478 window->size_hints.min_height == output->height &&
2479 window->size_hints.max_width == output->width &&
2480 window->size_hints.max_height == output->height)
2481 matching_size = 1;
2482
2483 if (matching_size && !window->decorate &&
2484 (window->size_hints.flags & (USPosition | PPosition)) &&
2485 window->size_hints.x == output->x &&
2486 window->size_hints.y == output->y) {
2487 *output_ret = output;
2488 return 1;
2489 }
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002490 }
2491
2492 return 0;
2493}
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002494
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002495static bool
2496weston_wm_window_type_inactive(struct weston_wm_window *window)
2497{
2498 struct weston_wm *wm = window->wm;
2499
2500 return window->type == wm->atom.net_wm_window_type_tooltip ||
2501 window->type == wm->atom.net_wm_window_type_dropdown ||
2502 window->type == wm->atom.net_wm_window_type_dnd ||
2503 window->type == wm->atom.net_wm_window_type_combo ||
Giulio Camuffo84787ea2015-04-29 19:00:48 +03002504 window->type == wm->atom.net_wm_window_type_popup ||
2505 window->type == wm->atom.net_wm_window_type_utility;
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002506}
2507
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002508static void
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002509xserver_map_shell_surface(struct weston_wm_window *window,
2510 struct weston_surface *surface)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002511{
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002512 struct weston_wm *wm = window->wm;
Quentin Glidic955cec02016-08-12 10:41:35 +02002513 struct weston_desktop_xwayland *xwayland =
2514 wm->server->compositor->xwayland;
2515 const struct weston_desktop_xwayland_interface *xwayland_interface =
2516 wm->server->compositor->xwayland_interface;
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002517 struct weston_output *output;
Kristian Høgsberg9f7e3312014-01-02 22:40:37 -08002518 struct weston_wm_window *parent;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002519
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002520 weston_wm_window_read_properties(window);
2521
2522 /* A weston_wm_window may have many different surfaces assigned
2523 * throughout its life, so we must make sure to remove the listener
2524 * from the old surface signal list. */
2525 if (window->surface)
2526 wl_list_remove(&window->surface_destroy_listener.link);
2527
2528 window->surface = surface;
2529 window->surface_destroy_listener.notify = surface_destroy;
2530 wl_signal_add(&window->surface->destroy_signal,
2531 &window->surface_destroy_listener);
2532
2533 weston_wm_window_schedule_repaint(window);
2534
Quentin Glidic955cec02016-08-12 10:41:35 +02002535 if (!xwayland_interface)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002536 return;
2537
Quentin Glidic2edc3d52016-08-12 10:41:33 +02002538 if (window->surface->committed) {
Pekka Paalanen50b67472014-10-01 15:02:41 +03002539 weston_log("warning, unexpected in %s: "
2540 "surface's configure hook is already set.\n",
2541 __func__);
2542 return;
2543 }
2544
Murray Calavera883ac022015-06-06 13:02:22 +00002545 window->shsurf =
Quentin Glidic955cec02016-08-12 10:41:35 +02002546 xwayland_interface->create_surface(xwayland,
2547 window->surface,
2548 &shell_client);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002549
Giulio Camuffo62942ad2013-09-11 18:20:47 +02002550 if (window->name)
Quentin Glidic955cec02016-08-12 10:41:35 +02002551 xwayland_interface->set_title(window->shsurf, window->name);
Giulio Camuffoa8e9b412015-01-27 19:10:37 +02002552 if (window->pid > 0)
Quentin Glidic955cec02016-08-12 10:41:35 +02002553 xwayland_interface->set_pid(window->shsurf, window->pid);
Giulio Camuffo62942ad2013-09-11 18:20:47 +02002554
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002555 if (window->fullscreen) {
2556 window->saved_width = window->width;
2557 window->saved_height = window->height;
Quentin Glidic955cec02016-08-12 10:41:35 +02002558 xwayland_interface->set_fullscreen(window->shsurf, NULL);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002559 return;
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002560 } else if (legacy_fullscreen(wm, window, &output)) {
2561 window->fullscreen = 1;
Quentin Glidic955cec02016-08-12 10:41:35 +02002562 xwayland_interface->set_fullscreen(window->shsurf, output);
Kristian Høgsberg9f7e3312014-01-02 22:40:37 -08002563 } else if (window->override_redirect) {
Quentin Glidic955cec02016-08-12 10:41:35 +02002564 xwayland_interface->set_xwayland(window->shsurf,
2565 window->x, window->y);
Axel Davye4450f92014-01-12 15:06:05 +01002566 } else if (window->transient_for && window->transient_for->surface) {
Kristian Høgsberg9f7e3312014-01-02 22:40:37 -08002567 parent = window->transient_for;
Quentin Glidic955cec02016-08-12 10:41:35 +02002568 if (weston_wm_window_type_inactive(window)) {
2569 xwayland_interface->set_transient(window->shsurf,
2570 parent->surface,
2571 window->x - parent->x,
2572 window->y - parent->y);
2573 } else {
2574 xwayland_interface->set_toplevel(window->shsurf);
2575 xwayland_interface->set_parent(window->shsurf,
2576 parent->surface);
2577 }
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02002578 } else if (weston_wm_window_is_maximized(window)) {
Quentin Glidic955cec02016-08-12 10:41:35 +02002579 xwayland_interface->set_maximized(window->shsurf);
Kristian Høgsberg9f7e3312014-01-02 22:40:37 -08002580 } else {
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002581 if (weston_wm_window_type_inactive(window)) {
Quentin Glidic955cec02016-08-12 10:41:35 +02002582 xwayland_interface->set_xwayland(window->shsurf,
2583 window->x,
2584 window->y);
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002585 } else {
Quentin Glidic955cec02016-08-12 10:41:35 +02002586 xwayland_interface->set_toplevel(window->shsurf);
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002587 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002588 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002589}
Quentin Glidic955cec02016-08-12 10:41:35 +02002590
2591const struct weston_xwayland_surface_api surface_api = {
2592 is_wm_window,
2593 send_position,
2594};