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