blob: fdfe21bfaceb6c9b75d72e48e5b9d630e9bd18df [file] [log] [blame]
Quentin Glidic248dd102016-08-12 10:41:34 +02001/*
2 * Copyright © 2016 Quentin "Sardem FF7" Glidic
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#include "config.h"
25
26#include <string.h>
27
28#include <wayland-server.h>
29#include <assert.h>
30
Pekka Paalanen3d5d9472019-03-28 16:28:47 +020031#include <libweston/libweston.h>
Pekka Paalanenecbdcfd2019-04-04 14:46:00 +030032#include <libweston/zalloc.h>
Pekka Paalanenc232f8d2019-04-05 16:09:45 +030033#include "shared/helpers.h"
Quentin Glidic248dd102016-08-12 10:41:34 +020034
Pekka Paalanen8ebd9812019-04-04 16:02:14 +030035#include <libweston-desktop/libweston-desktop.h>
Quentin Glidic248dd102016-08-12 10:41:34 +020036#include "internal.h"
37
38
39struct weston_desktop {
40 struct weston_compositor *compositor;
41 struct weston_desktop_api api;
42 void *user_data;
ant8med8d9f5e2018-11-28 22:46:37 +010043 struct wl_global *xdg_wm_base; /* Stable protocol xdg_shell replaces xdg_shell_unstable_v6 */
44 struct wl_global *xdg_shell_v6; /* Unstable xdg_shell_unstable_v6 protocol. */
Quentin Glidic248dd102016-08-12 10:41:34 +020045 struct wl_global *wl_shell;
46};
47
48void
49weston_desktop_destroy_request(struct wl_client *client,
50 struct wl_resource *resource)
51{
52 wl_resource_destroy(resource);
53}
54
55WL_EXPORT struct weston_desktop *
56weston_desktop_create(struct weston_compositor *compositor,
57 const struct weston_desktop_api *api, void *user_data)
58{
59 struct weston_desktop *desktop;
60 struct wl_display *display = compositor->wl_display;
61
62 assert(api->surface_added);
63 assert(api->surface_removed);
64
65 desktop = zalloc(sizeof(struct weston_desktop));
66 desktop->compositor = compositor;
67 desktop->user_data = user_data;
68
69 desktop->api.struct_size =
70 MIN(sizeof(struct weston_desktop_api), api->struct_size);
71 memcpy(&desktop->api, api, desktop->api.struct_size);
72
ant8med8d9f5e2018-11-28 22:46:37 +010073 desktop->xdg_wm_base =
74 weston_desktop_xdg_wm_base_create(desktop, display);
75 if (desktop->xdg_wm_base == NULL) {
76 weston_desktop_destroy(desktop);
77 return NULL;
78 }
79
Simon Ser413d2102021-02-16 13:34:46 +010080#ifdef HAVE_DEPRECATED_WL_SHELL
81 weston_log("Warning: support for deprecated wl_shell interface is "
82 "enabled. Please migrate legacy clients to xdg-shell.\n");
Quentin Glidic248dd102016-08-12 10:41:34 +020083 desktop->wl_shell =
84 weston_desktop_wl_shell_create(desktop, display);
85 if (desktop->wl_shell == NULL) {
86 weston_desktop_destroy(desktop);
87 return NULL;
88 }
Simon Ser413d2102021-02-16 13:34:46 +010089#else
90 weston_log("Note: support for the deprecated wl_shell interface is "
91 "disabled. If a legacy client still needs it, it can be "
92 "re-enabled by passing -Ddeprecated-wl-shell=true to Meson "
93 "when building Weston.\n");
94#endif
Quentin Glidic248dd102016-08-12 10:41:34 +020095
96 weston_desktop_xwayland_init(desktop);
97
98 return desktop;
99}
100
101WL_EXPORT void
102weston_desktop_destroy(struct weston_desktop *desktop)
103{
104 if (desktop == NULL)
105 return;
106
Pekka Paalanene2583ca2021-05-14 16:12:35 +0300107 weston_desktop_xwayland_fini(desktop);
108
Quentin Glidic248dd102016-08-12 10:41:34 +0200109 if (desktop->wl_shell != NULL)
110 wl_global_destroy(desktop->wl_shell);
Quentin Glidic9c5dd7e2016-08-12 10:41:37 +0200111 if (desktop->xdg_shell_v6 != NULL)
112 wl_global_destroy(desktop->xdg_shell_v6);
ant8med8d9f5e2018-11-28 22:46:37 +0100113 if (desktop->xdg_wm_base != NULL)
114 wl_global_destroy(desktop->xdg_wm_base);
Quentin Glidic248dd102016-08-12 10:41:34 +0200115
116 free(desktop);
117}
118
119
120struct weston_compositor *
121weston_desktop_get_compositor(struct weston_desktop *desktop)
122{
123 return desktop->compositor;
124}
125
126struct wl_display *
127weston_desktop_get_display(struct weston_desktop *desktop)
128{
129 return desktop->compositor->wl_display;
130}
131
132void
133weston_desktop_api_ping_timeout(struct weston_desktop *desktop,
134 struct weston_desktop_client *client)
135{
136 if (desktop->api.ping_timeout != NULL)
137 desktop->api.ping_timeout(client, desktop->user_data);
138}
139
140void
141weston_desktop_api_pong(struct weston_desktop *desktop,
142 struct weston_desktop_client *client)
143{
144 if (desktop->api.pong != NULL)
145 desktop->api.pong(client, desktop->user_data);
146}
147
148void
149weston_desktop_api_surface_added(struct weston_desktop *desktop,
150 struct weston_desktop_surface *surface)
151{
152 struct weston_desktop_client *client =
153 weston_desktop_surface_get_client(surface);
154 struct wl_list *list = weston_desktop_client_get_surface_list(client);
155 struct wl_list *link = weston_desktop_surface_get_client_link(surface);
156
157 desktop->api.surface_added(surface, desktop->user_data);
158 wl_list_insert(list, link);
159}
160
161void
162weston_desktop_api_surface_removed(struct weston_desktop *desktop,
163 struct weston_desktop_surface *surface)
164{
165 struct wl_list *link = weston_desktop_surface_get_client_link(surface);
166
167 wl_list_remove(link);
168 wl_list_init(link);
169 desktop->api.surface_removed(surface, desktop->user_data);
170}
171
172void
Quentin Glidic248dd102016-08-12 10:41:34 +0200173weston_desktop_api_committed(struct weston_desktop *desktop,
174 struct weston_desktop_surface *surface,
175 int32_t sx, int32_t sy)
176{
177 if (desktop->api.committed != NULL)
178 desktop->api.committed(surface, sx, sy, desktop->user_data);
179}
180
181void
182weston_desktop_api_show_window_menu(struct weston_desktop *desktop,
183 struct weston_desktop_surface *surface,
184 struct weston_seat *seat,
185 int32_t x, int32_t y)
186{
187 if (desktop->api.show_window_menu != NULL)
188 desktop->api.show_window_menu(surface, seat, x, y,
189 desktop->user_data);
190}
191
192void
193weston_desktop_api_set_parent(struct weston_desktop *desktop,
194 struct weston_desktop_surface *surface,
195 struct weston_desktop_surface *parent)
196{
197 if (desktop->api.set_parent != NULL)
198 desktop->api.set_parent(surface, parent, desktop->user_data);
199}
200
201void
202weston_desktop_api_move(struct weston_desktop *desktop,
203 struct weston_desktop_surface *surface,
204 struct weston_seat *seat, uint32_t serial)
205{
206 if (desktop->api.move != NULL)
207 desktop->api.move(surface, seat, serial, desktop->user_data);
208}
209
210void
211weston_desktop_api_resize(struct weston_desktop *desktop,
212 struct weston_desktop_surface *surface,
213 struct weston_seat *seat, uint32_t serial,
214 enum weston_desktop_surface_edge edges)
215{
216 if (desktop->api.resize != NULL)
217 desktop->api.resize(surface, seat, serial, edges,
218 desktop->user_data);
219}
220
221void
222weston_desktop_api_fullscreen_requested(struct weston_desktop *desktop,
223 struct weston_desktop_surface *surface,
224 bool fullscreen,
225 struct weston_output *output)
226{
227 if (desktop->api.fullscreen_requested != NULL)
228 desktop->api.fullscreen_requested(surface, fullscreen, output,
229 desktop->user_data);
230}
231
232void
233weston_desktop_api_maximized_requested(struct weston_desktop *desktop,
234 struct weston_desktop_surface *surface,
235 bool maximized)
236{
237 if (desktop->api.maximized_requested != NULL)
238 desktop->api.maximized_requested(surface, maximized,
239 desktop->user_data);
240}
241
242void
243weston_desktop_api_minimized_requested(struct weston_desktop *desktop,
244 struct weston_desktop_surface *surface)
245{
246 if (desktop->api.minimized_requested != NULL)
247 desktop->api.minimized_requested(surface, desktop->user_data);
248}
Pekka Paalanen37111e12016-11-16 14:03:31 +0200249
250void
251weston_desktop_api_set_xwayland_position(struct weston_desktop *desktop,
252 struct weston_desktop_surface *surface,
253 int32_t x, int32_t y)
254{
255 if (desktop->api.set_xwayland_position != NULL)
256 desktop->api.set_xwayland_position(surface, x, y,
257 desktop->user_data);
258}