Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010-2012 Intel Corporation |
| 3 | * Copyright © 2011-2012 Collabora, Ltd. |
| 4 | * Copyright © 2013 Raspberry Pi Foundation |
| 5 | * Copyright © 2016 Quentin "Sardem FF7" Glidic |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the next |
| 15 | * paragraph) shall be included in all copies or substantial portions of the |
| 16 | * Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 | * DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #include "config.h" |
| 28 | |
| 29 | #include <assert.h> |
| 30 | |
| 31 | #include <wayland-server.h> |
| 32 | |
| 33 | #include "compositor.h" |
| 34 | #include "zalloc.h" |
| 35 | |
| 36 | #include "libweston-desktop.h" |
| 37 | #include "internal.h" |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 38 | #include "xwayland/xwayland-internal-interface.h" |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 39 | |
| 40 | enum weston_desktop_xwayland_surface_state { |
| 41 | NONE, |
| 42 | TOPLEVEL, |
| 43 | MAXIMIZED, |
| 44 | FULLSCREEN, |
| 45 | TRANSIENT, |
| 46 | XWAYLAND, |
| 47 | }; |
| 48 | |
| 49 | struct weston_desktop_xwayland { |
| 50 | struct weston_desktop *desktop; |
| 51 | struct weston_desktop_client *client; |
| 52 | struct weston_layer layer; |
| 53 | }; |
| 54 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 55 | struct weston_desktop_xwayland_surface { |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 56 | struct weston_desktop_xwayland *xwayland; |
| 57 | struct weston_desktop *desktop; |
| 58 | struct weston_desktop_surface *surface; |
| 59 | struct wl_listener resource_destroy_listener; |
| 60 | struct weston_view *view; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 61 | const struct weston_xwayland_client_interface *client_interface; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 62 | struct weston_geometry next_geometry; |
| 63 | bool has_next_geometry; |
| 64 | bool added; |
| 65 | enum weston_desktop_xwayland_surface_state state; |
| 66 | }; |
| 67 | |
| 68 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 69 | weston_desktop_xwayland_surface_change_state(struct weston_desktop_xwayland_surface *surface, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 70 | enum weston_desktop_xwayland_surface_state state, |
| 71 | struct weston_desktop_surface *parent, |
| 72 | int32_t x, int32_t y) |
| 73 | { |
Pekka Paalanen | e3a582f | 2016-11-15 14:24:21 +0200 | [diff] [blame] | 74 | struct weston_surface *wsurface; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 75 | bool to_add = (parent == NULL && state != XWAYLAND); |
| 76 | |
| 77 | assert(state != NONE); |
Pekka Paalanen | a838b78 | 2016-11-15 11:43:36 +0200 | [diff] [blame] | 78 | assert(!parent || state == TRANSIENT); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 79 | |
Quentin Glidic | 6384edf | 2016-08-16 11:42:47 +0200 | [diff] [blame] | 80 | if (to_add && surface->added) { |
| 81 | surface->state = state; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 82 | return; |
Quentin Glidic | 6384edf | 2016-08-16 11:42:47 +0200 | [diff] [blame] | 83 | } |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 84 | |
Pekka Paalanen | e3a582f | 2016-11-15 14:24:21 +0200 | [diff] [blame] | 85 | wsurface = weston_desktop_surface_get_surface(surface->surface); |
| 86 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 87 | if (surface->state != state) { |
| 88 | if (surface->state == XWAYLAND) { |
Pekka Paalanen | bbc749a | 2016-11-15 12:22:09 +0200 | [diff] [blame] | 89 | assert(!surface->added); |
| 90 | |
Quentin Glidic | f01ecee | 2016-08-16 10:52:46 +0200 | [diff] [blame] | 91 | weston_desktop_surface_unlink_view(surface->view); |
Quentin Glidic | f6636a8 | 2016-08-16 10:55:02 +0200 | [diff] [blame] | 92 | weston_view_destroy(surface->view); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 93 | surface->view = NULL; |
Pekka Paalanen | e3a582f | 2016-11-15 14:24:21 +0200 | [diff] [blame] | 94 | weston_surface_unmap(wsurface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | if (to_add) { |
| 98 | weston_desktop_surface_unset_relative_to(surface->surface); |
| 99 | weston_desktop_api_surface_added(surface->desktop, |
| 100 | surface->surface); |
Pekka Paalanen | 3326820 | 2016-11-15 11:48:42 +0200 | [diff] [blame] | 101 | surface->added = true; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 102 | } else if (surface->added) { |
| 103 | weston_desktop_api_surface_removed(surface->desktop, |
| 104 | surface->surface); |
Pekka Paalanen | 3326820 | 2016-11-15 11:48:42 +0200 | [diff] [blame] | 105 | surface->added = false; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | if (state == XWAYLAND) { |
Pekka Paalanen | bbc749a | 2016-11-15 12:22:09 +0200 | [diff] [blame] | 109 | assert(!surface->added); |
| 110 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 111 | surface->view = |
| 112 | weston_desktop_surface_create_view(surface->surface); |
| 113 | weston_layer_entry_insert(&surface->xwayland->layer.view_list, |
| 114 | &surface->view->layer_link); |
| 115 | weston_view_set_position(surface->view, x, y); |
Pekka Paalanen | e3a582f | 2016-11-15 14:24:21 +0200 | [diff] [blame] | 116 | surface->view->is_mapped = true; |
| 117 | wsurface->is_mapped = true; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | surface->state = state; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | if (parent != NULL) |
| 124 | weston_desktop_surface_set_relative_to(surface->surface, parent, |
| 125 | x, y, false); |
| 126 | } |
| 127 | |
| 128 | static void |
| 129 | weston_desktop_xwayland_surface_committed(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 003da88 | 2016-08-15 12:21:39 +0200 | [diff] [blame] | 130 | void *user_data, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 131 | int32_t sx, int32_t sy) |
| 132 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 133 | struct weston_desktop_xwayland_surface *surface = user_data; |
Pekka Paalanen | 5f93b9f | 2017-01-18 15:37:59 +0200 | [diff] [blame^] | 134 | struct weston_geometry oldgeom; |
| 135 | |
| 136 | assert(dsurface == surface->surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 137 | |
Pekka Paalanen | 0adb6a7 | 2016-11-28 16:37:07 +0200 | [diff] [blame] | 138 | #ifdef WM_DEBUG |
| 139 | weston_log("%s: xwayland surface %p\n", __func__, surface); |
| 140 | #endif |
| 141 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 142 | if (surface->has_next_geometry) { |
Pekka Paalanen | 5f93b9f | 2017-01-18 15:37:59 +0200 | [diff] [blame^] | 143 | oldgeom = weston_desktop_surface_get_geometry(surface->surface); |
| 144 | sx -= surface->next_geometry.x - oldgeom.x; |
| 145 | sy -= surface->next_geometry.y - oldgeom.x; |
| 146 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 147 | surface->has_next_geometry = false; |
| 148 | weston_desktop_surface_set_geometry(surface->surface, |
| 149 | surface->next_geometry); |
| 150 | } |
| 151 | |
| 152 | if (surface->added) |
| 153 | weston_desktop_api_committed(surface->desktop, surface->surface, |
| 154 | sx, sy); |
| 155 | } |
| 156 | |
| 157 | static void |
| 158 | weston_desktop_xwayland_surface_set_size(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 159 | void *user_data, |
| 160 | int32_t width, int32_t height) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 161 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 162 | struct weston_desktop_xwayland_surface *surface = user_data; |
| 163 | struct weston_surface *wsurface = |
| 164 | weston_desktop_surface_get_surface(surface->surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 165 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 166 | surface->client_interface->send_configure(wsurface, width, height); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static void |
| 170 | weston_desktop_xwayland_surface_destroy(struct weston_desktop_surface *dsurface, |
| 171 | void *user_data) |
| 172 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 173 | struct weston_desktop_xwayland_surface *surface = user_data; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 174 | |
| 175 | wl_list_remove(&surface->resource_destroy_listener.link); |
| 176 | |
| 177 | weston_desktop_surface_unset_relative_to(surface->surface); |
Quentin Glidic | 1714f01 | 2016-08-18 16:45:30 +0200 | [diff] [blame] | 178 | if (surface->added) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 179 | weston_desktop_api_surface_removed(surface->desktop, |
| 180 | surface->surface); |
Quentin Glidic | 1714f01 | 2016-08-18 16:45:30 +0200 | [diff] [blame] | 181 | else if (surface->state == XWAYLAND) |
Quentin Glidic | f01ecee | 2016-08-16 10:52:46 +0200 | [diff] [blame] | 182 | weston_desktop_surface_unlink_view(surface->view); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 183 | |
| 184 | free(surface); |
| 185 | } |
| 186 | |
| 187 | static bool |
| 188 | weston_desktop_xwayland_surface_get_maximized(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 189 | void *user_data) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 190 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 191 | struct weston_desktop_xwayland_surface *surface = user_data; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 192 | |
| 193 | return surface->state == MAXIMIZED; |
| 194 | } |
| 195 | |
| 196 | static bool |
| 197 | weston_desktop_xwayland_surface_get_fullscreen(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 198 | void *user_data) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 199 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 200 | struct weston_desktop_xwayland_surface *surface = user_data; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 201 | |
| 202 | return surface->state == FULLSCREEN; |
| 203 | } |
| 204 | |
| 205 | static const struct weston_desktop_surface_implementation weston_desktop_xwayland_surface_internal_implementation = { |
| 206 | .committed = weston_desktop_xwayland_surface_committed, |
| 207 | .set_size = weston_desktop_xwayland_surface_set_size, |
| 208 | |
| 209 | .get_maximized = weston_desktop_xwayland_surface_get_maximized, |
| 210 | .get_fullscreen = weston_desktop_xwayland_surface_get_fullscreen, |
| 211 | |
| 212 | .destroy = weston_desktop_xwayland_surface_destroy, |
| 213 | }; |
| 214 | |
| 215 | static void |
| 216 | weston_destop_xwayland_resource_destroyed(struct wl_listener *listener, |
| 217 | void *data) |
| 218 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 219 | struct weston_desktop_xwayland_surface *surface = |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 220 | wl_container_of(listener, surface, resource_destroy_listener); |
| 221 | |
| 222 | weston_desktop_surface_destroy(surface->surface); |
| 223 | } |
| 224 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 225 | static struct weston_desktop_xwayland_surface * |
| 226 | create_surface(struct weston_desktop_xwayland *xwayland, |
| 227 | struct weston_surface *wsurface, |
| 228 | const struct weston_xwayland_client_interface *client_interface) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 229 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 230 | struct weston_desktop_xwayland_surface *surface; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 231 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 232 | surface = zalloc(sizeof(struct weston_desktop_xwayland_surface)); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 233 | if (surface == NULL) |
| 234 | return NULL; |
| 235 | |
| 236 | surface->xwayland = xwayland; |
| 237 | surface->desktop = xwayland->desktop; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 238 | surface->client_interface = client_interface; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 239 | |
| 240 | surface->surface = |
| 241 | weston_desktop_surface_create(surface->desktop, |
| 242 | xwayland->client, wsurface, |
| 243 | &weston_desktop_xwayland_surface_internal_implementation, |
| 244 | surface); |
| 245 | if (surface->surface == NULL) { |
| 246 | free(surface); |
| 247 | return NULL; |
| 248 | } |
| 249 | |
| 250 | surface->resource_destroy_listener.notify = |
| 251 | weston_destop_xwayland_resource_destroyed; |
| 252 | wl_resource_add_destroy_listener(wsurface->resource, |
| 253 | &surface->resource_destroy_listener); |
| 254 | |
Giulio Camuffo | f15320f | 2016-12-08 09:21:08 +0100 | [diff] [blame] | 255 | weston_desktop_surface_set_pid(surface->surface, 0); |
| 256 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 257 | return surface; |
| 258 | } |
| 259 | |
| 260 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 261 | set_toplevel(struct weston_desktop_xwayland_surface *surface) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 262 | { |
| 263 | weston_desktop_xwayland_surface_change_state(surface, TOPLEVEL, NULL, |
| 264 | 0, 0); |
| 265 | } |
| 266 | |
| 267 | static void |
Pekka Paalanen | 37111e1 | 2016-11-16 14:03:31 +0200 | [diff] [blame] | 268 | set_toplevel_with_position(struct weston_desktop_xwayland_surface *surface, |
| 269 | int32_t x, int32_t y) |
| 270 | { |
| 271 | weston_desktop_xwayland_surface_change_state(surface, TOPLEVEL, NULL, |
| 272 | 0, 0); |
| 273 | weston_desktop_api_set_xwayland_position(surface->desktop, |
| 274 | surface->surface, x, y); |
| 275 | } |
| 276 | |
| 277 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 278 | set_parent(struct weston_desktop_xwayland_surface *surface, |
| 279 | struct weston_surface *wparent) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 280 | { |
| 281 | struct weston_desktop_surface *parent; |
| 282 | |
| 283 | if (!weston_surface_is_desktop_surface(wparent)) |
| 284 | return; |
| 285 | |
| 286 | parent = weston_surface_get_desktop_surface(wparent); |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 287 | weston_desktop_api_set_parent(surface->desktop, surface->surface, parent); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 291 | set_transient(struct weston_desktop_xwayland_surface *surface, |
| 292 | struct weston_surface *wparent, int x, int y) |
| 293 | { |
| 294 | struct weston_desktop_surface *parent; |
| 295 | |
| 296 | if (!weston_surface_is_desktop_surface(wparent)) |
| 297 | return; |
| 298 | |
| 299 | parent = weston_surface_get_desktop_surface(wparent); |
| 300 | weston_desktop_xwayland_surface_change_state(surface, TRANSIENT, parent, |
| 301 | x, y); |
| 302 | } |
| 303 | |
| 304 | static void |
| 305 | set_fullscreen(struct weston_desktop_xwayland_surface *surface, |
| 306 | struct weston_output *output) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 307 | { |
| 308 | weston_desktop_xwayland_surface_change_state(surface, FULLSCREEN, NULL, |
| 309 | 0, 0); |
| 310 | weston_desktop_api_fullscreen_requested(surface->desktop, |
| 311 | surface->surface, true, output); |
| 312 | } |
| 313 | |
| 314 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 315 | set_xwayland(struct weston_desktop_xwayland_surface *surface, int x, int y) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 316 | { |
| 317 | weston_desktop_xwayland_surface_change_state(surface, XWAYLAND, NULL, |
| 318 | x, y); |
| 319 | } |
| 320 | |
| 321 | static int |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 322 | move(struct weston_desktop_xwayland_surface *surface, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 323 | struct weston_pointer *pointer) |
| 324 | { |
| 325 | if (surface->state == TOPLEVEL || |
| 326 | surface->state == MAXIMIZED || |
| 327 | surface->state == FULLSCREEN) |
| 328 | weston_desktop_api_move(surface->desktop, surface->surface, |
| 329 | pointer->seat, pointer->grab_serial); |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | static int |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 334 | resize(struct weston_desktop_xwayland_surface *surface, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 335 | struct weston_pointer *pointer, uint32_t edges) |
| 336 | { |
| 337 | if (surface->state == TOPLEVEL || |
| 338 | surface->state == MAXIMIZED || |
| 339 | surface->state == FULLSCREEN) |
| 340 | weston_desktop_api_resize(surface->desktop, surface->surface, |
| 341 | pointer->seat, pointer->grab_serial, |
| 342 | edges); |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 347 | set_title(struct weston_desktop_xwayland_surface *surface, const char *title) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 348 | { |
| 349 | weston_desktop_surface_set_title(surface->surface, title); |
| 350 | } |
| 351 | |
| 352 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 353 | set_window_geometry(struct weston_desktop_xwayland_surface *surface, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 354 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 355 | { |
| 356 | surface->has_next_geometry = true; |
| 357 | surface->next_geometry.x = x; |
| 358 | surface->next_geometry.y = y; |
| 359 | surface->next_geometry.width = width; |
| 360 | surface->next_geometry.height = height; |
| 361 | } |
| 362 | |
| 363 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 364 | set_maximized(struct weston_desktop_xwayland_surface *surface) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 365 | { |
| 366 | weston_desktop_xwayland_surface_change_state(surface, MAXIMIZED, NULL, |
| 367 | 0, 0); |
| 368 | weston_desktop_api_maximized_requested(surface->desktop, |
| 369 | surface->surface, true); |
| 370 | } |
| 371 | |
| 372 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 373 | set_pid(struct weston_desktop_xwayland_surface *surface, pid_t pid) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 374 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 375 | weston_desktop_surface_set_pid(surface->surface, pid); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 376 | } |
| 377 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 378 | static const struct weston_desktop_xwayland_interface weston_desktop_xwayland_interface = { |
| 379 | .create_surface = create_surface, |
| 380 | .set_toplevel = set_toplevel, |
Pekka Paalanen | 37111e1 | 2016-11-16 14:03:31 +0200 | [diff] [blame] | 381 | .set_toplevel_with_position = set_toplevel_with_position, |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 382 | .set_parent = set_parent, |
| 383 | .set_transient = set_transient, |
| 384 | .set_fullscreen = set_fullscreen, |
| 385 | .set_xwayland = set_xwayland, |
| 386 | .move = move, |
| 387 | .resize = resize, |
| 388 | .set_title = set_title, |
| 389 | .set_window_geometry = set_window_geometry, |
| 390 | .set_maximized = set_maximized, |
| 391 | .set_pid = set_pid, |
| 392 | }; |
| 393 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 394 | void |
| 395 | weston_desktop_xwayland_init(struct weston_desktop *desktop) |
| 396 | { |
| 397 | struct weston_compositor *compositor = weston_desktop_get_compositor(desktop); |
| 398 | struct weston_desktop_xwayland *xwayland; |
| 399 | |
| 400 | xwayland = zalloc(sizeof(struct weston_desktop_xwayland)); |
| 401 | if (xwayland == NULL) |
| 402 | return; |
| 403 | |
| 404 | xwayland->desktop = desktop; |
| 405 | xwayland->client = weston_desktop_client_create(desktop, NULL, NULL, NULL, NULL, 0, 0); |
| 406 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 407 | weston_layer_init(&xwayland->layer, compositor); |
| 408 | /* We put this layer on top of regular shell surfaces, but hopefully |
| 409 | * below any UI the shell would add */ |
| 410 | weston_layer_set_position(&xwayland->layer, |
| 411 | WESTON_LAYER_POSITION_NORMAL + 1); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 412 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 413 | compositor->xwayland = xwayland; |
| 414 | compositor->xwayland_interface = &weston_desktop_xwayland_interface; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 415 | } |