diff --git a/autotests/integration/no_global_shortcuts_test.cpp b/autotests/integration/no_global_shortcuts_test.cpp index 0de0567420..f806d2456f 100644 --- a/autotests/integration/no_global_shortcuts_test.cpp +++ b/autotests/integration/no_global_shortcuts_test.cpp @@ -80,7 +80,8 @@ void NoGlobalShortcutsTest::initTestCase() { qRegisterMetaType("ElectricBorder"); QSignalSpy applicationStartedSpy(kwinApp(), &Application::started); - QVERIFY(waylandServer()->init(s_socketName, KWin::WaylandServer::InitializationFlag::NoGlobalShortcuts)); + kwinApp()->setSupportsGlobalShortcuts(false); + QVERIFY(waylandServer()->init(s_socketName)); Test::setOutputConfig({ QRect(0, 0, 1280, 1024), QRect(1280, 0, 1280, 1024), diff --git a/src/input.cpp b/src/input.cpp index e2693c627f..a7f9469430 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -2916,7 +2916,6 @@ private: void InputRedirection::setupInputFilters() { - const bool hasGlobalShortcutSupport = waylandServer()->hasGlobalShortcutSupport(); if (kwinApp()->session()->capabilities() & Session::Capability::SwitchTerminal) { m_virtualTerminalFilter = std::make_unique(); installInputEventFilter(m_virtualTerminalFilter.get()); @@ -2934,7 +2933,7 @@ void InputRedirection::setupInputFilters() m_lockscreenFilter = std::make_unique(); installInputEventFilter(m_lockscreenFilter.get()); - if (hasGlobalShortcutSupport) { + if (kwinApp()->supportsGlobalShortcuts()) { m_screenEdgeFilter = std::make_unique(); installInputEventFilter(m_screenEdgeFilter.get()); } @@ -2950,7 +2949,7 @@ void InputRedirection::setupInputFilters() installInputEventFilter(m_tabboxFilter.get()); #endif #if KWIN_BUILD_GLOBALSHORTCUTS - if (hasGlobalShortcutSupport) { + if (kwinApp()->supportsGlobalShortcuts()) { m_globalShortcutFilter = std::make_unique(); installInputEventFilter(m_globalShortcutFilter.get()); } diff --git a/src/keyboard_input.cpp b/src/keyboard_input.cpp index a1dc7ac4cd..f2c91937b6 100644 --- a/src/keyboard_input.cpp +++ b/src/keyboard_input.cpp @@ -154,7 +154,7 @@ void KeyboardInputRedirection::init() update(); }); #if KWIN_BUILD_SCREENLOCKER - if (waylandServer()->hasScreenLockerIntegration()) { + if (kwinApp()->supportsLockScreen()) { connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, &KeyboardInputRedirection::update); } #endif diff --git a/src/main.h b/src/main.h index a0b55dd5c9..e1a691a1a4 100644 --- a/src/main.h +++ b/src/main.h @@ -272,6 +272,15 @@ public: return m_terminating; } + bool initiallyLocked() const; + void setInitiallyLocked(bool locked); + + bool supportsLockScreen() const; + void setSupportsLockScreen(bool set); + + bool supportsGlobalShortcuts() const; + void setSupportsGlobalShortcuts(bool set); + void installNativeX11EventFilter(); void removeNativeX11EventFilter(); @@ -386,6 +395,9 @@ private: #endif bool m_followLocale1 = false; bool m_configLock; + bool m_initiallyLocked = false; + bool m_supportsLockScreen = true; + bool m_supportsGlobalShortcuts = true; KSharedConfigPtr m_config; KSharedConfigPtr m_kxkbConfig; KSharedConfigPtr m_inputConfig; @@ -414,6 +426,36 @@ private: std::unique_ptr m_platformCursor; }; +inline bool Application::initiallyLocked() const +{ + return m_initiallyLocked; +} + +inline void Application::setInitiallyLocked(bool locked) +{ + m_initiallyLocked = locked; +} + +inline bool Application::supportsLockScreen() const +{ + return m_supportsLockScreen; +} + +inline void Application::setSupportsLockScreen(bool set) +{ + m_supportsLockScreen = set; +} + +inline bool Application::supportsGlobalShortcuts() const +{ + return m_supportsGlobalShortcuts; +} + +inline void Application::setSupportsGlobalShortcuts(bool set) +{ + m_supportsGlobalShortcuts = set; +} + inline static Application *kwinApp() { Q_ASSERT(qobject_cast(QCoreApplication::instance())); diff --git a/src/main_wayland.cpp b/src/main_wayland.cpp index 98a58250cc..02e6bbee28 100644 --- a/src/main_wayland.cpp +++ b/src/main_wayland.cpp @@ -555,16 +555,15 @@ int main(int argc, char *argv[]) } KWin::WaylandServer *server = KWin::WaylandServer::create(); - KWin::WaylandServer::InitializationFlags flags; #if KWIN_BUILD_SCREENLOCKER if (parser.isSet(screenLockerOption)) { - flags = KWin::WaylandServer::InitializationFlag::LockScreen; + a.setInitiallyLocked(true); } else if (parser.isSet(noScreenLockerOption)) { - flags = KWin::WaylandServer::InitializationFlag::NoLockScreenIntegration; + a.setSupportsLockScreen(false); } #endif if (parser.isSet(noGlobalShortcutsOption)) { - flags |= KWin::WaylandServer::InitializationFlag::NoGlobalShortcuts; + a.setSupportsGlobalShortcuts(false); } const QString socketName = parser.value(waylandSocketOption); @@ -588,7 +587,7 @@ int main(int argc, char *argv[]) qInfo() << "Accepting client connections on sockets:" << server->display()->socketNames(); } - if (!server->init(flags)) { + if (!server->init()) { std::cerr << "FATAL ERROR: could not create Wayland server" << std::endl; return 1; } diff --git a/src/pointer_input.cpp b/src/pointer_input.cpp index b797266377..3c79d91f73 100644 --- a/src/pointer_input.cpp +++ b/src/pointer_input.cpp @@ -110,7 +110,7 @@ void PointerInputRedirection::init() connect(workspace(), &Workspace::outputsChanged, this, &PointerInputRedirection::updateAfterScreenChange); #if KWIN_BUILD_SCREENLOCKER - if (waylandServer()->hasScreenLockerIntegration()) { + if (kwinApp()->supportsLockScreen()) { connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, [this]() { if (waylandServer()->seat()->hasPointer()) { waylandServer()->seat()->cancelPointerPinchGesture(); @@ -963,7 +963,7 @@ CursorImage::CursorImage(PointerInputRedirection *parent) m_serverCursor.shape = std::make_unique(); #if KWIN_BUILD_SCREENLOCKER - if (waylandServer()->hasScreenLockerIntegration()) { + if (kwinApp()->supportsLockScreen()) { connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, &CursorImage::reevaluteSource); } #endif diff --git a/src/screenlockerwatcher.cpp b/src/screenlockerwatcher.cpp index fac6209aff..a3fb9a48b9 100644 --- a/src/screenlockerwatcher.cpp +++ b/src/screenlockerwatcher.cpp @@ -7,7 +7,6 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "screenlockerwatcher.h" -#include "wayland_server.h" // dbus generated #include "kscreenlocker_interface.h" @@ -22,11 +21,7 @@ ScreenLockerWatcher::ScreenLockerWatcher() : m_serviceWatcher(new QDBusServiceWatcher(this)) , m_locked(false) { - if (waylandServer() && waylandServer()->hasScreenLockerIntegration()) { - connect(waylandServer(), &WaylandServer::initialized, this, &ScreenLockerWatcher::initialize); - } else { - initialize(); - } + initialize(); } void ScreenLockerWatcher::initialize() diff --git a/src/touch_input.cpp b/src/touch_input.cpp index 44042a132a..c267b4c4a7 100644 --- a/src/touch_input.cpp +++ b/src/touch_input.cpp @@ -49,7 +49,7 @@ void TouchInputRedirection::init() InputDeviceHandler::init(); #if KWIN_BUILD_SCREENLOCKER - if (waylandServer()->hasScreenLockerIntegration()) { + if (kwinApp()->supportsLockScreen()) { connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, [this]() { cancel(); // position doesn't matter diff --git a/src/wayland_server.cpp b/src/wayland_server.cpp index f9290b3799..b17d283407 100644 --- a/src/wayland_server.cpp +++ b/src/wayland_server.cpp @@ -305,17 +305,16 @@ bool WaylandServer::start() return m_display->start(); } -bool WaylandServer::init(const QString &socketName, InitializationFlags flags) +bool WaylandServer::init(const QString &socketName) { if (!m_display->addSocketName(socketName)) { return false; } - return init(flags); + return init(); } -bool WaylandServer::init(InitializationFlags flags) +bool WaylandServer::init() { - m_initFlags = flags; m_compositor = new CompositorInterface(m_display, m_display); #if KWIN_BUILD_X11 connect(m_compositor, &CompositorInterface::surfaceCreated, this, [this](SurfaceInterface *surface) { @@ -600,7 +599,7 @@ void WaylandServer::initWorkspace() connect(workspace(), &Workspace::outputAdded, this, &WaylandServer::handleOutputEnabled); connect(workspace(), &Workspace::outputRemoved, this, &WaylandServer::handleOutputDisabled); - if (hasScreenLockerIntegration()) { + if (kwinApp()->supportsLockScreen()) { initScreenLocker(); } @@ -666,7 +665,7 @@ void WaylandServer::initScreenLocker() ScreenLocker::KSldApp::self()->initialize(); - if (m_initFlags.testFlag(InitializationFlag::LockScreen)) { + if (kwinApp()->initiallyLocked()) { ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate); } #endif @@ -787,7 +786,7 @@ XdgSurfaceWindow *WaylandServer::findXdgSurfaceWindow(SurfaceInterface *surface) bool WaylandServer::isScreenLocked() const { #if KWIN_BUILD_SCREENLOCKER - if (!hasScreenLockerIntegration()) { + if (!kwinApp()->supportsLockScreen()) { return false; } return ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::Locked || ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::AcquiringLock; @@ -796,20 +795,6 @@ bool WaylandServer::isScreenLocked() const #endif } -bool WaylandServer::hasScreenLockerIntegration() const -{ -#if KWIN_BUILD_SCREENLOCKER - return !m_initFlags.testFlag(InitializationFlag::NoLockScreenIntegration); -#else - return false; -#endif -} - -bool WaylandServer::hasGlobalShortcutSupport() const -{ - return !m_initFlags.testFlag(InitializationFlag::NoGlobalShortcuts); -} - bool WaylandServer::isKeyboardShortcutsInhibited() const { auto surface = seat()->focusedKeyboardSurface(); diff --git a/src/wayland_server.h b/src/wayland_server.h index bcb26d9960..0cf8978939 100644 --- a/src/wayland_server.h +++ b/src/wayland_server.h @@ -68,18 +68,9 @@ class KWIN_EXPORT WaylandServer : public QObject Q_OBJECT public: - enum class InitializationFlag { - NoOptions = 0x0, - LockScreen = 0x1, - NoLockScreenIntegration = 0x2, - NoGlobalShortcuts = 0x4 - }; - - Q_DECLARE_FLAGS(InitializationFlags, InitializationFlag) - ~WaylandServer() override; - bool init(const QString &socketName, InitializationFlags flags = InitializationFlag::NoOptions); - bool init(InitializationFlags flags = InitializationFlag::NoOptions); + bool init(const QString &socketName); + bool init(); bool start(); @@ -184,15 +175,6 @@ public: * @returns true if screen is locked. */ bool isScreenLocked() const; - /** - * @returns whether integration with KScreenLocker is available. - */ - bool hasScreenLockerIntegration() const; - - /** - * @returns whether any kind of global shortcuts are supported. - */ - bool hasGlobalShortcutSupport() const; void initWorkspace(); @@ -300,7 +282,6 @@ private: PresentationTime *m_presentationTime = nullptr; LinuxDrmSyncObjV1Interface *m_linuxDrmSyncObj = nullptr; QList m_windows; - InitializationFlags m_initFlags; QHash m_waylandOutputs; QHash m_waylandOutputDevices; DrmLeaseManagerV1 *m_leaseManager = nullptr;