File indexing completed on 2024-11-10 04:56:34

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include "core/output.h"
0012 
0013 #include <KWayland/Client/xdgshell.h>
0014 
0015 #include <QObject>
0016 #include <QTimer>
0017 
0018 namespace KWayland
0019 {
0020 namespace Client
0021 {
0022 class Surface;
0023 class Pointer;
0024 class LockedPointer;
0025 class XdgDecoration;
0026 }
0027 }
0028 
0029 struct wl_buffer;
0030 
0031 namespace KWin
0032 {
0033 class OutputFrame;
0034 
0035 namespace Wayland
0036 {
0037 class WaylandBackend;
0038 
0039 class WaylandCursor
0040 {
0041 public:
0042     explicit WaylandCursor(WaylandBackend *backend);
0043     ~WaylandCursor();
0044 
0045     KWayland::Client::Pointer *pointer() const;
0046     void setPointer(KWayland::Client::Pointer *pointer);
0047 
0048     void setEnabled(bool enable);
0049     void update(wl_buffer *buffer, qreal scale, const QPoint &hotspot);
0050 
0051 private:
0052     void sync();
0053 
0054     KWayland::Client::Pointer *m_pointer = nullptr;
0055     std::unique_ptr<KWayland::Client::Surface> m_surface;
0056     wl_buffer *m_buffer = nullptr;
0057     QPoint m_hotspot;
0058     qreal m_scale = 1;
0059     bool m_enabled = true;
0060 };
0061 
0062 class WaylandOutput : public Output
0063 {
0064     Q_OBJECT
0065 public:
0066     WaylandOutput(const QString &name, WaylandBackend *backend);
0067     ~WaylandOutput() override;
0068 
0069     RenderLoop *renderLoop() const override;
0070     bool updateCursorLayer() override;
0071 
0072     void init(const QSize &pixelSize, qreal scale);
0073 
0074     bool isReady() const;
0075     KWayland::Client::Surface *surface() const;
0076     WaylandCursor *cursor() const;
0077     WaylandBackend *backend() const;
0078 
0079     void lockPointer(KWayland::Client::Pointer *pointer, bool lock);
0080     void resize(const QSize &pixelSize);
0081     void setDpmsMode(DpmsMode mode) override;
0082     void updateDpmsMode(DpmsMode dpmsMode);
0083     void updateEnabled(bool enabled);
0084 
0085     void framePending(const std::shared_ptr<OutputFrame> &frame);
0086 
0087 private:
0088     void handleConfigure(const QSize &size, KWayland::Client::XdgShellSurface::States states, quint32 serial);
0089     void updateWindowTitle();
0090     void applyConfigure(const QSize &size, quint32 serial);
0091 
0092     std::unique_ptr<RenderLoop> m_renderLoop;
0093     std::unique_ptr<KWayland::Client::Surface> m_surface;
0094     std::unique_ptr<KWayland::Client::XdgShellSurface> m_xdgShellSurface;
0095     std::unique_ptr<KWayland::Client::LockedPointer> m_pointerLock;
0096     std::unique_ptr<KWayland::Client::XdgDecoration> m_xdgDecoration;
0097     WaylandBackend *const m_backend;
0098     std::unique_ptr<WaylandCursor> m_cursor;
0099     QTimer m_turnOffTimer;
0100     bool m_hasPointerLock = false;
0101     bool m_ready = false;
0102     std::shared_ptr<OutputFrame> m_frame;
0103     quint32 m_pendingConfigureSerial = 0;
0104     QSize m_pendingConfigureSize;
0105     QTimer m_configureThrottleTimer;
0106 };
0107 
0108 } // namespace Wayland
0109 } // namespace KWin