2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "sm.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <fixx11h.h>
|
|
|
|
#include <kconfig.h>
|
|
|
|
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
2013-09-02 11:14:39 +00:00
|
|
|
#include <QDebug>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QSocketNotifier>
|
2008-02-02 20:54:19 +00:00
|
|
|
#include <QSessionManager>
|
2013-08-06 08:27:49 +00:00
|
|
|
#include <KDE/KApplication>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool SessionManager::saveState(QSessionManager& sm)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// If the session manager is ksmserver, save stacking
|
|
|
|
// order, active window, active desktop etc. in phase 1,
|
|
|
|
// as ksmserver assures no interaction will be done
|
|
|
|
// before the WM finishes phase 1. Saving in phase 2 is
|
|
|
|
// too late, as possible user interaction may change some things.
|
|
|
|
// Phase2 is still needed though (ICCCM 5.2)
|
2013-07-23 04:40:47 +00:00
|
|
|
#if KWIN_QT5_PORTING
|
2011-01-30 14:34:42 +00:00
|
|
|
char* sm_vendor = SmcVendor(static_cast< SmcConn >(sm.handle()));
|
|
|
|
bool ksmserver = qstrcmp(sm_vendor, "KDE") == 0;
|
|
|
|
free(sm_vendor);
|
2013-07-23 04:40:47 +00:00
|
|
|
#else
|
|
|
|
#warning need to figure out whether the used SessionManager is ksmserver
|
|
|
|
bool ksmserver = false;
|
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!sm.isPhase2()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
Workspace::self()->sessionSaveStarted();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (ksmserver) // save stacking order etc. before "save file?" etc. dialogs change it
|
|
|
|
Workspace::self()->storeSession(kapp->sessionConfig(), SMSavePhase0);
|
2007-04-29 17:35:43 +00:00
|
|
|
sm.release(); // Qt doesn't automatically release in this case (bug?)
|
|
|
|
sm.requestPhase2();
|
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
Workspace::self()->storeSession(kapp->sessionConfig(), ksmserver ? SMSavePhase2 : SMSavePhase2Full);
|
2013-08-28 11:50:52 +00:00
|
|
|
#if KWIN_QT5_PORTING
|
2007-04-29 17:35:43 +00:00
|
|
|
kapp->sessionConfig()->sync();
|
2013-08-28 11:50:52 +00:00
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// I bet this is broken, just like everywhere else in KDE
|
2011-01-30 14:34:42 +00:00
|
|
|
bool SessionManager::commitData(QSessionManager& sm)
|
|
|
|
{
|
|
|
|
if (!sm.isPhase2())
|
2007-04-29 17:35:43 +00:00
|
|
|
Workspace::self()->sessionSaveStarted();
|
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// Workspace
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Stores the current session in the config file
|
|
|
|
|
|
|
|
\sa loadSessionInfo()
|
|
|
|
*/
|
2011-01-30 14:34:42 +00:00
|
|
|
void Workspace::storeSession(KConfig* config, SMSavePhase phase)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
KConfigGroup cg(config, "Session");
|
|
|
|
int count = 0;
|
|
|
|
int active_client = -1;
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (ClientList::Iterator it = clients.begin(); it != clients.end(); ++it) {
|
2007-04-29 17:35:43 +00:00
|
|
|
Client* c = (*it);
|
|
|
|
QByteArray sessionId = c->sessionId();
|
|
|
|
QByteArray wmCommand = c->wmCommand();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (sessionId.isEmpty())
|
|
|
|
// remember also applications that are not XSMP capable
|
|
|
|
// and use the obsolete WM_COMMAND / WM_SAVE_YOURSELF
|
|
|
|
if (wmCommand.isEmpty())
|
2007-04-29 17:35:43 +00:00
|
|
|
continue;
|
|
|
|
count++;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->isActive())
|
2007-04-29 17:35:43 +00:00
|
|
|
active_client = count;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (phase == SMSavePhase2 || phase == SMSavePhase2Full)
|
2010-10-20 12:41:51 +00:00
|
|
|
storeClient(cg, count, c);
|
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
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Workspace::storeClient(KConfigGroup &cg, int num, Client *c)
|
|
|
|
{
|
2010-12-16 20:14:22 +00:00
|
|
|
c->setSessionInteract(false); //make sure we get the real values
|
2010-10-20 12:41:51 +00:00
|
|
|
QString n = QString::number(num);
|
2013-07-23 05:02:52 +00:00
|
|
|
cg.writeEntry(QStringLiteral("sessionId") + n, c->sessionId().constData());
|
|
|
|
cg.writeEntry(QStringLiteral("windowRole") + n, c->windowRole().constData());
|
|
|
|
cg.writeEntry(QStringLiteral("wmCommand") + n, c->wmCommand().constData());
|
|
|
|
cg.writeEntry(QStringLiteral("wmClientMachine") + n, c->wmClientMachine(true).constData());
|
|
|
|
cg.writeEntry(QStringLiteral("resourceName") + n, c->resourceName().constData());
|
|
|
|
cg.writeEntry(QStringLiteral("resourceClass") + n, c->resourceClass().constData());
|
|
|
|
cg.writeEntry(QStringLiteral("geometry") + n, QRect(c->calculateGravitation(true), c->clientSize())); // FRAME
|
|
|
|
cg.writeEntry(QStringLiteral("restore") + n, c->geometryRestore());
|
|
|
|
cg.writeEntry(QStringLiteral("fsrestore") + n, c->geometryFSRestore());
|
|
|
|
cg.writeEntry(QStringLiteral("maximize") + n, (int) c->maximizeMode());
|
|
|
|
cg.writeEntry(QStringLiteral("fullscreen") + n, (int) c->fullScreenMode());
|
|
|
|
cg.writeEntry(QStringLiteral("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)
|
2013-07-23 05:02:52 +00:00
|
|
|
cg.writeEntry(QStringLiteral("iconified") + n, c->isMinimized());
|
|
|
|
cg.writeEntry(QStringLiteral("opacity") + n, c->opacity());
|
2010-10-20 12:41:51 +00:00
|
|
|
// the config entry is called "sticky" for back. comp. reasons
|
2013-07-23 05:02:52 +00:00
|
|
|
cg.writeEntry(QStringLiteral("sticky") + n, c->isOnAllDesktops());
|
|
|
|
cg.writeEntry(QStringLiteral("shaded") + n, c->isShade());
|
2010-10-20 12:41:51 +00:00
|
|
|
// the config entry is called "staysOnTop" for back. comp. reasons
|
2013-07-23 05:02:52 +00:00
|
|
|
cg.writeEntry(QStringLiteral("staysOnTop") + n, c->keepAbove());
|
|
|
|
cg.writeEntry(QStringLiteral("keepBelow") + n, c->keepBelow());
|
|
|
|
cg.writeEntry(QStringLiteral("skipTaskbar") + n, c->skipTaskbar(true));
|
|
|
|
cg.writeEntry(QStringLiteral("skipPager") + n, c->skipPager());
|
|
|
|
cg.writeEntry(QStringLiteral("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
|
2013-07-23 05:02:52 +00:00
|
|
|
cg.writeEntry(QStringLiteral("userNoBorder") + n, c->noBorder());
|
|
|
|
cg.writeEntry(QStringLiteral("windowType") + n, windowTypeToTxt(c->windowType()));
|
|
|
|
cg.writeEntry(QStringLiteral("shortcut") + n, c->shortcut().toString());
|
|
|
|
cg.writeEntry(QStringLiteral("stackingOrder") + n, unconstrained_stacking_order.indexOf(c));
|
2012-01-12 06:42:55 +00:00
|
|
|
// KConfig doesn't support long so we need to live with less precision on 64-bit systems
|
2013-07-23 05:02:52 +00:00
|
|
|
cg.writeEntry(QStringLiteral("tabGroup") + n, static_cast<int>(reinterpret_cast<long>(c->tabGroup())));
|
|
|
|
cg.writeEntry(QStringLiteral("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
|
|
|
{
|
2010-10-20 12:41:51 +00:00
|
|
|
//TODO clear it first
|
2013-09-04 14:10:36 +00:00
|
|
|
KConfigGroup cg(KSharedConfig::openConfig(), QStringLiteral("SubSession: ") + name);
|
2010-10-20 12:41:51 +00:00
|
|
|
int count = 0;
|
|
|
|
int active_client = -1;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (ClientList::Iterator it = clients.begin(); it != clients.end(); ++it) {
|
2010-10-20 12:41:51 +00:00
|
|
|
Client* c = (*it);
|
|
|
|
QByteArray sessionId = c->sessionId();
|
|
|
|
QByteArray wmCommand = c->wmCommand();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (sessionId.isEmpty())
|
|
|
|
// remember also applications that are not XSMP capable
|
|
|
|
// and use the obsolete WM_COMMAND / WM_SAVE_YOURSELF
|
|
|
|
if (wmCommand.isEmpty())
|
2010-10-20 12:41:51 +00:00
|
|
|
continue;
|
|
|
|
if (!sessionIds.contains(sessionId))
|
|
|
|
continue;
|
|
|
|
|
2013-09-02 11:14:39 +00:00
|
|
|
qDebug() << "storing" << sessionId;
|
2010-10-20 12:41:51 +00:00
|
|
|
count++;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->isActive())
|
2010-10-20 12:41:51 +00:00
|
|
|
active_client = count;
|
|
|
|
storeClient(cg, count, c);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
cg.writeEntry("count", count);
|
|
|
|
cg.writeEntry("active", active_client);
|
|
|
|
//cg.writeEntry( "desktop", currentDesktop());
|
|
|
|
}
|
2010-10-20 12:41:51 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
/*!
|
|
|
|
Loads the session information from the config file.
|
|
|
|
|
|
|
|
\sa storeSession()
|
|
|
|
*/
|
|
|
|
void Workspace::loadSessionInfo()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
session.clear();
|
2013-08-28 11:50:52 +00:00
|
|
|
#if KWIN_QT5_PORTING
|
2007-04-29 17:35:43 +00:00
|
|
|
KConfigGroup cg(kapp->sessionConfig(), "Session");
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2010-10-20 12:41:51 +00:00
|
|
|
addSessionInfo(cg);
|
2013-08-28 11:50:52 +00:00
|
|
|
#endif
|
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
|
|
|
{
|
|
|
|
int count = cg.readEntry("count", 0);
|
|
|
|
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);
|
|
|
|
SessionInfo* info = new SessionInfo;
|
2011-01-30 14:34:42 +00:00
|
|
|
session.append(info);
|
2013-07-23 05:02:52 +00:00
|
|
|
info->sessionId = cg.readEntry(QStringLiteral("sessionId") + n, QString()).toLatin1();
|
|
|
|
info->windowRole = cg.readEntry(QStringLiteral("windowRole") + n, QString()).toLatin1();
|
|
|
|
info->wmCommand = cg.readEntry(QStringLiteral("wmCommand") + n, QString()).toLatin1();
|
|
|
|
info->wmClientMachine = cg.readEntry(QStringLiteral("wmClientMachine") + n, QString()).toLatin1();
|
|
|
|
info->resourceName = cg.readEntry(QStringLiteral("resourceName") + n, QString()).toLatin1();
|
|
|
|
info->resourceClass = cg.readEntry(QStringLiteral("resourceClass") + n, QString()).toLower().toLatin1();
|
|
|
|
info->geometry = cg.readEntry(QStringLiteral("geometry") + n, QRect());
|
|
|
|
info->restore = cg.readEntry(QStringLiteral("restore") + n, QRect());
|
|
|
|
info->fsrestore = cg.readEntry(QStringLiteral("fsrestore") + n, QRect());
|
|
|
|
info->maximized = cg.readEntry(QStringLiteral("maximize") + n, 0);
|
|
|
|
info->fullscreen = cg.readEntry(QStringLiteral("fullscreen") + n, 0);
|
|
|
|
info->desktop = cg.readEntry(QStringLiteral("desktop") + n, 0);
|
|
|
|
info->minimized = cg.readEntry(QStringLiteral("iconified") + n, false);
|
|
|
|
info->opacity = cg.readEntry(QStringLiteral("opacity") + n, 1.0);
|
|
|
|
info->onAllDesktops = cg.readEntry(QStringLiteral("sticky") + n, false);
|
|
|
|
info->shaded = cg.readEntry(QStringLiteral("shaded") + n, false);
|
|
|
|
info->keepAbove = cg.readEntry(QStringLiteral("staysOnTop") + n, false);
|
|
|
|
info->keepBelow = cg.readEntry(QStringLiteral("keepBelow") + n, false);
|
|
|
|
info->skipTaskbar = cg.readEntry(QStringLiteral("skipTaskbar") + n, false);
|
|
|
|
info->skipPager = cg.readEntry(QStringLiteral("skipPager") + n, false);
|
|
|
|
info->skipSwitcher = cg.readEntry(QStringLiteral("skipSwitcher") + n, false);
|
|
|
|
info->noBorder = cg.readEntry(QStringLiteral("userNoBorder") + n, false);
|
|
|
|
info->windowType = txtToWindowType(cg.readEntry(QStringLiteral("windowType") + n, QString()).toLatin1().constData());
|
|
|
|
info->shortcut = cg.readEntry(QStringLiteral("shortcut") + n, QString());
|
2011-01-30 14:34:42 +00:00
|
|
|
info->active = (active_client == i);
|
2013-07-23 05:02:52 +00:00
|
|
|
info->stackingOrder = cg.readEntry(QStringLiteral("stackingOrder") + n, -1);
|
|
|
|
info->tabGroup = cg.readEntry(QStringLiteral("tabGroup") + n, 0);
|
2012-01-12 06:42:55 +00:00
|
|
|
info->tabGroupClient = NULL;
|
2013-07-23 05:02:52 +00:00
|
|
|
info->activities = cg.readEntry(QStringLiteral("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
|
|
|
{
|
2013-09-04 14:10:36 +00:00
|
|
|
KConfigGroup cg(KSharedConfig::openConfig(), QStringLiteral("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
|
|
|
|
2007-04-29 17:35:43 +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.
|
|
|
|
*/
|
2011-01-30 14:34:42 +00:00
|
|
|
SessionInfo* Workspace::takeSessionInfo(Client* c)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
SessionInfo *realInfo = 0;
|
|
|
|
QByteArray sessionId = c->sessionId();
|
|
|
|
QByteArray windowRole = c->windowRole();
|
|
|
|
QByteArray wmCommand = c->wmCommand();
|
2011-01-30 14:34:42 +00:00
|
|
|
QByteArray wmClientMachine = c->wmClientMachine(true);
|
2007-04-29 17:35:43 +00:00
|
|
|
QByteArray resourceName = c->resourceName();
|
|
|
|
QByteArray resourceClass = c->resourceClass();
|
|
|
|
|
|
|
|
// First search ``session''
|
2011-01-30 14:34:42 +00:00
|
|
|
if (! sessionId.isEmpty()) {
|
2007-10-10 18:15:19 +00:00
|
|
|
// look for a real session managed client (algorithm suggested by ICCCM)
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (SessionInfo * info, session) {
|
|
|
|
if (realInfo)
|
2007-10-10 18:15:19 +00:00
|
|
|
break;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->sessionId == sessionId && sessionInfoWindowTypeMatch(c, info)) {
|
|
|
|
if (! windowRole.isEmpty()) {
|
|
|
|
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()
|
|
|
|
&& 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.
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (SessionInfo * info, session) {
|
|
|
|
if (realInfo)
|
2007-10-10 18:15:19 +00:00
|
|
|
break;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (info->resourceName == resourceName
|
|
|
|
&& info->resourceClass == resourceClass
|
|
|
|
&& info->wmClientMachine == wmClientMachine
|
|
|
|
&& sessionInfoWindowTypeMatch(c, info)) {
|
|
|
|
if (wmCommand.isEmpty() || info->wmCommand == wmCommand) {
|
2007-10-10 18:15:19 +00:00
|
|
|
realInfo = info;
|
2011-01-30 14:34:42 +00:00
|
|
|
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
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
// Set tabGroupClient for other clients in the same group
|
|
|
|
if (realInfo && realInfo->tabGroup) {
|
|
|
|
foreach (SessionInfo * info, session) {
|
|
|
|
if (!info->tabGroupClient && info->tabGroup == realInfo->tabGroup)
|
|
|
|
info->tabGroupClient = c;
|
|
|
|
}
|
|
|
|
}
|
2009-11-15 03:24:04 +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
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool Workspace::sessionInfoWindowTypeMatch(Client* c, SessionInfo* info)
|
|
|
|
{
|
|
|
|
if (info->windowType == -2) {
|
|
|
|
// undefined (not really part of NET::WindowType)
|
2007-04-29 17:35:43 +00:00
|
|
|
return !c->isSpecialWindow();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return info->windowType == c->windowType();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static const char* const window_type_names[] = {
|
2007-04-29 17:35:43 +00:00
|
|
|
"Unknown", "Normal" , "Desktop", "Dock", "Toolbar", "Menu", "Dialog",
|
|
|
|
"Override", "TopMenu", "Utility", "Splash"
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
// change also the two functions below when adding new entries
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
const char* Workspace::windowTypeToTxt(NET::WindowType type)
|
|
|
|
{
|
|
|
|
if (type >= NET::Unknown && type <= NET::Splash)
|
2007-04-29 17:35:43 +00:00
|
|
|
return window_type_names[ type + 1 ]; // +1 (unknown==-1)
|
2011-01-30 14:34:42 +00:00
|
|
|
if (type == -2) // undefined (not really part of NET::WindowType)
|
2007-04-29 17:35:43 +00:00
|
|
|
return "Undefined";
|
2013-09-02 11:14:39 +00:00
|
|
|
qFatal("Unknown Window Type");
|
2007-04-29 17:35:43 +00:00
|
|
|
return NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
NET::WindowType Workspace::txtToWindowType(const char* txt)
|
|
|
|
{
|
|
|
|
for (int i = NET::Unknown;
|
|
|
|
i <= NET::Splash;
|
|
|
|
++i)
|
|
|
|
if (qstrcmp(txt, window_type_names[ i + 1 ]) == 0) // +1
|
|
|
|
return static_cast< NET::WindowType >(i);
|
|
|
|
return static_cast< NET::WindowType >(-2); // undefined
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// KWin's focus stealing prevention causes problems with user interaction
|
|
|
|
// during session save, as it prevents possible dialogs from getting focus.
|
|
|
|
// Therefore it's temporarily disabled during session saving. Start of
|
|
|
|
// session saving can be detected in SessionManager::saveState() above,
|
|
|
|
// but Qt doesn't have API for saying when session saved finished (either
|
|
|
|
// successfully, or was canceled). Therefore, create another connection
|
|
|
|
// to session manager, that will provide this information.
|
2007-04-30 12:24:10 +00:00
|
|
|
// Similarly the remember feature of window-specific settings should be disabled
|
|
|
|
// during KDE shutdown when windows may move e.g. because of Kicker going away
|
|
|
|
// (struts changing). When session saving starts, it can be cancelled, in which
|
|
|
|
// case the shutdown_cancelled callback is invoked, or it's a checkpoint that
|
|
|
|
// is immediatelly followed by save_complete, or finally it's a shutdown that
|
|
|
|
// is immediatelly followed by die callback. So getting save_yourself with shutdown
|
|
|
|
// set disables window-specific settings remembering, getting shutdown_cancelled
|
|
|
|
// re-enables, otherwise KWin will go away after die.
|
2011-01-30 14:34:42 +00:00
|
|
|
static void save_yourself(SmcConn conn_P, SmPointer ptr, int, Bool shutdown, int, Bool)
|
|
|
|
{
|
|
|
|
SessionSaveDoneHelper* session = reinterpret_cast< SessionSaveDoneHelper* >(ptr);
|
|
|
|
if (conn_P != session->connection())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (shutdown)
|
2013-04-26 12:40:35 +00:00
|
|
|
RuleBook::self()->setUpdatesDisabled(true);
|
2011-01-30 14:34:42 +00:00
|
|
|
SmcSaveYourselfDone(conn_P, True);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static void die(SmcConn conn_P, SmPointer ptr)
|
|
|
|
{
|
|
|
|
SessionSaveDoneHelper* session = reinterpret_cast< SessionSaveDoneHelper* >(ptr);
|
|
|
|
if (conn_P != session->connection())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
// session->saveDone(); we will quit anyway
|
|
|
|
session->close();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static void save_complete(SmcConn conn_P, SmPointer ptr)
|
|
|
|
{
|
|
|
|
SessionSaveDoneHelper* session = reinterpret_cast< SessionSaveDoneHelper* >(ptr);
|
|
|
|
if (conn_P != session->connection())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
session->saveDone();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static void shutdown_cancelled(SmcConn conn_P, SmPointer ptr)
|
|
|
|
{
|
|
|
|
SessionSaveDoneHelper* session = reinterpret_cast< SessionSaveDoneHelper* >(ptr);
|
|
|
|
if (conn_P != session->connection())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2013-04-26 12:40:35 +00:00
|
|
|
RuleBook::self()->setUpdatesDisabled(false); // re-enable
|
2007-04-29 17:35:43 +00:00
|
|
|
// no need to differentiate between successful finish and cancel
|
|
|
|
session->saveDone();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void SessionSaveDoneHelper::saveDone()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-08-13 08:21:28 +00:00
|
|
|
#if KWIN_QT5_PORTING
|
2007-04-29 17:35:43 +00:00
|
|
|
Workspace::self()->sessionSaveDone();
|
2013-08-13 08:21:28 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
SessionSaveDoneHelper::SessionSaveDoneHelper()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
SmcCallbacks calls;
|
|
|
|
calls.save_yourself.callback = save_yourself;
|
|
|
|
calls.save_yourself.client_data = reinterpret_cast< SmPointer >(this);
|
|
|
|
calls.die.callback = die;
|
|
|
|
calls.die.client_data = reinterpret_cast< SmPointer >(this);
|
|
|
|
calls.save_complete.callback = save_complete;
|
|
|
|
calls.save_complete.client_data = reinterpret_cast< SmPointer >(this);
|
|
|
|
calls.shutdown_cancelled.callback = shutdown_cancelled;
|
|
|
|
calls.shutdown_cancelled.client_data = reinterpret_cast< SmPointer >(this);
|
|
|
|
char* id = NULL;
|
|
|
|
char err[ 11 ];
|
2011-01-30 14:34:42 +00:00
|
|
|
conn = SmcOpenConnection(NULL, 0, 1, 0,
|
|
|
|
SmcSaveYourselfProcMask | SmcDieProcMask | SmcSaveCompleteProcMask
|
|
|
|
| SmcShutdownCancelledProcMask, &calls, NULL, &id, 10, err);
|
|
|
|
if (id != NULL)
|
|
|
|
free(id);
|
|
|
|
if (conn == NULL)
|
2007-04-29 17:35:43 +00:00
|
|
|
return; // no SM
|
|
|
|
// set the required properties, mostly dummy values
|
|
|
|
SmPropValue propvalue[ 5 ];
|
|
|
|
SmProp props[ 5 ];
|
2011-01-30 14:34:42 +00:00
|
|
|
propvalue[ 0 ].length = sizeof(unsigned char);
|
2009-04-28 14:01:39 +00:00
|
|
|
unsigned char value0 = SmRestartNever; // so that this extra SM connection doesn't interfere
|
2007-04-29 17:35:43 +00:00
|
|
|
propvalue[ 0 ].value = &value0;
|
2011-01-30 14:34:42 +00:00
|
|
|
props[ 0 ].name = const_cast< char* >(SmRestartStyleHint);
|
|
|
|
props[ 0 ].type = const_cast< char* >(SmCARD8);
|
2007-04-29 17:35:43 +00:00
|
|
|
props[ 0 ].num_vals = 1;
|
|
|
|
props[ 0 ].vals = &propvalue[ 0 ];
|
2011-01-30 14:34:42 +00:00
|
|
|
struct passwd* entry = getpwuid(geteuid());
|
|
|
|
propvalue[ 1 ].length = entry != NULL ? strlen(entry->pw_name) : 0;
|
|
|
|
propvalue[ 1 ].value = (SmPointer)(entry != NULL ? entry->pw_name : "");
|
|
|
|
props[ 1 ].name = const_cast< char* >(SmUserID);
|
|
|
|
props[ 1 ].type = const_cast< char* >(SmARRAY8);
|
2007-04-29 17:35:43 +00:00
|
|
|
props[ 1 ].num_vals = 1;
|
|
|
|
props[ 1 ].vals = &propvalue[ 1 ];
|
|
|
|
propvalue[ 2 ].length = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
propvalue[ 2 ].value = (SmPointer)("");
|
|
|
|
props[ 2 ].name = const_cast< char* >(SmRestartCommand);
|
|
|
|
props[ 2 ].type = const_cast< char* >(SmLISTofARRAY8);
|
2007-04-29 17:35:43 +00:00
|
|
|
props[ 2 ].num_vals = 1;
|
|
|
|
props[ 2 ].vals = &propvalue[ 2 ];
|
2011-01-30 14:34:42 +00:00
|
|
|
propvalue[ 3 ].length = strlen("kwinsmhelper");
|
2007-10-10 18:23:19 +00:00
|
|
|
propvalue[ 3 ].value = (SmPointer)"kwinsmhelper";
|
2011-01-30 14:34:42 +00:00
|
|
|
props[ 3 ].name = const_cast< char* >(SmProgram);
|
|
|
|
props[ 3 ].type = const_cast< char* >(SmARRAY8);
|
2007-04-29 17:35:43 +00:00
|
|
|
props[ 3 ].num_vals = 1;
|
|
|
|
props[ 3 ].vals = &propvalue[ 3 ];
|
|
|
|
propvalue[ 4 ].length = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
propvalue[ 4 ].value = (SmPointer)("");
|
|
|
|
props[ 4 ].name = const_cast< char* >(SmCloneCommand);
|
|
|
|
props[ 4 ].type = const_cast< char* >(SmLISTofARRAY8);
|
2007-04-29 17:35:43 +00:00
|
|
|
props[ 4 ].num_vals = 1;
|
|
|
|
props[ 4 ].vals = &propvalue[ 4 ];
|
|
|
|
SmProp* p[ 5 ] = { &props[ 0 ], &props[ 1 ], &props[ 2 ], &props[ 3 ], &props[ 4 ] };
|
2011-01-30 14:34:42 +00:00
|
|
|
SmcSetProperties(conn, 5, p);
|
|
|
|
notifier = new QSocketNotifier(IceConnectionNumber(SmcGetIceConnection(conn)),
|
|
|
|
QSocketNotifier::Read, this);
|
|
|
|
connect(notifier, SIGNAL(activated(int)), SLOT(processData()));
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
SessionSaveDoneHelper::~SessionSaveDoneHelper()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
close();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void SessionSaveDoneHelper::close()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (conn != NULL) {
|
2007-04-29 17:35:43 +00:00
|
|
|
delete notifier;
|
2011-01-30 14:34:42 +00:00
|
|
|
SmcCloseConnection(conn, 0, NULL);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
conn = NULL;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void SessionSaveDoneHelper::processData()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (conn != NULL)
|
|
|
|
IceProcessMessages(SmcGetIceConnection(conn), 0, 0);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-12-16 20:14:22 +00:00
|
|
|
void Workspace::sessionSaveDone()
|
|
|
|
{
|
|
|
|
session_saving = false;
|
|
|
|
//remove sessionInteract flag from all clients
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Client * c, clients) {
|
2010-12-16 20:14:22 +00:00
|
|
|
c->setSessionInteract(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "sm.moc"
|