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());
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();

View file

@ -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();

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.
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<X11Window *>(window);
if (x11Window && x11Window->isBlockingCompositing()) {
shouldResume = false;
break;
}

View file

@ -191,12 +191,15 @@ void Workspace::propagateWindows(bool propagate_new_windows)
QVector<xcb_window_t> 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<X11Window *>(window);
if (x11Window) {
cl.push_back(x11Window->window());
}
}
rootInfo()->setClientList(cl.constData(), cl.size());
}

View file

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

View file

@ -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<X11Window *>(*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<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
{
if (X11Window *ret = Window::findInList(m_x11Clients, func)) {
return ret;
for (Window *window : std::as_const(m_windows)) {
X11Window *x11Window = qobject_cast<X11Window *>(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<X11Window *>(*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<X11Window *> old_group = (*it)->group()->members();
QList<X11Window *> 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<X11Window *>(*it)) {
x11Window->checkTransient(w);
}
}
}

View file

@ -240,14 +240,6 @@ public:
void windowHidden(Window *);
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
*/
@ -653,7 +645,6 @@ private:
Window *m_delayFocusWindow;
QPointF focusMousePos;
QList<X11Window *> m_x11Clients;
QList<Window *> m_windows;
QList<Window *> deleted;
@ -844,11 +835,6 @@ inline QPointF Workspace::focusMousePosition() const
return focusMousePos;
}
inline void Workspace::forEachClient(std::function<void(X11Window *)> func)
{
std::for_each(m_x11Clients.constBegin(), m_x11Clients.constEnd(), func);
}
inline Workspace *workspace()
{
return Workspace::_self;