1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "host/libs/wayland/wayland_shell.h"
18
19 #include <android-base/logging.h>
20
21 #include <wayland-server-core.h>
22 #include <wayland-server-protocol.h>
23 #include <xdg-shell-server-protocol.h>
24
25 namespace wayland {
26 namespace {
27
xdg_positioner_destroy(wl_client *,wl_resource * positioner)28 void xdg_positioner_destroy(wl_client*, wl_resource* positioner) {
29 LOG(VERBOSE) << __FUNCTION__
30 << " positioner=" << positioner;
31
32 wl_resource_destroy(positioner);
33 }
34
xdg_positioner_set_size(wl_client *,wl_resource * positioner,int32_t w,int32_t h)35 void xdg_positioner_set_size(wl_client*, wl_resource* positioner, int32_t w,
36 int32_t h) {
37 LOG(VERBOSE) << __FUNCTION__
38 << " positioner=" << positioner
39 << " w=" << w
40 << " h=" << h;
41 }
42
xdg_positioner_set_anchor_rect(wl_client *,wl_resource * positioner,int32_t x,int32_t y,int32_t w,int32_t h)43 void xdg_positioner_set_anchor_rect(wl_client*, wl_resource* positioner,
44 int32_t x, int32_t y, int32_t w,
45 int32_t h) {
46 LOG(VERBOSE) << __FUNCTION__
47 << " positioner=" << positioner
48 << " x=" << x
49 << " y=" << y
50 << " w=" << w
51 << " h=" << h;
52 }
53
xdg_positioner_set_anchor(wl_client *,wl_resource * positioner,uint32_t anchor)54 void xdg_positioner_set_anchor(wl_client*, wl_resource* positioner,
55 uint32_t anchor) {
56 LOG(VERBOSE) << __FUNCTION__
57 << " positioner=" << positioner
58 << " anchor=" << anchor;
59 }
60
xdg_positioner_set_gravity(wl_client *,wl_resource * positioner,uint32_t gravity)61 void xdg_positioner_set_gravity(wl_client*, wl_resource* positioner,
62 uint32_t gravity) {
63 LOG(VERBOSE) << __FUNCTION__
64 << " positioner=" << positioner
65 << " gravity=" << gravity;
66 }
67
xdg_positioner_set_constraint_adjustment(wl_client *,wl_resource * positioner,uint32_t adjustment)68 void xdg_positioner_set_constraint_adjustment(wl_client*,
69 wl_resource* positioner,
70 uint32_t adjustment) {
71 LOG(VERBOSE) << __FUNCTION__
72 << " positioner=" << positioner
73 << " adjustment=" << adjustment;
74 }
75
xdg_positioner_set_offset(wl_client *,wl_resource * positioner,int32_t x,int32_t y)76 void xdg_positioner_set_offset(wl_client*, wl_resource* positioner, int32_t x,
77 int32_t y) {
78 LOG(VERBOSE) << __FUNCTION__
79 << " positioner=" << positioner
80 << " x=" << x
81 << " y=" << y;
82 }
83
84 const struct xdg_positioner_interface xdg_positioner_implementation = {
85 .destroy = xdg_positioner_destroy,
86 .set_size = xdg_positioner_set_size,
87 .set_anchor_rect = xdg_positioner_set_anchor_rect,
88 .set_anchor = xdg_positioner_set_anchor,
89 .set_gravity = xdg_positioner_set_gravity,
90 .set_constraint_adjustment = xdg_positioner_set_constraint_adjustment,
91 .set_offset = xdg_positioner_set_offset};
92
xdg_toplevel_destroy(wl_client *,wl_resource * toplevel)93 void xdg_toplevel_destroy(wl_client*, wl_resource* toplevel) {
94 LOG(VERBOSE) << __FUNCTION__
95 << " toplevel=" << toplevel;
96
97 wl_resource_destroy(toplevel);
98 }
99
xdg_toplevel_set_parent(wl_client *,wl_resource * toplevel,wl_resource * parent_toplevel)100 void xdg_toplevel_set_parent(wl_client*, wl_resource* toplevel,
101 wl_resource* parent_toplevel) {
102 LOG(VERBOSE) << __FUNCTION__
103 << " toplevel=" << toplevel
104 << " parent_toplevel=" << parent_toplevel;
105 }
106
xdg_toplevel_set_title(wl_client *,wl_resource * toplevel,const char * title)107 void xdg_toplevel_set_title(wl_client*, wl_resource* toplevel,
108 const char* title) {
109 LOG(VERBOSE) << __FUNCTION__
110 << " toplevel=" << toplevel
111 << " title=" << title;
112 }
113
xdg_toplevel_set_app_id(wl_client *,wl_resource * toplevel,const char * app)114 void xdg_toplevel_set_app_id(wl_client*, wl_resource* toplevel,
115 const char* app) {
116 LOG(VERBOSE) << __FUNCTION__
117 << " toplevel=" << toplevel
118 << " app=" << app;
119 }
120
xdg_toplevel_show_window_menu(wl_client *,wl_resource * toplevel,wl_resource * seat,uint32_t serial,int32_t x,int32_t y)121 void xdg_toplevel_show_window_menu(wl_client*, wl_resource* toplevel,
122 wl_resource* seat, uint32_t serial,
123 int32_t x, int32_t y) {
124 LOG(VERBOSE) << __FUNCTION__
125 << " toplevel=" << toplevel
126 << " seat=" << seat
127 << " serial=" << serial
128 << " x=" << x
129 << " y=" << y;
130 }
131
xdg_toplevel_move(wl_client *,wl_resource * toplevel,wl_resource * seat,uint32_t serial)132 void xdg_toplevel_move(wl_client*, wl_resource* toplevel, wl_resource* seat,
133 uint32_t serial) {
134 LOG(VERBOSE) << __FUNCTION__
135 << " toplevel=" << toplevel
136 << " seat=" << seat
137 << " serial=" << serial;
138 }
139
xdg_toplevel_resize(wl_client *,wl_resource * toplevel,wl_resource * seat,uint32_t serial,uint32_t edges)140 void xdg_toplevel_resize(wl_client*, wl_resource* toplevel, wl_resource* seat,
141 uint32_t serial, uint32_t edges) {
142 LOG(VERBOSE) << __FUNCTION__
143 << " toplevel=" << toplevel
144 << " seat=" << seat
145 << " serial=" << serial
146 << " edges=" << edges;
147 }
148
xdg_toplevel_set_max_size(wl_client *,wl_resource * toplevel,int32_t w,int32_t h)149 void xdg_toplevel_set_max_size(wl_client*, wl_resource* toplevel, int32_t w,
150 int32_t h) {
151 LOG(VERBOSE) << __FUNCTION__
152 << " toplevel=" << toplevel
153 << " w=" << w
154 << " h=" << h;
155 }
156
xdg_toplevel_set_min_size(wl_client *,wl_resource * toplevel,int32_t w,int32_t h)157 void xdg_toplevel_set_min_size(wl_client*, wl_resource* toplevel, int32_t w,
158 int32_t h) {
159 LOG(VERBOSE) << __FUNCTION__
160 << " toplevel=" << toplevel
161 << " w=" << w
162 << " h=" << h;
163 }
164
xdg_toplevel_set_maximized(wl_client *,wl_resource * toplevel)165 void xdg_toplevel_set_maximized(wl_client*, wl_resource* toplevel) {
166 LOG(VERBOSE) << __FUNCTION__
167 << " toplevel=" << toplevel;
168 }
169
xdg_toplevel_unset_maximized(wl_client *,wl_resource * toplevel)170 void xdg_toplevel_unset_maximized(wl_client*, wl_resource* toplevel) {
171 LOG(VERBOSE) << __FUNCTION__
172 << " toplevel=" << toplevel;
173 }
174
xdg_toplevel_set_fullscreen(wl_client *,wl_resource * toplevel,wl_resource *)175 void xdg_toplevel_set_fullscreen(wl_client*, wl_resource* toplevel,
176 wl_resource*) {
177 LOG(VERBOSE) << __FUNCTION__
178 << " toplevel=" << toplevel;
179 }
180
xdg_toplevel_unset_fullscreen(wl_client *,wl_resource * toplevel)181 void xdg_toplevel_unset_fullscreen(wl_client*, wl_resource* toplevel) {
182 LOG(VERBOSE) << __FUNCTION__
183 << " toplevel=" << toplevel;
184 }
185
xdg_toplevel_set_minimized(wl_client *,wl_resource * toplevel)186 void xdg_toplevel_set_minimized(wl_client*, wl_resource* toplevel) {
187 LOG(VERBOSE) << __FUNCTION__
188 << " toplevel=" << toplevel;
189 }
190
191 const struct xdg_toplevel_interface xdg_toplevel_implementation = {
192 .destroy = xdg_toplevel_destroy,
193 .set_parent = xdg_toplevel_set_parent,
194 .set_title = xdg_toplevel_set_title,
195 .set_app_id = xdg_toplevel_set_app_id,
196 .show_window_menu = xdg_toplevel_show_window_menu,
197 .move = xdg_toplevel_move,
198 .resize = xdg_toplevel_resize,
199 .set_max_size = xdg_toplevel_set_max_size,
200 .set_min_size = xdg_toplevel_set_min_size,
201 .set_maximized = xdg_toplevel_set_maximized,
202 .unset_maximized = xdg_toplevel_unset_maximized,
203 .set_fullscreen = xdg_toplevel_set_fullscreen,
204 .unset_fullscreen = xdg_toplevel_unset_fullscreen,
205 .set_minimized = xdg_toplevel_set_minimized};
206
xdg_popup_destroy(wl_client *,wl_resource * popup)207 void xdg_popup_destroy(wl_client*, wl_resource* popup) {
208 LOG(VERBOSE) << __FUNCTION__
209 << " popup=" << popup;
210
211 wl_resource_destroy(popup);
212 }
213
xdg_popup_grab(wl_client *,wl_resource * popup,wl_resource * seat,uint32_t serial)214 void xdg_popup_grab(wl_client*, wl_resource* popup, wl_resource* seat,
215 uint32_t serial) {
216 LOG(VERBOSE) << __FUNCTION__
217 << " popup=" << popup
218 << " seat=" << seat
219 << " serial=" << serial;
220 }
221
222 const struct xdg_popup_interface xdg_popup_implementation = {
223 .destroy = xdg_popup_destroy, .grab = xdg_popup_grab};
224
xdg_surface_destroy(wl_client *,wl_resource * surface)225 void xdg_surface_destroy(wl_client*, wl_resource* surface) {
226 LOG(VERBOSE) << __FUNCTION__
227 << " surface=" << surface;
228
229 wl_resource_destroy(surface);
230 }
231
toplevel_destroy_resource_callback(struct wl_resource *)232 void toplevel_destroy_resource_callback(struct wl_resource*) {}
233
xdg_surface_get_toplevel(wl_client * client,wl_resource * surface,uint32_t id)234 void xdg_surface_get_toplevel(wl_client* client, wl_resource* surface,
235 uint32_t id) {
236 LOG(VERBOSE) << __FUNCTION__
237 << " surface=" << surface
238 << " id=" << id;
239
240 wl_resource* xdg_toplevel_resource =
241 wl_resource_create(client, &xdg_toplevel_interface, 1, id);
242
243 wl_resource_set_implementation(xdg_toplevel_resource,
244 &xdg_toplevel_implementation, nullptr,
245 toplevel_destroy_resource_callback);
246 }
247
popup_destroy_resource_callback(struct wl_resource *)248 void popup_destroy_resource_callback(struct wl_resource*) {}
249
xdg_surface_get_popup(wl_client * client,wl_resource * surface,uint32_t id,wl_resource * parent_surface,wl_resource * positioner)250 void xdg_surface_get_popup(wl_client* client, wl_resource* surface, uint32_t id,
251 wl_resource* parent_surface,
252 wl_resource* positioner) {
253 LOG(VERBOSE) << __FUNCTION__
254 << " surface=" << surface
255 << " id=" << id
256 << " parent_surface=" << parent_surface
257 << " positioner=" << positioner;
258
259 wl_resource* xdg_popup_resource =
260 wl_resource_create(client, &xdg_popup_interface, 1, id);
261
262 wl_resource_set_implementation(xdg_popup_resource, &xdg_popup_implementation,
263 nullptr, popup_destroy_resource_callback);
264 }
265
xdg_surface_set_window_geometry(wl_client *,wl_resource * surface,int32_t x,int32_t y,int32_t w,int32_t h)266 void xdg_surface_set_window_geometry(wl_client*, wl_resource* surface,
267 int32_t x, int32_t y, int32_t w,
268 int32_t h) {
269 LOG(VERBOSE) << __FUNCTION__
270 << " surface=" << surface
271 << " x=" << x
272 << " y=" << y
273 << " w=" << w
274 << " h=" << h;
275 }
276
xdg_surface_ack_configure(wl_client *,wl_resource * surface,uint32_t serial)277 void xdg_surface_ack_configure(wl_client*, wl_resource* surface,
278 uint32_t serial) {
279 LOG(VERBOSE) << __FUNCTION__
280 << " surface=" << surface
281 << " serial=" << serial;
282 }
283
284 const struct xdg_surface_interface xdg_surface_implementation = {
285 .destroy = xdg_surface_destroy,
286 .get_toplevel = xdg_surface_get_toplevel,
287 .get_popup = xdg_surface_get_popup,
288 .set_window_geometry = xdg_surface_set_window_geometry,
289 .ack_configure = xdg_surface_ack_configure};
290
xdg_shell_destroy(wl_client *,wl_resource * shell)291 void xdg_shell_destroy(wl_client*, wl_resource* shell) {
292 LOG(VERBOSE) << __FUNCTION__
293 << " shell=" << shell;
294
295 wl_resource_destroy(shell);
296 }
297
positioner_destroy_resource_callback(struct wl_resource *)298 void positioner_destroy_resource_callback(struct wl_resource*) {}
299
xdg_shell_create_positioner(wl_client * client,wl_resource * shell,uint32_t id)300 void xdg_shell_create_positioner(wl_client* client, wl_resource* shell,
301 uint32_t id) {
302 LOG(VERBOSE) << __FUNCTION__
303 << " shell=" << shell
304 << " id=" << id;
305
306 wl_resource* positioner_resource =
307 wl_resource_create(client, &xdg_positioner_interface, 1, id);
308
309 wl_resource_set_implementation(positioner_resource,
310 &xdg_positioner_implementation, nullptr,
311 positioner_destroy_resource_callback);
312 }
313
surface_destroy_resource_callback(struct wl_resource *)314 void surface_destroy_resource_callback(struct wl_resource*) {}
315
xdg_shell_get_xdg_surface(wl_client * client,wl_resource * shell,uint32_t id,wl_resource * surface)316 void xdg_shell_get_xdg_surface(wl_client* client, wl_resource* shell,
317 uint32_t id, wl_resource* surface) {
318 LOG(VERBOSE) << __FUNCTION__
319 << " shell=" << shell
320 << " id=" << id
321 << " surface=" << surface;
322
323 wl_resource* surface_resource =
324 wl_resource_create(client, &xdg_surface_interface, 1, id);
325
326 wl_resource_set_implementation(surface_resource, &xdg_surface_implementation,
327 nullptr, surface_destroy_resource_callback);
328 }
329
xdg_shell_pong(wl_client *,wl_resource * shell,uint32_t serial)330 void xdg_shell_pong(wl_client*, wl_resource* shell, uint32_t serial) {
331 LOG(VERBOSE) << __FUNCTION__
332 << " shell=" << shell
333 << " serial=" << serial;
334 }
335
336 const struct xdg_wm_base_interface xdg_shell_implementation = {
337 .destroy = xdg_shell_destroy,
338 .create_positioner = xdg_shell_create_positioner,
339 .get_xdg_surface = xdg_shell_get_xdg_surface,
340 .pong = xdg_shell_pong};
341
bind_shell(wl_client * client,void * data,uint32_t version,uint32_t id)342 void bind_shell(wl_client* client, void* data, uint32_t version, uint32_t id) {
343 wl_resource* shell_resource =
344 wl_resource_create(client, &xdg_wm_base_interface, version, id);
345
346 wl_resource_set_implementation(shell_resource, &xdg_shell_implementation,
347 data, nullptr);
348 }
349
350 } // namespace
351
BindShellInterface(wl_display * display)352 void BindShellInterface(wl_display* display) {
353 wl_global_create(display, &xdg_wm_base_interface, 1, nullptr, bind_shell);
354 }
355
356 } // namespace wayland