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