|
| 1 | +// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) |
| 2 | +// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) |
| 3 | +// Copyright (C) 2025-2027 Wing-summer (wingsummer) |
| 4 | +// SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +#ifndef LINUXDESKTOPENVAPI_H |
| 7 | +#define LINUXDESKTOPENVAPI_H |
| 8 | + |
| 9 | +// |
| 10 | +// W A R N I N G !!! |
| 11 | +// ----------------- |
| 12 | +// |
| 13 | +// This file is not part of the QWindowKit API. It is used purely as an |
| 14 | +// implementation detail. This header file may change from version to |
| 15 | +// version without notice, or may even be removed. |
| 16 | +// |
| 17 | + |
| 18 | +#include "qguiapplication_platform.h" |
| 19 | + |
| 20 | +// some declarations about x11 |
| 21 | +using Atom = unsigned long; |
| 22 | +using Bool = int; |
| 23 | +using XID = unsigned long; |
| 24 | +using Window = XID; |
| 25 | + |
| 26 | +union _XEvent; |
| 27 | +using XEvent = union _XEvent; |
| 28 | + |
| 29 | +namespace QWK { |
| 30 | + struct LinuxX11API { |
| 31 | + LinuxX11API() = default; |
| 32 | + Q_DISABLE_COPY(LinuxX11API) |
| 33 | + |
| 34 | + using XInternAtomFn = Atom (*)(Display *, const char *, Bool); |
| 35 | + using XSendEventFn = int (*)(Display *, Window, Bool, long, XEvent *); |
| 36 | + using XFlushFn = int (*)(Display *); |
| 37 | + |
| 38 | + XInternAtomFn XInternAtom = nullptr; |
| 39 | + XSendEventFn XSendEvent = nullptr; |
| 40 | + XFlushFn XFlush = nullptr; |
| 41 | + |
| 42 | + inline bool isValid() const { |
| 43 | + return XInternAtom && XSendEvent && XFlush; |
| 44 | + } |
| 45 | + }; |
| 46 | + |
| 47 | + struct LinuxWaylandAPI { |
| 48 | + LinuxWaylandAPI() = default; |
| 49 | + Q_DISABLE_COPY(LinuxWaylandAPI) |
| 50 | + |
| 51 | + using wl_display_flush_fn = int (*)(struct wl_display *); |
| 52 | + using wl_proxy_marshal_flags_fn = void (*)(struct wl_proxy *, uint32_t, |
| 53 | + const struct wl_interface *, uint32_t, uint32_t, |
| 54 | + ...); |
| 55 | + using wl_proxy_get_version_fn = int (*)(struct wl_proxy *); |
| 56 | + |
| 57 | + wl_display_flush_fn wl_display_flush = nullptr; |
| 58 | + wl_proxy_marshal_flags_fn wl_proxy_marshal_flags = nullptr; |
| 59 | + wl_proxy_get_version_fn wl_proxy_get_version = nullptr; |
| 60 | + |
| 61 | + inline bool isValid() const { |
| 62 | + return wl_display_flush && wl_proxy_marshal_flags && wl_proxy_get_version; |
| 63 | + } |
| 64 | + }; |
| 65 | + |
| 66 | + |
| 67 | + class LinuxDesktopEnvAPI { |
| 68 | + Q_DISABLE_COPY(LinuxDesktopEnvAPI) |
| 69 | + public: |
| 70 | + static bool isWaylandPlatform(); |
| 71 | + |
| 72 | + static bool isX11Platform(); |
| 73 | + |
| 74 | + public: |
| 75 | + static const LinuxX11API &x11API(); |
| 76 | + static const LinuxWaylandAPI &waylandAPI(); |
| 77 | + }; |
| 78 | +} |
| 79 | + |
| 80 | +#endif // LINUXDESKTOPENVAPI_H |
0 commit comments