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