Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / ksmserver / server.h
blobce086e872ad8ba1728c661a95d2190155d9ecd26
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>
38 #include <Qt3Support/Q3CString>
39 #include "server2.h"
41 #define SESSION_PREVIOUS_LOGOUT "saved at previous logout"
42 #define SESSION_BY_USER "saved by user"
44 class KSMListener;
45 class KSMConnection;
46 class KSMClient;
48 class OrgKdeKLauncherInterface;
49 class QDBusInterface;
51 enum SMType { SM_ERROR, SM_WMCOMMAND, SM_WMSAVEYOURSELF };
52 struct SMData
54 SMType type;
55 QStringList wmCommand;
56 QString wmClientMachine;
57 QString wmclass1, wmclass2;
59 typedef QMap<WId,SMData> WindowMap;
61 class KSMServer : public QObject
63 Q_OBJECT
64 public:
65 KSMServer( const QString& windowManager, bool only_local );
66 ~KSMServer();
68 static KSMServer* self();
70 void* watchConnection( IceConn iceConn );
71 void removeConnection( KSMConnection* conn );
73 KSMClient* newClient( SmsConn );
74 void deleteClient( KSMClient* client );
76 // callbacks
77 void saveYourselfDone( KSMClient* client, bool success );
78 void interactRequest( KSMClient* client, int dialogType );
79 void interactDone( KSMClient* client, bool cancelShutdown );
80 void phase2Request( KSMClient* client );
82 // error handling
83 void ioError( IceConn iceConn );
85 // notification
86 void clientSetProgram( KSMClient* client );
87 void clientRegistered( const char* previousId );
89 // public API
90 void restoreSession( const QString &sessionName );
91 void startDefaultSession();
92 void shutdown( KWorkSpace::ShutdownConfirm confirm,
93 KWorkSpace::ShutdownType sdtype,
94 KWorkSpace::ShutdownMode sdmode );
96 virtual void suspendStartup( const QString &app );
97 virtual void resumeStartup( const QString &app );
99 public Q_SLOTS:
100 void cleanUp();
102 private Q_SLOTS:
103 void newConnection( int socket );
104 void processData( int socket );
106 void protectionTimeout();
107 void timeoutQuit();
108 void timeoutWMQuit();
109 void kcmPhase1Timeout();
110 void kcmPhase2Timeout();
111 void pendingShutdownTimeout();
113 void autoStart0();
114 void autoStart1();
115 void autoStart2();
116 void tryRestoreNext();
117 void startupSuspendTimeout();
119 void logoutSoundFinished();
120 void autoStart0Done();
121 void autoStart1Done();
122 void autoStart2Done();
123 void kcmPhase1Done();
124 void kcmPhase2Done();
126 private:
127 void handlePendingInteractions();
128 void completeShutdownOrCheckpoint();
129 void startKilling();
130 void performStandardKilling();
131 void completeKilling();
132 void killWM();
133 void completeKillingWM();
134 void cancelShutdown( KSMClient* c );
135 void killingCompleted();
136 void createLogoutEffectWidget();
138 void runUserAutostart();
140 void discardSession();
141 void storeSession();
143 void startProtection();
144 void endProtection();
146 void startApplication( QStringList& command,
147 const QString& clientMachine = QString(),
148 const QString& userId = QString() );
149 void executeCommand( const QStringList& command );
151 bool isWM( const KSMClient* client ) const;
152 bool isWM( const QString& command ) const;
153 bool defaultSession() const; // empty session
154 void setupXIOErrorHandler();
156 void performLegacySessionSave();
157 void storeLegacySession( KConfig* config );
158 void restoreLegacySession( KConfig* config );
159 void restoreLegacySessionInternal( KConfigGroup* config, char sep = ',' );
160 QStringList windowWmCommand(WId w);
161 QString windowWmClientMachine(WId w);
162 WId windowWmClientLeader(WId w);
163 QByteArray windowSessionId(WId w, WId leader);
165 bool checkStartupSuspend();
166 void finishStartup();
167 void resumeStartupInternal();
169 // public dcop interface
171 public Q_SLOTS: //public dcop interface
172 void logout( int, int, int );
173 QString currentSession();
174 void saveCurrentSession();
175 void saveCurrentSessionAs( const QString & );
176 QStringList sessionList();
177 private:
178 QList<KSMListener*> listener;
179 QList<KSMClient*> clients;
181 enum State
183 Idle,
184 LaunchingWM, AutoStart0, KcmInitPhase1, AutoStart1, Restoring, FinishingStartup, // startup
185 Shutdown, Checkpoint, Killing, KillingWM, WaitingForKNotify // shutdown
187 State state;
188 bool dialogActive;
189 bool saveSession;
190 int wmPhase1WaitingCount;
191 int saveType;
192 QMap< QString, int > startupSuspendCount;
194 KWorkSpace::ShutdownType shutdownType;
195 KWorkSpace::ShutdownMode shutdownMode;
196 QString bootOption;
198 bool clean;
199 KSMClient* clientInteracting;
200 QString wm;
201 QString sessionGroup;
202 QString sessionName;
203 QTimer protectionTimer;
204 QTimer restoreTimer;
205 QString xonCommand;
206 QTimer startupSuspendTimeoutTimer;
207 bool waitAutoStart2;
208 bool waitKcmInit2;
209 QTimer pendingShutdown;
210 QWidget* logoutEffectWidget;
211 KWorkSpace::ShutdownConfirm pendingShutdown_confirm;
212 KWorkSpace::ShutdownType pendingShutdown_sdtype;
213 KWorkSpace::ShutdownMode pendingShutdown_sdmode;
215 // ksplash interface
216 void upAndRunning( const QString& msg );
217 void publishProgress( int progress, bool max = false );
219 // sequential startup
220 int appsToStart;
221 int lastAppStarted;
222 QString lastIdStarted;
224 QStringList excludeApps;
226 WindowMap legacyWindows;
228 OrgKdeKLauncherInterface* klauncherSignals;
229 QDBusInterface* kcminitSignals;
232 #endif