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