File indexing completed on 2024-05-12 05:33:51

0001 /*
0002  *  SPDX-FileCopyrightText: 2014-2015 Sebastian Kügler <sebas@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.1-or-later
0005  */
0006 #pragma once
0007 
0008 #include "abstractbackend.h"
0009 #include "config.h"
0010 
0011 #include <QDir>
0012 #include <QLoggingCategory>
0013 #include <QScreen>
0014 #include <QSize>
0015 #include <QSocketNotifier>
0016 
0017 struct kde_output_device_v2;
0018 struct wl_registry;
0019 
0020 namespace KScreen
0021 {
0022 class Output;
0023 class WaylandOutputDevice;
0024 class WaylandScreen;
0025 class WaylandOutputManagement;
0026 class WaylandOutputOrder;
0027 
0028 /**
0029  * @class WaylandConfig
0030  *
0031  * This class holds the basic skeleton of the configuration and takes care of
0032  * fetching the information from the Wayland server and synchronizing the
0033  * configuration out to the "clients" that receive the config from the backend.
0034  * We initialize a wayland connection, using a threaded event queue when
0035  * querying the wayland server for data.
0036  * Initially, the creation of a WaylandConfig blocks until all data has been
0037  * received, signalled by the initialized() signal. This means that the
0038  * wayland client has received information about all interfaces, and that all
0039  * outputs are completely initialized. From then on, we properly notifyUpdate().
0040  */
0041 class WaylandConfig : public QObject
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     explicit WaylandConfig(QObject *parent = nullptr);
0047 
0048     KScreen::ConfigPtr currentConfig();
0049     QMap<int, WaylandOutputDevice *> outputMap() const;
0050 
0051     void applyConfig(const KScreen::ConfigPtr &newConfig);
0052     WaylandOutputDevice *findOutputDevice(struct ::kde_output_device_v2 *outputdevice) const;
0053 
0054     bool isReady() const;
0055 
0056 Q_SIGNALS:
0057     void configChanged();
0058     void initialized();
0059     void globalRemoved(uint32_t name);
0060 
0061 private:
0062     void setupRegistry();
0063     void checkInitialized();
0064     void disconnected();
0065 
0066     void initKWinTabletMode();
0067 
0068     void addOutput(quint32 name, quint32 version);
0069     void removeOutput(WaylandOutputDevice *output);
0070 
0071     void blockSignals();
0072     void unblockSignals();
0073     void tryPendingConfig();
0074 
0075     wl_registry *m_registry;
0076 
0077     WaylandOutputManagement *m_outputManagement;
0078     std::unique_ptr<WaylandOutputOrder> m_outputOrder;
0079 
0080     // KWayland names as keys
0081     QMap<int, WaylandOutputDevice *> m_outputMap;
0082 
0083     // KWayland names
0084     QList<WaylandOutputDevice *> m_initializingOutputs;
0085     int m_lastOutputId = -1;
0086 
0087     bool m_registryInitialized;
0088     bool m_blockSignals;
0089     KScreen::ConfigPtr m_kscreenConfig;
0090     KScreen::ConfigPtr m_kscreenPendingConfig;
0091     WaylandScreen *m_screen;
0092 
0093     bool m_tabletModeAvailable;
0094     bool m_tabletModeEngaged;
0095     bool m_initialized = false;
0096 };
0097 
0098 }