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