2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2013-04-04 14:14:12 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2013-04-04 14:14:12 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-04-04 14:14:12 +00:00
|
|
|
#include "activities.h"
|
|
|
|
// KWin
|
2019-09-24 08:48:08 +00:00
|
|
|
#include "x11client.h"
|
2013-04-04 14:14:12 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
// KDE
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KConfigGroup>
|
2014-02-04 08:36:15 +00:00
|
|
|
#include <kactivities/controller.h>
|
2013-04-04 14:14:12 +00:00
|
|
|
// Qt
|
|
|
|
#include <QtConcurrentRun>
|
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QDBusPendingCall>
|
|
|
|
#include <QFutureWatcher>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2013-04-05 07:41:25 +00:00
|
|
|
KWIN_SINGLETON_FACTORY(Activities)
|
2013-04-04 14:14:12 +00:00
|
|
|
|
|
|
|
Activities::Activities(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_controller(new KActivities::Controller(this))
|
|
|
|
{
|
2014-02-03 12:44:06 +00:00
|
|
|
connect(m_controller, &KActivities::Controller::activityRemoved, this, &Activities::slotRemoved);
|
|
|
|
connect(m_controller, &KActivities::Controller::activityRemoved, this, &Activities::removed);
|
|
|
|
connect(m_controller, &KActivities::Controller::activityAdded, this, &Activities::added);
|
|
|
|
connect(m_controller, &KActivities::Controller::currentActivityChanged, this, &Activities::slotCurrentChanged);
|
2013-04-04 14:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Activities::~Activities()
|
|
|
|
{
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
s_self = nullptr;
|
2013-04-04 14:14:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-15 16:00:27 +00:00
|
|
|
KActivities::Consumer::ServiceStatus Activities::serviceStatus() const
|
|
|
|
{
|
|
|
|
return m_controller->serviceStatus();
|
|
|
|
}
|
|
|
|
|
2013-04-04 14:14:12 +00:00
|
|
|
void Activities::setCurrent(const QString &activity)
|
|
|
|
{
|
|
|
|
m_controller->setCurrentActivity(activity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Activities::slotCurrentChanged(const QString &newActivity)
|
|
|
|
{
|
|
|
|
if (m_current == newActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_previous = m_current;
|
|
|
|
m_current = newActivity;
|
|
|
|
emit currentChanged(newActivity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Activities::slotRemoved(const QString &activity)
|
|
|
|
{
|
2019-09-24 08:48:08 +00:00
|
|
|
foreach (X11Client *client, Workspace::self()->clientList()) {
|
2020-05-08 07:45:30 +00:00
|
|
|
if (client->isDesktop())
|
|
|
|
continue;
|
2013-04-04 14:14:12 +00:00
|
|
|
client->setOnActivity(activity, false);
|
|
|
|
}
|
|
|
|
//toss out any session data for it
|
2015-01-24 02:13:45 +00:00
|
|
|
KConfigGroup cg(KSharedConfig::openConfig(), QByteArray("SubSession: ").append(activity.toUtf8()).constData());
|
2013-04-04 14:14:12 +00:00
|
|
|
cg.deleteGroup();
|
|
|
|
}
|
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
void Activities::toggleClientOnActivity(X11Client *c, const QString &activity, bool dont_activate)
|
2013-04-04 14:14:12 +00:00
|
|
|
{
|
|
|
|
//int old_desktop = c->desktop();
|
|
|
|
bool was_on_activity = c->isOnActivity(activity);
|
|
|
|
bool was_on_all = c->isOnAllActivities();
|
|
|
|
//note: all activities === no activities
|
|
|
|
bool enable = was_on_all || !was_on_activity;
|
|
|
|
c->setOnActivity(activity, enable);
|
|
|
|
if (c->isOnActivity(activity) == was_on_activity && c->isOnAllActivities() == was_on_all) // No change
|
|
|
|
return;
|
|
|
|
|
|
|
|
Workspace *ws = Workspace::self();
|
|
|
|
if (c->isOnCurrentActivity()) {
|
|
|
|
if (c->wantsTabFocus() && options->focusPolicyIsReasonable() &&
|
|
|
|
!was_on_activity && // for stickyness changes
|
|
|
|
//FIXME not sure if the line above refers to the correct activity
|
|
|
|
!dont_activate)
|
|
|
|
ws->requestFocus(c);
|
|
|
|
else
|
|
|
|
ws->restackClientUnderActive(c);
|
|
|
|
} else
|
|
|
|
ws->raiseClient(c);
|
|
|
|
|
|
|
|
//notifyWindowDesktopChanged( c, old_desktop );
|
|
|
|
|
2015-09-14 07:27:48 +00:00
|
|
|
auto transients_stacking_order = ws->ensureStackingOrder(c->transients());
|
|
|
|
for (auto it = transients_stacking_order.constBegin();
|
2013-04-04 14:14:12 +00:00
|
|
|
it != transients_stacking_order.constEnd();
|
2015-09-14 08:55:27 +00:00
|
|
|
++it) {
|
2019-09-24 08:48:08 +00:00
|
|
|
X11Client *c = dynamic_cast<X11Client *>(*it);
|
2015-09-14 08:55:27 +00:00
|
|
|
if (!c) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
toggleClientOnActivity(c, activity, dont_activate);
|
|
|
|
}
|
2013-04-04 14:14:12 +00:00
|
|
|
ws->updateClientArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Activities::start(const QString &id)
|
|
|
|
{
|
|
|
|
Workspace *ws = Workspace::self();
|
2019-10-31 16:16:53 +00:00
|
|
|
if (ws->sessionManager()->state() == SessionState::Saving) {
|
2013-04-04 14:14:12 +00:00
|
|
|
return false; //ksmserver doesn't queue requests (yet)
|
|
|
|
}
|
|
|
|
|
2014-06-01 16:55:36 +00:00
|
|
|
if (!all().contains(id)) {
|
2013-04-04 14:14:12 +00:00
|
|
|
return false; //bogus id
|
|
|
|
}
|
|
|
|
|
|
|
|
ws->loadSubSessionInfo(id);
|
|
|
|
|
|
|
|
QDBusInterface ksmserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface");
|
|
|
|
if (ksmserver.isValid()) {
|
|
|
|
ksmserver.asyncCall("restoreSubSession", id);
|
|
|
|
} else {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "couldn't get ksmserver interface";
|
2013-04-04 14:14:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Activities::stop(const QString &id)
|
|
|
|
{
|
2019-10-31 16:16:53 +00:00
|
|
|
if (Workspace::self()->sessionManager()->state() == SessionState::Saving) {
|
2013-04-04 14:14:12 +00:00
|
|
|
return false; //ksmserver doesn't queue requests (yet)
|
|
|
|
//FIXME what about session *loading*?
|
|
|
|
}
|
|
|
|
|
|
|
|
//ugly hack to avoid dbus deadlocks
|
|
|
|
QMetaObject::invokeMethod(this, "reallyStop", Qt::QueuedConnection, Q_ARG(QString, id));
|
|
|
|
//then lie and assume it worked.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Activities::reallyStop(const QString &id)
|
|
|
|
{
|
|
|
|
Workspace *ws = Workspace::self();
|
2019-10-31 16:16:53 +00:00
|
|
|
if (ws->sessionManager()->state() == SessionState::Saving)
|
2013-04-04 14:14:12 +00:00
|
|
|
return; //ksmserver doesn't queue requests (yet)
|
|
|
|
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << id;
|
2013-04-04 14:14:12 +00:00
|
|
|
|
|
|
|
QSet<QByteArray> saveSessionIds;
|
|
|
|
QSet<QByteArray> dontCloseSessionIds;
|
Drop some custom list typedefs
Summary:
Qt has its own thing where a type might also have corresponding list
alias, e.g. QObject and QObjectList, QWidget and QWidgetList. I don't
know why Qt does that, maybe for some historical reasons, but what
matters is that we copy this pattern here in KWin. While this pattern
might be useful with some long list types, for example
QList<QWeakPointer<TabBoxClient>> TabBoxClientList
in general, it causes more harm than good. For example, we've got two
new client types, do we need corresponding list typedefs for them? If
no, why do we have ClientList and so on?
Another problem with these typedefs is that you need to include utils.h
header in order to use them. A better way to handle such things is to
just forward declare a client class (if that's possible) and use it
directly with QList or QVector. This way translation units don't get
"bloated" with utils.h stuff for no apparent reason.
So, in order to make code more consistent and easier to follow, this
change drops some of our custom typedefs. Namely ConstClientList,
ClientList, DeletedList, UnmanagedList, ToplevelList, and GroupList.
Test Plan: Compiles.
Reviewers: #kwin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24950
2019-10-16 09:11:04 +00:00
|
|
|
const QList<X11Client *> &clients = ws->clientList();
|
|
|
|
for (auto it = clients.constBegin(); it != clients.constEnd(); ++it) {
|
2019-09-24 08:48:08 +00:00
|
|
|
const X11Client *c = (*it);
|
2020-05-08 07:45:30 +00:00
|
|
|
if (c->isDesktop())
|
|
|
|
continue;
|
2013-04-04 14:14:12 +00:00
|
|
|
const QByteArray sessionId = c->sessionId();
|
|
|
|
if (sessionId.isEmpty()) {
|
2016-06-23 17:40:40 +00:00
|
|
|
continue; //TODO support old wm_command apps too?
|
2013-04-04 14:14:12 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 11:29:05 +00:00
|
|
|
//qDebug() << sessionId;
|
2013-04-04 14:14:12 +00:00
|
|
|
|
|
|
|
//if it's on the activity that's closing, it needs saving
|
|
|
|
//but if a process is on some other open activity, I don't wanna close it yet
|
|
|
|
//this is, of course, complicated by a process having many windows.
|
|
|
|
if (c->isOnAllActivities()) {
|
|
|
|
dontCloseSessionIds << sessionId;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QStringList activities = c->activities();
|
|
|
|
foreach (const QString & activityId, activities) {
|
|
|
|
if (activityId == id) {
|
|
|
|
saveSessionIds << sessionId;
|
2014-06-01 16:55:36 +00:00
|
|
|
} else if (running().contains(activityId)) {
|
2013-04-04 14:14:12 +00:00
|
|
|
dontCloseSessionIds << sessionId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ws->storeSubSession(id, saveSessionIds);
|
|
|
|
|
|
|
|
QStringList saveAndClose;
|
|
|
|
QStringList saveOnly;
|
|
|
|
foreach (const QByteArray & sessionId, saveSessionIds) {
|
|
|
|
if (dontCloseSessionIds.contains(sessionId)) {
|
|
|
|
saveOnly << sessionId;
|
|
|
|
} else {
|
|
|
|
saveAndClose << sessionId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "saveActivity" << id << saveAndClose << saveOnly;
|
2013-04-04 14:14:12 +00:00
|
|
|
|
|
|
|
//pass off to ksmserver
|
|
|
|
QDBusInterface ksmserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface");
|
|
|
|
if (ksmserver.isValid()) {
|
|
|
|
ksmserver.asyncCall("saveSubSession", id, saveAndClose, saveOnly);
|
|
|
|
} else {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "couldn't get ksmserver interface";
|
2013-04-04 14:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|