Drop Workspace::clientList()

This commit is contained in:
Vlad Zahorodnii 2023-03-21 19:47:58 +02:00
parent 4a1e7df599
commit 1f43605329
7 changed files with 58 additions and 47 deletions

View file

@ -53,8 +53,8 @@ void DontCrashGlxgearsTest::testGlxgears()
QVERIFY(windowAddedSpy.wait()); QVERIFY(windowAddedSpy.wait());
QCOMPARE(windowAddedSpy.count(), 1); QCOMPARE(windowAddedSpy.count(), 1);
QCOMPARE(workspace()->clientList().count(), 1); QCOMPARE(workspace()->windows().count(), 1);
X11Window *glxgearsWindow = workspace()->clientList().first(); Window *glxgearsWindow = workspace()->windows().first();
QVERIFY(glxgearsWindow->isDecorated()); QVERIFY(glxgearsWindow->isDecorated());
QSignalSpy closedSpy(glxgearsWindow, &X11Window::closed); QSignalSpy closedSpy(glxgearsWindow, &X11Window::closed);
KDecoration2::Decoration *decoration = glxgearsWindow->decoration(); KDecoration2::Decoration *decoration = glxgearsWindow->decoration();

View file

@ -851,8 +851,8 @@ void X11WindowTest::testCaptionWmName()
QVERIFY(windowAddedSpy.wait()); QVERIFY(windowAddedSpy.wait());
QCOMPARE(windowAddedSpy.count(), 1); QCOMPARE(windowAddedSpy.count(), 1);
QCOMPARE(workspace()->clientList().count(), 1); QCOMPARE(workspace()->windows().count(), 1);
X11Window *glxgearsWindow = workspace()->clientList().first(); Window *glxgearsWindow = workspace()->windows().first();
QCOMPARE(glxgearsWindow->caption(), QStringLiteral("glxgears")); QCOMPARE(glxgearsWindow->caption(), QStringLiteral("glxgears"));
glxgears.terminate(); glxgears.terminate();

View file

@ -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. // If !c we just check if we can resume in case a blocking client was lost.
bool shouldResume = true; bool shouldResume = true;
for (auto it = Workspace::self()->clientList().constBegin(); const auto windows = workspace()->windows();
it != Workspace::self()->clientList().constEnd(); ++it) { for (Window *window : windows) {
if ((*it)->isBlockingCompositing()) { X11Window *x11Window = qobject_cast<X11Window *>(window);
if (x11Window && x11Window->isBlockingCompositing()) {
shouldResume = false; shouldResume = false;
break; break;
} }

View file

@ -191,12 +191,15 @@ void Workspace::propagateWindows(bool propagate_new_windows)
QVector<xcb_window_t> cl; QVector<xcb_window_t> cl;
if (propagate_new_windows) { 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)) { for (const auto win : std::as_const(manual_overlays)) {
cl.push_back(win); cl.push_back(win);
} }
for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { for (Window *window : std::as_const(m_windows)) {
cl.push_back((*it)->window()); X11Window *x11Window = qobject_cast<X11Window *>(window);
if (x11Window) {
cl.push_back(x11Window->window());
}
} }
rootInfo()->setClientList(cl.constData(), cl.size()); rootInfo()->setClientList(cl.constData(), cl.size());
} }

View file

@ -88,9 +88,12 @@ void SessionManager::storeSession(const QString &sessionName, SMSavePhase phase)
int count = 0; int count = 0;
int active_client = -1; int active_client = -1;
const QList<X11Window *> x11Clients = workspace()->clientList(); const QList<Window *> windows = workspace()->windows();
for (auto it = x11Clients.begin(); it != x11Clients.end(); ++it) { for (auto it = windows.begin(); it != windows.end(); ++it) {
X11Window *c = (*it); X11Window *c = qobject_cast<X11Window *>(*it);
if (!c) {
continue;
}
if (c->windowType() > NET::Splash) { if (c->windowType() > NET::Splash) {
// window types outside this are not tooltips/menus/OSDs // 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 // 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<QByteArray> sessi
KConfigGroup cg(KSharedConfig::openConfig(), QLatin1String("SubSession: ") + name); KConfigGroup cg(KSharedConfig::openConfig(), QLatin1String("SubSession: ") + name);
int count = 0; int count = 0;
int active_client = -1; int active_client = -1;
const QList<X11Window *> x11Clients = workspace()->clientList(); const QList<Window *> windows = workspace()->windows();
for (auto it = x11Clients.begin(); it != x11Clients.end(); ++it) { for (auto it = windows.begin(); it != windows.end(); ++it) {
X11Window *c = (*it); X11Window *c = qobject_cast<X11Window *>(*it);
if (!c) {
continue;
}
if (c->windowType() > NET::Splash) { if (c->windowType() > NET::Splash) {
continue; continue;
} }

View file

@ -738,7 +738,6 @@ void Workspace::addX11Window(X11Window *window)
} else { } else {
m_focusChain->update(window, FocusChain::Update); m_focusChain->update(window, FocusChain::Update);
} }
m_x11Clients.append(window);
m_windows.append(window); m_windows.append(window);
addToStack(window); addToStack(window);
updateClientArea(); // This cannot be in manage(), because the window got added only now 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) void Workspace::removeX11Window(X11Window *window)
{ {
Q_ASSERT(m_x11Clients.contains(window)); Q_ASSERT(m_windows.contains(window));
// TODO: if marked window is removed, notify the marked list
m_x11Clients.removeAll(window);
Group *group = findGroup(window->window()); Group *group = findGroup(window->window());
if (group != nullptr) { if (group != nullptr) {
group->lostLeader(); 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?) // TODO: What if Client's transiency/group changes? should this be called too? (I'm paranoid, am I not?)
if (!options->isHideUtilityWindowsForInactive()) { if (!options->isHideUtilityWindowsForInactive()) {
for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) {
(*it)->showClient(); if (X11Window *x11Window = qobject_cast<X11Window *>(*it)) {
x11Window->showClient();
}
} }
return; return;
} }
@ -1614,7 +1613,7 @@ void Workspace::disableGlobalShortcutsForClient(bool disable)
m_globalShortcutsDisabledForWindow = disable; m_globalShortcutsDisabledForWindow = disable;
// Update also Meta+LMB actions etc. // 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(); (*it)->updateMouseGrab();
} }
} }
@ -1918,10 +1917,23 @@ QString Workspace::supportInformation() const
return support; return support;
} }
void Workspace::forEachClient(std::function<void(X11Window *)> func)
{
for (Window *window : std::as_const(m_windows)) {
X11Window *x11Window = qobject_cast<X11Window *>(window);
if (x11Window) {
func(x11Window);
}
}
}
X11Window *Workspace::findClient(std::function<bool(const X11Window *)> func) const X11Window *Workspace::findClient(std::function<bool(const X11Window *)> func) const
{ {
if (X11Window *ret = Window::findInList(m_x11Clients, func)) { for (Window *window : std::as_const(m_windows)) {
return ret; X11Window *x11Window = qobject_cast<X11Window *>(window);
if (x11Window && func(x11Window)) {
return x11Window;
}
} }
return nullptr; return nullptr;
} }
@ -2082,19 +2094,20 @@ Group *Workspace::findGroup(xcb_window_t leader) const
Group *Workspace::findClientLeaderGroup(const X11Window *window) const Group *Workspace::findClientLeaderGroup(const X11Window *window) const
{ {
Group *ret = nullptr; Group *ret = nullptr;
for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) {
if (*it == window) { X11Window *candidate = qobject_cast<X11Window *>(*it);
if (!candidate || candidate == window) {
continue; continue;
} }
if ((*it)->wmClientLeader() == window->wmClientLeader()) { if (candidate->wmClientLeader() == window->wmClientLeader()) {
if (ret == nullptr || ret == (*it)->group()) { if (ret == nullptr || ret == candidate->group()) {
ret = (*it)->group(); ret = candidate->group();
} else { } else {
// There are already two groups with the same client leader. // There are already two groups with the same client leader.
// This most probably means the app uses group transients without // This most probably means the app uses group transients without
// setting group for its windows. Merging the two groups is a bad // setting group for its windows. Merging the two groups is a bad
// hack, but there's no really good solution for this case. // hack, but there's no really good solution for this case.
QList<X11Window *> old_group = (*it)->group()->members(); QList<X11Window *> old_group = candidate->group()->members();
// old_group autodeletes when being empty // old_group autodeletes when being empty
for (int pos = 0; pos < old_group.count(); ++pos) { for (int pos = 0; pos < old_group.count(); ++pos) {
X11Window *tmp = old_group[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. // 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) void Workspace::checkTransients(xcb_window_t w)
{ {
for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) {
(*it)->checkTransient(w); if (X11Window *x11Window = qobject_cast<X11Window *>(*it)) {
x11Window->checkTransient(w);
}
} }
} }

View file

@ -240,14 +240,6 @@ public:
void windowHidden(Window *); void windowHidden(Window *);
void windowAttentionChanged(Window *, bool set); void windowAttentionChanged(Window *, bool set);
/**
* @return List of windows currently managed by Workspace
*/
const QList<X11Window *> &clientList() const
{
return m_x11Clients;
}
/** /**
* @returns List of all windows (either X11 or Wayland) currently managed by Workspace * @returns List of all windows (either X11 or Wayland) currently managed by Workspace
*/ */
@ -653,7 +645,6 @@ private:
Window *m_delayFocusWindow; Window *m_delayFocusWindow;
QPointF focusMousePos; QPointF focusMousePos;
QList<X11Window *> m_x11Clients;
QList<Window *> m_windows; QList<Window *> m_windows;
QList<Window *> deleted; QList<Window *> deleted;
@ -844,11 +835,6 @@ inline QPointF Workspace::focusMousePosition() const
return focusMousePos; return focusMousePos;
} }
inline void Workspace::forEachClient(std::function<void(X11Window *)> func)
{
std::for_each(m_x11Clients.constBegin(), m_x11Clients.constEnd(), func);
}
inline Workspace *workspace() inline Workspace *workspace()
{ {
return Workspace::_self; return Workspace::_self;