Changeset View
Changeset View
Standalone View
Standalone View
backends/kwayland/waylandconfig.cpp
Show All 16 Lines | |||||
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | ||
18 | *************************************************************************************/ | 18 | *************************************************************************************/ | ||
19 | #include "waylandconfig.h" | 19 | #include "waylandconfig.h" | ||
20 | 20 | | |||
21 | #include "waylandbackend.h" | 21 | #include "waylandbackend.h" | ||
22 | #include "waylandoutput.h" | 22 | #include "waylandoutput.h" | ||
23 | #include "waylandscreen.h" | 23 | #include "waylandscreen.h" | ||
24 | 24 | | |||
25 | #include "tabletmodemanager_interface.h" | ||||
26 | | ||||
25 | #include <configmonitor.h> | 27 | #include <configmonitor.h> | ||
26 | #include <mode.h> | 28 | #include <mode.h> | ||
27 | 29 | | |||
28 | #include <KWayland/Client/connection_thread.h> | 30 | #include <KWayland/Client/connection_thread.h> | ||
29 | #include <KWayland/Client/event_queue.h> | 31 | #include <KWayland/Client/event_queue.h> | ||
30 | #include <KWayland/Client/registry.h> | 32 | #include <KWayland/Client/registry.h> | ||
31 | #include <KWayland/Client/outputconfiguration.h> | 33 | #include <KWayland/Client/outputconfiguration.h> | ||
32 | #include <KWayland/Client/outputmanagement.h> | 34 | #include <KWayland/Client/outputmanagement.h> | ||
33 | 35 | | |||
34 | #include <QTimer> | 36 | #include <QTimer> | ||
35 | 37 | | |||
36 | using namespace KScreen; | 38 | using namespace KScreen; | ||
37 | 39 | | |||
38 | WaylandConfig::WaylandConfig(QObject *parent) | 40 | WaylandConfig::WaylandConfig(QObject *parent) | ||
39 | : QObject(parent) | 41 | : QObject(parent) | ||
40 | , m_outputManagement(nullptr) | 42 | , m_outputManagement(nullptr) | ||
41 | , m_registryInitialized(false) | 43 | , m_registryInitialized(false) | ||
42 | , m_blockSignals(true) | 44 | , m_blockSignals(true) | ||
43 | , m_kscreenConfig(new Config) | 45 | , m_kscreenConfig(new Config) | ||
44 | , m_kscreenPendingConfig(nullptr) | 46 | , m_kscreenPendingConfig(nullptr) | ||
45 | , m_screen(new WaylandScreen(this)) | 47 | , m_screen(new WaylandScreen(this)) | ||
48 | , m_tabletModeAvailable(false) | ||||
49 | , m_tabletModeEngaged(false) | ||||
46 | { | 50 | { | ||
47 | connect(this, &WaylandConfig::initialized, &m_syncLoop, &QEventLoop::quit); | 51 | connect(this, &WaylandConfig::initialized, &m_syncLoop, &QEventLoop::quit); | ||
48 | 52 | | |||
49 | QTimer::singleShot(1000, this, [this] { | 53 | QTimer::singleShot(1000, this, [this] { | ||
50 | if (m_syncLoop.isRunning()) { | 54 | if (m_syncLoop.isRunning()) { | ||
51 | qCWarning(KSCREEN_WAYLAND) << "Connection to Wayland server at socket:" | 55 | qCWarning(KSCREEN_WAYLAND) << "Connection to Wayland server at socket:" | ||
52 | << m_connection->socketName() << "timed out."; | 56 | << m_connection->socketName() << "timed out."; | ||
53 | m_syncLoop.quit(); | 57 | m_syncLoop.quit(); | ||
54 | m_thread->quit(); | 58 | m_thread->quit(); | ||
55 | m_thread->wait(); | 59 | m_thread->wait(); | ||
56 | } | 60 | } | ||
57 | }); | 61 | }); | ||
58 | 62 | | |||
63 | initKWinTabletMode(); | ||||
59 | initConnection(); | 64 | initConnection(); | ||
60 | m_syncLoop.exec(); | 65 | m_syncLoop.exec(); | ||
61 | } | 66 | } | ||
62 | 67 | | |||
63 | WaylandConfig::~WaylandConfig() | 68 | WaylandConfig::~WaylandConfig() | ||
64 | { | 69 | { | ||
65 | m_thread->quit(); | 70 | m_thread->quit(); | ||
66 | m_thread->wait(); | 71 | m_thread->wait(); | ||
67 | m_syncLoop.quit(); | 72 | m_syncLoop.quit(); | ||
68 | } | 73 | } | ||
69 | 74 | | |||
75 | void WaylandConfig::initKWinTabletMode() | ||||
76 | { | ||||
77 | auto *interface = new OrgKdeKWinTabletModeManagerInterface(QStringLiteral("org.kde.KWin"), | ||||
78 | QStringLiteral("/org/kde/KWin"), | ||||
79 | QDBusConnection::sessionBus(), this); | ||||
80 | if (!interface->isValid()) { | ||||
81 | m_tabletModeAvailable = false; | ||||
82 | m_tabletModeEngaged = false; | ||||
83 | return; | ||||
84 | } | ||||
85 | | ||||
86 | m_tabletModeAvailable = interface->tabletModeAvailable(); | ||||
87 | m_tabletModeEngaged = interface->tabletMode(); | ||||
88 | | ||||
89 | connect(interface, &OrgKdeKWinTabletModeManagerInterface::tabletModeChanged, | ||||
90 | this, [this](bool tabletMode) { | ||||
91 | if (m_tabletModeEngaged == tabletMode) { | ||||
92 | return; | ||||
93 | } | ||||
94 | m_tabletModeEngaged = tabletMode; | ||||
95 | if (!m_blockSignals && m_initializingOutputs.empty()) { | ||||
96 | Q_EMIT configChanged(); | ||||
97 | } | ||||
98 | } | ||||
99 | ); | ||||
100 | connect(interface, &OrgKdeKWinTabletModeManagerInterface::tabletModeAvailableChanged, | ||||
101 | this, [this](bool available) { | ||||
102 | if (m_tabletModeAvailable == available) { | ||||
103 | return; | ||||
104 | } | ||||
105 | m_tabletModeAvailable = available; | ||||
106 | if (!m_blockSignals && m_initializingOutputs.empty()) { | ||||
107 | Q_EMIT configChanged(); | ||||
108 | } | ||||
109 | }); | ||||
110 | } | ||||
111 | | ||||
70 | void WaylandConfig::initConnection() | 112 | void WaylandConfig::initConnection() | ||
71 | { | 113 | { | ||
72 | m_thread = new QThread(this); | 114 | m_thread = new QThread(this); | ||
73 | m_connection = new KWayland::Client::ConnectionThread; | 115 | m_connection = new KWayland::Client::ConnectionThread; | ||
74 | 116 | | |||
75 | connect(m_connection, &KWayland::Client::ConnectionThread::connected, | 117 | connect(m_connection, &KWayland::Client::ConnectionThread::connected, | ||
76 | this, &WaylandConfig::setupRegistry, Qt::QueuedConnection); | 118 | this, &WaylandConfig::setupRegistry, Qt::QueuedConnection); | ||
77 | 119 | | |||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | |||||
222 | } | 264 | } | ||
223 | 265 | | |||
224 | KScreen::ConfigPtr WaylandConfig::currentConfig() | 266 | KScreen::ConfigPtr WaylandConfig::currentConfig() | ||
225 | { | 267 | { | ||
226 | // TODO: do this setScreen call less clunky | 268 | // TODO: do this setScreen call less clunky | ||
227 | m_kscreenConfig->setScreen(m_screen->toKScreenScreen(m_kscreenConfig)); | 269 | m_kscreenConfig->setScreen(m_screen->toKScreenScreen(m_kscreenConfig)); | ||
228 | 270 | | |||
229 | auto features = Config::Feature::Writable | Config::Feature::PerOutputScaling; | 271 | auto features = Config::Feature::Writable | Config::Feature::PerOutputScaling; | ||
272 | // TODO: enable new features when all patches have landed | ||||
273 | // const auto features = Config::Feature::Writable | Config::Feature::PerOutputScaling | ||||
274 | // | Config::Feature::AutoRotation | Config::Feature::TabletMode; | ||||
230 | m_kscreenConfig->setSupportedFeatures(features); | 275 | m_kscreenConfig->setSupportedFeatures(features); | ||
231 | m_kscreenConfig->setValid(m_connection->display()); | 276 | m_kscreenConfig->setValid(m_connection->display()); | ||
232 | 277 | | |||
233 | KScreen::ScreenPtr screen = m_kscreenConfig->screen(); | 278 | KScreen::ScreenPtr screen = m_kscreenConfig->screen(); | ||
234 | m_screen->updateKScreenScreen(screen); | 279 | m_screen->updateKScreenScreen(screen); | ||
235 | 280 | | |||
236 | //Removing removed outputs | 281 | //Removing removed outputs | ||
237 | const KScreen::OutputList outputs = m_kscreenConfig->outputs(); | 282 | const KScreen::OutputList outputs = m_kscreenConfig->outputs(); | ||
Show All 15 Lines | 297 | if (kscreenOutput && m_outputMap.count() == 1) { | |||
253 | kscreenOutput->setPrimary(true); | 298 | kscreenOutput->setPrimary(true); | ||
254 | } else if (m_outputMap.count() > 1) { | 299 | } else if (m_outputMap.count() > 1) { | ||
255 | // primaryScreen concept doesn't exist in kwayland, so we don't set one | 300 | // primaryScreen concept doesn't exist in kwayland, so we don't set one | ||
256 | } | 301 | } | ||
257 | output->updateKScreenOutput(kscreenOutput); | 302 | output->updateKScreenOutput(kscreenOutput); | ||
258 | } | 303 | } | ||
259 | m_kscreenConfig->setOutputs(kscreenOutputs); | 304 | m_kscreenConfig->setOutputs(kscreenOutputs); | ||
260 | 305 | | |||
306 | m_kscreenConfig->setTabletModeAvailable(m_tabletModeAvailable); | ||||
307 | m_kscreenConfig->setTabletModeEngaged(m_tabletModeEngaged); | ||||
308 | | ||||
261 | return m_kscreenConfig; | 309 | return m_kscreenConfig; | ||
262 | } | 310 | } | ||
263 | 311 | | |||
264 | QMap<int, WaylandOutput*> WaylandConfig::outputMap() const | 312 | QMap<int, WaylandOutput*> WaylandConfig::outputMap() const | ||
265 | { | 313 | { | ||
266 | return m_outputMap; | 314 | return m_outputMap; | ||
267 | } | 315 | } | ||
268 | 316 | | |||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |