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