Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010-2012 Intel Corporation |
| 3 | * Copyright © 2011-2012 Collabora, Ltd. |
| 4 | * Copyright © 2013 Raspberry Pi Foundation |
| 5 | * Copyright © 2016 Quentin "Sardem FF7" Glidic |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the next |
| 15 | * paragraph) shall be included in all copies or substantial portions of the |
| 16 | * Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 | * DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #include "config.h" |
| 28 | |
| 29 | #include <stdbool.h> |
| 30 | |
| 31 | #include <wayland-server.h> |
| 32 | |
| 33 | #include "compositor.h" |
| 34 | #include "zalloc.h" |
Daniel Stone | 7dbb0e1 | 2016-11-24 15:30:41 +0000 | [diff] [blame] | 35 | #include "xdg-shell-unstable-v5-server-protocol.h" |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 36 | |
| 37 | #include "libweston-desktop.h" |
| 38 | #include "internal.h" |
| 39 | |
| 40 | #define WD_XDG_SHELL_PROTOCOL_VERSION 1 |
| 41 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 42 | struct weston_desktop_xdg_surface_state { |
| 43 | bool maximized; |
| 44 | bool fullscreen; |
| 45 | bool resizing; |
| 46 | bool activated; |
| 47 | }; |
| 48 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 49 | struct weston_desktop_xdg_surface { |
| 50 | struct wl_resource *resource; |
| 51 | struct weston_desktop_surface *surface; |
| 52 | struct weston_desktop *desktop; |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 53 | bool added; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 54 | struct wl_event_source *add_idle; |
| 55 | struct wl_event_source *configure_idle; |
| 56 | uint32_t configure_serial; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 57 | struct { |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 58 | struct weston_desktop_xdg_surface_state state; |
| 59 | struct weston_size size; |
| 60 | } pending; |
| 61 | struct { |
| 62 | struct weston_desktop_xdg_surface_state state; |
Quentin Glidic | ac394a1 | 2017-07-12 09:45:43 +0200 | [diff] [blame^] | 63 | struct weston_size size; |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 64 | } next; |
| 65 | struct { |
| 66 | struct weston_desktop_xdg_surface_state state; |
| 67 | } current; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 68 | bool has_next_geometry; |
| 69 | struct weston_geometry next_geometry; |
| 70 | }; |
| 71 | |
| 72 | struct weston_desktop_xdg_popup { |
| 73 | struct wl_resource *resource; |
| 74 | struct weston_desktop_surface *popup; |
| 75 | struct weston_desktop *desktop; |
| 76 | struct weston_desktop_seat *seat; |
| 77 | struct wl_display *display; |
| 78 | }; |
| 79 | |
| 80 | static void |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 81 | weston_desktop_xdg_surface_ensure_added(struct weston_desktop_xdg_surface *surface) |
| 82 | { |
| 83 | if (surface->added) |
| 84 | return; |
| 85 | |
| 86 | if (surface->add_idle != NULL) |
| 87 | wl_event_source_remove(surface->add_idle); |
| 88 | surface->add_idle = NULL; |
| 89 | weston_desktop_api_surface_added(surface->desktop, surface->surface); |
| 90 | surface->added = true; |
| 91 | } |
| 92 | |
| 93 | static void |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 94 | weston_desktop_xdg_surface_send_configure(void *data) |
| 95 | { |
| 96 | struct weston_desktop_xdg_surface *surface = data; |
| 97 | uint32_t *s; |
| 98 | struct wl_array states; |
| 99 | |
| 100 | surface->configure_idle = NULL; |
| 101 | |
| 102 | surface->configure_serial = |
| 103 | wl_display_next_serial(weston_desktop_get_display(surface->desktop)); |
| 104 | |
| 105 | wl_array_init(&states); |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 106 | if (surface->pending.state.maximized) { |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 107 | s = wl_array_add(&states, sizeof(uint32_t)); |
| 108 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 109 | } |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 110 | if (surface->pending.state.fullscreen) { |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 111 | s = wl_array_add(&states, sizeof(uint32_t)); |
| 112 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 113 | } |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 114 | if (surface->pending.state.resizing) { |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 115 | s = wl_array_add(&states, sizeof(uint32_t)); |
| 116 | *s = XDG_SURFACE_STATE_RESIZING; |
| 117 | } |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 118 | if (surface->pending.state.activated) { |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 119 | s = wl_array_add(&states, sizeof(uint32_t)); |
| 120 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 121 | } |
| 122 | |
| 123 | xdg_surface_send_configure(surface->resource, |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 124 | surface->pending.size.width, |
| 125 | surface->pending.size.height, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 126 | &states, |
| 127 | surface->configure_serial); |
| 128 | |
| 129 | wl_array_release(&states); |
| 130 | }; |
| 131 | |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 132 | static bool |
| 133 | weston_desktop_xdg_surface_state_compare(struct weston_desktop_xdg_surface *surface) |
| 134 | { |
| 135 | struct weston_surface *wsurface = |
| 136 | weston_desktop_surface_get_surface(surface->surface); |
| 137 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 138 | if (surface->pending.state.activated != surface->current.state.activated) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 139 | return false; |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 140 | if (surface->pending.state.fullscreen != surface->current.state.fullscreen) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 141 | return false; |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 142 | if (surface->pending.state.maximized != surface->current.state.maximized) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 143 | return false; |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 144 | if (surface->pending.state.resizing != surface->current.state.resizing) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 145 | return false; |
| 146 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 147 | if (wsurface->width == surface->pending.size.width && |
| 148 | wsurface->height == surface->pending.size.height) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 149 | return true; |
| 150 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 151 | if (surface->pending.size.width == 0 && |
| 152 | surface->pending.size.height == 0) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 153 | return true; |
| 154 | |
| 155 | return false; |
| 156 | } |
| 157 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 158 | static void |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 159 | weston_desktop_xdg_surface_schedule_configure(struct weston_desktop_xdg_surface *surface, |
| 160 | bool force) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 161 | { |
| 162 | struct wl_display *display = weston_desktop_get_display(surface->desktop); |
| 163 | struct wl_event_loop *loop = wl_display_get_event_loop(display); |
Quentin Glidic | 218126d | 2017-07-11 13:31:36 +0200 | [diff] [blame] | 164 | bool pending_same = |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 165 | !force && weston_desktop_xdg_surface_state_compare(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 166 | |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 167 | if (surface->configure_idle != NULL) { |
Quentin Glidic | 218126d | 2017-07-11 13:31:36 +0200 | [diff] [blame] | 168 | if (!pending_same) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 169 | return; |
| 170 | |
| 171 | wl_event_source_remove(surface->configure_idle); |
| 172 | surface->configure_idle = NULL; |
| 173 | } else { |
Quentin Glidic | 218126d | 2017-07-11 13:31:36 +0200 | [diff] [blame] | 174 | if (pending_same) |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 175 | return; |
| 176 | |
| 177 | surface->configure_idle = |
| 178 | wl_event_loop_add_idle(loop, |
| 179 | weston_desktop_xdg_surface_send_configure, |
| 180 | surface); |
| 181 | } |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static void |
| 185 | weston_desktop_xdg_surface_set_maximized(struct weston_desktop_surface *dsurface, |
| 186 | void *user_data, bool maximized) |
| 187 | { |
| 188 | struct weston_desktop_xdg_surface *surface = user_data; |
| 189 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 190 | surface->pending.state.maximized = maximized; |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 191 | weston_desktop_xdg_surface_schedule_configure(surface, false); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static void |
| 195 | weston_desktop_xdg_surface_set_fullscreen(struct weston_desktop_surface *dsurface, |
| 196 | void *user_data, bool fullscreen) |
| 197 | { |
| 198 | struct weston_desktop_xdg_surface *surface = user_data; |
| 199 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 200 | surface->pending.state.fullscreen = fullscreen; |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 201 | weston_desktop_xdg_surface_schedule_configure(surface, false); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static void |
| 205 | weston_desktop_xdg_surface_set_resizing(struct weston_desktop_surface *dsurface, |
| 206 | void *user_data, bool resizing) |
| 207 | { |
| 208 | struct weston_desktop_xdg_surface *surface = user_data; |
| 209 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 210 | surface->pending.state.resizing = resizing; |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 211 | weston_desktop_xdg_surface_schedule_configure(surface, false); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static void |
| 215 | weston_desktop_xdg_surface_set_activated(struct weston_desktop_surface *dsurface, |
| 216 | void *user_data, bool activated) |
| 217 | { |
| 218 | struct weston_desktop_xdg_surface *surface = user_data; |
| 219 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 220 | surface->pending.state.activated = activated; |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 221 | weston_desktop_xdg_surface_schedule_configure(surface, false); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static void |
| 225 | weston_desktop_xdg_surface_set_size(struct weston_desktop_surface *dsurface, |
| 226 | void *user_data, |
| 227 | int32_t width, int32_t height) |
| 228 | { |
| 229 | struct weston_desktop_xdg_surface *surface = user_data; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 230 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 231 | surface->pending.size.width = width; |
| 232 | surface->pending.size.height = height; |
Quentin Glidic | a56b053 | 2016-09-13 10:05:58 +0200 | [diff] [blame] | 233 | |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 234 | weston_desktop_xdg_surface_schedule_configure(surface, false); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static void |
| 238 | weston_desktop_xdg_surface_committed(struct weston_desktop_surface *dsurface, |
Quentin Glidic | 003da88 | 2016-08-15 12:21:39 +0200 | [diff] [blame] | 239 | void *user_data, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 240 | int32_t sx, int32_t sy) |
| 241 | { |
| 242 | struct weston_desktop_xdg_surface *surface = user_data; |
| 243 | struct weston_surface *wsurface = |
| 244 | weston_desktop_surface_get_surface(surface->surface); |
| 245 | bool reconfigure = false; |
| 246 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 247 | if (surface->next.state.maximized || surface->next.state.fullscreen) |
Quentin Glidic | ac394a1 | 2017-07-12 09:45:43 +0200 | [diff] [blame^] | 248 | reconfigure = surface->next.size.width != wsurface->width || |
| 249 | surface->next.size.height != wsurface->height; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 250 | |
| 251 | if (reconfigure) { |
Quentin Glidic | d51f826 | 2017-04-13 20:25:27 +0200 | [diff] [blame] | 252 | weston_desktop_xdg_surface_schedule_configure(surface, true); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 253 | } else { |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 254 | surface->current.state = surface->next.state; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 255 | if (surface->has_next_geometry) { |
| 256 | surface->has_next_geometry = false; |
| 257 | weston_desktop_surface_set_geometry(surface->surface, |
| 258 | surface->next_geometry); |
| 259 | } |
| 260 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 261 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 262 | weston_desktop_api_committed(surface->desktop, surface->surface, |
| 263 | sx, sy); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | static void |
| 268 | weston_desktop_xdg_surface_ping(struct weston_desktop_surface *dsurface, |
| 269 | uint32_t serial, void *user_data) |
| 270 | { |
| 271 | struct weston_desktop_client *client = |
| 272 | weston_desktop_surface_get_client(dsurface); |
| 273 | |
| 274 | xdg_shell_send_ping(weston_desktop_client_get_resource(client), |
| 275 | serial); |
| 276 | } |
| 277 | |
| 278 | static void |
| 279 | weston_desktop_xdg_surface_close(struct weston_desktop_surface *dsurface, |
| 280 | void *user_data) |
| 281 | { |
| 282 | struct weston_desktop_xdg_surface *surface = user_data; |
| 283 | |
| 284 | xdg_surface_send_close(surface->resource); |
| 285 | } |
| 286 | |
| 287 | static bool |
| 288 | weston_desktop_xdg_surface_get_maximized(struct weston_desktop_surface *dsurface, |
| 289 | void *user_data) |
| 290 | { |
| 291 | struct weston_desktop_xdg_surface *surface = user_data; |
| 292 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 293 | return surface->current.state.maximized; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static bool |
| 297 | weston_desktop_xdg_surface_get_fullscreen(struct weston_desktop_surface *dsurface, |
| 298 | void *user_data) |
| 299 | { |
| 300 | struct weston_desktop_xdg_surface *surface = user_data; |
| 301 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 302 | return surface->current.state.fullscreen; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | static bool |
| 306 | weston_desktop_xdg_surface_get_resizing(struct weston_desktop_surface *dsurface, |
| 307 | void *user_data) |
| 308 | { |
| 309 | struct weston_desktop_xdg_surface *surface = user_data; |
| 310 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 311 | return surface->current.state.resizing; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static bool |
| 315 | weston_desktop_xdg_surface_get_activated(struct weston_desktop_surface *dsurface, |
| 316 | void *user_data) |
| 317 | { |
| 318 | struct weston_desktop_xdg_surface *surface = user_data; |
| 319 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 320 | return surface->current.state.activated; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static void |
| 324 | weston_desktop_xdg_surface_destroy(struct weston_desktop_surface *dsurface, |
| 325 | void *user_data) |
| 326 | { |
| 327 | struct weston_desktop_xdg_surface *surface = user_data; |
| 328 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 329 | if (surface->added) |
| 330 | weston_desktop_api_surface_removed(surface->desktop, |
| 331 | surface->surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 332 | |
| 333 | if (surface->add_idle != NULL) |
| 334 | wl_event_source_remove(surface->add_idle); |
| 335 | |
| 336 | if (surface->configure_idle != NULL) |
| 337 | wl_event_source_remove(surface->configure_idle); |
| 338 | |
| 339 | free(surface); |
| 340 | } |
| 341 | |
| 342 | static void |
| 343 | weston_desktop_xdg_surface_protocol_set_parent(struct wl_client *wl_client, |
| 344 | struct wl_resource *resource, |
| 345 | struct wl_resource *parent_resource) |
| 346 | { |
| 347 | struct weston_desktop_surface *dsurface = |
| 348 | wl_resource_get_user_data(resource); |
| 349 | struct weston_desktop_xdg_surface *surface = |
| 350 | weston_desktop_surface_get_implementation_data(dsurface); |
| 351 | struct weston_desktop_surface *parent = NULL; |
| 352 | |
| 353 | if (parent_resource != NULL) |
| 354 | parent = wl_resource_get_user_data(parent_resource); |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 355 | |
| 356 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 357 | weston_desktop_api_set_parent(surface->desktop, dsurface, parent); |
| 358 | } |
| 359 | |
| 360 | static void |
| 361 | weston_desktop_xdg_surface_protocol_set_title(struct wl_client *wl_client, |
| 362 | struct wl_resource *resource, |
| 363 | const char *title) |
| 364 | { |
| 365 | struct weston_desktop_surface *surface = |
| 366 | wl_resource_get_user_data(resource); |
| 367 | |
| 368 | weston_desktop_surface_set_title(surface, title); |
| 369 | } |
| 370 | |
| 371 | static void |
| 372 | weston_desktop_xdg_surface_protocol_set_app_id(struct wl_client *wl_client, |
| 373 | struct wl_resource *resource, |
| 374 | const char *app_id) |
| 375 | { |
| 376 | struct weston_desktop_surface *surface = |
| 377 | wl_resource_get_user_data(resource); |
| 378 | |
| 379 | weston_desktop_surface_set_app_id(surface, app_id); |
| 380 | } |
| 381 | |
| 382 | static void |
| 383 | weston_desktop_xdg_surface_protocol_show_window_menu(struct wl_client *wl_client, |
| 384 | struct wl_resource *resource, |
| 385 | struct wl_resource *seat_resource, |
| 386 | uint32_t serial, |
| 387 | int32_t x, int32_t y) |
| 388 | { |
| 389 | struct weston_desktop_surface *dsurface = |
| 390 | wl_resource_get_user_data(resource); |
| 391 | struct weston_seat *seat = |
| 392 | wl_resource_get_user_data(seat_resource); |
| 393 | struct weston_desktop_xdg_surface *surface = |
| 394 | weston_desktop_surface_get_implementation_data(dsurface); |
| 395 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 396 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 397 | weston_desktop_api_show_window_menu(surface->desktop, dsurface, seat, x, y); |
| 398 | } |
| 399 | |
| 400 | static void |
| 401 | weston_desktop_xdg_surface_protocol_move(struct wl_client *wl_client, |
| 402 | struct wl_resource *resource, |
| 403 | struct wl_resource *seat_resource, |
| 404 | uint32_t serial) |
| 405 | { |
| 406 | struct weston_desktop_surface *dsurface = |
| 407 | wl_resource_get_user_data(resource); |
| 408 | struct weston_seat *seat = |
| 409 | wl_resource_get_user_data(seat_resource); |
| 410 | struct weston_desktop_xdg_surface *surface = |
| 411 | weston_desktop_surface_get_implementation_data(dsurface); |
| 412 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 413 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 414 | weston_desktop_api_move(surface->desktop, dsurface, seat, serial); |
| 415 | } |
| 416 | |
| 417 | static void |
| 418 | weston_desktop_xdg_surface_protocol_resize(struct wl_client *wl_client, |
| 419 | struct wl_resource *resource, |
| 420 | struct wl_resource *seat_resource, |
| 421 | uint32_t serial, |
| 422 | enum xdg_surface_resize_edge edges) |
| 423 | { |
| 424 | struct weston_desktop_surface *dsurface = |
| 425 | wl_resource_get_user_data(resource); |
| 426 | struct weston_seat *seat = |
| 427 | wl_resource_get_user_data(seat_resource); |
| 428 | struct weston_desktop_xdg_surface *surface = |
| 429 | weston_desktop_surface_get_implementation_data(dsurface); |
Armin Krezović | 4e2fa0a | 2016-09-10 19:11:21 +0200 | [diff] [blame] | 430 | enum weston_desktop_surface_edge surf_edges = |
| 431 | (enum weston_desktop_surface_edge) edges; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 432 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 433 | weston_desktop_xdg_surface_ensure_added(surface); |
Armin Krezović | 4e2fa0a | 2016-09-10 19:11:21 +0200 | [diff] [blame] | 434 | weston_desktop_api_resize(surface->desktop, dsurface, seat, serial, surf_edges); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | static void |
| 438 | weston_desktop_xdg_surface_protocol_ack_configure(struct wl_client *wl_client, |
| 439 | struct wl_resource *resource, |
| 440 | uint32_t serial) |
| 441 | { |
| 442 | struct weston_desktop_surface *dsurface = |
| 443 | wl_resource_get_user_data(resource); |
| 444 | struct weston_desktop_xdg_surface *surface = |
| 445 | weston_desktop_surface_get_implementation_data(dsurface); |
| 446 | |
| 447 | if (surface->configure_serial != serial) |
| 448 | return; |
| 449 | |
Quentin Glidic | 19d1f6e | 2017-07-12 09:42:57 +0200 | [diff] [blame] | 450 | surface->next.state = surface->pending.state; |
Quentin Glidic | ac394a1 | 2017-07-12 09:45:43 +0200 | [diff] [blame^] | 451 | surface->next.size = surface->pending.size; |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static void |
| 455 | weston_desktop_xdg_surface_protocol_set_window_geometry(struct wl_client *wl_client, |
| 456 | struct wl_resource *resource, |
| 457 | int32_t x, int32_t y, |
| 458 | int32_t width, int32_t height) |
| 459 | { |
| 460 | struct weston_desktop_surface *dsurface = |
| 461 | wl_resource_get_user_data(resource); |
| 462 | struct weston_desktop_xdg_surface *surface = |
| 463 | weston_desktop_surface_get_implementation_data(dsurface); |
| 464 | |
| 465 | surface->has_next_geometry = true; |
| 466 | surface->next_geometry.x = x; |
| 467 | surface->next_geometry.y = y; |
| 468 | surface->next_geometry.width = width; |
| 469 | surface->next_geometry.height = height; |
| 470 | } |
| 471 | |
| 472 | static void |
| 473 | weston_desktop_xdg_surface_protocol_set_maximized(struct wl_client *wl_client, |
| 474 | struct wl_resource *resource) |
| 475 | { |
| 476 | struct weston_desktop_surface *dsurface = |
| 477 | wl_resource_get_user_data(resource); |
| 478 | struct weston_desktop_xdg_surface *surface = |
| 479 | weston_desktop_surface_get_implementation_data(dsurface); |
| 480 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 481 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 482 | weston_desktop_api_maximized_requested(surface->desktop, dsurface, true); |
| 483 | } |
| 484 | |
| 485 | static void |
| 486 | weston_desktop_xdg_surface_protocol_unset_maximized(struct wl_client *wl_client, |
| 487 | struct wl_resource *resource) |
| 488 | { |
| 489 | struct weston_desktop_surface *dsurface = |
| 490 | wl_resource_get_user_data(resource); |
| 491 | struct weston_desktop_xdg_surface *surface = |
| 492 | weston_desktop_surface_get_implementation_data(dsurface); |
| 493 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 494 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 495 | weston_desktop_api_maximized_requested(surface->desktop, dsurface, false); |
| 496 | } |
| 497 | |
| 498 | static void |
| 499 | weston_desktop_xdg_surface_protocol_set_fullscreen(struct wl_client *wl_client, |
| 500 | struct wl_resource *resource, |
| 501 | struct wl_resource *output_resource) |
| 502 | { |
| 503 | struct weston_desktop_surface *dsurface = |
| 504 | wl_resource_get_user_data(resource); |
| 505 | struct weston_desktop_xdg_surface *surface = |
| 506 | weston_desktop_surface_get_implementation_data(dsurface); |
| 507 | struct weston_output *output = NULL; |
| 508 | |
| 509 | if (output_resource != NULL) |
| 510 | output = wl_resource_get_user_data(output_resource); |
| 511 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 512 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 513 | weston_desktop_api_fullscreen_requested(surface->desktop, dsurface, |
| 514 | true, output); |
| 515 | } |
| 516 | |
| 517 | static void |
| 518 | weston_desktop_xdg_surface_protocol_unset_fullscreen(struct wl_client *wl_client, |
| 519 | struct wl_resource *resource) |
| 520 | { |
| 521 | struct weston_desktop_surface *dsurface = |
| 522 | wl_resource_get_user_data(resource); |
| 523 | struct weston_desktop_xdg_surface *surface = |
| 524 | weston_desktop_surface_get_implementation_data(dsurface); |
| 525 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 526 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 527 | weston_desktop_api_fullscreen_requested(surface->desktop, dsurface, |
| 528 | false, NULL); |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | weston_desktop_xdg_surface_protocol_set_minimized(struct wl_client *wl_client, |
| 533 | struct wl_resource *resource) |
| 534 | { |
| 535 | struct weston_desktop_surface *dsurface = |
| 536 | wl_resource_get_user_data(resource); |
| 537 | struct weston_desktop_xdg_surface *surface = |
| 538 | weston_desktop_surface_get_implementation_data(dsurface); |
| 539 | |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 540 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 541 | weston_desktop_api_minimized_requested(surface->desktop, dsurface); |
| 542 | } |
| 543 | |
| 544 | static const struct xdg_surface_interface weston_desktop_xdg_surface_implementation = { |
| 545 | .destroy = weston_desktop_destroy_request, |
| 546 | .set_parent = weston_desktop_xdg_surface_protocol_set_parent, |
| 547 | .set_title = weston_desktop_xdg_surface_protocol_set_title, |
| 548 | .set_app_id = weston_desktop_xdg_surface_protocol_set_app_id, |
| 549 | .show_window_menu = weston_desktop_xdg_surface_protocol_show_window_menu, |
| 550 | .move = weston_desktop_xdg_surface_protocol_move, |
| 551 | .resize = weston_desktop_xdg_surface_protocol_resize, |
| 552 | .ack_configure = weston_desktop_xdg_surface_protocol_ack_configure, |
| 553 | .set_window_geometry = weston_desktop_xdg_surface_protocol_set_window_geometry, |
| 554 | .set_maximized = weston_desktop_xdg_surface_protocol_set_maximized, |
| 555 | .unset_maximized = weston_desktop_xdg_surface_protocol_unset_maximized, |
| 556 | .set_fullscreen = weston_desktop_xdg_surface_protocol_set_fullscreen, |
| 557 | .unset_fullscreen = weston_desktop_xdg_surface_protocol_unset_fullscreen, |
| 558 | .set_minimized = weston_desktop_xdg_surface_protocol_set_minimized, |
| 559 | }; |
| 560 | |
| 561 | static const struct weston_desktop_surface_implementation weston_desktop_xdg_surface_internal_implementation = { |
| 562 | .set_maximized = weston_desktop_xdg_surface_set_maximized, |
| 563 | .set_fullscreen = weston_desktop_xdg_surface_set_fullscreen, |
| 564 | .set_resizing = weston_desktop_xdg_surface_set_resizing, |
| 565 | .set_activated = weston_desktop_xdg_surface_set_activated, |
| 566 | .set_size = weston_desktop_xdg_surface_set_size, |
| 567 | .committed = weston_desktop_xdg_surface_committed, |
| 568 | .ping = weston_desktop_xdg_surface_ping, |
| 569 | .close = weston_desktop_xdg_surface_close, |
| 570 | |
| 571 | .get_maximized = weston_desktop_xdg_surface_get_maximized, |
| 572 | .get_fullscreen = weston_desktop_xdg_surface_get_fullscreen, |
| 573 | .get_resizing = weston_desktop_xdg_surface_get_resizing, |
| 574 | .get_activated = weston_desktop_xdg_surface_get_activated, |
| 575 | |
| 576 | .destroy = weston_desktop_xdg_surface_destroy, |
| 577 | }; |
| 578 | |
| 579 | static void |
| 580 | weston_desktop_xdg_popup_close(struct weston_desktop_surface *dsurface, |
| 581 | void *user_data) |
| 582 | { |
| 583 | struct weston_desktop_xdg_popup *popup = user_data; |
| 584 | |
| 585 | xdg_popup_send_popup_done(popup->resource); |
| 586 | } |
| 587 | |
| 588 | static void |
| 589 | weston_desktop_xdg_popup_destroy(struct weston_desktop_surface *dsurface, |
| 590 | void *user_data) |
| 591 | { |
| 592 | struct weston_desktop_xdg_popup *popup = user_data; |
| 593 | struct weston_desktop_surface *topmost; |
| 594 | struct weston_desktop_client *client = |
| 595 | weston_desktop_surface_get_client(popup->popup); |
| 596 | |
| 597 | if (!weston_desktop_surface_get_grab(popup->popup)) |
| 598 | goto end; |
| 599 | |
| 600 | topmost = weston_desktop_seat_popup_grab_get_topmost_surface(popup->seat); |
| 601 | if (topmost != popup->popup) { |
| 602 | struct wl_resource *client_resource = |
| 603 | weston_desktop_client_get_resource(client); |
| 604 | |
| 605 | wl_resource_post_error(client_resource, |
| 606 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
| 607 | "xdg_popup was destroyed while it was not the topmost popup."); |
| 608 | } |
| 609 | |
| 610 | weston_desktop_surface_popup_ungrab(popup->popup, popup->seat); |
| 611 | |
| 612 | end: |
| 613 | free(popup); |
| 614 | } |
| 615 | |
| 616 | static const struct xdg_popup_interface weston_desktop_xdg_popup_implementation = { |
| 617 | .destroy = weston_desktop_destroy_request, |
| 618 | }; |
| 619 | |
| 620 | static const struct weston_desktop_surface_implementation weston_desktop_xdg_popup_internal_implementation = { |
| 621 | .close = weston_desktop_xdg_popup_close, |
| 622 | |
| 623 | .destroy = weston_desktop_xdg_popup_destroy, |
| 624 | }; |
| 625 | |
| 626 | static void |
| 627 | weston_desktop_xdg_shell_protocol_use_unstable_version(struct wl_client *wl_client, |
| 628 | struct wl_resource *resource, |
| 629 | int32_t version) |
| 630 | { |
| 631 | if (version > 1) { |
| 632 | wl_resource_post_error(resource, |
| 633 | 1, "xdg_shell version not supported"); |
| 634 | return; |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | static void |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 639 | weston_desktop_xdg_surface_add_idle_callback(void *user_data) |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 640 | { |
| 641 | struct weston_desktop_xdg_surface *surface = user_data; |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 642 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 643 | surface->add_idle = NULL; |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 644 | weston_desktop_xdg_surface_ensure_added(surface); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static void |
| 648 | weston_desktop_xdg_shell_protocol_get_xdg_surface(struct wl_client *wl_client, |
| 649 | struct wl_resource *resource, |
| 650 | uint32_t id, |
| 651 | struct wl_resource *surface_resource) |
| 652 | { |
| 653 | struct weston_desktop_client *client = |
| 654 | wl_resource_get_user_data(resource); |
| 655 | struct weston_desktop *desktop = |
| 656 | weston_desktop_client_get_desktop(client); |
| 657 | struct weston_surface *wsurface = |
| 658 | wl_resource_get_user_data(surface_resource); |
| 659 | struct weston_desktop_xdg_surface *surface; |
| 660 | struct wl_display *display = weston_desktop_get_display(desktop); |
| 661 | struct wl_event_loop *loop = wl_display_get_event_loop(display); |
| 662 | |
| 663 | if (weston_surface_set_role(wsurface, "xdg_surface", resource, XDG_SHELL_ERROR_ROLE) < 0) |
| 664 | return; |
| 665 | |
| 666 | surface = zalloc(sizeof(struct weston_desktop_xdg_surface)); |
| 667 | if (surface == NULL) { |
| 668 | wl_client_post_no_memory(wl_client); |
| 669 | return; |
| 670 | } |
| 671 | |
| 672 | surface->desktop = desktop; |
| 673 | |
| 674 | surface->surface = |
| 675 | weston_desktop_surface_create(surface->desktop, client, |
| 676 | wsurface, |
| 677 | &weston_desktop_xdg_surface_internal_implementation, |
| 678 | surface); |
| 679 | if (surface->surface == NULL) { |
| 680 | free(surface); |
| 681 | return; |
| 682 | } |
| 683 | |
| 684 | surface->resource = |
| 685 | weston_desktop_surface_add_resource(surface->surface, |
| 686 | &xdg_surface_interface, |
| 687 | &weston_desktop_xdg_surface_implementation, |
| 688 | id, NULL); |
| 689 | if (surface->resource == NULL) |
| 690 | return; |
| 691 | |
| 692 | surface->add_idle = |
| 693 | wl_event_loop_add_idle(loop, |
Quentin Glidic | 6967f0e | 2016-08-18 15:51:38 +0200 | [diff] [blame] | 694 | weston_desktop_xdg_surface_add_idle_callback, |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 695 | surface); |
| 696 | } |
| 697 | |
| 698 | static void |
| 699 | weston_desktop_xdg_shell_protocol_get_xdg_popup(struct wl_client *wl_client, |
| 700 | struct wl_resource *resource, |
| 701 | uint32_t id, |
| 702 | struct wl_resource *surface_resource, |
| 703 | struct wl_resource *parent_resource, |
| 704 | struct wl_resource *seat_resource, |
| 705 | uint32_t serial, |
| 706 | int32_t x, int32_t y) |
| 707 | { |
| 708 | struct weston_desktop_client *client = |
| 709 | wl_resource_get_user_data(resource); |
| 710 | struct weston_surface *wsurface = |
| 711 | wl_resource_get_user_data(surface_resource); |
| 712 | struct weston_surface *wparent = |
| 713 | wl_resource_get_user_data(parent_resource); |
| 714 | struct weston_seat *wseat = wl_resource_get_user_data(seat_resource); |
| 715 | struct weston_desktop_seat *seat = weston_desktop_seat_from_seat(wseat); |
| 716 | struct weston_desktop_surface *parent, *topmost; |
| 717 | bool parent_is_popup, parent_is_xdg; |
| 718 | struct weston_desktop_xdg_popup *popup; |
| 719 | |
| 720 | if (weston_surface_set_role(wsurface, "xdg_popup", resource, XDG_SHELL_ERROR_ROLE) < 0) |
| 721 | return; |
| 722 | |
| 723 | if (!weston_surface_is_desktop_surface(wparent)) { |
| 724 | wl_resource_post_error(resource, |
| 725 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 726 | "xdg_popup parent was invalid"); |
| 727 | return; |
| 728 | } |
| 729 | |
| 730 | parent = weston_surface_get_desktop_surface(wparent); |
| 731 | parent_is_xdg = |
| 732 | weston_desktop_surface_has_implementation(parent, |
| 733 | &weston_desktop_xdg_surface_internal_implementation); |
| 734 | parent_is_popup = |
| 735 | weston_desktop_surface_has_implementation(parent, |
| 736 | &weston_desktop_xdg_popup_internal_implementation); |
| 737 | |
| 738 | if (!parent_is_xdg && !parent_is_popup) { |
| 739 | wl_resource_post_error(resource, |
| 740 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 741 | "xdg_popup parent was invalid"); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | topmost = weston_desktop_seat_popup_grab_get_topmost_surface(seat); |
| 746 | if ((topmost == NULL && parent_is_popup) || |
| 747 | (topmost != NULL && topmost != parent)) { |
| 748 | wl_resource_post_error(resource, |
| 749 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
| 750 | "xdg_popup was not created on the topmost popup"); |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | popup = zalloc(sizeof(struct weston_desktop_xdg_popup)); |
| 755 | if (popup == NULL) { |
| 756 | wl_client_post_no_memory(wl_client); |
| 757 | return; |
| 758 | } |
| 759 | |
| 760 | popup->desktop = weston_desktop_client_get_desktop(client); |
| 761 | popup->display = weston_desktop_get_display(popup->desktop); |
| 762 | popup->seat = seat; |
| 763 | |
| 764 | popup->popup = |
| 765 | weston_desktop_surface_create(popup->desktop, client, wsurface, |
| 766 | &weston_desktop_xdg_popup_internal_implementation, |
| 767 | popup); |
| 768 | if (popup->popup == NULL) { |
| 769 | free(popup); |
| 770 | return; |
| 771 | } |
| 772 | |
| 773 | popup->resource = |
| 774 | weston_desktop_surface_add_resource(popup->popup, |
| 775 | &xdg_popup_interface, |
| 776 | &weston_desktop_xdg_popup_implementation, |
| 777 | id, NULL); |
| 778 | if (popup->resource == NULL) |
| 779 | return; |
| 780 | |
| 781 | weston_desktop_surface_set_relative_to(popup->popup, parent, x, y, false); |
| 782 | weston_desktop_surface_popup_grab(popup->popup, popup->seat, serial); |
| 783 | } |
| 784 | |
| 785 | static void |
| 786 | weston_desktop_xdg_shell_protocol_pong(struct wl_client *wl_client, |
| 787 | struct wl_resource *resource, |
| 788 | uint32_t serial) |
| 789 | { |
| 790 | struct weston_desktop_client *client = |
| 791 | wl_resource_get_user_data(resource); |
| 792 | |
| 793 | weston_desktop_client_pong(client, serial); |
| 794 | } |
| 795 | |
| 796 | static const struct xdg_shell_interface weston_desktop_xdg_shell_implementation = { |
| 797 | .destroy = weston_desktop_destroy_request, |
| 798 | .use_unstable_version = weston_desktop_xdg_shell_protocol_use_unstable_version, |
| 799 | .get_xdg_surface = weston_desktop_xdg_shell_protocol_get_xdg_surface, |
| 800 | .get_xdg_popup = weston_desktop_xdg_shell_protocol_get_xdg_popup, |
| 801 | .pong = weston_desktop_xdg_shell_protocol_pong, |
| 802 | }; |
| 803 | |
| 804 | static int |
| 805 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 806 | void *_target, uint32_t opcode, |
| 807 | const struct wl_message *message, |
| 808 | union wl_argument *args) |
| 809 | { |
| 810 | struct wl_resource *resource = _target; |
| 811 | struct weston_desktop_client *client = |
| 812 | wl_resource_get_user_data(resource); |
| 813 | |
| 814 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
| 815 | wl_resource_post_error(resource, |
| 816 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 817 | "must call use_unstable_version first"); |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | #define XDG_SERVER_VERSION 5 |
| 822 | |
| 823 | if (args[0].i != XDG_SERVER_VERSION) { |
| 824 | wl_resource_post_error(resource, |
| 825 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 826 | "incompatible version, server is %d " "client wants %d", |
| 827 | XDG_SERVER_VERSION, args[0].i); |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | wl_resource_set_implementation(resource, |
| 832 | &weston_desktop_xdg_shell_implementation, |
| 833 | client, implementation); |
| 834 | |
| 835 | return 1; |
| 836 | } |
| 837 | |
| 838 | static void |
| 839 | weston_desktop_xdg_shell_bind(struct wl_client *client, void *data, |
| 840 | uint32_t version, uint32_t id) |
| 841 | { |
| 842 | struct weston_desktop *desktop = data; |
| 843 | |
| 844 | weston_desktop_client_create(desktop, client, |
| 845 | xdg_shell_unversioned_dispatch, |
| 846 | &xdg_shell_interface, NULL, version, id); |
| 847 | } |
| 848 | |
| 849 | struct wl_global * |
| 850 | weston_desktop_xdg_shell_v5_create(struct weston_desktop *desktop, |
| 851 | struct wl_display *display) |
| 852 | { |
| 853 | return wl_global_create(display, |
| 854 | &xdg_shell_interface, |
| 855 | WD_XDG_SHELL_PROTOCOL_VERSION, |
| 856 | desktop, weston_desktop_xdg_shell_bind); |
| 857 | } |