From 1f43605329b5e2360e21073dc9fcda73301e87d4 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 21 Mar 2023 19:47:58 +0200 Subject: [PATCH] Drop Workspace::clientList() --- autotests/integration/dont_crash_glxgears.cpp | 4 +- autotests/integration/x11_window_test.cpp | 4 +- src/composite.cpp | 7 +-- src/layers.cpp | 9 ++-- src/sm.cpp | 18 ++++--- src/workspace.cpp | 49 ++++++++++++------- src/workspace.h | 14 ------ 7 files changed, 58 insertions(+), 47 deletions(-) diff --git a/autotests/integration/dont_crash_glxgears.cpp b/autotests/integration/dont_crash_glxgears.cpp index 3684991104..52312aafe7 100644 --- a/autotests/integration/dont_crash_glxgears.cpp +++ b/autotests/integration/dont_crash_glxgears.cpp @@ -53,8 +53,8 @@ void DontCrashGlxgearsTest::testGlxgears() QVERIFY(windowAddedSpy.wait()); QCOMPARE(windowAddedSpy.count(), 1); - QCOMPARE(workspace()->clientList().count(), 1); - X11Window *glxgearsWindow = workspace()->clientList().first(); + QCOMPARE(workspace()->windows().count(), 1); + Window *glxgearsWindow = workspace()->windows().first(); QVERIFY(glxgearsWindow->isDecorated()); QSignalSpy closedSpy(glxgearsWindow, &X11Window::closed); KDecoration2::Decoration *decoration = glxgearsWindow->decoration(); diff --git a/autotests/integration/x11_window_test.cpp b/autotests/integration/x11_window_test.cpp index e0fa7e2133..ae95cabf00 100644 --- a/autotests/integration/x11_window_test.cpp +++ b/autotests/integration/x11_window_test.cpp @@ -851,8 +851,8 @@ void X11WindowTest::testCaptionWmName() QVERIFY(windowAddedSpy.wait()); QCOMPARE(windowAddedSpy.count(), 1); - QCOMPARE(workspace()->clientList().count(), 1); - X11Window *glxgearsWindow = workspace()->clientList().first(); + QCOMPARE(workspace()->windows().count(), 1); + Window *glxgearsWindow = workspace()->windows().first(); QCOMPARE(glxgearsWindow->caption(), QStringLiteral("glxgears")); glxgears.terminate(); diff --git a/src/composite.cpp b/src/composite.cpp index 1ba83894b5..faca40aeff 100644 --- a/src/composite.cpp +++ b/src/composite.cpp @@ -985,9 +985,10 @@ void X11Compositor::updateClientCompositeBlocking(X11Window *c) // If !c we just check if we can resume in case a blocking client was lost. bool shouldResume = true; - for (auto it = Workspace::self()->clientList().constBegin(); - it != Workspace::self()->clientList().constEnd(); ++it) { - if ((*it)->isBlockingCompositing()) { + const auto windows = workspace()->windows(); + for (Window *window : windows) { + X11Window *x11Window = qobject_cast(window); + if (x11Window && x11Window->isBlockingCompositing()) { shouldResume = false; break; } diff --git a/src/layers.cpp b/src/layers.cpp index e9801121c6..b9c370d6ba 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -191,12 +191,15 @@ void Workspace::propagateWindows(bool propagate_new_windows) QVector cl; if (propagate_new_windows) { - cl.reserve(manual_overlays.size() + m_x11Clients.size()); + cl.reserve(manual_overlays.size() + m_windows.size()); for (const auto win : std::as_const(manual_overlays)) { cl.push_back(win); } - for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { - cl.push_back((*it)->window()); + for (Window *window : std::as_const(m_windows)) { + X11Window *x11Window = qobject_cast(window); + if (x11Window) { + cl.push_back(x11Window->window()); + } } rootInfo()->setClientList(cl.constData(), cl.size()); } diff --git a/src/sm.cpp b/src/sm.cpp index 213ff2aa19..ec73ddf032 100644 --- a/src/sm.cpp +++ b/src/sm.cpp @@ -88,9 +88,12 @@ void SessionManager::storeSession(const QString &sessionName, SMSavePhase phase) int count = 0; int active_client = -1; - const QList x11Clients = workspace()->clientList(); - for (auto it = x11Clients.begin(); it != x11Clients.end(); ++it) { - X11Window *c = (*it); + const QList windows = workspace()->windows(); + for (auto it = windows.begin(); it != windows.end(); ++it) { + X11Window *c = qobject_cast(*it); + if (!c) { + continue; + } if (c->windowType() > NET::Splash) { // window types outside this are not tooltips/menus/OSDs // typically these will be unmanaged and not in this list anyway, but that is not enforced @@ -173,10 +176,13 @@ void SessionManager::storeSubSession(const QString &name, QSet sessi KConfigGroup cg(KSharedConfig::openConfig(), QLatin1String("SubSession: ") + name); int count = 0; int active_client = -1; - const QList x11Clients = workspace()->clientList(); + const QList windows = workspace()->windows(); - for (auto it = x11Clients.begin(); it != x11Clients.end(); ++it) { - X11Window *c = (*it); + for (auto it = windows.begin(); it != windows.end(); ++it) { + X11Window *c = qobject_cast(*it); + if (!c) { + continue; + } if (c->windowType() > NET::Splash) { continue; } diff --git a/src/workspace.cpp b/src/workspace.cpp index 829fb8e676..b74322f98d 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -738,7 +738,6 @@ void Workspace::addX11Window(X11Window *window) } else { m_focusChain->update(window, FocusChain::Update); } - m_x11Clients.append(window); m_windows.append(window); addToStack(window); updateClientArea(); // This cannot be in manage(), because the window got added only now @@ -772,9 +771,7 @@ void Workspace::addUnmanaged(Unmanaged *window) */ void Workspace::removeX11Window(X11Window *window) { - Q_ASSERT(m_x11Clients.contains(window)); - // TODO: if marked window is removed, notify the marked list - m_x11Clients.removeAll(window); + Q_ASSERT(m_windows.contains(window)); Group *group = findGroup(window->window()); if (group != nullptr) { group->lostLeader(); @@ -888,8 +885,10 @@ void Workspace::updateToolWindows(bool also_hide) { // TODO: What if Client's transiency/group changes? should this be called too? (I'm paranoid, am I not?) if (!options->isHideUtilityWindowsForInactive()) { - for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { - (*it)->showClient(); + for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) { + if (X11Window *x11Window = qobject_cast(*it)) { + x11Window->showClient(); + } } return; } @@ -1614,7 +1613,7 @@ void Workspace::disableGlobalShortcutsForClient(bool disable) m_globalShortcutsDisabledForWindow = disable; // Update also Meta+LMB actions etc. - for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { + for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) { (*it)->updateMouseGrab(); } } @@ -1918,10 +1917,23 @@ QString Workspace::supportInformation() const return support; } +void Workspace::forEachClient(std::function func) +{ + for (Window *window : std::as_const(m_windows)) { + X11Window *x11Window = qobject_cast(window); + if (x11Window) { + func(x11Window); + } + } +} + X11Window *Workspace::findClient(std::function func) const { - if (X11Window *ret = Window::findInList(m_x11Clients, func)) { - return ret; + for (Window *window : std::as_const(m_windows)) { + X11Window *x11Window = qobject_cast(window); + if (x11Window && func(x11Window)) { + return x11Window; + } } return nullptr; } @@ -2082,19 +2094,20 @@ Group *Workspace::findGroup(xcb_window_t leader) const Group *Workspace::findClientLeaderGroup(const X11Window *window) const { Group *ret = nullptr; - for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { - if (*it == window) { + for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) { + X11Window *candidate = qobject_cast(*it); + if (!candidate || candidate == window) { continue; } - if ((*it)->wmClientLeader() == window->wmClientLeader()) { - if (ret == nullptr || ret == (*it)->group()) { - ret = (*it)->group(); + if (candidate->wmClientLeader() == window->wmClientLeader()) { + if (ret == nullptr || ret == candidate->group()) { + ret = candidate->group(); } else { // There are already two groups with the same client leader. // This most probably means the app uses group transients without // setting group for its windows. Merging the two groups is a bad // hack, but there's no really good solution for this case. - QList old_group = (*it)->group()->members(); + QList old_group = candidate->group()->members(); // old_group autodeletes when being empty for (int pos = 0; pos < old_group.count(); ++pos) { X11Window *tmp = old_group[pos]; @@ -2160,8 +2173,10 @@ void Workspace::updateOnAllDesktopsOfTransients(Window *window) // A new window has been mapped. Check if it's not a mainwindow for some already existing transient window. void Workspace::checkTransients(xcb_window_t w) { - for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { - (*it)->checkTransient(w); + for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) { + if (X11Window *x11Window = qobject_cast(*it)) { + x11Window->checkTransient(w); + } } } diff --git a/src/workspace.h b/src/workspace.h index 0bc8553ddf..2cc1ec4f1e 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -240,14 +240,6 @@ public: void windowHidden(Window *); void windowAttentionChanged(Window *, bool set); - /** - * @return List of windows currently managed by Workspace - */ - const QList &clientList() const - { - return m_x11Clients; - } - /** * @returns List of all windows (either X11 or Wayland) currently managed by Workspace */ @@ -653,7 +645,6 @@ private: Window *m_delayFocusWindow; QPointF focusMousePos; - QList m_x11Clients; QList m_windows; QList deleted; @@ -844,11 +835,6 @@ inline QPointF Workspace::focusMousePosition() const return focusMousePos; } -inline void Workspace::forEachClient(std::function func) -{ - std::for_each(m_x11Clients.constBegin(), m_x11Clients.constEnd(), func); -} - inline Workspace *workspace() { return Workspace::_self;