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-unstable-v6-server-protocol.h>
24 
25 namespace wayland {
26 namespace {
27 
28 
zxdg_positioner_v6_destroy(wl_client *,wl_resource * positioner)29 void zxdg_positioner_v6_destroy(wl_client*, wl_resource* positioner) {
30   LOG(VERBOSE) << __FUNCTION__
31                << " positioner=" << positioner;
32 
33   wl_resource_destroy(positioner);
34 }
35 
zxdg_positioner_v6_set_size(wl_client *,wl_resource * positioner,int32_t w,int32_t h)36 void zxdg_positioner_v6_set_size(wl_client*,
37                                  wl_resource* positioner,
38                                  int32_t w,
39                                  int32_t h) {
40   LOG(VERBOSE) << __FUNCTION__
41                << " positioner=" << positioner
42                << " w=" << w
43                << " h=" << h;
44 }
45 
zxdg_positioner_v6_set_anchor_rect(wl_client *,wl_resource * positioner,int32_t x,int32_t y,int32_t w,int32_t h)46 void zxdg_positioner_v6_set_anchor_rect(wl_client*,
47                                         wl_resource* positioner,
48                                         int32_t x,
49                                         int32_t y,
50                                         int32_t w,
51                                         int32_t h) {
52   LOG(VERBOSE) << __FUNCTION__
53                << " positioner=" << positioner
54                << " x=" << x
55                << " y=" << y
56                << " w=" << w
57                << " h=" << h;
58 }
59 
zxdg_positioner_v6_set_anchor(wl_client *,wl_resource * positioner,uint32_t anchor)60 void zxdg_positioner_v6_set_anchor(wl_client*,
61                                    wl_resource* positioner,
62                                    uint32_t anchor) {
63   LOG(VERBOSE) << __FUNCTION__
64                << " positioner=" << positioner
65                << " anchor=" << anchor;
66 }
67 
zxdg_positioner_v6_set_gravity(wl_client *,wl_resource * positioner,uint32_t gravity)68 void zxdg_positioner_v6_set_gravity(wl_client*,
69                                     wl_resource* positioner,
70                                     uint32_t gravity) {
71   LOG(VERBOSE) << __FUNCTION__
72                << " positioner=" << positioner
73                << " gravity=" << gravity;
74 }
75 
zxdg_positioner_v6_set_constraint_adjustment(wl_client *,wl_resource * positioner,uint32_t adjustment)76 void zxdg_positioner_v6_set_constraint_adjustment(wl_client*,
77                                                   wl_resource* positioner,
78                                                   uint32_t adjustment) {
79   LOG(VERBOSE) << __FUNCTION__
80                << " positioner=" << positioner
81                << " adjustment=" << adjustment;
82 }
83 
zxdg_positioner_v6_set_offset(wl_client *,wl_resource * positioner,int32_t x,int32_t y)84 void zxdg_positioner_v6_set_offset(wl_client*,
85                                    wl_resource* positioner,
86                                    int32_t x,
87                                    int32_t y) {
88   LOG(VERBOSE) << __FUNCTION__
89                << " positioner=" << positioner
90                << " x=" << x
91                << " y=" << y;
92 }
93 
94 const struct zxdg_positioner_v6_interface
95     zxdg_positioner_v6_implementation = {
96         .destroy = zxdg_positioner_v6_destroy,
97         .set_size = zxdg_positioner_v6_set_size,
98         .set_anchor_rect = zxdg_positioner_v6_set_anchor_rect,
99         .set_anchor = zxdg_positioner_v6_set_anchor,
100         .set_gravity = zxdg_positioner_v6_set_gravity,
101         .set_constraint_adjustment = zxdg_positioner_v6_set_constraint_adjustment,
102         .set_offset = zxdg_positioner_v6_set_offset};
103 
zxdg_toplevel_v6_destroy(wl_client *,wl_resource * toplevel)104 void zxdg_toplevel_v6_destroy(wl_client*, wl_resource* toplevel) {
105   LOG(VERBOSE) << __FUNCTION__
106                << " toplevel=" << toplevel;
107 
108   wl_resource_destroy(toplevel);
109 }
110 
zxdg_toplevel_v6_set_parent(wl_client *,wl_resource * toplevel,wl_resource * parent_toplevel)111 void zxdg_toplevel_v6_set_parent(wl_client*,
112                                  wl_resource* toplevel,
113                                  wl_resource* parent_toplevel) {
114   LOG(VERBOSE) << __FUNCTION__
115                << " toplevel=" << toplevel
116                << " parent_toplevel=" << parent_toplevel;
117 }
118 
zxdg_toplevel_v6_set_title(wl_client *,wl_resource * toplevel,const char * title)119 void zxdg_toplevel_v6_set_title(wl_client*,
120                                 wl_resource* toplevel,
121                                 const char* title) {
122   LOG(VERBOSE) << __FUNCTION__
123                << " toplevel=" << toplevel
124                << " title=" << title;
125 }
126 
zxdg_toplevel_v6_set_app_id(wl_client *,wl_resource * toplevel,const char * app)127 void zxdg_toplevel_v6_set_app_id(wl_client*,
128                                  wl_resource* toplevel,
129                                  const char* app) {
130   LOG(VERBOSE) << __FUNCTION__
131                << " toplevel=" << toplevel
132                << " app=" << app;
133 }
134 
zxdg_toplevel_v6_show_window_menu(wl_client *,wl_resource * toplevel,wl_resource * seat,uint32_t serial,int32_t x,int32_t y)135 void zxdg_toplevel_v6_show_window_menu(wl_client*,
136                                        wl_resource* toplevel,
137                                        wl_resource* seat,
138                                        uint32_t serial,
139                                        int32_t x,
140                                        int32_t y) {
141   LOG(VERBOSE) << __FUNCTION__
142                << " toplevel=" << toplevel
143                << " seat=" << seat
144                << " serial=" << serial
145                << " x=" << x
146                << " y=" << y;
147 }
148 
zxdg_toplevel_v6_move(wl_client *,wl_resource * toplevel,wl_resource * seat,uint32_t serial)149 void zxdg_toplevel_v6_move(wl_client*,
150                            wl_resource* toplevel,
151                            wl_resource* seat,
152                            uint32_t serial) {
153   LOG(VERBOSE) << __FUNCTION__
154                << " toplevel=" << toplevel
155                << " seat=" << seat
156                << " serial=" << serial;
157 }
158 
zxdg_toplevel_v6_resize(wl_client *,wl_resource * toplevel,wl_resource * seat,uint32_t serial,uint32_t edges)159 void zxdg_toplevel_v6_resize(wl_client*,
160                              wl_resource* toplevel,
161                              wl_resource* seat,
162                              uint32_t serial,
163                              uint32_t edges) {
164   LOG(VERBOSE) << __FUNCTION__
165                << " toplevel=" << toplevel
166                << " seat=" << seat
167                << " serial=" << serial
168                << " edges=" << edges;
169 }
170 
zxdg_toplevel_v6_set_max_size(wl_client *,wl_resource * toplevel,int32_t w,int32_t h)171 void zxdg_toplevel_v6_set_max_size(wl_client*,
172                                    wl_resource* toplevel,
173                                    int32_t w,
174                                    int32_t h) {
175   LOG(VERBOSE) << __FUNCTION__
176                << " toplevel=" << toplevel
177                << " w=" << w
178                << " h=" << h;
179 }
180 
zxdg_toplevel_v6_set_min_size(wl_client *,wl_resource * toplevel,int32_t w,int32_t h)181 void zxdg_toplevel_v6_set_min_size(wl_client*,
182                                    wl_resource* toplevel,
183                                    int32_t w,
184                                    int32_t h) {
185   LOG(VERBOSE) << __FUNCTION__
186                << " toplevel=" << toplevel
187                << " w=" << w
188                << " h=" << h;
189 }
190 
zxdg_toplevel_v6_set_maximized(wl_client *,wl_resource * toplevel)191 void zxdg_toplevel_v6_set_maximized(wl_client*, wl_resource* toplevel) {
192   LOG(VERBOSE) << __FUNCTION__
193                << " toplevel=" << toplevel;
194 }
195 
zxdg_toplevel_v6_unset_maximized(wl_client *,wl_resource * toplevel)196 void zxdg_toplevel_v6_unset_maximized(wl_client*, wl_resource* toplevel) {
197   LOG(VERBOSE) << __FUNCTION__
198                << " toplevel=" << toplevel;
199 }
200 
zxdg_toplevel_v6_set_fullscreen(wl_client *,wl_resource * toplevel,wl_resource *)201 void zxdg_toplevel_v6_set_fullscreen(wl_client*,
202                                      wl_resource* toplevel,
203                                      wl_resource*) {
204   LOG(VERBOSE) << __FUNCTION__
205                << " toplevel=" << toplevel;
206 }
207 
zxdg_toplevel_v6_unset_fullscreen(wl_client *,wl_resource * toplevel)208 void zxdg_toplevel_v6_unset_fullscreen(wl_client*, wl_resource* toplevel) {
209   LOG(VERBOSE) << __FUNCTION__
210                << " toplevel=" << toplevel;
211 }
212 
zxdg_toplevel_v6_set_minimized(wl_client *,wl_resource * toplevel)213 void zxdg_toplevel_v6_set_minimized(wl_client*, wl_resource* toplevel) {
214   LOG(VERBOSE) << __FUNCTION__
215                << " toplevel=" << toplevel;
216 }
217 
218 const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation = {
219   .destroy = zxdg_toplevel_v6_destroy,
220   .set_parent = zxdg_toplevel_v6_set_parent,
221   .set_title = zxdg_toplevel_v6_set_title,
222   .set_app_id = zxdg_toplevel_v6_set_app_id,
223   .show_window_menu = zxdg_toplevel_v6_show_window_menu,
224   .move = zxdg_toplevel_v6_move,
225   .resize = zxdg_toplevel_v6_resize,
226   .set_max_size = zxdg_toplevel_v6_set_max_size,
227   .set_min_size = zxdg_toplevel_v6_set_min_size,
228   .set_maximized = zxdg_toplevel_v6_set_maximized,
229   .unset_maximized = zxdg_toplevel_v6_unset_maximized,
230   .set_fullscreen = zxdg_toplevel_v6_set_fullscreen,
231   .unset_fullscreen = zxdg_toplevel_v6_unset_fullscreen,
232   .set_minimized = zxdg_toplevel_v6_set_minimized
233 };
234 
zxdg_popup_v6_destroy(wl_client *,wl_resource * popup)235 void zxdg_popup_v6_destroy(wl_client*, wl_resource* popup) {
236   LOG(VERBOSE) << __FUNCTION__
237                << " popup=" << popup;
238 
239   wl_resource_destroy(popup);
240 }
241 
zxdg_popup_v6_grab(wl_client *,wl_resource * popup,wl_resource * seat,uint32_t serial)242 void zxdg_popup_v6_grab(wl_client*,
243                         wl_resource* popup,
244                         wl_resource* seat,
245                         uint32_t serial) {
246   LOG(VERBOSE) << __FUNCTION__
247                << " popup=" << popup
248                << " seat=" << seat
249                << " serial=" << serial;
250 }
251 
252 const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation = {
253     .destroy = zxdg_popup_v6_destroy,
254     .grab = zxdg_popup_v6_grab
255 };
256 
zxdg_surface_v6_destroy(wl_client *,wl_resource * surface)257 void zxdg_surface_v6_destroy(wl_client*, wl_resource* surface) {
258   LOG(VERBOSE) << __FUNCTION__
259                << " surface=" << surface;
260 
261   wl_resource_destroy(surface);
262 }
263 
toplevel_destroy_resource_callback(struct wl_resource *)264 void toplevel_destroy_resource_callback(struct wl_resource*) {}
265 
zxdg_surface_v6_get_toplevel(wl_client * client,wl_resource * surface,uint32_t id)266 void zxdg_surface_v6_get_toplevel(wl_client* client,
267                                   wl_resource* surface,
268                                   uint32_t id) {
269   LOG(VERBOSE) << __FUNCTION__
270                << " surface=" << surface
271                << " id=" << id;
272 
273   wl_resource* xdg_toplevel_resource =
274       wl_resource_create(client, &zxdg_toplevel_v6_interface, 1, id);
275 
276   wl_resource_set_implementation(xdg_toplevel_resource,
277                                  &zxdg_toplevel_v6_implementation, nullptr,
278                                  toplevel_destroy_resource_callback);
279 }
280 
popup_destroy_resource_callback(struct wl_resource *)281 void popup_destroy_resource_callback(struct wl_resource*) {}
282 
zxdg_surface_v6_get_popup(wl_client * client,wl_resource * surface,uint32_t id,wl_resource * parent_surface,wl_resource * positioner)283 void zxdg_surface_v6_get_popup(wl_client* client,
284                               wl_resource* surface,
285                               uint32_t id,
286                               wl_resource* parent_surface,
287                               wl_resource* positioner) {
288   LOG(VERBOSE) << __FUNCTION__
289                << " surface=" << surface
290                << " id=" << id
291                << " parent_surface=" << parent_surface
292                << " positioner=" << positioner;
293 
294   wl_resource* xdg_popup_resource =
295       wl_resource_create(client, &zxdg_popup_v6_interface, 1, id);
296 
297   wl_resource_set_implementation(xdg_popup_resource,
298                                  &zxdg_popup_v6_implementation, nullptr,
299                                  popup_destroy_resource_callback);
300 }
301 
zxdg_surface_v6_set_window_geometry(wl_client *,wl_resource * surface,int32_t x,int32_t y,int32_t w,int32_t h)302 void zxdg_surface_v6_set_window_geometry(wl_client*,
303                                          wl_resource* surface,
304                                          int32_t x,
305                                          int32_t y,
306                                          int32_t w,
307                                          int32_t h) {
308   LOG(VERBOSE) << __FUNCTION__
309                << " surface=" << surface
310                << " x=" << x
311                << " y=" << y
312                << " w=" << w
313                << " h=" << h;
314 }
315 
zxdg_surface_v6_ack_configure(wl_client *,wl_resource * surface,uint32_t serial)316 void zxdg_surface_v6_ack_configure(wl_client*,
317                                    wl_resource* surface,
318                                    uint32_t serial) {
319   LOG(VERBOSE) << __FUNCTION__
320                << " surface=" << surface
321                << " serial=" << serial;
322 }
323 
324 const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = {
325     .destroy = zxdg_surface_v6_destroy,
326     .get_toplevel = zxdg_surface_v6_get_toplevel,
327     .get_popup = zxdg_surface_v6_get_popup,
328     .set_window_geometry = zxdg_surface_v6_set_window_geometry,
329     .ack_configure = zxdg_surface_v6_ack_configure
330 };
331 
zxdg_shell_v6_destroy(wl_client *,wl_resource * shell)332 void zxdg_shell_v6_destroy(wl_client*, wl_resource* shell) {
333   LOG(VERBOSE) << __FUNCTION__
334                << " shell=" << shell;
335 
336   wl_resource_destroy(shell);
337 }
338 
positioner_destroy_resource_callback(struct wl_resource *)339 void positioner_destroy_resource_callback(struct wl_resource*) {}
340 
zxdg_shell_v6_create_positioner(wl_client * client,wl_resource * shell,uint32_t id)341 void zxdg_shell_v6_create_positioner(wl_client* client,
342                                      wl_resource* shell,
343                                      uint32_t id) {
344   LOG(VERBOSE) << __FUNCTION__
345                << " shell=" << shell
346                << " id=" << id;
347 
348   wl_resource* positioner_resource =
349       wl_resource_create(client, &zxdg_positioner_v6_interface, 1, id);
350 
351   wl_resource_set_implementation(positioner_resource,
352                                  &zxdg_positioner_v6_implementation, nullptr,
353                                  positioner_destroy_resource_callback);
354 }
355 
surface_destroy_resource_callback(struct wl_resource *)356 void surface_destroy_resource_callback(struct wl_resource*) {}
357 
zxdg_shell_v6_get_xdg_surface(wl_client * client,wl_resource * shell,uint32_t id,wl_resource * surface)358 void zxdg_shell_v6_get_xdg_surface(wl_client* client,
359                                    wl_resource* shell,
360                                    uint32_t id,
361                                    wl_resource* surface) {
362   LOG(VERBOSE) << __FUNCTION__
363                << " shell=" << shell
364                << " id=" << id
365                << " surface=" << surface;
366 
367   wl_resource* surface_resource =
368       wl_resource_create(client, &zxdg_surface_v6_interface, 1, id);
369 
370   wl_resource_set_implementation(surface_resource,
371                                  &zxdg_surface_v6_implementation, nullptr,
372                                  surface_destroy_resource_callback);
373 }
374 
zxdg_shell_v6_pong(wl_client *,wl_resource * shell,uint32_t serial)375 void zxdg_shell_v6_pong(wl_client*, wl_resource* shell, uint32_t serial) {
376   LOG(VERBOSE) << __FUNCTION__
377                << " shell=" << shell
378                << " serial=" << serial;
379 }
380 
381 const struct zxdg_shell_v6_interface zxdg_shell_v6_implementation = {
382     .destroy = zxdg_shell_v6_destroy,
383     .create_positioner = zxdg_shell_v6_create_positioner,
384     .get_xdg_surface = zxdg_shell_v6_get_xdg_surface,
385     .pong = zxdg_shell_v6_pong
386 };
387 
bind_shell(wl_client * client,void * data,uint32_t version,uint32_t id)388 void bind_shell(wl_client* client, void* data, uint32_t version, uint32_t id) {
389   wl_resource* shell_resource =
390       wl_resource_create(client, &zxdg_shell_v6_interface, version, id);
391 
392   wl_resource_set_implementation(shell_resource,
393                                  &zxdg_shell_v6_implementation, data, nullptr);
394 }
395 
396 }  // namespace
397 
BindShellInterface(wl_display * display)398 void BindShellInterface(wl_display* display) {
399   wl_global_create(display, &zxdg_shell_v6_interface, 1, nullptr, bind_shell);
400 }
401 
402 }  // namespace wayland