File indexing completed on 2026-06-14 15:32:07

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 zwp_linux_dmabuf_v1;
0017 
0018 namespace KWayland
0019 {
0020 namespace Client
0021 {
0022 class Compositor;
0023 class PointerConstraints;
0024 class PointerGestures;
0025 class RelativePointerManager;
0026 class Seat;
0027 class ShmPool;
0028 class XdgDecorationManager;
0029 class XdgShell;
0030 }
0031 }
0032 
0033 namespace KWin
0034 {
0035 namespace Wayland
0036 {
0037 
0038 class WaylandEventThread;
0039 
0040 class WaylandLinuxDmabufV1
0041 {
0042 public:
0043     WaylandLinuxDmabufV1(wl_registry *registry, uint32_t name, uint32_t version);
0044     ~WaylandLinuxDmabufV1();
0045 
0046     zwp_linux_dmabuf_v1 *handle() const;
0047     QHash<uint32_t, QVector<uint64_t>> formats() const;
0048 
0049 private:
0050     static void format(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, uint32_t format);
0051     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);
0052 
0053     zwp_linux_dmabuf_v1 *m_dmabuf;
0054     QHash<uint32_t, QVector<uint64_t>> m_formats;
0055 };
0056 
0057 class WaylandDisplay : public QObject
0058 {
0059     Q_OBJECT
0060 
0061 public:
0062     WaylandDisplay();
0063     ~WaylandDisplay() override;
0064 
0065     bool initialize(const QString &socketName);
0066 
0067     wl_display *nativeDisplay() const;
0068     KWayland::Client::Compositor *compositor() const;
0069     KWayland::Client::PointerConstraints *pointerConstraints() const;
0070     KWayland::Client::PointerGestures *pointerGestures() const;
0071     KWayland::Client::RelativePointerManager *relativePointerManager() const;
0072     KWayland::Client::Seat *seat() const;
0073     KWayland::Client::XdgDecorationManager *xdgDecorationManager() const;
0074     KWayland::Client::ShmPool *shmPool() const;
0075     KWayland::Client::XdgShell *xdgShell() const;
0076     WaylandLinuxDmabufV1 *linuxDmabuf() const;
0077 
0078 public Q_SLOTS:
0079     void flush();
0080 
0081 private:
0082     static void registry_global(void *data, wl_registry *registry, uint32_t name, const char *interface, uint32_t version);
0083     static void registry_global_remove(void *data, wl_registry *registry, uint32_t name);
0084 
0085     wl_display *m_display = nullptr;
0086     wl_registry *m_registry = nullptr;
0087     std::unique_ptr<WaylandEventThread> m_eventThread;
0088     std::unique_ptr<WaylandLinuxDmabufV1> m_linuxDmabuf;
0089     std::unique_ptr<KWayland::Client::Compositor> m_compositor;
0090     std::unique_ptr<KWayland::Client::PointerConstraints> m_pointerConstraints;
0091     std::unique_ptr<KWayland::Client::PointerGestures> m_pointerGestures;
0092     std::unique_ptr<KWayland::Client::RelativePointerManager> m_relativePointerManager;
0093     std::unique_ptr<KWayland::Client::Seat> m_seat;
0094     std::unique_ptr<KWayland::Client::XdgDecorationManager> m_xdgDecorationManager;
0095     std::unique_ptr<KWayland::Client::ShmPool> m_shmPool;
0096     std::unique_ptr<KWayland::Client::XdgShell> m_xdgShell;
0097 };
0098 
0099 }
0100 }