File: server.h

package info (click to toggle)
plasma-workspace 4%3A5.27.5-2%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 102,040 kB
  • sloc: cpp: 121,800; xml: 3,238; python: 645; perl: 586; sh: 254; javascript: 113; ruby: 62; makefile: 15; ansic: 13
file content (227 lines) | stat: -rw-r--r-- 5,485 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
    ksmserver - the KDE session management server

    SPDX-FileCopyrightText: 2000 Matthias Ettrich <ettrich@kde.org>

    SPDX-License-Identifier: MIT
*/

#pragma once

#define INT32 QINT32
#include <X11/ICE/ICElib.h>
#include <X11/Xlib.h>
#include <X11/Xmd.h>
extern "C" {
#include <X11/SM/SM.h>
#include <X11/SM/SMlib.h>
}

#include <fixx11h.h>

// needed to avoid clash with INT8 defined in X11/Xmd.h on solaris
#define QT_CLEAN_NAMESPACE 1
#include <QDBusContext>
#include <QDBusMessage>
#include <QObject>
#include <QStringList>

#include <KConfigGroup>
#include <QMap>
#include <QTime>
#include <QTimer>
#include <kmessagebox.h>
#include <kworkspace.h>

#define SESSION_PREVIOUS_LOGOUT "saved at previous logout"
#define SESSION_BY_USER "saved by user"

class KProcess;

class KSMListener;
class KSMConnection;
class KSMClient;

class OrgKdeKWinSessionInterface;

enum SMType {
    SM_ERROR,
    SM_WMCOMMAND,
    SM_WMSAVEYOURSELF,
};
struct SMData {
    SMType type;
    QStringList wmCommand;
    QString wmClientMachine;
    QString wmclass1, wmclass2;
};
typedef QMap<WId, SMData> WindowMap;

class KSMServer : public QObject, protected QDBusContext
{
    Q_OBJECT
public:
    enum class InitFlag {
        None = 0,
        OnlyLocal = 1 << 0,
        ImmediateLockScreen = 1 << 1,
        NoLockScreen = 1 << 2,
    };

    Q_DECLARE_FLAGS(InitFlags, InitFlag)
    KSMServer(InitFlags flags);
    ~KSMServer() override;

    static KSMServer *self();

    void *watchConnection(IceConn iceConn);
    void removeConnection(KSMConnection *conn);

    KSMClient *newClient(SmsConn);
    void deleteClient(KSMClient *client);

    // callbacks
    void saveYourselfDone(KSMClient *client, bool success);
    void interactRequest(KSMClient *client, int dialogType);
    void interactDone(KSMClient *client, bool cancelShutdown);
    void phase2Request(KSMClient *client);

    // error handling
    void ioError(IceConn iceConn);

    // notification
    void clientRegistered(const char *previousId);

    // public API
    void performLogout();
    void restoreSession();
    void setRestoreSession(const QString &sessionName);
    void startDefaultSession();
    void shutdown(KWorkSpace::ShutdownConfirm confirm, KWorkSpace::ShutdownType sdtype, KWorkSpace::ShutdownMode sdmode);

    void setupShortcuts();

Q_SIGNALS:
    void logoutFinished(bool sessionClosed);

public Q_SLOTS:

    void cleanUp();

private Q_SLOTS:
    void newConnection(int socket);
    void processData(int socket);

    void protectionTimeout();
    void timeoutQuit();

    void defaultLogout();
    void logoutWithoutConfirmation();
    void haltWithoutConfirmation();
    void rebootWithoutConfirmation();

private:
    void handlePendingInteractions();
    void completeShutdownOrCheckpoint();
    void startKilling();
    void startKillingSubSession();
    void performStandardKilling();
    void completeKilling();
    void completeKillingSubSession();
    void signalSubSessionClosed();
    void cancelShutdown(KSMClient *c);
    void killingCompleted();

    void discardSession();
    void storeSession();

    void startProtection();
    void endProtection();

    void startApplication(const QStringList &command, const QString &clientMachine = QString(), const QString &userId = QString());
    void executeCommand(const QStringList &command);

    bool defaultSession() const; // empty session
    void setupXIOErrorHandler();

    void performLegacySessionSave();
    void storeLegacySession(KConfig *config);
    void restoreLegacySession(KConfig *config);
    void restoreLegacySessionInternal(KConfigGroup *config, char sep = ',');
    QStringList windowWmCommand(WId w);
    QString windowWmClientMachine(WId w);
    WId windowWmClientLeader(WId w);
    QByteArray windowSessionId(WId w, WId leader);

    void tryRestoreNext();
    void startupDone();

    void runShutdownScripts();

    // public dcop interface

public Q_SLOTS: // public dcop interface
    void logout(int, int, int);
    bool canShutdown();
    bool isShuttingDown() const;
    QString currentSession();
    void saveCurrentSession();
    void saveCurrentSessionAs(const QString &);
    QStringList sessionList();
    void saveSubSession(const QString &name, QStringList saveAndClose, QStringList saveOnly = QStringList());
    void restoreSubSession(const QString &name);

    void openSwitchUserDialog();
    bool closeSession();

Q_SIGNALS:
    void subSessionClosed();
    void subSessionCloseCanceled();
    void subSessionOpened();
    void sessionRestored();

private:
    QList<KSMListener *> listener;
    QList<KSMClient *> clients;

    enum State {
        Idle,
        Restoring,
        Shutdown,
        Checkpoint,
        Killing,
        WaitingForKNotify, // shutdown
        ClosingSubSession,
        KillingSubSession,
        RestoringSubSession,
    };
    State state;
    bool saveSession;
    int saveType;

    bool clean;
    KSMClient *clientInteracting;
    QString sessionGroup;
    QTimer protectionTimer;
    QTimer restoreTimer;
    QString xonCommand;
    // sequential startup
    int appsToStart;
    int lastAppStarted;
    QString lastIdStarted;

    QStringList excludeApps;

    WindowMap legacyWindows;

    QDBusMessage m_restoreSessionCall;

    // subSession stuff
    QList<KSMClient *> clientsToKill;
    QList<KSMClient *> clientsToSave;

    OrgKdeKWinSessionInterface *m_kwinInterface;

    int sockets[2];
    friend bool readFromPipe(int pipe);
};