Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +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 <stdbool.h> |
| 30 | #include <assert.h> |
| 31 | |
| 32 | #include <wayland-server.h> |
| 33 | |
| 34 | #include "compositor.h" |
| 35 | #include "zalloc.h" |
Daniel Stone | 7dbb0e1 | 2016-11-24 15:30:41 +0000 | [diff] [blame] | 36 | #include "xdg-shell-unstable-v6-server-protocol.h" |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 37 | |
| 38 | #include "libweston-desktop.h" |
| 39 | #include "internal.h" |
| 40 | |
| 41 | #define WD_XDG_SHELL_PROTOCOL_VERSION 1 |
| 42 | |
| 43 | static const char *weston_desktop_xdg_toplevel_role = "xdg_toplevel"; |
| 44 | static const char *weston_desktop_xdg_popup_role = "xdg_popup"; |
| 45 | |
| 46 | struct weston_desktop_xdg_positioner { |
| 47 | struct weston_desktop *desktop; |
| 48 | struct weston_desktop_client *client; |
| 49 | struct wl_resource *resource; |
| 50 | |
| 51 | struct weston_size size; |
| 52 | struct weston_geometry anchor_rect; |
| 53 | enum zxdg_positioner_v6_anchor anchor; |
| 54 | enum zxdg_positioner_v6_gravity gravity; |
| 55 | enum zxdg_positioner_v6_constraint_adjustment constraint_adjustment; |
| 56 | struct weston_position offset; |
| 57 | }; |
| 58 | |
| 59 | enum weston_desktop_xdg_surface_role { |
| 60 | WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE, |
| 61 | WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL, |
| 62 | WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP, |
| 63 | }; |
| 64 | |
| 65 | struct weston_desktop_xdg_surface { |
| 66 | struct wl_resource *resource; |
| 67 | struct weston_desktop *desktop; |
| 68 | struct weston_surface *surface; |
| 69 | struct weston_desktop_surface *desktop_surface; |
| 70 | bool configured; |
| 71 | struct wl_event_source *configure_idle; |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 72 | struct wl_list configure_list; /* weston_desktop_xdg_surface_configure::link */ |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 73 | |
| 74 | bool has_next_geometry; |
| 75 | struct weston_geometry next_geometry; |
| 76 | |
| 77 | enum weston_desktop_xdg_surface_role role; |
| 78 | }; |
| 79 | |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 80 | struct weston_desktop_xdg_surface_configure { |
| 81 | struct wl_list link; /* weston_desktop_xdg_surface::configure_list */ |
| 82 | uint32_t serial; |
| 83 | }; |
| 84 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 85 | struct weston_desktop_xdg_toplevel_state { |
| 86 | bool maximized; |
| 87 | bool fullscreen; |
| 88 | bool resizing; |
| 89 | bool activated; |
| 90 | }; |
| 91 | |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 92 | struct weston_desktop_xdg_toplevel_configure { |
| 93 | struct weston_desktop_xdg_surface_configure base; |
| 94 | struct weston_desktop_xdg_toplevel_state state; |
| 95 | struct weston_size size; |
| 96 | }; |
| 97 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 98 | struct weston_desktop_xdg_toplevel { |
| 99 | struct weston_desktop_xdg_surface base; |
| 100 | |
| 101 | struct wl_resource *resource; |
| 102 | bool added; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 103 | struct { |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 104 | struct weston_desktop_xdg_toplevel_state state; |
| 105 | struct weston_size size; |
| 106 | } pending; |
| 107 | struct { |
| 108 | struct weston_desktop_xdg_toplevel_state state; |
Quentin Glidic | ac394a1 | 2017-07-12 09:45:43 +0200 | [diff] [blame] | 109 | struct weston_size size; |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 110 | struct weston_size min_size, max_size; |
| 111 | } next; |
| 112 | struct { |
| 113 | struct weston_desktop_xdg_toplevel_state state; |
| 114 | struct weston_size min_size, max_size; |
| 115 | } current; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | struct weston_desktop_xdg_popup { |
| 119 | struct weston_desktop_xdg_surface base; |
| 120 | |
| 121 | struct wl_resource *resource; |
| 122 | bool committed; |
| 123 | struct weston_desktop_xdg_surface *parent; |
| 124 | struct weston_desktop_seat *seat; |
| 125 | struct weston_geometry geometry; |
| 126 | }; |
| 127 | |
| 128 | #define weston_desktop_surface_role_biggest_size (sizeof(struct weston_desktop_xdg_toplevel)) |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 129 | #define weston_desktop_surface_configure_biggest_size (sizeof(struct weston_desktop_xdg_toplevel)) |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 130 | |
| 131 | |
| 132 | static struct weston_geometry |
| 133 | weston_desktop_xdg_positioner_get_geometry(struct weston_desktop_xdg_positioner *positioner, |
| 134 | struct weston_desktop_surface *dsurface, |
| 135 | struct weston_desktop_surface *parent) |
| 136 | { |
| 137 | struct weston_geometry geometry = { |
| 138 | .x = positioner->offset.x, |
| 139 | .y = positioner->offset.y, |
| 140 | .width = positioner->size.width, |
| 141 | .height = positioner->size.height, |
| 142 | }; |
| 143 | |
| 144 | if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) |
| 145 | geometry.y += positioner->anchor_rect.y; |
| 146 | else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) |
| 147 | geometry.y += positioner->anchor_rect.y + positioner->anchor_rect.height; |
| 148 | else |
| 149 | geometry.y += positioner->anchor_rect.y + positioner->anchor_rect.height / 2; |
| 150 | |
| 151 | if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) |
| 152 | geometry.x += positioner->anchor_rect.x; |
| 153 | else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) |
| 154 | geometry.x += positioner->anchor_rect.x + positioner->anchor_rect.width; |
| 155 | else |
| 156 | geometry.x += positioner->anchor_rect.x + positioner->anchor_rect.width / 2; |
| 157 | |
| 158 | if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) |
| 159 | geometry.y -= geometry.height; |
| 160 | else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM) |
| 161 | geometry.y = geometry.y; |
| 162 | else |
| 163 | geometry.y -= geometry.height / 2; |
| 164 | |
| 165 | if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) |
| 166 | geometry.x -= geometry.width; |
| 167 | else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT) |
| 168 | geometry.x = geometry.x; |
| 169 | else |
| 170 | geometry.x -= geometry.width / 2; |
| 171 | |
| 172 | if (positioner->constraint_adjustment == ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE) |
| 173 | return geometry; |
| 174 | |
| 175 | /* TODO: add compositor policy configuration and the code here */ |
| 176 | |
| 177 | return geometry; |
| 178 | } |
| 179 | |
| 180 | static void |
| 181 | weston_desktop_xdg_positioner_protocol_set_size(struct wl_client *wl_client, |
| 182 | struct wl_resource *resource, |
| 183 | int32_t width, int32_t height) |
| 184 | { |
| 185 | struct weston_desktop_xdg_positioner *positioner = |
| 186 | wl_resource_get_user_data(resource); |
| 187 | |
| 188 | if (width < 1 || height < 1) { |
| 189 | wl_resource_post_error(resource, |
| 190 | ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, |
| 191 | "width and height must be positives and non-zero"); |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | positioner->size.width = width; |
| 196 | positioner->size.height = height; |
| 197 | } |
| 198 | |
| 199 | static void |
| 200 | weston_desktop_xdg_positioner_protocol_set_anchor_rect(struct wl_client *wl_client, |
| 201 | struct wl_resource *resource, |
| 202 | int32_t x, int32_t y, |
| 203 | int32_t width, int32_t height) |
| 204 | { |
| 205 | struct weston_desktop_xdg_positioner *positioner = |
| 206 | wl_resource_get_user_data(resource); |
| 207 | |
| 208 | if (width < 1 || height < 1) { |
| 209 | wl_resource_post_error(resource, |
| 210 | ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, |
| 211 | "width and height must be positives and non-zero"); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | positioner->anchor_rect.x = x; |
| 216 | positioner->anchor_rect.y = y; |
| 217 | positioner->anchor_rect.width = width; |
| 218 | positioner->anchor_rect.height = height; |
| 219 | } |
| 220 | |
| 221 | static void |
| 222 | weston_desktop_xdg_positioner_protocol_set_anchor(struct wl_client *wl_client, |
| 223 | struct wl_resource *resource, |
| 224 | enum zxdg_positioner_v6_anchor anchor) |
| 225 | { |
| 226 | struct weston_desktop_xdg_positioner *positioner = |
| 227 | wl_resource_get_user_data(resource); |
| 228 | |
| 229 | if (((anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP ) && |
| 230 | (anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM)) || |
| 231 | ((anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) && |
| 232 | (anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT))) { |
| 233 | wl_resource_post_error(resource, |
| 234 | ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, |
| 235 | "same-axis values are not allowed"); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | positioner->anchor = anchor; |
| 240 | } |
| 241 | |
| 242 | static void |
| 243 | weston_desktop_xdg_positioner_protocol_set_gravity(struct wl_client *wl_client, |
| 244 | struct wl_resource *resource, |
| 245 | enum zxdg_positioner_v6_gravity gravity) |
| 246 | { |
| 247 | struct weston_desktop_xdg_positioner *positioner = |
| 248 | wl_resource_get_user_data(resource); |
| 249 | |
| 250 | if (((gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) && |
| 251 | (gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM)) || |
| 252 | ((gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) && |
| 253 | (gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT))) { |
| 254 | wl_resource_post_error(resource, |
| 255 | ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT, |
| 256 | "same-axis values are not allowed"); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | positioner->gravity = gravity; |
| 261 | } |
| 262 | |
| 263 | static void |
| 264 | weston_desktop_xdg_positioner_protocol_set_constraint_adjustment(struct wl_client *wl_client, |
| 265 | struct wl_resource *resource, |
| 266 | enum zxdg_positioner_v6_constraint_adjustment constraint_adjustment) |
| 267 | { |
| 268 | struct weston_desktop_xdg_positioner *positioner = |
| 269 | wl_resource_get_user_data(resource); |
| 270 | |
| 271 | positioner->constraint_adjustment = constraint_adjustment; |
| 272 | } |
| 273 | |
| 274 | static void |
| 275 | weston_desktop_xdg_positioner_protocol_set_offset(struct wl_client *wl_client, |
| 276 | struct wl_resource *resource, |
| 277 | int32_t x, int32_t y) |
| 278 | { |
| 279 | struct weston_desktop_xdg_positioner *positioner = |
| 280 | wl_resource_get_user_data(resource); |
| 281 | |
| 282 | positioner->offset.x = x; |
| 283 | positioner->offset.y = y; |
| 284 | } |
| 285 | |
| 286 | static void |
| 287 | weston_desktop_xdg_positioner_destroy(struct wl_resource *resource) |
| 288 | { |
| 289 | struct weston_desktop_xdg_positioner *positioner = |
| 290 | wl_resource_get_user_data(resource); |
| 291 | |
| 292 | free(positioner); |
| 293 | } |
| 294 | |
| 295 | static const struct zxdg_positioner_v6_interface weston_desktop_xdg_positioner_implementation = { |
| 296 | .destroy = weston_desktop_destroy_request, |
| 297 | .set_size = weston_desktop_xdg_positioner_protocol_set_size, |
| 298 | .set_anchor_rect = weston_desktop_xdg_positioner_protocol_set_anchor_rect, |
| 299 | .set_anchor = weston_desktop_xdg_positioner_protocol_set_anchor, |
| 300 | .set_gravity = weston_desktop_xdg_positioner_protocol_set_gravity, |
| 301 | .set_constraint_adjustment = weston_desktop_xdg_positioner_protocol_set_constraint_adjustment, |
| 302 | .set_offset = weston_desktop_xdg_positioner_protocol_set_offset, |
| 303 | }; |
| 304 | |
| 305 | static void |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 306 | weston_desktop_xdg_surface_schedule_configure(struct weston_desktop_xdg_surface *surface, |
| 307 | bool force); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 308 | |
| 309 | static void |
Quentin Glidic | 3d7e607 | 2016-09-11 11:29:23 +0200 | [diff] [blame] | 310 | weston_desktop_xdg_toplevel_ensure_added(struct weston_desktop_xdg_toplevel *toplevel) |
| 311 | { |
| 312 | if (toplevel->added) |
| 313 | return; |
| 314 | |
| 315 | weston_desktop_api_surface_added(toplevel->base.desktop, |
| 316 | toplevel->base.desktop_surface); |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 317 | weston_desktop_xdg_surface_schedule_configure(&toplevel->base, true); |
Quentin Glidic | 3d7e607 | 2016-09-11 11:29:23 +0200 | [diff] [blame] | 318 | toplevel->added = true; |
| 319 | } |
| 320 | |
| 321 | static void |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 322 | weston_desktop_xdg_toplevel_protocol_set_parent(struct wl_client *wl_client, |
| 323 | struct wl_resource *resource, |
| 324 | struct wl_resource *parent_resource) |
| 325 | { |
| 326 | struct weston_desktop_surface *dsurface = |
| 327 | wl_resource_get_user_data(resource); |
| 328 | struct weston_desktop_xdg_toplevel *toplevel = |
| 329 | weston_desktop_surface_get_implementation_data(dsurface); |
| 330 | struct weston_desktop_surface *parent = NULL; |
| 331 | |
| 332 | if (parent_resource != NULL) |
| 333 | parent = wl_resource_get_user_data(parent_resource); |
Quentin Glidic | 3d7e607 | 2016-09-11 11:29:23 +0200 | [diff] [blame] | 334 | |
| 335 | weston_desktop_xdg_toplevel_ensure_added(toplevel); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 336 | weston_desktop_api_set_parent(toplevel->base.desktop, dsurface, parent); |
| 337 | } |
| 338 | |
| 339 | static void |
| 340 | weston_desktop_xdg_toplevel_protocol_set_title(struct wl_client *wl_client, |
| 341 | struct wl_resource *resource, |
| 342 | const char *title) |
| 343 | { |
| 344 | struct weston_desktop_surface *toplevel = |
| 345 | wl_resource_get_user_data(resource); |
| 346 | |
| 347 | weston_desktop_surface_set_title(toplevel, title); |
| 348 | } |
| 349 | |
| 350 | static void |
| 351 | weston_desktop_xdg_toplevel_protocol_set_app_id(struct wl_client *wl_client, |
| 352 | struct wl_resource *resource, |
| 353 | const char *app_id) |
| 354 | { |
| 355 | struct weston_desktop_surface *toplevel = |
| 356 | wl_resource_get_user_data(resource); |
| 357 | |
| 358 | weston_desktop_surface_set_app_id(toplevel, app_id); |
| 359 | } |
| 360 | |
| 361 | static void |
| 362 | weston_desktop_xdg_toplevel_protocol_show_window_menu(struct wl_client *wl_client, |
| 363 | struct wl_resource *resource, |
| 364 | struct wl_resource *seat_resource, |
| 365 | uint32_t serial, |
| 366 | int32_t x, int32_t y) |
| 367 | { |
| 368 | struct weston_desktop_surface *dsurface = |
| 369 | wl_resource_get_user_data(resource); |
| 370 | struct weston_seat *seat = |
| 371 | wl_resource_get_user_data(seat_resource); |
| 372 | struct weston_desktop_xdg_toplevel *toplevel = |
| 373 | weston_desktop_surface_get_implementation_data(dsurface); |
| 374 | |
Quentin Glidic | 0abf890 | 2016-09-11 11:34:47 +0200 | [diff] [blame] | 375 | if (!toplevel->base.configured) { |
| 376 | wl_resource_post_error(toplevel->resource, |
| 377 | ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, |
| 378 | "Surface has not been configured yet"); |
| 379 | return; |
| 380 | } |
| 381 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 382 | weston_desktop_api_show_window_menu(toplevel->base.desktop, |
| 383 | dsurface, seat, x, y); |
| 384 | } |
| 385 | |
| 386 | static void |
| 387 | weston_desktop_xdg_toplevel_protocol_move(struct wl_client *wl_client, |
| 388 | struct wl_resource *resource, |
| 389 | struct wl_resource *seat_resource, |
| 390 | uint32_t serial) |
| 391 | { |
| 392 | struct weston_desktop_surface *dsurface = |
| 393 | wl_resource_get_user_data(resource); |
| 394 | struct weston_seat *seat = |
| 395 | wl_resource_get_user_data(seat_resource); |
| 396 | struct weston_desktop_xdg_toplevel *toplevel = |
| 397 | weston_desktop_surface_get_implementation_data(dsurface); |
| 398 | |
Quentin Glidic | 0abf890 | 2016-09-11 11:34:47 +0200 | [diff] [blame] | 399 | if (!toplevel->base.configured) { |
| 400 | wl_resource_post_error(toplevel->resource, |
| 401 | ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, |
| 402 | "Surface has not been configured yet"); |
| 403 | return; |
| 404 | } |
| 405 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 406 | weston_desktop_api_move(toplevel->base.desktop, dsurface, seat, serial); |
| 407 | } |
| 408 | |
| 409 | static void |
| 410 | weston_desktop_xdg_toplevel_protocol_resize(struct wl_client *wl_client, |
| 411 | struct wl_resource *resource, |
| 412 | struct wl_resource *seat_resource, |
| 413 | uint32_t serial, |
| 414 | enum zxdg_toplevel_v6_resize_edge edges) |
| 415 | { |
| 416 | struct weston_desktop_surface *dsurface = |
| 417 | wl_resource_get_user_data(resource); |
| 418 | struct weston_seat *seat = |
| 419 | wl_resource_get_user_data(seat_resource); |
| 420 | struct weston_desktop_xdg_toplevel *toplevel = |
| 421 | weston_desktop_surface_get_implementation_data(dsurface); |
Armin Krezović | 4e2fa0a | 2016-09-10 19:11:21 +0200 | [diff] [blame] | 422 | enum weston_desktop_surface_edge surf_edges = |
| 423 | (enum weston_desktop_surface_edge) edges; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 424 | |
Quentin Glidic | 0abf890 | 2016-09-11 11:34:47 +0200 | [diff] [blame] | 425 | if (!toplevel->base.configured) { |
| 426 | wl_resource_post_error(toplevel->resource, |
| 427 | ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, |
| 428 | "Surface has not been configured yet"); |
| 429 | return; |
| 430 | } |
| 431 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 432 | weston_desktop_api_resize(toplevel->base.desktop, |
Armin Krezović | 4e2fa0a | 2016-09-10 19:11:21 +0200 | [diff] [blame] | 433 | dsurface, seat, serial, surf_edges); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static void |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 437 | weston_desktop_xdg_toplevel_ack_configure(struct weston_desktop_xdg_toplevel *toplevel, |
| 438 | struct weston_desktop_xdg_toplevel_configure *configure) |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 439 | { |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 440 | toplevel->next.state = configure->state; |
| 441 | toplevel->next.size = configure->size; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | static void |
| 445 | weston_desktop_xdg_toplevel_protocol_set_min_size(struct wl_client *wl_client, |
| 446 | struct wl_resource *resource, |
| 447 | int32_t width, int32_t height) |
| 448 | { |
| 449 | struct weston_desktop_surface *dsurface = |
| 450 | wl_resource_get_user_data(resource); |
| 451 | struct weston_desktop_xdg_toplevel *toplevel = |
| 452 | weston_desktop_surface_get_implementation_data(dsurface); |
| 453 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 454 | toplevel->next.min_size.width = width; |
| 455 | toplevel->next.min_size.height = height; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static void |
| 459 | weston_desktop_xdg_toplevel_protocol_set_max_size(struct wl_client *wl_client, |
| 460 | struct wl_resource *resource, |
| 461 | int32_t width, int32_t height) |
| 462 | { |
| 463 | struct weston_desktop_surface *dsurface = |
| 464 | wl_resource_get_user_data(resource); |
| 465 | struct weston_desktop_xdg_toplevel *toplevel = |
| 466 | weston_desktop_surface_get_implementation_data(dsurface); |
| 467 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 468 | toplevel->next.max_size.width = width; |
| 469 | toplevel->next.max_size.height = height; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static void |
| 473 | weston_desktop_xdg_toplevel_protocol_set_maximized(struct wl_client *wl_client, |
| 474 | struct wl_resource *resource) |
| 475 | { |
| 476 | struct weston_desktop_surface *dsurface = |
| 477 | wl_resource_get_user_data(resource); |
| 478 | struct weston_desktop_xdg_toplevel *toplevel = |
| 479 | weston_desktop_surface_get_implementation_data(dsurface); |
| 480 | |
Quentin Glidic | 3d7e607 | 2016-09-11 11:29:23 +0200 | [diff] [blame] | 481 | weston_desktop_xdg_toplevel_ensure_added(toplevel); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 482 | weston_desktop_api_maximized_requested(toplevel->base.desktop, dsurface, true); |
| 483 | } |
| 484 | |
| 485 | static void |
| 486 | weston_desktop_xdg_toplevel_protocol_unset_maximized(struct wl_client *wl_client, |
| 487 | struct wl_resource *resource) |
| 488 | { |
| 489 | struct weston_desktop_surface *dsurface = |
| 490 | wl_resource_get_user_data(resource); |
| 491 | struct weston_desktop_xdg_toplevel *toplevel = |
| 492 | weston_desktop_surface_get_implementation_data(dsurface); |
| 493 | |
Quentin Glidic | 3d7e607 | 2016-09-11 11:29:23 +0200 | [diff] [blame] | 494 | weston_desktop_xdg_toplevel_ensure_added(toplevel); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 495 | weston_desktop_api_maximized_requested(toplevel->base.desktop, dsurface, false); |
| 496 | } |
| 497 | |
| 498 | static void |
| 499 | weston_desktop_xdg_toplevel_protocol_set_fullscreen(struct wl_client *wl_client, |
| 500 | struct wl_resource *resource, |
| 501 | struct wl_resource *output_resource) |
| 502 | { |
| 503 | struct weston_desktop_surface *dsurface = |
| 504 | wl_resource_get_user_data(resource); |
| 505 | struct weston_desktop_xdg_toplevel *toplevel = |
| 506 | weston_desktop_surface_get_implementation_data(dsurface); |
| 507 | struct weston_output *output = NULL; |
| 508 | |
| 509 | if (output_resource != NULL) |
| 510 | output = wl_resource_get_user_data(output_resource); |
| 511 | |
Quentin Glidic | 3d7e607 | 2016-09-11 11:29:23 +0200 | [diff] [blame] | 512 | weston_desktop_xdg_toplevel_ensure_added(toplevel); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 513 | weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface, |
| 514 | true, output); |
| 515 | } |
| 516 | |
| 517 | static void |
| 518 | weston_desktop_xdg_toplevel_protocol_unset_fullscreen(struct wl_client *wl_client, |
| 519 | struct wl_resource *resource) |
| 520 | { |
| 521 | struct weston_desktop_surface *dsurface = |
| 522 | wl_resource_get_user_data(resource); |
| 523 | struct weston_desktop_xdg_toplevel *toplevel = |
| 524 | weston_desktop_surface_get_implementation_data(dsurface); |
| 525 | |
Quentin Glidic | 3d7e607 | 2016-09-11 11:29:23 +0200 | [diff] [blame] | 526 | weston_desktop_xdg_toplevel_ensure_added(toplevel); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 527 | weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface, |
| 528 | false, NULL); |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | weston_desktop_xdg_toplevel_protocol_set_minimized(struct wl_client *wl_client, |
| 533 | struct wl_resource *resource) |
| 534 | { |
| 535 | struct weston_desktop_surface *dsurface = |
| 536 | wl_resource_get_user_data(resource); |
| 537 | struct weston_desktop_xdg_toplevel *toplevel = |
| 538 | weston_desktop_surface_get_implementation_data(dsurface); |
| 539 | |
Quentin Glidic | 3d7e607 | 2016-09-11 11:29:23 +0200 | [diff] [blame] | 540 | weston_desktop_xdg_toplevel_ensure_added(toplevel); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 541 | weston_desktop_api_minimized_requested(toplevel->base.desktop, dsurface); |
| 542 | } |
| 543 | |
| 544 | static void |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 545 | weston_desktop_xdg_toplevel_send_configure(struct weston_desktop_xdg_toplevel *toplevel, |
| 546 | struct weston_desktop_xdg_toplevel_configure *configure) |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 547 | { |
| 548 | uint32_t *s; |
| 549 | struct wl_array states; |
| 550 | |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 551 | configure->state = toplevel->pending.state; |
| 552 | configure->size = toplevel->pending.size; |
| 553 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 554 | wl_array_init(&states); |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 555 | if (toplevel->pending.state.maximized) { |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 556 | s = wl_array_add(&states, sizeof(uint32_t)); |
| 557 | *s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED; |
| 558 | } |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 559 | if (toplevel->pending.state.fullscreen) { |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 560 | s = wl_array_add(&states, sizeof(uint32_t)); |
| 561 | *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN; |
| 562 | } |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 563 | if (toplevel->pending.state.resizing) { |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 564 | s = wl_array_add(&states, sizeof(uint32_t)); |
| 565 | *s = ZXDG_TOPLEVEL_V6_STATE_RESIZING; |
| 566 | } |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 567 | if (toplevel->pending.state.activated) { |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 568 | s = wl_array_add(&states, sizeof(uint32_t)); |
| 569 | *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED; |
| 570 | } |
| 571 | |
| 572 | zxdg_toplevel_v6_send_configure(toplevel->resource, |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 573 | toplevel->pending.size.width, |
| 574 | toplevel->pending.size.height, |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 575 | &states); |
| 576 | |
| 577 | wl_array_release(&states); |
| 578 | }; |
| 579 | |
| 580 | static void |
| 581 | weston_desktop_xdg_toplevel_set_maximized(struct weston_desktop_surface *dsurface, |
| 582 | void *user_data, bool maximized) |
| 583 | { |
| 584 | struct weston_desktop_xdg_toplevel *toplevel = user_data; |
| 585 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 586 | toplevel->pending.state.maximized = maximized; |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 587 | weston_desktop_xdg_surface_schedule_configure(&toplevel->base, false); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | static void |
| 591 | weston_desktop_xdg_toplevel_set_fullscreen(struct weston_desktop_surface *dsurface, |
| 592 | void *user_data, bool fullscreen) |
| 593 | { |
| 594 | struct weston_desktop_xdg_toplevel *toplevel = user_data; |
| 595 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 596 | toplevel->pending.state.fullscreen = fullscreen; |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 597 | weston_desktop_xdg_surface_schedule_configure(&toplevel->base, false); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static void |
| 601 | weston_desktop_xdg_toplevel_set_resizing(struct weston_desktop_surface *dsurface, |
| 602 | void *user_data, bool resizing) |
| 603 | { |
| 604 | struct weston_desktop_xdg_toplevel *toplevel = user_data; |
| 605 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 606 | toplevel->pending.state.resizing = resizing; |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 607 | weston_desktop_xdg_surface_schedule_configure(&toplevel->base, false); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | static void |
| 611 | weston_desktop_xdg_toplevel_set_activated(struct weston_desktop_surface *dsurface, |
| 612 | void *user_data, bool activated) |
| 613 | { |
| 614 | struct weston_desktop_xdg_toplevel *toplevel = user_data; |
| 615 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 616 | toplevel->pending.state.activated = activated; |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 617 | weston_desktop_xdg_surface_schedule_configure(&toplevel->base, false); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static void |
| 621 | weston_desktop_xdg_toplevel_set_size(struct weston_desktop_surface *dsurface, |
| 622 | void *user_data, |
| 623 | int32_t width, int32_t height) |
| 624 | { |
| 625 | struct weston_desktop_xdg_toplevel *toplevel = user_data; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 626 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 627 | toplevel->pending.size.width = width; |
| 628 | toplevel->pending.size.height = height; |
Quentin Glidic | a56b053 | 2016-09-13 10:05:58 +0200 | [diff] [blame] | 629 | |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 630 | weston_desktop_xdg_surface_schedule_configure(&toplevel->base, false); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | static void |
| 634 | weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplevel, |
Quentin Glidic | cba26e7 | 2016-08-15 12:20:22 +0200 | [diff] [blame] | 635 | int32_t sx, int32_t sy) |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 636 | { |
| 637 | struct weston_surface *wsurface = |
| 638 | weston_desktop_surface_get_surface(toplevel->base.desktop_surface); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 639 | |
Quentin Glidic | cba26e7 | 2016-08-15 12:20:22 +0200 | [diff] [blame] | 640 | if (!wsurface->buffer_ref.buffer && !toplevel->added) { |
Quentin Glidic | 3d7e607 | 2016-09-11 11:29:23 +0200 | [diff] [blame] | 641 | weston_desktop_xdg_toplevel_ensure_added(toplevel); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 642 | return; |
| 643 | } |
Quentin Glidic | cba26e7 | 2016-08-15 12:20:22 +0200 | [diff] [blame] | 644 | if (!wsurface->buffer_ref.buffer) |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 645 | return; |
| 646 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 647 | if ((toplevel->next.state.maximized || toplevel->next.state.fullscreen) && |
Quentin Glidic | ac394a1 | 2017-07-12 09:45:43 +0200 | [diff] [blame] | 648 | (toplevel->next.size.width != wsurface->width || |
| 649 | toplevel->next.size.height != wsurface->height)) { |
Quentin Glidic | c84423b | 2017-03-10 11:50:41 +0100 | [diff] [blame] | 650 | struct weston_desktop_client *client = |
| 651 | weston_desktop_surface_get_client(toplevel->base.desktop_surface); |
| 652 | struct wl_resource *client_resource = |
| 653 | weston_desktop_client_get_resource(client); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 654 | |
Quentin Glidic | c84423b | 2017-03-10 11:50:41 +0100 | [diff] [blame] | 655 | wl_resource_post_error(client_resource, |
| 656 | ZXDG_SHELL_V6_ERROR_INVALID_SURFACE_STATE, |
| 657 | "xdg_surface buffer does not match the configured state"); |
| 658 | return; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 659 | } |
Quentin Glidic | c84423b | 2017-03-10 11:50:41 +0100 | [diff] [blame] | 660 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 661 | toplevel->current.state = toplevel->next.state; |
| 662 | toplevel->current.min_size = toplevel->next.min_size; |
| 663 | toplevel->current.max_size = toplevel->next.max_size; |
Quentin Glidic | c84423b | 2017-03-10 11:50:41 +0100 | [diff] [blame] | 664 | |
| 665 | weston_desktop_api_committed(toplevel->base.desktop, |
| 666 | toplevel->base.desktop_surface, |
| 667 | sx, sy); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static void |
| 671 | weston_desktop_xdg_toplevel_close(struct weston_desktop_xdg_toplevel *toplevel) |
| 672 | { |
| 673 | zxdg_toplevel_v6_send_close(toplevel->resource); |
| 674 | } |
| 675 | |
| 676 | static bool |
| 677 | weston_desktop_xdg_toplevel_get_maximized(struct weston_desktop_surface *dsurface, |
| 678 | void *user_data) |
| 679 | { |
| 680 | struct weston_desktop_xdg_toplevel *toplevel = user_data; |
| 681 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 682 | return toplevel->current.state.maximized; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | static bool |
| 686 | weston_desktop_xdg_toplevel_get_fullscreen(struct weston_desktop_surface *dsurface, |
| 687 | void *user_data) |
| 688 | { |
| 689 | struct weston_desktop_xdg_toplevel *toplevel = user_data; |
| 690 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 691 | return toplevel->current.state.fullscreen; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static bool |
| 695 | weston_desktop_xdg_toplevel_get_resizing(struct weston_desktop_surface *dsurface, |
| 696 | void *user_data) |
| 697 | { |
| 698 | struct weston_desktop_xdg_toplevel *toplevel = user_data; |
| 699 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 700 | return toplevel->current.state.resizing; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | static bool |
| 704 | weston_desktop_xdg_toplevel_get_activated(struct weston_desktop_surface *dsurface, |
| 705 | void *user_data) |
| 706 | { |
| 707 | struct weston_desktop_xdg_toplevel *toplevel = user_data; |
| 708 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 709 | return toplevel->current.state.activated; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | static void |
| 713 | weston_desktop_xdg_toplevel_destroy(struct weston_desktop_xdg_toplevel *toplevel) |
| 714 | { |
| 715 | if (toplevel->added) |
| 716 | weston_desktop_api_surface_removed(toplevel->base.desktop, |
| 717 | toplevel->base.desktop_surface); |
| 718 | } |
| 719 | |
| 720 | static void |
| 721 | weston_desktop_xdg_toplevel_resource_destroy(struct wl_resource *resource) |
| 722 | { |
| 723 | struct weston_desktop_surface *dsurface = |
| 724 | wl_resource_get_user_data(resource); |
| 725 | |
| 726 | if (dsurface != NULL) |
| 727 | weston_desktop_surface_resource_destroy(resource); |
| 728 | } |
| 729 | |
| 730 | static const struct zxdg_toplevel_v6_interface weston_desktop_xdg_toplevel_implementation = { |
| 731 | .destroy = weston_desktop_destroy_request, |
| 732 | .set_parent = weston_desktop_xdg_toplevel_protocol_set_parent, |
| 733 | .set_title = weston_desktop_xdg_toplevel_protocol_set_title, |
| 734 | .set_app_id = weston_desktop_xdg_toplevel_protocol_set_app_id, |
| 735 | .show_window_menu = weston_desktop_xdg_toplevel_protocol_show_window_menu, |
| 736 | .move = weston_desktop_xdg_toplevel_protocol_move, |
| 737 | .resize = weston_desktop_xdg_toplevel_protocol_resize, |
| 738 | .set_min_size = weston_desktop_xdg_toplevel_protocol_set_min_size, |
| 739 | .set_max_size = weston_desktop_xdg_toplevel_protocol_set_max_size, |
| 740 | .set_maximized = weston_desktop_xdg_toplevel_protocol_set_maximized, |
| 741 | .unset_maximized = weston_desktop_xdg_toplevel_protocol_unset_maximized, |
| 742 | .set_fullscreen = weston_desktop_xdg_toplevel_protocol_set_fullscreen, |
| 743 | .unset_fullscreen = weston_desktop_xdg_toplevel_protocol_unset_fullscreen, |
| 744 | .set_minimized = weston_desktop_xdg_toplevel_protocol_set_minimized, |
| 745 | }; |
| 746 | |
| 747 | static void |
| 748 | weston_desktop_xdg_popup_protocol_grab(struct wl_client *wl_client, |
| 749 | struct wl_resource *resource, |
| 750 | struct wl_resource *seat_resource, |
| 751 | uint32_t serial) |
| 752 | { |
| 753 | struct weston_desktop_surface *dsurface = |
| 754 | wl_resource_get_user_data(resource); |
| 755 | struct weston_desktop_xdg_popup *popup = |
| 756 | weston_desktop_surface_get_implementation_data(dsurface); |
| 757 | struct weston_seat *wseat = wl_resource_get_user_data(seat_resource); |
| 758 | struct weston_desktop_seat *seat = weston_desktop_seat_from_seat(wseat); |
| 759 | struct weston_desktop_surface *topmost; |
| 760 | bool parent_is_toplevel = |
| 761 | popup->parent->role == WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL; |
| 762 | |
| 763 | if (popup->committed) { |
| 764 | wl_resource_post_error(popup->resource, |
| 765 | ZXDG_POPUP_V6_ERROR_INVALID_GRAB, |
| 766 | "xdg_popup already is mapped"); |
| 767 | return; |
| 768 | } |
| 769 | |
| 770 | topmost = weston_desktop_seat_popup_grab_get_topmost_surface(seat); |
| 771 | if ((topmost == NULL && !parent_is_toplevel) || |
| 772 | (topmost != NULL && topmost != popup->parent->desktop_surface)) { |
| 773 | struct weston_desktop_client *client = |
| 774 | weston_desktop_surface_get_client(dsurface); |
| 775 | struct wl_resource *client_resource = |
| 776 | weston_desktop_client_get_resource(client); |
| 777 | |
| 778 | wl_resource_post_error(client_resource, |
| 779 | ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP, |
| 780 | "xdg_popup was not created on the topmost popup"); |
| 781 | return; |
| 782 | } |
| 783 | |
| 784 | popup->seat = seat; |
| 785 | weston_desktop_surface_popup_grab(popup->base.desktop_surface, |
| 786 | popup->seat, serial); |
| 787 | } |
| 788 | |
| 789 | static void |
| 790 | weston_desktop_xdg_popup_send_configure(struct weston_desktop_xdg_popup *popup) |
| 791 | { |
| 792 | zxdg_popup_v6_send_configure(popup->resource, |
| 793 | popup->geometry.x, |
| 794 | popup->geometry.y, |
| 795 | popup->geometry.width, |
| 796 | popup->geometry.height); |
| 797 | } |
| 798 | |
| 799 | static void |
| 800 | weston_desktop_xdg_popup_update_position(struct weston_desktop_surface *dsurface, |
| 801 | void *user_data); |
| 802 | |
| 803 | static void |
| 804 | weston_desktop_xdg_popup_committed(struct weston_desktop_xdg_popup *popup) |
| 805 | { |
| 806 | if (!popup->committed) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 807 | weston_desktop_xdg_surface_schedule_configure(&popup->base, true); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 808 | popup->committed = true; |
| 809 | weston_desktop_xdg_popup_update_position(popup->base.desktop_surface, |
| 810 | popup); |
| 811 | } |
| 812 | |
| 813 | static void |
| 814 | weston_desktop_xdg_popup_update_position(struct weston_desktop_surface *dsurface, |
| 815 | void *user_data) |
| 816 | { |
| 817 | } |
| 818 | |
| 819 | static void |
| 820 | weston_desktop_xdg_popup_close(struct weston_desktop_xdg_popup *popup) |
| 821 | { |
| 822 | zxdg_popup_v6_send_popup_done(popup->resource); |
| 823 | } |
| 824 | |
| 825 | static void |
| 826 | weston_desktop_xdg_popup_destroy(struct weston_desktop_xdg_popup *popup) |
| 827 | { |
| 828 | struct weston_desktop_surface *topmost; |
| 829 | struct weston_desktop_client *client = |
| 830 | weston_desktop_surface_get_client(popup->base.desktop_surface); |
| 831 | |
| 832 | if (!weston_desktop_surface_get_grab(popup->base.desktop_surface)) |
| 833 | return; |
| 834 | |
| 835 | topmost = weston_desktop_seat_popup_grab_get_topmost_surface(popup->seat); |
| 836 | if (topmost != popup->base.desktop_surface) { |
| 837 | struct wl_resource *client_resource = |
| 838 | weston_desktop_client_get_resource(client); |
| 839 | |
| 840 | wl_resource_post_error(client_resource, |
| 841 | ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP, |
| 842 | "xdg_popup was destroyed while it was not the topmost popup."); |
| 843 | } |
| 844 | |
| 845 | weston_desktop_surface_popup_ungrab(popup->base.desktop_surface, |
| 846 | popup->seat); |
| 847 | } |
| 848 | |
| 849 | static void |
| 850 | weston_desktop_xdg_popup_resource_destroy(struct wl_resource *resource) |
| 851 | { |
| 852 | struct weston_desktop_surface *dsurface = |
| 853 | wl_resource_get_user_data(resource); |
| 854 | |
| 855 | if (dsurface != NULL) |
| 856 | weston_desktop_surface_resource_destroy(resource); |
| 857 | } |
| 858 | |
| 859 | static const struct zxdg_popup_v6_interface weston_desktop_xdg_popup_implementation = { |
| 860 | .destroy = weston_desktop_destroy_request, |
| 861 | .grab = weston_desktop_xdg_popup_protocol_grab, |
| 862 | }; |
| 863 | |
| 864 | static void |
| 865 | weston_desktop_xdg_surface_send_configure(void *user_data) |
| 866 | { |
| 867 | struct weston_desktop_xdg_surface *surface = user_data; |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 868 | struct weston_desktop_xdg_surface_configure *configure; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 869 | |
| 870 | surface->configure_idle = NULL; |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 871 | |
| 872 | configure = zalloc(weston_desktop_surface_configure_biggest_size); |
| 873 | if (configure == NULL) { |
| 874 | struct weston_desktop_client *client = |
| 875 | weston_desktop_surface_get_client(surface->desktop_surface); |
| 876 | struct wl_client *wl_client = |
| 877 | weston_desktop_client_get_client(client); |
| 878 | wl_client_post_no_memory(wl_client); |
| 879 | return; |
| 880 | } |
| 881 | wl_list_insert(surface->configure_list.prev, &configure->link); |
| 882 | configure->serial = |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 883 | wl_display_next_serial(weston_desktop_get_display(surface->desktop)); |
| 884 | |
| 885 | switch (surface->role) { |
| 886 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE: |
| 887 | assert(0 && "not reached"); |
| 888 | break; |
| 889 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL: |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 890 | weston_desktop_xdg_toplevel_send_configure((struct weston_desktop_xdg_toplevel *) surface, |
| 891 | (struct weston_desktop_xdg_toplevel_configure *) configure); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 892 | break; |
| 893 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP: |
| 894 | weston_desktop_xdg_popup_send_configure((struct weston_desktop_xdg_popup *) surface); |
| 895 | break; |
| 896 | } |
| 897 | |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 898 | zxdg_surface_v6_send_configure(surface->resource, configure->serial); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 899 | } |
| 900 | |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 901 | static bool |
| 902 | weston_desktop_xdg_toplevel_state_compare(struct weston_desktop_xdg_toplevel *toplevel) |
| 903 | { |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 904 | if (toplevel->pending.state.activated != toplevel->current.state.activated) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 905 | return false; |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 906 | if (toplevel->pending.state.fullscreen != toplevel->current.state.fullscreen) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 907 | return false; |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 908 | if (toplevel->pending.state.maximized != toplevel->current.state.maximized) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 909 | return false; |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 910 | if (toplevel->pending.state.resizing != toplevel->current.state.resizing) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 911 | return false; |
| 912 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 913 | if (toplevel->base.surface->width == toplevel->pending.size.width && |
| 914 | toplevel->base.surface->height == toplevel->pending.size.height) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 915 | return true; |
| 916 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 917 | if (toplevel->pending.size.width == 0 && |
| 918 | toplevel->pending.size.height == 0) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 919 | return true; |
| 920 | |
| 921 | return false; |
| 922 | } |
| 923 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 924 | static void |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 925 | weston_desktop_xdg_surface_schedule_configure(struct weston_desktop_xdg_surface *surface, |
| 926 | bool force) |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 927 | { |
| 928 | struct wl_display *display = weston_desktop_get_display(surface->desktop); |
| 929 | struct wl_event_loop *loop = wl_display_get_event_loop(display); |
Quentin Glidic | 218126d | 2017-07-11 13:31:36 +0200 | [diff] [blame] | 930 | bool pending_same = !force; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 931 | |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 932 | switch (surface->role) { |
| 933 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE: |
| 934 | assert(0 && "not reached"); |
| 935 | break; |
| 936 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL: |
Quentin Glidic | 218126d | 2017-07-11 13:31:36 +0200 | [diff] [blame] | 937 | pending_same = pending_same && |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 938 | weston_desktop_xdg_toplevel_state_compare((struct weston_desktop_xdg_toplevel *) surface); |
| 939 | break; |
| 940 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP: |
| 941 | break; |
| 942 | } |
| 943 | |
| 944 | if (surface->configure_idle != NULL) { |
Quentin Glidic | 218126d | 2017-07-11 13:31:36 +0200 | [diff] [blame] | 945 | if (!pending_same) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 946 | return; |
| 947 | |
| 948 | wl_event_source_remove(surface->configure_idle); |
| 949 | surface->configure_idle = NULL; |
| 950 | } else { |
Quentin Glidic | 218126d | 2017-07-11 13:31:36 +0200 | [diff] [blame] | 951 | if (pending_same) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 952 | return; |
| 953 | |
| 954 | surface->configure_idle = |
| 955 | wl_event_loop_add_idle(loop, |
| 956 | weston_desktop_xdg_surface_send_configure, |
| 957 | surface); |
| 958 | } |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static void |
| 962 | weston_desktop_xdg_surface_protocol_get_toplevel(struct wl_client *wl_client, |
| 963 | struct wl_resource *resource, |
| 964 | uint32_t id) |
| 965 | { |
| 966 | struct weston_desktop_surface *dsurface = |
| 967 | wl_resource_get_user_data(resource); |
| 968 | struct weston_surface *wsurface = |
| 969 | weston_desktop_surface_get_surface(dsurface); |
| 970 | struct weston_desktop_xdg_toplevel *toplevel = |
| 971 | weston_desktop_surface_get_implementation_data(dsurface); |
| 972 | |
| 973 | if (weston_surface_set_role(wsurface, weston_desktop_xdg_toplevel_role, |
| 974 | resource, ZXDG_SHELL_V6_ERROR_ROLE) < 0) |
| 975 | return; |
| 976 | |
| 977 | toplevel->resource = |
| 978 | weston_desktop_surface_add_resource(toplevel->base.desktop_surface, |
| 979 | &zxdg_toplevel_v6_interface, |
| 980 | &weston_desktop_xdg_toplevel_implementation, |
| 981 | id, weston_desktop_xdg_toplevel_resource_destroy); |
| 982 | if (toplevel->resource == NULL) |
| 983 | return; |
| 984 | |
| 985 | toplevel->base.role = WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL; |
| 986 | } |
| 987 | |
| 988 | static void |
| 989 | weston_desktop_xdg_surface_protocol_get_popup(struct wl_client *wl_client, |
| 990 | struct wl_resource *resource, |
| 991 | uint32_t id, |
| 992 | struct wl_resource *parent_resource, |
| 993 | struct wl_resource *positioner_resource) |
| 994 | { |
| 995 | struct weston_desktop_surface *dsurface = |
| 996 | wl_resource_get_user_data(resource); |
| 997 | struct weston_surface *wsurface = |
| 998 | weston_desktop_surface_get_surface(dsurface); |
| 999 | struct weston_desktop_xdg_popup *popup = |
| 1000 | weston_desktop_surface_get_implementation_data(dsurface); |
| 1001 | struct weston_desktop_surface *parent_surface = |
| 1002 | wl_resource_get_user_data(parent_resource); |
| 1003 | struct weston_desktop_xdg_surface *parent = |
| 1004 | weston_desktop_surface_get_implementation_data(parent_surface); |
| 1005 | struct weston_desktop_xdg_positioner *positioner = |
| 1006 | wl_resource_get_user_data(positioner_resource); |
| 1007 | |
Sjoerd Simons | be8a6d3 | 2016-09-23 09:31:23 +0200 | [diff] [blame] | 1008 | /* Checking whether the size and anchor rect both have a positive size |
| 1009 | * is enough to verify both have been correctly set */ |
| 1010 | if (positioner->size.width == 0 || positioner->anchor_rect.width == 0) { |
| 1011 | wl_resource_post_error(resource, |
| 1012 | ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER, |
| 1013 | "positioner object is not complete"); |
| 1014 | return; |
| 1015 | } |
| 1016 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1017 | if (weston_surface_set_role(wsurface, weston_desktop_xdg_popup_role, |
| 1018 | resource, ZXDG_SHELL_V6_ERROR_ROLE) < 0) |
| 1019 | return; |
| 1020 | |
| 1021 | popup->resource = |
| 1022 | weston_desktop_surface_add_resource(popup->base.desktop_surface, |
| 1023 | &zxdg_popup_v6_interface, |
| 1024 | &weston_desktop_xdg_popup_implementation, |
| 1025 | id, weston_desktop_xdg_popup_resource_destroy); |
| 1026 | if (popup->resource == NULL) |
| 1027 | return; |
| 1028 | |
| 1029 | popup->base.role = WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP; |
| 1030 | popup->parent = parent; |
| 1031 | |
| 1032 | popup->geometry = |
| 1033 | weston_desktop_xdg_positioner_get_geometry(positioner, |
| 1034 | dsurface, |
| 1035 | parent_surface); |
| 1036 | |
| 1037 | weston_desktop_surface_set_relative_to(popup->base.desktop_surface, |
| 1038 | parent_surface, |
| 1039 | popup->geometry.x, |
| 1040 | popup->geometry.y, |
| 1041 | true); |
| 1042 | } |
| 1043 | |
| 1044 | static bool |
| 1045 | weston_desktop_xdg_surface_check_role(struct weston_desktop_xdg_surface *surface) |
| 1046 | { |
| 1047 | struct weston_surface *wsurface = |
| 1048 | weston_desktop_surface_get_surface(surface->desktop_surface); |
| 1049 | const char *role; |
| 1050 | |
| 1051 | role = weston_surface_get_role(wsurface); |
| 1052 | if (role != NULL && |
| 1053 | (role == weston_desktop_xdg_toplevel_role || |
| 1054 | role == weston_desktop_xdg_popup_role)) |
| 1055 | return true; |
| 1056 | |
| 1057 | wl_resource_post_error(surface->resource, |
| 1058 | ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, |
| 1059 | "xdg_surface must have a role"); |
| 1060 | return false; |
| 1061 | } |
| 1062 | |
| 1063 | static void |
| 1064 | weston_desktop_xdg_surface_protocol_set_window_geometry(struct wl_client *wl_client, |
| 1065 | struct wl_resource *resource, |
| 1066 | int32_t x, int32_t y, |
| 1067 | int32_t width, int32_t height) |
| 1068 | { |
| 1069 | struct weston_desktop_surface *dsurface = |
| 1070 | wl_resource_get_user_data(resource); |
| 1071 | struct weston_desktop_xdg_surface *surface = |
| 1072 | weston_desktop_surface_get_implementation_data(dsurface); |
| 1073 | |
| 1074 | if (!weston_desktop_xdg_surface_check_role(surface)) |
| 1075 | return; |
| 1076 | |
| 1077 | surface->has_next_geometry = true; |
| 1078 | surface->next_geometry.x = x; |
| 1079 | surface->next_geometry.y = y; |
| 1080 | surface->next_geometry.width = width; |
| 1081 | surface->next_geometry.height = height; |
| 1082 | } |
| 1083 | |
| 1084 | static void |
| 1085 | weston_desktop_xdg_surface_protocol_ack_configure(struct wl_client *wl_client, |
| 1086 | struct wl_resource *resource, |
| 1087 | uint32_t serial) |
| 1088 | { |
| 1089 | struct weston_desktop_surface *dsurface = |
| 1090 | wl_resource_get_user_data(resource); |
| 1091 | struct weston_desktop_xdg_surface *surface = |
| 1092 | weston_desktop_surface_get_implementation_data(dsurface); |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 1093 | struct weston_desktop_xdg_surface_configure *configure, *temp; |
| 1094 | bool found = false; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1095 | |
| 1096 | if (!weston_desktop_xdg_surface_check_role(surface)) |
| 1097 | return; |
| 1098 | |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 1099 | wl_list_for_each_safe(configure, temp, &surface->configure_list, link) { |
| 1100 | if (configure->serial < serial) { |
| 1101 | wl_list_remove(&configure->link); |
| 1102 | free(configure); |
| 1103 | } else if (configure->serial == serial) { |
| 1104 | wl_list_remove(&configure->link); |
| 1105 | found = true; |
| 1106 | } |
| 1107 | break; |
| 1108 | } |
| 1109 | if (!found) { |
| 1110 | struct weston_desktop_client *client = |
| 1111 | weston_desktop_surface_get_client(dsurface); |
| 1112 | struct wl_resource *client_resource = |
| 1113 | weston_desktop_client_get_resource(client); |
| 1114 | wl_resource_post_error(client_resource, |
| 1115 | ZXDG_SHELL_V6_ERROR_INVALID_SURFACE_STATE, |
| 1116 | "Wrong configure serial: %u", serial); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1117 | return; |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 1118 | } |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1119 | |
| 1120 | surface->configured = true; |
| 1121 | |
| 1122 | switch (surface->role) { |
| 1123 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE: |
| 1124 | assert(0 && "not reached"); |
| 1125 | break; |
| 1126 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL: |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 1127 | weston_desktop_xdg_toplevel_ack_configure((struct weston_desktop_xdg_toplevel *) surface, |
| 1128 | (struct weston_desktop_xdg_toplevel_configure *) configure); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1129 | break; |
| 1130 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP: |
| 1131 | break; |
| 1132 | } |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 1133 | |
| 1134 | free(configure); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | static void |
| 1138 | weston_desktop_xdg_surface_ping(struct weston_desktop_surface *dsurface, |
| 1139 | uint32_t serial, void *user_data) |
| 1140 | { |
| 1141 | struct weston_desktop_client *client = |
| 1142 | weston_desktop_surface_get_client(dsurface); |
| 1143 | |
| 1144 | zxdg_shell_v6_send_ping(weston_desktop_client_get_resource(client), |
| 1145 | serial); |
| 1146 | } |
| 1147 | |
| 1148 | static void |
| 1149 | weston_desktop_xdg_surface_committed(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 003da88 | 2016-08-15 12:21:39 +0200 | [diff] [blame] | 1150 | void *user_data, |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1151 | int32_t sx, int32_t sy) |
| 1152 | { |
| 1153 | struct weston_desktop_xdg_surface *surface = user_data; |
Quentin Glidic | cba26e7 | 2016-08-15 12:20:22 +0200 | [diff] [blame] | 1154 | struct weston_surface *wsurface = |
| 1155 | weston_desktop_surface_get_surface (dsurface); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1156 | |
Quentin Glidic | cba26e7 | 2016-08-15 12:20:22 +0200 | [diff] [blame] | 1157 | if (wsurface->buffer_ref.buffer && !surface->configured) { |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1158 | wl_resource_post_error(surface->resource, |
| 1159 | ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, |
| 1160 | "xdg_surface has never been configured"); |
| 1161 | return; |
| 1162 | } |
| 1163 | |
| 1164 | if (surface->has_next_geometry) { |
| 1165 | surface->has_next_geometry = false; |
| 1166 | weston_desktop_surface_set_geometry(surface->desktop_surface, |
| 1167 | surface->next_geometry); |
| 1168 | } |
| 1169 | |
| 1170 | switch (surface->role) { |
| 1171 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE: |
| 1172 | wl_resource_post_error(surface->resource, |
| 1173 | ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, |
| 1174 | "xdg_surface must have a role"); |
| 1175 | break; |
| 1176 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL: |
Quentin Glidic | cba26e7 | 2016-08-15 12:20:22 +0200 | [diff] [blame] | 1177 | weston_desktop_xdg_toplevel_committed((struct weston_desktop_xdg_toplevel *) surface, sx, sy); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1178 | break; |
| 1179 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP: |
| 1180 | weston_desktop_xdg_popup_committed((struct weston_desktop_xdg_popup *) surface); |
| 1181 | break; |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | static void |
| 1186 | weston_desktop_xdg_surface_close(struct weston_desktop_surface *dsurface, |
| 1187 | void *user_data) |
| 1188 | { |
| 1189 | struct weston_desktop_xdg_surface *surface = user_data; |
| 1190 | |
| 1191 | switch (surface->role) { |
| 1192 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE: |
| 1193 | assert(0 && "not reached"); |
| 1194 | break; |
| 1195 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL: |
| 1196 | weston_desktop_xdg_toplevel_close((struct weston_desktop_xdg_toplevel *) surface); |
| 1197 | break; |
| 1198 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP: |
| 1199 | weston_desktop_xdg_popup_close((struct weston_desktop_xdg_popup *) surface); |
| 1200 | break; |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | static void |
| 1205 | weston_desktop_xdg_surface_destroy(struct weston_desktop_surface *dsurface, |
| 1206 | void *user_data) |
| 1207 | { |
| 1208 | struct weston_desktop_xdg_surface *surface = user_data; |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 1209 | struct weston_desktop_xdg_surface_configure *configure, *temp; |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1210 | |
| 1211 | switch (surface->role) { |
| 1212 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE: |
| 1213 | break; |
| 1214 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL: |
| 1215 | weston_desktop_xdg_toplevel_destroy((struct weston_desktop_xdg_toplevel *) surface); |
| 1216 | break; |
| 1217 | case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP: |
| 1218 | weston_desktop_xdg_popup_destroy((struct weston_desktop_xdg_popup *) surface); |
| 1219 | break; |
| 1220 | } |
| 1221 | |
| 1222 | if (surface->configure_idle != NULL) |
| 1223 | wl_event_source_remove(surface->configure_idle); |
| 1224 | |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 1225 | wl_list_for_each_safe(configure, temp, &surface->configure_list, link) |
| 1226 | free(configure); |
| 1227 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1228 | free(surface); |
| 1229 | } |
| 1230 | |
| 1231 | static const struct zxdg_surface_v6_interface weston_desktop_xdg_surface_implementation = { |
| 1232 | .destroy = weston_desktop_destroy_request, |
| 1233 | .get_toplevel = weston_desktop_xdg_surface_protocol_get_toplevel, |
| 1234 | .get_popup = weston_desktop_xdg_surface_protocol_get_popup, |
| 1235 | .set_window_geometry = weston_desktop_xdg_surface_protocol_set_window_geometry, |
| 1236 | .ack_configure = weston_desktop_xdg_surface_protocol_ack_configure, |
| 1237 | }; |
| 1238 | |
| 1239 | static const struct weston_desktop_surface_implementation weston_desktop_xdg_surface_internal_implementation = { |
| 1240 | /* These are used for toplevel only */ |
| 1241 | .set_maximized = weston_desktop_xdg_toplevel_set_maximized, |
| 1242 | .set_fullscreen = weston_desktop_xdg_toplevel_set_fullscreen, |
| 1243 | .set_resizing = weston_desktop_xdg_toplevel_set_resizing, |
| 1244 | .set_activated = weston_desktop_xdg_toplevel_set_activated, |
| 1245 | .set_size = weston_desktop_xdg_toplevel_set_size, |
| 1246 | |
| 1247 | .get_maximized = weston_desktop_xdg_toplevel_get_maximized, |
| 1248 | .get_fullscreen = weston_desktop_xdg_toplevel_get_fullscreen, |
| 1249 | .get_resizing = weston_desktop_xdg_toplevel_get_resizing, |
| 1250 | .get_activated = weston_desktop_xdg_toplevel_get_activated, |
| 1251 | |
| 1252 | /* These are used for popup only */ |
| 1253 | .update_position = weston_desktop_xdg_popup_update_position, |
| 1254 | |
| 1255 | /* Common API */ |
| 1256 | .committed = weston_desktop_xdg_surface_committed, |
| 1257 | .ping = weston_desktop_xdg_surface_ping, |
| 1258 | .close = weston_desktop_xdg_surface_close, |
| 1259 | |
| 1260 | .destroy = weston_desktop_xdg_surface_destroy, |
| 1261 | }; |
| 1262 | |
| 1263 | static void |
| 1264 | weston_desktop_xdg_shell_protocol_create_positioner(struct wl_client *wl_client, |
| 1265 | struct wl_resource *resource, |
| 1266 | uint32_t id) |
| 1267 | { |
| 1268 | struct weston_desktop_client *client = |
| 1269 | wl_resource_get_user_data(resource); |
| 1270 | struct weston_desktop_xdg_positioner *positioner; |
| 1271 | |
| 1272 | positioner = zalloc(sizeof(struct weston_desktop_xdg_positioner)); |
| 1273 | if (positioner == NULL) { |
| 1274 | wl_client_post_no_memory(wl_client); |
| 1275 | return; |
| 1276 | } |
| 1277 | |
| 1278 | positioner->client = client; |
| 1279 | positioner->desktop = weston_desktop_client_get_desktop(positioner->client); |
| 1280 | |
| 1281 | positioner->resource = |
| 1282 | wl_resource_create(wl_client, |
| 1283 | &zxdg_positioner_v6_interface, |
| 1284 | wl_resource_get_version(resource), id); |
| 1285 | if (positioner->resource == NULL) { |
| 1286 | wl_client_post_no_memory(wl_client); |
| 1287 | free(positioner); |
| 1288 | return; |
| 1289 | } |
| 1290 | wl_resource_set_implementation(positioner->resource, |
| 1291 | &weston_desktop_xdg_positioner_implementation, |
| 1292 | positioner, weston_desktop_xdg_positioner_destroy); |
| 1293 | } |
| 1294 | |
| 1295 | static void |
| 1296 | weston_desktop_xdg_surface_resource_destroy(struct wl_resource *resource) |
| 1297 | { |
| 1298 | struct weston_desktop_surface *dsurface = |
| 1299 | wl_resource_get_user_data(resource); |
| 1300 | |
| 1301 | if (dsurface != NULL) |
| 1302 | weston_desktop_surface_resource_destroy(resource); |
| 1303 | } |
| 1304 | |
| 1305 | static void |
| 1306 | weston_desktop_xdg_shell_protocol_get_xdg_surface(struct wl_client *wl_client, |
| 1307 | struct wl_resource *resource, |
| 1308 | uint32_t id, |
| 1309 | struct wl_resource *surface_resource) |
| 1310 | { |
| 1311 | struct weston_desktop_client *client = |
| 1312 | wl_resource_get_user_data(resource); |
| 1313 | struct weston_surface *wsurface = |
| 1314 | wl_resource_get_user_data(surface_resource); |
| 1315 | struct weston_desktop_xdg_surface *surface; |
| 1316 | |
| 1317 | surface = zalloc(weston_desktop_surface_role_biggest_size); |
| 1318 | if (surface == NULL) { |
| 1319 | wl_client_post_no_memory(wl_client); |
| 1320 | return; |
| 1321 | } |
| 1322 | |
| 1323 | surface->desktop = weston_desktop_client_get_desktop(client); |
| 1324 | surface->surface = wsurface; |
| 1325 | |
| 1326 | surface->desktop_surface = |
| 1327 | weston_desktop_surface_create(surface->desktop, client, |
| 1328 | surface->surface, |
| 1329 | &weston_desktop_xdg_surface_internal_implementation, |
| 1330 | surface); |
| 1331 | if (surface->desktop_surface == NULL) { |
| 1332 | free(surface); |
| 1333 | return; |
| 1334 | } |
| 1335 | |
| 1336 | surface->resource = |
| 1337 | weston_desktop_surface_add_resource(surface->desktop_surface, |
| 1338 | &zxdg_surface_v6_interface, |
| 1339 | &weston_desktop_xdg_surface_implementation, |
| 1340 | id, weston_desktop_xdg_surface_resource_destroy); |
| 1341 | if (surface->resource == NULL) |
| 1342 | return; |
| 1343 | |
| 1344 | if (wsurface->buffer_ref.buffer != NULL) { |
| 1345 | wl_resource_post_error(surface->resource, |
| 1346 | ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, |
| 1347 | "xdg_surface must not have a buffer at creation"); |
| 1348 | return; |
| 1349 | } |
Quentin Glidic | 749637a | 2017-07-18 12:59:14 +0200 | [diff] [blame^] | 1350 | |
| 1351 | wl_list_init(&surface->configure_list); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | static void |
| 1355 | weston_desktop_xdg_shell_protocol_pong(struct wl_client *wl_client, |
| 1356 | struct wl_resource *resource, |
| 1357 | uint32_t serial) |
| 1358 | { |
| 1359 | struct weston_desktop_client *client = |
| 1360 | wl_resource_get_user_data(resource); |
| 1361 | |
| 1362 | weston_desktop_client_pong(client, serial); |
| 1363 | } |
| 1364 | |
| 1365 | static const struct zxdg_shell_v6_interface weston_desktop_xdg_shell_implementation = { |
| 1366 | .destroy = weston_desktop_destroy_request, |
| 1367 | .create_positioner = weston_desktop_xdg_shell_protocol_create_positioner, |
| 1368 | .get_xdg_surface = weston_desktop_xdg_shell_protocol_get_xdg_surface, |
| 1369 | .pong = weston_desktop_xdg_shell_protocol_pong, |
| 1370 | }; |
| 1371 | |
| 1372 | static void |
| 1373 | weston_desktop_xdg_shell_bind(struct wl_client *client, void *data, |
| 1374 | uint32_t version, uint32_t id) |
| 1375 | { |
| 1376 | struct weston_desktop *desktop = data; |
| 1377 | |
| 1378 | weston_desktop_client_create(desktop, client, NULL, |
| 1379 | &zxdg_shell_v6_interface, |
| 1380 | &weston_desktop_xdg_shell_implementation, |
| 1381 | version, id); |
| 1382 | } |
| 1383 | |
| 1384 | struct wl_global * |
| 1385 | weston_desktop_xdg_shell_v6_create(struct weston_desktop *desktop, struct wl_display *display) |
| 1386 | { |
| 1387 | return wl_global_create(display, &zxdg_shell_v6_interface, |
| 1388 | WD_XDG_SHELL_PROTOCOL_VERSION, desktop, |
| 1389 | weston_desktop_xdg_shell_bind); |
| 1390 | } |