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 | |
Pekka Paalanen | 3d5d947 | 2019-03-28 16:28:47 +0200 | [diff] [blame] | 33 | #include <libweston/libweston.h> |
Pekka Paalanen | ecbdcfd | 2019-04-04 14:46:00 +0300 | [diff] [blame] | 34 | #include <libweston/zalloc.h> |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 35 | |
Pekka Paalanen | 8ebd981 | 2019-04-04 16:02:14 +0300 | [diff] [blame] | 36 | #include <libweston-desktop/libweston-desktop.h> |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 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; |
Quentin Glidic | 8e8fa8e | 2017-12-08 11:10:53 +0100 | [diff] [blame] | 64 | bool committed; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 65 | bool added; |
| 66 | enum weston_desktop_xwayland_surface_state state; |
| 67 | }; |
| 68 | |
| 69 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 70 | weston_desktop_xwayland_surface_change_state(struct weston_desktop_xwayland_surface *surface, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 71 | enum weston_desktop_xwayland_surface_state state, |
| 72 | struct weston_desktop_surface *parent, |
| 73 | int32_t x, int32_t y) |
| 74 | { |
Pekka Paalanen | e3a582f | 2016-11-15 14:24:21 +0200 | [diff] [blame] | 75 | struct weston_surface *wsurface; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 76 | bool to_add = (parent == NULL && state != XWAYLAND); |
| 77 | |
| 78 | assert(state != NONE); |
Pekka Paalanen | a838b78 | 2016-11-15 11:43:36 +0200 | [diff] [blame] | 79 | assert(!parent || state == TRANSIENT); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 80 | |
Quentin Glidic | 6384edf | 2016-08-16 11:42:47 +0200 | [diff] [blame] | 81 | if (to_add && surface->added) { |
| 82 | surface->state = state; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 83 | return; |
Quentin Glidic | 6384edf | 2016-08-16 11:42:47 +0200 | [diff] [blame] | 84 | } |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 85 | |
Pekka Paalanen | e3a582f | 2016-11-15 14:24:21 +0200 | [diff] [blame] | 86 | wsurface = weston_desktop_surface_get_surface(surface->surface); |
| 87 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 88 | if (surface->state != state) { |
| 89 | if (surface->state == XWAYLAND) { |
Pekka Paalanen | bbc749a | 2016-11-15 12:22:09 +0200 | [diff] [blame] | 90 | assert(!surface->added); |
| 91 | |
Quentin Glidic | f01ecee | 2016-08-16 10:52:46 +0200 | [diff] [blame] | 92 | weston_desktop_surface_unlink_view(surface->view); |
Quentin Glidic | f6636a8 | 2016-08-16 10:55:02 +0200 | [diff] [blame] | 93 | weston_view_destroy(surface->view); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 94 | surface->view = NULL; |
Pekka Paalanen | e3a582f | 2016-11-15 14:24:21 +0200 | [diff] [blame] | 95 | weston_surface_unmap(wsurface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | if (to_add) { |
| 99 | weston_desktop_surface_unset_relative_to(surface->surface); |
| 100 | weston_desktop_api_surface_added(surface->desktop, |
| 101 | surface->surface); |
Pekka Paalanen | 3326820 | 2016-11-15 11:48:42 +0200 | [diff] [blame] | 102 | surface->added = true; |
Quentin Glidic | 8e8fa8e | 2017-12-08 11:10:53 +0100 | [diff] [blame] | 103 | if (surface->state == NONE && surface->committed) |
| 104 | /* We had a race, and wl_surface.commit() was |
| 105 | * faster, just fake a commit to map the |
| 106 | * surface */ |
| 107 | weston_desktop_api_committed(surface->desktop, |
| 108 | surface->surface, |
| 109 | 0, 0); |
| 110 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 111 | } else if (surface->added) { |
| 112 | weston_desktop_api_surface_removed(surface->desktop, |
| 113 | surface->surface); |
Pekka Paalanen | 3326820 | 2016-11-15 11:48:42 +0200 | [diff] [blame] | 114 | surface->added = false; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | if (state == XWAYLAND) { |
Pekka Paalanen | bbc749a | 2016-11-15 12:22:09 +0200 | [diff] [blame] | 118 | assert(!surface->added); |
| 119 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 120 | surface->view = |
| 121 | weston_desktop_surface_create_view(surface->surface); |
| 122 | weston_layer_entry_insert(&surface->xwayland->layer.view_list, |
| 123 | &surface->view->layer_link); |
Pekka Paalanen | e3a582f | 2016-11-15 14:24:21 +0200 | [diff] [blame] | 124 | surface->view->is_mapped = true; |
| 125 | wsurface->is_mapped = true; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | surface->state = state; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | if (parent != NULL) |
| 132 | weston_desktop_surface_set_relative_to(surface->surface, parent, |
| 133 | x, y, false); |
| 134 | } |
| 135 | |
| 136 | static void |
| 137 | weston_desktop_xwayland_surface_committed(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 003da88 | 2016-08-15 12:21:39 +0200 | [diff] [blame] | 138 | void *user_data, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 139 | int32_t sx, int32_t sy) |
| 140 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 141 | struct weston_desktop_xwayland_surface *surface = user_data; |
Pekka Paalanen | 5f93b9f | 2017-01-18 15:37:59 +0200 | [diff] [blame] | 142 | struct weston_geometry oldgeom; |
| 143 | |
| 144 | assert(dsurface == surface->surface); |
Quentin Glidic | 8e8fa8e | 2017-12-08 11:10:53 +0100 | [diff] [blame] | 145 | surface->committed = true; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 146 | |
Pekka Paalanen | 0adb6a7 | 2016-11-28 16:37:07 +0200 | [diff] [blame] | 147 | #ifdef WM_DEBUG |
| 148 | weston_log("%s: xwayland surface %p\n", __func__, surface); |
| 149 | #endif |
| 150 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 151 | if (surface->has_next_geometry) { |
Pekka Paalanen | 5f93b9f | 2017-01-18 15:37:59 +0200 | [diff] [blame] | 152 | oldgeom = weston_desktop_surface_get_geometry(surface->surface); |
| 153 | sx -= surface->next_geometry.x - oldgeom.x; |
| 154 | sy -= surface->next_geometry.y - oldgeom.x; |
| 155 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 156 | surface->has_next_geometry = false; |
| 157 | weston_desktop_surface_set_geometry(surface->surface, |
| 158 | surface->next_geometry); |
| 159 | } |
| 160 | |
| 161 | if (surface->added) |
| 162 | weston_desktop_api_committed(surface->desktop, surface->surface, |
| 163 | sx, sy); |
| 164 | } |
| 165 | |
| 166 | static void |
| 167 | weston_desktop_xwayland_surface_set_size(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 168 | void *user_data, |
| 169 | int32_t width, int32_t height) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 170 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 171 | struct weston_desktop_xwayland_surface *surface = user_data; |
| 172 | struct weston_surface *wsurface = |
| 173 | weston_desktop_surface_get_surface(surface->surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 174 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 175 | surface->client_interface->send_configure(wsurface, width, height); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static void |
| 179 | weston_desktop_xwayland_surface_destroy(struct weston_desktop_surface *dsurface, |
| 180 | void *user_data) |
| 181 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 182 | struct weston_desktop_xwayland_surface *surface = user_data; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 183 | |
| 184 | wl_list_remove(&surface->resource_destroy_listener.link); |
| 185 | |
| 186 | weston_desktop_surface_unset_relative_to(surface->surface); |
Quentin Glidic | 1714f01 | 2016-08-18 16:45:30 +0200 | [diff] [blame] | 187 | if (surface->added) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 188 | weston_desktop_api_surface_removed(surface->desktop, |
| 189 | surface->surface); |
Quentin Glidic | 1714f01 | 2016-08-18 16:45:30 +0200 | [diff] [blame] | 190 | else if (surface->state == XWAYLAND) |
Quentin Glidic | f01ecee | 2016-08-16 10:52:46 +0200 | [diff] [blame] | 191 | weston_desktop_surface_unlink_view(surface->view); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 192 | |
| 193 | free(surface); |
| 194 | } |
| 195 | |
John Good | f33ddd0 | 2020-03-22 18:19:38 +0100 | [diff] [blame] | 196 | static void |
| 197 | weston_desktop_xwayland_surface_close(struct weston_desktop_surface *dsurface, |
| 198 | void *user_data) |
| 199 | { |
| 200 | struct weston_desktop_xwayland_surface *surface = user_data; |
| 201 | struct weston_surface *wsurface = |
| 202 | weston_desktop_surface_get_surface(surface->surface); |
| 203 | |
| 204 | surface->client_interface->send_close(wsurface); |
| 205 | } |
| 206 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 207 | static bool |
| 208 | weston_desktop_xwayland_surface_get_maximized(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 209 | void *user_data) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 210 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 211 | struct weston_desktop_xwayland_surface *surface = user_data; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 212 | |
| 213 | return surface->state == MAXIMIZED; |
| 214 | } |
| 215 | |
| 216 | static bool |
| 217 | weston_desktop_xwayland_surface_get_fullscreen(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 218 | void *user_data) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 219 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 220 | struct weston_desktop_xwayland_surface *surface = user_data; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 221 | |
| 222 | return surface->state == FULLSCREEN; |
| 223 | } |
| 224 | |
| 225 | static const struct weston_desktop_surface_implementation weston_desktop_xwayland_surface_internal_implementation = { |
| 226 | .committed = weston_desktop_xwayland_surface_committed, |
| 227 | .set_size = weston_desktop_xwayland_surface_set_size, |
| 228 | |
| 229 | .get_maximized = weston_desktop_xwayland_surface_get_maximized, |
| 230 | .get_fullscreen = weston_desktop_xwayland_surface_get_fullscreen, |
| 231 | |
| 232 | .destroy = weston_desktop_xwayland_surface_destroy, |
John Good | f33ddd0 | 2020-03-22 18:19:38 +0100 | [diff] [blame] | 233 | .close = weston_desktop_xwayland_surface_close, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | static void |
| 237 | weston_destop_xwayland_resource_destroyed(struct wl_listener *listener, |
| 238 | void *data) |
| 239 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 240 | struct weston_desktop_xwayland_surface *surface = |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 241 | wl_container_of(listener, surface, resource_destroy_listener); |
| 242 | |
| 243 | weston_desktop_surface_destroy(surface->surface); |
| 244 | } |
| 245 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 246 | static struct weston_desktop_xwayland_surface * |
| 247 | create_surface(struct weston_desktop_xwayland *xwayland, |
| 248 | struct weston_surface *wsurface, |
| 249 | const struct weston_xwayland_client_interface *client_interface) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 250 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 251 | struct weston_desktop_xwayland_surface *surface; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 252 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 253 | surface = zalloc(sizeof(struct weston_desktop_xwayland_surface)); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 254 | if (surface == NULL) |
| 255 | return NULL; |
| 256 | |
| 257 | surface->xwayland = xwayland; |
| 258 | surface->desktop = xwayland->desktop; |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 259 | surface->client_interface = client_interface; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 260 | |
| 261 | surface->surface = |
| 262 | weston_desktop_surface_create(surface->desktop, |
| 263 | xwayland->client, wsurface, |
| 264 | &weston_desktop_xwayland_surface_internal_implementation, |
| 265 | surface); |
| 266 | if (surface->surface == NULL) { |
| 267 | free(surface); |
| 268 | return NULL; |
| 269 | } |
| 270 | |
| 271 | surface->resource_destroy_listener.notify = |
| 272 | weston_destop_xwayland_resource_destroyed; |
| 273 | wl_resource_add_destroy_listener(wsurface->resource, |
| 274 | &surface->resource_destroy_listener); |
| 275 | |
Giulio Camuffo | f15320f | 2016-12-08 09:21:08 +0100 | [diff] [blame] | 276 | weston_desktop_surface_set_pid(surface->surface, 0); |
| 277 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 278 | return surface; |
| 279 | } |
| 280 | |
| 281 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 282 | set_toplevel(struct weston_desktop_xwayland_surface *surface) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 283 | { |
| 284 | weston_desktop_xwayland_surface_change_state(surface, TOPLEVEL, NULL, |
| 285 | 0, 0); |
| 286 | } |
| 287 | |
| 288 | static void |
Pekka Paalanen | 37111e1 | 2016-11-16 14:03:31 +0200 | [diff] [blame] | 289 | set_toplevel_with_position(struct weston_desktop_xwayland_surface *surface, |
| 290 | int32_t x, int32_t y) |
| 291 | { |
| 292 | weston_desktop_xwayland_surface_change_state(surface, TOPLEVEL, NULL, |
| 293 | 0, 0); |
| 294 | weston_desktop_api_set_xwayland_position(surface->desktop, |
| 295 | surface->surface, x, y); |
| 296 | } |
| 297 | |
| 298 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 299 | set_parent(struct weston_desktop_xwayland_surface *surface, |
| 300 | struct weston_surface *wparent) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 301 | { |
| 302 | struct weston_desktop_surface *parent; |
| 303 | |
| 304 | if (!weston_surface_is_desktop_surface(wparent)) |
| 305 | return; |
| 306 | |
| 307 | parent = weston_surface_get_desktop_surface(wparent); |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 308 | weston_desktop_api_set_parent(surface->desktop, surface->surface, parent); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 312 | set_transient(struct weston_desktop_xwayland_surface *surface, |
| 313 | struct weston_surface *wparent, int x, int y) |
| 314 | { |
| 315 | struct weston_desktop_surface *parent; |
| 316 | |
| 317 | if (!weston_surface_is_desktop_surface(wparent)) |
| 318 | return; |
| 319 | |
| 320 | parent = weston_surface_get_desktop_surface(wparent); |
| 321 | weston_desktop_xwayland_surface_change_state(surface, TRANSIENT, parent, |
| 322 | x, y); |
| 323 | } |
| 324 | |
| 325 | static void |
| 326 | set_fullscreen(struct weston_desktop_xwayland_surface *surface, |
| 327 | struct weston_output *output) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 328 | { |
| 329 | weston_desktop_xwayland_surface_change_state(surface, FULLSCREEN, NULL, |
| 330 | 0, 0); |
| 331 | weston_desktop_api_fullscreen_requested(surface->desktop, |
| 332 | surface->surface, true, output); |
| 333 | } |
| 334 | |
| 335 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 336 | set_xwayland(struct weston_desktop_xwayland_surface *surface, int x, int y) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 337 | { |
| 338 | weston_desktop_xwayland_surface_change_state(surface, XWAYLAND, NULL, |
| 339 | x, y); |
Ilia Bozhinov | 3e5303d | 2017-06-28 00:08:40 +0300 | [diff] [blame] | 340 | weston_view_set_position(surface->view, x, y); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static int |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 344 | move(struct weston_desktop_xwayland_surface *surface, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 345 | struct weston_pointer *pointer) |
| 346 | { |
| 347 | if (surface->state == TOPLEVEL || |
| 348 | surface->state == MAXIMIZED || |
| 349 | surface->state == FULLSCREEN) |
| 350 | weston_desktop_api_move(surface->desktop, surface->surface, |
| 351 | pointer->seat, pointer->grab_serial); |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | static int |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 356 | resize(struct weston_desktop_xwayland_surface *surface, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 357 | struct weston_pointer *pointer, uint32_t edges) |
| 358 | { |
| 359 | if (surface->state == TOPLEVEL || |
| 360 | surface->state == MAXIMIZED || |
| 361 | surface->state == FULLSCREEN) |
| 362 | weston_desktop_api_resize(surface->desktop, surface->surface, |
| 363 | pointer->seat, pointer->grab_serial, |
| 364 | edges); |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 369 | set_title(struct weston_desktop_xwayland_surface *surface, const char *title) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 370 | { |
| 371 | weston_desktop_surface_set_title(surface->surface, title); |
| 372 | } |
| 373 | |
| 374 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 375 | set_window_geometry(struct weston_desktop_xwayland_surface *surface, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 376 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 377 | { |
| 378 | surface->has_next_geometry = true; |
| 379 | surface->next_geometry.x = x; |
| 380 | surface->next_geometry.y = y; |
| 381 | surface->next_geometry.width = width; |
| 382 | surface->next_geometry.height = height; |
| 383 | } |
| 384 | |
| 385 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 386 | set_maximized(struct weston_desktop_xwayland_surface *surface) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 387 | { |
| 388 | weston_desktop_xwayland_surface_change_state(surface, MAXIMIZED, NULL, |
| 389 | 0, 0); |
| 390 | weston_desktop_api_maximized_requested(surface->desktop, |
| 391 | surface->surface, true); |
| 392 | } |
| 393 | |
| 394 | static void |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 395 | set_pid(struct weston_desktop_xwayland_surface *surface, pid_t pid) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 396 | { |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 397 | weston_desktop_surface_set_pid(surface->surface, pid); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 398 | } |
| 399 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 400 | static const struct weston_desktop_xwayland_interface weston_desktop_xwayland_interface = { |
| 401 | .create_surface = create_surface, |
| 402 | .set_toplevel = set_toplevel, |
Pekka Paalanen | 37111e1 | 2016-11-16 14:03:31 +0200 | [diff] [blame] | 403 | .set_toplevel_with_position = set_toplevel_with_position, |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 404 | .set_parent = set_parent, |
| 405 | .set_transient = set_transient, |
| 406 | .set_fullscreen = set_fullscreen, |
| 407 | .set_xwayland = set_xwayland, |
| 408 | .move = move, |
| 409 | .resize = resize, |
| 410 | .set_title = set_title, |
| 411 | .set_window_geometry = set_window_geometry, |
| 412 | .set_maximized = set_maximized, |
| 413 | .set_pid = set_pid, |
| 414 | }; |
| 415 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 416 | void |
| 417 | weston_desktop_xwayland_init(struct weston_desktop *desktop) |
| 418 | { |
| 419 | struct weston_compositor *compositor = weston_desktop_get_compositor(desktop); |
| 420 | struct weston_desktop_xwayland *xwayland; |
| 421 | |
| 422 | xwayland = zalloc(sizeof(struct weston_desktop_xwayland)); |
| 423 | if (xwayland == NULL) |
| 424 | return; |
| 425 | |
| 426 | xwayland->desktop = desktop; |
| 427 | xwayland->client = weston_desktop_client_create(desktop, NULL, NULL, NULL, NULL, 0, 0); |
| 428 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 429 | weston_layer_init(&xwayland->layer, compositor); |
| 430 | /* We put this layer on top of regular shell surfaces, but hopefully |
| 431 | * below any UI the shell would add */ |
| 432 | weston_layer_set_position(&xwayland->layer, |
| 433 | WESTON_LAYER_POSITION_NORMAL + 1); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 434 | |
Quentin Glidic | 955cec0 | 2016-08-12 10:41:35 +0200 | [diff] [blame] | 435 | compositor->xwayland = xwayland; |
| 436 | compositor->xwayland_interface = &weston_desktop_xwayland_interface; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 437 | } |
Pekka Paalanen | e2583ca | 2021-05-14 16:12:35 +0300 | [diff] [blame] | 438 | |
| 439 | void |
| 440 | weston_desktop_xwayland_fini(struct weston_desktop *desktop) |
| 441 | { |
| 442 | struct weston_compositor *compositor = weston_desktop_get_compositor(desktop); |
| 443 | struct weston_desktop_xwayland *xwayland; |
| 444 | |
| 445 | xwayland = compositor->xwayland; |
| 446 | |
| 447 | weston_desktop_client_destroy(xwayland->client); |
| 448 | weston_layer_fini(&xwayland->layer); |
| 449 | free(xwayland); |
| 450 | |
| 451 | compositor->xwayland = NULL; |
| 452 | compositor->xwayland_interface = NULL; |
| 453 | } |