blob: d4d0112ed851302a5a518ba74b479242d0c00186 [file] [log] [blame]
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +02001/*
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"
36#include "protocol/xdg-shell-unstable-v6-server-protocol.h"
37
38#include "libweston-desktop.h"
39#include "internal.h"
40
41#define WD_XDG_SHELL_PROTOCOL_VERSION 1
42
43static const char *weston_desktop_xdg_toplevel_role = "xdg_toplevel";
44static const char *weston_desktop_xdg_popup_role = "xdg_popup";
45
46struct 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
59enum 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
65struct 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
80struct weston_desktop_xdg_toplevel {
81 struct weston_desktop_xdg_surface base;
82
83 struct wl_resource *resource;
84 bool added;
85 struct weston_size requested_size;
86 struct {
87 bool maximized;
88 bool fullscreen;
89 bool resizing;
90 bool activated;
91 } requested_state, next_state, state;
92 struct weston_size
93 next_max_size, max_size,
94 next_min_size, min_size;
95};
96
97struct 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
110static struct weston_geometry
111weston_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
158static void
159weston_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
177static void
178weston_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
199static void
200weston_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
220static void
221weston_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
241static void
242weston_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
252static void
253weston_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
264static void
265weston_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
273static 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
283static void
284weston_desktop_xdg_surface_schedule_configure(struct weston_desktop_xdg_surface *surface);
285
286static void
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200287weston_desktop_xdg_toplevel_ensure_added(struct weston_desktop_xdg_toplevel *toplevel)
288{
289 if (toplevel->added)
290 return;
291
292 weston_desktop_api_surface_added(toplevel->base.desktop,
293 toplevel->base.desktop_surface);
294 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
295 toplevel->added = true;
296}
297
298static void
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200299weston_desktop_xdg_toplevel_protocol_set_parent(struct wl_client *wl_client,
300 struct wl_resource *resource,
301 struct wl_resource *parent_resource)
302{
303 struct weston_desktop_surface *dsurface =
304 wl_resource_get_user_data(resource);
305 struct weston_desktop_xdg_toplevel *toplevel =
306 weston_desktop_surface_get_implementation_data(dsurface);
307 struct weston_desktop_surface *parent = NULL;
308
309 if (parent_resource != NULL)
310 parent = wl_resource_get_user_data(parent_resource);
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200311
312 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200313 weston_desktop_api_set_parent(toplevel->base.desktop, dsurface, parent);
314}
315
316static void
317weston_desktop_xdg_toplevel_protocol_set_title(struct wl_client *wl_client,
318 struct wl_resource *resource,
319 const char *title)
320{
321 struct weston_desktop_surface *toplevel =
322 wl_resource_get_user_data(resource);
323
324 weston_desktop_surface_set_title(toplevel, title);
325}
326
327static void
328weston_desktop_xdg_toplevel_protocol_set_app_id(struct wl_client *wl_client,
329 struct wl_resource *resource,
330 const char *app_id)
331{
332 struct weston_desktop_surface *toplevel =
333 wl_resource_get_user_data(resource);
334
335 weston_desktop_surface_set_app_id(toplevel, app_id);
336}
337
338static void
339weston_desktop_xdg_toplevel_protocol_show_window_menu(struct wl_client *wl_client,
340 struct wl_resource *resource,
341 struct wl_resource *seat_resource,
342 uint32_t serial,
343 int32_t x, int32_t y)
344{
345 struct weston_desktop_surface *dsurface =
346 wl_resource_get_user_data(resource);
347 struct weston_seat *seat =
348 wl_resource_get_user_data(seat_resource);
349 struct weston_desktop_xdg_toplevel *toplevel =
350 weston_desktop_surface_get_implementation_data(dsurface);
351
Quentin Glidic0abf8902016-09-11 11:34:47 +0200352 if (!toplevel->base.configured) {
353 wl_resource_post_error(toplevel->resource,
354 ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
355 "Surface has not been configured yet");
356 return;
357 }
358
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200359 weston_desktop_api_show_window_menu(toplevel->base.desktop,
360 dsurface, seat, x, y);
361}
362
363static void
364weston_desktop_xdg_toplevel_protocol_move(struct wl_client *wl_client,
365 struct wl_resource *resource,
366 struct wl_resource *seat_resource,
367 uint32_t serial)
368{
369 struct weston_desktop_surface *dsurface =
370 wl_resource_get_user_data(resource);
371 struct weston_seat *seat =
372 wl_resource_get_user_data(seat_resource);
373 struct weston_desktop_xdg_toplevel *toplevel =
374 weston_desktop_surface_get_implementation_data(dsurface);
375
Quentin Glidic0abf8902016-09-11 11:34:47 +0200376 if (!toplevel->base.configured) {
377 wl_resource_post_error(toplevel->resource,
378 ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
379 "Surface has not been configured yet");
380 return;
381 }
382
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200383 weston_desktop_api_move(toplevel->base.desktop, dsurface, seat, serial);
384}
385
386static void
387weston_desktop_xdg_toplevel_protocol_resize(struct wl_client *wl_client,
388 struct wl_resource *resource,
389 struct wl_resource *seat_resource,
390 uint32_t serial,
391 enum zxdg_toplevel_v6_resize_edge edges)
392{
393 struct weston_desktop_surface *dsurface =
394 wl_resource_get_user_data(resource);
395 struct weston_seat *seat =
396 wl_resource_get_user_data(seat_resource);
397 struct weston_desktop_xdg_toplevel *toplevel =
398 weston_desktop_surface_get_implementation_data(dsurface);
399
Quentin Glidic0abf8902016-09-11 11:34:47 +0200400 if (!toplevel->base.configured) {
401 wl_resource_post_error(toplevel->resource,
402 ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
403 "Surface has not been configured yet");
404 return;
405 }
406
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200407 weston_desktop_api_resize(toplevel->base.desktop,
408 dsurface, seat, serial, edges);
409}
410
411static void
412weston_desktop_xdg_toplevel_ack_configure(struct weston_desktop_xdg_toplevel *toplevel)
413{
414 toplevel->next_state = toplevel->requested_state;
415}
416
417static void
418weston_desktop_xdg_toplevel_protocol_set_min_size(struct wl_client *wl_client,
419 struct wl_resource *resource,
420 int32_t width, int32_t height)
421{
422 struct weston_desktop_surface *dsurface =
423 wl_resource_get_user_data(resource);
424 struct weston_desktop_xdg_toplevel *toplevel =
425 weston_desktop_surface_get_implementation_data(dsurface);
426
427 toplevel->next_min_size.width = width;
428 toplevel->next_min_size.height = height;
429}
430
431static void
432weston_desktop_xdg_toplevel_protocol_set_max_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
441 toplevel->next_max_size.width = width;
442 toplevel->next_max_size.height = height;
443}
444
445static void
446weston_desktop_xdg_toplevel_protocol_set_maximized(struct wl_client *wl_client,
447 struct wl_resource *resource)
448{
449 struct weston_desktop_surface *dsurface =
450 wl_resource_get_user_data(resource);
451 struct weston_desktop_xdg_toplevel *toplevel =
452 weston_desktop_surface_get_implementation_data(dsurface);
453
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200454 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200455 weston_desktop_api_maximized_requested(toplevel->base.desktop, dsurface, true);
456}
457
458static void
459weston_desktop_xdg_toplevel_protocol_unset_maximized(struct wl_client *wl_client,
460 struct wl_resource *resource)
461{
462 struct weston_desktop_surface *dsurface =
463 wl_resource_get_user_data(resource);
464 struct weston_desktop_xdg_toplevel *toplevel =
465 weston_desktop_surface_get_implementation_data(dsurface);
466
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200467 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200468 weston_desktop_api_maximized_requested(toplevel->base.desktop, dsurface, false);
469}
470
471static void
472weston_desktop_xdg_toplevel_protocol_set_fullscreen(struct wl_client *wl_client,
473 struct wl_resource *resource,
474 struct wl_resource *output_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 struct weston_output *output = NULL;
481
482 if (output_resource != NULL)
483 output = wl_resource_get_user_data(output_resource);
484
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200485 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200486 weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface,
487 true, output);
488}
489
490static void
491weston_desktop_xdg_toplevel_protocol_unset_fullscreen(struct wl_client *wl_client,
492 struct wl_resource *resource)
493{
494 struct weston_desktop_surface *dsurface =
495 wl_resource_get_user_data(resource);
496 struct weston_desktop_xdg_toplevel *toplevel =
497 weston_desktop_surface_get_implementation_data(dsurface);
498
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200499 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200500 weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface,
501 false, NULL);
502}
503
504static void
505weston_desktop_xdg_toplevel_protocol_set_minimized(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 Glidic3d7e6072016-09-11 11:29:23 +0200513 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200514 weston_desktop_api_minimized_requested(toplevel->base.desktop, dsurface);
515}
516
517static void
518weston_desktop_xdg_toplevel_send_configure(struct weston_desktop_xdg_toplevel *toplevel)
519{
520 uint32_t *s;
521 struct wl_array states;
522
523 wl_array_init(&states);
524 if (toplevel->requested_state.maximized) {
525 s = wl_array_add(&states, sizeof(uint32_t));
526 *s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED;
527 }
528 if (toplevel->requested_state.fullscreen) {
529 s = wl_array_add(&states, sizeof(uint32_t));
530 *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN;
531 }
532 if (toplevel->requested_state.resizing) {
533 s = wl_array_add(&states, sizeof(uint32_t));
534 *s = ZXDG_TOPLEVEL_V6_STATE_RESIZING;
535 }
536 if (toplevel->requested_state.activated) {
537 s = wl_array_add(&states, sizeof(uint32_t));
538 *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED;
539 }
540
541 zxdg_toplevel_v6_send_configure(toplevel->resource,
542 toplevel->requested_size.width,
543 toplevel->requested_size.height,
544 &states);
545
546 wl_array_release(&states);
547};
548
549static void
550weston_desktop_xdg_toplevel_set_maximized(struct weston_desktop_surface *dsurface,
551 void *user_data, bool maximized)
552{
553 struct weston_desktop_xdg_toplevel *toplevel = user_data;
554
555 if (toplevel->state.maximized == maximized)
556 return;
557
558 toplevel->requested_state.maximized = maximized;
559 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
560}
561
562static void
563weston_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
568 if (toplevel->state.fullscreen == fullscreen)
569 return;
570
571 toplevel->requested_state.fullscreen = fullscreen;
572 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
573}
574
575static void
576weston_desktop_xdg_toplevel_set_resizing(struct weston_desktop_surface *dsurface,
577 void *user_data, bool resizing)
578{
579 struct weston_desktop_xdg_toplevel *toplevel = user_data;
580
581 if (toplevel->state.resizing == resizing)
582 return;
583
584 toplevel->requested_state.resizing = resizing;
585 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
586}
587
588static void
589weston_desktop_xdg_toplevel_set_activated(struct weston_desktop_surface *dsurface,
590 void *user_data, bool activated)
591{
592 struct weston_desktop_xdg_toplevel *toplevel = user_data;
593
594 if (toplevel->state.activated == activated)
595 return;
596
597 toplevel->requested_state.activated = activated;
598 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
599}
600
601static void
602weston_desktop_xdg_toplevel_set_size(struct weston_desktop_surface *dsurface,
603 void *user_data,
604 int32_t width, int32_t height)
605{
606 struct weston_desktop_xdg_toplevel *toplevel = user_data;
607 struct weston_surface *wsurface =
608 weston_desktop_surface_get_surface(toplevel->base.desktop_surface);
609
610 if (wsurface->width == width && wsurface->height == height)
611 return;
612
613 toplevel->requested_size.width = width;
614 toplevel->requested_size.height = height;
615 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
616}
617
618static void
619weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplevel,
Quentin Glidiccba26e72016-08-15 12:20:22 +0200620 int32_t sx, int32_t sy)
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200621{
622 struct weston_surface *wsurface =
623 weston_desktop_surface_get_surface(toplevel->base.desktop_surface);
624 bool reconfigure = false;
625
Quentin Glidiccba26e72016-08-15 12:20:22 +0200626 if (!wsurface->buffer_ref.buffer && !toplevel->added) {
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200627 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200628 return;
629 }
Quentin Glidiccba26e72016-08-15 12:20:22 +0200630 if (!wsurface->buffer_ref.buffer)
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200631 return;
632
633 if (toplevel->next_state.maximized || toplevel->next_state.fullscreen)
634 reconfigure =
635 ( ( toplevel->requested_size.width != wsurface->width ) ||
636 ( toplevel->requested_size.height != wsurface->height ) );
637
638 if (reconfigure) {
639 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
640 } else {
641 toplevel->state = toplevel->next_state;
642 toplevel->min_size = toplevel->next_min_size;
643 toplevel->max_size = toplevel->next_max_size;
644
645 weston_desktop_api_committed(toplevel->base.desktop,
646 toplevel->base.desktop_surface,
647 sx, sy);
648 }
649}
650
651static void
652weston_desktop_xdg_toplevel_close(struct weston_desktop_xdg_toplevel *toplevel)
653{
654 zxdg_toplevel_v6_send_close(toplevel->resource);
655}
656
657static bool
658weston_desktop_xdg_toplevel_get_maximized(struct weston_desktop_surface *dsurface,
659 void *user_data)
660{
661 struct weston_desktop_xdg_toplevel *toplevel = user_data;
662
663 return toplevel->state.maximized;
664}
665
666static bool
667weston_desktop_xdg_toplevel_get_fullscreen(struct weston_desktop_surface *dsurface,
668 void *user_data)
669{
670 struct weston_desktop_xdg_toplevel *toplevel = user_data;
671
672 return toplevel->state.fullscreen;
673}
674
675static bool
676weston_desktop_xdg_toplevel_get_resizing(struct weston_desktop_surface *dsurface,
677 void *user_data)
678{
679 struct weston_desktop_xdg_toplevel *toplevel = user_data;
680
681 return toplevel->state.resizing;
682}
683
684static bool
685weston_desktop_xdg_toplevel_get_activated(struct weston_desktop_surface *dsurface,
686 void *user_data)
687{
688 struct weston_desktop_xdg_toplevel *toplevel = user_data;
689
690 return toplevel->state.activated;
691}
692
693static void
694weston_desktop_xdg_toplevel_destroy(struct weston_desktop_xdg_toplevel *toplevel)
695{
696 if (toplevel->added)
697 weston_desktop_api_surface_removed(toplevel->base.desktop,
698 toplevel->base.desktop_surface);
699}
700
701static void
702weston_desktop_xdg_toplevel_resource_destroy(struct wl_resource *resource)
703{
704 struct weston_desktop_surface *dsurface =
705 wl_resource_get_user_data(resource);
706
707 if (dsurface != NULL)
708 weston_desktop_surface_resource_destroy(resource);
709}
710
711static const struct zxdg_toplevel_v6_interface weston_desktop_xdg_toplevel_implementation = {
712 .destroy = weston_desktop_destroy_request,
713 .set_parent = weston_desktop_xdg_toplevel_protocol_set_parent,
714 .set_title = weston_desktop_xdg_toplevel_protocol_set_title,
715 .set_app_id = weston_desktop_xdg_toplevel_protocol_set_app_id,
716 .show_window_menu = weston_desktop_xdg_toplevel_protocol_show_window_menu,
717 .move = weston_desktop_xdg_toplevel_protocol_move,
718 .resize = weston_desktop_xdg_toplevel_protocol_resize,
719 .set_min_size = weston_desktop_xdg_toplevel_protocol_set_min_size,
720 .set_max_size = weston_desktop_xdg_toplevel_protocol_set_max_size,
721 .set_maximized = weston_desktop_xdg_toplevel_protocol_set_maximized,
722 .unset_maximized = weston_desktop_xdg_toplevel_protocol_unset_maximized,
723 .set_fullscreen = weston_desktop_xdg_toplevel_protocol_set_fullscreen,
724 .unset_fullscreen = weston_desktop_xdg_toplevel_protocol_unset_fullscreen,
725 .set_minimized = weston_desktop_xdg_toplevel_protocol_set_minimized,
726};
727
728static void
729weston_desktop_xdg_popup_protocol_grab(struct wl_client *wl_client,
730 struct wl_resource *resource,
731 struct wl_resource *seat_resource,
732 uint32_t serial)
733{
734 struct weston_desktop_surface *dsurface =
735 wl_resource_get_user_data(resource);
736 struct weston_desktop_xdg_popup *popup =
737 weston_desktop_surface_get_implementation_data(dsurface);
738 struct weston_seat *wseat = wl_resource_get_user_data(seat_resource);
739 struct weston_desktop_seat *seat = weston_desktop_seat_from_seat(wseat);
740 struct weston_desktop_surface *topmost;
741 bool parent_is_toplevel =
742 popup->parent->role == WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL;
743
744 if (popup->committed) {
745 wl_resource_post_error(popup->resource,
746 ZXDG_POPUP_V6_ERROR_INVALID_GRAB,
747 "xdg_popup already is mapped");
748 return;
749 }
750
751 topmost = weston_desktop_seat_popup_grab_get_topmost_surface(seat);
752 if ((topmost == NULL && !parent_is_toplevel) ||
753 (topmost != NULL && topmost != popup->parent->desktop_surface)) {
754 struct weston_desktop_client *client =
755 weston_desktop_surface_get_client(dsurface);
756 struct wl_resource *client_resource =
757 weston_desktop_client_get_resource(client);
758
759 wl_resource_post_error(client_resource,
760 ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP,
761 "xdg_popup was not created on the topmost popup");
762 return;
763 }
764
765 popup->seat = seat;
766 weston_desktop_surface_popup_grab(popup->base.desktop_surface,
767 popup->seat, serial);
768}
769
770static void
771weston_desktop_xdg_popup_send_configure(struct weston_desktop_xdg_popup *popup)
772{
773 zxdg_popup_v6_send_configure(popup->resource,
774 popup->geometry.x,
775 popup->geometry.y,
776 popup->geometry.width,
777 popup->geometry.height);
778}
779
780static void
781weston_desktop_xdg_popup_update_position(struct weston_desktop_surface *dsurface,
782 void *user_data);
783
784static void
785weston_desktop_xdg_popup_committed(struct weston_desktop_xdg_popup *popup)
786{
787 if (!popup->committed)
788 weston_desktop_xdg_surface_schedule_configure(&popup->base);
789 popup->committed = true;
790 weston_desktop_xdg_popup_update_position(popup->base.desktop_surface,
791 popup);
792}
793
794static void
795weston_desktop_xdg_popup_update_position(struct weston_desktop_surface *dsurface,
796 void *user_data)
797{
798}
799
800static void
801weston_desktop_xdg_popup_close(struct weston_desktop_xdg_popup *popup)
802{
803 zxdg_popup_v6_send_popup_done(popup->resource);
804}
805
806static void
807weston_desktop_xdg_popup_destroy(struct weston_desktop_xdg_popup *popup)
808{
809 struct weston_desktop_surface *topmost;
810 struct weston_desktop_client *client =
811 weston_desktop_surface_get_client(popup->base.desktop_surface);
812
813 if (!weston_desktop_surface_get_grab(popup->base.desktop_surface))
814 return;
815
816 topmost = weston_desktop_seat_popup_grab_get_topmost_surface(popup->seat);
817 if (topmost != popup->base.desktop_surface) {
818 struct wl_resource *client_resource =
819 weston_desktop_client_get_resource(client);
820
821 wl_resource_post_error(client_resource,
822 ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP,
823 "xdg_popup was destroyed while it was not the topmost popup.");
824 }
825
826 weston_desktop_surface_popup_ungrab(popup->base.desktop_surface,
827 popup->seat);
828}
829
830static void
831weston_desktop_xdg_popup_resource_destroy(struct wl_resource *resource)
832{
833 struct weston_desktop_surface *dsurface =
834 wl_resource_get_user_data(resource);
835
836 if (dsurface != NULL)
837 weston_desktop_surface_resource_destroy(resource);
838}
839
840static const struct zxdg_popup_v6_interface weston_desktop_xdg_popup_implementation = {
841 .destroy = weston_desktop_destroy_request,
842 .grab = weston_desktop_xdg_popup_protocol_grab,
843};
844
845static void
846weston_desktop_xdg_surface_send_configure(void *user_data)
847{
848 struct weston_desktop_xdg_surface *surface = user_data;
849
850 surface->configure_idle = NULL;
851 surface->configure_serial =
852 wl_display_next_serial(weston_desktop_get_display(surface->desktop));
853
854 switch (surface->role) {
855 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
856 assert(0 && "not reached");
857 break;
858 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
859 weston_desktop_xdg_toplevel_send_configure((struct weston_desktop_xdg_toplevel *) surface);
860 break;
861 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
862 weston_desktop_xdg_popup_send_configure((struct weston_desktop_xdg_popup *) surface);
863 break;
864 }
865
866 zxdg_surface_v6_send_configure(surface->resource, surface->configure_serial);
867}
868
869static void
870weston_desktop_xdg_surface_schedule_configure(struct weston_desktop_xdg_surface *surface)
871{
872 struct wl_display *display = weston_desktop_get_display(surface->desktop);
873 struct wl_event_loop *loop = wl_display_get_event_loop(display);
874
875 if (surface->configure_idle != NULL)
876 return;
877 surface->configure_idle =
878 wl_event_loop_add_idle(loop,
879 weston_desktop_xdg_surface_send_configure,
880 surface);
881}
882
883static void
884weston_desktop_xdg_surface_protocol_get_toplevel(struct wl_client *wl_client,
885 struct wl_resource *resource,
886 uint32_t id)
887{
888 struct weston_desktop_surface *dsurface =
889 wl_resource_get_user_data(resource);
890 struct weston_surface *wsurface =
891 weston_desktop_surface_get_surface(dsurface);
892 struct weston_desktop_xdg_toplevel *toplevel =
893 weston_desktop_surface_get_implementation_data(dsurface);
894
895 if (weston_surface_set_role(wsurface, weston_desktop_xdg_toplevel_role,
896 resource, ZXDG_SHELL_V6_ERROR_ROLE) < 0)
897 return;
898
899 toplevel->resource =
900 weston_desktop_surface_add_resource(toplevel->base.desktop_surface,
901 &zxdg_toplevel_v6_interface,
902 &weston_desktop_xdg_toplevel_implementation,
903 id, weston_desktop_xdg_toplevel_resource_destroy);
904 if (toplevel->resource == NULL)
905 return;
906
907 toplevel->base.role = WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL;
908}
909
910static void
911weston_desktop_xdg_surface_protocol_get_popup(struct wl_client *wl_client,
912 struct wl_resource *resource,
913 uint32_t id,
914 struct wl_resource *parent_resource,
915 struct wl_resource *positioner_resource)
916{
917 struct weston_desktop_surface *dsurface =
918 wl_resource_get_user_data(resource);
919 struct weston_surface *wsurface =
920 weston_desktop_surface_get_surface(dsurface);
921 struct weston_desktop_xdg_popup *popup =
922 weston_desktop_surface_get_implementation_data(dsurface);
923 struct weston_desktop_surface *parent_surface =
924 wl_resource_get_user_data(parent_resource);
925 struct weston_desktop_xdg_surface *parent =
926 weston_desktop_surface_get_implementation_data(parent_surface);
927 struct weston_desktop_xdg_positioner *positioner =
928 wl_resource_get_user_data(positioner_resource);
929
930 if (weston_surface_set_role(wsurface, weston_desktop_xdg_popup_role,
931 resource, ZXDG_SHELL_V6_ERROR_ROLE) < 0)
932 return;
933
934 popup->resource =
935 weston_desktop_surface_add_resource(popup->base.desktop_surface,
936 &zxdg_popup_v6_interface,
937 &weston_desktop_xdg_popup_implementation,
938 id, weston_desktop_xdg_popup_resource_destroy);
939 if (popup->resource == NULL)
940 return;
941
942 popup->base.role = WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP;
943 popup->parent = parent;
944
945 popup->geometry =
946 weston_desktop_xdg_positioner_get_geometry(positioner,
947 dsurface,
948 parent_surface);
949
950 weston_desktop_surface_set_relative_to(popup->base.desktop_surface,
951 parent_surface,
952 popup->geometry.x,
953 popup->geometry.y,
954 true);
955}
956
957static bool
958weston_desktop_xdg_surface_check_role(struct weston_desktop_xdg_surface *surface)
959{
960 struct weston_surface *wsurface =
961 weston_desktop_surface_get_surface(surface->desktop_surface);
962 const char *role;
963
964 role = weston_surface_get_role(wsurface);
965 if (role != NULL &&
966 (role == weston_desktop_xdg_toplevel_role ||
967 role == weston_desktop_xdg_popup_role))
968 return true;
969
970 wl_resource_post_error(surface->resource,
971 ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
972 "xdg_surface must have a role");
973 return false;
974}
975
976static void
977weston_desktop_xdg_surface_protocol_set_window_geometry(struct wl_client *wl_client,
978 struct wl_resource *resource,
979 int32_t x, int32_t y,
980 int32_t width, int32_t height)
981{
982 struct weston_desktop_surface *dsurface =
983 wl_resource_get_user_data(resource);
984 struct weston_desktop_xdg_surface *surface =
985 weston_desktop_surface_get_implementation_data(dsurface);
986
987 if (!weston_desktop_xdg_surface_check_role(surface))
988 return;
989
990 surface->has_next_geometry = true;
991 surface->next_geometry.x = x;
992 surface->next_geometry.y = y;
993 surface->next_geometry.width = width;
994 surface->next_geometry.height = height;
995}
996
997static void
998weston_desktop_xdg_surface_protocol_ack_configure(struct wl_client *wl_client,
999 struct wl_resource *resource,
1000 uint32_t serial)
1001{
1002 struct weston_desktop_surface *dsurface =
1003 wl_resource_get_user_data(resource);
1004 struct weston_desktop_xdg_surface *surface =
1005 weston_desktop_surface_get_implementation_data(dsurface);
1006
1007 if (!weston_desktop_xdg_surface_check_role(surface))
1008 return;
1009
1010 if (surface->configure_serial != serial)
1011 return;
1012
1013 surface->configured = true;
1014
1015 switch (surface->role) {
1016 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
1017 assert(0 && "not reached");
1018 break;
1019 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
1020 weston_desktop_xdg_toplevel_ack_configure((struct weston_desktop_xdg_toplevel *) surface);
1021 break;
1022 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
1023 break;
1024 }
1025}
1026
1027static void
1028weston_desktop_xdg_surface_ping(struct weston_desktop_surface *dsurface,
1029 uint32_t serial, void *user_data)
1030{
1031 struct weston_desktop_client *client =
1032 weston_desktop_surface_get_client(dsurface);
1033
1034 zxdg_shell_v6_send_ping(weston_desktop_client_get_resource(client),
1035 serial);
1036}
1037
1038static void
1039weston_desktop_xdg_surface_committed(struct weston_desktop_surface *dsurface,
Quentin Glidic003da882016-08-15 12:21:39 +02001040 void *user_data,
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +02001041 int32_t sx, int32_t sy)
1042{
1043 struct weston_desktop_xdg_surface *surface = user_data;
Quentin Glidiccba26e72016-08-15 12:20:22 +02001044 struct weston_surface *wsurface =
1045 weston_desktop_surface_get_surface (dsurface);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +02001046
Quentin Glidiccba26e72016-08-15 12:20:22 +02001047 if (wsurface->buffer_ref.buffer && !surface->configured) {
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +02001048 wl_resource_post_error(surface->resource,
1049 ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
1050 "xdg_surface has never been configured");
1051 return;
1052 }
1053
1054 if (surface->has_next_geometry) {
1055 surface->has_next_geometry = false;
1056 weston_desktop_surface_set_geometry(surface->desktop_surface,
1057 surface->next_geometry);
1058 }
1059
1060 switch (surface->role) {
1061 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
1062 wl_resource_post_error(surface->resource,
1063 ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
1064 "xdg_surface must have a role");
1065 break;
1066 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
Quentin Glidiccba26e72016-08-15 12:20:22 +02001067 weston_desktop_xdg_toplevel_committed((struct weston_desktop_xdg_toplevel *) surface, sx, sy);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +02001068 break;
1069 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
1070 weston_desktop_xdg_popup_committed((struct weston_desktop_xdg_popup *) surface);
1071 break;
1072 }
1073}
1074
1075static void
1076weston_desktop_xdg_surface_close(struct weston_desktop_surface *dsurface,
1077 void *user_data)
1078{
1079 struct weston_desktop_xdg_surface *surface = user_data;
1080
1081 switch (surface->role) {
1082 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
1083 assert(0 && "not reached");
1084 break;
1085 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
1086 weston_desktop_xdg_toplevel_close((struct weston_desktop_xdg_toplevel *) surface);
1087 break;
1088 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
1089 weston_desktop_xdg_popup_close((struct weston_desktop_xdg_popup *) surface);
1090 break;
1091 }
1092}
1093
1094static void
1095weston_desktop_xdg_surface_destroy(struct weston_desktop_surface *dsurface,
1096 void *user_data)
1097{
1098 struct weston_desktop_xdg_surface *surface = user_data;
1099
1100 switch (surface->role) {
1101 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
1102 break;
1103 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
1104 weston_desktop_xdg_toplevel_destroy((struct weston_desktop_xdg_toplevel *) surface);
1105 break;
1106 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
1107 weston_desktop_xdg_popup_destroy((struct weston_desktop_xdg_popup *) surface);
1108 break;
1109 }
1110
1111 if (surface->configure_idle != NULL)
1112 wl_event_source_remove(surface->configure_idle);
1113
1114 free(surface);
1115}
1116
1117static const struct zxdg_surface_v6_interface weston_desktop_xdg_surface_implementation = {
1118 .destroy = weston_desktop_destroy_request,
1119 .get_toplevel = weston_desktop_xdg_surface_protocol_get_toplevel,
1120 .get_popup = weston_desktop_xdg_surface_protocol_get_popup,
1121 .set_window_geometry = weston_desktop_xdg_surface_protocol_set_window_geometry,
1122 .ack_configure = weston_desktop_xdg_surface_protocol_ack_configure,
1123};
1124
1125static const struct weston_desktop_surface_implementation weston_desktop_xdg_surface_internal_implementation = {
1126 /* These are used for toplevel only */
1127 .set_maximized = weston_desktop_xdg_toplevel_set_maximized,
1128 .set_fullscreen = weston_desktop_xdg_toplevel_set_fullscreen,
1129 .set_resizing = weston_desktop_xdg_toplevel_set_resizing,
1130 .set_activated = weston_desktop_xdg_toplevel_set_activated,
1131 .set_size = weston_desktop_xdg_toplevel_set_size,
1132
1133 .get_maximized = weston_desktop_xdg_toplevel_get_maximized,
1134 .get_fullscreen = weston_desktop_xdg_toplevel_get_fullscreen,
1135 .get_resizing = weston_desktop_xdg_toplevel_get_resizing,
1136 .get_activated = weston_desktop_xdg_toplevel_get_activated,
1137
1138 /* These are used for popup only */
1139 .update_position = weston_desktop_xdg_popup_update_position,
1140
1141 /* Common API */
1142 .committed = weston_desktop_xdg_surface_committed,
1143 .ping = weston_desktop_xdg_surface_ping,
1144 .close = weston_desktop_xdg_surface_close,
1145
1146 .destroy = weston_desktop_xdg_surface_destroy,
1147};
1148
1149static void
1150weston_desktop_xdg_shell_protocol_create_positioner(struct wl_client *wl_client,
1151 struct wl_resource *resource,
1152 uint32_t id)
1153{
1154 struct weston_desktop_client *client =
1155 wl_resource_get_user_data(resource);
1156 struct weston_desktop_xdg_positioner *positioner;
1157
1158 positioner = zalloc(sizeof(struct weston_desktop_xdg_positioner));
1159 if (positioner == NULL) {
1160 wl_client_post_no_memory(wl_client);
1161 return;
1162 }
1163
1164 positioner->client = client;
1165 positioner->desktop = weston_desktop_client_get_desktop(positioner->client);
1166
1167 positioner->resource =
1168 wl_resource_create(wl_client,
1169 &zxdg_positioner_v6_interface,
1170 wl_resource_get_version(resource), id);
1171 if (positioner->resource == NULL) {
1172 wl_client_post_no_memory(wl_client);
1173 free(positioner);
1174 return;
1175 }
1176 wl_resource_set_implementation(positioner->resource,
1177 &weston_desktop_xdg_positioner_implementation,
1178 positioner, weston_desktop_xdg_positioner_destroy);
1179}
1180
1181static void
1182weston_desktop_xdg_surface_resource_destroy(struct wl_resource *resource)
1183{
1184 struct weston_desktop_surface *dsurface =
1185 wl_resource_get_user_data(resource);
1186
1187 if (dsurface != NULL)
1188 weston_desktop_surface_resource_destroy(resource);
1189}
1190
1191static void
1192weston_desktop_xdg_shell_protocol_get_xdg_surface(struct wl_client *wl_client,
1193 struct wl_resource *resource,
1194 uint32_t id,
1195 struct wl_resource *surface_resource)
1196{
1197 struct weston_desktop_client *client =
1198 wl_resource_get_user_data(resource);
1199 struct weston_surface *wsurface =
1200 wl_resource_get_user_data(surface_resource);
1201 struct weston_desktop_xdg_surface *surface;
1202
1203 surface = zalloc(weston_desktop_surface_role_biggest_size);
1204 if (surface == NULL) {
1205 wl_client_post_no_memory(wl_client);
1206 return;
1207 }
1208
1209 surface->desktop = weston_desktop_client_get_desktop(client);
1210 surface->surface = wsurface;
1211
1212 surface->desktop_surface =
1213 weston_desktop_surface_create(surface->desktop, client,
1214 surface->surface,
1215 &weston_desktop_xdg_surface_internal_implementation,
1216 surface);
1217 if (surface->desktop_surface == NULL) {
1218 free(surface);
1219 return;
1220 }
1221
1222 surface->resource =
1223 weston_desktop_surface_add_resource(surface->desktop_surface,
1224 &zxdg_surface_v6_interface,
1225 &weston_desktop_xdg_surface_implementation,
1226 id, weston_desktop_xdg_surface_resource_destroy);
1227 if (surface->resource == NULL)
1228 return;
1229
1230 if (wsurface->buffer_ref.buffer != NULL) {
1231 wl_resource_post_error(surface->resource,
1232 ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
1233 "xdg_surface must not have a buffer at creation");
1234 return;
1235 }
1236}
1237
1238static void
1239weston_desktop_xdg_shell_protocol_pong(struct wl_client *wl_client,
1240 struct wl_resource *resource,
1241 uint32_t serial)
1242{
1243 struct weston_desktop_client *client =
1244 wl_resource_get_user_data(resource);
1245
1246 weston_desktop_client_pong(client, serial);
1247}
1248
1249static const struct zxdg_shell_v6_interface weston_desktop_xdg_shell_implementation = {
1250 .destroy = weston_desktop_destroy_request,
1251 .create_positioner = weston_desktop_xdg_shell_protocol_create_positioner,
1252 .get_xdg_surface = weston_desktop_xdg_shell_protocol_get_xdg_surface,
1253 .pong = weston_desktop_xdg_shell_protocol_pong,
1254};
1255
1256static void
1257weston_desktop_xdg_shell_bind(struct wl_client *client, void *data,
1258 uint32_t version, uint32_t id)
1259{
1260 struct weston_desktop *desktop = data;
1261
1262 weston_desktop_client_create(desktop, client, NULL,
1263 &zxdg_shell_v6_interface,
1264 &weston_desktop_xdg_shell_implementation,
1265 version, id);
1266}
1267
1268struct wl_global *
1269weston_desktop_xdg_shell_v6_create(struct weston_desktop *desktop, struct wl_display *display)
1270{
1271 return wl_global_create(display, &zxdg_shell_v6_interface,
1272 WD_XDG_SHELL_PROTOCOL_VERSION, desktop,
1273 weston_desktop_xdg_shell_bind);
1274}