2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "sm.h"
|
|
|
|
|
2019-07-09 19:19:26 +00:00
|
|
|
#include <cstdlib>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kconfig.h>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <unistd.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2021-08-12 14:16:08 +00:00
|
|
|
#include "virtualdesktops.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "workspace.h"
|
2019-09-24 08:48:08 +00:00
|
|
|
#include "x11client.h"
|
2013-09-02 11:14:39 +00:00
|
|
|
#include <QDebug>
|
2008-02-02 20:54:19 +00:00
|
|
|
#include <QSessionManager>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-10-31 16:16:53 +00:00
|
|
|
#include "sessionadaptor.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QDBusConnection>
|
2019-10-31 16:16:53 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2015-05-01 14:55:15 +00:00
|
|
|
static KConfig *sessionConfig(QString id, QString key)
|
|
|
|
{
|
|
|
|
static KConfig *config = nullptr;
|
|
|
|
static QString lastId;
|
|
|
|
static QString lastKey;
|
|
|
|
static QString pattern = QString(QLatin1String("session/%1_%2_%3")).arg(qApp->applicationName());
|
|
|
|
if (id != lastId || key != lastKey) {
|
|
|
|
delete config;
|
|
|
|
config = nullptr;
|
|
|
|
}
|
|
|
|
lastId = id;
|
|
|
|
lastKey = key;
|
|
|
|
if (!config) {
|
2021-08-22 13:15:16 +00:00
|
|
|
config = new KConfig(pattern.arg(id, key), KConfig::SimpleConfig);
|
2015-05-01 14:55:15 +00:00
|
|
|
}
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
static const char *const window_type_names[] = {
|
|
|
|
"Unknown", "Normal", "Desktop", "Dock", "Toolbar", "Menu", "Dialog",
|
|
|
|
"Override", "TopMenu", "Utility", "Splash"};
|
2019-04-24 07:55:35 +00:00
|
|
|
// change also the two functions below when adding new entries
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
static const char *windowTypeToTxt(NET::WindowType type)
|
2019-04-24 07:55:35 +00:00
|
|
|
{
|
2022-03-25 12:20:32 +00:00
|
|
|
if (type >= NET::Unknown && type <= NET::Splash) {
|
2022-03-23 10:13:38 +00:00
|
|
|
return window_type_names[type + 1]; // +1 (unknown==-1)
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
|
|
|
if (type == -2) { // undefined (not really part of NET::WindowType)
|
2019-04-24 07:55:35 +00:00
|
|
|
return "Undefined";
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2019-04-24 07:55:35 +00:00
|
|
|
qFatal("Unknown Window Type");
|
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
|
|
|
return nullptr;
|
2019-04-24 07:55:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
static NET::WindowType txtToWindowType(const char *txt)
|
2019-04-24 07:55:35 +00:00
|
|
|
{
|
|
|
|
for (int i = NET::Unknown;
|
2022-03-23 10:13:38 +00:00
|
|
|
i <= NET::Splash;
|
2022-03-25 12:20:32 +00:00
|
|
|
++i) {
|
|
|
|
if (qstrcmp(txt, window_type_names[i + 1]) == 0) { // +1
|
2022-03-23 10:13:38 +00:00
|
|
|
return static_cast<NET::WindowType>(i);
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
return static_cast<NET::WindowType>(-2); // undefined
|
2019-04-24 07:55:35 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:17:44 +00:00
|
|
|
/**
|
|
|
|
* Stores the current session in the config file
|
|
|
|
*
|
|
|
|
* @see loadSessionInfo
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2020-04-02 11:44:27 +00:00
|
|
|
void Workspace::storeSession(const QString &sessionName, SMSavePhase phase)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2020-04-02 11:44:27 +00:00
|
|
|
qCDebug(KWIN_CORE) << "storing session" << sessionName << "in phase" << phase;
|
|
|
|
KConfig *config = sessionConfig(sessionName, QString());
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
KConfigGroup cg(config, "Session");
|
2022-03-23 10:13:38 +00:00
|
|
|
int count = 0;
|
2007-04-29 17:35:43 +00:00
|
|
|
int active_client = -1;
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2021-05-24 16:01:49 +00:00
|
|
|
for (auto it = m_x11Clients.begin(); it != m_x11Clients.end(); ++it) {
|
2019-09-24 08:48:08 +00:00
|
|
|
X11Client *c = (*it);
|
2018-06-27 00:36:02 +00:00
|
|
|
if (c->windowType() > NET::Splash) {
|
2022-03-23 10:13:38 +00:00
|
|
|
// 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
|
2018-06-27 00:36:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
QByteArray sessionId = c->sessionId();
|
2016-06-23 17:40:40 +00:00
|
|
|
QByteArray wmCommand = c->wmCommand();
|
2022-03-25 12:20:32 +00:00
|
|
|
if (sessionId.isEmpty()) {
|
2016-06-23 17:40:40 +00:00
|
|
|
// remember also applications that are not XSMP capable
|
|
|
|
// and use the obsolete WM_COMMAND / WM_SAVE_YOURSELF
|
2022-03-25 12:20:32 +00:00
|
|
|
if (wmCommand.isEmpty()) {
|
2016-06-23 17:40:40 +00:00
|
|
|
continue;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
count++;
|
2022-03-25 12:20:32 +00:00
|
|
|
if (c->isActive()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
active_client = count;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
|
|
|
if (phase == SMSavePhase2 || phase == SMSavePhase2Full) {
|
2010-10-20 12:41:51 +00:00
|
|
|
storeClient(cg, count, c);
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (phase == SMSavePhase0) {
|
2007-04-29 17:35:43 +00:00
|
|
|
// it would be much simpler to save these values to the config file,
|
|
|
|
// but both Qt and KDE treat phase1 and phase2 separately,
|
|
|
|
// which results in different sessionkey and different config file :(
|
|
|
|
session_active_client = active_client;
|
2012-11-16 07:23:47 +00:00
|
|
|
session_desktop = VirtualDesktopManager::self()->current();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (phase == SMSavePhase2) {
|
|
|
|
cg.writeEntry("count", count);
|
|
|
|
cg.writeEntry("active", session_active_client);
|
|
|
|
cg.writeEntry("desktop", session_desktop);
|
|
|
|
} else { // SMSavePhase2Full
|
|
|
|
cg.writeEntry("count", count);
|
|
|
|
cg.writeEntry("active", session_active_client);
|
2012-11-16 07:23:47 +00:00
|
|
|
cg.writeEntry("desktop", VirtualDesktopManager::self()->current());
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2020-04-02 11:44:27 +00:00
|
|
|
config->sync(); // it previously did some "revert to defaults" stuff for phase1 I think
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
void Workspace::storeClient(KConfigGroup &cg, int num, X11Client *c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
c->setSessionActivityOverride(false); // make sure we get the real values
|
2010-10-20 12:41:51 +00:00
|
|
|
QString n = QString::number(num);
|
2015-11-05 14:14:06 +00:00
|
|
|
cg.writeEntry(QLatin1String("sessionId") + n, c->sessionId().constData());
|
|
|
|
cg.writeEntry(QLatin1String("windowRole") + n, c->windowRole().constData());
|
2016-06-23 17:40:40 +00:00
|
|
|
cg.writeEntry(QLatin1String("wmCommand") + n, c->wmCommand().constData());
|
2015-11-05 14:14:06 +00:00
|
|
|
cg.writeEntry(QLatin1String("resourceName") + n, c->resourceName().constData());
|
|
|
|
cg.writeEntry(QLatin1String("resourceClass") + n, c->resourceClass().constData());
|
2022-03-23 10:13:38 +00:00
|
|
|
cg.writeEntry(QLatin1String("geometry") + n, QRect(c->calculateGravitation(true), c->clientSize())); // FRAME
|
2015-11-05 14:14:06 +00:00
|
|
|
cg.writeEntry(QLatin1String("restore") + n, c->geometryRestore());
|
2021-01-20 19:36:07 +00:00
|
|
|
cg.writeEntry(QLatin1String("fsrestore") + n, c->fullscreenGeometryRestore());
|
2022-03-23 10:13:38 +00:00
|
|
|
cg.writeEntry(QLatin1String("maximize") + n, (int)c->maximizeMode());
|
|
|
|
cg.writeEntry(QLatin1String("fullscreen") + n, (int)c->fullScreenMode());
|
2015-11-05 14:14:06 +00:00
|
|
|
cg.writeEntry(QLatin1String("desktop") + n, c->desktop());
|
2010-10-20 12:41:51 +00:00
|
|
|
// the config entry is called "iconified" for back. comp. reasons
|
|
|
|
// (kconf_update script for updating session files would be too complicated)
|
2015-11-05 14:14:06 +00:00
|
|
|
cg.writeEntry(QLatin1String("iconified") + n, c->isMinimized());
|
|
|
|
cg.writeEntry(QLatin1String("opacity") + n, c->opacity());
|
2010-10-20 12:41:51 +00:00
|
|
|
// the config entry is called "sticky" for back. comp. reasons
|
2015-11-05 14:14:06 +00:00
|
|
|
cg.writeEntry(QLatin1String("sticky") + n, c->isOnAllDesktops());
|
|
|
|
cg.writeEntry(QLatin1String("shaded") + n, c->isShade());
|
2010-10-20 12:41:51 +00:00
|
|
|
// the config entry is called "staysOnTop" for back. comp. reasons
|
2015-11-05 14:14:06 +00:00
|
|
|
cg.writeEntry(QLatin1String("staysOnTop") + n, c->keepAbove());
|
|
|
|
cg.writeEntry(QLatin1String("keepBelow") + n, c->keepBelow());
|
|
|
|
cg.writeEntry(QLatin1String("skipTaskbar") + n, c->originalSkipTaskbar());
|
|
|
|
cg.writeEntry(QLatin1String("skipPager") + n, c->skipPager());
|
|
|
|
cg.writeEntry(QLatin1String("skipSwitcher") + n, c->skipSwitcher());
|
2010-10-20 12:41:51 +00:00
|
|
|
// not really just set by user, but name kept for back. comp. reasons
|
2019-02-05 11:10:40 +00:00
|
|
|
cg.writeEntry(QLatin1String("userNoBorder") + n, c->userNoBorder());
|
2015-11-05 14:14:06 +00:00
|
|
|
cg.writeEntry(QLatin1String("windowType") + n, windowTypeToTxt(c->windowType()));
|
|
|
|
cg.writeEntry(QLatin1String("shortcut") + n, c->shortcut().toString());
|
|
|
|
cg.writeEntry(QLatin1String("stackingOrder") + n, unconstrained_stacking_order.indexOf(c));
|
|
|
|
cg.writeEntry(QLatin1String("activities") + n, c->activities());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-20 12:41:51 +00:00
|
|
|
|
|
|
|
void Workspace::storeSubSession(const QString &name, QSet<QByteArray> sessionIds)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
// TODO clear it first
|
2015-11-05 14:14:06 +00:00
|
|
|
KConfigGroup cg(KSharedConfig::openConfig(), QLatin1String("SubSession: ") + name);
|
2022-03-23 10:13:38 +00:00
|
|
|
int count = 0;
|
2010-10-20 12:41:51 +00:00
|
|
|
int active_client = -1;
|
2021-05-24 16:01:49 +00:00
|
|
|
for (auto it = m_x11Clients.begin(); it != m_x11Clients.end(); ++it) {
|
2019-09-24 08:48:08 +00:00
|
|
|
X11Client *c = (*it);
|
2018-06-27 00:36:02 +00:00
|
|
|
if (c->windowType() > NET::Splash) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-10-20 12:41:51 +00:00
|
|
|
QByteArray sessionId = c->sessionId();
|
2016-06-23 17:40:40 +00:00
|
|
|
QByteArray wmCommand = c->wmCommand();
|
2022-03-25 12:20:32 +00:00
|
|
|
if (sessionId.isEmpty()) {
|
2016-06-23 17:40:40 +00:00
|
|
|
// remember also applications that are not XSMP capable
|
|
|
|
// and use the obsolete WM_COMMAND / WM_SAVE_YOURSELF
|
2022-03-25 12:20:32 +00:00
|
|
|
if (wmCommand.isEmpty()) {
|
2016-06-23 17:40:40 +00:00
|
|
|
continue;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!sessionIds.contains(sessionId)) {
|
2010-10-20 12:41:51 +00:00
|
|
|
continue;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2010-10-20 12:41:51 +00:00
|
|
|
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "storing" << sessionId;
|
2010-10-20 12:41:51 +00:00
|
|
|
count++;
|
2022-03-25 12:20:32 +00:00
|
|
|
if (c->isActive()) {
|
2010-10-20 12:41:51 +00:00
|
|
|
active_client = count;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2010-10-20 12:41:51 +00:00
|
|
|
storeClient(cg, count, c);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
cg.writeEntry("count", count);
|
|
|
|
cg.writeEntry("active", active_client);
|
2022-03-23 10:13:38 +00:00
|
|
|
// cg.writeEntry( "desktop", currentDesktop());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-20 12:41:51 +00:00
|
|
|
|
2019-02-02 18:17:44 +00:00
|
|
|
/**
|
|
|
|
* Loads the session information from the config file.
|
|
|
|
*
|
|
|
|
* @see storeSession
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2020-04-02 11:44:27 +00:00
|
|
|
void Workspace::loadSessionInfo(const QString &sessionName)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
session.clear();
|
2020-04-02 11:44:27 +00:00
|
|
|
KConfigGroup cg(sessionConfig(sessionName, QString()), "Session");
|
2010-10-20 12:41:51 +00:00
|
|
|
addSessionInfo(cg);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-20 12:41:51 +00:00
|
|
|
|
|
|
|
void Workspace::addSessionInfo(KConfigGroup &cg)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2015-11-05 14:14:06 +00:00
|
|
|
m_initialDesktop = cg.readEntry("desktop", 1);
|
2022-03-23 10:13:38 +00:00
|
|
|
int count = cg.readEntry("count", 0);
|
2011-01-30 14:34:42 +00:00
|
|
|
int active_client = cg.readEntry("active", 0);
|
|
|
|
for (int i = 1; i <= count; i++) {
|
2007-04-29 17:35:43 +00:00
|
|
|
QString n = QString::number(i);
|
2022-03-23 10:13:38 +00:00
|
|
|
SessionInfo *info = new SessionInfo;
|
2011-01-30 14:34:42 +00:00
|
|
|
session.append(info);
|
2015-11-05 14:14:06 +00:00
|
|
|
info->sessionId = cg.readEntry(QLatin1String("sessionId") + n, QString()).toLatin1();
|
|
|
|
info->windowRole = cg.readEntry(QLatin1String("windowRole") + n, QString()).toLatin1();
|
2016-06-23 17:40:40 +00:00
|
|
|
info->wmCommand = cg.readEntry(QLatin1String("wmCommand") + n, QString()).toLatin1();
|
2015-11-05 14:14:06 +00:00
|
|
|
info->resourceName = cg.readEntry(QLatin1String("resourceName") + n, QString()).toLatin1();
|
|
|
|
info->resourceClass = cg.readEntry(QLatin1String("resourceClass") + n, QString()).toLower().toLatin1();
|
|
|
|
info->geometry = cg.readEntry(QLatin1String("geometry") + n, QRect());
|
|
|
|
info->restore = cg.readEntry(QLatin1String("restore") + n, QRect());
|
|
|
|
info->fsrestore = cg.readEntry(QLatin1String("fsrestore") + n, QRect());
|
|
|
|
info->maximized = cg.readEntry(QLatin1String("maximize") + n, 0);
|
|
|
|
info->fullscreen = cg.readEntry(QLatin1String("fullscreen") + n, 0);
|
|
|
|
info->desktop = cg.readEntry(QLatin1String("desktop") + n, 0);
|
|
|
|
info->minimized = cg.readEntry(QLatin1String("iconified") + n, false);
|
|
|
|
info->opacity = cg.readEntry(QLatin1String("opacity") + n, 1.0);
|
|
|
|
info->onAllDesktops = cg.readEntry(QLatin1String("sticky") + n, false);
|
|
|
|
info->shaded = cg.readEntry(QLatin1String("shaded") + n, false);
|
|
|
|
info->keepAbove = cg.readEntry(QLatin1String("staysOnTop") + n, false);
|
|
|
|
info->keepBelow = cg.readEntry(QLatin1String("keepBelow") + n, false);
|
|
|
|
info->skipTaskbar = cg.readEntry(QLatin1String("skipTaskbar") + n, false);
|
|
|
|
info->skipPager = cg.readEntry(QLatin1String("skipPager") + n, false);
|
|
|
|
info->skipSwitcher = cg.readEntry(QLatin1String("skipSwitcher") + n, false);
|
|
|
|
info->noBorder = cg.readEntry(QLatin1String("userNoBorder") + n, false);
|
|
|
|
info->windowType = txtToWindowType(cg.readEntry(QLatin1String("windowType") + n, QString()).toLatin1().constData());
|
|
|
|
info->shortcut = cg.readEntry(QLatin1String("shortcut") + n, QString());
|
2011-01-30 14:34:42 +00:00
|
|
|
info->active = (active_client == i);
|
2015-11-05 14:14:06 +00:00
|
|
|
info->stackingOrder = cg.readEntry(QLatin1String("stackingOrder") + n, -1);
|
|
|
|
info->activities = cg.readEntry(QLatin1String("activities") + n, QStringList());
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-10-20 12:41:51 +00:00
|
|
|
void Workspace::loadSubSessionInfo(const QString &name)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2015-11-05 14:14:06 +00:00
|
|
|
KConfigGroup cg(KSharedConfig::openConfig(), QLatin1String("SubSession: ") + name);
|
2010-10-20 12:41:51 +00:00
|
|
|
addSessionInfo(cg);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-20 12:41:51 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
static bool sessionInfoWindowTypeMatch(X11Client *c, SessionInfo *info)
|
2019-04-24 07:55:35 +00:00
|
|
|
{
|
|
|
|
if (info->windowType == -2) {
|
|
|
|
// undefined (not really part of NET::WindowType)
|
|
|
|
return !c->isSpecialWindow();
|
|
|
|
}
|
|
|
|
return info->windowType == c->windowType();
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:17:44 +00:00
|
|
|
/**
|
|
|
|
* Returns a SessionInfo for client \a c. The returned session
|
|
|
|
* info is removed from the storage. It's up to the caller to delete it.
|
|
|
|
*
|
|
|
|
* This function is called when a new window is mapped and must be managed.
|
|
|
|
* We try to find a matching entry in the session.
|
|
|
|
*
|
|
|
|
* May return 0 if there's no session info for the client.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-03-23 10:13:38 +00:00
|
|
|
SessionInfo *Workspace::takeSessionInfo(X11Client *c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
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
|
|
|
SessionInfo *realInfo = nullptr;
|
2007-04-29 17:35:43 +00:00
|
|
|
QByteArray sessionId = c->sessionId();
|
|
|
|
QByteArray windowRole = c->windowRole();
|
2016-06-23 17:40:40 +00:00
|
|
|
QByteArray wmCommand = c->wmCommand();
|
2007-04-29 17:35:43 +00:00
|
|
|
QByteArray resourceName = c->resourceName();
|
|
|
|
QByteArray resourceClass = c->resourceClass();
|
|
|
|
|
|
|
|
// First search ``session''
|
2022-03-23 10:13:38 +00:00
|
|
|
if (!sessionId.isEmpty()) {
|
2007-10-10 18:15:19 +00:00
|
|
|
// look for a real session managed client (algorithm suggested by ICCCM)
|
2021-11-03 11:55:31 +00:00
|
|
|
for (SessionInfo *info : qAsConst(session)) {
|
2022-03-25 12:20:32 +00:00
|
|
|
if (realInfo) {
|
2007-10-10 18:15:19 +00:00
|
|
|
break;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->sessionId == sessionId && sessionInfoWindowTypeMatch(c, info)) {
|
2022-03-23 10:13:38 +00:00
|
|
|
if (!windowRole.isEmpty()) {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->windowRole == windowRole) {
|
2007-10-10 18:15:19 +00:00
|
|
|
realInfo = info;
|
|
|
|
session.removeAll(info);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
if (info->windowRole.isEmpty()
|
2022-03-23 10:13:38 +00:00
|
|
|
&& info->resourceName == resourceName
|
|
|
|
&& info->resourceClass == resourceClass) {
|
2007-10-10 18:15:19 +00:00
|
|
|
realInfo = info;
|
|
|
|
session.removeAll(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2007-10-10 18:15:19 +00:00
|
|
|
// look for a sessioninfo with matching features.
|
2021-11-03 11:55:31 +00:00
|
|
|
for (SessionInfo *info : qAsConst(session)) {
|
2022-03-25 12:20:32 +00:00
|
|
|
if (realInfo) {
|
2007-10-10 18:15:19 +00:00
|
|
|
break;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->resourceName == resourceName
|
2022-03-23 10:13:38 +00:00
|
|
|
&& info->resourceClass == resourceClass
|
|
|
|
&& sessionInfoWindowTypeMatch(c, info)) {
|
2016-06-23 17:40:40 +00:00
|
|
|
if (wmCommand.isEmpty() || info->wmCommand == wmCommand) {
|
|
|
|
realInfo = info;
|
|
|
|
session.removeAll(info);
|
|
|
|
}
|
2007-10-10 18:15:19 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
return realInfo;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-10-31 16:16:53 +00:00
|
|
|
SessionManager::SessionManager(QObject *parent)
|
|
|
|
: QObject(parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-10-31 16:16:53 +00:00
|
|
|
new SessionAdaptor(this);
|
|
|
|
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Session"), this);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-10-31 16:16:53 +00:00
|
|
|
SessionManager::~SessionManager()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-10-31 16:16:53 +00:00
|
|
|
SessionState SessionManager::state() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-10-31 16:16:53 +00:00
|
|
|
return m_sessionState;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-10-31 16:16:53 +00:00
|
|
|
void SessionManager::setState(uint state)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-10-31 16:16:53 +00:00
|
|
|
switch (state) {
|
|
|
|
case 0:
|
|
|
|
setState(SessionState::Saving);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
setState(SessionState::Quitting);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
setState(SessionState::Normal);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-04-02 11:44:27 +00:00
|
|
|
// TODO should we rethink this now that we have dedicated start end end save methods?
|
2019-10-31 16:16:53 +00:00
|
|
|
void SessionManager::setState(SessionState state)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-10-31 16:16:53 +00:00
|
|
|
if (state == m_sessionState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If we're starting to save a session
|
|
|
|
if (state == SessionState::Saving) {
|
|
|
|
RuleBook::self()->setUpdatesDisabled(true);
|
|
|
|
}
|
|
|
|
// If we're ending a save session due to either completion or cancellation
|
|
|
|
if (m_sessionState == SessionState::Saving) {
|
|
|
|
RuleBook::self()->setUpdatesDisabled(false);
|
|
|
|
Workspace::self()->forEachClient([](X11Client *client) {
|
|
|
|
client->setSessionActivityOverride(false);
|
|
|
|
});
|
2010-12-16 20:14:22 +00:00
|
|
|
}
|
2019-10-31 16:16:53 +00:00
|
|
|
m_sessionState = state;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT stateChanged();
|
2010-12-16 20:14:22 +00:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:44:27 +00:00
|
|
|
void SessionManager::loadSession(const QString &name)
|
|
|
|
{
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT loadSessionRequested(name);
|
2020-04-02 11:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SessionManager::aboutToSaveSession(const QString &name)
|
|
|
|
{
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT prepareSessionSaveRequested(name);
|
2020-04-02 11:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SessionManager::finishSaveSession(const QString &name)
|
|
|
|
{
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT finishSessionSaveRequested(name);
|
2020-04-02 11:44:27 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 13:08:02 +00:00
|
|
|
void SessionManager::quit()
|
|
|
|
{
|
|
|
|
qApp->quit();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|