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+ 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+ }
0 commit comments