Warning, file /plasma/plasma-workspace/ksmserver/server.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 ksmserver - the KDE session management server 0003 0004 SPDX-FileCopyrightText: 2000 Matthias Ettrich <ettrich@kde.org> 0005 0006 SPDX-License-Identifier: MIT 0007 */ 0008 0009 #pragma once 0010 0011 #define INT32 QINT32 0012 #include <X11/ICE/ICElib.h> 0013 #include <X11/Xlib.h> 0014 #include <X11/Xmd.h> 0015 extern "C" { 0016 #include <X11/SM/SM.h> 0017 #include <X11/SM/SMlib.h> 0018 } 0019 0020 #include <fixx11h.h> 0021 0022 // needed to avoid clash with INT8 defined in X11/Xmd.h on solaris 0023 #define QT_CLEAN_NAMESPACE 1 0024 #include <QDBusContext> 0025 #include <QDBusMessage> 0026 #include <QObject> 0027 #include <QStringList> 0028 0029 #include <KConfigGroup> 0030 #include <QMap> 0031 #include <QTime> 0032 #include <QTimer> 0033 #include <kmessagebox.h> 0034 #include <kworkspace.h> 0035 0036 #define SESSION_PREVIOUS_LOGOUT "saved at previous logout" 0037 #define SESSION_BY_USER "saved by user" 0038 0039 class KProcess; 0040 0041 class KSMListener; 0042 class KSMConnection; 0043 class KSMClient; 0044 0045 class OrgKdeKWinSessionInterface; 0046 0047 enum SMType { 0048 SM_ERROR, 0049 SM_WMCOMMAND, 0050 SM_WMSAVEYOURSELF, 0051 }; 0052 struct SMData { 0053 SMType type; 0054 QStringList wmCommand; 0055 QString wmClientMachine; 0056 QString wmclass1, wmclass2; 0057 }; 0058 typedef QMap<WId, SMData> WindowMap; 0059 0060 class KSMServer : public QObject, protected QDBusContext 0061 { 0062 Q_OBJECT 0063 public: 0064 enum class InitFlag { 0065 None = 0, 0066 OnlyLocal = 1 << 0, 0067 ImmediateLockScreen = 1 << 1, 0068 NoLockScreen = 1 << 2, 0069 }; 0070 0071 Q_DECLARE_FLAGS(InitFlags, InitFlag) 0072 KSMServer(InitFlags flags); 0073 ~KSMServer() override; 0074 0075 static KSMServer *self(); 0076 0077 void *watchConnection(IceConn iceConn); 0078 void removeConnection(KSMConnection *conn); 0079 0080 KSMClient *newClient(SmsConn); 0081 void deleteClient(KSMClient *client); 0082 0083 // callbacks 0084 void saveYourselfDone(KSMClient *client, bool success); 0085 void interactRequest(KSMClient *client, int dialogType); 0086 void interactDone(KSMClient *client, bool cancelShutdown); 0087 void phase2Request(KSMClient *client); 0088 0089 // error handling 0090 void ioError(IceConn iceConn); 0091 0092 // notification 0093 void clientRegistered(const char *previousId); 0094 0095 // public API 0096 void performLogout(); 0097 void restoreSession(); 0098 void setRestoreSession(const QString &sessionName); 0099 void startDefaultSession(); 0100 void shutdown(KWorkSpace::ShutdownConfirm confirm, KWorkSpace::ShutdownType sdtype, KWorkSpace::ShutdownMode sdmode); 0101 0102 void setupShortcuts(); 0103 0104 Q_SIGNALS: 0105 void logoutFinished(bool sessionClosed); 0106 0107 public Q_SLOTS: 0108 0109 void cleanUp(); 0110 0111 private Q_SLOTS: 0112 void newConnection(int socket); 0113 void processData(int socket); 0114 0115 void protectionTimeout(); 0116 void timeoutQuit(); 0117 0118 void defaultLogout(); 0119 void logoutWithoutConfirmation(); 0120 void haltWithoutConfirmation(); 0121 void rebootWithoutConfirmation(); 0122 0123 private: 0124 void handlePendingInteractions(); 0125 void completeShutdownOrCheckpoint(); 0126 void startKilling(); 0127 void startKillingSubSession(); 0128 void performStandardKilling(); 0129 void completeKilling(); 0130 void completeKillingSubSession(); 0131 void signalSubSessionClosed(); 0132 void cancelShutdown(KSMClient *c); 0133 void killingCompleted(); 0134 0135 void discardSession(); 0136 void storeSession(); 0137 0138 void startProtection(); 0139 void endProtection(); 0140 0141 void startApplication(const QStringList &command, const QString &clientMachine = QString(), const QString &userId = QString()); 0142 void executeCommand(const QStringList &command); 0143 0144 bool defaultSession() const; // empty session 0145 void setupXIOErrorHandler(); 0146 0147 void performLegacySessionSave(); 0148 void storeLegacySession(KConfig *config); 0149 void restoreLegacySession(KConfig *config); 0150 void restoreLegacySessionInternal(KConfigGroup *config, char sep = ','); 0151 QStringList windowWmCommand(WId w); 0152 QString windowWmClientMachine(WId w); 0153 WId windowWmClientLeader(WId w); 0154 QByteArray windowSessionId(WId w, WId leader); 0155 0156 void tryRestoreNext(); 0157 void startupDone(); 0158 0159 void runShutdownScripts(); 0160 0161 // public dcop interface 0162 0163 public Q_SLOTS: // public dcop interface 0164 void logout(int, int, int); 0165 bool canShutdown(); 0166 bool isShuttingDown() const; 0167 QString currentSession(); 0168 void saveCurrentSession(); 0169 void saveCurrentSessionAs(const QString &); 0170 QStringList sessionList(); 0171 void saveSubSession(const QString &name, QStringList saveAndClose, QStringList saveOnly = QStringList()); 0172 void restoreSubSession(const QString &name); 0173 0174 void openSwitchUserDialog(); 0175 bool closeSession(); 0176 0177 Q_SIGNALS: 0178 void subSessionClosed(); 0179 void subSessionCloseCanceled(); 0180 void subSessionOpened(); 0181 void sessionRestored(); 0182 0183 private: 0184 QList<KSMListener *> listener; 0185 QList<KSMClient *> clients; 0186 0187 enum State { 0188 Idle, 0189 Restoring, 0190 Shutdown, 0191 Checkpoint, 0192 Killing, 0193 WaitingForKNotify, // shutdown 0194 ClosingSubSession, 0195 KillingSubSession, 0196 RestoringSubSession, 0197 }; 0198 State state; 0199 bool saveSession; 0200 int saveType; 0201 0202 bool clean; 0203 KSMClient *clientInteracting; 0204 QString sessionGroup; 0205 QTimer protectionTimer; 0206 QTimer restoreTimer; 0207 QString xonCommand; 0208 // sequential startup 0209 int appsToStart; 0210 int lastAppStarted; 0211 QString lastIdStarted; 0212 0213 QStringList excludeApps; 0214 0215 WindowMap legacyWindows; 0216 0217 QDBusMessage m_restoreSessionCall; 0218 0219 // subSession stuff 0220 QList<KSMClient *> clientsToKill; 0221 QList<KSMClient *> clientsToSave; 0222 0223 OrgKdeKWinSessionInterface *m_kwinInterface; 0224 0225 int sockets[2]; 0226 friend bool readFromPipe(int pipe); 0227 };