Skip to content

Commit f6fb565

Browse files
authored
[Wayland] Add support for xdg-foreign-v2 (#728)
This is important for the actual versions of xdg-desktop-portal under Wayland.
1 parent 1a439ae commit f6fb565

9 files changed

+496
-69
lines changed

src/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ if have_wayland
529529
'wayland/meta-wayland-input-device.h',
530530
'wayland/meta-wayland-keyboard.c',
531531
'wayland/meta-wayland-keyboard.h',
532+
'wayland/meta-wayland-legacy-xdg-foreign.c',
533+
'wayland/meta-wayland-legacy-xdg-foreign.h',
532534
'wayland/meta-wayland-legacy-xdg-shell.c',
533535
'wayland/meta-wayland-legacy-xdg-shell.h',
534536
'wayland/meta-wayland-outputs.c',
@@ -590,6 +592,7 @@ if have_wayland
590592
'wayland/meta-wayland-wl-shell.h',
591593
'wayland/meta-wayland-xdg-foreign.c',
592594
'wayland/meta-wayland-xdg-foreign.h',
595+
'wayland/meta-wayland-xdg-foreign-private.h',
593596
'wayland/meta-wayland-xdg-shell.c',
594597
'wayland/meta-wayland-xdg-shell.h',
595598
'wayland/meta-window-wayland.c',
@@ -814,6 +817,7 @@ if have_wayland
814817
['text-input', 'unstable', 'v3', ],
815818
['viewporter', 'stable', ],
816819
['xdg-foreign', 'unstable', 'v1', ],
820+
['xdg-foreign', 'unstable', 'v2', ],
817821
['xdg-output', 'unstable', 'v1', ],
818822
['xdg-shell', 'unstable', 'v6', ],
819823
['xdg-shell', 'stable', ],
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2+
3+
/*
4+
* Copyright (C) 2015 Red Hat Inc.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License as
8+
* published by the Free Software Foundation; either version 2 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19+
* 02111-1307, USA.
20+
*
21+
* Written by:
22+
* Jonas Ådahl <[email protected]>
23+
*/
24+
25+
#include "config.h"
26+
27+
#include "wayland/meta-wayland-legacy-xdg-foreign.h"
28+
29+
#include <wayland-server.h>
30+
31+
#include "core/util-private.h"
32+
#include "wayland/meta-wayland-private.h"
33+
#include "wayland/meta-wayland-versions.h"
34+
#include "wayland/meta-wayland-xdg-foreign-private.h"
35+
36+
#include "xdg-foreign-unstable-v1-server-protocol.h"
37+
38+
static void
39+
xdg_exporter_v1_destroy (struct wl_client *client,
40+
struct wl_resource *resource)
41+
{
42+
wl_resource_destroy (resource);
43+
}
44+
45+
static void
46+
xdg_exported_v1_destroy (struct wl_client *client,
47+
struct wl_resource *resource)
48+
{
49+
wl_resource_destroy (resource);
50+
}
51+
52+
static const struct zxdg_exported_v1_interface meta_xdg_exported_v1_interface = {
53+
xdg_exported_v1_destroy,
54+
};
55+
56+
static void
57+
xdg_exported_v1_destructor (struct wl_resource *resource)
58+
{
59+
MetaWaylandXdgExported *exported = wl_resource_get_user_data (resource);
60+
61+
if (exported)
62+
meta_wayland_xdg_exported_destroy (exported);
63+
}
64+
65+
static void
66+
xdg_exporter_v1_export (struct wl_client *client,
67+
struct wl_resource *resource,
68+
uint32_t id,
69+
struct wl_resource *surface_resource)
70+
{
71+
MetaWaylandXdgForeign *foreign = wl_resource_get_user_data (resource);
72+
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
73+
struct wl_resource *xdg_exported_resource;
74+
MetaWaylandXdgExported *exported;
75+
const char *handle;
76+
77+
if (!meta_wayland_xdg_foreign_is_valid_surface (surface, resource))
78+
return;
79+
80+
xdg_exported_resource =
81+
wl_resource_create (client,
82+
&zxdg_exported_v1_interface,
83+
wl_resource_get_version (resource),
84+
id);
85+
if (!xdg_exported_resource)
86+
{
87+
wl_client_post_no_memory (client);
88+
return;
89+
}
90+
91+
exported = meta_wayland_xdg_foreign_export (foreign, xdg_exported_resource, surface);
92+
if (!exported)
93+
return;
94+
95+
wl_resource_set_implementation (xdg_exported_resource,
96+
&meta_xdg_exported_v1_interface,
97+
exported,
98+
xdg_exported_v1_destructor);
99+
100+
handle = meta_wayland_xdg_exported_get_handle (exported);
101+
102+
zxdg_exported_v1_send_handle (xdg_exported_resource, handle);
103+
}
104+
105+
static const struct zxdg_exporter_v1_interface meta_xdg_exporter_v1_interface = {
106+
xdg_exporter_v1_destroy,
107+
xdg_exporter_v1_export,
108+
};
109+
110+
static void
111+
bind_xdg_exporter_v1 (struct wl_client *client,
112+
void *data,
113+
uint32_t version,
114+
uint32_t id)
115+
{
116+
MetaWaylandXdgForeign *foreign = data;
117+
struct wl_resource *resource;
118+
119+
resource = wl_resource_create (client,
120+
&zxdg_exporter_v1_interface,
121+
META_ZXDG_EXPORTER_V1_VERSION,
122+
id);
123+
124+
if (resource == NULL)
125+
{
126+
wl_client_post_no_memory (client);
127+
return;
128+
}
129+
130+
wl_resource_set_implementation (resource,
131+
&meta_xdg_exporter_v1_interface,
132+
foreign, NULL);
133+
}
134+
135+
static void
136+
xdg_imported_v1_destroy (struct wl_client *client,
137+
struct wl_resource *resource)
138+
{
139+
wl_resource_destroy (resource);
140+
}
141+
142+
static void
143+
xdg_imported_v1_set_parent_of (struct wl_client *client,
144+
struct wl_resource *resource,
145+
struct wl_resource *surface_resource)
146+
{
147+
MetaWaylandXdgImported *imported = wl_resource_get_user_data (resource);
148+
149+
meta_wayland_xdg_imported_set_parent_of (imported, surface_resource);
150+
}
151+
152+
static const struct zxdg_imported_v1_interface meta_xdg_imported_v1_interface = {
153+
xdg_imported_v1_destroy,
154+
xdg_imported_v1_set_parent_of,
155+
};
156+
157+
static void
158+
xdg_importer_v1_destroy (struct wl_client *client,
159+
struct wl_resource *resource)
160+
{
161+
wl_resource_destroy (resource);
162+
}
163+
164+
static void
165+
xdg_imported_v1_destructor (struct wl_resource *resource)
166+
{
167+
MetaWaylandXdgImported *imported;
168+
169+
imported = wl_resource_get_user_data (resource);
170+
if (!imported)
171+
return;
172+
173+
meta_wayland_xdg_imported_destroy (imported);
174+
}
175+
176+
static void
177+
xdg_importer_v1_import (struct wl_client *client,
178+
struct wl_resource *resource,
179+
uint32_t id,
180+
const char *handle)
181+
{
182+
MetaWaylandXdgForeign *foreign = wl_resource_get_user_data (resource);
183+
struct wl_resource *xdg_imported_resource;
184+
MetaWaylandXdgImported *imported;
185+
186+
xdg_imported_resource =
187+
wl_resource_create (client,
188+
&zxdg_imported_v1_interface,
189+
wl_resource_get_version (resource),
190+
id);
191+
if (!xdg_imported_resource)
192+
{
193+
wl_client_post_no_memory (client);
194+
return;
195+
}
196+
197+
imported = meta_wayland_xdg_foreign_import (foreign, xdg_imported_resource,
198+
handle,
199+
zxdg_imported_v1_send_destroyed);
200+
if (!imported)
201+
{
202+
zxdg_imported_v1_send_destroyed (xdg_imported_resource);
203+
return;
204+
}
205+
206+
wl_resource_set_implementation (xdg_imported_resource,
207+
&meta_xdg_imported_v1_interface,
208+
imported,
209+
xdg_imported_v1_destructor);
210+
}
211+
212+
static const struct zxdg_importer_v1_interface meta_xdg_importer_v1_interface = {
213+
xdg_importer_v1_destroy,
214+
xdg_importer_v1_import,
215+
};
216+
217+
static void
218+
bind_xdg_importer_v1 (struct wl_client *client,
219+
void *data,
220+
uint32_t version,
221+
uint32_t id)
222+
{
223+
MetaWaylandXdgForeign *foreign = data;
224+
struct wl_resource *resource;
225+
226+
resource = wl_resource_create (client,
227+
&zxdg_importer_v1_interface,
228+
META_ZXDG_IMPORTER_V1_VERSION,
229+
id);
230+
231+
if (resource == NULL)
232+
{
233+
wl_client_post_no_memory (client);
234+
return;
235+
}
236+
237+
wl_resource_set_implementation (resource,
238+
&meta_xdg_importer_v1_interface,
239+
foreign,
240+
NULL);
241+
}
242+
243+
gboolean
244+
meta_wayland_legacy_xdg_foreign_init (MetaWaylandCompositor *compositor)
245+
{
246+
if (wl_global_create (compositor->wayland_display,
247+
&zxdg_exporter_v1_interface, 1,
248+
compositor->foreign,
249+
bind_xdg_exporter_v1) == NULL)
250+
return FALSE;
251+
252+
if (wl_global_create (compositor->wayland_display,
253+
&zxdg_importer_v1_interface, 1,
254+
compositor->foreign,
255+
bind_xdg_importer_v1) == NULL)
256+
return FALSE;
257+
258+
return TRUE;
259+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2+
3+
/*
4+
* Copyright (C) 2015 Red Hat
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License as
8+
* published by the Free Software Foundation; either version 2 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19+
* 02111-1307, USA.
20+
*
21+
* Written by:
22+
* Jonas Ådahl <[email protected]>
23+
*/
24+
25+
#ifndef META_WAYLAND_LEGACY_FOREIGN_H
26+
#define META_WAYLAND_LEGACY_FOREIGN_H
27+
28+
#include <glib.h>
29+
30+
#include "wayland/meta-wayland-types.h"
31+
32+
gboolean meta_wayland_legacy_xdg_foreign_init (MetaWaylandCompositor *compositor);
33+
34+
#endif /* META_WAYLAND_LEGACY_FOREIGN_H */

src/wayland/meta-wayland-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct _MetaWaylandCompositor
8585

8686
MetaWaylandSeat *seat;
8787
MetaWaylandTabletManager *tablet_manager;
88+
MetaWaylandXdgForeign *foreign;
8889

8990
GHashTable *scheduled_surface_associations;
9091
};

src/wayland/meta-wayland-types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@ typedef struct _MetaWaylandWindowConfiguration MetaWaylandWindowConfiguration;
6161

6262
typedef struct _MetaWaylandPointerClient MetaWaylandPointerClient;
6363

64+
typedef struct _MetaWaylandXdgForeign MetaWaylandXdgForeign;
65+
6466
#endif

src/wayland/meta-wayland-versions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#define META_ZWP_POINTER_GESTURES_V1_VERSION 1
4949
#define META_ZXDG_EXPORTER_V1_VERSION 1
5050
#define META_ZXDG_IMPORTER_V1_VERSION 1
51+
#define META_ZXDG_EXPORTER_V2_VERSION 1
52+
#define META_ZXDG_IMPORTER_V2_VERSION 1
5153
#define META_ZWP_LINUX_DMABUF_V1_VERSION 3
5254
#define META_ZWP_KEYBOARD_SHORTCUTS_INHIBIT_V1_VERSION 1
5355
#define META_ZXDG_OUTPUT_V1_VERSION 3

0 commit comments

Comments
 (0)