Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 1 | /* |
| 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 Paalanen | 3d5d947 | 2019-03-28 16:28:47 +0200 | [diff] [blame] | 31 | #include <libweston/libweston.h> |
Pekka Paalanen | ecbdcfd | 2019-04-04 14:46:00 +0300 | [diff] [blame] | 32 | #include <libweston/zalloc.h> |
Pekka Paalanen | c232f8d | 2019-04-05 16:09:45 +0300 | [diff] [blame] | 33 | #include "shared/helpers.h" |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 34 | |
Pekka Paalanen | 8ebd981 | 2019-04-04 16:02:14 +0300 | [diff] [blame] | 35 | #include <libweston-desktop/libweston-desktop.h> |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 36 | #include "internal.h" |
| 37 | |
| 38 | |
| 39 | struct weston_desktop { |
| 40 | struct weston_compositor *compositor; |
| 41 | struct weston_desktop_api api; |
| 42 | void *user_data; |
ant8me | d8d9f5e | 2018-11-28 22:46:37 +0100 | [diff] [blame] | 43 | 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 Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 45 | struct wl_global *wl_shell; |
| 46 | }; |
| 47 | |
| 48 | void |
| 49 | weston_desktop_destroy_request(struct wl_client *client, |
| 50 | struct wl_resource *resource) |
| 51 | { |
| 52 | wl_resource_destroy(resource); |
| 53 | } |
| 54 | |
| 55 | WL_EXPORT struct weston_desktop * |
| 56 | weston_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 | |
ant8me | d8d9f5e | 2018-11-28 22:46:37 +0100 | [diff] [blame] | 73 | 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 Ser | 413d210 | 2021-02-16 13:34:46 +0100 | [diff] [blame] | 80 | #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 Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 83 | 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 Ser | 413d210 | 2021-02-16 13:34:46 +0100 | [diff] [blame] | 89 | #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 Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 95 | |
| 96 | weston_desktop_xwayland_init(desktop); |
| 97 | |
| 98 | return desktop; |
| 99 | } |
| 100 | |
| 101 | WL_EXPORT void |
| 102 | weston_desktop_destroy(struct weston_desktop *desktop) |
| 103 | { |
| 104 | if (desktop == NULL) |
| 105 | return; |
| 106 | |
Pekka Paalanen | e2583ca | 2021-05-14 16:12:35 +0300 | [diff] [blame] | 107 | weston_desktop_xwayland_fini(desktop); |
| 108 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 109 | if (desktop->wl_shell != NULL) |
| 110 | wl_global_destroy(desktop->wl_shell); |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 111 | if (desktop->xdg_shell_v6 != NULL) |
| 112 | wl_global_destroy(desktop->xdg_shell_v6); |
ant8me | d8d9f5e | 2018-11-28 22:46:37 +0100 | [diff] [blame] | 113 | if (desktop->xdg_wm_base != NULL) |
| 114 | wl_global_destroy(desktop->xdg_wm_base); |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 115 | |
| 116 | free(desktop); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | struct weston_compositor * |
| 121 | weston_desktop_get_compositor(struct weston_desktop *desktop) |
| 122 | { |
| 123 | return desktop->compositor; |
| 124 | } |
| 125 | |
| 126 | struct wl_display * |
| 127 | weston_desktop_get_display(struct weston_desktop *desktop) |
| 128 | { |
| 129 | return desktop->compositor->wl_display; |
| 130 | } |
| 131 | |
| 132 | void |
| 133 | weston_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 | |
| 140 | void |
| 141 | weston_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 | |
| 148 | void |
| 149 | weston_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 | |
| 161 | void |
| 162 | weston_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 | |
| 172 | void |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 173 | weston_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 | |
| 181 | void |
| 182 | weston_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 | |
| 192 | void |
| 193 | weston_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 | |
| 201 | void |
| 202 | weston_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 | |
| 210 | void |
| 211 | weston_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 | |
| 221 | void |
| 222 | weston_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 | |
| 232 | void |
| 233 | weston_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 | |
| 242 | void |
| 243 | weston_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 Paalanen | 37111e1 | 2016-11-16 14:03:31 +0200 | [diff] [blame] | 249 | |
| 250 | void |
| 251 | weston_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 | } |