not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / ksmserver / server.h
blob450ee199e8925f4549b1610877f2bc7129d08dad
1 /*****************************************************************
2 ksmserver - the KDE session management server
4 Copyright 2000 Matthias Ettrich <ettrich@kde.org>
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 ******************************************************************/
25 #ifndef SERVER_H
26 #define SERVER_H
28 // needed to avoid clash with INT8 defined in X11/Xmd.h on solaris
29 #define QT_CLEAN_NAMESPACE 1
30 #include <QStringList>
31 #include <QObject>
33 #include <kapplication.h>
34 #include <kworkspace.h>
35 #include <QTimer>
36 #include <QTime>
37 #include <QMap>
39 #define INT32 QINT32
40 #include <X11/Xlib.h>
41 #include <X11/Xmd.h>
42 #include <X11/ICE/ICElib.h>
43 extern "C" {
44 #include <X11/ICE/ICEutil.h>
45 #include <X11/ICE/ICEmsg.h>
46 #include <X11/ICE/ICEproto.h>
47 #include <X11/SM/SM.h>
48 #include <X11/SM/SMlib.h>
51 #include <fixx11h.h>
53 #define SESSION_PREVIOUS_LOGOUT "saved at previous logout"
54 #define SESSION_BY_USER "saved by user"
56 class KProcess;
58 class KSMListener;
59 class KSMConnection;
60 class KSMClient;
62 class OrgKdeKLauncherInterface;
63 class QDBusInterface;
65 enum SMType { SM_ERROR, SM_WMCOMMAND, SM_WMSAVEYOURSELF };
66 struct SMData
68 SMType type;
69 QStringList wmCommand;
70 QString wmClientMachine;
71 QString wmclass1, wmclass2;
73 typedef QMap<WId,SMData> WindowMap;
75 class KSMServer : public QObject
77 Q_OBJECT
78 public:
79 KSMServer( const QString& windowManager, bool only_local );
80 ~KSMServer();
82 static KSMServer* self();
84 void* watchConnection( IceConn iceConn );
85 void removeConnection( KSMConnection* conn );
87 KSMClient* newClient( SmsConn );
88 void deleteClient( KSMClient* client );
90 // callbacks
91 void saveYourselfDone( KSMClient* client, bool success );
92 void interactRequest( KSMClient* client, int dialogType );
93 void interactDone( KSMClient* client, bool cancelShutdown );
94 void phase2Request( KSMClient* client );
96 // error handling
97 void ioError( IceConn iceConn );
99 // notification
100 void clientSetProgram( KSMClient* client );
101 void clientRegistered( const char* previousId );
103 // public API
104 void restoreSession( const QString &sessionName );
105 void startDefaultSession();
106 void shutdown( KWorkSpace::ShutdownConfirm confirm,
107 KWorkSpace::ShutdownType sdtype,
108 KWorkSpace::ShutdownMode sdmode );
110 virtual void suspendStartup( const QString &app );
111 virtual void resumeStartup( const QString &app );
113 void launchWM( const QList< QStringList >& wmStartCommands );
115 public Q_SLOTS:
116 void cleanUp();
118 private Q_SLOTS:
119 void newConnection( int socket );
120 void processData( int socket );
122 void protectionTimeout();
123 void timeoutQuit();
124 void timeoutWMQuit();
125 void kcmPhase1Timeout();
126 void kcmPhase2Timeout();
127 void pendingShutdownTimeout();
129 void autoStart0();
130 void autoStart1();
131 void autoStart2();
132 void tryRestoreNext();
133 void startupSuspendTimeout();
134 void wmProcessChange();
135 void logoutSoundFinished();
136 void autoStart0Done();
137 void autoStart1Done();
138 void autoStart2Done();
139 void kcmPhase1Done();
140 void kcmPhase2Done();
142 private:
143 void handlePendingInteractions();
144 void completeShutdownOrCheckpoint();
145 void startKilling();
146 void performStandardKilling();
147 void completeKilling();
148 void killWM();
149 void completeKillingWM();
150 void cancelShutdown( KSMClient* c );
151 void killingCompleted();
152 void createLogoutEffectWidget();
154 void runUserAutostart();
156 void discardSession();
157 void storeSession();
159 void startProtection();
160 void endProtection();
162 KProcess* startApplication( const QStringList& command,
163 const QString& clientMachine = QString(),
164 const QString& userId = QString() );
165 void executeCommand( const QStringList& command );
167 bool isWM( const KSMClient* client ) const;
168 bool isWM( const QString& command ) const;
169 void selectWm( const QString& kdewm );
170 bool defaultSession() const; // empty session
171 void setupXIOErrorHandler();
173 void performLegacySessionSave();
174 void storeLegacySession( KConfig* config );
175 void restoreLegacySession( KConfig* config );
176 void restoreLegacySessionInternal( KConfigGroup* config, char sep = ',' );
177 QStringList windowWmCommand(WId w);
178 QString windowWmClientMachine(WId w);
179 WId windowWmClientLeader(WId w);
180 QByteArray windowSessionId(WId w, WId leader);
182 bool checkStartupSuspend();
183 void finishStartup();
184 void resumeStartupInternal();
186 // public dcop interface
188 public Q_SLOTS: //public dcop interface
189 void logout( int, int, int );
190 bool canShutdown();
191 QString currentSession();
192 void saveCurrentSession();
193 void saveCurrentSessionAs( const QString & );
194 QStringList sessionList();
195 void wmChanged();
196 private:
197 QList<KSMListener*> listener;
198 QList<KSMClient*> clients;
200 enum State
202 Idle,
203 LaunchingWM, AutoStart0, KcmInitPhase1, AutoStart1, Restoring, FinishingStartup, // startup
204 Shutdown, Checkpoint, Killing, KillingWM, WaitingForKNotify // shutdown
206 State state;
207 bool dialogActive;
208 bool saveSession;
209 int wmPhase1WaitingCount;
210 int saveType;
211 QMap< QString, int > startupSuspendCount;
213 KWorkSpace::ShutdownType shutdownType;
214 KWorkSpace::ShutdownMode shutdownMode;
215 QString bootOption;
217 bool clean;
218 KSMClient* clientInteracting;
219 QString wm;
220 QStringList wmCommands;
221 KProcess* wmProcess;
222 QString sessionGroup;
223 QString sessionName;
224 QTimer protectionTimer;
225 QTimer restoreTimer;
226 QString xonCommand;
227 QTimer startupSuspendTimeoutTimer;
228 bool waitAutoStart2;
229 bool waitKcmInit2;
230 QTimer pendingShutdown;
231 QWidget* logoutEffectWidget;
232 KWorkSpace::ShutdownConfirm pendingShutdown_confirm;
233 KWorkSpace::ShutdownType pendingShutdown_sdtype;
234 KWorkSpace::ShutdownMode pendingShutdown_sdmode;
236 // ksplash interface
237 void upAndRunning( const QString& msg );
238 void publishProgress( int progress, bool max = false );
240 // sequential startup
241 int appsToStart;
242 int lastAppStarted;
243 QString lastIdStarted;
245 QStringList excludeApps;
247 WindowMap legacyWindows;
249 OrgKdeKLauncherInterface* klauncherSignals;
250 QDBusInterface* kcminitSignals;
253 #endif