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>
42 #include <X11/ICE/ICElib.h>
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>
53 #define SESSION_PREVIOUS_LOGOUT "saved at previous logout"
54 #define SESSION_BY_USER "saved by user"
62 class OrgKdeKLauncherInterface
;
65 enum SMType
{ SM_ERROR
, SM_WMCOMMAND
, SM_WMSAVEYOURSELF
};
69 QStringList wmCommand
;
70 QString wmClientMachine
;
71 QString wmclass1
, wmclass2
;
73 typedef QMap
<WId
,SMData
> WindowMap
;
75 class KSMServer
: public QObject
79 KSMServer( const QString
& windowManager
, bool only_local
);
82 static KSMServer
* self();
84 void* watchConnection( IceConn iceConn
);
85 void removeConnection( KSMConnection
* conn
);
87 KSMClient
* newClient( SmsConn
);
88 void deleteClient( KSMClient
* client
);
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
);
97 void ioError( IceConn iceConn
);
100 void clientSetProgram( KSMClient
* client
);
101 void clientRegistered( const char* previousId
);
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
);
119 void newConnection( int socket
);
120 void processData( int socket
);
122 void protectionTimeout();
124 void timeoutWMQuit();
125 void kcmPhase1Timeout();
126 void kcmPhase2Timeout();
127 void pendingShutdownTimeout();
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();
143 void handlePendingInteractions();
144 void completeShutdownOrCheckpoint();
146 void performStandardKilling();
147 void completeKilling();
149 void completeKillingWM();
150 void cancelShutdown( KSMClient
* c
);
151 void killingCompleted();
152 void createLogoutEffectWidget();
154 void runUserAutostart();
156 void discardSession();
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 );
191 QString
currentSession();
192 void saveCurrentSession();
193 void saveCurrentSessionAs( const QString
& );
194 QStringList
sessionList();
197 QList
<KSMListener
*> listener
;
198 QList
<KSMClient
*> clients
;
203 LaunchingWM
, AutoStart0
, KcmInitPhase1
, AutoStart1
, Restoring
, FinishingStartup
, // startup
204 Shutdown
, Checkpoint
, Killing
, KillingWM
, WaitingForKNotify
// shutdown
209 int wmPhase1WaitingCount
;
211 QMap
< QString
, int > startupSuspendCount
;
213 KWorkSpace::ShutdownType shutdownType
;
214 KWorkSpace::ShutdownMode shutdownMode
;
218 KSMClient
* clientInteracting
;
220 QStringList wmCommands
;
222 QString sessionGroup
;
224 QTimer protectionTimer
;
227 QTimer startupSuspendTimeoutTimer
;
230 QTimer pendingShutdown
;
231 QWidget
* logoutEffectWidget
;
232 KWorkSpace::ShutdownConfirm pendingShutdown_confirm
;
233 KWorkSpace::ShutdownType pendingShutdown_sdtype
;
234 KWorkSpace::ShutdownMode pendingShutdown_sdmode
;
237 void upAndRunning( const QString
& msg
);
238 void publishProgress( int progress
, bool max
= false );
240 // sequential startup
243 QString lastIdStarted
;
245 QStringList excludeApps
;
247 WindowMap legacyWindows
;
249 OrgKdeKLauncherInterface
* klauncherSignals
;
250 QDBusInterface
* kcminitSignals
;