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 ******************************************************************/
28 // needed to avoid clash with INT8 defined in X11/Xmd.h on solaris
29 #define QT_CLEAN_NAMESPACE 1
30 #include <QStringList>
33 #include <kapplication.h>
34 #include <kworkspace.h>
38 #include <Qt3Support/Q3CString>
41 #define SESSION_PREVIOUS_LOGOUT "saved at previous logout"
42 #define SESSION_BY_USER "saved by user"
48 class OrgKdeKLauncherInterface
;
51 enum SMType
{ SM_ERROR
, SM_WMCOMMAND
, SM_WMSAVEYOURSELF
};
55 QStringList wmCommand
;
56 QString wmClientMachine
;
57 QString wmclass1
, wmclass2
;
59 typedef QMap
<WId
,SMData
> WindowMap
;
61 class KSMServer
: public QObject
65 KSMServer( const QString
& windowManager
, bool only_local
);
68 static KSMServer
* self();
70 void* watchConnection( IceConn iceConn
);
71 void removeConnection( KSMConnection
* conn
);
73 KSMClient
* newClient( SmsConn
);
74 void deleteClient( KSMClient
* client
);
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
);
83 void ioError( IceConn iceConn
);
86 void clientSetProgram( KSMClient
* client
);
87 void clientRegistered( const char* previousId
);
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
);
103 void newConnection( int socket
);
104 void processData( int socket
);
106 void protectionTimeout();
108 void timeoutWMQuit();
109 void kcmPhase1Timeout();
110 void kcmPhase2Timeout();
111 void pendingShutdownTimeout();
116 void tryRestoreNext();
117 void startupSuspendTimeout();
119 void logoutSoundFinished();
120 void autoStart0Done();
121 void autoStart1Done();
122 void autoStart2Done();
123 void kcmPhase1Done();
124 void kcmPhase2Done();
127 void handlePendingInteractions();
128 void completeShutdownOrCheckpoint();
130 void performStandardKilling();
131 void completeKilling();
133 void completeKillingWM();
134 void cancelShutdown( KSMClient
* c
);
135 void killingCompleted();
136 void createLogoutEffectWidget();
138 void runUserAutostart();
140 void discardSession();
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();
178 QList
<KSMListener
*> listener
;
179 QList
<KSMClient
*> clients
;
184 LaunchingWM
, AutoStart0
, KcmInitPhase1
, AutoStart1
, Restoring
, FinishingStartup
, // startup
185 Shutdown
, Checkpoint
, Killing
, KillingWM
, WaitingForKNotify
// shutdown
190 int wmPhase1WaitingCount
;
192 QMap
< QString
, int > startupSuspendCount
;
194 KWorkSpace::ShutdownType shutdownType
;
195 KWorkSpace::ShutdownMode shutdownMode
;
199 KSMClient
* clientInteracting
;
201 QString sessionGroup
;
203 QTimer protectionTimer
;
206 QTimer startupSuspendTimeoutTimer
;
209 QTimer pendingShutdown
;
210 QWidget
* logoutEffectWidget
;
211 KWorkSpace::ShutdownConfirm pendingShutdown_confirm
;
212 KWorkSpace::ShutdownType pendingShutdown_sdtype
;
213 KWorkSpace::ShutdownMode pendingShutdown_sdmode
;
216 void upAndRunning( const QString
& msg
);
217 void publishProgress( int progress
, bool max
= false );
219 // sequential startup
222 QString lastIdStarted
;
224 QStringList excludeApps
;
226 WindowMap legacyWindows
;
228 OrgKdeKLauncherInterface
* klauncherSignals
;
229 QDBusInterface
* kcminitSignals
;