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