| 1 | /* |
| 2 | * Copyright © 2008-2013 Kristian Høgsberg |
| 3 | * Copyright © 2013 Rafael Antognolli |
| 4 | * Copyright © 2013 Jasper St. Pierre |
| 5 | * Copyright © 2010-2013 Intel Corporation |
| 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 | #ifndef QT_WAYLAND_SERVER_XDG_SHELL_UNSTABLE_V5 |
| 28 | #define QT_WAYLAND_SERVER_XDG_SHELL_UNSTABLE_V5 |
| 29 | |
| 30 | #include "wayland-server.h" |
| 31 | #include <QtWaylandCompositor/private/wayland-xdg-shell-unstable-v5-server-protocol_p.h> |
| 32 | #include <QByteArray> |
| 33 | #include <QMultiMap> |
| 34 | #include <QString> |
| 35 | |
| 36 | #ifndef WAYLAND_VERSION_CHECK |
| 37 | #define WAYLAND_VERSION_CHECK(major, minor, micro) \ |
| 38 | ((WAYLAND_VERSION_MAJOR > (major)) || \ |
| 39 | (WAYLAND_VERSION_MAJOR == (major) && WAYLAND_VERSION_MINOR > (minor)) || \ |
| 40 | (WAYLAND_VERSION_MAJOR == (major) && WAYLAND_VERSION_MINOR == (minor) && WAYLAND_VERSION_MICRO >= (micro))) |
| 41 | #endif |
| 42 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | QT_WARNING_PUSH |
| 45 | QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers" ) |
| 46 | QT_WARNING_DISABLE_CLANG("-Wmissing-field-initializers" ) |
| 47 | |
| 48 | #if !defined(Q_WAYLAND_SERVER_XDG_SHELL_UNSTABLE_V5_EXPORT) |
| 49 | # if defined(QT_SHARED) |
| 50 | # define Q_WAYLAND_SERVER_XDG_SHELL_UNSTABLE_V5_EXPORT Q_DECL_EXPORT |
| 51 | # else |
| 52 | # define Q_WAYLAND_SERVER_XDG_SHELL_UNSTABLE_V5_EXPORT |
| 53 | # endif |
| 54 | #endif |
| 55 | |
| 56 | namespace QtWaylandServer { |
| 57 | class Q_WAYLAND_SERVER_XDG_SHELL_UNSTABLE_V5_EXPORT xdg_shell_v5 |
| 58 | { |
| 59 | public: |
| 60 | xdg_shell_v5(struct ::wl_client *client, int id, int version); |
| 61 | xdg_shell_v5(struct ::wl_display *display, int version); |
| 62 | xdg_shell_v5(struct ::wl_resource *resource); |
| 63 | xdg_shell_v5(); |
| 64 | |
| 65 | virtual ~xdg_shell_v5(); |
| 66 | |
| 67 | class Resource |
| 68 | { |
| 69 | public: |
| 70 | Resource() : xdg_shell_object(nullptr), handle(nullptr) {} |
| 71 | virtual ~Resource() {} |
| 72 | |
| 73 | xdg_shell_v5 *xdg_shell_object; |
| 74 | xdg_shell_v5 *object() { return xdg_shell_object; } |
| 75 | struct ::wl_resource *handle; |
| 76 | |
| 77 | struct ::wl_client *client() const { return wl_resource_get_client(resource: handle); } |
| 78 | int version() const { return wl_resource_get_version(resource: handle); } |
| 79 | |
| 80 | static Resource *fromResource(struct ::wl_resource *resource); |
| 81 | }; |
| 82 | |
| 83 | void init(struct ::wl_client *client, int id, int version); |
| 84 | void init(struct ::wl_display *display, int version); |
| 85 | void init(struct ::wl_resource *resource); |
| 86 | |
| 87 | Resource *add(struct ::wl_client *client, int version); |
| 88 | Resource *add(struct ::wl_client *client, int id, int version); |
| 89 | Resource *add(struct wl_list *resource_list, struct ::wl_client *client, int id, int version); |
| 90 | |
| 91 | Resource *resource() { return m_resource; } |
| 92 | const Resource *resource() const { return m_resource; } |
| 93 | |
| 94 | QMultiMap<struct ::wl_client*, Resource*> resourceMap() { return m_resource_map; } |
| 95 | const QMultiMap<struct ::wl_client*, Resource*> resourceMap() const { return m_resource_map; } |
| 96 | |
| 97 | bool isGlobal() const { return m_global != nullptr; } |
| 98 | bool isResource() const { return m_resource != nullptr; } |
| 99 | |
| 100 | static const struct ::wl_interface *interface(); |
| 101 | static QByteArray interfaceName() { return interface()->name; } |
| 102 | static int interfaceVersion() { return interface()->version; } |
| 103 | |
| 104 | |
| 105 | enum version { |
| 106 | version_current = 5 // Always the latest version |
| 107 | }; |
| 108 | |
| 109 | enum error { |
| 110 | error_role = 0, // given wl_surface has another role |
| 111 | error_defunct_surfaces = 1, // xdg_shell was destroyed before children |
| 112 | error_not_the_topmost_popup = 2, // the client tried to map or destroy a non-topmost popup |
| 113 | error_invalid_popup_parent = 3 // the client specified an invalid popup parent surface |
| 114 | }; |
| 115 | |
| 116 | void send_ping(uint32_t serial); |
| 117 | void send_ping(struct ::wl_resource *resource, uint32_t serial); |
| 118 | |
| 119 | protected: |
| 120 | virtual Resource *xdg_shell_allocate(); |
| 121 | |
| 122 | virtual void xdg_shell_bind_resource(Resource *resource); |
| 123 | virtual void xdg_shell_destroy_resource(Resource *resource); |
| 124 | |
| 125 | virtual void xdg_shell_destroy(Resource *resource); |
| 126 | virtual void xdg_shell_use_unstable_version(Resource *resource, int32_t version); |
| 127 | virtual void xdg_shell_get_xdg_surface(Resource *resource, uint32_t id, struct ::wl_resource *surface); |
| 128 | virtual void xdg_shell_get_xdg_popup(Resource *resource, uint32_t id, struct ::wl_resource *surface, struct ::wl_resource *parent, struct ::wl_resource *seat, uint32_t serial, int32_t x, int32_t y); |
| 129 | virtual void xdg_shell_pong(Resource *resource, uint32_t serial); |
| 130 | |
| 131 | private: |
| 132 | static void bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id); |
| 133 | static void destroy_func(struct ::wl_resource *client_resource); |
| 134 | static void display_destroy_func(struct ::wl_listener *listener, void *data); |
| 135 | |
| 136 | Resource *bind(struct ::wl_client *client, uint32_t id, int version); |
| 137 | Resource *bind(struct ::wl_resource *handle); |
| 138 | |
| 139 | static const struct ::xdg_shell_v5_interface m_xdg_shell_interface; |
| 140 | |
| 141 | static void handle_destroy( |
| 142 | ::wl_client *client, |
| 143 | struct wl_resource *resource); |
| 144 | static void handle_use_unstable_version( |
| 145 | ::wl_client *client, |
| 146 | struct wl_resource *resource, |
| 147 | int32_t version); |
| 148 | static void handle_get_xdg_surface( |
| 149 | ::wl_client *client, |
| 150 | struct wl_resource *resource, |
| 151 | uint32_t id, |
| 152 | struct ::wl_resource *surface); |
| 153 | static void handle_get_xdg_popup( |
| 154 | ::wl_client *client, |
| 155 | struct wl_resource *resource, |
| 156 | uint32_t id, |
| 157 | struct ::wl_resource *surface, |
| 158 | struct ::wl_resource *parent, |
| 159 | struct ::wl_resource *seat, |
| 160 | uint32_t serial, |
| 161 | int32_t x, |
| 162 | int32_t y); |
| 163 | static void handle_pong( |
| 164 | ::wl_client *client, |
| 165 | struct wl_resource *resource, |
| 166 | uint32_t serial); |
| 167 | |
| 168 | QMultiMap<struct ::wl_client*, Resource*> m_resource_map; |
| 169 | Resource *m_resource; |
| 170 | struct ::wl_global *m_global; |
| 171 | uint32_t m_globalVersion; |
| 172 | struct DisplayDestroyedListener : ::wl_listener { |
| 173 | xdg_shell_v5 *parent; |
| 174 | }; |
| 175 | DisplayDestroyedListener m_displayDestroyedListener; |
| 176 | }; |
| 177 | |
| 178 | class Q_WAYLAND_SERVER_XDG_SHELL_UNSTABLE_V5_EXPORT xdg_surface_v5 |
| 179 | { |
| 180 | public: |
| 181 | xdg_surface_v5(struct ::wl_client *client, int id, int version); |
| 182 | xdg_surface_v5(struct ::wl_display *display, int version); |
| 183 | xdg_surface_v5(struct ::wl_resource *resource); |
| 184 | xdg_surface_v5(); |
| 185 | |
| 186 | virtual ~xdg_surface_v5(); |
| 187 | |
| 188 | class Resource |
| 189 | { |
| 190 | public: |
| 191 | Resource() : xdg_surface_object(nullptr), handle(nullptr) {} |
| 192 | virtual ~Resource() {} |
| 193 | |
| 194 | xdg_surface_v5 *xdg_surface_object; |
| 195 | xdg_surface_v5 *object() { return xdg_surface_object; } |
| 196 | struct ::wl_resource *handle; |
| 197 | |
| 198 | struct ::wl_client *client() const { return wl_resource_get_client(resource: handle); } |
| 199 | int version() const { return wl_resource_get_version(resource: handle); } |
| 200 | |
| 201 | static Resource *fromResource(struct ::wl_resource *resource); |
| 202 | }; |
| 203 | |
| 204 | void init(struct ::wl_client *client, int id, int version); |
| 205 | void init(struct ::wl_display *display, int version); |
| 206 | void init(struct ::wl_resource *resource); |
| 207 | |
| 208 | Resource *add(struct ::wl_client *client, int version); |
| 209 | Resource *add(struct ::wl_client *client, int id, int version); |
| 210 | Resource *add(struct wl_list *resource_list, struct ::wl_client *client, int id, int version); |
| 211 | |
| 212 | Resource *resource() { return m_resource; } |
| 213 | const Resource *resource() const { return m_resource; } |
| 214 | |
| 215 | QMultiMap<struct ::wl_client*, Resource*> resourceMap() { return m_resource_map; } |
| 216 | const QMultiMap<struct ::wl_client*, Resource*> resourceMap() const { return m_resource_map; } |
| 217 | |
| 218 | bool isGlobal() const { return m_global != nullptr; } |
| 219 | bool isResource() const { return m_resource != nullptr; } |
| 220 | |
| 221 | static const struct ::wl_interface *interface(); |
| 222 | static QByteArray interfaceName() { return interface()->name; } |
| 223 | static int interfaceVersion() { return interface()->version; } |
| 224 | |
| 225 | |
| 226 | enum resize_edge { |
| 227 | resize_edge_none = 0, |
| 228 | resize_edge_top = 1, |
| 229 | resize_edge_bottom = 2, |
| 230 | resize_edge_left = 4, |
| 231 | resize_edge_top_left = 5, |
| 232 | resize_edge_bottom_left = 6, |
| 233 | resize_edge_right = 8, |
| 234 | resize_edge_top_right = 9, |
| 235 | resize_edge_bottom_right = 10 |
| 236 | }; |
| 237 | |
| 238 | enum state { |
| 239 | state_maximized = 1, // the surface is maximized |
| 240 | state_fullscreen = 2, // the surface is fullscreen |
| 241 | state_resizing = 3, |
| 242 | state_activated = 4 |
| 243 | }; |
| 244 | |
| 245 | void send_configure(int32_t width, int32_t height, const QByteArray &states, uint32_t serial); |
| 246 | void send_configure(struct ::wl_resource *resource, int32_t width, int32_t height, const QByteArray &states, uint32_t serial); |
| 247 | void send_close(); |
| 248 | void send_close(struct ::wl_resource *resource); |
| 249 | |
| 250 | protected: |
| 251 | virtual Resource *xdg_surface_allocate(); |
| 252 | |
| 253 | virtual void xdg_surface_bind_resource(Resource *resource); |
| 254 | virtual void xdg_surface_destroy_resource(Resource *resource); |
| 255 | |
| 256 | virtual void xdg_surface_destroy(Resource *resource); |
| 257 | virtual void xdg_surface_set_parent(Resource *resource, struct ::wl_resource *parent); |
| 258 | virtual void xdg_surface_set_title(Resource *resource, const QString &title); |
| 259 | virtual void xdg_surface_set_app_id(Resource *resource, const QString &app_id); |
| 260 | virtual void xdg_surface_show_window_menu(Resource *resource, struct ::wl_resource *seat, uint32_t serial, int32_t x, int32_t y); |
| 261 | virtual void xdg_surface_move(Resource *resource, struct ::wl_resource *seat, uint32_t serial); |
| 262 | virtual void xdg_surface_resize(Resource *resource, struct ::wl_resource *seat, uint32_t serial, uint32_t edges); |
| 263 | virtual void xdg_surface_ack_configure(Resource *resource, uint32_t serial); |
| 264 | virtual void xdg_surface_set_window_geometry(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height); |
| 265 | virtual void xdg_surface_set_maximized(Resource *resource); |
| 266 | virtual void xdg_surface_unset_maximized(Resource *resource); |
| 267 | virtual void xdg_surface_set_fullscreen(Resource *resource, struct ::wl_resource *output); |
| 268 | virtual void xdg_surface_unset_fullscreen(Resource *resource); |
| 269 | virtual void xdg_surface_set_minimized(Resource *resource); |
| 270 | |
| 271 | private: |
| 272 | static void bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id); |
| 273 | static void destroy_func(struct ::wl_resource *client_resource); |
| 274 | static void display_destroy_func(struct ::wl_listener *listener, void *data); |
| 275 | |
| 276 | Resource *bind(struct ::wl_client *client, uint32_t id, int version); |
| 277 | Resource *bind(struct ::wl_resource *handle); |
| 278 | |
| 279 | static const struct ::xdg_surface_v5_interface m_xdg_surface_interface; |
| 280 | |
| 281 | static void handle_destroy( |
| 282 | ::wl_client *client, |
| 283 | struct wl_resource *resource); |
| 284 | static void handle_set_parent( |
| 285 | ::wl_client *client, |
| 286 | struct wl_resource *resource, |
| 287 | struct ::wl_resource *parent); |
| 288 | static void handle_set_title( |
| 289 | ::wl_client *client, |
| 290 | struct wl_resource *resource, |
| 291 | const char *title); |
| 292 | static void handle_set_app_id( |
| 293 | ::wl_client *client, |
| 294 | struct wl_resource *resource, |
| 295 | const char *app_id); |
| 296 | static void handle_show_window_menu( |
| 297 | ::wl_client *client, |
| 298 | struct wl_resource *resource, |
| 299 | struct ::wl_resource *seat, |
| 300 | uint32_t serial, |
| 301 | int32_t x, |
| 302 | int32_t y); |
| 303 | static void handle_move( |
| 304 | ::wl_client *client, |
| 305 | struct wl_resource *resource, |
| 306 | struct ::wl_resource *seat, |
| 307 | uint32_t serial); |
| 308 | static void handle_resize( |
| 309 | ::wl_client *client, |
| 310 | struct wl_resource *resource, |
| 311 | struct ::wl_resource *seat, |
| 312 | uint32_t serial, |
| 313 | uint32_t edges); |
| 314 | static void handle_ack_configure( |
| 315 | ::wl_client *client, |
| 316 | struct wl_resource *resource, |
| 317 | uint32_t serial); |
| 318 | static void handle_set_window_geometry( |
| 319 | ::wl_client *client, |
| 320 | struct wl_resource *resource, |
| 321 | int32_t x, |
| 322 | int32_t y, |
| 323 | int32_t width, |
| 324 | int32_t height); |
| 325 | static void handle_set_maximized( |
| 326 | ::wl_client *client, |
| 327 | struct wl_resource *resource); |
| 328 | static void handle_unset_maximized( |
| 329 | ::wl_client *client, |
| 330 | struct wl_resource *resource); |
| 331 | static void handle_set_fullscreen( |
| 332 | ::wl_client *client, |
| 333 | struct wl_resource *resource, |
| 334 | struct ::wl_resource *output); |
| 335 | static void handle_unset_fullscreen( |
| 336 | ::wl_client *client, |
| 337 | struct wl_resource *resource); |
| 338 | static void handle_set_minimized( |
| 339 | ::wl_client *client, |
| 340 | struct wl_resource *resource); |
| 341 | |
| 342 | QMultiMap<struct ::wl_client*, Resource*> m_resource_map; |
| 343 | Resource *m_resource; |
| 344 | struct ::wl_global *m_global; |
| 345 | uint32_t m_globalVersion; |
| 346 | struct DisplayDestroyedListener : ::wl_listener { |
| 347 | xdg_surface_v5 *parent; |
| 348 | }; |
| 349 | DisplayDestroyedListener m_displayDestroyedListener; |
| 350 | }; |
| 351 | |
| 352 | class Q_WAYLAND_SERVER_XDG_SHELL_UNSTABLE_V5_EXPORT xdg_popup_v5 |
| 353 | { |
| 354 | public: |
| 355 | xdg_popup_v5(struct ::wl_client *client, int id, int version); |
| 356 | xdg_popup_v5(struct ::wl_display *display, int version); |
| 357 | xdg_popup_v5(struct ::wl_resource *resource); |
| 358 | xdg_popup_v5(); |
| 359 | |
| 360 | virtual ~xdg_popup_v5(); |
| 361 | |
| 362 | class Resource |
| 363 | { |
| 364 | public: |
| 365 | Resource() : xdg_popup_object(nullptr), handle(nullptr) {} |
| 366 | virtual ~Resource() {} |
| 367 | |
| 368 | xdg_popup_v5 *xdg_popup_object; |
| 369 | xdg_popup_v5 *object() { return xdg_popup_object; } |
| 370 | struct ::wl_resource *handle; |
| 371 | |
| 372 | struct ::wl_client *client() const { return wl_resource_get_client(resource: handle); } |
| 373 | int version() const { return wl_resource_get_version(resource: handle); } |
| 374 | |
| 375 | static Resource *fromResource(struct ::wl_resource *resource); |
| 376 | }; |
| 377 | |
| 378 | void init(struct ::wl_client *client, int id, int version); |
| 379 | void init(struct ::wl_display *display, int version); |
| 380 | void init(struct ::wl_resource *resource); |
| 381 | |
| 382 | Resource *add(struct ::wl_client *client, int version); |
| 383 | Resource *add(struct ::wl_client *client, int id, int version); |
| 384 | Resource *add(struct wl_list *resource_list, struct ::wl_client *client, int id, int version); |
| 385 | |
| 386 | Resource *resource() { return m_resource; } |
| 387 | const Resource *resource() const { return m_resource; } |
| 388 | |
| 389 | QMultiMap<struct ::wl_client*, Resource*> resourceMap() { return m_resource_map; } |
| 390 | const QMultiMap<struct ::wl_client*, Resource*> resourceMap() const { return m_resource_map; } |
| 391 | |
| 392 | bool isGlobal() const { return m_global != nullptr; } |
| 393 | bool isResource() const { return m_resource != nullptr; } |
| 394 | |
| 395 | static const struct ::wl_interface *interface(); |
| 396 | static QByteArray interfaceName() { return interface()->name; } |
| 397 | static int interfaceVersion() { return interface()->version; } |
| 398 | |
| 399 | |
| 400 | void send_popup_done(); |
| 401 | void send_popup_done(struct ::wl_resource *resource); |
| 402 | |
| 403 | protected: |
| 404 | virtual Resource *xdg_popup_allocate(); |
| 405 | |
| 406 | virtual void xdg_popup_bind_resource(Resource *resource); |
| 407 | virtual void xdg_popup_destroy_resource(Resource *resource); |
| 408 | |
| 409 | virtual void xdg_popup_destroy(Resource *resource); |
| 410 | |
| 411 | private: |
| 412 | static void bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id); |
| 413 | static void destroy_func(struct ::wl_resource *client_resource); |
| 414 | static void display_destroy_func(struct ::wl_listener *listener, void *data); |
| 415 | |
| 416 | Resource *bind(struct ::wl_client *client, uint32_t id, int version); |
| 417 | Resource *bind(struct ::wl_resource *handle); |
| 418 | |
| 419 | static const struct ::xdg_popup_v5_interface m_xdg_popup_interface; |
| 420 | |
| 421 | static void handle_destroy( |
| 422 | ::wl_client *client, |
| 423 | struct wl_resource *resource); |
| 424 | |
| 425 | QMultiMap<struct ::wl_client*, Resource*> m_resource_map; |
| 426 | Resource *m_resource; |
| 427 | struct ::wl_global *m_global; |
| 428 | uint32_t m_globalVersion; |
| 429 | struct DisplayDestroyedListener : ::wl_listener { |
| 430 | xdg_popup_v5 *parent; |
| 431 | }; |
| 432 | DisplayDestroyedListener m_displayDestroyedListener; |
| 433 | }; |
| 434 | } |
| 435 | |
| 436 | QT_WARNING_POP |
| 437 | QT_END_NAMESPACE |
| 438 | |
| 439 | #endif |
| 440 | |