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 | |
| 23 | #define _GNU_SOURCE |
| 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> |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 35 | |
| 36 | #include "xwayland.h" |
| 37 | |
| 38 | #include "../../shared/cairo-util.h" |
| 39 | #include "../compositor.h" |
| 40 | #include "xserver-server-protocol.h" |
| 41 | #include "hash.h" |
| 42 | |
| 43 | struct motif_wm_hints { |
| 44 | uint32_t flags; |
| 45 | uint32_t functions; |
| 46 | uint32_t decorations; |
| 47 | int32_t input_mode; |
| 48 | uint32_t status; |
| 49 | }; |
| 50 | |
| 51 | #define MWM_HINTS_FUNCTIONS (1L << 0) |
| 52 | #define MWM_HINTS_DECORATIONS (1L << 1) |
| 53 | #define MWM_HINTS_INPUT_MODE (1L << 2) |
| 54 | #define MWM_HINTS_STATUS (1L << 3) |
| 55 | |
| 56 | #define MWM_FUNC_ALL (1L << 0) |
| 57 | #define MWM_FUNC_RESIZE (1L << 1) |
| 58 | #define MWM_FUNC_MOVE (1L << 2) |
| 59 | #define MWM_FUNC_MINIMIZE (1L << 3) |
| 60 | #define MWM_FUNC_MAXIMIZE (1L << 4) |
| 61 | #define MWM_FUNC_CLOSE (1L << 5) |
| 62 | |
| 63 | #define MWM_DECOR_ALL (1L << 0) |
| 64 | #define MWM_DECOR_BORDER (1L << 1) |
| 65 | #define MWM_DECOR_RESIZEH (1L << 2) |
| 66 | #define MWM_DECOR_TITLE (1L << 3) |
| 67 | #define MWM_DECOR_MENU (1L << 4) |
| 68 | #define MWM_DECOR_MINIMIZE (1L << 5) |
| 69 | #define MWM_DECOR_MAXIMIZE (1L << 6) |
| 70 | |
| 71 | #define MWM_INPUT_MODELESS 0 |
| 72 | #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 |
| 73 | #define MWM_INPUT_SYSTEM_MODAL 2 |
| 74 | #define MWM_INPUT_FULL_APPLICATION_MODAL 3 |
| 75 | #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL |
| 76 | |
| 77 | #define MWM_TEAROFF_WINDOW (1L<<0) |
| 78 | |
| 79 | #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0 |
| 80 | #define _NET_WM_MOVERESIZE_SIZE_TOP 1 |
| 81 | #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2 |
| 82 | #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3 |
| 83 | #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4 |
| 84 | #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5 |
| 85 | #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6 |
| 86 | #define _NET_WM_MOVERESIZE_SIZE_LEFT 7 |
| 87 | #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */ |
| 88 | #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */ |
| 89 | #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */ |
| 90 | #define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */ |
| 91 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 92 | struct weston_wm_window { |
| 93 | struct weston_wm *wm; |
| 94 | xcb_window_t id; |
| 95 | xcb_window_t frame_id; |
| 96 | cairo_surface_t *cairo_surface; |
| 97 | struct weston_surface *surface; |
| 98 | struct shell_surface *shsurf; |
| 99 | struct wl_listener surface_destroy_listener; |
| 100 | struct wl_event_source *repaint_source; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 101 | struct wl_event_source *configure_source; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 102 | int properties_dirty; |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 103 | int pid; |
| 104 | char *machine; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 105 | char *class; |
| 106 | char *name; |
| 107 | struct weston_wm_window *transient_for; |
| 108 | uint32_t protocols; |
| 109 | xcb_atom_t type; |
| 110 | int width, height; |
| 111 | int x, y; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 112 | int saved_width, saved_height; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 113 | int decorate; |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 114 | int override_redirect; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 115 | int fullscreen; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | static struct weston_wm_window * |
| 119 | get_wm_window(struct weston_surface *surface); |
| 120 | |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 121 | static void |
| 122 | weston_wm_window_schedule_repaint(struct weston_wm_window *window); |
| 123 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 124 | const char * |
| 125 | get_atom_name(xcb_connection_t *c, xcb_atom_t atom) |
| 126 | { |
| 127 | xcb_get_atom_name_cookie_t cookie; |
| 128 | xcb_get_atom_name_reply_t *reply; |
| 129 | xcb_generic_error_t *e; |
| 130 | static char buffer[64]; |
| 131 | |
| 132 | if (atom == XCB_ATOM_NONE) |
| 133 | return "None"; |
| 134 | |
| 135 | cookie = xcb_get_atom_name (c, atom); |
| 136 | reply = xcb_get_atom_name_reply (c, cookie, &e); |
| 137 | snprintf(buffer, sizeof buffer, "%.*s", |
| 138 | xcb_get_atom_name_name_length (reply), |
| 139 | xcb_get_atom_name_name (reply)); |
| 140 | free(reply); |
| 141 | |
| 142 | return buffer; |
| 143 | } |
| 144 | |
Tiago Vignatti | 90fada4 | 2012-07-16 12:02:08 -0400 | [diff] [blame] | 145 | static xcb_cursor_t |
| 146 | xcb_cursor_image_load_cursor(struct weston_wm *wm, const XcursorImage *img) |
| 147 | { |
| 148 | xcb_connection_t *c = wm->conn; |
| 149 | xcb_screen_iterator_t s = xcb_setup_roots_iterator(xcb_get_setup(c)); |
| 150 | xcb_screen_t *screen = s.data; |
| 151 | xcb_gcontext_t gc; |
| 152 | xcb_pixmap_t pix; |
| 153 | xcb_render_picture_t pic; |
| 154 | xcb_cursor_t cursor; |
| 155 | int stride = img->width * 4; |
| 156 | |
| 157 | pix = xcb_generate_id(c); |
| 158 | xcb_create_pixmap(c, 32, pix, screen->root, img->width, img->height); |
| 159 | |
| 160 | pic = xcb_generate_id(c); |
| 161 | xcb_render_create_picture(c, pic, pix, wm->format_rgba.id, 0, 0); |
| 162 | |
| 163 | gc = xcb_generate_id(c); |
| 164 | xcb_create_gc(c, gc, pix, 0, 0); |
| 165 | |
| 166 | xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc, |
| 167 | img->width, img->height, 0, 0, 0, 32, |
| 168 | stride * img->height, (uint8_t *) img->pixels); |
| 169 | xcb_free_gc(c, gc); |
| 170 | |
| 171 | cursor = xcb_generate_id(c); |
| 172 | xcb_render_create_cursor(c, cursor, pic, img->xhot, img->yhot); |
| 173 | |
| 174 | xcb_render_free_picture(c, pic); |
| 175 | xcb_free_pixmap(c, pix); |
| 176 | |
| 177 | return cursor; |
| 178 | } |
| 179 | |
| 180 | static xcb_cursor_t |
| 181 | xcb_cursor_images_load_cursor(struct weston_wm *wm, const XcursorImages *images) |
| 182 | { |
| 183 | /* TODO: treat animated cursors as well */ |
| 184 | if (images->nimage != 1) |
| 185 | return -1; |
| 186 | |
| 187 | return xcb_cursor_image_load_cursor(wm, images->images[0]); |
| 188 | } |
| 189 | |
| 190 | static xcb_cursor_t |
| 191 | xcb_cursor_library_load_cursor(struct weston_wm *wm, const char *file) |
| 192 | { |
| 193 | xcb_cursor_t cursor; |
| 194 | XcursorImages *images; |
| 195 | char *v = NULL; |
| 196 | int size = 0; |
| 197 | |
| 198 | if (!file) |
| 199 | return 0; |
| 200 | |
| 201 | v = getenv ("XCURSOR_SIZE"); |
| 202 | if (v) |
| 203 | size = atoi(v); |
| 204 | |
| 205 | if (!size) |
| 206 | size = 32; |
| 207 | |
| 208 | images = XcursorLibraryLoadImages (file, NULL, size); |
Tiago Vignatti | ac78bb1 | 2012-09-28 16:29:46 +0300 | [diff] [blame] | 209 | if (!images) |
| 210 | return -1; |
| 211 | |
Tiago Vignatti | 90fada4 | 2012-07-16 12:02:08 -0400 | [diff] [blame] | 212 | cursor = xcb_cursor_images_load_cursor (wm, images); |
| 213 | XcursorImagesDestroy (images); |
| 214 | |
| 215 | return cursor; |
| 216 | } |
| 217 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 218 | void |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 219 | dump_property(struct weston_wm *wm, |
| 220 | xcb_atom_t property, xcb_get_property_reply_t *reply) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 221 | { |
| 222 | int32_t *incr_value; |
| 223 | const char *text_value, *name; |
| 224 | xcb_atom_t *atom_value; |
| 225 | int width, len; |
| 226 | uint32_t i; |
| 227 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 228 | width = weston_log_continue("%s: ", get_atom_name(wm->conn, property)); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 229 | if (reply == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 230 | weston_log_continue("(no reply)\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 231 | return; |
| 232 | } |
| 233 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 234 | width += weston_log_continue( |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 235 | "%s/%d, length %d (value_len %d): ", |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 236 | get_atom_name(wm->conn, reply->type), |
| 237 | reply->format, |
| 238 | xcb_get_property_value_length(reply), |
| 239 | reply->value_len); |
| 240 | |
| 241 | if (reply->type == wm->atom.incr) { |
| 242 | incr_value = xcb_get_property_value(reply); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 243 | weston_log_continue("%d\n", *incr_value); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 244 | } else if (reply->type == wm->atom.utf8_string || |
| 245 | reply->type == wm->atom.string) { |
| 246 | text_value = xcb_get_property_value(reply); |
| 247 | if (reply->value_len > 40) |
| 248 | len = 40; |
| 249 | else |
| 250 | len = reply->value_len; |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 251 | weston_log_continue("\"%.*s\"\n", len, text_value); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 252 | } else if (reply->type == XCB_ATOM_ATOM) { |
| 253 | atom_value = xcb_get_property_value(reply); |
| 254 | for (i = 0; i < reply->value_len; i++) { |
| 255 | name = get_atom_name(wm->conn, atom_value[i]); |
| 256 | if (width + strlen(name) + 2 > 78) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 257 | weston_log_continue("\n "); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 258 | width = 4; |
| 259 | } else if (i > 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 260 | width += weston_log_continue(", "); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 261 | } |
| 262 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 263 | width += weston_log_continue("%s", name); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 264 | } |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 265 | weston_log_continue("\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 266 | } else { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 267 | weston_log_continue("huh?\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
Tiago Vignatti | 2d129f1 | 2012-11-30 17:19:59 -0200 | [diff] [blame] | 271 | static void |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 272 | read_and_dump_property(struct weston_wm *wm, |
| 273 | xcb_window_t window, xcb_atom_t property) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 274 | { |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 275 | xcb_get_property_reply_t *reply; |
| 276 | xcb_get_property_cookie_t cookie; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 277 | |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 278 | cookie = xcb_get_property(wm->conn, 0, window, |
| 279 | property, XCB_ATOM_ANY, 0, 2048); |
| 280 | reply = xcb_get_property_reply(wm->conn, cookie, NULL); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 281 | |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 282 | dump_property(wm, property, reply); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 283 | |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 284 | free(reply); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /* We reuse some predefined, but otherwise useles atoms */ |
| 288 | #define TYPE_WM_PROTOCOLS XCB_ATOM_CUT_BUFFER0 |
| 289 | #define TYPE_MOTIF_WM_HINTS XCB_ATOM_CUT_BUFFER1 |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 290 | #define TYPE_NET_WM_STATE XCB_ATOM_CUT_BUFFER2 |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 291 | |
| 292 | static void |
| 293 | weston_wm_window_read_properties(struct weston_wm_window *window) |
| 294 | { |
| 295 | struct weston_wm *wm = window->wm; |
| 296 | |
| 297 | #define F(field) offsetof(struct weston_wm_window, field) |
| 298 | const struct { |
| 299 | xcb_atom_t atom; |
| 300 | xcb_atom_t type; |
| 301 | int offset; |
| 302 | } props[] = { |
| 303 | { XCB_ATOM_WM_CLASS, XCB_ATOM_STRING, F(class) }, |
| 304 | { XCB_ATOM_WM_NAME, XCB_ATOM_STRING, F(name) }, |
| 305 | { XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, F(transient_for) }, |
| 306 | { wm->atom.wm_protocols, TYPE_WM_PROTOCOLS, F(protocols) }, |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 307 | { wm->atom.net_wm_state, TYPE_NET_WM_STATE }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 308 | { wm->atom.net_wm_window_type, XCB_ATOM_ATOM, F(type) }, |
| 309 | { wm->atom.net_wm_name, XCB_ATOM_STRING, F(name) }, |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 310 | { wm->atom.net_wm_pid, XCB_ATOM_CARDINAL, F(pid) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 311 | { wm->atom.motif_wm_hints, TYPE_MOTIF_WM_HINTS, 0 }, |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 312 | { 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] | 313 | }; |
| 314 | #undef F |
| 315 | |
| 316 | xcb_get_property_cookie_t cookie[ARRAY_LENGTH(props)]; |
| 317 | xcb_get_property_reply_t *reply; |
| 318 | void *p; |
| 319 | uint32_t *xid; |
| 320 | xcb_atom_t *atom; |
| 321 | uint32_t i; |
| 322 | struct motif_wm_hints *hints; |
| 323 | |
| 324 | if (!window->properties_dirty) |
| 325 | return; |
| 326 | window->properties_dirty = 0; |
| 327 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 328 | for (i = 0; i < ARRAY_LENGTH(props); i++) |
| 329 | cookie[i] = xcb_get_property(wm->conn, |
| 330 | 0, /* delete */ |
| 331 | window->id, |
| 332 | props[i].atom, |
| 333 | XCB_ATOM_ANY, 0, 2048); |
| 334 | |
Tiago Vignatti | 2ea74d9 | 2012-07-20 23:09:53 +0300 | [diff] [blame] | 335 | window->decorate = !window->override_redirect; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 336 | for (i = 0; i < ARRAY_LENGTH(props); i++) { |
| 337 | reply = xcb_get_property_reply(wm->conn, cookie[i], NULL); |
| 338 | if (!reply) |
| 339 | /* Bad window, typically */ |
| 340 | continue; |
| 341 | if (reply->type == XCB_ATOM_NONE) { |
| 342 | /* No such property */ |
| 343 | free(reply); |
| 344 | continue; |
| 345 | } |
| 346 | |
| 347 | p = ((char *) window + props[i].offset); |
| 348 | |
| 349 | switch (props[i].type) { |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 350 | case XCB_ATOM_WM_CLIENT_MACHINE: |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 351 | case XCB_ATOM_STRING: |
| 352 | /* FIXME: We're using this for both string and |
| 353 | utf8_string */ |
| 354 | if (*(char **) p) |
| 355 | free(*(char **) p); |
| 356 | |
| 357 | *(char **) p = |
| 358 | strndup(xcb_get_property_value(reply), |
| 359 | xcb_get_property_value_length(reply)); |
| 360 | break; |
| 361 | case XCB_ATOM_WINDOW: |
| 362 | xid = xcb_get_property_value(reply); |
| 363 | *(struct weston_wm_window **) p = |
| 364 | hash_table_lookup(wm->window_hash, *xid); |
| 365 | break; |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 366 | case XCB_ATOM_CARDINAL: |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 367 | case XCB_ATOM_ATOM: |
| 368 | atom = xcb_get_property_value(reply); |
| 369 | *(xcb_atom_t *) p = *atom; |
| 370 | break; |
| 371 | case TYPE_WM_PROTOCOLS: |
| 372 | break; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 373 | case TYPE_NET_WM_STATE: |
| 374 | window->fullscreen = 0; |
| 375 | atom = xcb_get_property_value(reply); |
| 376 | for (i = 0; i < reply->value_len; i++) |
| 377 | if (atom[i] == wm->atom.net_wm_state_fullscreen) |
| 378 | window->fullscreen = 1; |
| 379 | break; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 380 | case TYPE_MOTIF_WM_HINTS: |
| 381 | hints = xcb_get_property_value(reply); |
| 382 | if (hints->flags & MWM_HINTS_DECORATIONS) |
| 383 | window->decorate = hints->decorations > 0; |
| 384 | break; |
| 385 | default: |
| 386 | break; |
| 387 | } |
| 388 | free(reply); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 393 | weston_wm_window_get_frame_size(struct weston_wm_window *window, |
| 394 | int *width, int *height) |
| 395 | { |
| 396 | struct theme *t = window->wm->theme; |
| 397 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 398 | if (window->fullscreen) { |
| 399 | *width = window->width; |
| 400 | *height = window->height; |
| 401 | } else if (window->decorate) { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 402 | *width = window->width + (t->margin + t->width) * 2; |
| 403 | *height = window->height + |
| 404 | t->margin * 2 + t->width + t->titlebar_height; |
| 405 | } else { |
| 406 | *width = window->width + t->margin * 2; |
| 407 | *height = window->height + t->margin * 2; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | static void |
| 412 | weston_wm_window_get_child_position(struct weston_wm_window *window, |
| 413 | int *x, int *y) |
| 414 | { |
| 415 | struct theme *t = window->wm->theme; |
| 416 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 417 | if (window->fullscreen) { |
| 418 | *x = 0; |
| 419 | *y = 0; |
| 420 | } else if (window->decorate) { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 421 | *x = t->margin + t->width; |
| 422 | *y = t->margin + t->titlebar_height; |
| 423 | } else { |
| 424 | *x = t->margin; |
| 425 | *y = t->margin; |
| 426 | } |
| 427 | } |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 428 | |
| 429 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 430 | weston_wm_window_send_configure_notify(struct weston_wm_window *window) |
| 431 | { |
| 432 | xcb_configure_notify_event_t configure_notify; |
| 433 | struct weston_wm *wm = window->wm; |
| 434 | int x, y; |
| 435 | |
| 436 | weston_wm_window_get_child_position(window, &x, &y); |
| 437 | configure_notify.response_type = XCB_CONFIGURE_NOTIFY; |
| 438 | configure_notify.pad0 = 0; |
| 439 | configure_notify.event = window->id; |
| 440 | configure_notify.window = window->id; |
| 441 | configure_notify.above_sibling = XCB_WINDOW_NONE; |
| 442 | configure_notify.x = x; |
| 443 | configure_notify.y = y; |
| 444 | configure_notify.width = window->width; |
| 445 | configure_notify.height = window->height; |
| 446 | configure_notify.border_width = 0; |
| 447 | configure_notify.override_redirect = 0; |
| 448 | configure_notify.pad1 = 0; |
| 449 | |
| 450 | xcb_send_event(wm->conn, 0, window->id, |
| 451 | XCB_EVENT_MASK_STRUCTURE_NOTIFY, |
| 452 | (char *) &configure_notify); |
| 453 | } |
| 454 | |
| 455 | static void |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 456 | weston_wm_handle_configure_request(struct weston_wm *wm, xcb_generic_event_t *event) |
| 457 | { |
| 458 | xcb_configure_request_event_t *configure_request = |
| 459 | (xcb_configure_request_event_t *) event; |
| 460 | struct weston_wm_window *window; |
| 461 | uint32_t mask, values[16]; |
| 462 | int x, y, width, height, i = 0; |
| 463 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 464 | weston_log("XCB_CONFIGURE_REQUEST (window %d) %d,%d @ %dx%d\n", |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 465 | configure_request->window, |
| 466 | configure_request->x, configure_request->y, |
| 467 | configure_request->width, configure_request->height); |
| 468 | |
| 469 | window = hash_table_lookup(wm->window_hash, configure_request->window); |
| 470 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 471 | if (window->fullscreen) { |
| 472 | weston_wm_window_send_configure_notify(window); |
| 473 | return; |
| 474 | } |
| 475 | |
Kristian Høgsberg | eaee784 | 2012-05-22 10:04:20 -0400 | [diff] [blame] | 476 | if (configure_request->value_mask & XCB_CONFIG_WINDOW_WIDTH) |
| 477 | window->width = configure_request->width; |
| 478 | if (configure_request->value_mask & XCB_CONFIG_WINDOW_HEIGHT) |
| 479 | window->height = configure_request->height; |
| 480 | |
| 481 | weston_wm_window_get_child_position(window, &x, &y); |
| 482 | values[i++] = x; |
| 483 | values[i++] = y; |
| 484 | values[i++] = window->width; |
| 485 | values[i++] = window->height; |
| 486 | values[i++] = 0; |
| 487 | mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | |
| 488 | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | |
| 489 | XCB_CONFIG_WINDOW_BORDER_WIDTH; |
| 490 | if (configure_request->value_mask & XCB_CONFIG_WINDOW_SIBLING) { |
| 491 | values[i++] = configure_request->sibling; |
| 492 | mask |= XCB_CONFIG_WINDOW_SIBLING; |
| 493 | } |
| 494 | if (configure_request->value_mask & XCB_CONFIG_WINDOW_STACK_MODE) { |
| 495 | values[i++] = configure_request->stack_mode; |
| 496 | mask |= XCB_CONFIG_WINDOW_STACK_MODE; |
| 497 | } |
| 498 | |
| 499 | xcb_configure_window(wm->conn, window->id, mask, values); |
| 500 | |
| 501 | weston_wm_window_get_frame_size(window, &width, &height); |
| 502 | values[0] = width; |
| 503 | values[1] = height; |
| 504 | mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; |
| 505 | xcb_configure_window(wm->conn, window->frame_id, mask, values); |
| 506 | |
| 507 | weston_wm_window_schedule_repaint(window); |
| 508 | } |
| 509 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 510 | static void |
| 511 | weston_wm_handle_configure_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 512 | { |
| 513 | xcb_configure_notify_event_t *configure_notify = |
| 514 | (xcb_configure_notify_event_t *) event; |
| 515 | struct weston_wm_window *window; |
Tiago Vignatti | e66fcee | 2012-07-20 23:09:54 +0300 | [diff] [blame] | 516 | int x, y; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 517 | |
| 518 | window = hash_table_lookup(wm->window_hash, configure_notify->window); |
| 519 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 520 | weston_log("XCB_CONFIGURE_NOTIFY (%s window %d) %d,%d @ %dx%d\n", |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 521 | configure_notify->window == window->id ? "client" : "frame", |
| 522 | configure_notify->window, |
| 523 | configure_notify->x, configure_notify->y, |
| 524 | configure_notify->width, configure_notify->height); |
Tiago Vignatti | e66fcee | 2012-07-20 23:09:54 +0300 | [diff] [blame] | 525 | |
| 526 | /* resize falls here */ |
| 527 | if (configure_notify->window != window->id) |
| 528 | return; |
| 529 | |
| 530 | weston_wm_window_get_child_position(window, &x, &y); |
| 531 | window->x = configure_notify->x - x; |
| 532 | window->y = configure_notify->y - y; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | static void |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 536 | weston_wm_kill_client(struct wl_listener *listener, void *data) |
| 537 | { |
| 538 | struct weston_surface *surface = data; |
| 539 | struct weston_wm_window *window = get_wm_window(surface); |
| 540 | char name[1024]; |
| 541 | |
| 542 | if (!window) |
| 543 | return; |
| 544 | |
| 545 | gethostname(name, 1024); |
| 546 | |
| 547 | /* this is only one heuristic to guess the PID of a client is valid, |
| 548 | * assuming it's compliant with icccm and ewmh. Non-compliants and |
| 549 | * remote applications of course fail. */ |
| 550 | if (!strcmp(window->machine, name) && window->pid != 0) |
| 551 | kill(window->pid, SIGKILL); |
| 552 | } |
| 553 | |
| 554 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 555 | weston_wm_window_activate(struct wl_listener *listener, void *data) |
| 556 | { |
| 557 | struct weston_surface *surface = data; |
| 558 | struct weston_wm_window *window = get_wm_window(surface); |
Scott Moreau | 85ecac0 | 2012-05-21 15:49:14 -0600 | [diff] [blame] | 559 | struct weston_wm *wm = |
| 560 | container_of(listener, struct weston_wm, activate_listener); |
| 561 | xcb_client_message_event_t client_message; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 562 | |
Scott Moreau | 85ecac0 | 2012-05-21 15:49:14 -0600 | [diff] [blame] | 563 | if (window) { |
| 564 | client_message.response_type = XCB_CLIENT_MESSAGE; |
| 565 | client_message.format = 32; |
| 566 | client_message.window = window->id; |
| 567 | client_message.type = wm->atom.wm_protocols; |
| 568 | client_message.data.data32[0] = wm->atom.wm_take_focus; |
| 569 | client_message.data.data32[1] = XCB_TIME_CURRENT_TIME; |
| 570 | |
| 571 | xcb_send_event(wm->conn, 0, window->id, |
| 572 | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, |
| 573 | (char *) &client_message); |
| 574 | |
| 575 | xcb_set_input_focus (wm->conn, XCB_INPUT_FOCUS_POINTER_ROOT, |
| 576 | window->id, XCB_TIME_CURRENT_TIME); |
| 577 | } else { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 578 | xcb_set_input_focus (wm->conn, |
| 579 | XCB_INPUT_FOCUS_POINTER_ROOT, |
| 580 | XCB_NONE, |
| 581 | XCB_TIME_CURRENT_TIME); |
Scott Moreau | 85ecac0 | 2012-05-21 15:49:14 -0600 | [diff] [blame] | 582 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 583 | |
| 584 | if (wm->focus_window) |
| 585 | weston_wm_window_schedule_repaint(wm->focus_window); |
| 586 | wm->focus_window = window; |
Tiago Vignatti | ce1baa8 | 2012-07-20 23:09:55 +0300 | [diff] [blame] | 587 | if (window) |
| 588 | wm->focus_latest = window; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 589 | if (wm->focus_window) |
| 590 | weston_wm_window_schedule_repaint(wm->focus_window); |
| 591 | } |
| 592 | |
| 593 | static int |
| 594 | our_resource(struct weston_wm *wm, uint32_t id) |
| 595 | { |
| 596 | const xcb_setup_t *setup; |
| 597 | |
| 598 | setup = xcb_get_setup(wm->conn); |
| 599 | |
| 600 | return (id & ~setup->resource_id_mask) == setup->resource_id_base; |
| 601 | } |
| 602 | |
Kristian Høgsberg | a6d9a5e | 2012-05-30 12:15:44 -0400 | [diff] [blame] | 603 | #define ICCCM_WITHDRAWN_STATE 0 |
| 604 | #define ICCCM_NORMAL_STATE 1 |
| 605 | #define ICCCM_ICONIC_STATE 3 |
| 606 | |
| 607 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 608 | 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] | 609 | { |
| 610 | struct weston_wm *wm = window->wm; |
| 611 | uint32_t property[2]; |
| 612 | |
| 613 | property[0] = state; |
| 614 | property[1] = XCB_WINDOW_NONE; |
| 615 | |
| 616 | xcb_change_property(wm->conn, |
| 617 | XCB_PROP_MODE_REPLACE, |
| 618 | window->id, |
| 619 | wm->atom.wm_state, |
| 620 | wm->atom.wm_state, |
| 621 | 32, /* format */ |
| 622 | 2, property); |
| 623 | } |
| 624 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 625 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 626 | weston_wm_window_set_net_wm_state(struct weston_wm_window *window) |
| 627 | { |
| 628 | struct weston_wm *wm = window->wm; |
| 629 | uint32_t property[1]; |
| 630 | int i; |
| 631 | |
| 632 | i = 0; |
| 633 | if (window->fullscreen) |
| 634 | property[i++] = wm->atom.net_wm_state_fullscreen; |
| 635 | |
| 636 | xcb_change_property(wm->conn, |
| 637 | XCB_PROP_MODE_REPLACE, |
| 638 | window->id, |
| 639 | wm->atom.net_wm_state, |
| 640 | XCB_ATOM_ATOM, |
| 641 | 32, /* format */ |
| 642 | i, property); |
| 643 | } |
| 644 | |
| 645 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 646 | weston_wm_handle_map_request(struct weston_wm *wm, xcb_generic_event_t *event) |
| 647 | { |
| 648 | xcb_map_request_event_t *map_request = |
| 649 | (xcb_map_request_event_t *) event; |
| 650 | struct weston_wm_window *window; |
| 651 | uint32_t values[1]; |
| 652 | int x, y, width, height; |
| 653 | |
| 654 | if (our_resource(wm, map_request->window)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 655 | weston_log("XCB_MAP_REQUEST (window %d, ours)\n", |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 656 | map_request->window); |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | window = hash_table_lookup(wm->window_hash, map_request->window); |
| 661 | |
Kristian Høgsberg | bc6e162 | 2012-05-30 09:59:56 -0400 | [diff] [blame] | 662 | if (window->frame_id) |
| 663 | return; |
| 664 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 665 | weston_wm_window_read_properties(window); |
| 666 | |
| 667 | weston_wm_window_get_frame_size(window, &width, &height); |
| 668 | weston_wm_window_get_child_position(window, &x, &y); |
| 669 | |
| 670 | values[0] = |
| 671 | XCB_EVENT_MASK_KEY_PRESS | |
| 672 | XCB_EVENT_MASK_KEY_RELEASE | |
| 673 | XCB_EVENT_MASK_BUTTON_PRESS | |
| 674 | XCB_EVENT_MASK_BUTTON_RELEASE | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 675 | XCB_EVENT_MASK_POINTER_MOTION | |
| 676 | XCB_EVENT_MASK_ENTER_WINDOW | |
| 677 | XCB_EVENT_MASK_LEAVE_WINDOW | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 678 | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | |
Kristian Høgsberg | 44c2013 | 2012-05-30 10:09:21 -0400 | [diff] [blame] | 679 | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 680 | |
| 681 | window->frame_id = xcb_generate_id(wm->conn); |
| 682 | xcb_create_window(wm->conn, |
| 683 | XCB_COPY_FROM_PARENT, |
| 684 | window->frame_id, |
| 685 | wm->screen->root, |
| 686 | 0, 0, |
| 687 | width, height, |
| 688 | 0, |
| 689 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
| 690 | wm->screen->root_visual, |
| 691 | XCB_CW_EVENT_MASK, values); |
| 692 | xcb_reparent_window(wm->conn, window->id, window->frame_id, x, y); |
| 693 | |
| 694 | values[0] = 0; |
| 695 | xcb_configure_window(wm->conn, window->id, |
| 696 | XCB_CONFIG_WINDOW_BORDER_WIDTH, values); |
| 697 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 698 | weston_log("XCB_MAP_REQUEST (window %d, %p, frame %d)\n", |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 699 | window->id, window, window->frame_id); |
| 700 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 701 | weston_wm_window_set_wm_state(window, ICCCM_NORMAL_STATE); |
| 702 | weston_wm_window_set_net_wm_state(window); |
| 703 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 704 | xcb_map_window(wm->conn, map_request->window); |
| 705 | xcb_map_window(wm->conn, window->frame_id); |
| 706 | |
| 707 | window->cairo_surface = |
| 708 | cairo_xcb_surface_create_with_xrender_format(wm->conn, |
| 709 | wm->screen, |
| 710 | window->frame_id, |
Kristian Høgsberg | e89cef3 | 2012-07-16 11:57:08 -0400 | [diff] [blame] | 711 | &wm->format_rgb, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 712 | width, height); |
| 713 | |
| 714 | hash_table_insert(wm->window_hash, window->frame_id, window); |
| 715 | } |
| 716 | |
| 717 | static void |
| 718 | weston_wm_handle_map_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 719 | { |
| 720 | xcb_map_notify_event_t *map_notify = (xcb_map_notify_event_t *) event; |
| 721 | |
| 722 | if (our_resource(wm, map_notify->window)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 723 | weston_log("XCB_MAP_NOTIFY (window %d, ours)\n", |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 724 | map_notify->window); |
| 725 | return; |
| 726 | } |
| 727 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 728 | weston_log("XCB_MAP_NOTIFY (window %d)\n", map_notify->window); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | static void |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 732 | weston_wm_handle_unmap_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 733 | { |
| 734 | xcb_unmap_notify_event_t *unmap_notify = |
| 735 | (xcb_unmap_notify_event_t *) event; |
| 736 | struct weston_wm_window *window; |
| 737 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 738 | weston_log("XCB_UNMAP_NOTIFY (window %d, event %d%s)\n", |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 739 | unmap_notify->window, |
| 740 | unmap_notify->event, |
| 741 | our_resource(wm, unmap_notify->window) ? ", ours" : ""); |
| 742 | |
| 743 | if (our_resource(wm, unmap_notify->window)) |
| 744 | return; |
| 745 | |
Kristian Høgsberg | d64bdf4 | 2012-05-31 10:33:43 -0400 | [diff] [blame] | 746 | if (unmap_notify->response_type & 0x80) |
| 747 | /* We just ignore the ICCCM 4.1.4 synthetic unmap notify |
| 748 | * as it may come in after we've destroyed the window. */ |
Kristian Høgsberg | f197e9f | 2012-05-30 11:46:29 -0400 | [diff] [blame] | 749 | return; |
Kristian Høgsberg | f197e9f | 2012-05-30 11:46:29 -0400 | [diff] [blame] | 750 | |
Kristian Høgsberg | d64bdf4 | 2012-05-31 10:33:43 -0400 | [diff] [blame] | 751 | window = hash_table_lookup(wm->window_hash, unmap_notify->window); |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 752 | if (window->repaint_source) |
| 753 | wl_event_source_remove(window->repaint_source); |
| 754 | if (window->cairo_surface) |
| 755 | cairo_surface_destroy(window->cairo_surface); |
| 756 | |
Kristian Høgsberg | be375b3 | 2012-06-05 11:46:08 -0400 | [diff] [blame] | 757 | if (window->frame_id) { |
| 758 | xcb_reparent_window(wm->conn, window->id, wm->wm_window, 0, 0); |
| 759 | xcb_destroy_window(wm->conn, window->frame_id); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 760 | weston_wm_window_set_wm_state(window, ICCCM_WITHDRAWN_STATE); |
Kristian Høgsberg | be375b3 | 2012-06-05 11:46:08 -0400 | [diff] [blame] | 761 | hash_table_remove(wm->window_hash, window->frame_id); |
| 762 | window->frame_id = XCB_WINDOW_NONE; |
| 763 | } |
Kristian Høgsberg | a6d9a5e | 2012-05-30 12:15:44 -0400 | [diff] [blame] | 764 | |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 765 | if (wm->focus_window == window) |
| 766 | wm->focus_window = NULL; |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 767 | if (window->surface) |
| 768 | wl_list_remove(&window->surface_destroy_listener.link); |
| 769 | window->surface = NULL; |
| 770 | } |
| 771 | |
| 772 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 773 | weston_wm_window_draw_decoration(void *data) |
| 774 | { |
| 775 | struct weston_wm_window *window = data; |
| 776 | struct weston_wm *wm = window->wm; |
| 777 | struct theme *t = wm->theme; |
| 778 | cairo_t *cr; |
| 779 | int x, y, width, height; |
| 780 | const char *title; |
| 781 | uint32_t flags = 0; |
| 782 | |
| 783 | weston_wm_window_read_properties(window); |
| 784 | |
| 785 | window->repaint_source = NULL; |
| 786 | |
| 787 | weston_wm_window_get_frame_size(window, &width, &height); |
| 788 | weston_wm_window_get_child_position(window, &x, &y); |
| 789 | |
| 790 | cairo_xcb_surface_set_size(window->cairo_surface, width, height); |
| 791 | cr = cairo_create(window->cairo_surface); |
| 792 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 793 | if (window->fullscreen) { |
| 794 | /* nothing */ |
| 795 | } else if (window->decorate) { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 796 | if (wm->focus_window == window) |
| 797 | flags |= THEME_FRAME_ACTIVE; |
| 798 | |
| 799 | if (window->name) |
| 800 | title = window->name; |
| 801 | else |
| 802 | title = "untitled"; |
| 803 | |
| 804 | theme_render_frame(t, cr, width, height, title, flags); |
| 805 | } else { |
| 806 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 807 | cairo_set_source_rgba(cr, 0, 0, 0, 0); |
| 808 | cairo_paint(cr); |
| 809 | |
| 810 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
| 811 | cairo_set_source_rgba(cr, 0, 0, 0, 0.45); |
| 812 | tile_mask(cr, t->shadow, 2, 2, width + 8, height + 8, 64, 64); |
| 813 | } |
| 814 | |
| 815 | cairo_destroy(cr); |
| 816 | |
| 817 | if (window->surface) { |
Scott Moreau | 76d8fc8 | 2012-11-22 15:35:13 -0700 | [diff] [blame] | 818 | pixman_region32_fini(&window->surface->pending.opaque); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 819 | /* We leave an extra pixel around the X window area to |
| 820 | * make sure we don't sample from the undefined alpha |
| 821 | * channel when filtering. */ |
Kristian Høgsberg | 25bb696 | 2013-02-14 22:01:04 -0500 | [diff] [blame] | 822 | pixman_region32_init_rect(&window->surface->pending.opaque, |
| 823 | x - 1, y - 1, |
| 824 | window->width + 2, |
| 825 | window->height + 2); |
Pekka Paalanen | 4f9c07b | 2012-09-03 16:48:41 +0300 | [diff] [blame] | 826 | window->surface->geometry.dirty = 1; |
Kristian Høgsberg | d8b617d | 2013-02-14 21:56:32 -0500 | [diff] [blame] | 827 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 828 | |
Kristian Høgsberg | d8b617d | 2013-02-14 21:56:32 -0500 | [diff] [blame] | 829 | if (window->surface && !window->fullscreen) { |
Kristian Høgsberg | 81585e9 | 2013-02-14 22:01:58 -0500 | [diff] [blame] | 830 | pixman_region32_fini(&window->surface->pending.input); |
Kristian Høgsberg | d8b617d | 2013-02-14 21:56:32 -0500 | [diff] [blame] | 831 | pixman_region32_init_rect(&window->surface->pending.input, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 832 | t->margin, t->margin, |
| 833 | width - 2 * t->margin, |
| 834 | height - 2 * t->margin); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | static void |
| 839 | weston_wm_window_schedule_repaint(struct weston_wm_window *window) |
| 840 | { |
| 841 | struct weston_wm *wm = window->wm; |
Pekka Paalanen | 4f9c07b | 2012-09-03 16:48:41 +0300 | [diff] [blame] | 842 | int width, height; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 843 | |
Kristian Høgsberg | c4063f3 | 2012-07-22 15:32:45 -0400 | [diff] [blame] | 844 | if (window->frame_id == XCB_WINDOW_NONE) { |
| 845 | if (window->surface != NULL) { |
Pekka Paalanen | 4f9c07b | 2012-09-03 16:48:41 +0300 | [diff] [blame] | 846 | weston_wm_window_get_frame_size(window, &width, &height); |
Scott Moreau | 76d8fc8 | 2012-11-22 15:35:13 -0700 | [diff] [blame] | 847 | pixman_region32_fini(&window->surface->pending.opaque); |
| 848 | pixman_region32_init_rect(&window->surface->pending.opaque, 0, 0, |
Pekka Paalanen | 4f9c07b | 2012-09-03 16:48:41 +0300 | [diff] [blame] | 849 | width, height); |
| 850 | window->surface->geometry.dirty = 1; |
Kristian Høgsberg | c4063f3 | 2012-07-22 15:32:45 -0400 | [diff] [blame] | 851 | } |
| 852 | return; |
| 853 | } |
| 854 | |
| 855 | if (window->repaint_source) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 856 | return; |
| 857 | |
| 858 | window->repaint_source = |
| 859 | wl_event_loop_add_idle(wm->server->loop, |
| 860 | weston_wm_window_draw_decoration, |
| 861 | window); |
| 862 | } |
| 863 | |
| 864 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 865 | weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 866 | { |
| 867 | xcb_property_notify_event_t *property_notify = |
| 868 | (xcb_property_notify_event_t *) event; |
| 869 | struct weston_wm_window *window; |
| 870 | |
| 871 | window = hash_table_lookup(wm->window_hash, property_notify->window); |
Rob Bradford | aa521bd | 2013-01-10 19:48:57 +0000 | [diff] [blame] | 872 | if (!window) |
| 873 | return; |
| 874 | |
| 875 | window->properties_dirty = 1; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 876 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 877 | weston_log("XCB_PROPERTY_NOTIFY: window %d, ", |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 878 | property_notify->window); |
Kristian Høgsberg | e244cb0 | 2012-05-30 11:34:35 -0400 | [diff] [blame] | 879 | if (property_notify->state == XCB_PROPERTY_DELETE) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 880 | weston_log("deleted\n"); |
Kristian Høgsberg | e244cb0 | 2012-05-30 11:34:35 -0400 | [diff] [blame] | 881 | else |
| 882 | read_and_dump_property(wm, property_notify->window, |
| 883 | property_notify->atom); |
Kristian Høgsberg | 0273b57 | 2012-05-30 09:58:02 -0400 | [diff] [blame] | 884 | |
| 885 | if (property_notify->atom == wm->atom.net_wm_name || |
| 886 | property_notify->atom == XCB_ATOM_WM_NAME) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 887 | weston_wm_window_schedule_repaint(window); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | static void |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 891 | weston_wm_window_create(struct weston_wm *wm, |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 892 | xcb_window_t id, int width, int height, int override) |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 893 | { |
| 894 | struct weston_wm_window *window; |
| 895 | uint32_t values[1]; |
| 896 | |
| 897 | window = malloc(sizeof *window); |
| 898 | if (window == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 899 | weston_log("failed to allocate window\n"); |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 900 | return; |
| 901 | } |
| 902 | |
| 903 | values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE; |
| 904 | xcb_change_window_attributes(wm->conn, id, XCB_CW_EVENT_MASK, values); |
| 905 | |
| 906 | memset(window, 0, sizeof *window); |
| 907 | window->wm = wm; |
| 908 | window->id = id; |
| 909 | window->properties_dirty = 1; |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 910 | window->override_redirect = override; |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 911 | window->width = width; |
| 912 | window->height = height; |
| 913 | |
| 914 | hash_table_insert(wm->window_hash, id, window); |
| 915 | } |
| 916 | |
| 917 | static void |
| 918 | weston_wm_window_destroy(struct weston_wm_window *window) |
| 919 | { |
| 920 | hash_table_remove(window->wm->window_hash, window->id); |
| 921 | free(window); |
| 922 | } |
| 923 | |
| 924 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 925 | weston_wm_handle_create_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 926 | { |
| 927 | xcb_create_notify_event_t *create_notify = |
| 928 | (xcb_create_notify_event_t *) event; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 929 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 930 | weston_log("XCB_CREATE_NOTIFY (window %d, width %d, height %d%s%s)\n", |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 931 | create_notify->window, |
| 932 | create_notify->width, create_notify->height, |
| 933 | create_notify->override_redirect ? ", override" : "", |
| 934 | our_resource(wm, create_notify->window) ? ", ours" : ""); |
| 935 | |
| 936 | if (our_resource(wm, create_notify->window)) |
| 937 | return; |
| 938 | |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 939 | weston_wm_window_create(wm, create_notify->window, |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 940 | create_notify->width, create_notify->height, |
| 941 | create_notify->override_redirect); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | static void |
| 945 | weston_wm_handle_destroy_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 946 | { |
| 947 | xcb_destroy_notify_event_t *destroy_notify = |
| 948 | (xcb_destroy_notify_event_t *) event; |
| 949 | struct weston_wm_window *window; |
| 950 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 951 | weston_log("XCB_DESTROY_NOTIFY, win %d, event %d%s\n", |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 952 | destroy_notify->window, |
| 953 | destroy_notify->event, |
| 954 | our_resource(wm, destroy_notify->window) ? ", ours" : ""); |
| 955 | |
| 956 | if (our_resource(wm, destroy_notify->window)) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 957 | return; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 958 | |
| 959 | window = hash_table_lookup(wm->window_hash, destroy_notify->window); |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 960 | weston_wm_window_destroy(window); |
| 961 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 962 | |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 963 | static void |
| 964 | weston_wm_handle_reparent_notify(struct weston_wm *wm, xcb_generic_event_t *event) |
| 965 | { |
| 966 | xcb_reparent_notify_event_t *reparent_notify = |
| 967 | (xcb_reparent_notify_event_t *) event; |
| 968 | struct weston_wm_window *window; |
Kristian Høgsberg | c9571fb | 2012-05-29 15:35:29 -0400 | [diff] [blame] | 969 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 970 | weston_log("XCB_REPARENT_NOTIFY (window %d, parent %d, event %d)\n", |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 971 | reparent_notify->window, |
| 972 | reparent_notify->parent, |
| 973 | reparent_notify->event); |
| 974 | |
| 975 | if (reparent_notify->parent == wm->screen->root) { |
Tiago Vignatti | 771241e | 2012-06-04 20:01:45 +0300 | [diff] [blame] | 976 | weston_wm_window_create(wm, reparent_notify->window, 10, 10, |
| 977 | reparent_notify->override_redirect); |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 978 | } else if (!our_resource(wm, reparent_notify->parent)) { |
| 979 | window = hash_table_lookup(wm->window_hash, |
| 980 | reparent_notify->window); |
| 981 | weston_wm_window_destroy(window); |
| 982 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 983 | } |
| 984 | |
Kristian Høgsberg | 5ba3189 | 2012-08-10 10:06:59 -0400 | [diff] [blame] | 985 | struct weston_seat * |
| 986 | weston_wm_pick_seat(struct weston_wm *wm) |
| 987 | { |
| 988 | return container_of(wm->server->compositor->seat_list.next, |
| 989 | struct weston_seat, link); |
| 990 | } |
| 991 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 992 | static void |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 993 | weston_wm_window_handle_moveresize(struct weston_wm_window *window, |
| 994 | xcb_client_message_event_t *client_message) |
| 995 | { |
| 996 | static const int map[] = { |
| 997 | THEME_LOCATION_RESIZING_TOP_LEFT, |
| 998 | THEME_LOCATION_RESIZING_TOP, |
| 999 | THEME_LOCATION_RESIZING_TOP_RIGHT, |
| 1000 | THEME_LOCATION_RESIZING_RIGHT, |
| 1001 | THEME_LOCATION_RESIZING_BOTTOM_RIGHT, |
| 1002 | THEME_LOCATION_RESIZING_BOTTOM, |
| 1003 | THEME_LOCATION_RESIZING_BOTTOM_LEFT, |
| 1004 | THEME_LOCATION_RESIZING_LEFT |
| 1005 | }; |
| 1006 | |
| 1007 | struct weston_wm *wm = window->wm; |
Kristian Høgsberg | 5ba3189 | 2012-08-10 10:06:59 -0400 | [diff] [blame] | 1008 | struct weston_seat *seat = weston_wm_pick_seat(wm); |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1009 | int detail; |
| 1010 | struct weston_shell_interface *shell_interface = |
| 1011 | &wm->server->compositor->shell_interface; |
| 1012 | |
| 1013 | if (seat->seat.pointer->button_count != 1 || |
| 1014 | seat->seat.pointer->focus != &window->surface->surface) |
| 1015 | return; |
| 1016 | |
| 1017 | detail = client_message->data.data32[2]; |
| 1018 | switch (detail) { |
| 1019 | case _NET_WM_MOVERESIZE_MOVE: |
| 1020 | shell_interface->move(window->shsurf, seat); |
| 1021 | break; |
| 1022 | case _NET_WM_MOVERESIZE_SIZE_TOPLEFT: |
| 1023 | case _NET_WM_MOVERESIZE_SIZE_TOP: |
| 1024 | case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT: |
| 1025 | case _NET_WM_MOVERESIZE_SIZE_RIGHT: |
| 1026 | case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT: |
| 1027 | case _NET_WM_MOVERESIZE_SIZE_BOTTOM: |
| 1028 | case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT: |
| 1029 | case _NET_WM_MOVERESIZE_SIZE_LEFT: |
| 1030 | shell_interface->resize(window->shsurf, seat, map[detail]); |
| 1031 | break; |
| 1032 | case _NET_WM_MOVERESIZE_CANCEL: |
| 1033 | break; |
| 1034 | } |
| 1035 | } |
| 1036 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1037 | #define _NET_WM_STATE_REMOVE 0 |
| 1038 | #define _NET_WM_STATE_ADD 1 |
| 1039 | #define _NET_WM_STATE_TOGGLE 2 |
| 1040 | |
| 1041 | static int |
| 1042 | update_state(int action, int *state) |
| 1043 | { |
| 1044 | int new_state, changed; |
| 1045 | |
| 1046 | switch (action) { |
| 1047 | case _NET_WM_STATE_REMOVE: |
| 1048 | new_state = 0; |
| 1049 | break; |
| 1050 | case _NET_WM_STATE_ADD: |
| 1051 | new_state = 1; |
| 1052 | break; |
| 1053 | case _NET_WM_STATE_TOGGLE: |
| 1054 | new_state = !*state; |
| 1055 | break; |
| 1056 | default: |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | changed = (*state != new_state); |
| 1061 | *state = new_state; |
| 1062 | |
| 1063 | return changed; |
| 1064 | } |
| 1065 | |
| 1066 | static void |
| 1067 | weston_wm_window_configure(void *data); |
| 1068 | |
| 1069 | static void |
| 1070 | weston_wm_window_handle_state(struct weston_wm_window *window, |
| 1071 | xcb_client_message_event_t *client_message) |
| 1072 | { |
| 1073 | struct weston_wm *wm = window->wm; |
| 1074 | struct weston_shell_interface *shell_interface = |
| 1075 | &wm->server->compositor->shell_interface; |
| 1076 | uint32_t action, property; |
| 1077 | |
| 1078 | action = client_message->data.data32[0]; |
| 1079 | property = client_message->data.data32[1]; |
| 1080 | |
| 1081 | if (property == wm->atom.net_wm_state_fullscreen && |
| 1082 | update_state(action, &window->fullscreen)) { |
| 1083 | weston_wm_window_set_net_wm_state(window); |
| 1084 | if (window->fullscreen) { |
| 1085 | window->saved_width = window->width; |
| 1086 | window->saved_height = window->height; |
Kristian Høgsberg | 762b166 | 2013-02-21 20:18:37 -0500 | [diff] [blame^] | 1087 | |
| 1088 | if (window->shsurf) |
| 1089 | shell_interface->set_fullscreen(window->shsurf, |
| 1090 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
| 1091 | 0, NULL); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1092 | } else { |
| 1093 | shell_interface->set_toplevel(window->shsurf); |
| 1094 | window->width = window->saved_width; |
| 1095 | window->height = window->saved_height; |
| 1096 | weston_wm_window_configure(window); |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1101 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1102 | weston_wm_handle_client_message(struct weston_wm *wm, |
| 1103 | xcb_generic_event_t *event) |
| 1104 | { |
| 1105 | xcb_client_message_event_t *client_message = |
| 1106 | (xcb_client_message_event_t *) event; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1107 | struct weston_wm_window *window; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1108 | |
| 1109 | window = hash_table_lookup(wm->window_hash, client_message->window); |
| 1110 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1111 | weston_log("XCB_CLIENT_MESSAGE (%s %d %d %d %d %d win %d)\n", |
| 1112 | get_atom_name(wm->conn, client_message->type), |
| 1113 | client_message->data.data32[0], |
| 1114 | client_message->data.data32[1], |
| 1115 | client_message->data.data32[2], |
| 1116 | client_message->data.data32[3], |
| 1117 | client_message->data.data32[4], |
| 1118 | client_message->window); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1119 | |
Kristian Høgsberg | e68fd10 | 2012-05-22 17:09:40 -0400 | [diff] [blame] | 1120 | if (client_message->type == wm->atom.net_wm_moveresize) |
| 1121 | weston_wm_window_handle_moveresize(window, client_message); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1122 | else if (client_message->type == wm->atom.net_wm_state) |
| 1123 | weston_wm_window_handle_state(window, client_message); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1126 | enum cursor_type { |
| 1127 | XWM_CURSOR_TOP, |
| 1128 | XWM_CURSOR_BOTTOM, |
| 1129 | XWM_CURSOR_LEFT, |
| 1130 | XWM_CURSOR_RIGHT, |
| 1131 | XWM_CURSOR_TOP_LEFT, |
| 1132 | XWM_CURSOR_TOP_RIGHT, |
| 1133 | XWM_CURSOR_BOTTOM_LEFT, |
| 1134 | XWM_CURSOR_BOTTOM_RIGHT, |
| 1135 | XWM_CURSOR_LEFT_PTR, |
| 1136 | }; |
| 1137 | |
| 1138 | static const char *cursors[] = { |
| 1139 | "top_side", |
| 1140 | "bottom_side", |
| 1141 | "left_side", |
| 1142 | "right_side", |
| 1143 | "top_left_corner", |
| 1144 | "top_right_corner", |
| 1145 | "bottom_left_corner", |
| 1146 | "bottom_right_corner", |
| 1147 | "left_ptr" |
| 1148 | }; |
| 1149 | |
| 1150 | static void |
| 1151 | weston_wm_create_cursors(struct weston_wm *wm) |
| 1152 | { |
| 1153 | int i, count = ARRAY_LENGTH(cursors); |
| 1154 | |
| 1155 | wm->cursors = malloc(count * sizeof(xcb_cursor_t)); |
| 1156 | for (i = 0; i < count; i++) { |
| 1157 | wm->cursors[i] = |
| 1158 | xcb_cursor_library_load_cursor(wm, cursors[i]); |
| 1159 | } |
| 1160 | |
| 1161 | wm->last_cursor = -1; |
| 1162 | } |
| 1163 | |
| 1164 | static void |
| 1165 | weston_wm_destroy_cursors(struct weston_wm *wm) |
| 1166 | { |
| 1167 | uint8_t i; |
| 1168 | |
| 1169 | for (i = 0; i < ARRAY_LENGTH(cursors); i++) |
| 1170 | xcb_free_cursor(wm->conn, wm->cursors[i]); |
| 1171 | |
| 1172 | free(wm->cursors); |
| 1173 | } |
| 1174 | |
| 1175 | static int |
| 1176 | get_cursor_for_location(struct theme *t, int width, int height, int x, int y) |
| 1177 | { |
Scott Moreau | c6a7e4b | 2012-09-28 02:45:06 -0600 | [diff] [blame] | 1178 | int location = theme_get_location(t, x, y, width, height, 0); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1179 | |
| 1180 | switch (location) { |
| 1181 | case THEME_LOCATION_RESIZING_TOP: |
| 1182 | return XWM_CURSOR_TOP; |
| 1183 | case THEME_LOCATION_RESIZING_BOTTOM: |
| 1184 | return XWM_CURSOR_BOTTOM; |
| 1185 | case THEME_LOCATION_RESIZING_LEFT: |
| 1186 | return XWM_CURSOR_LEFT; |
| 1187 | case THEME_LOCATION_RESIZING_RIGHT: |
| 1188 | return XWM_CURSOR_RIGHT; |
| 1189 | case THEME_LOCATION_RESIZING_TOP_LEFT: |
| 1190 | return XWM_CURSOR_TOP_LEFT; |
| 1191 | case THEME_LOCATION_RESIZING_TOP_RIGHT: |
| 1192 | return XWM_CURSOR_TOP_RIGHT; |
| 1193 | case THEME_LOCATION_RESIZING_BOTTOM_LEFT: |
| 1194 | return XWM_CURSOR_BOTTOM_LEFT; |
| 1195 | case THEME_LOCATION_RESIZING_BOTTOM_RIGHT: |
| 1196 | return XWM_CURSOR_BOTTOM_RIGHT; |
| 1197 | case THEME_LOCATION_EXTERIOR: |
| 1198 | case THEME_LOCATION_TITLEBAR: |
| 1199 | default: |
| 1200 | return XWM_CURSOR_LEFT_PTR; |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | static void |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1205 | weston_wm_window_set_cursor(struct weston_wm *wm, xcb_window_t window_id, |
| 1206 | int cursor) |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1207 | { |
| 1208 | uint32_t cursor_value_list; |
| 1209 | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1210 | if (wm->last_cursor == cursor) |
| 1211 | return; |
| 1212 | |
| 1213 | wm->last_cursor = cursor; |
| 1214 | |
| 1215 | cursor_value_list = wm->cursors[cursor]; |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1216 | xcb_change_window_attributes (wm->conn, window_id, |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1217 | XCB_CW_CURSOR, &cursor_value_list); |
| 1218 | xcb_flush(wm->conn); |
| 1219 | } |
| 1220 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1221 | static void |
| 1222 | weston_wm_handle_button(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1223 | { |
| 1224 | xcb_button_press_event_t *button = (xcb_button_press_event_t *) event; |
| 1225 | struct weston_shell_interface *shell_interface = |
| 1226 | &wm->server->compositor->shell_interface; |
Kristian Høgsberg | 5ba3189 | 2012-08-10 10:06:59 -0400 | [diff] [blame] | 1227 | struct weston_seat *seat = weston_wm_pick_seat(wm); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1228 | struct weston_wm_window *window; |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 1229 | enum theme_location location; |
| 1230 | struct theme *t = wm->theme; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 1231 | int width, height; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1232 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1233 | weston_log("XCB_BUTTON_%s (detail %d)\n", |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1234 | button->response_type == XCB_BUTTON_PRESS ? |
| 1235 | "PRESS" : "RELEASE", button->detail); |
| 1236 | |
| 1237 | window = hash_table_lookup(wm->window_hash, button->event); |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 1238 | weston_wm_window_get_frame_size(window, &width, &height); |
| 1239 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1240 | if (button->response_type == XCB_BUTTON_PRESS && |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 1241 | button->detail == 1) { |
| 1242 | location = theme_get_location(t, |
| 1243 | button->event_x, |
| 1244 | button->event_y, |
Scott Moreau | c6a7e4b | 2012-09-28 02:45:06 -0600 | [diff] [blame] | 1245 | width, height, 0); |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 1246 | |
| 1247 | switch (location) { |
| 1248 | case THEME_LOCATION_TITLEBAR: |
Kristian Høgsberg | 5ba3189 | 2012-08-10 10:06:59 -0400 | [diff] [blame] | 1249 | shell_interface->move(window->shsurf, seat); |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 1250 | break; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 1251 | case THEME_LOCATION_RESIZING_TOP: |
| 1252 | case THEME_LOCATION_RESIZING_BOTTOM: |
| 1253 | case THEME_LOCATION_RESIZING_LEFT: |
| 1254 | case THEME_LOCATION_RESIZING_RIGHT: |
| 1255 | case THEME_LOCATION_RESIZING_TOP_LEFT: |
| 1256 | case THEME_LOCATION_RESIZING_TOP_RIGHT: |
| 1257 | case THEME_LOCATION_RESIZING_BOTTOM_LEFT: |
| 1258 | case THEME_LOCATION_RESIZING_BOTTOM_RIGHT: |
| 1259 | shell_interface->resize(window->shsurf, |
Kristian Høgsberg | 5ba3189 | 2012-08-10 10:06:59 -0400 | [diff] [blame] | 1260 | seat, location); |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 1261 | break; |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 1262 | default: |
| 1263 | break; |
| 1264 | } |
| 1265 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1266 | } |
| 1267 | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1268 | static void |
| 1269 | weston_wm_handle_motion(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1270 | { |
| 1271 | xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *) event; |
| 1272 | struct weston_wm_window *window; |
| 1273 | int cursor, width, height; |
| 1274 | |
| 1275 | window = hash_table_lookup(wm->window_hash, motion->event); |
Tiago Vignatti | 9134b77 | 2012-07-20 19:41:12 +0300 | [diff] [blame] | 1276 | if (!window || !window->decorate) |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1277 | return; |
| 1278 | |
| 1279 | weston_wm_window_get_frame_size(window, &width, &height); |
| 1280 | cursor = get_cursor_for_location(wm->theme, width, height, |
| 1281 | motion->event_x, motion->event_y); |
| 1282 | |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1283 | weston_wm_window_set_cursor(wm, window->frame_id, cursor); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | static void |
| 1287 | weston_wm_handle_enter(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1288 | { |
| 1289 | xcb_enter_notify_event_t *enter = (xcb_enter_notify_event_t *) event; |
| 1290 | struct weston_wm_window *window; |
| 1291 | int cursor, width, height; |
| 1292 | |
| 1293 | window = hash_table_lookup(wm->window_hash, enter->event); |
Tiago Vignatti | 9134b77 | 2012-07-20 19:41:12 +0300 | [diff] [blame] | 1294 | if (!window || !window->decorate) |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1295 | return; |
| 1296 | |
| 1297 | weston_wm_window_get_frame_size(window, &width, &height); |
| 1298 | cursor = get_cursor_for_location(wm->theme, width, height, |
| 1299 | enter->event_x, enter->event_y); |
| 1300 | |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1301 | weston_wm_window_set_cursor(wm, window->frame_id, cursor); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | static void |
| 1305 | weston_wm_handle_leave(struct weston_wm *wm, xcb_generic_event_t *event) |
| 1306 | { |
| 1307 | xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *) event; |
| 1308 | struct weston_wm_window *window; |
| 1309 | |
| 1310 | window = hash_table_lookup(wm->window_hash, leave->event); |
Tiago Vignatti | 9134b77 | 2012-07-20 19:41:12 +0300 | [diff] [blame] | 1311 | if (!window || !window->decorate) |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1312 | return; |
| 1313 | |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1314 | 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] | 1315 | } |
| 1316 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1317 | static int |
| 1318 | weston_wm_handle_event(int fd, uint32_t mask, void *data) |
| 1319 | { |
| 1320 | struct weston_wm *wm = data; |
| 1321 | xcb_generic_event_t *event; |
| 1322 | int count = 0; |
| 1323 | |
| 1324 | while (event = xcb_poll_for_event(wm->conn), event != NULL) { |
| 1325 | if (weston_wm_handle_selection_event(wm, event)) { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1326 | free(event); |
| 1327 | count++; |
| 1328 | continue; |
| 1329 | } |
| 1330 | |
Kristian Høgsberg | f197e9f | 2012-05-30 11:46:29 -0400 | [diff] [blame] | 1331 | switch (event->response_type & ~0x80) { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1332 | case XCB_BUTTON_PRESS: |
| 1333 | case XCB_BUTTON_RELEASE: |
| 1334 | weston_wm_handle_button(wm, event); |
| 1335 | break; |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1336 | case XCB_ENTER_NOTIFY: |
| 1337 | weston_wm_handle_enter(wm, event); |
| 1338 | break; |
| 1339 | case XCB_LEAVE_NOTIFY: |
| 1340 | weston_wm_handle_leave(wm, event); |
| 1341 | break; |
| 1342 | case XCB_MOTION_NOTIFY: |
| 1343 | weston_wm_handle_motion(wm, event); |
| 1344 | break; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1345 | case XCB_CREATE_NOTIFY: |
| 1346 | weston_wm_handle_create_notify(wm, event); |
| 1347 | break; |
| 1348 | case XCB_MAP_REQUEST: |
| 1349 | weston_wm_handle_map_request(wm, event); |
| 1350 | break; |
| 1351 | case XCB_MAP_NOTIFY: |
| 1352 | weston_wm_handle_map_notify(wm, event); |
| 1353 | break; |
| 1354 | case XCB_UNMAP_NOTIFY: |
Kristian Høgsberg | 194ea54 | 2012-05-30 10:05:41 -0400 | [diff] [blame] | 1355 | weston_wm_handle_unmap_notify(wm, event); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1356 | break; |
Kristian Høgsberg | 029539b | 2012-05-30 11:28:24 -0400 | [diff] [blame] | 1357 | case XCB_REPARENT_NOTIFY: |
| 1358 | weston_wm_handle_reparent_notify(wm, event); |
| 1359 | break; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1360 | case XCB_CONFIGURE_REQUEST: |
| 1361 | weston_wm_handle_configure_request(wm, event); |
| 1362 | break; |
| 1363 | case XCB_CONFIGURE_NOTIFY: |
| 1364 | weston_wm_handle_configure_notify(wm, event); |
| 1365 | break; |
| 1366 | case XCB_DESTROY_NOTIFY: |
| 1367 | weston_wm_handle_destroy_notify(wm, event); |
| 1368 | break; |
| 1369 | case XCB_MAPPING_NOTIFY: |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1370 | weston_log("XCB_MAPPING_NOTIFY\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1371 | break; |
| 1372 | case XCB_PROPERTY_NOTIFY: |
| 1373 | weston_wm_handle_property_notify(wm, event); |
| 1374 | break; |
| 1375 | case XCB_CLIENT_MESSAGE: |
| 1376 | weston_wm_handle_client_message(wm, event); |
| 1377 | break; |
| 1378 | } |
| 1379 | |
| 1380 | free(event); |
| 1381 | count++; |
| 1382 | } |
| 1383 | |
| 1384 | xcb_flush(wm->conn); |
| 1385 | |
| 1386 | return count; |
| 1387 | } |
| 1388 | |
| 1389 | static void |
Tiago Vignatti | 9c4ff83 | 2012-11-30 17:19:57 -0200 | [diff] [blame] | 1390 | weston_wm_get_resources(struct weston_wm *wm) |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1391 | { |
| 1392 | |
| 1393 | #define F(field) offsetof(struct weston_wm, field) |
| 1394 | |
| 1395 | static const struct { const char *name; int offset; } atoms[] = { |
| 1396 | { "WM_PROTOCOLS", F(atom.wm_protocols) }, |
| 1397 | { "WM_TAKE_FOCUS", F(atom.wm_take_focus) }, |
| 1398 | { "WM_DELETE_WINDOW", F(atom.wm_delete_window) }, |
Kristian Høgsberg | a6d9a5e | 2012-05-30 12:15:44 -0400 | [diff] [blame] | 1399 | { "WM_STATE", F(atom.wm_state) }, |
Kristian Høgsberg | 670b5d3 | 2012-06-04 11:00:40 -0400 | [diff] [blame] | 1400 | { "WM_S0", F(atom.wm_s0) }, |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 1401 | { "WM_CLIENT_MACHINE", F(atom.wm_client_machine) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1402 | { "_NET_WM_NAME", F(atom.net_wm_name) }, |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 1403 | { "_NET_WM_PID", F(atom.net_wm_pid) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1404 | { "_NET_WM_ICON", F(atom.net_wm_icon) }, |
| 1405 | { "_NET_WM_STATE", F(atom.net_wm_state) }, |
| 1406 | { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) }, |
| 1407 | { "_NET_WM_USER_TIME", F(atom.net_wm_user_time) }, |
| 1408 | { "_NET_WM_ICON_NAME", F(atom.net_wm_icon_name) }, |
| 1409 | { "_NET_WM_WINDOW_TYPE", F(atom.net_wm_window_type) }, |
| 1410 | |
| 1411 | { "_NET_WM_WINDOW_TYPE_DESKTOP", F(atom.net_wm_window_type_desktop) }, |
| 1412 | { "_NET_WM_WINDOW_TYPE_DOCK", F(atom.net_wm_window_type_dock) }, |
| 1413 | { "_NET_WM_WINDOW_TYPE_TOOLBAR", F(atom.net_wm_window_type_toolbar) }, |
| 1414 | { "_NET_WM_WINDOW_TYPE_MENU", F(atom.net_wm_window_type_menu) }, |
| 1415 | { "_NET_WM_WINDOW_TYPE_UTILITY", F(atom.net_wm_window_type_utility) }, |
| 1416 | { "_NET_WM_WINDOW_TYPE_SPLASH", F(atom.net_wm_window_type_splash) }, |
| 1417 | { "_NET_WM_WINDOW_TYPE_DIALOG", F(atom.net_wm_window_type_dialog) }, |
Tiago Vignatti | bf1e866 | 2012-06-12 14:07:49 +0300 | [diff] [blame] | 1418 | { "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", F(atom.net_wm_window_type_dropdown) }, |
| 1419 | { "_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] | 1420 | { "_NET_WM_WINDOW_TYPE_TOOLTIP", F(atom.net_wm_window_type_tooltip) }, |
| 1421 | { "_NET_WM_WINDOW_TYPE_NOTIFICATION", F(atom.net_wm_window_type_notification) }, |
| 1422 | { "_NET_WM_WINDOW_TYPE_COMBO", F(atom.net_wm_window_type_combo) }, |
| 1423 | { "_NET_WM_WINDOW_TYPE_DND", F(atom.net_wm_window_type_dnd) }, |
| 1424 | { "_NET_WM_WINDOW_TYPE_NORMAL", F(atom.net_wm_window_type_normal) }, |
| 1425 | |
| 1426 | { "_NET_WM_MOVERESIZE", F(atom.net_wm_moveresize) }, |
| 1427 | { "_NET_SUPPORTING_WM_CHECK", |
| 1428 | F(atom.net_supporting_wm_check) }, |
| 1429 | { "_NET_SUPPORTED", F(atom.net_supported) }, |
| 1430 | { "_MOTIF_WM_HINTS", F(atom.motif_wm_hints) }, |
| 1431 | { "CLIPBOARD", F(atom.clipboard) }, |
Kristian Høgsberg | cba022a | 2012-06-04 10:11:45 -0400 | [diff] [blame] | 1432 | { "CLIPBOARD_MANAGER", F(atom.clipboard_manager) }, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1433 | { "TARGETS", F(atom.targets) }, |
| 1434 | { "UTF8_STRING", F(atom.utf8_string) }, |
| 1435 | { "_WL_SELECTION", F(atom.wl_selection) }, |
| 1436 | { "INCR", F(atom.incr) }, |
| 1437 | { "TIMESTAMP", F(atom.timestamp) }, |
| 1438 | { "MULTIPLE", F(atom.multiple) }, |
| 1439 | { "UTF8_STRING" , F(atom.utf8_string) }, |
| 1440 | { "COMPOUND_TEXT", F(atom.compound_text) }, |
| 1441 | { "TEXT", F(atom.text) }, |
| 1442 | { "STRING", F(atom.string) }, |
| 1443 | { "text/plain;charset=utf-8", F(atom.text_plain_utf8) }, |
| 1444 | { "text/plain", F(atom.text_plain) }, |
| 1445 | }; |
| 1446 | #undef F |
| 1447 | |
| 1448 | xcb_xfixes_query_version_cookie_t xfixes_cookie; |
| 1449 | xcb_xfixes_query_version_reply_t *xfixes_reply; |
| 1450 | xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)]; |
| 1451 | xcb_intern_atom_reply_t *reply; |
| 1452 | xcb_render_query_pict_formats_reply_t *formats_reply; |
| 1453 | xcb_render_query_pict_formats_cookie_t formats_cookie; |
| 1454 | xcb_render_pictforminfo_t *formats; |
| 1455 | uint32_t i; |
| 1456 | |
| 1457 | xcb_prefetch_extension_data (wm->conn, &xcb_xfixes_id); |
| 1458 | |
| 1459 | formats_cookie = xcb_render_query_pict_formats(wm->conn); |
| 1460 | |
| 1461 | for (i = 0; i < ARRAY_LENGTH(atoms); i++) |
| 1462 | cookies[i] = xcb_intern_atom (wm->conn, 0, |
| 1463 | strlen(atoms[i].name), |
| 1464 | atoms[i].name); |
| 1465 | |
| 1466 | for (i = 0; i < ARRAY_LENGTH(atoms); i++) { |
| 1467 | reply = xcb_intern_atom_reply (wm->conn, cookies[i], NULL); |
| 1468 | *(xcb_atom_t *) ((char *) wm + atoms[i].offset) = reply->atom; |
| 1469 | free(reply); |
| 1470 | } |
| 1471 | |
| 1472 | wm->xfixes = xcb_get_extension_data(wm->conn, &xcb_xfixes_id); |
| 1473 | if (!wm->xfixes || !wm->xfixes->present) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1474 | weston_log("xfixes not available\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1475 | |
| 1476 | xfixes_cookie = xcb_xfixes_query_version(wm->conn, |
| 1477 | XCB_XFIXES_MAJOR_VERSION, |
| 1478 | XCB_XFIXES_MINOR_VERSION); |
| 1479 | xfixes_reply = xcb_xfixes_query_version_reply(wm->conn, |
| 1480 | xfixes_cookie, NULL); |
| 1481 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1482 | weston_log("xfixes version: %d.%d\n", |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1483 | xfixes_reply->major_version, xfixes_reply->minor_version); |
| 1484 | |
| 1485 | free(xfixes_reply); |
| 1486 | |
| 1487 | formats_reply = xcb_render_query_pict_formats_reply(wm->conn, |
| 1488 | formats_cookie, 0); |
| 1489 | if (formats_reply == NULL) |
| 1490 | return; |
| 1491 | |
| 1492 | formats = xcb_render_query_pict_formats_formats(formats_reply); |
Kristian Høgsberg | e89cef3 | 2012-07-16 11:57:08 -0400 | [diff] [blame] | 1493 | for (i = 0; i < formats_reply->num_formats; i++) { |
| 1494 | if (formats[i].direct.red_mask != 0xff && |
| 1495 | formats[i].direct.red_shift != 16) |
| 1496 | continue; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1497 | if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT && |
| 1498 | formats[i].depth == 24) |
Kristian Høgsberg | e89cef3 | 2012-07-16 11:57:08 -0400 | [diff] [blame] | 1499 | wm->format_rgb = formats[i]; |
| 1500 | if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT && |
| 1501 | formats[i].depth == 32 && |
| 1502 | formats[i].direct.alpha_mask == 0xff && |
| 1503 | formats[i].direct.alpha_shift == 24) |
| 1504 | wm->format_rgba = formats[i]; |
| 1505 | } |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1506 | |
| 1507 | free(formats_reply); |
| 1508 | } |
| 1509 | |
| 1510 | static void |
| 1511 | weston_wm_create_wm_window(struct weston_wm *wm) |
| 1512 | { |
| 1513 | static const char name[] = "Weston WM"; |
| 1514 | |
| 1515 | wm->wm_window = xcb_generate_id(wm->conn); |
| 1516 | xcb_create_window(wm->conn, |
| 1517 | XCB_COPY_FROM_PARENT, |
| 1518 | wm->wm_window, |
| 1519 | wm->screen->root, |
| 1520 | 0, 0, |
| 1521 | 10, 10, |
| 1522 | 0, |
| 1523 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
| 1524 | wm->screen->root_visual, |
| 1525 | 0, NULL); |
| 1526 | |
| 1527 | xcb_change_property(wm->conn, |
| 1528 | XCB_PROP_MODE_REPLACE, |
| 1529 | wm->wm_window, |
| 1530 | wm->atom.net_supporting_wm_check, |
| 1531 | XCB_ATOM_WINDOW, |
| 1532 | 32, /* format */ |
| 1533 | 1, &wm->wm_window); |
| 1534 | |
| 1535 | xcb_change_property(wm->conn, |
| 1536 | XCB_PROP_MODE_REPLACE, |
| 1537 | wm->wm_window, |
| 1538 | wm->atom.net_wm_name, |
| 1539 | wm->atom.utf8_string, |
| 1540 | 8, /* format */ |
| 1541 | strlen(name), name); |
| 1542 | |
| 1543 | xcb_change_property(wm->conn, |
| 1544 | XCB_PROP_MODE_REPLACE, |
| 1545 | wm->screen->root, |
| 1546 | wm->atom.net_supporting_wm_check, |
| 1547 | XCB_ATOM_WINDOW, |
| 1548 | 32, /* format */ |
| 1549 | 1, &wm->wm_window); |
| 1550 | |
Kristian Høgsberg | 670b5d3 | 2012-06-04 11:00:40 -0400 | [diff] [blame] | 1551 | /* Claim the WM_S0 selection even though we don't suport |
| 1552 | * the --replace functionality. */ |
| 1553 | xcb_set_selection_owner(wm->conn, |
| 1554 | wm->wm_window, |
| 1555 | wm->atom.wm_s0, |
| 1556 | XCB_TIME_CURRENT_TIME); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | struct weston_wm * |
| 1560 | weston_wm_create(struct weston_xserver *wxs) |
| 1561 | { |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1562 | struct weston_wm *wm; |
| 1563 | struct wl_event_loop *loop; |
| 1564 | xcb_screen_iterator_t s; |
Kristian Høgsberg | 4dec011 | 2012-06-03 09:18:06 -0400 | [diff] [blame] | 1565 | uint32_t values[1]; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1566 | int sv[2]; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1567 | xcb_atom_t supported[3]; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1568 | |
| 1569 | wm = malloc(sizeof *wm); |
| 1570 | if (wm == NULL) |
| 1571 | return NULL; |
| 1572 | |
| 1573 | memset(wm, 0, sizeof *wm); |
| 1574 | wm->server = wxs; |
| 1575 | wm->window_hash = hash_table_create(); |
| 1576 | if (wm->window_hash == NULL) { |
| 1577 | free(wm); |
| 1578 | return NULL; |
| 1579 | } |
| 1580 | |
| 1581 | if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1582 | weston_log("socketpair failed\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1583 | hash_table_destroy(wm->window_hash); |
| 1584 | free(wm); |
| 1585 | return NULL; |
| 1586 | } |
| 1587 | |
| 1588 | xserver_send_client(wxs->resource, sv[1]); |
| 1589 | wl_client_flush(wxs->resource->client); |
| 1590 | close(sv[1]); |
| 1591 | |
| 1592 | /* xcb_connect_to_fd takes ownership of the fd. */ |
| 1593 | wm->conn = xcb_connect_to_fd(sv[0], NULL); |
| 1594 | if (xcb_connection_has_error(wm->conn)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1595 | weston_log("xcb_connect_to_fd failed\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1596 | close(sv[0]); |
| 1597 | hash_table_destroy(wm->window_hash); |
| 1598 | free(wm); |
| 1599 | return NULL; |
| 1600 | } |
| 1601 | |
| 1602 | s = xcb_setup_roots_iterator(xcb_get_setup(wm->conn)); |
| 1603 | wm->screen = s.data; |
| 1604 | |
| 1605 | loop = wl_display_get_event_loop(wxs->wl_display); |
| 1606 | wm->source = |
| 1607 | wl_event_loop_add_fd(loop, sv[0], |
| 1608 | WL_EVENT_READABLE, |
| 1609 | weston_wm_handle_event, wm); |
| 1610 | wl_event_source_check(wm->source); |
| 1611 | |
Tiago Vignatti | 9c4ff83 | 2012-11-30 17:19:57 -0200 | [diff] [blame] | 1612 | weston_wm_get_resources(wm); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1613 | |
| 1614 | values[0] = |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1615 | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | |
| 1616 | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | |
| 1617 | XCB_EVENT_MASK_PROPERTY_CHANGE; |
| 1618 | xcb_change_window_attributes(wm->conn, wm->screen->root, |
| 1619 | XCB_CW_EVENT_MASK, values); |
| 1620 | wm->theme = theme_create(); |
| 1621 | |
| 1622 | weston_wm_create_wm_window(wm); |
| 1623 | |
| 1624 | supported[0] = wm->atom.net_wm_moveresize; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1625 | supported[1] = wm->atom.net_wm_state; |
| 1626 | supported[2] = wm->atom.net_wm_state_fullscreen; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1627 | xcb_change_property(wm->conn, |
| 1628 | XCB_PROP_MODE_REPLACE, |
| 1629 | wm->screen->root, |
| 1630 | wm->atom.net_supported, |
| 1631 | XCB_ATOM_ATOM, |
| 1632 | 32, /* format */ |
| 1633 | ARRAY_LENGTH(supported), supported); |
| 1634 | |
Kristian Høgsberg | 4dec011 | 2012-06-03 09:18:06 -0400 | [diff] [blame] | 1635 | weston_wm_selection_init(wm); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1636 | |
| 1637 | xcb_flush(wm->conn); |
| 1638 | |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1639 | wm->activate_listener.notify = weston_wm_window_activate; |
| 1640 | wl_signal_add(&wxs->compositor->activate_signal, |
| 1641 | &wm->activate_listener); |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 1642 | wm->kill_listener.notify = weston_wm_kill_client; |
| 1643 | wl_signal_add(&wxs->compositor->kill_signal, |
| 1644 | &wm->kill_listener); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1645 | |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1646 | weston_wm_create_cursors(wm); |
Tiago Vignatti | c190323 | 2012-07-16 12:15:37 -0400 | [diff] [blame] | 1647 | 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] | 1648 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1649 | weston_log("created wm\n"); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1650 | |
| 1651 | return wm; |
| 1652 | } |
| 1653 | |
| 1654 | void |
| 1655 | weston_wm_destroy(struct weston_wm *wm) |
| 1656 | { |
| 1657 | /* FIXME: Free windows in hash. */ |
| 1658 | hash_table_destroy(wm->window_hash); |
Tiago Vignatti | 236b48d | 2012-07-16 12:09:19 -0400 | [diff] [blame] | 1659 | weston_wm_destroy_cursors(wm); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1660 | xcb_disconnect(wm->conn); |
| 1661 | wl_event_source_remove(wm->source); |
| 1662 | wl_list_remove(&wm->selection_listener.link); |
| 1663 | wl_list_remove(&wm->activate_listener.link); |
Tiago Vignatti | 0d20d7c | 2012-09-27 17:48:37 +0300 | [diff] [blame] | 1664 | wl_list_remove(&wm->kill_listener.link); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1665 | |
| 1666 | free(wm); |
| 1667 | } |
| 1668 | |
| 1669 | static void |
| 1670 | surface_destroy(struct wl_listener *listener, void *data) |
| 1671 | { |
| 1672 | struct weston_wm_window *window = |
| 1673 | container_of(listener, |
| 1674 | struct weston_wm_window, surface_destroy_listener); |
| 1675 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1676 | weston_log("surface for xid %d destroyed\n", window->id); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | static struct weston_wm_window * |
| 1680 | get_wm_window(struct weston_surface *surface) |
| 1681 | { |
| 1682 | struct wl_resource *resource = &surface->surface.resource; |
| 1683 | struct wl_listener *listener; |
| 1684 | |
| 1685 | listener = wl_signal_get(&resource->destroy_signal, surface_destroy); |
| 1686 | if (listener) |
| 1687 | return container_of(listener, struct weston_wm_window, |
| 1688 | surface_destroy_listener); |
| 1689 | |
| 1690 | return NULL; |
| 1691 | } |
| 1692 | |
| 1693 | static void |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1694 | weston_wm_window_configure(void *data) |
| 1695 | { |
| 1696 | struct weston_wm_window *window = data; |
| 1697 | struct weston_wm *wm = window->wm; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1698 | uint32_t values[4]; |
| 1699 | int x, y, width, height; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1700 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1701 | weston_wm_window_get_child_position(window, &x, &y); |
| 1702 | values[0] = x; |
| 1703 | values[1] = y; |
| 1704 | values[2] = window->width; |
| 1705 | values[3] = window->height; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1706 | xcb_configure_window(wm->conn, |
| 1707 | window->id, |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1708 | XCB_CONFIG_WINDOW_X | |
| 1709 | XCB_CONFIG_WINDOW_Y | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1710 | XCB_CONFIG_WINDOW_WIDTH | |
| 1711 | XCB_CONFIG_WINDOW_HEIGHT, |
| 1712 | values); |
| 1713 | |
| 1714 | weston_wm_window_get_frame_size(window, &width, &height); |
| 1715 | values[0] = width; |
| 1716 | values[1] = height; |
| 1717 | xcb_configure_window(wm->conn, |
| 1718 | window->frame_id, |
| 1719 | XCB_CONFIG_WINDOW_WIDTH | |
| 1720 | XCB_CONFIG_WINDOW_HEIGHT, |
| 1721 | values); |
| 1722 | |
| 1723 | window->configure_source = NULL; |
| 1724 | |
| 1725 | weston_wm_window_schedule_repaint(window); |
| 1726 | } |
| 1727 | |
| 1728 | static void |
| 1729 | send_configure(struct weston_surface *surface, |
| 1730 | uint32_t edges, int32_t width, int32_t height) |
| 1731 | { |
| 1732 | struct weston_wm_window *window = get_wm_window(surface); |
| 1733 | struct weston_wm *wm = window->wm; |
| 1734 | struct theme *t = window->wm->theme; |
| 1735 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1736 | if (window->fullscreen) { |
| 1737 | window->width = width; |
| 1738 | window->height = height; |
| 1739 | } else if (window->decorate) { |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1740 | window->width = width - 2 * (t->margin + t->width); |
| 1741 | window->height = height - 2 * t->margin - |
| 1742 | t->titlebar_height - t->width; |
| 1743 | } else { |
| 1744 | window->width = width - 2 * t->margin; |
| 1745 | window->height = height - 2 * t->margin; |
| 1746 | } |
| 1747 | |
| 1748 | if (window->configure_source) |
| 1749 | return; |
| 1750 | |
| 1751 | window->configure_source = |
| 1752 | wl_event_loop_add_idle(wm->server->loop, |
| 1753 | weston_wm_window_configure, window); |
| 1754 | } |
| 1755 | |
| 1756 | static const struct weston_shell_client shell_client = { |
| 1757 | send_configure |
| 1758 | }; |
| 1759 | |
| 1760 | static void |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1761 | xserver_map_shell_surface(struct weston_wm *wm, |
| 1762 | struct weston_wm_window *window) |
| 1763 | { |
| 1764 | struct weston_shell_interface *shell_interface = |
| 1765 | &wm->server->compositor->shell_interface; |
| 1766 | struct weston_wm_window *parent; |
| 1767 | struct theme *t = window->wm->theme; |
Tiago Vignatti | ce1baa8 | 2012-07-20 23:09:55 +0300 | [diff] [blame] | 1768 | int parent_id, x = 0, y = 0; |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1769 | |
| 1770 | if (!shell_interface->create_shell_surface) |
| 1771 | return; |
| 1772 | |
| 1773 | window->shsurf = |
| 1774 | shell_interface->create_shell_surface(shell_interface->shell, |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1775 | window->surface, |
| 1776 | &shell_client); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1777 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1778 | if (window->fullscreen) { |
| 1779 | window->saved_width = window->width; |
| 1780 | window->saved_height = window->height; |
| 1781 | shell_interface->set_fullscreen(window->shsurf, |
| 1782 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
| 1783 | 0, NULL); |
| 1784 | return; |
| 1785 | } else if (!window->override_redirect) { |
| 1786 | /* ICCCM 4.1.1 */ |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1787 | shell_interface->set_toplevel(window->shsurf); |
| 1788 | return; |
| 1789 | } |
| 1790 | |
Tiago Vignatti | ce1baa8 | 2012-07-20 23:09:55 +0300 | [diff] [blame] | 1791 | /* not all non-toplevel has transient_for set. So we need this |
| 1792 | * workaround to guess a parent that will determine the relative |
| 1793 | * position of the transient surface */ |
| 1794 | if (!window->transient_for) |
| 1795 | parent_id = wm->focus_latest->id; |
| 1796 | else |
| 1797 | parent_id = window->transient_for->id; |
| 1798 | |
| 1799 | parent = hash_table_lookup(wm->window_hash, parent_id); |
Tiago Vignatti | e66fcee | 2012-07-20 23:09:54 +0300 | [diff] [blame] | 1800 | |
| 1801 | /* non-decorated and non-toplevel windows, e.g. sub-menus */ |
| 1802 | if (!parent->decorate && parent->override_redirect) { |
| 1803 | x = parent->x + t->margin; |
| 1804 | y = parent->y + t->margin; |
| 1805 | } |
| 1806 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1807 | shell_interface->set_transient(window->shsurf, parent->surface, |
Tiago Vignatti | e66fcee | 2012-07-20 23:09:54 +0300 | [diff] [blame] | 1808 | window->x + t->margin - x, |
| 1809 | window->y + t->margin - y, |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1810 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE); |
| 1811 | } |
| 1812 | |
| 1813 | static void |
| 1814 | xserver_set_window_id(struct wl_client *client, struct wl_resource *resource, |
| 1815 | struct wl_resource *surface_resource, uint32_t id) |
| 1816 | { |
| 1817 | struct weston_xserver *wxs = resource->data; |
| 1818 | struct weston_wm *wm = wxs->wm; |
| 1819 | struct wl_surface *surface = surface_resource->data; |
| 1820 | struct weston_wm_window *window; |
| 1821 | |
| 1822 | if (client != wxs->client) |
| 1823 | return; |
| 1824 | |
| 1825 | window = hash_table_lookup(wm->window_hash, id); |
| 1826 | if (window == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1827 | weston_log("set_window_id for unknown window %d\n", id); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1828 | return; |
| 1829 | } |
| 1830 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1831 | weston_log("set_window_id %d for surface %p\n", id, surface); |
Kristian Høgsberg | 380deee | 2012-05-21 17:12:41 -0400 | [diff] [blame] | 1832 | |
| 1833 | weston_wm_window_read_properties(window); |
| 1834 | |
| 1835 | window->surface = (struct weston_surface *) surface; |
| 1836 | window->surface_destroy_listener.notify = surface_destroy; |
| 1837 | wl_signal_add(&surface->resource.destroy_signal, |
| 1838 | &window->surface_destroy_listener); |
| 1839 | |
| 1840 | weston_wm_window_schedule_repaint(window); |
| 1841 | xserver_map_shell_surface(wm, window); |
| 1842 | } |
| 1843 | |
| 1844 | const struct xserver_interface xserver_implementation = { |
| 1845 | xserver_set_window_id |
| 1846 | }; |