File indexing completed on 2024-11-10 04:56:33
0001 /* 0002 SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QHash> 0010 #include <QObject> 0011 0012 #include <memory> 0013 0014 struct wl_display; 0015 struct wl_registry; 0016 struct wl_shm; 0017 struct zwp_linux_dmabuf_v1; 0018 0019 namespace KWayland 0020 { 0021 namespace Client 0022 { 0023 class Compositor; 0024 class PointerConstraints; 0025 class PointerGestures; 0026 class RelativePointerManager; 0027 class Seat; 0028 class XdgDecorationManager; 0029 class XdgShell; 0030 } 0031 } 0032 0033 namespace KWin 0034 { 0035 namespace Wayland 0036 { 0037 0038 class WaylandEventThread; 0039 class WaylandLinuxDmabufFeedbackV1; 0040 0041 class WaylandLinuxDmabufV1 0042 { 0043 public: 0044 WaylandLinuxDmabufV1(wl_registry *registry, uint32_t name, uint32_t version); 0045 ~WaylandLinuxDmabufV1(); 0046 0047 zwp_linux_dmabuf_v1 *handle() const; 0048 QByteArray mainDevice() const; 0049 QHash<uint32_t, QList<uint64_t>> formats() const; 0050 0051 private: 0052 static void format(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, uint32_t format); 0053 static void modifier(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo); 0054 0055 zwp_linux_dmabuf_v1 *m_dmabuf; 0056 std::unique_ptr<WaylandLinuxDmabufFeedbackV1> m_defaultFeedback; 0057 }; 0058 0059 class WaylandDisplay : public QObject 0060 { 0061 Q_OBJECT 0062 0063 public: 0064 WaylandDisplay(); 0065 ~WaylandDisplay() override; 0066 0067 bool initialize(const QString &socketName); 0068 0069 wl_display *nativeDisplay() const; 0070 KWayland::Client::Compositor *compositor() const; 0071 KWayland::Client::PointerConstraints *pointerConstraints() const; 0072 KWayland::Client::PointerGestures *pointerGestures() const; 0073 KWayland::Client::RelativePointerManager *relativePointerManager() const; 0074 KWayland::Client::Seat *seat() const; 0075 KWayland::Client::XdgDecorationManager *xdgDecorationManager() const; 0076 wl_shm *shm() const; 0077 KWayland::Client::XdgShell *xdgShell() const; 0078 WaylandLinuxDmabufV1 *linuxDmabuf() const; 0079 0080 public Q_SLOTS: 0081 void flush(); 0082 0083 private: 0084 static void registry_global(void *data, wl_registry *registry, uint32_t name, const char *interface, uint32_t version); 0085 static void registry_global_remove(void *data, wl_registry *registry, uint32_t name); 0086 0087 wl_display *m_display = nullptr; 0088 wl_registry *m_registry = nullptr; 0089 wl_shm *m_shm = nullptr; 0090 std::unique_ptr<WaylandEventThread> m_eventThread; 0091 std::unique_ptr<WaylandLinuxDmabufV1> m_linuxDmabuf; 0092 std::unique_ptr<KWayland::Client::Compositor> m_compositor; 0093 std::unique_ptr<KWayland::Client::PointerConstraints> m_pointerConstraints; 0094 std::unique_ptr<KWayland::Client::PointerGestures> m_pointerGestures; 0095 std::unique_ptr<KWayland::Client::RelativePointerManager> m_relativePointerManager; 0096 std::unique_ptr<KWayland::Client::Seat> m_seat; 0097 std::unique_ptr<KWayland::Client::XdgDecorationManager> m_xdgDecorationManager; 0098 std::unique_ptr<KWayland::Client::XdgShell> m_xdgShell; 0099 }; 0100 0101 } 0102 }