diff --git a/autotests/integration/pointer_input.cpp b/autotests/integration/pointer_input.cpp index 4b3b3017b0..15b719cde0 100644 --- a/autotests/integration/pointer_input.cpp +++ b/autotests/integration/pointer_input.cpp @@ -1620,8 +1620,8 @@ void PointerInputTest::testResizeCursor() // load the fallback cursor (arrow cursor) const PlatformCursorImage arrowCursor = loadReferenceThemeCursor(Qt::ArrowCursor); QVERIFY(!arrowCursor.isNull()); - QCOMPARE(kwinApp()->platform()->cursorImage().image(), arrowCursor.image()); - QCOMPARE(kwinApp()->platform()->cursorImage().hotSpot(), arrowCursor.hotSpot()); + QCOMPARE(kwinApp()->cursorImage().image(), arrowCursor.image()); + QCOMPARE(kwinApp()->cursorImage().hotSpot(), arrowCursor.hotSpot()); // we need a pointer to get the enter event auto pointer = m_seat->createPointer(m_seat); @@ -1679,16 +1679,16 @@ void PointerInputTest::testResizeCursor() QFETCH(KWin::CursorShape, cursorShape); const PlatformCursorImage resizeCursor = loadReferenceThemeCursor(cursorShape); QVERIFY(!resizeCursor.isNull()); - QCOMPARE(kwinApp()->platform()->cursorImage().image(), resizeCursor.image()); - QCOMPARE(kwinApp()->platform()->cursorImage().hotSpot(), resizeCursor.hotSpot()); + QCOMPARE(kwinApp()->cursorImage().image(), resizeCursor.image()); + QCOMPARE(kwinApp()->cursorImage().hotSpot(), resizeCursor.hotSpot()); // finish resizing the window Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++); Test::pointerButtonReleased(BTN_RIGHT, timestamp++); QVERIFY(!window->isInteractiveResize()); - QCOMPARE(kwinApp()->platform()->cursorImage().image(), arrowCursor.image()); - QCOMPARE(kwinApp()->platform()->cursorImage().hotSpot(), arrowCursor.hotSpot()); + QCOMPARE(kwinApp()->cursorImage().image(), arrowCursor.image()); + QCOMPARE(kwinApp()->cursorImage().hotSpot(), arrowCursor.hotSpot()); } void PointerInputTest::testMoveCursor() @@ -1707,8 +1707,8 @@ void PointerInputTest::testMoveCursor() // load the fallback cursor (arrow cursor) const PlatformCursorImage arrowCursor = loadReferenceThemeCursor(Qt::ArrowCursor); QVERIFY(!arrowCursor.isNull()); - QCOMPARE(kwinApp()->platform()->cursorImage().image(), arrowCursor.image()); - QCOMPARE(kwinApp()->platform()->cursorImage().hotSpot(), arrowCursor.hotSpot()); + QCOMPARE(kwinApp()->cursorImage().image(), arrowCursor.image()); + QCOMPARE(kwinApp()->cursorImage().hotSpot(), arrowCursor.hotSpot()); // we need a pointer to get the enter event auto pointer = m_seat->createPointer(m_seat); @@ -1746,16 +1746,16 @@ void PointerInputTest::testMoveCursor() const PlatformCursorImage sizeAllCursor = loadReferenceThemeCursor(Qt::SizeAllCursor); QVERIFY(!sizeAllCursor.isNull()); - QCOMPARE(kwinApp()->platform()->cursorImage().image(), sizeAllCursor.image()); - QCOMPARE(kwinApp()->platform()->cursorImage().hotSpot(), sizeAllCursor.hotSpot()); + QCOMPARE(kwinApp()->cursorImage().image(), sizeAllCursor.image()); + QCOMPARE(kwinApp()->cursorImage().hotSpot(), sizeAllCursor.hotSpot()); // finish moving the window Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++); Test::pointerButtonReleased(BTN_LEFT, timestamp++); QVERIFY(!window->isInteractiveMove()); - QCOMPARE(kwinApp()->platform()->cursorImage().image(), arrowCursor.image()); - QCOMPARE(kwinApp()->platform()->cursorImage().hotSpot(), arrowCursor.hotSpot()); + QCOMPARE(kwinApp()->cursorImage().image(), arrowCursor.image()); + QCOMPARE(kwinApp()->cursorImage().hotSpot(), arrowCursor.hotSpot()); } void PointerInputTest::testHideShowCursor() diff --git a/autotests/integration/window_selection_test.cpp b/autotests/integration/window_selection_test.cpp index 370ec2b047..c1a03f9d15 100644 --- a/autotests/integration/window_selection_test.cpp +++ b/autotests/integration/window_selection_test.cpp @@ -107,7 +107,7 @@ void TestWindowSelection::testSelectOnWindowPointer() // start the interaction QCOMPARE(input()->isSelectingWindow(), false); - kwinApp()->platform()->startInteractiveWindowSelection(callback); + kwinApp()->startInteractiveWindowSelection(callback); QCOMPARE(input()->isSelectingWindow(), true); QVERIFY(!selectedWindow); QCOMPARE(keyboardLeftSpy.count(), 0); @@ -187,7 +187,7 @@ void TestWindowSelection::testSelectOnWindowKeyboard() // start the interaction QCOMPARE(input()->isSelectingWindow(), false); - kwinApp()->platform()->startInteractiveWindowSelection(callback); + kwinApp()->startInteractiveWindowSelection(callback); QCOMPARE(input()->isSelectingWindow(), true); QVERIFY(!selectedWindow); QCOMPARE(keyboardLeftSpy.count(), 0); @@ -249,7 +249,7 @@ void TestWindowSelection::testSelectOnWindowTouch() // start the interaction QCOMPARE(input()->isSelectingWindow(), false); - kwinApp()->platform()->startInteractiveWindowSelection(callback); + kwinApp()->startInteractiveWindowSelection(callback); QCOMPARE(input()->isSelectingWindow(), true); QVERIFY(!selectedWindow); @@ -263,7 +263,7 @@ void TestWindowSelection::testSelectOnWindowTouch() // with movement selectedWindow = nullptr; - kwinApp()->platform()->startInteractiveWindowSelection(callback); + kwinApp()->startInteractiveWindowSelection(callback); Test::touchDown(0, window->frameGeometry().bottomRight() + QPoint(20, 20), timestamp++); QVERIFY(!selectedWindow); Test::touchMotion(0, window->frameGeometry().bottomRight() - QPoint(1, 1), timestamp++); @@ -276,7 +276,7 @@ void TestWindowSelection::testSelectOnWindowTouch() Test::touchDown(0, window->frameGeometry().center(), timestamp++); QVERIFY(touchStartedSpy.wait()); selectedWindow = nullptr; - kwinApp()->platform()->startInteractiveWindowSelection(callback); + kwinApp()->startInteractiveWindowSelection(callback); QCOMPARE(input()->isSelectingWindow(), true); QVERIFY(touchCanceledSpy.wait()); QVERIFY(!selectedWindow); @@ -318,7 +318,7 @@ void TestWindowSelection::testCancelOnWindowPointer() // start the interaction QCOMPARE(input()->isSelectingWindow(), false); - kwinApp()->platform()->startInteractiveWindowSelection(callback); + kwinApp()->startInteractiveWindowSelection(callback); QCOMPARE(input()->isSelectingWindow(), true); QVERIFY(!selectedWindow); QCOMPARE(keyboardLeftSpy.count(), 0); @@ -373,7 +373,7 @@ void TestWindowSelection::testCancelOnWindowKeyboard() // start the interaction QCOMPARE(input()->isSelectingWindow(), false); - kwinApp()->platform()->startInteractiveWindowSelection(callback); + kwinApp()->startInteractiveWindowSelection(callback); QCOMPARE(input()->isSelectingWindow(), true); QVERIFY(!selectedWindow); QCOMPARE(keyboardLeftSpy.count(), 0); @@ -428,7 +428,7 @@ void TestWindowSelection::testSelectPointPointer() // start the interaction QCOMPARE(input()->isSelectingWindow(), false); - kwinApp()->platform()->startInteractivePositionSelection(callback); + kwinApp()->startInteractivePositionSelection(callback); QCOMPARE(input()->isSelectingWindow(), true); QCOMPARE(point, QPoint()); QCOMPARE(keyboardLeftSpy.count(), 0); @@ -441,7 +441,7 @@ void TestWindowSelection::testSelectPointPointer() // trying again should not be allowed QPoint point2; - kwinApp()->platform()->startInteractivePositionSelection([&point2](const QPoint &p) { + kwinApp()->startInteractivePositionSelection([&point2](const QPoint &p) { point2 = p; }); QCOMPARE(point2, QPoint(-1, -1)); @@ -492,7 +492,7 @@ void TestWindowSelection::testSelectPointTouch() // start the interaction QCOMPARE(input()->isSelectingWindow(), false); - kwinApp()->platform()->startInteractivePositionSelection(callback); + kwinApp()->startInteractivePositionSelection(callback); QCOMPARE(input()->isSelectingWindow(), true); QCOMPARE(point, QPoint()); diff --git a/src/backends/x11/standalone/x11_standalone_platform.cpp b/src/backends/x11/standalone/x11_standalone_platform.cpp index b7c9995bd9..898a48af0e 100644 --- a/src/backends/x11/standalone/x11_standalone_platform.cpp +++ b/src/backends/x11/standalone/x11_standalone_platform.cpp @@ -241,12 +241,7 @@ void X11StandalonePlatform::startInteractivePositionSelection(std::function X11StandalonePlatform::createOutline(Outline *outline) { - // first try composited Outline - auto ret = Platform::createOutline(outline); - if (!ret) { - ret = std::make_unique(outline); - } - return ret; + return std::make_unique(outline); } void X11StandalonePlatform::createEffectsHandler(Compositor *compositor, Scene *scene) diff --git a/src/backends/x11/standalone/x11_standalone_platform.h b/src/backends/x11/standalone/x11_standalone_platform.h index 11792df64b..91b3b7ea39 100644 --- a/src/backends/x11/standalone/x11_standalone_platform.h +++ b/src/backends/x11/standalone/x11_standalone_platform.h @@ -27,6 +27,13 @@ class WindowSelector; class X11EventFilter; class X11Output; class X11Keyboard; +class Edge; +class ScreenEdges; +class Outline; +class OutlineVisual; +class Compositor; +class Scene; +class Window; class KWIN_EXPORT X11StandalonePlatform : public Platform { @@ -38,19 +45,20 @@ public: bool initialize() override; std::unique_ptr createOpenGLBackend() override; - std::unique_ptr createScreenEdge(ScreenEdges *parent) override; - void createPlatformCursor(QObject *parent = nullptr) override; - void startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName = QByteArray()) override; - void startInteractivePositionSelection(std::function callback) override; - PlatformCursorImage cursorImage() const override; - std::unique_ptr createOutline(Outline *outline) override; - void createEffectsHandler(Compositor *compositor, Scene *scene) override; QVector supportedCompositors() const override; void initOutputs(); void scheduleUpdateOutputs(); void updateOutputs(); + std::unique_ptr createScreenEdge(ScreenEdges *parent); + void createPlatformCursor(QObject *parent = nullptr); + void startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName = QByteArray()); + void startInteractivePositionSelection(std::function callback); + PlatformCursorImage cursorImage() const; + std::unique_ptr createOutline(Outline *outline); + void createEffectsHandler(Compositor *compositor, Scene *scene); + X11Keyboard *keyboard() const; RenderLoop *renderLoop() const; Outputs outputs() const override; diff --git a/src/composite.cpp b/src/composite.cpp index 2efe69ec7e..35c016013b 100644 --- a/src/composite.cpp +++ b/src/composite.cpp @@ -398,7 +398,7 @@ void Compositor::startupWithWorkspace() } // Sets also the 'effects' pointer. - kwinApp()->platform()->createEffectsHandler(this, m_scene.get()); + kwinApp()->createEffectsHandler(this, m_scene.get()); Q_EMIT compositingToggled(true); diff --git a/src/core/platform.cpp b/src/core/platform.cpp index 866e935aa1..7360073e44 100644 --- a/src/core/platform.cpp +++ b/src/core/platform.cpp @@ -9,18 +9,12 @@ #include "platform.h" -#include "composite.h" -#include "cursor.h" #include "dmabuftexture.h" -#include "effects.h" #include "inputbackend.h" #include "openglbackend.h" -#include "outline.h" #include "output.h" #include "outputconfiguration.h" -#include "pointer_input.h" #include "qpainterbackend.h" -#include "screenedge.h" namespace KWin { @@ -35,12 +29,6 @@ Platform::~Platform() { } -PlatformCursorImage Platform::cursorImage() const -{ - Cursor *cursor = Cursors::self()->currentCursor(); - return PlatformCursorImage(cursor->image(), cursor->hotspot()); -} - std::unique_ptr Platform::createInputBackend() { return nullptr; @@ -71,16 +59,6 @@ std::shared_ptr Platform::createDmaBufTexture(const DmaBufParams return createDmaBufTexture({attribs.width, attribs.height}, attribs.format, attribs.modifier); } -std::unique_ptr Platform::createScreenEdge(ScreenEdges *edges) -{ - return std::make_unique(edges); -} - -void Platform::createPlatformCursor(QObject *parent) -{ - new InputRedirectionCursor(parent); -} - bool Platform::applyOutputChanges(const OutputConfiguration &config) { const auto availableOutputs = outputs(); @@ -142,37 +120,6 @@ void Platform::setSceneEglDisplay(EGLDisplay display) m_eglDisplay = display; } -void Platform::startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName) -{ - if (!input()) { - callback(nullptr); - return; - } - input()->startInteractiveWindowSelection(callback, cursorName); -} - -void Platform::startInteractivePositionSelection(std::function callback) -{ - if (!input()) { - callback(QPoint(-1, -1)); - return; - } - input()->startInteractivePositionSelection(callback); -} - -std::unique_ptr Platform::createOutline(Outline *outline) -{ - if (Compositor::compositing()) { - return std::make_unique(outline); - } - return nullptr; -} - -void Platform::createEffectsHandler(Compositor *compositor, Scene *scene) -{ - new EffectsHandlerImpl(compositor, scene); -} - QString Platform::supportInformation() const { return QStringLiteral("Name: %1\n").arg(metaObject()->className()); diff --git a/src/core/platform.h b/src/core/platform.h index f252be2b0e..6cfbdbf4d2 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -12,28 +12,19 @@ #include #include -#include #include -#include #include #include namespace KWin { -class Window; class Output; -class Edge; -class Compositor; class DmaBufTexture; class InputBackend; class OpenGLBackend; -class Outline; -class OutlineVisual; class QPainterBackend; -class Scene; -class ScreenEdges; class OutputConfiguration; struct DmaBufParams; @@ -63,16 +54,6 @@ public: virtual std::shared_ptr createDmaBufTexture(const QSize &size, quint32 format, const uint64_t modifier); std::shared_ptr createDmaBufTexture(const DmaBufParams &attributes); - /** - * Allows the platform to create a platform specific screen edge. - * The default implementation creates a Edge. - */ - virtual std::unique_ptr createScreenEdge(ScreenEdges *parent); - /** - * Allows the platform to create a platform specific Cursor. - * The default implementation creates an InputRedirectionCursor. - */ - virtual void createPlatformCursor(QObject *parent = nullptr); /** * The EGLDisplay used by the compositing scene. */ @@ -92,51 +73,6 @@ public: */ void setSceneEglGlobalShareContext(EGLContext context); - /** - * Starts an interactive window selection process. - * - * Once the user selected a window the @p callback is invoked with the selected Window as - * argument. In case the user cancels the interactive window selection or selecting a window is currently - * not possible (e.g. screen locked) the @p callback is invoked with a @c nullptr argument. - * - * During the interactive window selection the cursor is turned into a crosshair cursor unless - * @p cursorName is provided. The argument @p cursorName is a QByteArray instead of Qt::CursorShape - * to support the "pirate" cursor for kill window which is not wrapped by Qt::CursorShape. - * - * The default implementation forwards to InputRedirection. - * - * @param callback The function to invoke once the interactive window selection ends - * @param cursorName The optional name of the cursor shape to use, default is crosshair - */ - virtual void startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName = QByteArray()); - - /** - * Starts an interactive position selection process. - * - * Once the user selected a position on the screen the @p callback is invoked with - * the selected point as argument. In case the user cancels the interactive position selection - * or selecting a position is currently not possible (e.g. screen locked) the @p callback - * is invoked with a point at @c -1 as x and y argument. - * - * During the interactive window selection the cursor is turned into a crosshair cursor. - * - * The default implementation forwards to InputRedirection. - * - * @param callback The function to invoke once the interactive position selection ends - */ - virtual void startInteractivePositionSelection(std::function callback); - - /** - * Returns a PlatformCursorImage. By default this is created by softwareCursor and - * softwareCursorHotspot. An implementing subclass can use this to provide a better - * suited PlatformCursorImage. - * - * @see softwareCursor - * @see softwareCursorHotspot - * @since 5.9 - */ - virtual PlatformCursorImage cursorImage() const; - bool isReady() const { return m_ready; @@ -166,17 +102,6 @@ public: m_initialOutputScale = scale; } - /** - * Creates the OutlineVisual for the given @p outline. - * Default implementation creates an OutlineVisual suited for composited usage. - */ - virtual std::unique_ptr createOutline(Outline *outline); - - /** - * Default implementation creates an EffectsHandlerImp; - */ - virtual void createEffectsHandler(Compositor *compositor, Scene *scene); - /** * The CompositingTypes supported by the Platform. * The first item should be the most preferred one. diff --git a/src/dbusinterface.cpp b/src/dbusinterface.cpp index 8d377b6462..5509ff9f38 100644 --- a/src/dbusinterface.cpp +++ b/src/dbusinterface.cpp @@ -17,7 +17,6 @@ #include "atoms.h" #include "composite.h" #include "core/output.h" -#include "core/platform.h" #include "core/renderbackend.h" #include "debug_console.h" #include "kwinadaptor.h" @@ -202,7 +201,7 @@ QVariantMap DBusInterface::queryWindowInfo() { m_replyQueryWindowInfo = message(); setDelayedReply(true); - kwinApp()->platform()->startInteractiveWindowSelection( + kwinApp()->startInteractiveWindowSelection( [this](Window *t) { if (!t) { QDBusConnection::sessionBus().send(m_replyQueryWindowInfo.createErrorReply( diff --git a/src/effects.cpp b/src/effects.cpp index 9dfb0040f8..1c6778f28a 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -38,7 +38,6 @@ #include "screenlockerwatcher.h" #endif #include "composite.h" -#include "core/platform.h" #include "decorations/decorationbridge.h" #include "inputmethod.h" #include "inputpanelv1window.h" @@ -1694,7 +1693,7 @@ void EffectsHandlerImpl::highlightWindows(const QVector &windows PlatformCursorImage EffectsHandlerImpl::cursorImage() const { - return kwinApp()->platform()->cursorImage(); + return kwinApp()->cursorImage(); } void EffectsHandlerImpl::hideCursor() @@ -1709,7 +1708,7 @@ void EffectsHandlerImpl::showCursor() void EffectsHandlerImpl::startInteractiveWindowSelection(std::function callback) { - kwinApp()->platform()->startInteractiveWindowSelection([callback](KWin::Window *window) { + kwinApp()->startInteractiveWindowSelection([callback](KWin::Window *window) { if (window && window->effectWindow()) { callback(window->effectWindow()); } else { @@ -1720,7 +1719,7 @@ void EffectsHandlerImpl::startInteractiveWindowSelection(std::function callback) { - kwinApp()->platform()->startInteractivePositionSelection(callback); + kwinApp()->startInteractivePositionSelection(callback); } void EffectsHandlerImpl::showOnScreenMessage(const QString &message, const QString &iconName) diff --git a/src/killwindow.cpp b/src/killwindow.cpp index a079b5cc93..a56c9f21c1 100644 --- a/src/killwindow.cpp +++ b/src/killwindow.cpp @@ -9,7 +9,6 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "killwindow.h" -#include "core/platform.h" #include "main.h" #include "osd.h" #include "unmanaged.h" @@ -32,7 +31,7 @@ void KillWindow::start() { OSD::show(i18n("Select window to force close with left click or enter.\nEscape or right click to cancel."), QStringLiteral("window-close")); - kwinApp()->platform()->startInteractiveWindowSelection( + kwinApp()->startInteractiveWindowSelection( [](KWin::Window *t) { OSD::hide(); if (!t) { diff --git a/src/main.cpp b/src/main.cpp index 96b776f7c8..d1abc3d3ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,15 +15,16 @@ #include "colormanager.h" #include "composite.h" #include "core/platform.h" +#include "core/session.h" #include "cursor.h" +#include "effects.h" #include "input.h" #include "inputmethod.h" #include "options.h" +#include "outline.h" #include "pluginmanager.h" -#if KWIN_BUILD_SCREENLOCKER -#include "screenlockerwatcher.h" -#endif -#include "core/session.h" +#include "pointer_input.h" +#include "screenedge.h" #include "sm.h" #include "tabletmodemanager.h" #include "utils/xcbutils.h" @@ -31,6 +32,10 @@ #include "workspace.h" #include "x11eventfilter.h" +#if KWIN_BUILD_SCREENLOCKER +#include "screenlockerwatcher.h" +#endif + #include // KDE @@ -258,7 +263,7 @@ void Application::createInput() #endif auto input = InputRedirection::create(this); input->init(); - m_platform->createPlatformCursor(this); + createPlatformCursor(this); } void Application::createAtoms() @@ -331,6 +336,29 @@ void Application::destroyInputMethod() m_inputMethod.reset(); } +std::unique_ptr Application::createScreenEdge(ScreenEdges *edges) +{ + return std::make_unique(edges); +} + +void Application::createPlatformCursor(QObject *parent) +{ + new InputRedirectionCursor(parent); +} + +std::unique_ptr Application::createOutline(Outline *outline) +{ + if (Compositor::compositing()) { + return std::make_unique(outline); + } + return nullptr; +} + +void Application::createEffectsHandler(Compositor *compositor, Scene *scene) +{ + new EffectsHandlerImpl(compositor, scene); +} + void Application::registerEventFilter(X11EventFilter *filter) { if (filter->isGenericEvent()) { @@ -629,4 +657,28 @@ ScreenLockerWatcher *Application::screenLockerWatcher() const } #endif +PlatformCursorImage Application::cursorImage() const +{ + Cursor *cursor = Cursors::self()->currentCursor(); + return PlatformCursorImage(cursor->image(), cursor->hotspot()); +} + +void Application::startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName) +{ + if (!input()) { + callback(nullptr); + return; + } + input()->startInteractiveWindowSelection(callback, cursorName); +} + +void Application::startInteractivePositionSelection(std::function callback) +{ + if (!input()) { + callback(QPoint(-1, -1)); + return; + } + input()->startInteractivePositionSelection(callback); +} + } // namespace diff --git a/src/main.h b/src/main.h index a2a2a0859e..aaf342ad46 100644 --- a/src/main.h +++ b/src/main.h @@ -36,6 +36,13 @@ class ColorManager; class ScreenLockerWatcher; class TabletModeManager; class XwaylandInterface; +class Edge; +class ScreenEdges; +class Outline; +class OutlineVisual; +class Compositor; +class Scene; +class Window; class XcbEventFilter : public QAbstractNativeEventFilter { @@ -245,6 +252,11 @@ public: void createAtoms(); void destroyAtoms(); + virtual std::unique_ptr createScreenEdge(ScreenEdges *parent); + virtual void createPlatformCursor(QObject *parent = nullptr); + virtual std::unique_ptr createOutline(Outline *outline); + virtual void createEffectsHandler(Compositor *compositor, Scene *scene); + static void setupMalloc(); static void setupLocalizedString(); @@ -256,6 +268,51 @@ public: ScreenLockerWatcher *screenLockerWatcher() const; #endif + /** + * Starts an interactive window selection process. + * + * Once the user selected a window the @p callback is invoked with the selected Window as + * argument. In case the user cancels the interactive window selection or selecting a window is currently + * not possible (e.g. screen locked) the @p callback is invoked with a @c nullptr argument. + * + * During the interactive window selection the cursor is turned into a crosshair cursor unless + * @p cursorName is provided. The argument @p cursorName is a QByteArray instead of Qt::CursorShape + * to support the "pirate" cursor for kill window which is not wrapped by Qt::CursorShape. + * + * The default implementation forwards to InputRedirection. + * + * @param callback The function to invoke once the interactive window selection ends + * @param cursorName The optional name of the cursor shape to use, default is crosshair + */ + virtual void startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName = QByteArray()); + + /** + * Starts an interactive position selection process. + * + * Once the user selected a position on the screen the @p callback is invoked with + * the selected point as argument. In case the user cancels the interactive position selection + * or selecting a position is currently not possible (e.g. screen locked) the @p callback + * is invoked with a point at @c -1 as x and y argument. + * + * During the interactive window selection the cursor is turned into a crosshair cursor. + * + * The default implementation forwards to InputRedirection. + * + * @param callback The function to invoke once the interactive position selection ends + */ + virtual void startInteractivePositionSelection(std::function callback); + + /** + * Returns a PlatformCursorImage. By default this is created by softwareCursor and + * softwareCursorHotspot. An implementing subclass can use this to provide a better + * suited PlatformCursorImage. + * + * @see softwareCursor + * @see softwareCursorHotspot + * @since 5.9 + */ + virtual PlatformCursorImage cursorImage() const; + Q_SIGNALS: void x11ConnectionChanged(); void x11ConnectionAboutToBeDestroyed(); diff --git a/src/main_x11.cpp b/src/main_x11.cpp index 34d49eeb0a..91c7968667 100644 --- a/src/main_x11.cpp +++ b/src/main_x11.cpp @@ -15,6 +15,8 @@ #include "backends/x11/standalone/x11_standalone_platform.h" #include "core/platform.h" #include "core/session.h" +#include "outline.h" +#include "screenedge.h" #include "sm.h" #include "tabletmodemanager.h" #include "utils/xcbutils.h" @@ -196,6 +198,45 @@ void ApplicationX11::setReplace(bool replace) m_replace = replace; } +std::unique_ptr ApplicationX11::createScreenEdge(ScreenEdges *parent) +{ + return static_cast(platform())->createScreenEdge(parent); +} + +void ApplicationX11::createPlatformCursor(QObject *parent) +{ + static_cast(platform())->createPlatformCursor(parent); +} + +std::unique_ptr ApplicationX11::createOutline(Outline *outline) +{ + // first try composited Outline + if (auto outlineVisual = Application::createOutline(outline)) { + return outlineVisual; + } + return static_cast(platform())->createOutline(outline); +} + +void ApplicationX11::createEffectsHandler(Compositor *compositor, Scene *scene) +{ + static_cast(platform())->createEffectsHandler(compositor, scene); +} + +void ApplicationX11::startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName) +{ + static_cast(platform())->startInteractiveWindowSelection(callback, cursorName); +} + +void ApplicationX11::startInteractivePositionSelection(std::function callback) +{ + static_cast(platform())->startInteractivePositionSelection(callback); +} + +PlatformCursorImage ApplicationX11::cursorImage() const +{ + return static_cast(platform())->cursorImage(); +} + void ApplicationX11::lostSelection() { sendPostedEvents(); diff --git a/src/main_x11.h b/src/main_x11.h index 54f8a86e2e..e5ce441164 100644 --- a/src/main_x11.h +++ b/src/main_x11.h @@ -24,6 +24,14 @@ public: void setReplace(bool replace); + std::unique_ptr createScreenEdge(ScreenEdges *parent) override; + void createPlatformCursor(QObject *parent = nullptr) override; + std::unique_ptr createOutline(Outline *outline) override; + void createEffectsHandler(Compositor *compositor, Scene *scene) override; + void startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName = QByteArray()) override; + void startInteractivePositionSelection(std::function callback) override; + PlatformCursorImage cursorImage() const override; + protected: void performStartup() override; diff --git a/src/outline.cpp b/src/outline.cpp index 406d67620b..37ac9bb12b 100644 --- a/src/outline.cpp +++ b/src/outline.cpp @@ -11,7 +11,6 @@ #include "outline.h" // KWin #include "composite.h" -#include "core/platform.h" #include "main.h" #include "scripting/scripting.h" #include "utils/common.h" @@ -105,7 +104,7 @@ void Outline::createHelper() if (m_visual) { return; } - m_visual = kwinApp()->platform()->createOutline(this); + m_visual = kwinApp()->createOutline(this); } void Outline::compositingChanged() diff --git a/src/screenedge.cpp b/src/screenedge.cpp index 6651b61fd8..a842c2cfc6 100644 --- a/src/screenedge.cpp +++ b/src/screenedge.cpp @@ -21,7 +21,6 @@ #include #include "core/output.h" -#include "core/platform.h" #include "cursor.h" #include "effects.h" #include "gestures.h" @@ -1166,7 +1165,7 @@ void ScreenEdges::createHorizontalEdge(ElectricBorder border, const QRect &scree std::unique_ptr ScreenEdges::createEdge(ElectricBorder border, int x, int y, int width, int height, Output *output, bool createAction) { - std::unique_ptr edge = kwinApp()->platform()->createScreenEdge(this); + std::unique_ptr edge = kwinApp()->createScreenEdge(this); // Edges can not have negative size. Q_ASSERT(width >= 0); Q_ASSERT(height >= 0);