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