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