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