From 039dd96f8d15471c086a413ef157650a6dbf317b Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 3 Aug 2022 12:31:27 +0200 Subject: [PATCH] xwaylandinterface: move global to Application --- autotests/integration/kwin_wayland_test.cpp | 18 +++++++---- autotests/integration/kwin_wayland_test.h | 3 +- .../integration/xwaylandserver_crash_test.cpp | 2 +- .../xwaylandserver_restart_test.cpp | 2 +- src/CMakeLists.txt | 1 - src/input.cpp | 6 ++-- src/main.cpp | 5 +++ src/main.h | 2 ++ src/main_wayland.cpp | 5 +++ src/main_wayland.h | 2 ++ src/xwayland/xwayland.h | 2 +- src/xwayland/xwayland_interface.cpp | 32 ------------------- src/xwayland/xwayland_interface.h | 15 ++------- 13 files changed, 36 insertions(+), 59 deletions(-) delete mode 100644 src/xwayland/xwayland_interface.cpp diff --git a/autotests/integration/kwin_wayland_test.cpp b/autotests/integration/kwin_wayland_test.cpp index 2c0bfbd7d5..40e308d75e 100644 --- a/autotests/integration/kwin_wayland_test.cpp +++ b/autotests/integration/kwin_wayland_test.cpp @@ -83,8 +83,7 @@ WaylandTestApplication::~WaylandTestApplication() if (effects) { static_cast(effects)->unloadAllEffects(); } - delete m_xwayland; - m_xwayland = nullptr; + m_xwayland.reset(); destroyVirtualInputDevices(); destroyWorkspace(); destroyInputMethod(); @@ -157,8 +156,8 @@ void WaylandTestApplication::continueStartupWithScreens() void WaylandTestApplication::finalizeStartup() { if (m_xwayland) { - disconnect(m_xwayland, &Xwl::Xwayland::errorOccurred, this, &WaylandTestApplication::finalizeStartup); - disconnect(m_xwayland, &Xwl::Xwayland::started, this, &WaylandTestApplication::finalizeStartup); + disconnect(m_xwayland.get(), &Xwl::Xwayland::errorOccurred, this, &WaylandTestApplication::finalizeStartup); + disconnect(m_xwayland.get(), &Xwl::Xwayland::started, this, &WaylandTestApplication::finalizeStartup); } notifyStarted(); } @@ -179,9 +178,9 @@ void WaylandTestApplication::continueStartupWithScene() return; } - m_xwayland = new Xwl::Xwayland(this); - connect(m_xwayland, &Xwl::Xwayland::errorOccurred, this, &WaylandTestApplication::finalizeStartup); - connect(m_xwayland, &Xwl::Xwayland::started, this, &WaylandTestApplication::finalizeStartup); + m_xwayland = std::make_unique(this); + connect(m_xwayland.get(), &Xwl::Xwayland::errorOccurred, this, &WaylandTestApplication::finalizeStartup); + connect(m_xwayland.get(), &Xwl::Xwayland::started, this, &WaylandTestApplication::finalizeStartup); m_xwayland->start(); } @@ -199,4 +198,9 @@ Test::VirtualInputDevice *WaylandTestApplication::virtualTouch() const { return m_virtualTouch.get(); } + +XwaylandInterface *WaylandTestApplication::xwayland() const +{ + return m_xwayland.get(); +} } diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index 180df8719a..1489b001aa 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -83,6 +83,7 @@ public: Test::VirtualInputDevice *virtualPointer() const; Test::VirtualInputDevice *virtualKeyboard() const; Test::VirtualInputDevice *virtualTouch() const; + XwaylandInterface *xwayland() const override; protected: void performStartup() override; @@ -95,7 +96,7 @@ private: void createVirtualInputDevices(); void destroyVirtualInputDevices(); - Xwl::Xwayland *m_xwayland = nullptr; + std::unique_ptr m_xwayland; QString m_inputMethodServerToStart; std::unique_ptr m_virtualPointer; diff --git a/autotests/integration/xwaylandserver_crash_test.cpp b/autotests/integration/xwaylandserver_crash_test.cpp index cbbba00ef4..272ed86701 100644 --- a/autotests/integration/xwaylandserver_crash_test.cpp +++ b/autotests/integration/xwaylandserver_crash_test.cpp @@ -118,7 +118,7 @@ void XwaylandServerCrashTest::testCrash() // Let's pretend that the Xwayland process has crashed. QSignalSpy x11ConnectionChangedSpy(kwinApp(), &Application::x11ConnectionChanged); QVERIFY(x11ConnectionChangedSpy.isValid()); - Xwl::Xwayland *xwayland = static_cast(XwaylandInterface::self()); + Xwl::Xwayland *xwayland = static_cast(kwinApp()->xwayland()); xwayland->xwaylandLauncher()->process()->terminate(); QVERIFY(x11ConnectionChangedSpy.wait()); diff --git a/autotests/integration/xwaylandserver_restart_test.cpp b/autotests/integration/xwaylandserver_restart_test.cpp index 35d5f2d515..3c1c5f08c8 100644 --- a/autotests/integration/xwaylandserver_restart_test.cpp +++ b/autotests/integration/xwaylandserver_restart_test.cpp @@ -69,7 +69,7 @@ void XwaylandServerRestartTest::testRestart() { // This test verifies that the Xwayland server will be restarted after a crash. - Xwl::Xwayland *xwayland = static_cast(XwaylandInterface::self()); + Xwl::Xwayland *xwayland = static_cast(kwinApp()->xwayland()); // Pretend that the Xwayland process has crashed by sending a SIGKILL to it. QSignalSpy startedSpy(xwayland, &Xwl::Xwayland::started); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12876fe934..d2370a5d47 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -162,7 +162,6 @@ target_sources(kwin PRIVATE xdgshellwindow.cpp xkb.cpp xwaylandwindow.cpp - xwayland/xwayland_interface.cpp ) target_link_libraries(kwin diff --git a/src/input.cpp b/src/input.cpp index 44aaba5b51..5651e6e49c 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -2382,8 +2382,8 @@ static KWaylandServer::AbstractDropHandler *dropHandler(Window *window) return dropTarget; } - if (qobject_cast(window) && xwayland()) { - return xwayland()->xwlDropHandler(); + if (qobject_cast(window) && kwinApp()->xwayland()) { + return kwinApp()->xwayland()->xwlDropHandler(); } return nullptr; @@ -2433,7 +2433,7 @@ public: } m_dragTarget = dragTarget; - if (auto *xwl = xwayland()) { + if (auto *xwl = kwinApp()->xwayland()) { const auto ret = xwl->dragMoveFilter(t, eventPos); if (ret == Xwl::DragEventReply::Ignore) { return false; diff --git a/src/main.cpp b/src/main.cpp index ac3acf4438..27fcc4b6c5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -582,6 +582,11 @@ ColorManager *Application::colorManager() const return m_colorManager.get(); } +XwaylandInterface *Application::xwayland() const +{ + return nullptr; +} + #if KWIN_BUILD_SCREENLOCKER ScreenLockerWatcher *Application::screenLockerWatcher() const { diff --git a/src/main.h b/src/main.h index 0742cdf95a..29c3d6274d 100644 --- a/src/main.h +++ b/src/main.h @@ -35,6 +35,7 @@ class InputMethod; class ColorManager; class ScreenLockerWatcher; class TabletModeManager; +class XwaylandInterface; class XcbEventFilter : public QAbstractNativeEventFilter { @@ -238,6 +239,7 @@ public: PluginManager *pluginManager() const; InputMethod *inputMethod() const; ColorManager *colorManager() const; + virtual XwaylandInterface *xwayland() const; #if KWIN_BUILD_SCREENLOCKER ScreenLockerWatcher *screenLockerWatcher() const; #endif diff --git a/src/main_wayland.cpp b/src/main_wayland.cpp index 3f22f84cb8..55dcbb8890 100644 --- a/src/main_wayland.cpp +++ b/src/main_wayland.cpp @@ -276,6 +276,11 @@ void ApplicationWayland::startSession() } } +XwaylandInterface *ApplicationWayland::xwayland() const +{ + return m_xwayland.get(); +} + } // namespace int main(int argc, char *argv[]) diff --git a/src/main_wayland.h b/src/main_wayland.h index 76bdb6b7c6..bfd3b95c13 100644 --- a/src/main_wayland.h +++ b/src/main_wayland.h @@ -55,6 +55,8 @@ public: m_sessionArgument = session; } + XwaylandInterface *xwayland() const override; + protected: void performStartup() override; diff --git a/src/xwayland/xwayland.h b/src/xwayland/xwayland.h index e777ba5476..d8d9537c1d 100644 --- a/src/xwayland/xwayland.h +++ b/src/xwayland/xwayland.h @@ -30,7 +30,7 @@ class XrandrEventFilter; class XwaylandLauncher; class DataBridge; -class KWIN_EXPORT Xwayland : public XwaylandInterface +class KWIN_EXPORT Xwayland : public QObject, public XwaylandInterface { Q_OBJECT diff --git a/src/xwayland/xwayland_interface.cpp b/src/xwayland/xwayland_interface.cpp deleted file mode 100644 index b34048ad95..0000000000 --- a/src/xwayland/xwayland_interface.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - KWin - the KDE window manager - This file is part of the KDE project. - - SPDX-FileCopyrightText: 2019 Roman Gilg - - SPDX-License-Identifier: GPL-2.0-or-later -*/ -#include "xwayland_interface.h" - -namespace KWin -{ - -XwaylandInterface *s_self = nullptr; - -XwaylandInterface *XwaylandInterface::self() -{ - return s_self; -} - -XwaylandInterface::XwaylandInterface(QObject *parent) - : QObject(parent) -{ - s_self = this; -} - -XwaylandInterface::~XwaylandInterface() -{ - s_self = nullptr; -} - -} // namespace KWin diff --git a/src/xwayland/xwayland_interface.h b/src/xwayland/xwayland_interface.h index 12c3c598d1..cc62bbd85e 100644 --- a/src/xwayland/xwayland_interface.h +++ b/src/xwayland/xwayland_interface.h @@ -37,29 +37,20 @@ enum class DragEventReply { }; } // namespace Xwl -class KWIN_EXPORT XwaylandInterface : public QObject +class KWIN_EXPORT XwaylandInterface { - Q_OBJECT - public: - static XwaylandInterface *self(); - virtual Xwl::DragEventReply dragMoveFilter(Window *target, const QPoint &pos) = 0; virtual KWaylandServer::AbstractDropHandler *xwlDropHandler() = 0; protected: - explicit XwaylandInterface(QObject *parent = nullptr); - ~XwaylandInterface() override; + explicit XwaylandInterface() = default; + virtual ~XwaylandInterface() = default; private: Q_DISABLE_COPY(XwaylandInterface) }; -inline XwaylandInterface *xwayland() -{ - return XwaylandInterface::self(); -} - } // namespace KWin #endif