From 601ef328df7e156d99c5b93f9dc19bfff8fb2de2 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 29 Mar 2022 12:59:02 +0300 Subject: [PATCH] Drop more legacy Workspace.clientArea() overloads With this change, the Workspace would provide clientArea() overloads that take only AbstractOutput and VirtualDesktop. integer ids are obsolete as they are unstable. --- autotests/integration/transient_placement.cpp | 4 +- src/effects.cpp | 22 ++++++----- src/inputpanelv1client.cpp | 2 +- src/scripting/workspace_wrapper.cpp | 32 +++++++++++++++- src/workspace.cpp | 38 +++++-------------- src/workspace.h | 2 - 6 files changed, 55 insertions(+), 45 deletions(-) diff --git a/autotests/integration/transient_placement.cpp b/autotests/integration/transient_placement.cpp index 0eb7a480ff..e319f163d9 100644 --- a/autotests/integration/transient_placement.cpp +++ b/autotests/integration/transient_placement.cpp @@ -478,14 +478,14 @@ void TransientPlacementTest::testXdgPopupWithPanel() plasmaSurface->setPanelBehavior(PlasmaShellSurface::PanelBehavior::AlwaysVisible); // now render and map the window - QVERIFY(workspace()->clientArea(PlacementArea, 0, 1) == workspace()->clientArea(FullScreenArea, 0, 1)); auto dock = Test::renderAndWaitForShown(surface.data(), QSize(1280, 50), Qt::blue); QVERIFY(dock); QCOMPARE(dock->windowType(), NET::Dock); QVERIFY(dock->isDock()); QCOMPARE(dock->frameGeometry(), QRect(0, screens()->geometry(0).height() - 50, 1280, 50)); QCOMPARE(dock->hasStrut(), true); - QVERIFY(workspace()->clientArea(PlacementArea, 0, 1) != workspace()->clientArea(FullScreenArea, 0, 1)); + QCOMPARE(workspace()->clientArea(PlacementArea, dock), QRect(0, 0, 1280, 1024 - 50)); + QCOMPARE(workspace()->clientArea(FullScreenArea, dock), QRect(0, 0, 1280, 1024)); // create parent QScopedPointer parentSurface(Test::createSurface()); diff --git a/src/effects.cpp b/src/effects.cpp index 23a5c5f788..32a6b37de0 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -1264,17 +1264,19 @@ EffectScreen *EffectsHandlerImpl::activeScreen() const return EffectScreenImpl::get(workspace()->activeOutput()); } +static VirtualDesktop *resolveVirtualDesktop(int desktopId) +{ + if (desktopId == 0 || desktopId == -1) { + return VirtualDesktopManager::self()->currentDesktop(); + } else { + return VirtualDesktopManager::self()->desktopForX11Id(desktopId); + } +} + QRect EffectsHandlerImpl::clientArea(clientAreaOption opt, const EffectScreen *screen, int desktop) const { - const VirtualDesktop *virtualDesktop; - if (desktop == 0 || desktop == -1) { - virtualDesktop = VirtualDesktopManager::self()->currentDesktop(); - } else { - virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop); - } - const EffectScreenImpl *screenImpl = static_cast(screen); - return Workspace::self()->clientArea(opt, screenImpl->platformOutput(), virtualDesktop); + return Workspace::self()->clientArea(opt, screenImpl->platformOutput(), resolveVirtualDesktop(desktop)); } QRect EffectsHandlerImpl::clientArea(clientAreaOption opt, const EffectWindow *c) const @@ -1285,7 +1287,9 @@ QRect EffectsHandlerImpl::clientArea(clientAreaOption opt, const EffectWindow *c QRect EffectsHandlerImpl::clientArea(clientAreaOption opt, const QPoint &p, int desktop) const { - return Workspace::self()->clientArea(opt, p, desktop); + const AbstractOutput *output = kwinApp()->platform()->outputAt(p); + const VirtualDesktop *virtualDesktop = resolveVirtualDesktop(desktop); + return Workspace::self()->clientArea(opt, output, virtualDesktop); } QRect EffectsHandlerImpl::virtualScreenGeometry() const diff --git a/src/inputpanelv1client.cpp b/src/inputpanelv1client.cpp index 3eec3f8f0c..84e85d800a 100644 --- a/src/inputpanelv1client.cpp +++ b/src/inputpanelv1client.cpp @@ -114,7 +114,7 @@ void KWin::InputPanelV1Client::reposition() } if (textClient) { cursorRectangle.translate(textClient->bufferGeometry().topLeft()); - const QRect screen = Workspace::self()->clientArea(PlacementArea, cursorRectangle.bottomLeft(), 0); + const QRect screen = Workspace::self()->clientArea(PlacementArea, this, cursorRectangle.bottomLeft()); // Reuse the similar logic like xdg popup QRect popupRect(popupOffset(cursorRectangle, Qt::BottomEdge | Qt::LeftEdge, Qt::RightEdge | Qt::BottomEdge, surface()->size()), surface()->size()); diff --git a/src/scripting/workspace_wrapper.cpp b/src/scripting/workspace_wrapper.cpp index d14ee93799..77be65b12b 100644 --- a/src/scripting/workspace_wrapper.cpp +++ b/src/scripting/workspace_wrapper.cpp @@ -254,9 +254,20 @@ int WorkspaceWrapper::displayHeight() const return displaySize().height(); } +static VirtualDesktop *resolveVirtualDesktop(int desktopId) +{ + if (desktopId == 0 || desktopId == -1) { + return VirtualDesktopManager::self()->currentDesktop(); + } else { + return VirtualDesktopManager::self()->desktopForX11Id(desktopId); + } +} + QRect WorkspaceWrapper::clientArea(ClientAreaOption option, const QPoint &p, int desktop) const { - return Workspace::self()->clientArea(static_cast(option), p, desktop); + const AbstractOutput *output = kwinApp()->platform()->outputAt(p); + const VirtualDesktop *virtualDesktop = resolveVirtualDesktop(desktop); + return Workspace::self()->clientArea(static_cast(option), output, virtualDesktop); } QRect WorkspaceWrapper::clientArea(ClientAreaOption option, const KWin::AbstractClient *c) const @@ -271,7 +282,24 @@ QRect WorkspaceWrapper::clientArea(ClientAreaOption option, KWin::AbstractClient QRect WorkspaceWrapper::clientArea(ClientAreaOption option, int screen, int desktop) const { - return Workspace::self()->clientArea(static_cast(option), screen, desktop); + VirtualDesktop *virtualDesktop; + AbstractOutput *output; + + if (desktop == NETWinInfo::OnAllDesktops || desktop == 0) { + virtualDesktop = VirtualDesktopManager::self()->currentDesktop(); + } else { + virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop); + Q_ASSERT(virtualDesktop); + } + + if (screen == -1) { + output = workspace()->activeOutput(); + } else { + output = kwinApp()->platform()->findOutput(screen); + Q_ASSERT(output); + } + + return workspace()->clientArea(static_cast(option), output, virtualDesktop); } QString WorkspaceWrapper::desktopName(int desktop) const diff --git a/src/workspace.cpp b/src/workspace.cpp index c23356931c..7a3e0b283e 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -2327,33 +2327,6 @@ QRect Workspace::clientArea(clientAreaOption opt, const AbstractOutput *output, } } -QRect Workspace::clientArea(clientAreaOption opt, int screen, int desktop) const -{ - VirtualDesktop *virtualDesktop; - AbstractOutput *output; - - if (desktop == NETWinInfo::OnAllDesktops || desktop == 0) { - virtualDesktop = VirtualDesktopManager::self()->currentDesktop(); - } else { - virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop); - Q_ASSERT(virtualDesktop); - } - - if (screen == -1) { - output = activeOutput(); - } else { - output = kwinApp()->platform()->findOutput(screen); - Q_ASSERT(output); - } - - return clientArea(opt, output, virtualDesktop); -} - -QRect Workspace::clientArea(clientAreaOption opt, const QPoint &p, int desktop) const -{ - return clientArea(opt, screens()->number(p), desktop); -} - QRect Workspace::clientArea(clientAreaOption opt, const Toplevel *window) const { return clientArea(opt, window, window->frameGeometry().center()); @@ -2361,12 +2334,19 @@ QRect Workspace::clientArea(clientAreaOption opt, const Toplevel *window) const QRect Workspace::clientArea(clientAreaOption opt, const Toplevel *window, const AbstractOutput *output) const { - return clientArea(opt, window, output->geometry().center()); + const VirtualDesktop *desktop; + if (window->isOnCurrentDesktop()) { + desktop = VirtualDesktopManager::self()->currentDesktop(); + } else { + desktop = window->desktops().constLast(); + } + + return clientArea(opt, output, desktop); } QRect Workspace::clientArea(clientAreaOption opt, const Toplevel *window, const QPoint &pos) const { - return clientArea(opt, screens()->number(pos), window->desktop()); + return clientArea(opt, window, kwinApp()->platform()->outputAt(pos)); } QRect Workspace::geometry() const diff --git a/src/workspace.h b/src/workspace.h index ee72ddefa7..57d43bfb50 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -141,11 +141,9 @@ public: Toplevel *findInternal(QWindow *w) const; QRect clientArea(clientAreaOption, const AbstractOutput *output, const VirtualDesktop *desktop) const; - QRect clientArea(clientAreaOption, const QPoint &p, int desktop) const; QRect clientArea(clientAreaOption, const Toplevel *window) const; QRect clientArea(clientAreaOption, const Toplevel *window, const AbstractOutput *output) const; QRect clientArea(clientAreaOption, const Toplevel *window, const QPoint &pos) const; - QRect clientArea(clientAreaOption, int screen, int desktop) const; /** * Returns the geometry of this Workspace, i.e. the bounding rectangle of all outputs.