Store normal clients and desktop clients in the same list

Summary:
On X11, Workspace stores windows in two lists. One with desktop windows
and the other one with all other windows. On Wayland, desktop windows
and normal windows are stored in the same list - m_allClients.

In order to unify scripting on X11 and Wayland, this change makes the
Workspace class store X11 desktop windows and normal X11 windows in the
same list. It's the responsibility of scripts to filter desktop windows.

Reviewers: #kwin, apol

Reviewed By: apol

Subscribers: apol, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D29522
master
Vlad Zahorodnii 2020-05-08 10:45:30 +03:00
parent 7ea7aa1ee9
commit fc3b16f892
6 changed files with 11 additions and 71 deletions

View File

@ -73,6 +73,8 @@ void Activities::slotCurrentChanged(const QString &newActivity)
void Activities::slotRemoved(const QString &activity)
{
foreach (X11Client *client, Workspace::self()->clientList()) {
if (client->isDesktop())
continue;
client->setOnActivity(activity, false);
}
//toss out any session data for it
@ -167,6 +169,8 @@ void Activities::reallyStop(const QString &id)
const QList<X11Client *> &clients = ws->clientList();
for (auto it = clients.constBegin(); it != clients.constEnd(); ++it) {
const X11Client *c = (*it);
if (c->isDesktop())
continue;
const QByteArray sessionId = c->sessionId();
if (sessionId.isEmpty()) {
continue; //TODO support old wm_command apps too?

View File

@ -369,9 +369,6 @@ void Compositor::startupWithWorkspace()
c->setupCompositing();
c->updateShadow();
}
for (X11Client *c : Workspace::self()->desktopList()) {
c->setupCompositing();
}
for (Unmanaged *c : Workspace::self()->unmanagedList()) {
c->setupCompositing();
c->updateShadow();
@ -427,9 +424,6 @@ void Compositor::stop()
for (X11Client *c : Workspace::self()->clientList()) {
m_scene->removeToplevel(c);
}
for (X11Client *c : Workspace::self()->desktopList()) {
m_scene->removeToplevel(c);
}
for (Unmanaged *c : Workspace::self()->unmanagedList()) {
m_scene->removeToplevel(c);
}
@ -439,9 +433,6 @@ void Compositor::stop()
for (X11Client *c : Workspace::self()->clientList()) {
c->finishCompositing();
}
for (X11Client *c : Workspace::self()->desktopList()) {
c->finishCompositing();
}
for (Unmanaged *c : Workspace::self()->unmanagedList()) {
c->finishCompositing();
}
@ -755,9 +746,6 @@ bool Compositor::windowRepaintsPending() const
if (repaintsPending(Workspace::self()->clientList())) {
return true;
}
if (repaintsPending(Workspace::self()->desktopList())) {
return true;
}
if (repaintsPending(Workspace::self()->unmanagedList())) {
return true;
}

View File

@ -894,10 +894,6 @@ DebugConsoleModel::DebugConsoleModel(QObject *parent)
for (auto c : x11Clients) {
m_x11Clients.append(c);
}
const auto x11DesktopClients = workspace()->desktopList();
for (auto c : x11DesktopClients) {
m_x11Clients.append(c);
}
connect(workspace(), &Workspace::clientAdded, this,
[this] (AbstractClient *client) {
if (X11Client *x11Client = qobject_cast<X11Client *>(client)) {
@ -1289,12 +1285,6 @@ SurfaceTreeModel::SurfaceTreeModel(QObject *parent)
}
connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset);
}
for (auto c : workspace()->desktopList()) {
if (!c->surface()) {
continue;
}
connect(c->surface(), &SurfaceInterface::subSurfaceTreeChanged, this, reset);
}
if (waylandServer()) {
connect(waylandServer(), &WaylandServer::shellClientAdded, this,
[this, reset] (AbstractClient *c) {
@ -1343,7 +1333,6 @@ int SurfaceTreeModel::rowCount(const QModelIndex &parent) const
}
// toplevel are all windows
return workspace()->allClientList().count() +
workspace()->desktopList().count() +
workspace()->unmanagedList().count();
}
@ -1371,11 +1360,6 @@ QModelIndex SurfaceTreeModel::index(int row, int column, const QModelIndex &pare
return createIndex(row, column, allClients.at(row)->surface());
}
int reference = allClients.count();
const auto &desktopClients = workspace()->desktopList();
if (row < reference + desktopClients.count()) {
return createIndex(row, column, desktopClients.at(row-reference)->surface());
}
reference += desktopClients.count();
const auto &unmanaged = workspace()->unmanagedList();
if (row < reference + unmanaged.count()) {
return createIndex(row, column, unmanaged.at(row-reference)->surface());
@ -1423,13 +1407,6 @@ QModelIndex SurfaceTreeModel::parent(const QModelIndex &child) const
}
}
row = allClients.count();
const auto &desktopClients = workspace()->desktopList();
for (int i = 0; i < desktopClients.count(); i++) {
if (desktopClients.at(i)->surface() == parent) {
return createIndex(row + i, 0, parent);
}
}
row += desktopClients.count();
const auto &unmanaged = workspace()->unmanagedList();
for (int i = 0; i < unmanaged.count(); i++) {
if (unmanaged.at(i)->surface() == parent) {

View File

@ -205,13 +205,10 @@ void Workspace::propagateClients(bool propagate_new_clients)
int pos = 0;
xcb_window_t *cl(nullptr);
if (propagate_new_clients) {
cl = new xcb_window_t[ manual_overlays.count() + desktops.count() + clients.count()];
cl = new xcb_window_t[ manual_overlays.count() + clients.count()];
for (const auto win : manual_overlays) {
cl[pos++] = win;
}
// TODO this is still not completely in the map order
for (auto it = desktops.constBegin(); it != desktops.constEnd(); ++it)
cl[pos++] = (*it)->window();
for (auto it = clients.constBegin(); it != clients.constEnd(); ++it)
cl[pos++] = (*it)->window();
rootInfo()->setClientList(cl, pos);

View File

@ -446,7 +446,7 @@ void Workspace::initWithX11()
// No client activated in manage()
if (new_active_client == nullptr)
new_active_client = topClientOnDesktop(VirtualDesktopManager::self()->current(), -1);
if (new_active_client == nullptr && !desktops.isEmpty())
if (new_active_client == nullptr)
new_active_client = findDesktop(true, VirtualDesktopManager::self()->current());
}
if (new_active_client != nullptr)
@ -477,7 +477,6 @@ Workspace::~Workspace()
// from crashing.
clients.removeAll(c);
m_allClients.removeAll(c);
desktops.removeAll(c);
}
X11Client::cleanupX11();
@ -576,14 +575,13 @@ void Workspace::addClient(X11Client *c)
grp->gotLeader(c);
if (c->isDesktop()) {
desktops.append(c);
if (active_client == nullptr && should_get_focus.isEmpty() && c->isOnCurrentDesktop())
requestFocus(c); // TODO: Make sure desktop is active after startup if there's no other window active
} else {
FocusChain::self()->update(c, FocusChain::Update);
clients.append(c);
m_allClients.append(c);
}
clients.append(c);
m_allClients.append(c);
if (!unconstrained_stacking_order.contains(c))
unconstrained_stacking_order.append(c); // Raise if it hasn't got any stacking position yet
if (!stacking_order.contains(c)) // It'll be updated later, and updateToolWindows() requires
@ -629,11 +627,10 @@ void Workspace::removeClient(X11Client *c)
clientShortcutUpdated(c); // Needed, since this is otherwise delayed by setShortcut() and wouldn't run
}
Q_ASSERT(clients.contains(c) || desktops.contains(c));
Q_ASSERT(clients.contains(c));
// TODO: if marked client is removed, notify the marked list
clients.removeAll(c);
m_allClients.removeAll(c);
desktops.removeAll(c);
markXStackingOrderAsDirty();
attention_chain.removeAll(c);
Group* group = findGroup(c->window());
@ -991,7 +988,7 @@ void Workspace::activateClientOnNewDesktop(uint desktop)
else if (active_client && active_client->isShown(true) && active_client->isOnCurrentDesktop())
c = active_client;
if (c == nullptr && !desktops.isEmpty())
if (!c)
c = findDesktop(true, desktop);
if (c != active_client)
@ -999,8 +996,6 @@ void Workspace::activateClientOnNewDesktop(uint desktop)
if (c)
requestFocus(c);
else if (!desktops.isEmpty())
requestFocus(findDesktop(true, desktop));
else
focusToNull();
}
@ -1107,7 +1102,7 @@ void Workspace::updateCurrentActivity(const QString &new_activity)
else if (active_client && active_client->isShown(true) && active_client->isOnCurrentDesktop() && active_client->isOnCurrentActivity())
c = active_client;
if (c == nullptr && !desktops.isEmpty())
if (!c)
c = findDesktop(true, VirtualDesktopManager::self()->current());
if (c != active_client)
@ -1115,8 +1110,6 @@ void Workspace::updateCurrentActivity(const QString &new_activity)
if (c)
requestFocus(c);
else if (!desktops.isEmpty())
requestFocus(findDesktop(true, VirtualDesktopManager::self()->current()));
else
focusToNull();
@ -1659,9 +1652,6 @@ X11Client *Workspace::findClient(std::function<bool (const X11Client *)> func) c
if (X11Client *ret = Toplevel::findInList(clients, func)) {
return ret;
}
if (X11Client *ret = Toplevel::findInList(desktops, func)) {
return ret;
}
return nullptr;
}
@ -1670,9 +1660,6 @@ AbstractClient *Workspace::findAbstractClient(std::function<bool (const Abstract
if (AbstractClient *ret = Toplevel::findInList(m_allClients, func)) {
return ret;
}
if (X11Client *ret = Toplevel::findInList(desktops, func)) {
return ret;
}
if (InternalClient *ret = Toplevel::findInList(m_internalClients, func)) {
return ret;
}
@ -1719,9 +1706,6 @@ Toplevel *Workspace::findToplevel(std::function<bool (const Toplevel*)> func) co
if (X11Client *ret = Toplevel::findInList(clients, func)) {
return ret;
}
if (X11Client *ret = Toplevel::findInList(desktops, func)) {
return ret;
}
if (Unmanaged *ret = Toplevel::findInList(unmanaged, func)) {
return ret;
}
@ -1734,7 +1718,6 @@ Toplevel *Workspace::findToplevel(std::function<bool (const Toplevel*)> func) co
void Workspace::forEachToplevel(std::function<void (Toplevel *)> func)
{
std::for_each(m_allClients.constBegin(), m_allClients.constEnd(), func);
std::for_each(desktops.constBegin(), desktops.constEnd(), func);
std::for_each(deleted.constBegin(), deleted.constEnd(), func);
std::for_each(unmanaged.constBegin(), unmanaged.constEnd(), func);
std::for_each(m_internalClients.constBegin(), m_internalClients.constEnd(), func);
@ -1755,7 +1738,6 @@ bool Workspace::hasClient(const AbstractClient *c)
void Workspace::forEachAbstractClient(std::function< void (AbstractClient*) > func)
{
std::for_each(m_allClients.constBegin(), m_allClients.constEnd(), func);
std::for_each(desktops.constBegin(), desktops.constEnd(), func);
std::for_each(m_internalClients.constBegin(), m_internalClients.constEnd(), func);
}

View File

@ -221,12 +221,6 @@ public:
const QList<Unmanaged *> &unmanagedList() const {
return unmanaged;
}
/**
* @return List of desktop "clients" currently managed by Workspace
*/
const QList<X11Client *> &desktopList() const {
return desktops;
}
/**
* @return List of deleted "clients" currently managed by Workspace
*/
@ -596,7 +590,6 @@ private:
QList<X11Client *> clients;
QList<AbstractClient*> m_allClients;
QList<X11Client *> desktops;
QList<Unmanaged *> unmanaged;
QList<Deleted *> deleted;
QList<InternalClient *> m_internalClients;
@ -780,7 +773,6 @@ inline
void Workspace::forEachClient(std::function< void (X11Client *) > func)
{
std::for_each(clients.constBegin(), clients.constEnd(), func);
std::for_each(desktops.constBegin(), desktops.constEnd(), func);
}
inline