blob: e69749af582018cfd7d93bf034ace517b3ce0beb [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
Pekka Paalanena04eacc2016-11-28 16:42:25 +02001053 wm_log("XWM: start draw decoration, win %d\n", window->id);
1054
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001055 weston_wm_window_read_properties(window);
1056
1057 window->repaint_source = NULL;
1058
1059 weston_wm_window_get_frame_size(window, &width, &height);
1060 weston_wm_window_get_child_position(window, &x, &y);
1061
1062 cairo_xcb_surface_set_size(window->cairo_surface, width, height);
1063 cr = cairo_create(window->cairo_surface);
1064
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001065 if (window->fullscreen) {
1066 /* nothing */
1067 } else if (window->decorate) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001068 if (wm->focus_window == window)
1069 flags |= THEME_FRAME_ACTIVE;
1070
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001071 frame_repaint(window->frame, cr);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001072 } else {
1073 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1074 cairo_set_source_rgba(cr, 0, 0, 0, 0);
1075 cairo_paint(cr);
1076
Marek Chalupa0d7fe8d2014-10-29 14:51:22 +01001077 render_shadow(cr, t->shadow, 2, 2, width + 8, height + 8, 64, 64);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001078 }
1079
1080 cairo_destroy(cr);
1081
1082 if (window->surface) {
Scott Moreau76d8fc82012-11-22 15:35:13 -07001083 pixman_region32_fini(&window->surface->pending.opaque);
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001084 if (window->has_alpha) {
MoD384a11a2013-06-22 11:04:21 -05001085 pixman_region32_init(&window->surface->pending.opaque);
1086 } else {
1087 /* We leave an extra pixel around the X window area to
1088 * make sure we don't sample from the undefined alpha
1089 * channel when filtering. */
Murray Calavera883ac022015-06-06 13:02:22 +00001090 pixman_region32_init_rect(&window->surface->pending.opaque,
MoD384a11a2013-06-22 11:04:21 -05001091 x - 1, y - 1,
1092 window->width + 2,
1093 window->height + 2);
1094 }
Giulio Camuffoaa974782015-02-01 16:18:51 +02001095 wl_list_for_each(view, &window->surface->views, surface_link)
1096 weston_view_geometry_dirty(view);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001097
Kristian Høgsberg81585e92013-02-14 22:01:58 -05001098 pixman_region32_fini(&window->surface->pending.input);
Kristian Høgsberg1d75c7d2013-10-30 23:46:08 -07001099
Jasper St. Pierred19e9b02015-03-21 21:24:43 -07001100 if (window->decorate && !window->fullscreen) {
Kristian Høgsberg1d75c7d2013-10-30 23:46:08 -07001101 frame_input_rect(window->frame, &input_x, &input_y,
1102 &input_w, &input_h);
Jasper St. Pierred19e9b02015-03-21 21:24:43 -07001103 } else {
1104 input_x = x;
1105 input_y = y;
1106 input_w = width;
1107 input_h = height;
Kristian Høgsberg1d75c7d2013-10-30 23:46:08 -07001108 }
1109
Kristian Høgsbergd8b617d2013-02-14 21:56:32 -05001110 pixman_region32_init_rect(&window->surface->pending.input,
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001111 input_x, input_y, input_w, input_h);
Jasper St. Pierreccf48fb2014-05-02 10:21:38 -04001112
Pekka Paalanena04eacc2016-11-28 16:42:25 +02001113 wm_log("XWM: draw decoration, win %d geometry: %d,%d %dx%d\n",
1114 window->id, input_x, input_y, input_w, input_h);
1115
Quentin Glidic955cec02016-08-12 10:41:35 +02001116 xwayland_interface->set_window_geometry(window->shsurf,
1117 input_x, input_y, input_w, input_h);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001118 }
1119}
1120
1121static void
1122weston_wm_window_schedule_repaint(struct weston_wm_window *window)
1123{
1124 struct weston_wm *wm = window->wm;
Giulio Camuffoaa974782015-02-01 16:18:51 +02001125 struct weston_view *view;
Pekka Paalanen4f9c07b2012-09-03 16:48:41 +03001126 int width, height;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001127
Kristian Høgsbergc4063f32012-07-22 15:32:45 -04001128 if (window->frame_id == XCB_WINDOW_NONE) {
1129 if (window->surface != NULL) {
Pekka Paalanen4f9c07b2012-09-03 16:48:41 +03001130 weston_wm_window_get_frame_size(window, &width, &height);
Scott Moreau76d8fc82012-11-22 15:35:13 -07001131 pixman_region32_fini(&window->surface->pending.opaque);
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001132 if (window->has_alpha) {
MoD384a11a2013-06-22 11:04:21 -05001133 pixman_region32_init(&window->surface->pending.opaque);
1134 } else {
1135 pixman_region32_init_rect(&window->surface->pending.opaque, 0, 0,
1136 width, height);
1137 }
Giulio Camuffoaa974782015-02-01 16:18:51 +02001138 wl_list_for_each(view, &window->surface->views, surface_link)
1139 weston_view_geometry_dirty(view);
Kristian Høgsbergc4063f32012-07-22 15:32:45 -04001140 }
1141 return;
1142 }
1143
1144 if (window->repaint_source)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001145 return;
1146
Pekka Paalanena04eacc2016-11-28 16:42:25 +02001147 wm_log("XWM: schedule repaint, win %d\n", window->id);
1148
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001149 window->repaint_source =
1150 wl_event_loop_add_idle(wm->server->loop,
1151 weston_wm_window_draw_decoration,
1152 window);
1153}
1154
1155static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001156weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1157{
1158 xcb_property_notify_event_t *property_notify =
1159 (xcb_property_notify_event_t *) event;
1160 struct weston_wm_window *window;
1161
Derek Foreman49372142015-04-09 10:51:22 -05001162 if (!wm_lookup_window(wm, property_notify->window, &window))
Rob Bradfordaa521bd2013-01-10 19:48:57 +00001163 return;
1164
1165 window->properties_dirty = 1;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001166
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001167 wm_log("XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
Kristian Høgsberge244cb02012-05-30 11:34:35 -04001168 if (property_notify->state == XCB_PROPERTY_DELETE)
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001169 wm_log("deleted\n");
Kristian Høgsberge244cb02012-05-30 11:34:35 -04001170 else
1171 read_and_dump_property(wm, property_notify->window,
1172 property_notify->atom);
Kristian Høgsberg0273b572012-05-30 09:58:02 -04001173
1174 if (property_notify->atom == wm->atom.net_wm_name ||
1175 property_notify->atom == XCB_ATOM_WM_NAME)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001176 weston_wm_window_schedule_repaint(window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001177}
1178
1179static void
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001180weston_wm_window_create(struct weston_wm *wm,
Giulio Camuffoca43f092013-09-11 17:49:13 +02001181 xcb_window_t id, int width, int height, int x, int y, int override)
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001182{
1183 struct weston_wm_window *window;
1184 uint32_t values[1];
MoD384a11a2013-06-22 11:04:21 -05001185 xcb_get_geometry_cookie_t geometry_cookie;
1186 xcb_get_geometry_reply_t *geometry_reply;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001187
Peter Huttererf3d62272013-08-08 11:57:05 +10001188 window = zalloc(sizeof *window);
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001189 if (window == NULL) {
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001190 wm_log("failed to allocate window\n");
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001191 return;
1192 }
1193
MoD384a11a2013-06-22 11:04:21 -05001194 geometry_cookie = xcb_get_geometry(wm->conn, id);
1195
Giulio Camuffob18f7882015-03-29 14:20:23 +03001196 values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE |
1197 XCB_EVENT_MASK_FOCUS_CHANGE;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001198 xcb_change_window_attributes(wm->conn, id, XCB_CW_EVENT_MASK, values);
1199
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001200 window->wm = wm;
1201 window->id = id;
1202 window->properties_dirty = 1;
Tiago Vignatti771241e2012-06-04 20:01:45 +03001203 window->override_redirect = override;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001204 window->width = width;
1205 window->height = height;
Giulio Camuffoca43f092013-09-11 17:49:13 +02001206 window->x = x;
1207 window->y = y;
Giulio Camuffof05d18f2015-12-11 20:57:05 +02001208 window->pos_dirty = false;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001209
MoD384a11a2013-06-22 11:04:21 -05001210 geometry_reply = xcb_get_geometry_reply(wm->conn, geometry_cookie, NULL);
1211 /* technically we should use XRender and check the visual format's
1212 alpha_mask, but checking depth is simpler and works in all known cases */
Dawid Gajownik74a635b2015-08-06 17:12:19 -03001213 if (geometry_reply != NULL)
MoD384a11a2013-06-22 11:04:21 -05001214 window->has_alpha = geometry_reply->depth == 32;
1215 free(geometry_reply);
1216
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001217 hash_table_insert(wm->window_hash, id, window);
1218}
1219
1220static void
1221weston_wm_window_destroy(struct weston_wm_window *window)
1222{
Kristian Høgsbergab6d6672013-09-03 16:38:51 -07001223 struct weston_wm *wm = window->wm;
1224
1225 if (window->repaint_source)
1226 wl_event_source_remove(window->repaint_source);
1227 if (window->cairo_surface)
1228 cairo_surface_destroy(window->cairo_surface);
1229
1230 if (window->frame_id) {
1231 xcb_reparent_window(wm->conn, window->id, wm->wm_window, 0, 0);
1232 xcb_destroy_window(wm->conn, window->frame_id);
1233 weston_wm_window_set_wm_state(window, ICCCM_WITHDRAWN_STATE);
Giulio Camuffoe90ea442014-12-13 18:06:34 +02001234 weston_wm_window_set_virtual_desktop(window, -1);
Kristian Høgsbergab6d6672013-09-03 16:38:51 -07001235 hash_table_remove(wm->window_hash, window->frame_id);
1236 window->frame_id = XCB_WINDOW_NONE;
1237 }
1238
Kristian Høgsbergba83db22014-04-07 10:16:19 -07001239 if (window->surface_id)
1240 wl_list_remove(&window->link);
1241
Derek Foreman9a0b2b52015-04-09 14:48:22 -05001242 if (window->surface)
1243 wl_list_remove(&window->surface_destroy_listener.link);
1244
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001245 hash_table_remove(window->wm->window_hash, window->id);
1246 free(window);
1247}
1248
1249static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001250weston_wm_handle_create_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1251{
1252 xcb_create_notify_event_t *create_notify =
1253 (xcb_create_notify_event_t *) event;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001254
Pekka Paalanen7db6c432016-11-14 14:30:57 +02001255 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 -04001256 create_notify->window,
Pekka Paalanen7db6c432016-11-14 14:30:57 +02001257 create_notify->x, create_notify->y,
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001258 create_notify->width, create_notify->height,
1259 create_notify->override_redirect ? ", override" : "",
1260 our_resource(wm, create_notify->window) ? ", ours" : "");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001261
1262 if (our_resource(wm, create_notify->window))
1263 return;
1264
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001265 weston_wm_window_create(wm, create_notify->window,
Tiago Vignatti771241e2012-06-04 20:01:45 +03001266 create_notify->width, create_notify->height,
Giulio Camuffoca43f092013-09-11 17:49:13 +02001267 create_notify->x, create_notify->y,
Tiago Vignatti771241e2012-06-04 20:01:45 +03001268 create_notify->override_redirect);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001269}
1270
1271static void
1272weston_wm_handle_destroy_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1273{
1274 xcb_destroy_notify_event_t *destroy_notify =
1275 (xcb_destroy_notify_event_t *) event;
1276 struct weston_wm_window *window;
1277
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001278 wm_log("XCB_DESTROY_NOTIFY, win %d, event %d%s\n",
1279 destroy_notify->window,
1280 destroy_notify->event,
1281 our_resource(wm, destroy_notify->window) ? ", ours" : "");
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001282
1283 if (our_resource(wm, destroy_notify->window))
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001284 return;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001285
Derek Foreman49372142015-04-09 10:51:22 -05001286 if (!wm_lookup_window(wm, destroy_notify->window, &window))
1287 return;
1288
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001289 weston_wm_window_destroy(window);
1290}
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001291
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001292static void
1293weston_wm_handle_reparent_notify(struct weston_wm *wm, xcb_generic_event_t *event)
1294{
1295 xcb_reparent_notify_event_t *reparent_notify =
1296 (xcb_reparent_notify_event_t *) event;
1297 struct weston_wm_window *window;
Kristian Høgsbergc9571fb2012-05-29 15:35:29 -04001298
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001299 wm_log("XCB_REPARENT_NOTIFY (window %d, parent %d, event %d)\n",
1300 reparent_notify->window,
1301 reparent_notify->parent,
1302 reparent_notify->event);
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001303
1304 if (reparent_notify->parent == wm->screen->root) {
Tiago Vignatti771241e2012-06-04 20:01:45 +03001305 weston_wm_window_create(wm, reparent_notify->window, 10, 10,
Giulio Camuffoca43f092013-09-11 17:49:13 +02001306 reparent_notify->x, reparent_notify->y,
Tiago Vignatti771241e2012-06-04 20:01:45 +03001307 reparent_notify->override_redirect);
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001308 } else if (!our_resource(wm, reparent_notify->parent)) {
Derek Foreman49372142015-04-09 10:51:22 -05001309 if (!wm_lookup_window(wm, reparent_notify->window, &window))
1310 return;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001311 weston_wm_window_destroy(window);
1312 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001313}
1314
Kristian Høgsberg5ba31892012-08-10 10:06:59 -04001315struct weston_seat *
1316weston_wm_pick_seat(struct weston_wm *wm)
1317{
Tom Hochsteine7fff212016-11-01 14:14:00 -05001318 struct wl_list *seats = wm->server->compositor->seat_list.next;
1319 if (wl_list_empty(seats))
1320 return NULL;
1321 return container_of(seats, struct weston_seat, link);
Kristian Høgsberg5ba31892012-08-10 10:06:59 -04001322}
1323
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001324static struct weston_seat *
1325weston_wm_pick_seat_for_window(struct weston_wm_window *window)
1326{
1327 struct weston_wm *wm = window->wm;
1328 struct weston_seat *seat, *s;
1329
1330 seat = NULL;
1331 wl_list_for_each(s, &wm->server->compositor->seat_list, link) {
Derek Foreman1281a362015-07-31 16:55:32 -05001332 struct weston_pointer *pointer = weston_seat_get_pointer(s);
1333 struct weston_pointer *old_pointer =
1334 weston_seat_get_pointer(seat);
1335
1336 if (pointer && pointer->focus &&
1337 pointer->focus->surface == window->surface &&
1338 pointer->button_count > 0 &&
1339 (!seat ||
1340 pointer->grab_serial -
1341 old_pointer->grab_serial < (1 << 30)))
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001342 seat = s;
1343 }
1344
1345 return seat;
1346}
1347
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001348static void
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001349weston_wm_window_handle_moveresize(struct weston_wm_window *window,
1350 xcb_client_message_event_t *client_message)
1351{
1352 static const int map[] = {
1353 THEME_LOCATION_RESIZING_TOP_LEFT,
1354 THEME_LOCATION_RESIZING_TOP,
1355 THEME_LOCATION_RESIZING_TOP_RIGHT,
1356 THEME_LOCATION_RESIZING_RIGHT,
1357 THEME_LOCATION_RESIZING_BOTTOM_RIGHT,
1358 THEME_LOCATION_RESIZING_BOTTOM,
1359 THEME_LOCATION_RESIZING_BOTTOM_LEFT,
1360 THEME_LOCATION_RESIZING_LEFT
1361 };
1362
1363 struct weston_wm *wm = window->wm;
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001364 struct weston_seat *seat = weston_wm_pick_seat_for_window(window);
Derek Foreman1281a362015-07-31 16:55:32 -05001365 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001366 int detail;
Quentin Glidic955cec02016-08-12 10:41:35 +02001367 const struct weston_desktop_xwayland_interface *xwayland_interface =
1368 wm->server->compositor->xwayland_interface;
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001369
Derek Foreman1281a362015-07-31 16:55:32 -05001370 if (!pointer || pointer->button_count != 1
1371 || !pointer->focus
1372 || pointer->focus->surface != window->surface)
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001373 return;
1374
1375 detail = client_message->data.data32[2];
1376 switch (detail) {
1377 case _NET_WM_MOVERESIZE_MOVE:
Quentin Glidic955cec02016-08-12 10:41:35 +02001378 xwayland_interface->move(window->shsurf, pointer);
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001379 break;
1380 case _NET_WM_MOVERESIZE_SIZE_TOPLEFT:
1381 case _NET_WM_MOVERESIZE_SIZE_TOP:
1382 case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT:
1383 case _NET_WM_MOVERESIZE_SIZE_RIGHT:
1384 case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT:
1385 case _NET_WM_MOVERESIZE_SIZE_BOTTOM:
1386 case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT:
1387 case _NET_WM_MOVERESIZE_SIZE_LEFT:
Quentin Glidic955cec02016-08-12 10:41:35 +02001388 xwayland_interface->resize(window->shsurf, pointer, map[detail]);
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001389 break;
1390 case _NET_WM_MOVERESIZE_CANCEL:
1391 break;
1392 }
1393}
1394
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001395#define _NET_WM_STATE_REMOVE 0
1396#define _NET_WM_STATE_ADD 1
1397#define _NET_WM_STATE_TOGGLE 2
1398
1399static int
1400update_state(int action, int *state)
1401{
1402 int new_state, changed;
1403
1404 switch (action) {
1405 case _NET_WM_STATE_REMOVE:
1406 new_state = 0;
1407 break;
1408 case _NET_WM_STATE_ADD:
1409 new_state = 1;
1410 break;
1411 case _NET_WM_STATE_TOGGLE:
1412 new_state = !*state;
1413 break;
1414 default:
1415 return 0;
1416 }
1417
1418 changed = (*state != new_state);
1419 *state = new_state;
1420
1421 return changed;
1422}
1423
1424static void
1425weston_wm_window_configure(void *data);
1426
1427static void
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001428weston_wm_window_set_toplevel(struct weston_wm_window *window)
1429{
Quentin Glidic955cec02016-08-12 10:41:35 +02001430 const struct weston_desktop_xwayland_interface *xwayland_interface =
1431 window->wm->server->compositor->xwayland_interface;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001432
Quentin Glidic955cec02016-08-12 10:41:35 +02001433 xwayland_interface->set_toplevel(window->shsurf);
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001434 window->width = window->saved_width;
1435 window->height = window->saved_height;
1436 if (window->frame)
1437 frame_resize_inside(window->frame,
1438 window->width,
1439 window->height);
1440 weston_wm_window_configure(window);
1441}
1442
1443static inline bool
1444weston_wm_window_is_maximized(struct weston_wm_window *window)
1445{
1446 return window->maximized_horz && window->maximized_vert;
1447}
1448
1449static void
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001450weston_wm_window_handle_state(struct weston_wm_window *window,
1451 xcb_client_message_event_t *client_message)
1452{
1453 struct weston_wm *wm = window->wm;
Quentin Glidic955cec02016-08-12 10:41:35 +02001454 const struct weston_desktop_xwayland_interface *xwayland_interface =
1455 wm->server->compositor->xwayland_interface;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001456 uint32_t action, property;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001457 int maximized = weston_wm_window_is_maximized(window);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001458
1459 action = client_message->data.data32[0];
1460 property = client_message->data.data32[1];
1461
1462 if (property == wm->atom.net_wm_state_fullscreen &&
1463 update_state(action, &window->fullscreen)) {
1464 weston_wm_window_set_net_wm_state(window);
1465 if (window->fullscreen) {
1466 window->saved_width = window->width;
1467 window->saved_height = window->height;
Kristian Høgsberg762b1662013-02-21 20:18:37 -05001468
1469 if (window->shsurf)
Quentin Glidic955cec02016-08-12 10:41:35 +02001470 xwayland_interface->set_fullscreen(window->shsurf,
1471 NULL);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001472 } else {
Andrew Engelbrecht4c5a6f72014-12-02 12:18:44 -05001473 if (window->shsurf)
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001474 weston_wm_window_set_toplevel(window);
1475 }
1476 } else {
1477 if (property == wm->atom.net_wm_state_maximized_vert &&
1478 update_state(action, &window->maximized_vert))
1479 weston_wm_window_set_net_wm_state(window);
1480 if (property == wm->atom.net_wm_state_maximized_horz &&
1481 update_state(action, &window->maximized_horz))
1482 weston_wm_window_set_net_wm_state(window);
Andrew Engelbrecht4c5a6f72014-12-02 12:18:44 -05001483
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001484 if (maximized != weston_wm_window_is_maximized(window)) {
1485 if (weston_wm_window_is_maximized(window)) {
1486 window->saved_width = window->width;
1487 window->saved_height = window->height;
1488
1489 if (window->shsurf)
Quentin Glidic955cec02016-08-12 10:41:35 +02001490 xwayland_interface->set_maximized(window->shsurf);
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001491 } else if (window->shsurf) {
1492 weston_wm_window_set_toplevel(window);
1493 }
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001494 }
1495 }
1496}
1497
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001498static void
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001499surface_destroy(struct wl_listener *listener, void *data)
1500{
1501 struct weston_wm_window *window =
1502 container_of(listener,
1503 struct weston_wm_window, surface_destroy_listener);
1504
1505 wm_log("surface for xid %d destroyed\n", window->id);
1506
1507 /* This should have been freed by the shell.
1508 * Don't try to use it later. */
1509 window->shsurf = NULL;
1510 window->surface = NULL;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001511}
1512
1513static void
1514weston_wm_window_handle_surface_id(struct weston_wm_window *window,
1515 xcb_client_message_event_t *client_message)
1516{
1517 struct weston_wm *wm = window->wm;
1518 struct wl_resource *resource;
1519
1520 if (window->surface_id != 0) {
1521 wm_log("already have surface id for window %d\n", window->id);
1522 return;
1523 }
1524
1525 /* Xwayland will send the wayland requests to create the
1526 * wl_surface before sending this client message. Even so, we
1527 * can end up handling the X event before the wayland requests
1528 * and thus when we try to look up the surface ID, the surface
1529 * hasn't been created yet. In that case put the window on
1530 * the unpaired window list and continue when the surface gets
1531 * created. */
Jason Ekstrand4ff4d922014-07-24 13:16:58 -07001532 uint32_t id = client_message->data.data32[0];
1533 resource = wl_client_get_object(wm->server->client, id);
Tyler Venesscf4c13a2014-07-02 15:00:44 -07001534 if (resource) {
1535 window->surface_id = 0;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001536 xserver_map_shell_surface(window,
1537 wl_resource_get_user_data(resource));
Tyler Venesscf4c13a2014-07-02 15:00:44 -07001538 }
1539 else {
Jason Ekstrand4ff4d922014-07-24 13:16:58 -07001540 window->surface_id = id;
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001541 wl_list_insert(&wm->unpaired_window_list, &window->link);
Tyler Venesscf4c13a2014-07-02 15:00:44 -07001542 }
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001543}
1544
1545static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001546weston_wm_handle_client_message(struct weston_wm *wm,
1547 xcb_generic_event_t *event)
1548{
1549 xcb_client_message_event_t *client_message =
1550 (xcb_client_message_event_t *) event;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001551 struct weston_wm_window *window;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001552
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001553 wm_log("XCB_CLIENT_MESSAGE (%s %d %d %d %d %d win %d)\n",
1554 get_atom_name(wm->conn, client_message->type),
1555 client_message->data.data32[0],
1556 client_message->data.data32[1],
1557 client_message->data.data32[2],
1558 client_message->data.data32[3],
1559 client_message->data.data32[4],
1560 client_message->window);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001561
Jason Ekstrand0250a742014-07-24 13:17:47 -07001562 /* The window may get created and destroyed before we actually
1563 * handle the message. If it doesn't exist, bail.
1564 */
Derek Foreman49372142015-04-09 10:51:22 -05001565 if (!wm_lookup_window(wm, client_message->window, &window))
Jason Ekstrand0250a742014-07-24 13:17:47 -07001566 return;
1567
Kristian Høgsberge68fd102012-05-22 17:09:40 -04001568 if (client_message->type == wm->atom.net_wm_moveresize)
1569 weston_wm_window_handle_moveresize(window, client_message);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05001570 else if (client_message->type == wm->atom.net_wm_state)
1571 weston_wm_window_handle_state(window, client_message);
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07001572 else if (client_message->type == wm->atom.wl_surface_id)
1573 weston_wm_window_handle_surface_id(window, client_message);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001574}
1575
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001576enum cursor_type {
1577 XWM_CURSOR_TOP,
1578 XWM_CURSOR_BOTTOM,
1579 XWM_CURSOR_LEFT,
1580 XWM_CURSOR_RIGHT,
1581 XWM_CURSOR_TOP_LEFT,
1582 XWM_CURSOR_TOP_RIGHT,
1583 XWM_CURSOR_BOTTOM_LEFT,
1584 XWM_CURSOR_BOTTOM_RIGHT,
1585 XWM_CURSOR_LEFT_PTR,
1586};
1587
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001588/*
1589 * The following correspondences between file names and cursors was copied
1590 * from: https://bugs.kde.org/attachment.cgi?id=67313
1591 */
1592
1593static const char *bottom_left_corners[] = {
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001594 "bottom_left_corner",
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001595 "sw-resize",
1596 "size_bdiag"
1597};
1598
1599static const char *bottom_right_corners[] = {
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001600 "bottom_right_corner",
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001601 "se-resize",
1602 "size_fdiag"
1603};
1604
1605static const char *bottom_sides[] = {
1606 "bottom_side",
1607 "s-resize",
1608 "size_ver"
1609};
1610
1611static const char *left_ptrs[] = {
1612 "left_ptr",
1613 "default",
1614 "top_left_arrow",
1615 "left-arrow"
1616};
1617
1618static const char *left_sides[] = {
1619 "left_side",
1620 "w-resize",
1621 "size_hor"
1622};
1623
1624static const char *right_sides[] = {
1625 "right_side",
1626 "e-resize",
1627 "size_hor"
1628};
1629
1630static const char *top_left_corners[] = {
1631 "top_left_corner",
1632 "nw-resize",
1633 "size_fdiag"
1634};
1635
1636static const char *top_right_corners[] = {
1637 "top_right_corner",
1638 "ne-resize",
1639 "size_bdiag"
1640};
1641
1642static const char *top_sides[] = {
1643 "top_side",
1644 "n-resize",
1645 "size_ver"
1646};
1647
1648struct cursor_alternatives {
1649 const char **names;
1650 size_t count;
1651};
1652
1653static const struct cursor_alternatives cursors[] = {
1654 {top_sides, ARRAY_LENGTH(top_sides)},
1655 {bottom_sides, ARRAY_LENGTH(bottom_sides)},
1656 {left_sides, ARRAY_LENGTH(left_sides)},
1657 {right_sides, ARRAY_LENGTH(right_sides)},
1658 {top_left_corners, ARRAY_LENGTH(top_left_corners)},
1659 {top_right_corners, ARRAY_LENGTH(top_right_corners)},
1660 {bottom_left_corners, ARRAY_LENGTH(bottom_left_corners)},
1661 {bottom_right_corners, ARRAY_LENGTH(bottom_right_corners)},
1662 {left_ptrs, ARRAY_LENGTH(left_ptrs)},
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001663};
1664
1665static void
1666weston_wm_create_cursors(struct weston_wm *wm)
1667{
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001668 const char *name;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001669 int i, count = ARRAY_LENGTH(cursors);
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001670 size_t j;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001671
1672 wm->cursors = malloc(count * sizeof(xcb_cursor_t));
1673 for (i = 0; i < count; i++) {
Giulio Camuffoa2df51c2013-09-18 15:20:04 +02001674 for (j = 0; j < cursors[i].count; j++) {
1675 name = cursors[i].names[j];
1676 wm->cursors[i] =
1677 xcb_cursor_library_load_cursor(wm, name);
1678 if (wm->cursors[i] != (xcb_cursor_t)-1)
1679 break;
1680 }
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001681 }
1682
1683 wm->last_cursor = -1;
1684}
1685
1686static void
1687weston_wm_destroy_cursors(struct weston_wm *wm)
1688{
1689 uint8_t i;
1690
1691 for (i = 0; i < ARRAY_LENGTH(cursors); i++)
1692 xcb_free_cursor(wm->conn, wm->cursors[i]);
1693
1694 free(wm->cursors);
1695}
1696
1697static int
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001698get_cursor_for_location(enum theme_location location)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001699{
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001700 switch (location) {
1701 case THEME_LOCATION_RESIZING_TOP:
1702 return XWM_CURSOR_TOP;
1703 case THEME_LOCATION_RESIZING_BOTTOM:
1704 return XWM_CURSOR_BOTTOM;
1705 case THEME_LOCATION_RESIZING_LEFT:
1706 return XWM_CURSOR_LEFT;
1707 case THEME_LOCATION_RESIZING_RIGHT:
1708 return XWM_CURSOR_RIGHT;
1709 case THEME_LOCATION_RESIZING_TOP_LEFT:
1710 return XWM_CURSOR_TOP_LEFT;
1711 case THEME_LOCATION_RESIZING_TOP_RIGHT:
1712 return XWM_CURSOR_TOP_RIGHT;
1713 case THEME_LOCATION_RESIZING_BOTTOM_LEFT:
1714 return XWM_CURSOR_BOTTOM_LEFT;
1715 case THEME_LOCATION_RESIZING_BOTTOM_RIGHT:
1716 return XWM_CURSOR_BOTTOM_RIGHT;
1717 case THEME_LOCATION_EXTERIOR:
1718 case THEME_LOCATION_TITLEBAR:
1719 default:
1720 return XWM_CURSOR_LEFT_PTR;
1721 }
1722}
1723
1724static void
Tiago Vignattic1903232012-07-16 12:15:37 -04001725weston_wm_window_set_cursor(struct weston_wm *wm, xcb_window_t window_id,
1726 int cursor)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001727{
1728 uint32_t cursor_value_list;
1729
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001730 if (wm->last_cursor == cursor)
1731 return;
1732
1733 wm->last_cursor = cursor;
1734
1735 cursor_value_list = wm->cursors[cursor];
Tiago Vignattic1903232012-07-16 12:15:37 -04001736 xcb_change_window_attributes (wm->conn, window_id,
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001737 XCB_CW_CURSOR, &cursor_value_list);
1738 xcb_flush(wm->conn);
1739}
1740
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001741static void
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -07001742weston_wm_window_close(struct weston_wm_window *window, xcb_timestamp_t time)
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001743{
1744 xcb_client_message_event_t client_message;
1745
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -07001746 if (window->delete_window) {
1747 client_message.response_type = XCB_CLIENT_MESSAGE;
1748 client_message.format = 32;
1749 client_message.window = window->id;
1750 client_message.type = window->wm->atom.wm_protocols;
1751 client_message.data.data32[0] =
1752 window->wm->atom.wm_delete_window;
1753 client_message.data.data32[1] = time;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001754
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -07001755 xcb_send_event(window->wm->conn, 0, window->id,
1756 XCB_EVENT_MASK_NO_EVENT,
1757 (char *) &client_message);
1758 } else {
1759 xcb_kill_client(window->wm->conn, window->id);
1760 }
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001761}
1762
1763static void
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001764weston_wm_handle_button(struct weston_wm *wm, xcb_generic_event_t *event)
1765{
1766 xcb_button_press_event_t *button = (xcb_button_press_event_t *) event;
Quentin Glidic955cec02016-08-12 10:41:35 +02001767 const struct weston_desktop_xwayland_interface *xwayland_interface =
1768 wm->server->compositor->xwayland_interface;
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001769 struct weston_seat *seat;
Derek Foremane4d6c832015-08-05 14:48:11 -05001770 struct weston_pointer *pointer;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001771 struct weston_wm_window *window;
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001772 enum theme_location location;
Quentin Glidicd8b17bc2016-07-10 11:00:55 +02001773 enum wl_pointer_button_state button_state;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001774 uint32_t button_id;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001775
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001776 wm_log("XCB_BUTTON_%s (detail %d)\n",
1777 button->response_type == XCB_BUTTON_PRESS ?
1778 "PRESS" : "RELEASE", button->detail);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001779
Derek Foreman49372142015-04-09 10:51:22 -05001780 if (!wm_lookup_window(wm, button->event, &window) ||
1781 !window->decorate)
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001782 return;
Kristian Høgsbergc1693f22012-05-22 16:56:23 -04001783
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001784 if (button->detail != 1 && button->detail != 2)
1785 return;
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001786
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001787 seat = weston_wm_pick_seat_for_window(window);
Derek Foremane4d6c832015-08-05 14:48:11 -05001788 pointer = weston_seat_get_pointer(seat);
Kristian Høgsberg052ef4e2014-04-30 16:10:14 -07001789
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001790 button_state = button->response_type == XCB_BUTTON_PRESS ?
Quentin Glidicd8b17bc2016-07-10 11:00:55 +02001791 WL_POINTER_BUTTON_STATE_PRESSED :
1792 WL_POINTER_BUTTON_STATE_RELEASED;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001793 button_id = button->detail == 1 ? BTN_LEFT : BTN_RIGHT;
1794
Kristian Høgsberg8c3c7382014-04-30 16:52:30 -07001795 /* Make sure we're looking at the right location. The frame
1796 * could have received a motion event from a pointer from a
1797 * different wl_seat, but under X it looks like our core
1798 * pointer moved. Move the frame pointer to the button press
1799 * location before deciding what to do. */
1800 location = frame_pointer_motion(window->frame, NULL,
1801 button->event_x, button->event_y);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001802 location = frame_pointer_button(window->frame, NULL,
1803 button_id, button_state);
1804 if (frame_status(window->frame) & FRAME_STATUS_REPAINT)
1805 weston_wm_window_schedule_repaint(window);
1806
1807 if (frame_status(window->frame) & FRAME_STATUS_MOVE) {
Derek Foremane4d6c832015-08-05 14:48:11 -05001808 if (pointer)
Quentin Glidic955cec02016-08-12 10:41:35 +02001809 xwayland_interface->move(window->shsurf, pointer);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001810 frame_status_clear(window->frame, FRAME_STATUS_MOVE);
1811 }
1812
1813 if (frame_status(window->frame) & FRAME_STATUS_RESIZE) {
Derek Foremane4d6c832015-08-05 14:48:11 -05001814 if (pointer)
Quentin Glidic955cec02016-08-12 10:41:35 +02001815 xwayland_interface->resize(window->shsurf, pointer, location);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001816 frame_status_clear(window->frame, FRAME_STATUS_RESIZE);
1817 }
1818
1819 if (frame_status(window->frame) & FRAME_STATUS_CLOSE) {
Kristian Høgsberg2cd6da12013-10-13 22:11:07 -07001820 weston_wm_window_close(window, button->time);
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001821 frame_status_clear(window->frame, FRAME_STATUS_CLOSE);
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -04001822 }
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001823
1824 if (frame_status(window->frame) & FRAME_STATUS_MAXIMIZE) {
1825 window->maximized_horz = !window->maximized_horz;
1826 window->maximized_vert = !window->maximized_vert;
1827 if (weston_wm_window_is_maximized(window)) {
1828 window->saved_width = window->width;
1829 window->saved_height = window->height;
Quentin Glidic955cec02016-08-12 10:41:35 +02001830 xwayland_interface->set_maximized(window->shsurf);
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02001831 } else {
1832 weston_wm_window_set_toplevel(window);
1833 }
1834 frame_status_clear(window->frame, FRAME_STATUS_MAXIMIZE);
1835 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001836}
1837
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001838static void
1839weston_wm_handle_motion(struct weston_wm *wm, xcb_generic_event_t *event)
1840{
1841 xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *) event;
1842 struct weston_wm_window *window;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001843 enum theme_location location;
1844 int cursor;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001845
Derek Foreman49372142015-04-09 10:51:22 -05001846 if (!wm_lookup_window(wm, motion->event, &window) ||
1847 !window->decorate)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001848 return;
1849
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001850 location = frame_pointer_motion(window->frame, NULL,
1851 motion->event_x, motion->event_y);
1852 if (frame_status(window->frame) & FRAME_STATUS_REPAINT)
1853 weston_wm_window_schedule_repaint(window);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001854
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001855 cursor = get_cursor_for_location(location);
Tiago Vignattic1903232012-07-16 12:15:37 -04001856 weston_wm_window_set_cursor(wm, window->frame_id, cursor);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001857}
1858
1859static void
1860weston_wm_handle_enter(struct weston_wm *wm, xcb_generic_event_t *event)
1861{
1862 xcb_enter_notify_event_t *enter = (xcb_enter_notify_event_t *) event;
1863 struct weston_wm_window *window;
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001864 enum theme_location location;
1865 int cursor;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001866
Derek Foreman49372142015-04-09 10:51:22 -05001867 if (!wm_lookup_window(wm, enter->event, &window) ||
1868 !window->decorate)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001869 return;
1870
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001871 location = frame_pointer_enter(window->frame, NULL,
1872 enter->event_x, enter->event_y);
1873 if (frame_status(window->frame) & FRAME_STATUS_REPAINT)
1874 weston_wm_window_schedule_repaint(window);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001875
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001876 cursor = get_cursor_for_location(location);
Tiago Vignattic1903232012-07-16 12:15:37 -04001877 weston_wm_window_set_cursor(wm, window->frame_id, cursor);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001878}
1879
1880static void
1881weston_wm_handle_leave(struct weston_wm *wm, xcb_generic_event_t *event)
1882{
1883 xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *) event;
1884 struct weston_wm_window *window;
1885
Derek Foreman49372142015-04-09 10:51:22 -05001886 if (!wm_lookup_window(wm, leave->event, &window) ||
1887 !window->decorate)
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001888 return;
1889
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05001890 frame_pointer_leave(window->frame, NULL);
1891 if (frame_status(window->frame) & FRAME_STATUS_REPAINT)
1892 weston_wm_window_schedule_repaint(window);
1893
Tiago Vignattic1903232012-07-16 12:15:37 -04001894 weston_wm_window_set_cursor(wm, window->frame_id, XWM_CURSOR_LEFT_PTR);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001895}
1896
Giulio Camuffob18f7882015-03-29 14:20:23 +03001897static void
1898weston_wm_handle_focus_in(struct weston_wm *wm, xcb_generic_event_t *event)
1899{
1900 xcb_focus_in_event_t *focus = (xcb_focus_in_event_t *) event;
1901 /* Do not let X clients change the focus behind the compositor's
1902 * back. Reset the focus to the old one if it changed. */
1903 if (!wm->focus_window || focus->event != wm->focus_window->id)
1904 weston_wm_send_focus_window(wm, wm->focus_window);
1905}
1906
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001907static int
1908weston_wm_handle_event(int fd, uint32_t mask, void *data)
1909{
1910 struct weston_wm *wm = data;
1911 xcb_generic_event_t *event;
1912 int count = 0;
1913
1914 while (event = xcb_poll_for_event(wm->conn), event != NULL) {
1915 if (weston_wm_handle_selection_event(wm, event)) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001916 free(event);
1917 count++;
1918 continue;
1919 }
1920
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -07001921 if (weston_wm_handle_dnd_event(wm, event)) {
1922 free(event);
1923 count++;
1924 continue;
1925 }
1926
MoD31700122013-06-11 19:58:55 -05001927 switch (EVENT_TYPE(event)) {
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001928 case XCB_BUTTON_PRESS:
1929 case XCB_BUTTON_RELEASE:
1930 weston_wm_handle_button(wm, event);
1931 break;
Tiago Vignatti236b48d2012-07-16 12:09:19 -04001932 case XCB_ENTER_NOTIFY:
1933 weston_wm_handle_enter(wm, event);
1934 break;
1935 case XCB_LEAVE_NOTIFY:
1936 weston_wm_handle_leave(wm, event);
1937 break;
1938 case XCB_MOTION_NOTIFY:
1939 weston_wm_handle_motion(wm, event);
1940 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001941 case XCB_CREATE_NOTIFY:
1942 weston_wm_handle_create_notify(wm, event);
1943 break;
1944 case XCB_MAP_REQUEST:
1945 weston_wm_handle_map_request(wm, event);
1946 break;
1947 case XCB_MAP_NOTIFY:
1948 weston_wm_handle_map_notify(wm, event);
1949 break;
1950 case XCB_UNMAP_NOTIFY:
Kristian Høgsberg194ea542012-05-30 10:05:41 -04001951 weston_wm_handle_unmap_notify(wm, event);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001952 break;
Kristian Høgsberg029539b2012-05-30 11:28:24 -04001953 case XCB_REPARENT_NOTIFY:
1954 weston_wm_handle_reparent_notify(wm, event);
1955 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001956 case XCB_CONFIGURE_REQUEST:
1957 weston_wm_handle_configure_request(wm, event);
1958 break;
1959 case XCB_CONFIGURE_NOTIFY:
1960 weston_wm_handle_configure_notify(wm, event);
1961 break;
1962 case XCB_DESTROY_NOTIFY:
1963 weston_wm_handle_destroy_notify(wm, event);
1964 break;
1965 case XCB_MAPPING_NOTIFY:
Kristian Høgsberg082d58c2013-06-18 01:00:27 -04001966 wm_log("XCB_MAPPING_NOTIFY\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001967 break;
1968 case XCB_PROPERTY_NOTIFY:
1969 weston_wm_handle_property_notify(wm, event);
1970 break;
1971 case XCB_CLIENT_MESSAGE:
1972 weston_wm_handle_client_message(wm, event);
1973 break;
Giulio Camuffob18f7882015-03-29 14:20:23 +03001974 case XCB_FOCUS_IN:
1975 weston_wm_handle_focus_in(wm, event);
1976 break;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001977 }
1978
1979 free(event);
1980 count++;
1981 }
1982
Marek Chalupaa1f3f3c2015-08-12 09:55:12 +02001983 if (count != 0)
1984 xcb_flush(wm->conn);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04001985
1986 return count;
1987}
1988
1989static void
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02001990weston_wm_set_net_active_window(struct weston_wm *wm, xcb_window_t window) {
1991 xcb_change_property(wm->conn, XCB_PROP_MODE_REPLACE,
1992 wm->screen->root, wm->atom.net_active_window,
1993 wm->atom.window, 32, 1, &window);
1994}
1995
1996static void
Kristian Høgsbergf9187192013-05-02 13:43:24 -04001997weston_wm_get_visual_and_colormap(struct weston_wm *wm)
1998{
1999 xcb_depth_iterator_t d_iter;
2000 xcb_visualtype_iterator_t vt_iter;
2001 xcb_visualtype_t *visualtype;
2002
2003 d_iter = xcb_screen_allowed_depths_iterator(wm->screen);
2004 visualtype = NULL;
2005 while (d_iter.rem > 0) {
2006 if (d_iter.data->depth == 32) {
2007 vt_iter = xcb_depth_visuals_iterator(d_iter.data);
2008 visualtype = vt_iter.data;
2009 break;
2010 }
2011
2012 xcb_depth_next(&d_iter);
2013 }
2014
2015 if (visualtype == NULL) {
2016 weston_log("no 32 bit visualtype\n");
2017 return;
2018 }
2019
2020 wm->visual_id = visualtype->visual_id;
2021 wm->colormap = xcb_generate_id(wm->conn);
2022 xcb_create_colormap(wm->conn, XCB_COLORMAP_ALLOC_NONE,
2023 wm->colormap, wm->screen->root, wm->visual_id);
2024}
2025
2026static void
Tiago Vignatti9c4ff832012-11-30 17:19:57 -02002027weston_wm_get_resources(struct weston_wm *wm)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002028{
2029
2030#define F(field) offsetof(struct weston_wm, field)
2031
2032 static const struct { const char *name; int offset; } atoms[] = {
2033 { "WM_PROTOCOLS", F(atom.wm_protocols) },
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -07002034 { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002035 { "WM_TAKE_FOCUS", F(atom.wm_take_focus) },
2036 { "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
Kristian Høgsberga6d9a5e2012-05-30 12:15:44 -04002037 { "WM_STATE", F(atom.wm_state) },
Kristian Høgsberg670b5d32012-06-04 11:00:40 -04002038 { "WM_S0", F(atom.wm_s0) },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03002039 { "WM_CLIENT_MACHINE", F(atom.wm_client_machine) },
Kristian Høgsberg69981d92013-08-21 22:14:58 -07002040 { "_NET_WM_CM_S0", F(atom.net_wm_cm_s0) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002041 { "_NET_WM_NAME", F(atom.net_wm_name) },
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03002042 { "_NET_WM_PID", F(atom.net_wm_pid) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002043 { "_NET_WM_ICON", F(atom.net_wm_icon) },
2044 { "_NET_WM_STATE", F(atom.net_wm_state) },
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02002045 { "_NET_WM_STATE_MAXIMIZED_VERT", F(atom.net_wm_state_maximized_vert) },
2046 { "_NET_WM_STATE_MAXIMIZED_HORZ", F(atom.net_wm_state_maximized_horz) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002047 { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
2048 { "_NET_WM_USER_TIME", F(atom.net_wm_user_time) },
2049 { "_NET_WM_ICON_NAME", F(atom.net_wm_icon_name) },
Giulio Camuffoe90ea442014-12-13 18:06:34 +02002050 { "_NET_WM_DESKTOP", F(atom.net_wm_desktop) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002051 { "_NET_WM_WINDOW_TYPE", F(atom.net_wm_window_type) },
2052
2053 { "_NET_WM_WINDOW_TYPE_DESKTOP", F(atom.net_wm_window_type_desktop) },
2054 { "_NET_WM_WINDOW_TYPE_DOCK", F(atom.net_wm_window_type_dock) },
2055 { "_NET_WM_WINDOW_TYPE_TOOLBAR", F(atom.net_wm_window_type_toolbar) },
2056 { "_NET_WM_WINDOW_TYPE_MENU", F(atom.net_wm_window_type_menu) },
2057 { "_NET_WM_WINDOW_TYPE_UTILITY", F(atom.net_wm_window_type_utility) },
2058 { "_NET_WM_WINDOW_TYPE_SPLASH", F(atom.net_wm_window_type_splash) },
2059 { "_NET_WM_WINDOW_TYPE_DIALOG", F(atom.net_wm_window_type_dialog) },
Tiago Vignattibf1e8662012-06-12 14:07:49 +03002060 { "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", F(atom.net_wm_window_type_dropdown) },
2061 { "_NET_WM_WINDOW_TYPE_POPUP_MENU", F(atom.net_wm_window_type_popup) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002062 { "_NET_WM_WINDOW_TYPE_TOOLTIP", F(atom.net_wm_window_type_tooltip) },
2063 { "_NET_WM_WINDOW_TYPE_NOTIFICATION", F(atom.net_wm_window_type_notification) },
2064 { "_NET_WM_WINDOW_TYPE_COMBO", F(atom.net_wm_window_type_combo) },
2065 { "_NET_WM_WINDOW_TYPE_DND", F(atom.net_wm_window_type_dnd) },
2066 { "_NET_WM_WINDOW_TYPE_NORMAL", F(atom.net_wm_window_type_normal) },
2067
2068 { "_NET_WM_MOVERESIZE", F(atom.net_wm_moveresize) },
2069 { "_NET_SUPPORTING_WM_CHECK",
2070 F(atom.net_supporting_wm_check) },
2071 { "_NET_SUPPORTED", F(atom.net_supported) },
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002072 { "_NET_ACTIVE_WINDOW", F(atom.net_active_window) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002073 { "_MOTIF_WM_HINTS", F(atom.motif_wm_hints) },
2074 { "CLIPBOARD", F(atom.clipboard) },
Kristian Høgsbergcba022a2012-06-04 10:11:45 -04002075 { "CLIPBOARD_MANAGER", F(atom.clipboard_manager) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002076 { "TARGETS", F(atom.targets) },
2077 { "UTF8_STRING", F(atom.utf8_string) },
2078 { "_WL_SELECTION", F(atom.wl_selection) },
2079 { "INCR", F(atom.incr) },
2080 { "TIMESTAMP", F(atom.timestamp) },
2081 { "MULTIPLE", F(atom.multiple) },
2082 { "UTF8_STRING" , F(atom.utf8_string) },
2083 { "COMPOUND_TEXT", F(atom.compound_text) },
2084 { "TEXT", F(atom.text) },
2085 { "STRING", F(atom.string) },
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002086 { "WINDOW", F(atom.window) },
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002087 { "text/plain;charset=utf-8", F(atom.text_plain_utf8) },
2088 { "text/plain", F(atom.text_plain) },
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -07002089 { "XdndSelection", F(atom.xdnd_selection) },
2090 { "XdndAware", F(atom.xdnd_aware) },
2091 { "XdndEnter", F(atom.xdnd_enter) },
2092 { "XdndLeave", F(atom.xdnd_leave) },
2093 { "XdndDrop", F(atom.xdnd_drop) },
2094 { "XdndStatus", F(atom.xdnd_status) },
2095 { "XdndFinished", F(atom.xdnd_finished) },
2096 { "XdndTypeList", F(atom.xdnd_type_list) },
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002097 { "XdndActionCopy", F(atom.xdnd_action_copy) },
2098 { "WL_SURFACE_ID", F(atom.wl_surface_id) }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002099 };
2100#undef F
2101
2102 xcb_xfixes_query_version_cookie_t xfixes_cookie;
2103 xcb_xfixes_query_version_reply_t *xfixes_reply;
2104 xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
2105 xcb_intern_atom_reply_t *reply;
2106 xcb_render_query_pict_formats_reply_t *formats_reply;
2107 xcb_render_query_pict_formats_cookie_t formats_cookie;
2108 xcb_render_pictforminfo_t *formats;
2109 uint32_t i;
2110
2111 xcb_prefetch_extension_data (wm->conn, &xcb_xfixes_id);
Kristian Høgsbergbcfd07b2013-10-11 16:48:19 -07002112 xcb_prefetch_extension_data (wm->conn, &xcb_composite_id);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002113
2114 formats_cookie = xcb_render_query_pict_formats(wm->conn);
2115
2116 for (i = 0; i < ARRAY_LENGTH(atoms); i++)
2117 cookies[i] = xcb_intern_atom (wm->conn, 0,
2118 strlen(atoms[i].name),
2119 atoms[i].name);
2120
2121 for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
2122 reply = xcb_intern_atom_reply (wm->conn, cookies[i], NULL);
2123 *(xcb_atom_t *) ((char *) wm + atoms[i].offset) = reply->atom;
2124 free(reply);
2125 }
2126
2127 wm->xfixes = xcb_get_extension_data(wm->conn, &xcb_xfixes_id);
2128 if (!wm->xfixes || !wm->xfixes->present)
Martin Minarik6d118362012-06-07 18:01:59 +02002129 weston_log("xfixes not available\n");
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002130
2131 xfixes_cookie = xcb_xfixes_query_version(wm->conn,
2132 XCB_XFIXES_MAJOR_VERSION,
2133 XCB_XFIXES_MINOR_VERSION);
2134 xfixes_reply = xcb_xfixes_query_version_reply(wm->conn,
2135 xfixes_cookie, NULL);
2136
Martin Minarik6d118362012-06-07 18:01:59 +02002137 weston_log("xfixes version: %d.%d\n",
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002138 xfixes_reply->major_version, xfixes_reply->minor_version);
2139
2140 free(xfixes_reply);
2141
2142 formats_reply = xcb_render_query_pict_formats_reply(wm->conn,
2143 formats_cookie, 0);
2144 if (formats_reply == NULL)
2145 return;
2146
2147 formats = xcb_render_query_pict_formats_formats(formats_reply);
Kristian Høgsberge89cef32012-07-16 11:57:08 -04002148 for (i = 0; i < formats_reply->num_formats; i++) {
2149 if (formats[i].direct.red_mask != 0xff &&
2150 formats[i].direct.red_shift != 16)
2151 continue;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002152 if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT &&
2153 formats[i].depth == 24)
Kristian Høgsberge89cef32012-07-16 11:57:08 -04002154 wm->format_rgb = formats[i];
2155 if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT &&
2156 formats[i].depth == 32 &&
2157 formats[i].direct.alpha_mask == 0xff &&
2158 formats[i].direct.alpha_shift == 24)
2159 wm->format_rgba = formats[i];
2160 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002161
2162 free(formats_reply);
2163}
2164
2165static void
2166weston_wm_create_wm_window(struct weston_wm *wm)
2167{
2168 static const char name[] = "Weston WM";
2169
2170 wm->wm_window = xcb_generate_id(wm->conn);
2171 xcb_create_window(wm->conn,
2172 XCB_COPY_FROM_PARENT,
2173 wm->wm_window,
2174 wm->screen->root,
2175 0, 0,
2176 10, 10,
2177 0,
2178 XCB_WINDOW_CLASS_INPUT_OUTPUT,
2179 wm->screen->root_visual,
2180 0, NULL);
2181
2182 xcb_change_property(wm->conn,
2183 XCB_PROP_MODE_REPLACE,
2184 wm->wm_window,
2185 wm->atom.net_supporting_wm_check,
2186 XCB_ATOM_WINDOW,
2187 32, /* format */
2188 1, &wm->wm_window);
2189
2190 xcb_change_property(wm->conn,
2191 XCB_PROP_MODE_REPLACE,
2192 wm->wm_window,
2193 wm->atom.net_wm_name,
2194 wm->atom.utf8_string,
2195 8, /* format */
2196 strlen(name), name);
2197
2198 xcb_change_property(wm->conn,
2199 XCB_PROP_MODE_REPLACE,
2200 wm->screen->root,
2201 wm->atom.net_supporting_wm_check,
2202 XCB_ATOM_WINDOW,
2203 32, /* format */
2204 1, &wm->wm_window);
2205
Abdur Rehmanb8b150b2017-01-01 19:46:46 +05002206 /* Claim the WM_S0 selection even though we don't support
Kristian Høgsberg670b5d32012-06-04 11:00:40 -04002207 * the --replace functionality. */
2208 xcb_set_selection_owner(wm->conn,
2209 wm->wm_window,
2210 wm->atom.wm_s0,
2211 XCB_TIME_CURRENT_TIME);
Kristian Høgsberg69981d92013-08-21 22:14:58 -07002212
2213 xcb_set_selection_owner(wm->conn,
2214 wm->wm_window,
2215 wm->atom.net_wm_cm_s0,
2216 XCB_TIME_CURRENT_TIME);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002217}
2218
2219struct weston_wm *
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002220weston_wm_create(struct weston_xserver *wxs, int fd)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002221{
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002222 struct weston_wm *wm;
2223 struct wl_event_loop *loop;
2224 xcb_screen_iterator_t s;
Kristian Høgsberg4dec0112012-06-03 09:18:06 -04002225 uint32_t values[1];
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002226 xcb_atom_t supported[6];
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002227
Peter Huttererf3d62272013-08-08 11:57:05 +10002228 wm = zalloc(sizeof *wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002229 if (wm == NULL)
2230 return NULL;
2231
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002232 wm->server = wxs;
2233 wm->window_hash = hash_table_create();
2234 if (wm->window_hash == NULL) {
2235 free(wm);
2236 return NULL;
2237 }
2238
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002239 /* xcb_connect_to_fd takes ownership of the fd. */
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002240 wm->conn = xcb_connect_to_fd(fd, NULL);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002241 if (xcb_connection_has_error(wm->conn)) {
Martin Minarik6d118362012-06-07 18:01:59 +02002242 weston_log("xcb_connect_to_fd failed\n");
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002243 close(fd);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002244 hash_table_destroy(wm->window_hash);
2245 free(wm);
2246 return NULL;
2247 }
2248
2249 s = xcb_setup_roots_iterator(xcb_get_setup(wm->conn));
2250 wm->screen = s.data;
2251
2252 loop = wl_display_get_event_loop(wxs->wl_display);
2253 wm->source =
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002254 wl_event_loop_add_fd(loop, fd,
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002255 WL_EVENT_READABLE,
2256 weston_wm_handle_event, wm);
2257 wl_event_source_check(wm->source);
2258
Tiago Vignatti9c4ff832012-11-30 17:19:57 -02002259 weston_wm_get_resources(wm);
Kristian Høgsbergf9187192013-05-02 13:43:24 -04002260 weston_wm_get_visual_and_colormap(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002261
2262 values[0] =
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002263 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
2264 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
2265 XCB_EVENT_MASK_PROPERTY_CHANGE;
2266 xcb_change_window_attributes(wm->conn, wm->screen->root,
2267 XCB_CW_EVENT_MASK, values);
Kristian Høgsbergbcfd07b2013-10-11 16:48:19 -07002268
2269 xcb_composite_redirect_subwindows(wm->conn, wm->screen->root,
2270 XCB_COMPOSITE_REDIRECT_MANUAL);
2271
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002272 wm->theme = theme_create();
2273
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002274 supported[0] = wm->atom.net_wm_moveresize;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002275 supported[1] = wm->atom.net_wm_state;
2276 supported[2] = wm->atom.net_wm_state_fullscreen;
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02002277 supported[3] = wm->atom.net_wm_state_maximized_vert;
2278 supported[4] = wm->atom.net_wm_state_maximized_horz;
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002279 supported[5] = wm->atom.net_active_window;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002280 xcb_change_property(wm->conn,
2281 XCB_PROP_MODE_REPLACE,
2282 wm->screen->root,
2283 wm->atom.net_supported,
2284 XCB_ATOM_ATOM,
2285 32, /* format */
2286 ARRAY_LENGTH(supported), supported);
2287
Benoit Gschwind1a42ca12015-09-25 21:26:04 +02002288 weston_wm_set_net_active_window(wm, XCB_WINDOW_NONE);
2289
Kristian Høgsberg4dec0112012-06-03 09:18:06 -04002290 weston_wm_selection_init(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002291
Kristian Høgsbergf9cb3b12013-09-04 21:12:26 -07002292 weston_wm_dnd_init(wm);
2293
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002294 xcb_flush(wm->conn);
2295
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002296 wm->create_surface_listener.notify = weston_wm_create_surface;
2297 wl_signal_add(&wxs->compositor->create_surface_signal,
2298 &wm->create_surface_listener);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002299 wm->activate_listener.notify = weston_wm_window_activate;
2300 wl_signal_add(&wxs->compositor->activate_signal,
2301 &wm->activate_listener);
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03002302 wm->kill_listener.notify = weston_wm_kill_client;
2303 wl_signal_add(&wxs->compositor->kill_signal,
2304 &wm->kill_listener);
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002305 wl_list_init(&wm->unpaired_window_list);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002306
Tiago Vignatti236b48d2012-07-16 12:09:19 -04002307 weston_wm_create_cursors(wm);
Tiago Vignattic1903232012-07-16 12:15:37 -04002308 weston_wm_window_set_cursor(wm, wm->screen->root, XWM_CURSOR_LEFT_PTR);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04002309
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002310 /* Create wm window and take WM_S0 selection last, which
2311 * signals to Xwayland that we're done with setup. */
2312 weston_wm_create_wm_window(wm);
2313
2314 weston_log("created wm, root %d\n", wm->screen->root);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002315
2316 return wm;
2317}
2318
2319void
2320weston_wm_destroy(struct weston_wm *wm)
2321{
2322 /* FIXME: Free windows in hash. */
2323 hash_table_destroy(wm->window_hash);
Tiago Vignatti236b48d2012-07-16 12:09:19 -04002324 weston_wm_destroy_cursors(wm);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002325 xcb_disconnect(wm->conn);
2326 wl_event_source_remove(wm->source);
2327 wl_list_remove(&wm->selection_listener.link);
2328 wl_list_remove(&wm->activate_listener.link);
Tiago Vignatti0d20d7c2012-09-27 17:48:37 +03002329 wl_list_remove(&wm->kill_listener.link);
Derek Foremanf10e06c2015-02-03 11:05:10 -06002330 wl_list_remove(&wm->create_surface_listener.link);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002331
2332 free(wm);
2333}
2334
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002335static struct weston_wm_window *
2336get_wm_window(struct weston_surface *surface)
2337{
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002338 struct wl_listener *listener;
2339
Jason Ekstrand26ed73c2013-06-06 22:34:41 -05002340 listener = wl_signal_get(&surface->destroy_signal, surface_destroy);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002341 if (listener)
2342 return container_of(listener, struct weston_wm_window,
2343 surface_destroy_listener);
2344
2345 return NULL;
2346}
2347
Quentin Glidic955cec02016-08-12 10:41:35 +02002348static bool
2349is_wm_window(struct weston_surface *surface)
2350{
2351 return get_wm_window(surface) != NULL;
2352}
2353
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002354static void
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002355weston_wm_window_configure(void *data)
2356{
2357 struct weston_wm_window *window = data;
2358 struct weston_wm *wm = window->wm;
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002359 uint32_t values[4];
2360 int x, y, width, height;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002361
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002362 weston_wm_window_get_child_position(window, &x, &y);
2363 values[0] = x;
2364 values[1] = y;
2365 values[2] = window->width;
2366 values[3] = window->height;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002367 xcb_configure_window(wm->conn,
2368 window->id,
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002369 XCB_CONFIG_WINDOW_X |
2370 XCB_CONFIG_WINDOW_Y |
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002371 XCB_CONFIG_WINDOW_WIDTH |
2372 XCB_CONFIG_WINDOW_HEIGHT,
2373 values);
2374
2375 weston_wm_window_get_frame_size(window, &width, &height);
2376 values[0] = width;
2377 values[1] = height;
2378 xcb_configure_window(wm->conn,
2379 window->frame_id,
2380 XCB_CONFIG_WINDOW_WIDTH |
2381 XCB_CONFIG_WINDOW_HEIGHT,
2382 values);
2383
2384 window->configure_source = NULL;
2385
2386 weston_wm_window_schedule_repaint(window);
2387}
2388
2389static void
Jasper St. Pierreac985be2014-04-28 11:19:28 -04002390send_configure(struct weston_surface *surface, int32_t width, int32_t height)
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002391{
2392 struct weston_wm_window *window = get_wm_window(surface);
2393 struct weston_wm *wm = window->wm;
2394 struct theme *t = window->wm->theme;
Kristian Høgsbergfa514b42013-07-08 15:00:25 -04002395 int vborder, hborder;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002396
Marek Chalupae9fe4672014-10-29 13:44:44 +01002397 if (window->decorate && !window->fullscreen) {
Jasper St. Pierre8ffd38b2014-08-27 09:38:33 -04002398 hborder = 2 * t->width;
2399 vborder = t->titlebar_height + t->width;
2400 } else {
Kristian Høgsbergfa514b42013-07-08 15:00:25 -04002401 hborder = 0;
2402 vborder = 0;
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002403 }
2404
Kristian Høgsbergfa514b42013-07-08 15:00:25 -04002405 if (width > hborder)
2406 window->width = width - hborder;
2407 else
2408 window->width = 1;
2409
2410 if (height > vborder)
2411 window->height = height - vborder;
2412 else
2413 window->height = 1;
2414
Jason Ekstrandd14c4ca2013-10-13 19:08:41 -05002415 if (window->frame)
2416 frame_resize_inside(window->frame, window->width, window->height);
2417
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002418 if (window->configure_source)
2419 return;
2420
2421 window->configure_source =
2422 wl_event_loop_add_idle(wm->server->loop,
2423 weston_wm_window_configure, window);
2424}
2425
Giulio Camuffof05d18f2015-12-11 20:57:05 +02002426static void
2427send_position(struct weston_surface *surface, int32_t x, int32_t y)
2428{
2429 struct weston_wm_window *window = get_wm_window(surface);
2430 struct weston_wm *wm;
2431 uint32_t mask, values[2];
2432
2433 if (!window || !window->wm)
2434 return;
2435
2436 wm = window->wm;
2437 /* We use pos_dirty to tell whether a configure message is in flight.
2438 * This is needed in case we send two configure events in a very
2439 * short time, since window->x/y is set in after a roundtrip, hence
2440 * we cannot just check if the current x and y are different. */
2441 if (window->x != x || window->y != y || window->pos_dirty) {
2442 window->pos_dirty = true;
2443 values[0] = x;
2444 values[1] = y;
2445 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y;
2446
2447 xcb_configure_window(wm->conn, window->frame_id, mask, values);
2448 xcb_flush(wm->conn);
2449 }
2450}
2451
Quentin Glidic955cec02016-08-12 10:41:35 +02002452static const struct weston_xwayland_client_interface shell_client = {
Giulio Camuffof05d18f2015-12-11 20:57:05 +02002453 send_configure,
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002454};
2455
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002456static int
2457legacy_fullscreen(struct weston_wm *wm,
2458 struct weston_wm_window *window,
2459 struct weston_output **output_ret)
2460{
2461 struct weston_compositor *compositor = wm->server->compositor;
2462 struct weston_output *output;
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -07002463 uint32_t minmax = PMinSize | PMaxSize;
2464 int matching_size;
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002465
2466 /* Heuristics for detecting legacy fullscreen windows... */
2467
2468 wl_list_for_each(output, &compositor->output_list, link) {
2469 if (output->x == window->x &&
2470 output->y == window->y &&
2471 output->width == window->width &&
2472 output->height == window->height &&
2473 window->override_redirect) {
2474 *output_ret = output;
2475 return 1;
2476 }
Kristian Høgsberg1a7a57f2013-08-31 00:12:25 -07002477
2478 matching_size = 0;
2479 if ((window->size_hints.flags & (USSize |PSize)) &&
2480 window->size_hints.width == output->width &&
2481 window->size_hints.height == output->height)
2482 matching_size = 1;
2483 if ((window->size_hints.flags & minmax) == minmax &&
2484 window->size_hints.min_width == output->width &&
2485 window->size_hints.min_height == output->height &&
2486 window->size_hints.max_width == output->width &&
2487 window->size_hints.max_height == output->height)
2488 matching_size = 1;
2489
2490 if (matching_size && !window->decorate &&
2491 (window->size_hints.flags & (USPosition | PPosition)) &&
2492 window->size_hints.x == output->x &&
2493 window->size_hints.y == output->y) {
2494 *output_ret = output;
2495 return 1;
2496 }
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002497 }
2498
2499 return 0;
2500}
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002501
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002502static bool
2503weston_wm_window_type_inactive(struct weston_wm_window *window)
2504{
2505 struct weston_wm *wm = window->wm;
2506
2507 return window->type == wm->atom.net_wm_window_type_tooltip ||
2508 window->type == wm->atom.net_wm_window_type_dropdown ||
2509 window->type == wm->atom.net_wm_window_type_dnd ||
2510 window->type == wm->atom.net_wm_window_type_combo ||
Giulio Camuffo84787ea2015-04-29 19:00:48 +03002511 window->type == wm->atom.net_wm_window_type_popup ||
2512 window->type == wm->atom.net_wm_window_type_utility;
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002513}
2514
Kristian Høgsberga61ca062012-05-22 16:05:52 -04002515static void
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002516xserver_map_shell_surface(struct weston_wm_window *window,
2517 struct weston_surface *surface)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002518{
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002519 struct weston_wm *wm = window->wm;
Quentin Glidic955cec02016-08-12 10:41:35 +02002520 struct weston_desktop_xwayland *xwayland =
2521 wm->server->compositor->xwayland;
2522 const struct weston_desktop_xwayland_interface *xwayland_interface =
2523 wm->server->compositor->xwayland_interface;
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002524 struct weston_output *output;
Kristian Høgsberg9f7e3312014-01-02 22:40:37 -08002525 struct weston_wm_window *parent;
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002526
Kristian Høgsberg757d8af2014-03-17 22:33:29 -07002527 weston_wm_window_read_properties(window);
2528
2529 /* A weston_wm_window may have many different surfaces assigned
2530 * throughout its life, so we must make sure to remove the listener
2531 * from the old surface signal list. */
2532 if (window->surface)
2533 wl_list_remove(&window->surface_destroy_listener.link);
2534
2535 window->surface = surface;
2536 window->surface_destroy_listener.notify = surface_destroy;
2537 wl_signal_add(&window->surface->destroy_signal,
2538 &window->surface_destroy_listener);
2539
2540 weston_wm_window_schedule_repaint(window);
2541
Quentin Glidic955cec02016-08-12 10:41:35 +02002542 if (!xwayland_interface)
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002543 return;
2544
Quentin Glidic2edc3d52016-08-12 10:41:33 +02002545 if (window->surface->committed) {
Pekka Paalanen50b67472014-10-01 15:02:41 +03002546 weston_log("warning, unexpected in %s: "
2547 "surface's configure hook is already set.\n",
2548 __func__);
2549 return;
2550 }
2551
Murray Calavera883ac022015-06-06 13:02:22 +00002552 window->shsurf =
Quentin Glidic955cec02016-08-12 10:41:35 +02002553 xwayland_interface->create_surface(xwayland,
2554 window->surface,
2555 &shell_client);
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002556
Pekka Paalanena04eacc2016-11-28 16:42:25 +02002557 wm_log("XWM: map shell surface, win %d, xwayland surface %p\n",
2558 window->id, window->shsurf);
2559
Giulio Camuffo62942ad2013-09-11 18:20:47 +02002560 if (window->name)
Quentin Glidic955cec02016-08-12 10:41:35 +02002561 xwayland_interface->set_title(window->shsurf, window->name);
Giulio Camuffoa8e9b412015-01-27 19:10:37 +02002562 if (window->pid > 0)
Quentin Glidic955cec02016-08-12 10:41:35 +02002563 xwayland_interface->set_pid(window->shsurf, window->pid);
Giulio Camuffo62942ad2013-09-11 18:20:47 +02002564
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002565 if (window->fullscreen) {
2566 window->saved_width = window->width;
2567 window->saved_height = window->height;
Quentin Glidic955cec02016-08-12 10:41:35 +02002568 xwayland_interface->set_fullscreen(window->shsurf, NULL);
Kristian Høgsbergb810eb52013-02-12 20:07:05 -05002569 return;
Kristian Høgsberg59f44c12013-08-31 00:08:27 -07002570 } else if (legacy_fullscreen(wm, window, &output)) {
2571 window->fullscreen = 1;
Quentin Glidic955cec02016-08-12 10:41:35 +02002572 xwayland_interface->set_fullscreen(window->shsurf, output);
Kristian Høgsberg9f7e3312014-01-02 22:40:37 -08002573 } else if (window->override_redirect) {
Quentin Glidic955cec02016-08-12 10:41:35 +02002574 xwayland_interface->set_xwayland(window->shsurf,
2575 window->x, window->y);
Axel Davye4450f92014-01-12 15:06:05 +01002576 } else if (window->transient_for && window->transient_for->surface) {
Kristian Høgsberg9f7e3312014-01-02 22:40:37 -08002577 parent = window->transient_for;
Quentin Glidic955cec02016-08-12 10:41:35 +02002578 if (weston_wm_window_type_inactive(window)) {
2579 xwayland_interface->set_transient(window->shsurf,
2580 parent->surface,
2581 window->x - parent->x,
2582 window->y - parent->y);
2583 } else {
2584 xwayland_interface->set_toplevel(window->shsurf);
2585 xwayland_interface->set_parent(window->shsurf,
2586 parent->surface);
2587 }
Giulio Camuffo6b4b2412015-01-29 19:06:49 +02002588 } else if (weston_wm_window_is_maximized(window)) {
Quentin Glidic955cec02016-08-12 10:41:35 +02002589 xwayland_interface->set_maximized(window->shsurf);
Kristian Høgsberg9f7e3312014-01-02 22:40:37 -08002590 } else {
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002591 if (weston_wm_window_type_inactive(window)) {
Quentin Glidic955cec02016-08-12 10:41:35 +02002592 xwayland_interface->set_xwayland(window->shsurf,
2593 window->x,
2594 window->y);
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002595 } else {
Quentin Glidic955cec02016-08-12 10:41:35 +02002596 xwayland_interface->set_toplevel(window->shsurf);
Giulio Camuffo836b9c72015-01-24 17:54:21 +02002597 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002598 }
Kristian Høgsberg380deee2012-05-21 17:12:41 -04002599}
Quentin Glidic955cec02016-08-12 10:41:35 +02002600
2601const struct weston_xwayland_surface_api surface_api = {
2602 is_wm_window,
2603 send_position,
2604};