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