Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Intel Corporation |
| 3 | * |
Bryce Harrington | 0a007dd | 2015-06-11 16:22:34 -0700 | [diff] [blame] | 4 | * 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 11 | * |
Bryce Harrington | 0a007dd | 2015-06-11 16:22:34 -0700 | [diff] [blame] | 12 | * 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 27 | |
| 28 | #include <stdlib.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 29 | #include <stdint.h> |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 30 | #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 Vignatti | 90fada4 | 2012-07-16 12:02:08 -0400 | [diff] [blame] | 38 | #include <X11/Xcursor/Xcursor.h> |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 39 | #include <linux/input.h> |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 40 | |
| 41 | #include "xwayland.h" |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 42 | #include "xwayland-internal-interface.h" |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 43 | |
Kristian Høgsberg | 2ba10df | 2013-12-03 16:38:15 -0800 | [diff] [blame] | 44 | #include "cairo-util.h" |
| 45 | #include "compositor.h" |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 46 | #include "hash.h" |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 47 | #include "shared/helpers.h" |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 48 | |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 49 | struct wm_size_hints { |
Bryce Harrington | e00554b | 2015-06-12 10:17:39 -0700 | [diff] [blame] | 50 | uint32_t flags; |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 51 | 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 Harrington | e00554b | 2015-06-12 10:17:39 -0700 | [diff] [blame] | 55 | int32_t width_inc, height_inc; |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 56 | 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 75 | struct 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 Ryazanov | b0f5a25 | 2015-05-03 19:56:37 -0700 | [diff] [blame] | 103 | #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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 107 | #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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 128 | struct weston_wm_window { |
| 129 | struct weston_wm *wm; |
| 130 | xcb_window_t id; |
| 131 | xcb_window_t frame_id; |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 132 | struct frame *frame; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 133 | cairo_surface_t *cairo_surface; |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 134 | uint32_t surface_id; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 135 | struct weston_surface *surface; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 136 | struct weston_desktop_xwayland_surface *shsurf; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 137 | struct wl_listener surface_destroy_listener; |
| 138 | struct wl_event_source *repaint_source; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 139 | struct wl_event_source *configure_source; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 140 | int properties_dirty; |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 141 | int pid; |
| 142 | char *machine; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 143 | 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 Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 150 | bool pos_dirty; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 151 | int saved_width, saved_height; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 152 | int decorate; |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 153 | int override_redirect; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 154 | int fullscreen; |
MoD | 384a11a | 2013-06-22 11:04:21 -0500 | [diff] [blame] | 155 | int has_alpha; |
Kristian Høgsberg | 2cd6da1 | 2013-10-13 22:11:07 -0700 | [diff] [blame] | 156 | int delete_window; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 157 | int maximized_vert; |
| 158 | int maximized_horz; |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 159 | struct wm_size_hints size_hints; |
| 160 | struct motif_wm_hints motif_hints; |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 161 | struct wl_list link; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | static struct weston_wm_window * |
| 165 | get_wm_window(struct weston_surface *surface); |
| 166 | |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 167 | static void |
Benoit Gschwind | 1a42ca1 | 2015-09-25 21:26:04 +0200 | [diff] [blame] | 168 | weston_wm_set_net_active_window(struct weston_wm *wm, xcb_window_t window); |
| 169 | |
| 170 | static void |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 171 | weston_wm_window_schedule_repaint(struct weston_wm_window *window); |
| 172 | |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 173 | static void |
| 174 | xserver_map_shell_surface(struct weston_wm_window *window, |
| 175 | struct weston_surface *surface); |
| 176 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 177 | static int __attribute__ ((format (printf, 1, 2))) |
| 178 | wm_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 | |
| 194 | static int __attribute__ ((format (printf, 1, 2))) |
| 195 | wm_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 Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 211 | static bool __attribute__ ((warn_unused_result)) |
| 212 | wm_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øgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 220 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 221 | const char * |
| 222 | get_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); |
MoD | 55375b9 | 2013-06-11 19:59:42 -0500 | [diff] [blame] | 234 | |
Dawid Gajownik | 74a635b | 2015-08-06 17:12:19 -0300 | [diff] [blame] | 235 | if (reply) { |
MoD | 55375b9 | 2013-06-11 19:59:42 -0500 | [diff] [blame] | 236 | 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 243 | free(reply); |
| 244 | |
| 245 | return buffer; |
| 246 | } |
| 247 | |
Tiago Vignatti | 90fada4 | 2012-07-16 12:02:08 -0400 | [diff] [blame] | 248 | static xcb_cursor_t |
| 249 | xcb_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 | |
| 283 | static xcb_cursor_t |
| 284 | xcb_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 | |
| 293 | static xcb_cursor_t |
| 294 | xcb_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 Vignatti | ac78bb1 | 2012-09-28 16:29:46 +0300 | [diff] [blame] | 312 | if (!images) |
| 313 | return -1; |
| 314 | |
Tiago Vignatti | 90fada4 | 2012-07-16 12:02:08 -0400 | [diff] [blame] | 315 | cursor = xcb_cursor_images_load_cursor (wm, images); |
| 316 | XcursorImagesDestroy (images); |
| 317 | |
| 318 | return cursor; |
| 319 | } |
| 320 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 321 | void |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 322 | dump_property(struct weston_wm *wm, |
| 323 | xcb_atom_t property, xcb_get_property_reply_t *reply) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 324 | { |
| 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øgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 331 | width = wm_log_continue("%s: ", get_atom_name(wm->conn, property)); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 332 | if (reply == NULL) { |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 333 | wm_log_continue("(no reply)\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 334 | return; |
| 335 | } |
| 336 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 337 | 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 342 | |
| 343 | if (reply->type == wm->atom.incr) { |
| 344 | incr_value = xcb_get_property_value(reply); |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 345 | wm_log_continue("%d\n", *incr_value); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 346 | } 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øgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 353 | wm_log_continue("\"%.*s\"\n", len, text_value); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 354 | } 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øgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 359 | wm_log_continue("\n "); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 360 | width = 4; |
| 361 | } else if (i > 0) { |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 362 | width += wm_log_continue(", "); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 363 | } |
| 364 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 365 | width += wm_log_continue("%s", name); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 366 | } |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 367 | wm_log_continue("\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 368 | } else { |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 369 | wm_log_continue("huh?\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
Tiago Vignatti | 2d129f1 | 2012-11-30 17:19:59 -0200 | [diff] [blame] | 373 | static void |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 374 | read_and_dump_property(struct weston_wm *wm, |
| 375 | xcb_window_t window, xcb_atom_t property) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 376 | { |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 377 | xcb_get_property_reply_t *reply; |
| 378 | xcb_get_property_cookie_t cookie; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 379 | |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 380 | 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 383 | |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 384 | dump_property(wm, property, reply); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 385 | |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 386 | free(reply); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 387 | } |
| 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øgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 392 | #define TYPE_NET_WM_STATE XCB_ATOM_CUT_BUFFER2 |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 393 | #define TYPE_WM_NORMAL_HINTS XCB_ATOM_CUT_BUFFER3 |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 394 | |
| 395 | static void |
| 396 | weston_wm_window_read_properties(struct weston_wm_window *window) |
| 397 | { |
| 398 | struct weston_wm *wm = window->wm; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 399 | const struct weston_desktop_xwayland_interface *xwayland_interface = |
| 400 | wm->server->compositor->xwayland_interface; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 401 | |
| 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øgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 412 | { wm->atom.wm_normal_hints, TYPE_WM_NORMAL_HINTS, F(protocols) }, |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 413 | { wm->atom.net_wm_state, TYPE_NET_WM_STATE }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 414 | { wm->atom.net_wm_window_type, XCB_ATOM_ATOM, F(type) }, |
| 415 | { wm->atom.net_wm_name, XCB_ATOM_STRING, F(name) }, |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 416 | { wm->atom.net_wm_pid, XCB_ATOM_CARDINAL, F(pid) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 417 | { wm->atom.motif_wm_hints, TYPE_MOTIF_WM_HINTS, 0 }, |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 418 | { wm->atom.wm_client_machine, XCB_ATOM_WM_CLIENT_MACHINE, F(machine) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 419 | }; |
| 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 Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 428 | char name[1024]; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 429 | |
| 430 | if (!window->properties_dirty) |
| 431 | return; |
| 432 | window->properties_dirty = 0; |
| 433 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 434 | 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 Ryazanov | b0f5a25 | 2015-05-03 19:56:37 -0700 | [diff] [blame] | 441 | window->decorate = window->override_redirect ? 0 : MWM_DECOR_EVERYTHING; |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 442 | window->size_hints.flags = 0; |
| 443 | window->motif_hints.flags = 0; |
Kristian Høgsberg | 2cd6da1 | 2013-10-13 22:11:07 -0700 | [diff] [blame] | 444 | window->delete_window = 0; |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 445 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 446 | 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 Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 460 | case XCB_ATOM_WM_CLIENT_MACHINE: |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 461 | 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 Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 473 | 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 476 | break; |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 477 | case XCB_ATOM_CARDINAL: |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 478 | 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øgsberg | 2cd6da1 | 2013-10-13 22:11:07 -0700 | [diff] [blame] | 483 | atom = xcb_get_property_value(reply); |
| 484 | for (i = 0; i < reply->value_len; i++) |
Derek Foreman | b4deec6 | 2015-04-07 12:12:13 -0500 | [diff] [blame] | 485 | if (atom[i] == wm->atom.wm_delete_window) { |
Kristian Høgsberg | 2cd6da1 | 2013-10-13 22:11:07 -0700 | [diff] [blame] | 486 | window->delete_window = 1; |
Derek Foreman | b4deec6 | 2015-04-07 12:12:13 -0500 | [diff] [blame] | 487 | break; |
| 488 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 489 | break; |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 490 | 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øgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 495 | case TYPE_NET_WM_STATE: |
| 496 | window->fullscreen = 0; |
| 497 | atom = xcb_get_property_value(reply); |
Ryo Munakata | f3744f5 | 2015-03-11 17:36:30 +0900 | [diff] [blame] | 498 | for (i = 0; i < reply->value_len; i++) { |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 499 | if (atom[i] == wm->atom.net_wm_state_fullscreen) |
| 500 | window->fullscreen = 1; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 501 | 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 Munakata | f3744f5 | 2015-03-11 17:36:30 +0900 | [diff] [blame] | 505 | } |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 506 | break; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 507 | case TYPE_MOTIF_WM_HINTS: |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 508 | memcpy(&window->motif_hints, |
| 509 | xcb_get_property_value(reply), |
| 510 | sizeof window->motif_hints); |
Dima Ryazanov | b0f5a25 | 2015-05-03 19:56:37 -0700 | [diff] [blame] | 511 | 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 520 | break; |
| 521 | default: |
| 522 | break; |
| 523 | } |
| 524 | free(reply); |
| 525 | } |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 526 | |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 527 | 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 Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 543 | if (window->shsurf && window->name) |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 544 | xwayland_interface->set_title(window->shsurf, window->name); |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 545 | if (window->frame && window->name) |
| 546 | frame_set_title(window->frame, window->name); |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 547 | if (window->shsurf && window->pid > 0) |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 548 | xwayland_interface->set_pid(window->shsurf, window->pid); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 552 | weston_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øgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 557 | if (window->fullscreen) { |
| 558 | *width = window->width; |
| 559 | *height = window->height; |
Dima Ryazanov | cae1f0f | 2013-11-15 02:02:23 -0800 | [diff] [blame] | 560 | } else if (window->decorate && window->frame) { |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 561 | *width = frame_width(window->frame); |
| 562 | *height = frame_height(window->frame); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 563 | } else { |
| 564 | *width = window->width + t->margin * 2; |
| 565 | *height = window->height + t->margin * 2; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | static void |
| 570 | weston_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øgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 575 | if (window->fullscreen) { |
| 576 | *x = 0; |
| 577 | *y = 0; |
Dima Ryazanov | cae1f0f | 2013-11-15 02:02:23 -0800 | [diff] [blame] | 578 | } else if (window->decorate && window->frame) { |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 579 | frame_interior(window->frame, x, y, NULL, NULL); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 580 | } else { |
| 581 | *x = t->margin; |
| 582 | *y = t->margin; |
| 583 | } |
| 584 | } |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 585 | |
| 586 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 587 | weston_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 Calavera | 883ac02 | 2015-06-06 13:02:22 +0000 | [diff] [blame] | 607 | xcb_send_event(wm->conn, 0, window->id, |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 608 | XCB_EVENT_MASK_STRUCTURE_NOTIFY, |
| 609 | (char *) &configure_notify); |
| 610 | } |
| 611 | |
| 612 | static void |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 613 | weston_wm_handle_configure_request(struct weston_wm *wm, xcb_generic_event_t *event) |
| 614 | { |
Murray Calavera | 883ac02 | 2015-06-06 13:02:22 +0000 | [diff] [blame] | 615 | xcb_configure_request_event_t *configure_request = |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 616 | (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øgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 621 | 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øgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 625 | |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 626 | if (!wm_lookup_window(wm, configure_request->window, &window)) |
| 627 | return; |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 628 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 629 | if (window->fullscreen) { |
| 630 | weston_wm_window_send_configure_notify(window); |
| 631 | return; |
| 632 | } |
| 633 | |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 634 | 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 Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 639 | if (window->frame) |
| 640 | frame_resize_inside(window->frame, window->width, window->height); |
| 641 | |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 642 | 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øgsberg | 00db2ee | 2013-07-04 02:29:32 -0400 | [diff] [blame] | 671 | static int |
| 672 | our_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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 681 | static void |
| 682 | weston_wm_handle_configure_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 683 | { |
Murray Calavera | 883ac02 | 2015-06-06 13:02:22 +0000 | [diff] [blame] | 684 | xcb_configure_notify_event_t *configure_notify = |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 685 | (xcb_configure_notify_event_t *) event; |
| 686 | struct weston_wm_window *window; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 687 | |
Kristian Høgsberg | 00db2ee | 2013-07-04 02:29:32 -0400 | [diff] [blame] | 688 | wm_log("XCB_CONFIGURE_NOTIFY (window %d) %d,%d @ %dx%d\n", |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 689 | configure_notify->window, |
| 690 | configure_notify->x, configure_notify->y, |
| 691 | configure_notify->width, configure_notify->height); |
Tiago Vignatti | e66fcee | 2012-07-20 23:09:54 +0300 | [diff] [blame] | 692 | |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 693 | if (!wm_lookup_window(wm, configure_notify->window, &window)) |
| 694 | return; |
| 695 | |
Kristian Høgsberg | 122877d | 2013-08-22 16:18:17 -0700 | [diff] [blame] | 696 | window->x = configure_notify->x; |
| 697 | window->y = configure_notify->y; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 698 | window->pos_dirty = false; |
| 699 | |
Kristian Høgsberg | 1b6fed4 | 2013-08-31 00:00:57 -0700 | [diff] [blame] | 700 | if (window->override_redirect) { |
| 701 | window->width = configure_notify->width; |
| 702 | window->height = configure_notify->height; |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 703 | if (window->frame) |
| 704 | frame_resize_inside(window->frame, |
| 705 | window->width, window->height); |
Kristian Høgsberg | 1b6fed4 | 2013-08-31 00:00:57 -0700 | [diff] [blame] | 706 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | static void |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 710 | weston_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 Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 714 | if (!window) |
| 715 | return; |
| 716 | |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 717 | if (window->pid > 0) |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 718 | kill(window->pid, SIGKILL); |
| 719 | } |
| 720 | |
| 721 | static void |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 722 | weston_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øgsberg | ba83db2 | 2014-04-07 10:16:19 -0700 | [diff] [blame] | 737 | window->surface_id = 0; |
| 738 | wl_list_remove(&window->link); |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 739 | break; |
Murray Calavera | 883ac02 | 2015-06-06 13:02:22 +0000 | [diff] [blame] | 740 | } |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | static void |
Giulio Camuffo | b18f788 | 2015-03-29 14:20:23 +0300 | [diff] [blame] | 744 | weston_wm_send_focus_window(struct weston_wm *wm, |
| 745 | struct weston_wm_window *window) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 746 | { |
Scott Moreau | 85ecac0 | 2012-05-21 15:49:14 -0600 | [diff] [blame] | 747 | xcb_client_message_event_t client_message; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 748 | |
Scott Moreau | 85ecac0 | 2012-05-21 15:49:14 -0600 | [diff] [blame] | 749 | if (window) { |
Jasper St. Pierre | f30af4e | 2015-03-22 10:14:49 -0700 | [diff] [blame] | 750 | uint32_t values[1]; |
| 751 | |
Boyan Ding | b9f863c | 2014-08-30 10:33:23 +0800 | [diff] [blame] | 752 | if (window->override_redirect) |
| 753 | return; |
| 754 | |
Scott Moreau | 85ecac0 | 2012-05-21 15:49:14 -0600 | [diff] [blame] | 755 | 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 Calavera | 883ac02 | 2015-06-06 13:02:22 +0000 | [diff] [blame] | 762 | xcb_send_event(wm->conn, 0, window->id, |
Scott Moreau | 85ecac0 | 2012-05-21 15:49:14 -0600 | [diff] [blame] | 763 | 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. Pierre | f30af4e | 2015-03-22 10:14:49 -0700 | [diff] [blame] | 768 | |
| 769 | values[0] = XCB_STACK_MODE_ABOVE; |
| 770 | xcb_configure_window (wm->conn, window->frame_id, |
| 771 | XCB_CONFIG_WINDOW_STACK_MODE, values); |
Scott Moreau | 85ecac0 | 2012-05-21 15:49:14 -0600 | [diff] [blame] | 772 | } else { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 773 | xcb_set_input_focus (wm->conn, |
| 774 | XCB_INPUT_FOCUS_POINTER_ROOT, |
| 775 | XCB_NONE, |
| 776 | XCB_TIME_CURRENT_TIME); |
Scott Moreau | 85ecac0 | 2012-05-21 15:49:14 -0600 | [diff] [blame] | 777 | } |
Giulio Camuffo | b18f788 | 2015-03-29 14:20:23 +0300 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static void |
| 781 | weston_wm_window_activate(struct wl_listener *listener, void *data) |
| 782 | { |
Jonas Ådahl | f7deb6a | 2016-07-22 17:50:26 +0800 | [diff] [blame] | 783 | struct weston_surface_activation_data *activation_data = data; |
| 784 | struct weston_surface *surface = activation_data->surface; |
Giulio Camuffo | b18f788 | 2015-03-29 14:20:23 +0300 | [diff] [blame] | 785 | 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 Gschwind | 1a42ca1 | 2015-09-25 21:26:04 +0200 | [diff] [blame] | 793 | 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 Camuffo | b18f788 | 2015-03-29 14:20:23 +0300 | [diff] [blame] | 799 | weston_wm_send_focus_window(wm, window); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 800 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 801 | if (wm->focus_window) { |
Dima Ryazanov | b03b87f | 2013-11-15 02:01:19 -0800 | [diff] [blame] | 802 | if (wm->focus_window->frame) |
| 803 | frame_unset_flag(wm->focus_window->frame, FRAME_FLAG_ACTIVE); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 804 | weston_wm_window_schedule_repaint(wm->focus_window); |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 805 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 806 | wm->focus_window = window; |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 807 | if (wm->focus_window) { |
Dima Ryazanov | b03b87f | 2013-11-15 02:01:19 -0800 | [diff] [blame] | 808 | if (wm->focus_window->frame) |
| 809 | frame_set_flag(wm->focus_window->frame, FRAME_FLAG_ACTIVE); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 810 | weston_wm_window_schedule_repaint(wm->focus_window); |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 811 | } |
Benoit Gschwind | 1a42ca1 | 2015-09-25 21:26:04 +0200 | [diff] [blame] | 812 | |
| 813 | xcb_flush(wm->conn); |
| 814 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 815 | } |
| 816 | |
Kristian Høgsberg | a6d9a5e | 2012-05-30 12:15:44 -0400 | [diff] [blame] | 817 | #define ICCCM_WITHDRAWN_STATE 0 |
| 818 | #define ICCCM_NORMAL_STATE 1 |
| 819 | #define ICCCM_ICONIC_STATE 3 |
| 820 | |
| 821 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 822 | weston_wm_window_set_wm_state(struct weston_wm_window *window, int32_t state) |
Kristian Høgsberg | a6d9a5e | 2012-05-30 12:15:44 -0400 | [diff] [blame] | 823 | { |
| 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 839 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 840 | weston_wm_window_set_net_wm_state(struct weston_wm_window *window) |
| 841 | { |
| 842 | struct weston_wm *wm = window->wm; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 843 | uint32_t property[3]; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 844 | int i; |
| 845 | |
| 846 | i = 0; |
| 847 | if (window->fullscreen) |
| 848 | property[i++] = wm->atom.net_wm_state_fullscreen; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 849 | 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øgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 853 | |
| 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 | |
| 863 | static void |
Kristian Høgsberg | 318ea37 | 2013-09-03 16:19:18 -0700 | [diff] [blame] | 864 | weston_wm_window_create_frame(struct weston_wm_window *window) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 865 | { |
Kristian Høgsberg | 318ea37 | 2013-09-03 16:19:18 -0700 | [diff] [blame] | 866 | struct weston_wm *wm = window->wm; |
Kristian Høgsberg | f918719 | 2013-05-02 13:43:24 -0400 | [diff] [blame] | 867 | uint32_t values[3]; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 868 | int x, y, width, height; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 869 | int buttons = FRAME_BUTTON_CLOSE; |
| 870 | |
| 871 | if (window->decorate & MWM_DECOR_MAXIMIZE) |
| 872 | buttons |= FRAME_BUTTON_MAXIMIZE; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 873 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 874 | window->frame = frame_create(window->wm->theme, |
| 875 | window->width, window->height, |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 876 | buttons, window->name); |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 877 | frame_resize_inside(window->frame, window->width, window->height); |
| 878 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 879 | weston_wm_window_get_frame_size(window, &width, &height); |
| 880 | weston_wm_window_get_child_position(window, &x, &y); |
| 881 | |
Kristian Høgsberg | f918719 | 2013-05-02 13:43:24 -0400 | [diff] [blame] | 882 | values[0] = wm->screen->black_pixel; |
| 883 | values[1] = |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 884 | XCB_EVENT_MASK_KEY_PRESS | |
| 885 | XCB_EVENT_MASK_KEY_RELEASE | |
| 886 | XCB_EVENT_MASK_BUTTON_PRESS | |
| 887 | XCB_EVENT_MASK_BUTTON_RELEASE | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 888 | XCB_EVENT_MASK_POINTER_MOTION | |
| 889 | XCB_EVENT_MASK_ENTER_WINDOW | |
| 890 | XCB_EVENT_MASK_LEAVE_WINDOW | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 891 | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | |
Kristian Høgsberg | 44c2013 | 2012-05-30 10:09:21 -0400 | [diff] [blame] | 892 | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT; |
Kristian Høgsberg | f918719 | 2013-05-02 13:43:24 -0400 | [diff] [blame] | 893 | values[2] = wm->colormap; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 894 | |
| 895 | window->frame_id = xcb_generate_id(wm->conn); |
| 896 | xcb_create_window(wm->conn, |
Kristian Høgsberg | f918719 | 2013-05-02 13:43:24 -0400 | [diff] [blame] | 897 | 32, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 898 | window->frame_id, |
| 899 | wm->screen->root, |
| 900 | 0, 0, |
| 901 | width, height, |
| 902 | 0, |
| 903 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
Kristian Høgsberg | f918719 | 2013-05-02 13:43:24 -0400 | [diff] [blame] | 904 | wm->visual_id, |
| 905 | XCB_CW_BORDER_PIXEL | |
| 906 | XCB_CW_EVENT_MASK | |
| 907 | XCB_CW_COLORMAP, values); |
| 908 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 909 | 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 915 | window->cairo_surface = |
| 916 | cairo_xcb_surface_create_with_xrender_format(wm->conn, |
| 917 | wm->screen, |
| 918 | window->frame_id, |
Kristian Høgsberg | f918719 | 2013-05-02 13:43:24 -0400 | [diff] [blame] | 919 | &wm->format_rgba, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 920 | width, height); |
| 921 | |
| 922 | hash_table_insert(wm->window_hash, window->frame_id, window); |
| 923 | } |
| 924 | |
Giulio Camuffo | e90ea44 | 2014-12-13 18:06:34 +0200 | [diff] [blame] | 925 | /* |
| 926 | * Sets the _NET_WM_DESKTOP property for the window to 'desktop'. |
| 927 | * Passing a <0 desktop value deletes the property. |
| 928 | */ |
| 929 | static void |
| 930 | weston_wm_window_set_virtual_desktop(struct weston_wm_window *window, |
Bryce Harrington | e00554b | 2015-06-12 10:17:39 -0700 | [diff] [blame] | 931 | int desktop) |
Giulio Camuffo | e90ea44 | 2014-12-13 18:06:34 +0200 | [diff] [blame] | 932 | { |
| 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øgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 948 | static void |
Kristian Høgsberg | 318ea37 | 2013-09-03 16:19:18 -0700 | [diff] [blame] | 949 | weston_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 Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 961 | if (!wm_lookup_window(wm, map_request->window, &window)) |
| 962 | return; |
Kristian Høgsberg | 318ea37 | 2013-09-03 16:19:18 -0700 | [diff] [blame] | 963 | |
| 964 | weston_wm_window_read_properties(window); |
| 965 | |
| 966 | if (window->frame_id == XCB_WINDOW_NONE) |
| 967 | weston_wm_window_create_frame(window); |
| 968 | |
| 969 | wm_log("XCB_MAP_REQUEST (window %d, %p, frame %d)\n", |
| 970 | window->id, window, window->frame_id); |
| 971 | |
| 972 | weston_wm_window_set_wm_state(window, ICCCM_NORMAL_STATE); |
| 973 | weston_wm_window_set_net_wm_state(window); |
Giulio Camuffo | e90ea44 | 2014-12-13 18:06:34 +0200 | [diff] [blame] | 974 | weston_wm_window_set_virtual_desktop(window, 0); |
Kristian Høgsberg | 318ea37 | 2013-09-03 16:19:18 -0700 | [diff] [blame] | 975 | |
| 976 | xcb_map_window(wm->conn, map_request->window); |
| 977 | xcb_map_window(wm->conn, window->frame_id); |
| 978 | } |
| 979 | |
| 980 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 981 | weston_wm_handle_map_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 982 | { |
| 983 | xcb_map_notify_event_t *map_notify = (xcb_map_notify_event_t *) event; |
| 984 | |
| 985 | if (our_resource(wm, map_notify->window)) { |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 986 | wm_log("XCB_MAP_NOTIFY (window %d, ours)\n", |
| 987 | map_notify->window); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 988 | return; |
| 989 | } |
| 990 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 991 | wm_log("XCB_MAP_NOTIFY (window %d)\n", map_notify->window); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | static void |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 995 | weston_wm_handle_unmap_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 996 | { |
| 997 | xcb_unmap_notify_event_t *unmap_notify = |
| 998 | (xcb_unmap_notify_event_t *) event; |
| 999 | struct weston_wm_window *window; |
| 1000 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1001 | wm_log("XCB_UNMAP_NOTIFY (window %d, event %d%s)\n", |
| 1002 | unmap_notify->window, |
| 1003 | unmap_notify->event, |
| 1004 | our_resource(wm, unmap_notify->window) ? ", ours" : ""); |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 1005 | |
| 1006 | if (our_resource(wm, unmap_notify->window)) |
| 1007 | return; |
| 1008 | |
MoD | 3170012 | 2013-06-11 19:58:55 -0500 | [diff] [blame] | 1009 | if (unmap_notify->response_type & SEND_EVENT_MASK) |
Kristian Høgsberg | d64bdf4 | 2012-05-31 10:33:43 -0400 | [diff] [blame] | 1010 | /* We just ignore the ICCCM 4.1.4 synthetic unmap notify |
| 1011 | * as it may come in after we've destroyed the window. */ |
Kristian Høgsberg | f197e9f | 2012-05-30 11:46:29 -0400 | [diff] [blame] | 1012 | return; |
Kristian Høgsberg | f197e9f | 2012-05-30 11:46:29 -0400 | [diff] [blame] | 1013 | |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 1014 | if (!wm_lookup_window(wm, unmap_notify->window, &window)) |
| 1015 | return; |
| 1016 | |
Derek Foreman | 9a0b2b5 | 2015-04-09 14:48:22 -0500 | [diff] [blame] | 1017 | if (window->surface_id) { |
| 1018 | /* Make sure we're not on the unpaired surface list or we |
| 1019 | * could be assigned a surface during surface creation that |
| 1020 | * was mapped before this unmap request. |
| 1021 | */ |
| 1022 | wl_list_remove(&window->link); |
| 1023 | window->surface_id = 0; |
| 1024 | } |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 1025 | if (wm->focus_window == window) |
| 1026 | wm->focus_window = NULL; |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 1027 | if (window->surface) |
| 1028 | wl_list_remove(&window->surface_destroy_listener.link); |
| 1029 | window->surface = NULL; |
Giulio Camuffo | 85739ea | 2013-09-17 16:43:45 +0200 | [diff] [blame] | 1030 | window->shsurf = NULL; |
Giulio Camuffo | e90ea44 | 2014-12-13 18:06:34 +0200 | [diff] [blame] | 1031 | |
| 1032 | weston_wm_window_set_wm_state(window, ICCCM_WITHDRAWN_STATE); |
| 1033 | weston_wm_window_set_virtual_desktop(window, -1); |
| 1034 | |
Kristian Høgsberg | ab6d667 | 2013-09-03 16:38:51 -0700 | [diff] [blame] | 1035 | xcb_unmap_window(wm->conn, window->frame_id); |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1039 | weston_wm_window_draw_decoration(void *data) |
| 1040 | { |
| 1041 | struct weston_wm_window *window = data; |
| 1042 | struct weston_wm *wm = window->wm; |
| 1043 | struct theme *t = wm->theme; |
| 1044 | cairo_t *cr; |
| 1045 | int x, y, width, height; |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1046 | int32_t input_x, input_y, input_w, input_h; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1047 | const struct weston_desktop_xwayland_interface *xwayland_interface = |
| 1048 | wm->server->compositor->xwayland_interface; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1049 | uint32_t flags = 0; |
Giulio Camuffo | aa97478 | 2015-02-01 16:18:51 +0200 | [diff] [blame] | 1050 | struct weston_view *view; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1051 | |
| 1052 | weston_wm_window_read_properties(window); |
| 1053 | |
| 1054 | window->repaint_source = NULL; |
| 1055 | |
| 1056 | weston_wm_window_get_frame_size(window, &width, &height); |
| 1057 | weston_wm_window_get_child_position(window, &x, &y); |
| 1058 | |
| 1059 | cairo_xcb_surface_set_size(window->cairo_surface, width, height); |
| 1060 | cr = cairo_create(window->cairo_surface); |
| 1061 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1062 | if (window->fullscreen) { |
| 1063 | /* nothing */ |
| 1064 | } else if (window->decorate) { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1065 | if (wm->focus_window == window) |
| 1066 | flags |= THEME_FRAME_ACTIVE; |
| 1067 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1068 | frame_repaint(window->frame, cr); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1069 | } else { |
| 1070 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 1071 | cairo_set_source_rgba(cr, 0, 0, 0, 0); |
| 1072 | cairo_paint(cr); |
| 1073 | |
Marek Chalupa | 0d7fe8d | 2014-10-29 14:51:22 +0100 | [diff] [blame] | 1074 | render_shadow(cr, t->shadow, 2, 2, width + 8, height + 8, 64, 64); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | cairo_destroy(cr); |
| 1078 | |
| 1079 | if (window->surface) { |
Scott Moreau | 76d8fc8 | 2012-11-22 15:35:13 -0700 | [diff] [blame] | 1080 | pixman_region32_fini(&window->surface->pending.opaque); |
Dawid Gajownik | 74a635b | 2015-08-06 17:12:19 -0300 | [diff] [blame] | 1081 | if (window->has_alpha) { |
MoD | 384a11a | 2013-06-22 11:04:21 -0500 | [diff] [blame] | 1082 | pixman_region32_init(&window->surface->pending.opaque); |
| 1083 | } else { |
| 1084 | /* We leave an extra pixel around the X window area to |
| 1085 | * make sure we don't sample from the undefined alpha |
| 1086 | * channel when filtering. */ |
Murray Calavera | 883ac02 | 2015-06-06 13:02:22 +0000 | [diff] [blame] | 1087 | pixman_region32_init_rect(&window->surface->pending.opaque, |
MoD | 384a11a | 2013-06-22 11:04:21 -0500 | [diff] [blame] | 1088 | x - 1, y - 1, |
| 1089 | window->width + 2, |
| 1090 | window->height + 2); |
| 1091 | } |
Giulio Camuffo | aa97478 | 2015-02-01 16:18:51 +0200 | [diff] [blame] | 1092 | wl_list_for_each(view, &window->surface->views, surface_link) |
| 1093 | weston_view_geometry_dirty(view); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1094 | |
Kristian Høgsberg | 81585e9 | 2013-02-14 22:01:58 -0500 | [diff] [blame] | 1095 | pixman_region32_fini(&window->surface->pending.input); |
Kristian Høgsberg | 1d75c7d | 2013-10-30 23:46:08 -0700 | [diff] [blame] | 1096 | |
Jasper St. Pierre | d19e9b0 | 2015-03-21 21:24:43 -0700 | [diff] [blame] | 1097 | if (window->decorate && !window->fullscreen) { |
Kristian Høgsberg | 1d75c7d | 2013-10-30 23:46:08 -0700 | [diff] [blame] | 1098 | frame_input_rect(window->frame, &input_x, &input_y, |
| 1099 | &input_w, &input_h); |
Jasper St. Pierre | d19e9b0 | 2015-03-21 21:24:43 -0700 | [diff] [blame] | 1100 | } else { |
| 1101 | input_x = x; |
| 1102 | input_y = y; |
| 1103 | input_w = width; |
| 1104 | input_h = height; |
Kristian Høgsberg | 1d75c7d | 2013-10-30 23:46:08 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
Kristian Høgsberg | d8b617d | 2013-02-14 21:56:32 -0500 | [diff] [blame] | 1107 | pixman_region32_init_rect(&window->surface->pending.input, |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1108 | input_x, input_y, input_w, input_h); |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1109 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1110 | xwayland_interface->set_window_geometry(window->shsurf, |
| 1111 | input_x, input_y, input_w, input_h); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | static void |
| 1116 | weston_wm_window_schedule_repaint(struct weston_wm_window *window) |
| 1117 | { |
| 1118 | struct weston_wm *wm = window->wm; |
Giulio Camuffo | aa97478 | 2015-02-01 16:18:51 +0200 | [diff] [blame] | 1119 | struct weston_view *view; |
Pekka Paalanen | 4f9c07b | 2012-09-03 16:48:41 +0300 | [diff] [blame] | 1120 | int width, height; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1121 | |
Kristian Høgsberg | c4063f3 | 2012-07-22 15:32:45 -0400 | [diff] [blame] | 1122 | if (window->frame_id == XCB_WINDOW_NONE) { |
| 1123 | if (window->surface != NULL) { |
Pekka Paalanen | 4f9c07b | 2012-09-03 16:48:41 +0300 | [diff] [blame] | 1124 | weston_wm_window_get_frame_size(window, &width, &height); |
Scott Moreau | 76d8fc8 | 2012-11-22 15:35:13 -0700 | [diff] [blame] | 1125 | pixman_region32_fini(&window->surface->pending.opaque); |
Dawid Gajownik | 74a635b | 2015-08-06 17:12:19 -0300 | [diff] [blame] | 1126 | if (window->has_alpha) { |
MoD | 384a11a | 2013-06-22 11:04:21 -0500 | [diff] [blame] | 1127 | pixman_region32_init(&window->surface->pending.opaque); |
| 1128 | } else { |
| 1129 | pixman_region32_init_rect(&window->surface->pending.opaque, 0, 0, |
| 1130 | width, height); |
| 1131 | } |
Giulio Camuffo | aa97478 | 2015-02-01 16:18:51 +0200 | [diff] [blame] | 1132 | wl_list_for_each(view, &window->surface->views, surface_link) |
| 1133 | weston_view_geometry_dirty(view); |
Kristian Høgsberg | c4063f3 | 2012-07-22 15:32:45 -0400 | [diff] [blame] | 1134 | } |
| 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | if (window->repaint_source) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1139 | return; |
| 1140 | |
| 1141 | window->repaint_source = |
| 1142 | wl_event_loop_add_idle(wm->server->loop, |
| 1143 | weston_wm_window_draw_decoration, |
| 1144 | window); |
| 1145 | } |
| 1146 | |
| 1147 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1148 | weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1149 | { |
| 1150 | xcb_property_notify_event_t *property_notify = |
| 1151 | (xcb_property_notify_event_t *) event; |
| 1152 | struct weston_wm_window *window; |
| 1153 | |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 1154 | if (!wm_lookup_window(wm, property_notify->window, &window)) |
Rob Bradford | aa521bd | 2013-01-10 19:48:57 +0000 | [diff] [blame] | 1155 | return; |
| 1156 | |
| 1157 | window->properties_dirty = 1; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1158 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1159 | wm_log("XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window); |
Kristian Høgsberg | e244cb0 | 2012-05-30 11:34:35 -0400 | [diff] [blame] | 1160 | if (property_notify->state == XCB_PROPERTY_DELETE) |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1161 | wm_log("deleted\n"); |
Kristian Høgsberg | e244cb0 | 2012-05-30 11:34:35 -0400 | [diff] [blame] | 1162 | else |
| 1163 | read_and_dump_property(wm, property_notify->window, |
| 1164 | property_notify->atom); |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 1165 | |
| 1166 | if (property_notify->atom == wm->atom.net_wm_name || |
| 1167 | property_notify->atom == XCB_ATOM_WM_NAME) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1168 | weston_wm_window_schedule_repaint(window); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | static void |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1172 | weston_wm_window_create(struct weston_wm *wm, |
Giulio Camuffo | ca43f09 | 2013-09-11 17:49:13 +0200 | [diff] [blame] | 1173 | xcb_window_t id, int width, int height, int x, int y, int override) |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1174 | { |
| 1175 | struct weston_wm_window *window; |
| 1176 | uint32_t values[1]; |
MoD | 384a11a | 2013-06-22 11:04:21 -0500 | [diff] [blame] | 1177 | xcb_get_geometry_cookie_t geometry_cookie; |
| 1178 | xcb_get_geometry_reply_t *geometry_reply; |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1179 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 1180 | window = zalloc(sizeof *window); |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1181 | if (window == NULL) { |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1182 | wm_log("failed to allocate window\n"); |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1183 | return; |
| 1184 | } |
| 1185 | |
MoD | 384a11a | 2013-06-22 11:04:21 -0500 | [diff] [blame] | 1186 | geometry_cookie = xcb_get_geometry(wm->conn, id); |
| 1187 | |
Giulio Camuffo | b18f788 | 2015-03-29 14:20:23 +0300 | [diff] [blame] | 1188 | values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE | |
| 1189 | XCB_EVENT_MASK_FOCUS_CHANGE; |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1190 | xcb_change_window_attributes(wm->conn, id, XCB_CW_EVENT_MASK, values); |
| 1191 | |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1192 | window->wm = wm; |
| 1193 | window->id = id; |
| 1194 | window->properties_dirty = 1; |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 1195 | window->override_redirect = override; |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1196 | window->width = width; |
| 1197 | window->height = height; |
Giulio Camuffo | ca43f09 | 2013-09-11 17:49:13 +0200 | [diff] [blame] | 1198 | window->x = x; |
| 1199 | window->y = y; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 1200 | window->pos_dirty = false; |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1201 | |
MoD | 384a11a | 2013-06-22 11:04:21 -0500 | [diff] [blame] | 1202 | geometry_reply = xcb_get_geometry_reply(wm->conn, geometry_cookie, NULL); |
| 1203 | /* technically we should use XRender and check the visual format's |
| 1204 | alpha_mask, but checking depth is simpler and works in all known cases */ |
Dawid Gajownik | 74a635b | 2015-08-06 17:12:19 -0300 | [diff] [blame] | 1205 | if (geometry_reply != NULL) |
MoD | 384a11a | 2013-06-22 11:04:21 -0500 | [diff] [blame] | 1206 | window->has_alpha = geometry_reply->depth == 32; |
| 1207 | free(geometry_reply); |
| 1208 | |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1209 | hash_table_insert(wm->window_hash, id, window); |
| 1210 | } |
| 1211 | |
| 1212 | static void |
| 1213 | weston_wm_window_destroy(struct weston_wm_window *window) |
| 1214 | { |
Kristian Høgsberg | ab6d667 | 2013-09-03 16:38:51 -0700 | [diff] [blame] | 1215 | struct weston_wm *wm = window->wm; |
| 1216 | |
| 1217 | if (window->repaint_source) |
| 1218 | wl_event_source_remove(window->repaint_source); |
| 1219 | if (window->cairo_surface) |
| 1220 | cairo_surface_destroy(window->cairo_surface); |
| 1221 | |
| 1222 | if (window->frame_id) { |
| 1223 | xcb_reparent_window(wm->conn, window->id, wm->wm_window, 0, 0); |
| 1224 | xcb_destroy_window(wm->conn, window->frame_id); |
| 1225 | weston_wm_window_set_wm_state(window, ICCCM_WITHDRAWN_STATE); |
Giulio Camuffo | e90ea44 | 2014-12-13 18:06:34 +0200 | [diff] [blame] | 1226 | weston_wm_window_set_virtual_desktop(window, -1); |
Kristian Høgsberg | ab6d667 | 2013-09-03 16:38:51 -0700 | [diff] [blame] | 1227 | hash_table_remove(wm->window_hash, window->frame_id); |
| 1228 | window->frame_id = XCB_WINDOW_NONE; |
| 1229 | } |
| 1230 | |
Kristian Høgsberg | ba83db2 | 2014-04-07 10:16:19 -0700 | [diff] [blame] | 1231 | if (window->surface_id) |
| 1232 | wl_list_remove(&window->link); |
| 1233 | |
Derek Foreman | 9a0b2b5 | 2015-04-09 14:48:22 -0500 | [diff] [blame] | 1234 | if (window->surface) |
| 1235 | wl_list_remove(&window->surface_destroy_listener.link); |
| 1236 | |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1237 | hash_table_remove(window->wm->window_hash, window->id); |
| 1238 | free(window); |
| 1239 | } |
| 1240 | |
| 1241 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1242 | weston_wm_handle_create_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1243 | { |
| 1244 | xcb_create_notify_event_t *create_notify = |
| 1245 | (xcb_create_notify_event_t *) event; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1246 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1247 | wm_log("XCB_CREATE_NOTIFY (window %d, width %d, height %d%s%s)\n", |
| 1248 | create_notify->window, |
| 1249 | create_notify->width, create_notify->height, |
| 1250 | create_notify->override_redirect ? ", override" : "", |
| 1251 | our_resource(wm, create_notify->window) ? ", ours" : ""); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1252 | |
| 1253 | if (our_resource(wm, create_notify->window)) |
| 1254 | return; |
| 1255 | |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1256 | weston_wm_window_create(wm, create_notify->window, |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 1257 | create_notify->width, create_notify->height, |
Giulio Camuffo | ca43f09 | 2013-09-11 17:49:13 +0200 | [diff] [blame] | 1258 | create_notify->x, create_notify->y, |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 1259 | create_notify->override_redirect); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | static void |
| 1263 | weston_wm_handle_destroy_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1264 | { |
| 1265 | xcb_destroy_notify_event_t *destroy_notify = |
| 1266 | (xcb_destroy_notify_event_t *) event; |
| 1267 | struct weston_wm_window *window; |
| 1268 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1269 | wm_log("XCB_DESTROY_NOTIFY, win %d, event %d%s\n", |
| 1270 | destroy_notify->window, |
| 1271 | destroy_notify->event, |
| 1272 | our_resource(wm, destroy_notify->window) ? ", ours" : ""); |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 1273 | |
| 1274 | if (our_resource(wm, destroy_notify->window)) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1275 | return; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1276 | |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 1277 | if (!wm_lookup_window(wm, destroy_notify->window, &window)) |
| 1278 | return; |
| 1279 | |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1280 | weston_wm_window_destroy(window); |
| 1281 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1282 | |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1283 | static void |
| 1284 | weston_wm_handle_reparent_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1285 | { |
| 1286 | xcb_reparent_notify_event_t *reparent_notify = |
| 1287 | (xcb_reparent_notify_event_t *) event; |
| 1288 | struct weston_wm_window *window; |
Kristian Høgsberg | c9571fb | 2012-05-29 15:35:29 -0400 | [diff] [blame] | 1289 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1290 | wm_log("XCB_REPARENT_NOTIFY (window %d, parent %d, event %d)\n", |
| 1291 | reparent_notify->window, |
| 1292 | reparent_notify->parent, |
| 1293 | reparent_notify->event); |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1294 | |
| 1295 | if (reparent_notify->parent == wm->screen->root) { |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 1296 | weston_wm_window_create(wm, reparent_notify->window, 10, 10, |
Giulio Camuffo | ca43f09 | 2013-09-11 17:49:13 +0200 | [diff] [blame] | 1297 | reparent_notify->x, reparent_notify->y, |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 1298 | reparent_notify->override_redirect); |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1299 | } else if (!our_resource(wm, reparent_notify->parent)) { |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 1300 | if (!wm_lookup_window(wm, reparent_notify->window, &window)) |
| 1301 | return; |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1302 | weston_wm_window_destroy(window); |
| 1303 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1304 | } |
| 1305 | |
Kristian Høgsberg | 5ba3189 | 2012-08-10 10:06:59 -0400 | [diff] [blame] | 1306 | struct weston_seat * |
| 1307 | weston_wm_pick_seat(struct weston_wm *wm) |
| 1308 | { |
| 1309 | return container_of(wm->server->compositor->seat_list.next, |
| 1310 | struct weston_seat, link); |
| 1311 | } |
| 1312 | |
Kristian Høgsberg | 052ef4e | 2014-04-30 16:10:14 -0700 | [diff] [blame] | 1313 | static struct weston_seat * |
| 1314 | weston_wm_pick_seat_for_window(struct weston_wm_window *window) |
| 1315 | { |
| 1316 | struct weston_wm *wm = window->wm; |
| 1317 | struct weston_seat *seat, *s; |
| 1318 | |
| 1319 | seat = NULL; |
| 1320 | wl_list_for_each(s, &wm->server->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1321 | struct weston_pointer *pointer = weston_seat_get_pointer(s); |
| 1322 | struct weston_pointer *old_pointer = |
| 1323 | weston_seat_get_pointer(seat); |
| 1324 | |
| 1325 | if (pointer && pointer->focus && |
| 1326 | pointer->focus->surface == window->surface && |
| 1327 | pointer->button_count > 0 && |
| 1328 | (!seat || |
| 1329 | pointer->grab_serial - |
| 1330 | old_pointer->grab_serial < (1 << 30))) |
Kristian Høgsberg | 052ef4e | 2014-04-30 16:10:14 -0700 | [diff] [blame] | 1331 | seat = s; |
| 1332 | } |
| 1333 | |
| 1334 | return seat; |
| 1335 | } |
| 1336 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1337 | static void |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1338 | weston_wm_window_handle_moveresize(struct weston_wm_window *window, |
| 1339 | xcb_client_message_event_t *client_message) |
| 1340 | { |
| 1341 | static const int map[] = { |
| 1342 | THEME_LOCATION_RESIZING_TOP_LEFT, |
| 1343 | THEME_LOCATION_RESIZING_TOP, |
| 1344 | THEME_LOCATION_RESIZING_TOP_RIGHT, |
| 1345 | THEME_LOCATION_RESIZING_RIGHT, |
| 1346 | THEME_LOCATION_RESIZING_BOTTOM_RIGHT, |
| 1347 | THEME_LOCATION_RESIZING_BOTTOM, |
| 1348 | THEME_LOCATION_RESIZING_BOTTOM_LEFT, |
| 1349 | THEME_LOCATION_RESIZING_LEFT |
| 1350 | }; |
| 1351 | |
| 1352 | struct weston_wm *wm = window->wm; |
Kristian Høgsberg | 052ef4e | 2014-04-30 16:10:14 -0700 | [diff] [blame] | 1353 | struct weston_seat *seat = weston_wm_pick_seat_for_window(window); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1354 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1355 | int detail; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1356 | const struct weston_desktop_xwayland_interface *xwayland_interface = |
| 1357 | wm->server->compositor->xwayland_interface; |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1358 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1359 | if (!pointer || pointer->button_count != 1 |
| 1360 | || !pointer->focus |
| 1361 | || pointer->focus->surface != window->surface) |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1362 | return; |
| 1363 | |
| 1364 | detail = client_message->data.data32[2]; |
| 1365 | switch (detail) { |
| 1366 | case _NET_WM_MOVERESIZE_MOVE: |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1367 | xwayland_interface->move(window->shsurf, pointer); |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1368 | break; |
| 1369 | case _NET_WM_MOVERESIZE_SIZE_TOPLEFT: |
| 1370 | case _NET_WM_MOVERESIZE_SIZE_TOP: |
| 1371 | case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT: |
| 1372 | case _NET_WM_MOVERESIZE_SIZE_RIGHT: |
| 1373 | case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT: |
| 1374 | case _NET_WM_MOVERESIZE_SIZE_BOTTOM: |
| 1375 | case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT: |
| 1376 | case _NET_WM_MOVERESIZE_SIZE_LEFT: |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1377 | xwayland_interface->resize(window->shsurf, pointer, map[detail]); |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1378 | break; |
| 1379 | case _NET_WM_MOVERESIZE_CANCEL: |
| 1380 | break; |
| 1381 | } |
| 1382 | } |
| 1383 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1384 | #define _NET_WM_STATE_REMOVE 0 |
| 1385 | #define _NET_WM_STATE_ADD 1 |
| 1386 | #define _NET_WM_STATE_TOGGLE 2 |
| 1387 | |
| 1388 | static int |
| 1389 | update_state(int action, int *state) |
| 1390 | { |
| 1391 | int new_state, changed; |
| 1392 | |
| 1393 | switch (action) { |
| 1394 | case _NET_WM_STATE_REMOVE: |
| 1395 | new_state = 0; |
| 1396 | break; |
| 1397 | case _NET_WM_STATE_ADD: |
| 1398 | new_state = 1; |
| 1399 | break; |
| 1400 | case _NET_WM_STATE_TOGGLE: |
| 1401 | new_state = !*state; |
| 1402 | break; |
| 1403 | default: |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | changed = (*state != new_state); |
| 1408 | *state = new_state; |
| 1409 | |
| 1410 | return changed; |
| 1411 | } |
| 1412 | |
| 1413 | static void |
| 1414 | weston_wm_window_configure(void *data); |
| 1415 | |
| 1416 | static void |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 1417 | weston_wm_window_set_toplevel(struct weston_wm_window *window) |
| 1418 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1419 | const struct weston_desktop_xwayland_interface *xwayland_interface = |
| 1420 | window->wm->server->compositor->xwayland_interface; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 1421 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1422 | xwayland_interface->set_toplevel(window->shsurf); |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 1423 | window->width = window->saved_width; |
| 1424 | window->height = window->saved_height; |
| 1425 | if (window->frame) |
| 1426 | frame_resize_inside(window->frame, |
| 1427 | window->width, |
| 1428 | window->height); |
| 1429 | weston_wm_window_configure(window); |
| 1430 | } |
| 1431 | |
| 1432 | static inline bool |
| 1433 | weston_wm_window_is_maximized(struct weston_wm_window *window) |
| 1434 | { |
| 1435 | return window->maximized_horz && window->maximized_vert; |
| 1436 | } |
| 1437 | |
| 1438 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1439 | weston_wm_window_handle_state(struct weston_wm_window *window, |
| 1440 | xcb_client_message_event_t *client_message) |
| 1441 | { |
| 1442 | struct weston_wm *wm = window->wm; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1443 | const struct weston_desktop_xwayland_interface *xwayland_interface = |
| 1444 | wm->server->compositor->xwayland_interface; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1445 | uint32_t action, property; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 1446 | int maximized = weston_wm_window_is_maximized(window); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1447 | |
| 1448 | action = client_message->data.data32[0]; |
| 1449 | property = client_message->data.data32[1]; |
| 1450 | |
| 1451 | if (property == wm->atom.net_wm_state_fullscreen && |
| 1452 | update_state(action, &window->fullscreen)) { |
| 1453 | weston_wm_window_set_net_wm_state(window); |
| 1454 | if (window->fullscreen) { |
| 1455 | window->saved_width = window->width; |
| 1456 | window->saved_height = window->height; |
Kristian Høgsberg | 762b166 | 2013-02-21 20:18:37 -0500 | [diff] [blame] | 1457 | |
| 1458 | if (window->shsurf) |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1459 | xwayland_interface->set_fullscreen(window->shsurf, |
| 1460 | NULL); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1461 | } else { |
Andrew Engelbrecht | 4c5a6f7 | 2014-12-02 12:18:44 -0500 | [diff] [blame] | 1462 | if (window->shsurf) |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 1463 | weston_wm_window_set_toplevel(window); |
| 1464 | } |
| 1465 | } else { |
| 1466 | if (property == wm->atom.net_wm_state_maximized_vert && |
| 1467 | update_state(action, &window->maximized_vert)) |
| 1468 | weston_wm_window_set_net_wm_state(window); |
| 1469 | if (property == wm->atom.net_wm_state_maximized_horz && |
| 1470 | update_state(action, &window->maximized_horz)) |
| 1471 | weston_wm_window_set_net_wm_state(window); |
Andrew Engelbrecht | 4c5a6f7 | 2014-12-02 12:18:44 -0500 | [diff] [blame] | 1472 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 1473 | if (maximized != weston_wm_window_is_maximized(window)) { |
| 1474 | if (weston_wm_window_is_maximized(window)) { |
| 1475 | window->saved_width = window->width; |
| 1476 | window->saved_height = window->height; |
| 1477 | |
| 1478 | if (window->shsurf) |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1479 | xwayland_interface->set_maximized(window->shsurf); |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 1480 | } else if (window->shsurf) { |
| 1481 | weston_wm_window_set_toplevel(window); |
| 1482 | } |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1483 | } |
| 1484 | } |
| 1485 | } |
| 1486 | |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1487 | static void |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 1488 | surface_destroy(struct wl_listener *listener, void *data) |
| 1489 | { |
| 1490 | struct weston_wm_window *window = |
| 1491 | container_of(listener, |
| 1492 | struct weston_wm_window, surface_destroy_listener); |
| 1493 | |
| 1494 | wm_log("surface for xid %d destroyed\n", window->id); |
| 1495 | |
| 1496 | /* This should have been freed by the shell. |
| 1497 | * Don't try to use it later. */ |
| 1498 | window->shsurf = NULL; |
| 1499 | window->surface = NULL; |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | static void |
| 1503 | weston_wm_window_handle_surface_id(struct weston_wm_window *window, |
| 1504 | xcb_client_message_event_t *client_message) |
| 1505 | { |
| 1506 | struct weston_wm *wm = window->wm; |
| 1507 | struct wl_resource *resource; |
| 1508 | |
| 1509 | if (window->surface_id != 0) { |
| 1510 | wm_log("already have surface id for window %d\n", window->id); |
| 1511 | return; |
| 1512 | } |
| 1513 | |
| 1514 | /* Xwayland will send the wayland requests to create the |
| 1515 | * wl_surface before sending this client message. Even so, we |
| 1516 | * can end up handling the X event before the wayland requests |
| 1517 | * and thus when we try to look up the surface ID, the surface |
| 1518 | * hasn't been created yet. In that case put the window on |
| 1519 | * the unpaired window list and continue when the surface gets |
| 1520 | * created. */ |
Jason Ekstrand | 4ff4d92 | 2014-07-24 13:16:58 -0700 | [diff] [blame] | 1521 | uint32_t id = client_message->data.data32[0]; |
| 1522 | resource = wl_client_get_object(wm->server->client, id); |
Tyler Veness | cf4c13a | 2014-07-02 15:00:44 -0700 | [diff] [blame] | 1523 | if (resource) { |
| 1524 | window->surface_id = 0; |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 1525 | xserver_map_shell_surface(window, |
| 1526 | wl_resource_get_user_data(resource)); |
Tyler Veness | cf4c13a | 2014-07-02 15:00:44 -0700 | [diff] [blame] | 1527 | } |
| 1528 | else { |
Jason Ekstrand | 4ff4d92 | 2014-07-24 13:16:58 -0700 | [diff] [blame] | 1529 | window->surface_id = id; |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 1530 | wl_list_insert(&wm->unpaired_window_list, &window->link); |
Tyler Veness | cf4c13a | 2014-07-02 15:00:44 -0700 | [diff] [blame] | 1531 | } |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1535 | weston_wm_handle_client_message(struct weston_wm *wm, |
| 1536 | xcb_generic_event_t *event) |
| 1537 | { |
| 1538 | xcb_client_message_event_t *client_message = |
| 1539 | (xcb_client_message_event_t *) event; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1540 | struct weston_wm_window *window; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1541 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1542 | wm_log("XCB_CLIENT_MESSAGE (%s %d %d %d %d %d win %d)\n", |
| 1543 | get_atom_name(wm->conn, client_message->type), |
| 1544 | client_message->data.data32[0], |
| 1545 | client_message->data.data32[1], |
| 1546 | client_message->data.data32[2], |
| 1547 | client_message->data.data32[3], |
| 1548 | client_message->data.data32[4], |
| 1549 | client_message->window); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1550 | |
Jason Ekstrand | 0250a74 | 2014-07-24 13:17:47 -0700 | [diff] [blame] | 1551 | /* The window may get created and destroyed before we actually |
| 1552 | * handle the message. If it doesn't exist, bail. |
| 1553 | */ |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 1554 | if (!wm_lookup_window(wm, client_message->window, &window)) |
Jason Ekstrand | 0250a74 | 2014-07-24 13:17:47 -0700 | [diff] [blame] | 1555 | return; |
| 1556 | |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1557 | if (client_message->type == wm->atom.net_wm_moveresize) |
| 1558 | weston_wm_window_handle_moveresize(window, client_message); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1559 | else if (client_message->type == wm->atom.net_wm_state) |
| 1560 | weston_wm_window_handle_state(window, client_message); |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 1561 | else if (client_message->type == wm->atom.wl_surface_id) |
| 1562 | weston_wm_window_handle_surface_id(window, client_message); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1563 | } |
| 1564 | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1565 | enum cursor_type { |
| 1566 | XWM_CURSOR_TOP, |
| 1567 | XWM_CURSOR_BOTTOM, |
| 1568 | XWM_CURSOR_LEFT, |
| 1569 | XWM_CURSOR_RIGHT, |
| 1570 | XWM_CURSOR_TOP_LEFT, |
| 1571 | XWM_CURSOR_TOP_RIGHT, |
| 1572 | XWM_CURSOR_BOTTOM_LEFT, |
| 1573 | XWM_CURSOR_BOTTOM_RIGHT, |
| 1574 | XWM_CURSOR_LEFT_PTR, |
| 1575 | }; |
| 1576 | |
Giulio Camuffo | a2df51c | 2013-09-18 15:20:04 +0200 | [diff] [blame] | 1577 | /* |
| 1578 | * The following correspondences between file names and cursors was copied |
| 1579 | * from: https://bugs.kde.org/attachment.cgi?id=67313 |
| 1580 | */ |
| 1581 | |
| 1582 | static const char *bottom_left_corners[] = { |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1583 | "bottom_left_corner", |
Giulio Camuffo | a2df51c | 2013-09-18 15:20:04 +0200 | [diff] [blame] | 1584 | "sw-resize", |
| 1585 | "size_bdiag" |
| 1586 | }; |
| 1587 | |
| 1588 | static const char *bottom_right_corners[] = { |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1589 | "bottom_right_corner", |
Giulio Camuffo | a2df51c | 2013-09-18 15:20:04 +0200 | [diff] [blame] | 1590 | "se-resize", |
| 1591 | "size_fdiag" |
| 1592 | }; |
| 1593 | |
| 1594 | static const char *bottom_sides[] = { |
| 1595 | "bottom_side", |
| 1596 | "s-resize", |
| 1597 | "size_ver" |
| 1598 | }; |
| 1599 | |
| 1600 | static const char *left_ptrs[] = { |
| 1601 | "left_ptr", |
| 1602 | "default", |
| 1603 | "top_left_arrow", |
| 1604 | "left-arrow" |
| 1605 | }; |
| 1606 | |
| 1607 | static const char *left_sides[] = { |
| 1608 | "left_side", |
| 1609 | "w-resize", |
| 1610 | "size_hor" |
| 1611 | }; |
| 1612 | |
| 1613 | static const char *right_sides[] = { |
| 1614 | "right_side", |
| 1615 | "e-resize", |
| 1616 | "size_hor" |
| 1617 | }; |
| 1618 | |
| 1619 | static const char *top_left_corners[] = { |
| 1620 | "top_left_corner", |
| 1621 | "nw-resize", |
| 1622 | "size_fdiag" |
| 1623 | }; |
| 1624 | |
| 1625 | static const char *top_right_corners[] = { |
| 1626 | "top_right_corner", |
| 1627 | "ne-resize", |
| 1628 | "size_bdiag" |
| 1629 | }; |
| 1630 | |
| 1631 | static const char *top_sides[] = { |
| 1632 | "top_side", |
| 1633 | "n-resize", |
| 1634 | "size_ver" |
| 1635 | }; |
| 1636 | |
| 1637 | struct cursor_alternatives { |
| 1638 | const char **names; |
| 1639 | size_t count; |
| 1640 | }; |
| 1641 | |
| 1642 | static const struct cursor_alternatives cursors[] = { |
| 1643 | {top_sides, ARRAY_LENGTH(top_sides)}, |
| 1644 | {bottom_sides, ARRAY_LENGTH(bottom_sides)}, |
| 1645 | {left_sides, ARRAY_LENGTH(left_sides)}, |
| 1646 | {right_sides, ARRAY_LENGTH(right_sides)}, |
| 1647 | {top_left_corners, ARRAY_LENGTH(top_left_corners)}, |
| 1648 | {top_right_corners, ARRAY_LENGTH(top_right_corners)}, |
| 1649 | {bottom_left_corners, ARRAY_LENGTH(bottom_left_corners)}, |
| 1650 | {bottom_right_corners, ARRAY_LENGTH(bottom_right_corners)}, |
| 1651 | {left_ptrs, ARRAY_LENGTH(left_ptrs)}, |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1652 | }; |
| 1653 | |
| 1654 | static void |
| 1655 | weston_wm_create_cursors(struct weston_wm *wm) |
| 1656 | { |
Giulio Camuffo | a2df51c | 2013-09-18 15:20:04 +0200 | [diff] [blame] | 1657 | const char *name; |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1658 | int i, count = ARRAY_LENGTH(cursors); |
Giulio Camuffo | a2df51c | 2013-09-18 15:20:04 +0200 | [diff] [blame] | 1659 | size_t j; |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1660 | |
| 1661 | wm->cursors = malloc(count * sizeof(xcb_cursor_t)); |
| 1662 | for (i = 0; i < count; i++) { |
Giulio Camuffo | a2df51c | 2013-09-18 15:20:04 +0200 | [diff] [blame] | 1663 | for (j = 0; j < cursors[i].count; j++) { |
| 1664 | name = cursors[i].names[j]; |
| 1665 | wm->cursors[i] = |
| 1666 | xcb_cursor_library_load_cursor(wm, name); |
| 1667 | if (wm->cursors[i] != (xcb_cursor_t)-1) |
| 1668 | break; |
| 1669 | } |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | wm->last_cursor = -1; |
| 1673 | } |
| 1674 | |
| 1675 | static void |
| 1676 | weston_wm_destroy_cursors(struct weston_wm *wm) |
| 1677 | { |
| 1678 | uint8_t i; |
| 1679 | |
| 1680 | for (i = 0; i < ARRAY_LENGTH(cursors); i++) |
| 1681 | xcb_free_cursor(wm->conn, wm->cursors[i]); |
| 1682 | |
| 1683 | free(wm->cursors); |
| 1684 | } |
| 1685 | |
| 1686 | static int |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1687 | get_cursor_for_location(enum theme_location location) |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1688 | { |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1689 | switch (location) { |
| 1690 | case THEME_LOCATION_RESIZING_TOP: |
| 1691 | return XWM_CURSOR_TOP; |
| 1692 | case THEME_LOCATION_RESIZING_BOTTOM: |
| 1693 | return XWM_CURSOR_BOTTOM; |
| 1694 | case THEME_LOCATION_RESIZING_LEFT: |
| 1695 | return XWM_CURSOR_LEFT; |
| 1696 | case THEME_LOCATION_RESIZING_RIGHT: |
| 1697 | return XWM_CURSOR_RIGHT; |
| 1698 | case THEME_LOCATION_RESIZING_TOP_LEFT: |
| 1699 | return XWM_CURSOR_TOP_LEFT; |
| 1700 | case THEME_LOCATION_RESIZING_TOP_RIGHT: |
| 1701 | return XWM_CURSOR_TOP_RIGHT; |
| 1702 | case THEME_LOCATION_RESIZING_BOTTOM_LEFT: |
| 1703 | return XWM_CURSOR_BOTTOM_LEFT; |
| 1704 | case THEME_LOCATION_RESIZING_BOTTOM_RIGHT: |
| 1705 | return XWM_CURSOR_BOTTOM_RIGHT; |
| 1706 | case THEME_LOCATION_EXTERIOR: |
| 1707 | case THEME_LOCATION_TITLEBAR: |
| 1708 | default: |
| 1709 | return XWM_CURSOR_LEFT_PTR; |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | static void |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1714 | weston_wm_window_set_cursor(struct weston_wm *wm, xcb_window_t window_id, |
| 1715 | int cursor) |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1716 | { |
| 1717 | uint32_t cursor_value_list; |
| 1718 | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1719 | if (wm->last_cursor == cursor) |
| 1720 | return; |
| 1721 | |
| 1722 | wm->last_cursor = cursor; |
| 1723 | |
| 1724 | cursor_value_list = wm->cursors[cursor]; |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1725 | xcb_change_window_attributes (wm->conn, window_id, |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1726 | XCB_CW_CURSOR, &cursor_value_list); |
| 1727 | xcb_flush(wm->conn); |
| 1728 | } |
| 1729 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1730 | static void |
Kristian Høgsberg | 2cd6da1 | 2013-10-13 22:11:07 -0700 | [diff] [blame] | 1731 | weston_wm_window_close(struct weston_wm_window *window, xcb_timestamp_t time) |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1732 | { |
| 1733 | xcb_client_message_event_t client_message; |
| 1734 | |
Kristian Høgsberg | 2cd6da1 | 2013-10-13 22:11:07 -0700 | [diff] [blame] | 1735 | if (window->delete_window) { |
| 1736 | client_message.response_type = XCB_CLIENT_MESSAGE; |
| 1737 | client_message.format = 32; |
| 1738 | client_message.window = window->id; |
| 1739 | client_message.type = window->wm->atom.wm_protocols; |
| 1740 | client_message.data.data32[0] = |
| 1741 | window->wm->atom.wm_delete_window; |
| 1742 | client_message.data.data32[1] = time; |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1743 | |
Kristian Høgsberg | 2cd6da1 | 2013-10-13 22:11:07 -0700 | [diff] [blame] | 1744 | xcb_send_event(window->wm->conn, 0, window->id, |
| 1745 | XCB_EVENT_MASK_NO_EVENT, |
| 1746 | (char *) &client_message); |
| 1747 | } else { |
| 1748 | xcb_kill_client(window->wm->conn, window->id); |
| 1749 | } |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1753 | weston_wm_handle_button(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1754 | { |
| 1755 | xcb_button_press_event_t *button = (xcb_button_press_event_t *) event; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1756 | const struct weston_desktop_xwayland_interface *xwayland_interface = |
| 1757 | wm->server->compositor->xwayland_interface; |
Kristian Høgsberg | 052ef4e | 2014-04-30 16:10:14 -0700 | [diff] [blame] | 1758 | struct weston_seat *seat; |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 1759 | struct weston_pointer *pointer; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1760 | struct weston_wm_window *window; |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 1761 | enum theme_location location; |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1762 | enum frame_button_state button_state; |
| 1763 | uint32_t button_id; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1764 | |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1765 | wm_log("XCB_BUTTON_%s (detail %d)\n", |
| 1766 | button->response_type == XCB_BUTTON_PRESS ? |
| 1767 | "PRESS" : "RELEASE", button->detail); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1768 | |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 1769 | if (!wm_lookup_window(wm, button->event, &window) || |
| 1770 | !window->decorate) |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1771 | return; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 1772 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1773 | if (button->detail != 1 && button->detail != 2) |
| 1774 | return; |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 1775 | |
Kristian Høgsberg | 052ef4e | 2014-04-30 16:10:14 -0700 | [diff] [blame] | 1776 | seat = weston_wm_pick_seat_for_window(window); |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 1777 | pointer = weston_seat_get_pointer(seat); |
Kristian Høgsberg | 052ef4e | 2014-04-30 16:10:14 -0700 | [diff] [blame] | 1778 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1779 | button_state = button->response_type == XCB_BUTTON_PRESS ? |
| 1780 | FRAME_BUTTON_PRESSED : FRAME_BUTTON_RELEASED; |
| 1781 | button_id = button->detail == 1 ? BTN_LEFT : BTN_RIGHT; |
| 1782 | |
Kristian Høgsberg | 8c3c738 | 2014-04-30 16:52:30 -0700 | [diff] [blame] | 1783 | /* Make sure we're looking at the right location. The frame |
| 1784 | * could have received a motion event from a pointer from a |
| 1785 | * different wl_seat, but under X it looks like our core |
| 1786 | * pointer moved. Move the frame pointer to the button press |
| 1787 | * location before deciding what to do. */ |
| 1788 | location = frame_pointer_motion(window->frame, NULL, |
| 1789 | button->event_x, button->event_y); |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1790 | location = frame_pointer_button(window->frame, NULL, |
| 1791 | button_id, button_state); |
| 1792 | if (frame_status(window->frame) & FRAME_STATUS_REPAINT) |
| 1793 | weston_wm_window_schedule_repaint(window); |
| 1794 | |
| 1795 | if (frame_status(window->frame) & FRAME_STATUS_MOVE) { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 1796 | if (pointer) |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1797 | xwayland_interface->move(window->shsurf, pointer); |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1798 | frame_status_clear(window->frame, FRAME_STATUS_MOVE); |
| 1799 | } |
| 1800 | |
| 1801 | if (frame_status(window->frame) & FRAME_STATUS_RESIZE) { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 1802 | if (pointer) |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1803 | xwayland_interface->resize(window->shsurf, pointer, location); |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1804 | frame_status_clear(window->frame, FRAME_STATUS_RESIZE); |
| 1805 | } |
| 1806 | |
| 1807 | if (frame_status(window->frame) & FRAME_STATUS_CLOSE) { |
Kristian Høgsberg | 2cd6da1 | 2013-10-13 22:11:07 -0700 | [diff] [blame] | 1808 | weston_wm_window_close(window, button->time); |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1809 | frame_status_clear(window->frame, FRAME_STATUS_CLOSE); |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 1810 | } |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 1811 | |
| 1812 | if (frame_status(window->frame) & FRAME_STATUS_MAXIMIZE) { |
| 1813 | window->maximized_horz = !window->maximized_horz; |
| 1814 | window->maximized_vert = !window->maximized_vert; |
| 1815 | if (weston_wm_window_is_maximized(window)) { |
| 1816 | window->saved_width = window->width; |
| 1817 | window->saved_height = window->height; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 1818 | xwayland_interface->set_maximized(window->shsurf); |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 1819 | } else { |
| 1820 | weston_wm_window_set_toplevel(window); |
| 1821 | } |
| 1822 | frame_status_clear(window->frame, FRAME_STATUS_MAXIMIZE); |
| 1823 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1824 | } |
| 1825 | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1826 | static void |
| 1827 | weston_wm_handle_motion(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1828 | { |
| 1829 | xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *) event; |
| 1830 | struct weston_wm_window *window; |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1831 | enum theme_location location; |
| 1832 | int cursor; |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1833 | |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 1834 | if (!wm_lookup_window(wm, motion->event, &window) || |
| 1835 | !window->decorate) |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1836 | return; |
| 1837 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1838 | location = frame_pointer_motion(window->frame, NULL, |
| 1839 | motion->event_x, motion->event_y); |
| 1840 | if (frame_status(window->frame) & FRAME_STATUS_REPAINT) |
| 1841 | weston_wm_window_schedule_repaint(window); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1842 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1843 | cursor = get_cursor_for_location(location); |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1844 | weston_wm_window_set_cursor(wm, window->frame_id, cursor); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | static void |
| 1848 | weston_wm_handle_enter(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1849 | { |
| 1850 | xcb_enter_notify_event_t *enter = (xcb_enter_notify_event_t *) event; |
| 1851 | struct weston_wm_window *window; |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1852 | enum theme_location location; |
| 1853 | int cursor; |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1854 | |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 1855 | if (!wm_lookup_window(wm, enter->event, &window) || |
| 1856 | !window->decorate) |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1857 | return; |
| 1858 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1859 | location = frame_pointer_enter(window->frame, NULL, |
| 1860 | enter->event_x, enter->event_y); |
| 1861 | if (frame_status(window->frame) & FRAME_STATUS_REPAINT) |
| 1862 | weston_wm_window_schedule_repaint(window); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1863 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1864 | cursor = get_cursor_for_location(location); |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1865 | weston_wm_window_set_cursor(wm, window->frame_id, cursor); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | static void |
| 1869 | weston_wm_handle_leave(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1870 | { |
| 1871 | xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *) event; |
| 1872 | struct weston_wm_window *window; |
| 1873 | |
Derek Foreman | 4937214 | 2015-04-09 10:51:22 -0500 | [diff] [blame] | 1874 | if (!wm_lookup_window(wm, leave->event, &window) || |
| 1875 | !window->decorate) |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1876 | return; |
| 1877 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 1878 | frame_pointer_leave(window->frame, NULL); |
| 1879 | if (frame_status(window->frame) & FRAME_STATUS_REPAINT) |
| 1880 | weston_wm_window_schedule_repaint(window); |
| 1881 | |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1882 | weston_wm_window_set_cursor(wm, window->frame_id, XWM_CURSOR_LEFT_PTR); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1883 | } |
| 1884 | |
Giulio Camuffo | b18f788 | 2015-03-29 14:20:23 +0300 | [diff] [blame] | 1885 | static void |
| 1886 | weston_wm_handle_focus_in(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1887 | { |
| 1888 | xcb_focus_in_event_t *focus = (xcb_focus_in_event_t *) event; |
| 1889 | /* Do not let X clients change the focus behind the compositor's |
| 1890 | * back. Reset the focus to the old one if it changed. */ |
| 1891 | if (!wm->focus_window || focus->event != wm->focus_window->id) |
| 1892 | weston_wm_send_focus_window(wm, wm->focus_window); |
| 1893 | } |
| 1894 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1895 | static int |
| 1896 | weston_wm_handle_event(int fd, uint32_t mask, void *data) |
| 1897 | { |
| 1898 | struct weston_wm *wm = data; |
| 1899 | xcb_generic_event_t *event; |
| 1900 | int count = 0; |
| 1901 | |
| 1902 | while (event = xcb_poll_for_event(wm->conn), event != NULL) { |
| 1903 | if (weston_wm_handle_selection_event(wm, event)) { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1904 | free(event); |
| 1905 | count++; |
| 1906 | continue; |
| 1907 | } |
| 1908 | |
Kristian Høgsberg | f9cb3b1 | 2013-09-04 21:12:26 -0700 | [diff] [blame] | 1909 | if (weston_wm_handle_dnd_event(wm, event)) { |
| 1910 | free(event); |
| 1911 | count++; |
| 1912 | continue; |
| 1913 | } |
| 1914 | |
MoD | 3170012 | 2013-06-11 19:58:55 -0500 | [diff] [blame] | 1915 | switch (EVENT_TYPE(event)) { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1916 | case XCB_BUTTON_PRESS: |
| 1917 | case XCB_BUTTON_RELEASE: |
| 1918 | weston_wm_handle_button(wm, event); |
| 1919 | break; |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1920 | case XCB_ENTER_NOTIFY: |
| 1921 | weston_wm_handle_enter(wm, event); |
| 1922 | break; |
| 1923 | case XCB_LEAVE_NOTIFY: |
| 1924 | weston_wm_handle_leave(wm, event); |
| 1925 | break; |
| 1926 | case XCB_MOTION_NOTIFY: |
| 1927 | weston_wm_handle_motion(wm, event); |
| 1928 | break; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1929 | case XCB_CREATE_NOTIFY: |
| 1930 | weston_wm_handle_create_notify(wm, event); |
| 1931 | break; |
| 1932 | case XCB_MAP_REQUEST: |
| 1933 | weston_wm_handle_map_request(wm, event); |
| 1934 | break; |
| 1935 | case XCB_MAP_NOTIFY: |
| 1936 | weston_wm_handle_map_notify(wm, event); |
| 1937 | break; |
| 1938 | case XCB_UNMAP_NOTIFY: |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 1939 | weston_wm_handle_unmap_notify(wm, event); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1940 | break; |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1941 | case XCB_REPARENT_NOTIFY: |
| 1942 | weston_wm_handle_reparent_notify(wm, event); |
| 1943 | break; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1944 | case XCB_CONFIGURE_REQUEST: |
| 1945 | weston_wm_handle_configure_request(wm, event); |
| 1946 | break; |
| 1947 | case XCB_CONFIGURE_NOTIFY: |
| 1948 | weston_wm_handle_configure_notify(wm, event); |
| 1949 | break; |
| 1950 | case XCB_DESTROY_NOTIFY: |
| 1951 | weston_wm_handle_destroy_notify(wm, event); |
| 1952 | break; |
| 1953 | case XCB_MAPPING_NOTIFY: |
Kristian Høgsberg | 082d58c | 2013-06-18 01:00:27 -0400 | [diff] [blame] | 1954 | wm_log("XCB_MAPPING_NOTIFY\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1955 | break; |
| 1956 | case XCB_PROPERTY_NOTIFY: |
| 1957 | weston_wm_handle_property_notify(wm, event); |
| 1958 | break; |
| 1959 | case XCB_CLIENT_MESSAGE: |
| 1960 | weston_wm_handle_client_message(wm, event); |
| 1961 | break; |
Giulio Camuffo | b18f788 | 2015-03-29 14:20:23 +0300 | [diff] [blame] | 1962 | case XCB_FOCUS_IN: |
| 1963 | weston_wm_handle_focus_in(wm, event); |
| 1964 | break; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | free(event); |
| 1968 | count++; |
| 1969 | } |
| 1970 | |
Marek Chalupa | a1f3f3c | 2015-08-12 09:55:12 +0200 | [diff] [blame] | 1971 | if (count != 0) |
| 1972 | xcb_flush(wm->conn); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1973 | |
| 1974 | return count; |
| 1975 | } |
| 1976 | |
| 1977 | static void |
Benoit Gschwind | 1a42ca1 | 2015-09-25 21:26:04 +0200 | [diff] [blame] | 1978 | weston_wm_set_net_active_window(struct weston_wm *wm, xcb_window_t window) { |
| 1979 | xcb_change_property(wm->conn, XCB_PROP_MODE_REPLACE, |
| 1980 | wm->screen->root, wm->atom.net_active_window, |
| 1981 | wm->atom.window, 32, 1, &window); |
| 1982 | } |
| 1983 | |
| 1984 | static void |
Kristian Høgsberg | f918719 | 2013-05-02 13:43:24 -0400 | [diff] [blame] | 1985 | weston_wm_get_visual_and_colormap(struct weston_wm *wm) |
| 1986 | { |
| 1987 | xcb_depth_iterator_t d_iter; |
| 1988 | xcb_visualtype_iterator_t vt_iter; |
| 1989 | xcb_visualtype_t *visualtype; |
| 1990 | |
| 1991 | d_iter = xcb_screen_allowed_depths_iterator(wm->screen); |
| 1992 | visualtype = NULL; |
| 1993 | while (d_iter.rem > 0) { |
| 1994 | if (d_iter.data->depth == 32) { |
| 1995 | vt_iter = xcb_depth_visuals_iterator(d_iter.data); |
| 1996 | visualtype = vt_iter.data; |
| 1997 | break; |
| 1998 | } |
| 1999 | |
| 2000 | xcb_depth_next(&d_iter); |
| 2001 | } |
| 2002 | |
| 2003 | if (visualtype == NULL) { |
| 2004 | weston_log("no 32 bit visualtype\n"); |
| 2005 | return; |
| 2006 | } |
| 2007 | |
| 2008 | wm->visual_id = visualtype->visual_id; |
| 2009 | wm->colormap = xcb_generate_id(wm->conn); |
| 2010 | xcb_create_colormap(wm->conn, XCB_COLORMAP_ALLOC_NONE, |
| 2011 | wm->colormap, wm->screen->root, wm->visual_id); |
| 2012 | } |
| 2013 | |
| 2014 | static void |
Tiago Vignatti | 9c4ff83 | 2012-11-30 17:19:57 -0200 | [diff] [blame] | 2015 | weston_wm_get_resources(struct weston_wm *wm) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2016 | { |
| 2017 | |
| 2018 | #define F(field) offsetof(struct weston_wm, field) |
| 2019 | |
| 2020 | static const struct { const char *name; int offset; } atoms[] = { |
| 2021 | { "WM_PROTOCOLS", F(atom.wm_protocols) }, |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 2022 | { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2023 | { "WM_TAKE_FOCUS", F(atom.wm_take_focus) }, |
| 2024 | { "WM_DELETE_WINDOW", F(atom.wm_delete_window) }, |
Kristian Høgsberg | a6d9a5e | 2012-05-30 12:15:44 -0400 | [diff] [blame] | 2025 | { "WM_STATE", F(atom.wm_state) }, |
Kristian Høgsberg | 670b5d3 | 2012-06-04 11:00:40 -0400 | [diff] [blame] | 2026 | { "WM_S0", F(atom.wm_s0) }, |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 2027 | { "WM_CLIENT_MACHINE", F(atom.wm_client_machine) }, |
Kristian Høgsberg | 69981d9 | 2013-08-21 22:14:58 -0700 | [diff] [blame] | 2028 | { "_NET_WM_CM_S0", F(atom.net_wm_cm_s0) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2029 | { "_NET_WM_NAME", F(atom.net_wm_name) }, |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 2030 | { "_NET_WM_PID", F(atom.net_wm_pid) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2031 | { "_NET_WM_ICON", F(atom.net_wm_icon) }, |
| 2032 | { "_NET_WM_STATE", F(atom.net_wm_state) }, |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2033 | { "_NET_WM_STATE_MAXIMIZED_VERT", F(atom.net_wm_state_maximized_vert) }, |
| 2034 | { "_NET_WM_STATE_MAXIMIZED_HORZ", F(atom.net_wm_state_maximized_horz) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2035 | { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) }, |
| 2036 | { "_NET_WM_USER_TIME", F(atom.net_wm_user_time) }, |
| 2037 | { "_NET_WM_ICON_NAME", F(atom.net_wm_icon_name) }, |
Giulio Camuffo | e90ea44 | 2014-12-13 18:06:34 +0200 | [diff] [blame] | 2038 | { "_NET_WM_DESKTOP", F(atom.net_wm_desktop) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2039 | { "_NET_WM_WINDOW_TYPE", F(atom.net_wm_window_type) }, |
| 2040 | |
| 2041 | { "_NET_WM_WINDOW_TYPE_DESKTOP", F(atom.net_wm_window_type_desktop) }, |
| 2042 | { "_NET_WM_WINDOW_TYPE_DOCK", F(atom.net_wm_window_type_dock) }, |
| 2043 | { "_NET_WM_WINDOW_TYPE_TOOLBAR", F(atom.net_wm_window_type_toolbar) }, |
| 2044 | { "_NET_WM_WINDOW_TYPE_MENU", F(atom.net_wm_window_type_menu) }, |
| 2045 | { "_NET_WM_WINDOW_TYPE_UTILITY", F(atom.net_wm_window_type_utility) }, |
| 2046 | { "_NET_WM_WINDOW_TYPE_SPLASH", F(atom.net_wm_window_type_splash) }, |
| 2047 | { "_NET_WM_WINDOW_TYPE_DIALOG", F(atom.net_wm_window_type_dialog) }, |
Tiago Vignatti | bf1e866 | 2012-06-12 14:07:49 +0300 | [diff] [blame] | 2048 | { "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", F(atom.net_wm_window_type_dropdown) }, |
| 2049 | { "_NET_WM_WINDOW_TYPE_POPUP_MENU", F(atom.net_wm_window_type_popup) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2050 | { "_NET_WM_WINDOW_TYPE_TOOLTIP", F(atom.net_wm_window_type_tooltip) }, |
| 2051 | { "_NET_WM_WINDOW_TYPE_NOTIFICATION", F(atom.net_wm_window_type_notification) }, |
| 2052 | { "_NET_WM_WINDOW_TYPE_COMBO", F(atom.net_wm_window_type_combo) }, |
| 2053 | { "_NET_WM_WINDOW_TYPE_DND", F(atom.net_wm_window_type_dnd) }, |
| 2054 | { "_NET_WM_WINDOW_TYPE_NORMAL", F(atom.net_wm_window_type_normal) }, |
| 2055 | |
| 2056 | { "_NET_WM_MOVERESIZE", F(atom.net_wm_moveresize) }, |
| 2057 | { "_NET_SUPPORTING_WM_CHECK", |
| 2058 | F(atom.net_supporting_wm_check) }, |
| 2059 | { "_NET_SUPPORTED", F(atom.net_supported) }, |
Benoit Gschwind | 1a42ca1 | 2015-09-25 21:26:04 +0200 | [diff] [blame] | 2060 | { "_NET_ACTIVE_WINDOW", F(atom.net_active_window) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2061 | { "_MOTIF_WM_HINTS", F(atom.motif_wm_hints) }, |
| 2062 | { "CLIPBOARD", F(atom.clipboard) }, |
Kristian Høgsberg | cba022a | 2012-06-04 10:11:45 -0400 | [diff] [blame] | 2063 | { "CLIPBOARD_MANAGER", F(atom.clipboard_manager) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2064 | { "TARGETS", F(atom.targets) }, |
| 2065 | { "UTF8_STRING", F(atom.utf8_string) }, |
| 2066 | { "_WL_SELECTION", F(atom.wl_selection) }, |
| 2067 | { "INCR", F(atom.incr) }, |
| 2068 | { "TIMESTAMP", F(atom.timestamp) }, |
| 2069 | { "MULTIPLE", F(atom.multiple) }, |
| 2070 | { "UTF8_STRING" , F(atom.utf8_string) }, |
| 2071 | { "COMPOUND_TEXT", F(atom.compound_text) }, |
| 2072 | { "TEXT", F(atom.text) }, |
| 2073 | { "STRING", F(atom.string) }, |
Benoit Gschwind | 1a42ca1 | 2015-09-25 21:26:04 +0200 | [diff] [blame] | 2074 | { "WINDOW", F(atom.window) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2075 | { "text/plain;charset=utf-8", F(atom.text_plain_utf8) }, |
| 2076 | { "text/plain", F(atom.text_plain) }, |
Kristian Høgsberg | f9cb3b1 | 2013-09-04 21:12:26 -0700 | [diff] [blame] | 2077 | { "XdndSelection", F(atom.xdnd_selection) }, |
| 2078 | { "XdndAware", F(atom.xdnd_aware) }, |
| 2079 | { "XdndEnter", F(atom.xdnd_enter) }, |
| 2080 | { "XdndLeave", F(atom.xdnd_leave) }, |
| 2081 | { "XdndDrop", F(atom.xdnd_drop) }, |
| 2082 | { "XdndStatus", F(atom.xdnd_status) }, |
| 2083 | { "XdndFinished", F(atom.xdnd_finished) }, |
| 2084 | { "XdndTypeList", F(atom.xdnd_type_list) }, |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2085 | { "XdndActionCopy", F(atom.xdnd_action_copy) }, |
| 2086 | { "WL_SURFACE_ID", F(atom.wl_surface_id) } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2087 | }; |
| 2088 | #undef F |
| 2089 | |
| 2090 | xcb_xfixes_query_version_cookie_t xfixes_cookie; |
| 2091 | xcb_xfixes_query_version_reply_t *xfixes_reply; |
| 2092 | xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)]; |
| 2093 | xcb_intern_atom_reply_t *reply; |
| 2094 | xcb_render_query_pict_formats_reply_t *formats_reply; |
| 2095 | xcb_render_query_pict_formats_cookie_t formats_cookie; |
| 2096 | xcb_render_pictforminfo_t *formats; |
| 2097 | uint32_t i; |
| 2098 | |
| 2099 | xcb_prefetch_extension_data (wm->conn, &xcb_xfixes_id); |
Kristian Høgsberg | bcfd07b | 2013-10-11 16:48:19 -0700 | [diff] [blame] | 2100 | xcb_prefetch_extension_data (wm->conn, &xcb_composite_id); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2101 | |
| 2102 | formats_cookie = xcb_render_query_pict_formats(wm->conn); |
| 2103 | |
| 2104 | for (i = 0; i < ARRAY_LENGTH(atoms); i++) |
| 2105 | cookies[i] = xcb_intern_atom (wm->conn, 0, |
| 2106 | strlen(atoms[i].name), |
| 2107 | atoms[i].name); |
| 2108 | |
| 2109 | for (i = 0; i < ARRAY_LENGTH(atoms); i++) { |
| 2110 | reply = xcb_intern_atom_reply (wm->conn, cookies[i], NULL); |
| 2111 | *(xcb_atom_t *) ((char *) wm + atoms[i].offset) = reply->atom; |
| 2112 | free(reply); |
| 2113 | } |
| 2114 | |
| 2115 | wm->xfixes = xcb_get_extension_data(wm->conn, &xcb_xfixes_id); |
| 2116 | if (!wm->xfixes || !wm->xfixes->present) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2117 | weston_log("xfixes not available\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2118 | |
| 2119 | xfixes_cookie = xcb_xfixes_query_version(wm->conn, |
| 2120 | XCB_XFIXES_MAJOR_VERSION, |
| 2121 | XCB_XFIXES_MINOR_VERSION); |
| 2122 | xfixes_reply = xcb_xfixes_query_version_reply(wm->conn, |
| 2123 | xfixes_cookie, NULL); |
| 2124 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2125 | weston_log("xfixes version: %d.%d\n", |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2126 | xfixes_reply->major_version, xfixes_reply->minor_version); |
| 2127 | |
| 2128 | free(xfixes_reply); |
| 2129 | |
| 2130 | formats_reply = xcb_render_query_pict_formats_reply(wm->conn, |
| 2131 | formats_cookie, 0); |
| 2132 | if (formats_reply == NULL) |
| 2133 | return; |
| 2134 | |
| 2135 | formats = xcb_render_query_pict_formats_formats(formats_reply); |
Kristian Høgsberg | e89cef3 | 2012-07-16 11:57:08 -0400 | [diff] [blame] | 2136 | for (i = 0; i < formats_reply->num_formats; i++) { |
| 2137 | if (formats[i].direct.red_mask != 0xff && |
| 2138 | formats[i].direct.red_shift != 16) |
| 2139 | continue; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2140 | if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT && |
| 2141 | formats[i].depth == 24) |
Kristian Høgsberg | e89cef3 | 2012-07-16 11:57:08 -0400 | [diff] [blame] | 2142 | wm->format_rgb = formats[i]; |
| 2143 | if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT && |
| 2144 | formats[i].depth == 32 && |
| 2145 | formats[i].direct.alpha_mask == 0xff && |
| 2146 | formats[i].direct.alpha_shift == 24) |
| 2147 | wm->format_rgba = formats[i]; |
| 2148 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2149 | |
| 2150 | free(formats_reply); |
| 2151 | } |
| 2152 | |
| 2153 | static void |
| 2154 | weston_wm_create_wm_window(struct weston_wm *wm) |
| 2155 | { |
| 2156 | static const char name[] = "Weston WM"; |
| 2157 | |
| 2158 | wm->wm_window = xcb_generate_id(wm->conn); |
| 2159 | xcb_create_window(wm->conn, |
| 2160 | XCB_COPY_FROM_PARENT, |
| 2161 | wm->wm_window, |
| 2162 | wm->screen->root, |
| 2163 | 0, 0, |
| 2164 | 10, 10, |
| 2165 | 0, |
| 2166 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
| 2167 | wm->screen->root_visual, |
| 2168 | 0, NULL); |
| 2169 | |
| 2170 | xcb_change_property(wm->conn, |
| 2171 | XCB_PROP_MODE_REPLACE, |
| 2172 | wm->wm_window, |
| 2173 | wm->atom.net_supporting_wm_check, |
| 2174 | XCB_ATOM_WINDOW, |
| 2175 | 32, /* format */ |
| 2176 | 1, &wm->wm_window); |
| 2177 | |
| 2178 | xcb_change_property(wm->conn, |
| 2179 | XCB_PROP_MODE_REPLACE, |
| 2180 | wm->wm_window, |
| 2181 | wm->atom.net_wm_name, |
| 2182 | wm->atom.utf8_string, |
| 2183 | 8, /* format */ |
| 2184 | strlen(name), name); |
| 2185 | |
| 2186 | xcb_change_property(wm->conn, |
| 2187 | XCB_PROP_MODE_REPLACE, |
| 2188 | wm->screen->root, |
| 2189 | wm->atom.net_supporting_wm_check, |
| 2190 | XCB_ATOM_WINDOW, |
| 2191 | 32, /* format */ |
| 2192 | 1, &wm->wm_window); |
| 2193 | |
Kristian Høgsberg | 670b5d3 | 2012-06-04 11:00:40 -0400 | [diff] [blame] | 2194 | /* Claim the WM_S0 selection even though we don't suport |
| 2195 | * the --replace functionality. */ |
| 2196 | xcb_set_selection_owner(wm->conn, |
| 2197 | wm->wm_window, |
| 2198 | wm->atom.wm_s0, |
| 2199 | XCB_TIME_CURRENT_TIME); |
Kristian Høgsberg | 69981d9 | 2013-08-21 22:14:58 -0700 | [diff] [blame] | 2200 | |
| 2201 | xcb_set_selection_owner(wm->conn, |
| 2202 | wm->wm_window, |
| 2203 | wm->atom.net_wm_cm_s0, |
| 2204 | XCB_TIME_CURRENT_TIME); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | struct weston_wm * |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2208 | weston_wm_create(struct weston_xserver *wxs, int fd) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2209 | { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2210 | struct weston_wm *wm; |
| 2211 | struct wl_event_loop *loop; |
| 2212 | xcb_screen_iterator_t s; |
Kristian Høgsberg | 4dec011 | 2012-06-03 09:18:06 -0400 | [diff] [blame] | 2213 | uint32_t values[1]; |
Benoit Gschwind | 1a42ca1 | 2015-09-25 21:26:04 +0200 | [diff] [blame] | 2214 | xcb_atom_t supported[6]; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2215 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 2216 | wm = zalloc(sizeof *wm); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2217 | if (wm == NULL) |
| 2218 | return NULL; |
| 2219 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2220 | wm->server = wxs; |
| 2221 | wm->window_hash = hash_table_create(); |
| 2222 | if (wm->window_hash == NULL) { |
| 2223 | free(wm); |
| 2224 | return NULL; |
| 2225 | } |
| 2226 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2227 | /* xcb_connect_to_fd takes ownership of the fd. */ |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2228 | wm->conn = xcb_connect_to_fd(fd, NULL); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2229 | if (xcb_connection_has_error(wm->conn)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2230 | weston_log("xcb_connect_to_fd failed\n"); |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2231 | close(fd); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2232 | hash_table_destroy(wm->window_hash); |
| 2233 | free(wm); |
| 2234 | return NULL; |
| 2235 | } |
| 2236 | |
| 2237 | s = xcb_setup_roots_iterator(xcb_get_setup(wm->conn)); |
| 2238 | wm->screen = s.data; |
| 2239 | |
| 2240 | loop = wl_display_get_event_loop(wxs->wl_display); |
| 2241 | wm->source = |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2242 | wl_event_loop_add_fd(loop, fd, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2243 | WL_EVENT_READABLE, |
| 2244 | weston_wm_handle_event, wm); |
| 2245 | wl_event_source_check(wm->source); |
| 2246 | |
Tiago Vignatti | 9c4ff83 | 2012-11-30 17:19:57 -0200 | [diff] [blame] | 2247 | weston_wm_get_resources(wm); |
Kristian Høgsberg | f918719 | 2013-05-02 13:43:24 -0400 | [diff] [blame] | 2248 | weston_wm_get_visual_and_colormap(wm); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2249 | |
| 2250 | values[0] = |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2251 | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | |
| 2252 | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | |
| 2253 | XCB_EVENT_MASK_PROPERTY_CHANGE; |
| 2254 | xcb_change_window_attributes(wm->conn, wm->screen->root, |
| 2255 | XCB_CW_EVENT_MASK, values); |
Kristian Høgsberg | bcfd07b | 2013-10-11 16:48:19 -0700 | [diff] [blame] | 2256 | |
| 2257 | xcb_composite_redirect_subwindows(wm->conn, wm->screen->root, |
| 2258 | XCB_COMPOSITE_REDIRECT_MANUAL); |
| 2259 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2260 | wm->theme = theme_create(); |
| 2261 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2262 | supported[0] = wm->atom.net_wm_moveresize; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2263 | supported[1] = wm->atom.net_wm_state; |
| 2264 | supported[2] = wm->atom.net_wm_state_fullscreen; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2265 | supported[3] = wm->atom.net_wm_state_maximized_vert; |
| 2266 | supported[4] = wm->atom.net_wm_state_maximized_horz; |
Benoit Gschwind | 1a42ca1 | 2015-09-25 21:26:04 +0200 | [diff] [blame] | 2267 | supported[5] = wm->atom.net_active_window; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2268 | xcb_change_property(wm->conn, |
| 2269 | XCB_PROP_MODE_REPLACE, |
| 2270 | wm->screen->root, |
| 2271 | wm->atom.net_supported, |
| 2272 | XCB_ATOM_ATOM, |
| 2273 | 32, /* format */ |
| 2274 | ARRAY_LENGTH(supported), supported); |
| 2275 | |
Benoit Gschwind | 1a42ca1 | 2015-09-25 21:26:04 +0200 | [diff] [blame] | 2276 | weston_wm_set_net_active_window(wm, XCB_WINDOW_NONE); |
| 2277 | |
Kristian Høgsberg | 4dec011 | 2012-06-03 09:18:06 -0400 | [diff] [blame] | 2278 | weston_wm_selection_init(wm); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2279 | |
Kristian Høgsberg | f9cb3b1 | 2013-09-04 21:12:26 -0700 | [diff] [blame] | 2280 | weston_wm_dnd_init(wm); |
| 2281 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2282 | xcb_flush(wm->conn); |
| 2283 | |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2284 | wm->create_surface_listener.notify = weston_wm_create_surface; |
| 2285 | wl_signal_add(&wxs->compositor->create_surface_signal, |
| 2286 | &wm->create_surface_listener); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2287 | wm->activate_listener.notify = weston_wm_window_activate; |
| 2288 | wl_signal_add(&wxs->compositor->activate_signal, |
| 2289 | &wm->activate_listener); |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 2290 | wm->kill_listener.notify = weston_wm_kill_client; |
| 2291 | wl_signal_add(&wxs->compositor->kill_signal, |
| 2292 | &wm->kill_listener); |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2293 | wl_list_init(&wm->unpaired_window_list); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2294 | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 2295 | weston_wm_create_cursors(wm); |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 2296 | weston_wm_window_set_cursor(wm, wm->screen->root, XWM_CURSOR_LEFT_PTR); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 2297 | |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2298 | /* Create wm window and take WM_S0 selection last, which |
| 2299 | * signals to Xwayland that we're done with setup. */ |
| 2300 | weston_wm_create_wm_window(wm); |
| 2301 | |
| 2302 | weston_log("created wm, root %d\n", wm->screen->root); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2303 | |
| 2304 | return wm; |
| 2305 | } |
| 2306 | |
| 2307 | void |
| 2308 | weston_wm_destroy(struct weston_wm *wm) |
| 2309 | { |
| 2310 | /* FIXME: Free windows in hash. */ |
| 2311 | hash_table_destroy(wm->window_hash); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 2312 | weston_wm_destroy_cursors(wm); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2313 | xcb_disconnect(wm->conn); |
| 2314 | wl_event_source_remove(wm->source); |
| 2315 | wl_list_remove(&wm->selection_listener.link); |
| 2316 | wl_list_remove(&wm->activate_listener.link); |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 2317 | wl_list_remove(&wm->kill_listener.link); |
Derek Foreman | f10e06c | 2015-02-03 11:05:10 -0600 | [diff] [blame] | 2318 | wl_list_remove(&wm->create_surface_listener.link); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2319 | |
| 2320 | free(wm); |
| 2321 | } |
| 2322 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2323 | static struct weston_wm_window * |
| 2324 | get_wm_window(struct weston_surface *surface) |
| 2325 | { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2326 | struct wl_listener *listener; |
| 2327 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2328 | listener = wl_signal_get(&surface->destroy_signal, surface_destroy); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2329 | if (listener) |
| 2330 | return container_of(listener, struct weston_wm_window, |
| 2331 | surface_destroy_listener); |
| 2332 | |
| 2333 | return NULL; |
| 2334 | } |
| 2335 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2336 | static bool |
| 2337 | is_wm_window(struct weston_surface *surface) |
| 2338 | { |
| 2339 | return get_wm_window(surface) != NULL; |
| 2340 | } |
| 2341 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2342 | static void |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2343 | weston_wm_window_configure(void *data) |
| 2344 | { |
| 2345 | struct weston_wm_window *window = data; |
| 2346 | struct weston_wm *wm = window->wm; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2347 | uint32_t values[4]; |
| 2348 | int x, y, width, height; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2349 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2350 | weston_wm_window_get_child_position(window, &x, &y); |
| 2351 | values[0] = x; |
| 2352 | values[1] = y; |
| 2353 | values[2] = window->width; |
| 2354 | values[3] = window->height; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2355 | xcb_configure_window(wm->conn, |
| 2356 | window->id, |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2357 | XCB_CONFIG_WINDOW_X | |
| 2358 | XCB_CONFIG_WINDOW_Y | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2359 | XCB_CONFIG_WINDOW_WIDTH | |
| 2360 | XCB_CONFIG_WINDOW_HEIGHT, |
| 2361 | values); |
| 2362 | |
| 2363 | weston_wm_window_get_frame_size(window, &width, &height); |
| 2364 | values[0] = width; |
| 2365 | values[1] = height; |
| 2366 | xcb_configure_window(wm->conn, |
| 2367 | window->frame_id, |
| 2368 | XCB_CONFIG_WINDOW_WIDTH | |
| 2369 | XCB_CONFIG_WINDOW_HEIGHT, |
| 2370 | values); |
| 2371 | |
| 2372 | window->configure_source = NULL; |
| 2373 | |
| 2374 | weston_wm_window_schedule_repaint(window); |
| 2375 | } |
| 2376 | |
| 2377 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 2378 | send_configure(struct weston_surface *surface, int32_t width, int32_t height) |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2379 | { |
| 2380 | struct weston_wm_window *window = get_wm_window(surface); |
| 2381 | struct weston_wm *wm = window->wm; |
| 2382 | struct theme *t = window->wm->theme; |
Kristian Høgsberg | fa514b4 | 2013-07-08 15:00:25 -0400 | [diff] [blame] | 2383 | int vborder, hborder; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2384 | |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 2385 | if (window->decorate && !window->fullscreen) { |
Jasper St. Pierre | 8ffd38b | 2014-08-27 09:38:33 -0400 | [diff] [blame] | 2386 | hborder = 2 * t->width; |
| 2387 | vborder = t->titlebar_height + t->width; |
| 2388 | } else { |
Kristian Høgsberg | fa514b4 | 2013-07-08 15:00:25 -0400 | [diff] [blame] | 2389 | hborder = 0; |
| 2390 | vborder = 0; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2391 | } |
| 2392 | |
Kristian Høgsberg | fa514b4 | 2013-07-08 15:00:25 -0400 | [diff] [blame] | 2393 | if (width > hborder) |
| 2394 | window->width = width - hborder; |
| 2395 | else |
| 2396 | window->width = 1; |
| 2397 | |
| 2398 | if (height > vborder) |
| 2399 | window->height = height - vborder; |
| 2400 | else |
| 2401 | window->height = 1; |
| 2402 | |
Jason Ekstrand | d14c4ca | 2013-10-13 19:08:41 -0500 | [diff] [blame] | 2403 | if (window->frame) |
| 2404 | frame_resize_inside(window->frame, window->width, window->height); |
| 2405 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2406 | if (window->configure_source) |
| 2407 | return; |
| 2408 | |
| 2409 | window->configure_source = |
| 2410 | wl_event_loop_add_idle(wm->server->loop, |
| 2411 | weston_wm_window_configure, window); |
| 2412 | } |
| 2413 | |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 2414 | static void |
| 2415 | send_position(struct weston_surface *surface, int32_t x, int32_t y) |
| 2416 | { |
| 2417 | struct weston_wm_window *window = get_wm_window(surface); |
| 2418 | struct weston_wm *wm; |
| 2419 | uint32_t mask, values[2]; |
| 2420 | |
| 2421 | if (!window || !window->wm) |
| 2422 | return; |
| 2423 | |
| 2424 | wm = window->wm; |
| 2425 | /* We use pos_dirty to tell whether a configure message is in flight. |
| 2426 | * This is needed in case we send two configure events in a very |
| 2427 | * short time, since window->x/y is set in after a roundtrip, hence |
| 2428 | * we cannot just check if the current x and y are different. */ |
| 2429 | if (window->x != x || window->y != y || window->pos_dirty) { |
| 2430 | window->pos_dirty = true; |
| 2431 | values[0] = x; |
| 2432 | values[1] = y; |
| 2433 | mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y; |
| 2434 | |
| 2435 | xcb_configure_window(wm->conn, window->frame_id, mask, values); |
| 2436 | xcb_flush(wm->conn); |
| 2437 | } |
| 2438 | } |
| 2439 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2440 | static const struct weston_xwayland_client_interface shell_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 2441 | send_configure, |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2442 | }; |
| 2443 | |
Kristian Høgsberg | 59f44c1 | 2013-08-31 00:08:27 -0700 | [diff] [blame] | 2444 | static int |
| 2445 | legacy_fullscreen(struct weston_wm *wm, |
| 2446 | struct weston_wm_window *window, |
| 2447 | struct weston_output **output_ret) |
| 2448 | { |
| 2449 | struct weston_compositor *compositor = wm->server->compositor; |
| 2450 | struct weston_output *output; |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 2451 | uint32_t minmax = PMinSize | PMaxSize; |
| 2452 | int matching_size; |
Kristian Høgsberg | 59f44c1 | 2013-08-31 00:08:27 -0700 | [diff] [blame] | 2453 | |
| 2454 | /* Heuristics for detecting legacy fullscreen windows... */ |
| 2455 | |
| 2456 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2457 | if (output->x == window->x && |
| 2458 | output->y == window->y && |
| 2459 | output->width == window->width && |
| 2460 | output->height == window->height && |
| 2461 | window->override_redirect) { |
| 2462 | *output_ret = output; |
| 2463 | return 1; |
| 2464 | } |
Kristian Høgsberg | 1a7a57f | 2013-08-31 00:12:25 -0700 | [diff] [blame] | 2465 | |
| 2466 | matching_size = 0; |
| 2467 | if ((window->size_hints.flags & (USSize |PSize)) && |
| 2468 | window->size_hints.width == output->width && |
| 2469 | window->size_hints.height == output->height) |
| 2470 | matching_size = 1; |
| 2471 | if ((window->size_hints.flags & minmax) == minmax && |
| 2472 | window->size_hints.min_width == output->width && |
| 2473 | window->size_hints.min_height == output->height && |
| 2474 | window->size_hints.max_width == output->width && |
| 2475 | window->size_hints.max_height == output->height) |
| 2476 | matching_size = 1; |
| 2477 | |
| 2478 | if (matching_size && !window->decorate && |
| 2479 | (window->size_hints.flags & (USPosition | PPosition)) && |
| 2480 | window->size_hints.x == output->x && |
| 2481 | window->size_hints.y == output->y) { |
| 2482 | *output_ret = output; |
| 2483 | return 1; |
| 2484 | } |
Kristian Høgsberg | 59f44c1 | 2013-08-31 00:08:27 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | return 0; |
| 2488 | } |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2489 | |
Giulio Camuffo | 836b9c7 | 2015-01-24 17:54:21 +0200 | [diff] [blame] | 2490 | static bool |
| 2491 | weston_wm_window_type_inactive(struct weston_wm_window *window) |
| 2492 | { |
| 2493 | struct weston_wm *wm = window->wm; |
| 2494 | |
| 2495 | return window->type == wm->atom.net_wm_window_type_tooltip || |
| 2496 | window->type == wm->atom.net_wm_window_type_dropdown || |
| 2497 | window->type == wm->atom.net_wm_window_type_dnd || |
| 2498 | window->type == wm->atom.net_wm_window_type_combo || |
Giulio Camuffo | 84787ea | 2015-04-29 19:00:48 +0300 | [diff] [blame] | 2499 | window->type == wm->atom.net_wm_window_type_popup || |
| 2500 | window->type == wm->atom.net_wm_window_type_utility; |
Giulio Camuffo | 836b9c7 | 2015-01-24 17:54:21 +0200 | [diff] [blame] | 2501 | } |
| 2502 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2503 | static void |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2504 | xserver_map_shell_surface(struct weston_wm_window *window, |
| 2505 | struct weston_surface *surface) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2506 | { |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2507 | struct weston_wm *wm = window->wm; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2508 | struct weston_desktop_xwayland *xwayland = |
| 2509 | wm->server->compositor->xwayland; |
| 2510 | const struct weston_desktop_xwayland_interface *xwayland_interface = |
| 2511 | wm->server->compositor->xwayland_interface; |
Kristian Høgsberg | 59f44c1 | 2013-08-31 00:08:27 -0700 | [diff] [blame] | 2512 | struct weston_output *output; |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2513 | struct weston_wm_window *parent; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2514 | |
Kristian Høgsberg | 757d8af | 2014-03-17 22:33:29 -0700 | [diff] [blame] | 2515 | weston_wm_window_read_properties(window); |
| 2516 | |
| 2517 | /* A weston_wm_window may have many different surfaces assigned |
| 2518 | * throughout its life, so we must make sure to remove the listener |
| 2519 | * from the old surface signal list. */ |
| 2520 | if (window->surface) |
| 2521 | wl_list_remove(&window->surface_destroy_listener.link); |
| 2522 | |
| 2523 | window->surface = surface; |
| 2524 | window->surface_destroy_listener.notify = surface_destroy; |
| 2525 | wl_signal_add(&window->surface->destroy_signal, |
| 2526 | &window->surface_destroy_listener); |
| 2527 | |
| 2528 | weston_wm_window_schedule_repaint(window); |
| 2529 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2530 | if (!xwayland_interface) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2531 | return; |
| 2532 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2533 | if (window->surface->committed) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 2534 | weston_log("warning, unexpected in %s: " |
| 2535 | "surface's configure hook is already set.\n", |
| 2536 | __func__); |
| 2537 | return; |
| 2538 | } |
| 2539 | |
Murray Calavera | 883ac02 | 2015-06-06 13:02:22 +0000 | [diff] [blame] | 2540 | window->shsurf = |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2541 | xwayland_interface->create_surface(xwayland, |
| 2542 | window->surface, |
| 2543 | &shell_client); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2544 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2545 | if (window->name) |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2546 | xwayland_interface->set_title(window->shsurf, window->name); |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2547 | if (window->pid > 0) |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2548 | xwayland_interface->set_pid(window->shsurf, window->pid); |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2549 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2550 | if (window->fullscreen) { |
| 2551 | window->saved_width = window->width; |
| 2552 | window->saved_height = window->height; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2553 | xwayland_interface->set_fullscreen(window->shsurf, NULL); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2554 | return; |
Kristian Høgsberg | 59f44c1 | 2013-08-31 00:08:27 -0700 | [diff] [blame] | 2555 | } else if (legacy_fullscreen(wm, window, &output)) { |
| 2556 | window->fullscreen = 1; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2557 | xwayland_interface->set_fullscreen(window->shsurf, output); |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2558 | } else if (window->override_redirect) { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2559 | xwayland_interface->set_xwayland(window->shsurf, |
| 2560 | window->x, window->y); |
Axel Davy | e4450f9 | 2014-01-12 15:06:05 +0100 | [diff] [blame] | 2561 | } else if (window->transient_for && window->transient_for->surface) { |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2562 | parent = window->transient_for; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2563 | if (weston_wm_window_type_inactive(window)) { |
| 2564 | xwayland_interface->set_transient(window->shsurf, |
| 2565 | parent->surface, |
| 2566 | window->x - parent->x, |
| 2567 | window->y - parent->y); |
| 2568 | } else { |
| 2569 | xwayland_interface->set_toplevel(window->shsurf); |
| 2570 | xwayland_interface->set_parent(window->shsurf, |
| 2571 | parent->surface); |
| 2572 | } |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2573 | } else if (weston_wm_window_is_maximized(window)) { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2574 | xwayland_interface->set_maximized(window->shsurf); |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2575 | } else { |
Giulio Camuffo | 836b9c7 | 2015-01-24 17:54:21 +0200 | [diff] [blame] | 2576 | if (weston_wm_window_type_inactive(window)) { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2577 | xwayland_interface->set_xwayland(window->shsurf, |
| 2578 | window->x, |
| 2579 | window->y); |
Giulio Camuffo | 836b9c7 | 2015-01-24 17:54:21 +0200 | [diff] [blame] | 2580 | } else { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2581 | xwayland_interface->set_toplevel(window->shsurf); |
Giulio Camuffo | 836b9c7 | 2015-01-24 17:54:21 +0200 | [diff] [blame] | 2582 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2583 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 2584 | } |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame^] | 2585 | |
| 2586 | const struct weston_xwayland_surface_api surface_api = { |
| 2587 | is_wm_window, |
| 2588 | send_position, |
| 2589 | }; |