blob: fbf3e69eb7a8a4189b255455458f7c558a0c80f9 [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
352 weston_desktop_api_show_window_menu(toplevel->base.desktop,
353 dsurface, seat, x, y);
354}
355
356static void
357weston_desktop_xdg_toplevel_protocol_move(struct wl_client *wl_client,
358 struct wl_resource *resource,
359 struct wl_resource *seat_resource,
360 uint32_t serial)
361{
362 struct weston_desktop_surface *dsurface =
363 wl_resource_get_user_data(resource);
364 struct weston_seat *seat =
365 wl_resource_get_user_data(seat_resource);
366 struct weston_desktop_xdg_toplevel *toplevel =
367 weston_desktop_surface_get_implementation_data(dsurface);
368
369 weston_desktop_api_move(toplevel->base.desktop, dsurface, seat, serial);
370}
371
372static void
373weston_desktop_xdg_toplevel_protocol_resize(struct wl_client *wl_client,
374 struct wl_resource *resource,
375 struct wl_resource *seat_resource,
376 uint32_t serial,
377 enum zxdg_toplevel_v6_resize_edge edges)
378{
379 struct weston_desktop_surface *dsurface =
380 wl_resource_get_user_data(resource);
381 struct weston_seat *seat =
382 wl_resource_get_user_data(seat_resource);
383 struct weston_desktop_xdg_toplevel *toplevel =
384 weston_desktop_surface_get_implementation_data(dsurface);
385
386 weston_desktop_api_resize(toplevel->base.desktop,
387 dsurface, seat, serial, edges);
388}
389
390static void
391weston_desktop_xdg_toplevel_ack_configure(struct weston_desktop_xdg_toplevel *toplevel)
392{
393 toplevel->next_state = toplevel->requested_state;
394}
395
396static void
397weston_desktop_xdg_toplevel_protocol_set_min_size(struct wl_client *wl_client,
398 struct wl_resource *resource,
399 int32_t width, int32_t height)
400{
401 struct weston_desktop_surface *dsurface =
402 wl_resource_get_user_data(resource);
403 struct weston_desktop_xdg_toplevel *toplevel =
404 weston_desktop_surface_get_implementation_data(dsurface);
405
406 toplevel->next_min_size.width = width;
407 toplevel->next_min_size.height = height;
408}
409
410static void
411weston_desktop_xdg_toplevel_protocol_set_max_size(struct wl_client *wl_client,
412 struct wl_resource *resource,
413 int32_t width, int32_t height)
414{
415 struct weston_desktop_surface *dsurface =
416 wl_resource_get_user_data(resource);
417 struct weston_desktop_xdg_toplevel *toplevel =
418 weston_desktop_surface_get_implementation_data(dsurface);
419
420 toplevel->next_max_size.width = width;
421 toplevel->next_max_size.height = height;
422}
423
424static void
425weston_desktop_xdg_toplevel_protocol_set_maximized(struct wl_client *wl_client,
426 struct wl_resource *resource)
427{
428 struct weston_desktop_surface *dsurface =
429 wl_resource_get_user_data(resource);
430 struct weston_desktop_xdg_toplevel *toplevel =
431 weston_desktop_surface_get_implementation_data(dsurface);
432
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200433 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200434 weston_desktop_api_maximized_requested(toplevel->base.desktop, dsurface, true);
435}
436
437static void
438weston_desktop_xdg_toplevel_protocol_unset_maximized(struct wl_client *wl_client,
439 struct wl_resource *resource)
440{
441 struct weston_desktop_surface *dsurface =
442 wl_resource_get_user_data(resource);
443 struct weston_desktop_xdg_toplevel *toplevel =
444 weston_desktop_surface_get_implementation_data(dsurface);
445
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200446 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200447 weston_desktop_api_maximized_requested(toplevel->base.desktop, dsurface, false);
448}
449
450static void
451weston_desktop_xdg_toplevel_protocol_set_fullscreen(struct wl_client *wl_client,
452 struct wl_resource *resource,
453 struct wl_resource *output_resource)
454{
455 struct weston_desktop_surface *dsurface =
456 wl_resource_get_user_data(resource);
457 struct weston_desktop_xdg_toplevel *toplevel =
458 weston_desktop_surface_get_implementation_data(dsurface);
459 struct weston_output *output = NULL;
460
461 if (output_resource != NULL)
462 output = wl_resource_get_user_data(output_resource);
463
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200464 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200465 weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface,
466 true, output);
467}
468
469static void
470weston_desktop_xdg_toplevel_protocol_unset_fullscreen(struct wl_client *wl_client,
471 struct wl_resource *resource)
472{
473 struct weston_desktop_surface *dsurface =
474 wl_resource_get_user_data(resource);
475 struct weston_desktop_xdg_toplevel *toplevel =
476 weston_desktop_surface_get_implementation_data(dsurface);
477
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200478 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200479 weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface,
480 false, NULL);
481}
482
483static void
484weston_desktop_xdg_toplevel_protocol_set_minimized(struct wl_client *wl_client,
485 struct wl_resource *resource)
486{
487 struct weston_desktop_surface *dsurface =
488 wl_resource_get_user_data(resource);
489 struct weston_desktop_xdg_toplevel *toplevel =
490 weston_desktop_surface_get_implementation_data(dsurface);
491
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200492 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200493 weston_desktop_api_minimized_requested(toplevel->base.desktop, dsurface);
494}
495
496static void
497weston_desktop_xdg_toplevel_send_configure(struct weston_desktop_xdg_toplevel *toplevel)
498{
499 uint32_t *s;
500 struct wl_array states;
501
502 wl_array_init(&states);
503 if (toplevel->requested_state.maximized) {
504 s = wl_array_add(&states, sizeof(uint32_t));
505 *s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED;
506 }
507 if (toplevel->requested_state.fullscreen) {
508 s = wl_array_add(&states, sizeof(uint32_t));
509 *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN;
510 }
511 if (toplevel->requested_state.resizing) {
512 s = wl_array_add(&states, sizeof(uint32_t));
513 *s = ZXDG_TOPLEVEL_V6_STATE_RESIZING;
514 }
515 if (toplevel->requested_state.activated) {
516 s = wl_array_add(&states, sizeof(uint32_t));
517 *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED;
518 }
519
520 zxdg_toplevel_v6_send_configure(toplevel->resource,
521 toplevel->requested_size.width,
522 toplevel->requested_size.height,
523 &states);
524
525 wl_array_release(&states);
526};
527
528static void
529weston_desktop_xdg_toplevel_set_maximized(struct weston_desktop_surface *dsurface,
530 void *user_data, bool maximized)
531{
532 struct weston_desktop_xdg_toplevel *toplevel = user_data;
533
534 if (toplevel->state.maximized == maximized)
535 return;
536
537 toplevel->requested_state.maximized = maximized;
538 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
539}
540
541static void
542weston_desktop_xdg_toplevel_set_fullscreen(struct weston_desktop_surface *dsurface,
543 void *user_data, bool fullscreen)
544{
545 struct weston_desktop_xdg_toplevel *toplevel = user_data;
546
547 if (toplevel->state.fullscreen == fullscreen)
548 return;
549
550 toplevel->requested_state.fullscreen = fullscreen;
551 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
552}
553
554static void
555weston_desktop_xdg_toplevel_set_resizing(struct weston_desktop_surface *dsurface,
556 void *user_data, bool resizing)
557{
558 struct weston_desktop_xdg_toplevel *toplevel = user_data;
559
560 if (toplevel->state.resizing == resizing)
561 return;
562
563 toplevel->requested_state.resizing = resizing;
564 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
565}
566
567static void
568weston_desktop_xdg_toplevel_set_activated(struct weston_desktop_surface *dsurface,
569 void *user_data, bool activated)
570{
571 struct weston_desktop_xdg_toplevel *toplevel = user_data;
572
573 if (toplevel->state.activated == activated)
574 return;
575
576 toplevel->requested_state.activated = activated;
577 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
578}
579
580static void
581weston_desktop_xdg_toplevel_set_size(struct weston_desktop_surface *dsurface,
582 void *user_data,
583 int32_t width, int32_t height)
584{
585 struct weston_desktop_xdg_toplevel *toplevel = user_data;
586 struct weston_surface *wsurface =
587 weston_desktop_surface_get_surface(toplevel->base.desktop_surface);
588
589 if (wsurface->width == width && wsurface->height == height)
590 return;
591
592 toplevel->requested_size.width = width;
593 toplevel->requested_size.height = height;
594 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
595}
596
597static void
598weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplevel,
Quentin Glidiccba26e72016-08-15 12:20:22 +0200599 int32_t sx, int32_t sy)
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200600{
601 struct weston_surface *wsurface =
602 weston_desktop_surface_get_surface(toplevel->base.desktop_surface);
603 bool reconfigure = false;
604
Quentin Glidiccba26e72016-08-15 12:20:22 +0200605 if (!wsurface->buffer_ref.buffer && !toplevel->added) {
Quentin Glidic3d7e6072016-09-11 11:29:23 +0200606 weston_desktop_xdg_toplevel_ensure_added(toplevel);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200607 return;
608 }
Quentin Glidiccba26e72016-08-15 12:20:22 +0200609 if (!wsurface->buffer_ref.buffer)
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200610 return;
611
612 if (toplevel->next_state.maximized || toplevel->next_state.fullscreen)
613 reconfigure =
614 ( ( toplevel->requested_size.width != wsurface->width ) ||
615 ( toplevel->requested_size.height != wsurface->height ) );
616
617 if (reconfigure) {
618 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
619 } else {
620 toplevel->state = toplevel->next_state;
621 toplevel->min_size = toplevel->next_min_size;
622 toplevel->max_size = toplevel->next_max_size;
623
624 weston_desktop_api_committed(toplevel->base.desktop,
625 toplevel->base.desktop_surface,
626 sx, sy);
627 }
628}
629
630static void
631weston_desktop_xdg_toplevel_close(struct weston_desktop_xdg_toplevel *toplevel)
632{
633 zxdg_toplevel_v6_send_close(toplevel->resource);
634}
635
636static bool
637weston_desktop_xdg_toplevel_get_maximized(struct weston_desktop_surface *dsurface,
638 void *user_data)
639{
640 struct weston_desktop_xdg_toplevel *toplevel = user_data;
641
642 return toplevel->state.maximized;
643}
644
645static bool
646weston_desktop_xdg_toplevel_get_fullscreen(struct weston_desktop_surface *dsurface,
647 void *user_data)
648{
649 struct weston_desktop_xdg_toplevel *toplevel = user_data;
650
651 return toplevel->state.fullscreen;
652}
653
654static bool
655weston_desktop_xdg_toplevel_get_resizing(struct weston_desktop_surface *dsurface,
656 void *user_data)
657{
658 struct weston_desktop_xdg_toplevel *toplevel = user_data;
659
660 return toplevel->state.resizing;
661}
662
663static bool
664weston_desktop_xdg_toplevel_get_activated(struct weston_desktop_surface *dsurface,
665 void *user_data)
666{
667 struct weston_desktop_xdg_toplevel *toplevel = user_data;
668
669 return toplevel->state.activated;
670}
671
672static void
673weston_desktop_xdg_toplevel_destroy(struct weston_desktop_xdg_toplevel *toplevel)
674{
675 if (toplevel->added)
676 weston_desktop_api_surface_removed(toplevel->base.desktop,
677 toplevel->base.desktop_surface);
678}
679
680static void
681weston_desktop_xdg_toplevel_resource_destroy(struct wl_resource *resource)
682{
683 struct weston_desktop_surface *dsurface =
684 wl_resource_get_user_data(resource);
685
686 if (dsurface != NULL)
687 weston_desktop_surface_resource_destroy(resource);
688}
689
690static const struct zxdg_toplevel_v6_interface weston_desktop_xdg_toplevel_implementation = {
691 .destroy = weston_desktop_destroy_request,
692 .set_parent = weston_desktop_xdg_toplevel_protocol_set_parent,
693 .set_title = weston_desktop_xdg_toplevel_protocol_set_title,
694 .set_app_id = weston_desktop_xdg_toplevel_protocol_set_app_id,
695 .show_window_menu = weston_desktop_xdg_toplevel_protocol_show_window_menu,
696 .move = weston_desktop_xdg_toplevel_protocol_move,
697 .resize = weston_desktop_xdg_toplevel_protocol_resize,
698 .set_min_size = weston_desktop_xdg_toplevel_protocol_set_min_size,
699 .set_max_size = weston_desktop_xdg_toplevel_protocol_set_max_size,
700 .set_maximized = weston_desktop_xdg_toplevel_protocol_set_maximized,
701 .unset_maximized = weston_desktop_xdg_toplevel_protocol_unset_maximized,
702 .set_fullscreen = weston_desktop_xdg_toplevel_protocol_set_fullscreen,
703 .unset_fullscreen = weston_desktop_xdg_toplevel_protocol_unset_fullscreen,
704 .set_minimized = weston_desktop_xdg_toplevel_protocol_set_minimized,
705};
706
707static void
708weston_desktop_xdg_popup_protocol_grab(struct wl_client *wl_client,
709 struct wl_resource *resource,
710 struct wl_resource *seat_resource,
711 uint32_t serial)
712{
713 struct weston_desktop_surface *dsurface =
714 wl_resource_get_user_data(resource);
715 struct weston_desktop_xdg_popup *popup =
716 weston_desktop_surface_get_implementation_data(dsurface);
717 struct weston_seat *wseat = wl_resource_get_user_data(seat_resource);
718 struct weston_desktop_seat *seat = weston_desktop_seat_from_seat(wseat);
719 struct weston_desktop_surface *topmost;
720 bool parent_is_toplevel =
721 popup->parent->role == WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL;
722
723 if (popup->committed) {
724 wl_resource_post_error(popup->resource,
725 ZXDG_POPUP_V6_ERROR_INVALID_GRAB,
726 "xdg_popup already is mapped");
727 return;
728 }
729
730 topmost = weston_desktop_seat_popup_grab_get_topmost_surface(seat);
731 if ((topmost == NULL && !parent_is_toplevel) ||
732 (topmost != NULL && topmost != popup->parent->desktop_surface)) {
733 struct weston_desktop_client *client =
734 weston_desktop_surface_get_client(dsurface);
735 struct wl_resource *client_resource =
736 weston_desktop_client_get_resource(client);
737
738 wl_resource_post_error(client_resource,
739 ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP,
740 "xdg_popup was not created on the topmost popup");
741 return;
742 }
743
744 popup->seat = seat;
745 weston_desktop_surface_popup_grab(popup->base.desktop_surface,
746 popup->seat, serial);
747}
748
749static void
750weston_desktop_xdg_popup_send_configure(struct weston_desktop_xdg_popup *popup)
751{
752 zxdg_popup_v6_send_configure(popup->resource,
753 popup->geometry.x,
754 popup->geometry.y,
755 popup->geometry.width,
756 popup->geometry.height);
757}
758
759static void
760weston_desktop_xdg_popup_update_position(struct weston_desktop_surface *dsurface,
761 void *user_data);
762
763static void
764weston_desktop_xdg_popup_committed(struct weston_desktop_xdg_popup *popup)
765{
766 if (!popup->committed)
767 weston_desktop_xdg_surface_schedule_configure(&popup->base);
768 popup->committed = true;
769 weston_desktop_xdg_popup_update_position(popup->base.desktop_surface,
770 popup);
771}
772
773static void
774weston_desktop_xdg_popup_update_position(struct weston_desktop_surface *dsurface,
775 void *user_data)
776{
777}
778
779static void
780weston_desktop_xdg_popup_close(struct weston_desktop_xdg_popup *popup)
781{
782 zxdg_popup_v6_send_popup_done(popup->resource);
783}
784
785static void
786weston_desktop_xdg_popup_destroy(struct weston_desktop_xdg_popup *popup)
787{
788 struct weston_desktop_surface *topmost;
789 struct weston_desktop_client *client =
790 weston_desktop_surface_get_client(popup->base.desktop_surface);
791
792 if (!weston_desktop_surface_get_grab(popup->base.desktop_surface))
793 return;
794
795 topmost = weston_desktop_seat_popup_grab_get_topmost_surface(popup->seat);
796 if (topmost != popup->base.desktop_surface) {
797 struct wl_resource *client_resource =
798 weston_desktop_client_get_resource(client);
799
800 wl_resource_post_error(client_resource,
801 ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP,
802 "xdg_popup was destroyed while it was not the topmost popup.");
803 }
804
805 weston_desktop_surface_popup_ungrab(popup->base.desktop_surface,
806 popup->seat);
807}
808
809static void
810weston_desktop_xdg_popup_resource_destroy(struct wl_resource *resource)
811{
812 struct weston_desktop_surface *dsurface =
813 wl_resource_get_user_data(resource);
814
815 if (dsurface != NULL)
816 weston_desktop_surface_resource_destroy(resource);
817}
818
819static const struct zxdg_popup_v6_interface weston_desktop_xdg_popup_implementation = {
820 .destroy = weston_desktop_destroy_request,
821 .grab = weston_desktop_xdg_popup_protocol_grab,
822};
823
824static void
825weston_desktop_xdg_surface_send_configure(void *user_data)
826{
827 struct weston_desktop_xdg_surface *surface = user_data;
828
829 surface->configure_idle = NULL;
830 surface->configure_serial =
831 wl_display_next_serial(weston_desktop_get_display(surface->desktop));
832
833 switch (surface->role) {
834 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
835 assert(0 && "not reached");
836 break;
837 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
838 weston_desktop_xdg_toplevel_send_configure((struct weston_desktop_xdg_toplevel *) surface);
839 break;
840 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
841 weston_desktop_xdg_popup_send_configure((struct weston_desktop_xdg_popup *) surface);
842 break;
843 }
844
845 zxdg_surface_v6_send_configure(surface->resource, surface->configure_serial);
846}
847
848static void
849weston_desktop_xdg_surface_schedule_configure(struct weston_desktop_xdg_surface *surface)
850{
851 struct wl_display *display = weston_desktop_get_display(surface->desktop);
852 struct wl_event_loop *loop = wl_display_get_event_loop(display);
853
854 if (surface->configure_idle != NULL)
855 return;
856 surface->configure_idle =
857 wl_event_loop_add_idle(loop,
858 weston_desktop_xdg_surface_send_configure,
859 surface);
860}
861
862static void
863weston_desktop_xdg_surface_protocol_get_toplevel(struct wl_client *wl_client,
864 struct wl_resource *resource,
865 uint32_t id)
866{
867 struct weston_desktop_surface *dsurface =
868 wl_resource_get_user_data(resource);
869 struct weston_surface *wsurface =
870 weston_desktop_surface_get_surface(dsurface);
871 struct weston_desktop_xdg_toplevel *toplevel =
872 weston_desktop_surface_get_implementation_data(dsurface);
873
874 if (weston_surface_set_role(wsurface, weston_desktop_xdg_toplevel_role,
875 resource, ZXDG_SHELL_V6_ERROR_ROLE) < 0)
876 return;
877
878 toplevel->resource =
879 weston_desktop_surface_add_resource(toplevel->base.desktop_surface,
880 &zxdg_toplevel_v6_interface,
881 &weston_desktop_xdg_toplevel_implementation,
882 id, weston_desktop_xdg_toplevel_resource_destroy);
883 if (toplevel->resource == NULL)
884 return;
885
886 toplevel->base.role = WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL;
887}
888
889static void
890weston_desktop_xdg_surface_protocol_get_popup(struct wl_client *wl_client,
891 struct wl_resource *resource,
892 uint32_t id,
893 struct wl_resource *parent_resource,
894 struct wl_resource *positioner_resource)
895{
896 struct weston_desktop_surface *dsurface =
897 wl_resource_get_user_data(resource);
898 struct weston_surface *wsurface =
899 weston_desktop_surface_get_surface(dsurface);
900 struct weston_desktop_xdg_popup *popup =
901 weston_desktop_surface_get_implementation_data(dsurface);
902 struct weston_desktop_surface *parent_surface =
903 wl_resource_get_user_data(parent_resource);
904 struct weston_desktop_xdg_surface *parent =
905 weston_desktop_surface_get_implementation_data(parent_surface);
906 struct weston_desktop_xdg_positioner *positioner =
907 wl_resource_get_user_data(positioner_resource);
908
909 if (weston_surface_set_role(wsurface, weston_desktop_xdg_popup_role,
910 resource, ZXDG_SHELL_V6_ERROR_ROLE) < 0)
911 return;
912
913 popup->resource =
914 weston_desktop_surface_add_resource(popup->base.desktop_surface,
915 &zxdg_popup_v6_interface,
916 &weston_desktop_xdg_popup_implementation,
917 id, weston_desktop_xdg_popup_resource_destroy);
918 if (popup->resource == NULL)
919 return;
920
921 popup->base.role = WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP;
922 popup->parent = parent;
923
924 popup->geometry =
925 weston_desktop_xdg_positioner_get_geometry(positioner,
926 dsurface,
927 parent_surface);
928
929 weston_desktop_surface_set_relative_to(popup->base.desktop_surface,
930 parent_surface,
931 popup->geometry.x,
932 popup->geometry.y,
933 true);
934}
935
936static bool
937weston_desktop_xdg_surface_check_role(struct weston_desktop_xdg_surface *surface)
938{
939 struct weston_surface *wsurface =
940 weston_desktop_surface_get_surface(surface->desktop_surface);
941 const char *role;
942
943 role = weston_surface_get_role(wsurface);
944 if (role != NULL &&
945 (role == weston_desktop_xdg_toplevel_role ||
946 role == weston_desktop_xdg_popup_role))
947 return true;
948
949 wl_resource_post_error(surface->resource,
950 ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
951 "xdg_surface must have a role");
952 return false;
953}
954
955static void
956weston_desktop_xdg_surface_protocol_set_window_geometry(struct wl_client *wl_client,
957 struct wl_resource *resource,
958 int32_t x, int32_t y,
959 int32_t width, int32_t height)
960{
961 struct weston_desktop_surface *dsurface =
962 wl_resource_get_user_data(resource);
963 struct weston_desktop_xdg_surface *surface =
964 weston_desktop_surface_get_implementation_data(dsurface);
965
966 if (!weston_desktop_xdg_surface_check_role(surface))
967 return;
968
969 surface->has_next_geometry = true;
970 surface->next_geometry.x = x;
971 surface->next_geometry.y = y;
972 surface->next_geometry.width = width;
973 surface->next_geometry.height = height;
974}
975
976static void
977weston_desktop_xdg_surface_protocol_ack_configure(struct wl_client *wl_client,
978 struct wl_resource *resource,
979 uint32_t serial)
980{
981 struct weston_desktop_surface *dsurface =
982 wl_resource_get_user_data(resource);
983 struct weston_desktop_xdg_surface *surface =
984 weston_desktop_surface_get_implementation_data(dsurface);
985
986 if (!weston_desktop_xdg_surface_check_role(surface))
987 return;
988
989 if (surface->configure_serial != serial)
990 return;
991
992 surface->configured = true;
993
994 switch (surface->role) {
995 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
996 assert(0 && "not reached");
997 break;
998 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
999 weston_desktop_xdg_toplevel_ack_configure((struct weston_desktop_xdg_toplevel *) surface);
1000 break;
1001 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
1002 break;
1003 }
1004}
1005
1006static void
1007weston_desktop_xdg_surface_ping(struct weston_desktop_surface *dsurface,
1008 uint32_t serial, void *user_data)
1009{
1010 struct weston_desktop_client *client =
1011 weston_desktop_surface_get_client(dsurface);
1012
1013 zxdg_shell_v6_send_ping(weston_desktop_client_get_resource(client),
1014 serial);
1015}
1016
1017static void
1018weston_desktop_xdg_surface_committed(struct weston_desktop_surface *dsurface,
Quentin Glidic003da882016-08-15 12:21:39 +02001019 void *user_data,
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +02001020 int32_t sx, int32_t sy)
1021{
1022 struct weston_desktop_xdg_surface *surface = user_data;
Quentin Glidiccba26e72016-08-15 12:20:22 +02001023 struct weston_surface *wsurface =
1024 weston_desktop_surface_get_surface (dsurface);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +02001025
Quentin Glidiccba26e72016-08-15 12:20:22 +02001026 if (wsurface->buffer_ref.buffer && !surface->configured) {
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +02001027 wl_resource_post_error(surface->resource,
1028 ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
1029 "xdg_surface has never been configured");
1030 return;
1031 }
1032
1033 if (surface->has_next_geometry) {
1034 surface->has_next_geometry = false;
1035 weston_desktop_surface_set_geometry(surface->desktop_surface,
1036 surface->next_geometry);
1037 }
1038
1039 switch (surface->role) {
1040 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
1041 wl_resource_post_error(surface->resource,
1042 ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
1043 "xdg_surface must have a role");
1044 break;
1045 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
Quentin Glidiccba26e72016-08-15 12:20:22 +02001046 weston_desktop_xdg_toplevel_committed((struct weston_desktop_xdg_toplevel *) surface, sx, sy);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +02001047 break;
1048 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
1049 weston_desktop_xdg_popup_committed((struct weston_desktop_xdg_popup *) surface);
1050 break;
1051 }
1052}
1053
1054static void
1055weston_desktop_xdg_surface_close(struct weston_desktop_surface *dsurface,
1056 void *user_data)
1057{
1058 struct weston_desktop_xdg_surface *surface = user_data;
1059
1060 switch (surface->role) {
1061 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
1062 assert(0 && "not reached");
1063 break;
1064 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
1065 weston_desktop_xdg_toplevel_close((struct weston_desktop_xdg_toplevel *) surface);
1066 break;
1067 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
1068 weston_desktop_xdg_popup_close((struct weston_desktop_xdg_popup *) surface);
1069 break;
1070 }
1071}
1072
1073static void
1074weston_desktop_xdg_surface_destroy(struct weston_desktop_surface *dsurface,
1075 void *user_data)
1076{
1077 struct weston_desktop_xdg_surface *surface = user_data;
1078
1079 switch (surface->role) {
1080 case WESTON_DESKTOP_XDG_SURFACE_ROLE_NONE:
1081 break;
1082 case WESTON_DESKTOP_XDG_SURFACE_ROLE_TOPLEVEL:
1083 weston_desktop_xdg_toplevel_destroy((struct weston_desktop_xdg_toplevel *) surface);
1084 break;
1085 case WESTON_DESKTOP_XDG_SURFACE_ROLE_POPUP:
1086 weston_desktop_xdg_popup_destroy((struct weston_desktop_xdg_popup *) surface);
1087 break;
1088 }
1089
1090 if (surface->configure_idle != NULL)
1091 wl_event_source_remove(surface->configure_idle);
1092
1093 free(surface);
1094}
1095
1096static const struct zxdg_surface_v6_interface weston_desktop_xdg_surface_implementation = {
1097 .destroy = weston_desktop_destroy_request,
1098 .get_toplevel = weston_desktop_xdg_surface_protocol_get_toplevel,
1099 .get_popup = weston_desktop_xdg_surface_protocol_get_popup,
1100 .set_window_geometry = weston_desktop_xdg_surface_protocol_set_window_geometry,
1101 .ack_configure = weston_desktop_xdg_surface_protocol_ack_configure,
1102};
1103
1104static const struct weston_desktop_surface_implementation weston_desktop_xdg_surface_internal_implementation = {
1105 /* These are used for toplevel only */
1106 .set_maximized = weston_desktop_xdg_toplevel_set_maximized,
1107 .set_fullscreen = weston_desktop_xdg_toplevel_set_fullscreen,
1108 .set_resizing = weston_desktop_xdg_toplevel_set_resizing,
1109 .set_activated = weston_desktop_xdg_toplevel_set_activated,
1110 .set_size = weston_desktop_xdg_toplevel_set_size,
1111
1112 .get_maximized = weston_desktop_xdg_toplevel_get_maximized,
1113 .get_fullscreen = weston_desktop_xdg_toplevel_get_fullscreen,
1114 .get_resizing = weston_desktop_xdg_toplevel_get_resizing,
1115 .get_activated = weston_desktop_xdg_toplevel_get_activated,
1116
1117 /* These are used for popup only */
1118 .update_position = weston_desktop_xdg_popup_update_position,
1119
1120 /* Common API */
1121 .committed = weston_desktop_xdg_surface_committed,
1122 .ping = weston_desktop_xdg_surface_ping,
1123 .close = weston_desktop_xdg_surface_close,
1124
1125 .destroy = weston_desktop_xdg_surface_destroy,
1126};
1127
1128static void
1129weston_desktop_xdg_shell_protocol_create_positioner(struct wl_client *wl_client,
1130 struct wl_resource *resource,
1131 uint32_t id)
1132{
1133 struct weston_desktop_client *client =
1134 wl_resource_get_user_data(resource);
1135 struct weston_desktop_xdg_positioner *positioner;
1136
1137 positioner = zalloc(sizeof(struct weston_desktop_xdg_positioner));
1138 if (positioner == NULL) {
1139 wl_client_post_no_memory(wl_client);
1140 return;
1141 }
1142
1143 positioner->client = client;
1144 positioner->desktop = weston_desktop_client_get_desktop(positioner->client);
1145
1146 positioner->resource =
1147 wl_resource_create(wl_client,
1148 &zxdg_positioner_v6_interface,
1149 wl_resource_get_version(resource), id);
1150 if (positioner->resource == NULL) {
1151 wl_client_post_no_memory(wl_client);
1152 free(positioner);
1153 return;
1154 }
1155 wl_resource_set_implementation(positioner->resource,
1156 &weston_desktop_xdg_positioner_implementation,
1157 positioner, weston_desktop_xdg_positioner_destroy);
1158}
1159
1160static void
1161weston_desktop_xdg_surface_resource_destroy(struct wl_resource *resource)
1162{
1163 struct weston_desktop_surface *dsurface =
1164 wl_resource_get_user_data(resource);
1165
1166 if (dsurface != NULL)
1167 weston_desktop_surface_resource_destroy(resource);
1168}
1169
1170static void
1171weston_desktop_xdg_shell_protocol_get_xdg_surface(struct wl_client *wl_client,
1172 struct wl_resource *resource,
1173 uint32_t id,
1174 struct wl_resource *surface_resource)
1175{
1176 struct weston_desktop_client *client =
1177 wl_resource_get_user_data(resource);
1178 struct weston_surface *wsurface =
1179 wl_resource_get_user_data(surface_resource);
1180 struct weston_desktop_xdg_surface *surface;
1181
1182 surface = zalloc(weston_desktop_surface_role_biggest_size);
1183 if (surface == NULL) {
1184 wl_client_post_no_memory(wl_client);
1185 return;
1186 }
1187
1188 surface->desktop = weston_desktop_client_get_desktop(client);
1189 surface->surface = wsurface;
1190
1191 surface->desktop_surface =
1192 weston_desktop_surface_create(surface->desktop, client,
1193 surface->surface,
1194 &weston_desktop_xdg_surface_internal_implementation,
1195 surface);
1196 if (surface->desktop_surface == NULL) {
1197 free(surface);
1198 return;
1199 }
1200
1201 surface->resource =
1202 weston_desktop_surface_add_resource(surface->desktop_surface,
1203 &zxdg_surface_v6_interface,
1204 &weston_desktop_xdg_surface_implementation,
1205 id, weston_desktop_xdg_surface_resource_destroy);
1206 if (surface->resource == NULL)
1207 return;
1208
1209 if (wsurface->buffer_ref.buffer != NULL) {
1210 wl_resource_post_error(surface->resource,
1211 ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
1212 "xdg_surface must not have a buffer at creation");
1213 return;
1214 }
1215}
1216
1217static void
1218weston_desktop_xdg_shell_protocol_pong(struct wl_client *wl_client,
1219 struct wl_resource *resource,
1220 uint32_t serial)
1221{
1222 struct weston_desktop_client *client =
1223 wl_resource_get_user_data(resource);
1224
1225 weston_desktop_client_pong(client, serial);
1226}
1227
1228static const struct zxdg_shell_v6_interface weston_desktop_xdg_shell_implementation = {
1229 .destroy = weston_desktop_destroy_request,
1230 .create_positioner = weston_desktop_xdg_shell_protocol_create_positioner,
1231 .get_xdg_surface = weston_desktop_xdg_shell_protocol_get_xdg_surface,
1232 .pong = weston_desktop_xdg_shell_protocol_pong,
1233};
1234
1235static void
1236weston_desktop_xdg_shell_bind(struct wl_client *client, void *data,
1237 uint32_t version, uint32_t id)
1238{
1239 struct weston_desktop *desktop = data;
1240
1241 weston_desktop_client_create(desktop, client, NULL,
1242 &zxdg_shell_v6_interface,
1243 &weston_desktop_xdg_shell_implementation,
1244 version, id);
1245}
1246
1247struct wl_global *
1248weston_desktop_xdg_shell_v6_create(struct weston_desktop *desktop, struct wl_display *display)
1249{
1250 return wl_global_create(display, &zxdg_shell_v6_interface,
1251 WD_XDG_SHELL_PROTOCOL_VERSION, desktop,
1252 weston_desktop_xdg_shell_bind);
1253}