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
|
2021-03-05 11:18:22 +00:00
|
|
|
#include "abstract_client.h"
|
2013-04-04 14:14:12 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
// KDE
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KConfigGroup>
|
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)
|
|
|
|
{
|
2021-03-05 11:18:22 +00:00
|
|
|
const auto clients = Workspace::self()->allClientList();
|
|
|
|
for (auto * const client : clients) {
|
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();
|
|
|
|
}
|
|
|
|
|
2021-03-05 11:18:22 +00:00
|
|
|
void Activities::toggleClientOnActivity(AbstractClient *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 );
|
|
|
|
|
2021-03-05 11:18:22 +00:00
|
|
|
const auto transients_stacking_order = ws->ensureStackingOrder(c->transients());
|
|
|
|
for (auto * const c : transients_stacking_order) {
|
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;
|
2021-03-05 11:18:22 +00:00
|
|
|
const auto clients = ws->allClientList();
|
|
|
|
for (auto * const c : clients) {
|
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
|