[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    the real excessive logout time fix
From:       Bradley T Hughes <bhughes () trolltech ! com>
Date:       2001-01-26 14:22:12
[Download RAW message or body]

Matthias and I sat up last night and made this work... 2 patches, one against 
kdelibs and the other against kdebase (kapp.cpp in kdecore and ksmserver)

If there are no objections I'll commit tomorrow evening (Saturday)

-- 
--
Bradley T. Hughes <bhughes@trolltech.com>
Trolltech AS - Waldemar Thranes gt. 98B N-0175 Oslo, Norway
Office: +47 21604892
Mobile: +47 92019781


["kdelibs-diff" (text/x-c++)]

Index: kdecore/kapp.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kapp.cpp,v
retrieving revision 1.416
diff -u -b -r1.416 kapp.cpp
--- kdecore/kapp.cpp	2001/01/24 18:08:49	1.416
+++ kdecore/kapp.cpp	2001/01/26 13:54:52
@@ -538,6 +538,7 @@
 }
 
 static SmcConn mySmcConnection = 0;
+static SmcConn tmpSmcConnection = 0;
 static QTime* smModificationTime = 0;
 
 KApplication::KApplication( int& argc, char** argv, const QCString& rAppName,
@@ -791,7 +792,11 @@
 {
     if ( mySmcConnection ) {
         // we already have a connection to the session manager, use it.
-        SmcRequestSaveYourself( mySmcConnection, SmSaveBoth, True, SmInteractStyleAny, False, True );
+        SmcRequestSaveYourself( mySmcConnection, SmSaveBoth, True,
+				SmInteractStyleAny, False, True );
+
+	// flush the request
+	IceFlush(SmcGetIceConnection(mySmcConnection));
         return TRUE;
     }
 
@@ -802,22 +807,27 @@
     if (smEnv.isEmpty())
         return FALSE;
 
+    if (! tmpSmcConnection) {
     char cerror[256];
     char* myId = 0;
     char* prevId = 0;
     SmcCallbacks cb;
-    SmcConn smcConnection = SmcOpenConnection( 0, 0, 1, 0,
+	tmpSmcConnection = SmcOpenConnection( 0, 0, 1, 0,
                                                0, &cb,
                                                prevId,
                                                &myId,
                                                255,
                                                cerror );
     ::free( myId ); // it was allocated by C
-    if (!smcConnection )
+	if (!tmpSmcConnection )
         return FALSE;
+    }
 
-    SmcRequestSaveYourself( smcConnection, SmSaveBoth, True, SmInteractStyleAny, False, True );
-    SmcCloseConnection( smcConnection, 0, 0 );
+    SmcRequestSaveYourself( tmpSmcConnection, SmSaveBoth, True,
+			    SmInteractStyleAny, False, True );
+
+    // flush the request
+    IceFlush(SmcGetIceConnection(tmpSmcConnection));
     return TRUE;
 }
 
@@ -1155,6 +1189,12 @@
   mySmcConnection = 0;
   delete smModificationTime;
   smModificationTime = 0;
+
+  // close the temporary smc connection
+  if (tmpSmcConnection) {
+      SmcCloseConnection( tmpSmcConnection, 0, 0 );
+      tmpSmcConnection = 0;
+  }
 }
 
 

["kdebase-diff" (text/x-c++)]

? ksmserver/server.cpp.flc
Index: ksmserver/server.cpp
===================================================================
RCS file: /home/kde/kdebase/ksmserver/server.cpp,v
retrieving revision 1.53
diff -u -b -r1.53 server.cpp
--- ksmserver/server.cpp	2001/01/26 10:42:20	1.53
+++ ksmserver/server.cpp	2001/01/26 14:18:59
@@ -126,6 +126,7 @@
     saveYourselfDone = FALSE;
     pendingInteraction = FALSE;
     waitForPhase2 = FALSE;
+    wasPhase2 = FALSE;
 }
 
 /*
@@ -1045,6 +1046,7 @@
 void KSMServer::phase2Request( KSMClient* client )
 {
     client->waitForPhase2 = TRUE;
+    client->wasPhase2 = TRUE;
     completeShutdown();
 }
 
@@ -1136,30 +1138,39 @@
     // kill all clients
     state = Killing;
     for ( KSMClient* c = clients.first(); c; c = clients.next() ) {
-	// do not kill the wm yet, we do that in completeKilling()
-	// below.
-	if ( !wm.isEmpty() && c->program() == wm )
+        kdDebug() << "completeShutdown: client " << c->program() << endl;
+	if (c->wasPhase2)
 	    continue;
 	SmsDie( c->connection() );
     }
-    if ( clients.isEmpty() )
+    kdDebug() << " We killed all clients. We have now clients.count()=" <<
+	clients.count() << endl;
+
 	completeKilling();
-    else
 	QTimer::singleShot( 4000, this, SLOT( timeoutQuit() ) );
 }
 
 void KSMServer::completeKilling()
 {
-    if ( state != Killing )
-	return;
-    if ( !wm.isEmpty() && clients.count() == 1 && clients.first()->program() == wm ) {
-	// the wm was not killed yet, do it
-	SmsDie( clients.first()->connection() );
+    kdDebug(0) << "KSMServer::completeKilling clients.count()=" <<
+	clients.count() << endl;
+    if ( state != Killing ) {
+	kdWarning() << "Not Killing !!! state=" << state << endl;
 	return;
     }
 
-    if ( clients.isEmpty() )
+    if ( clients.isEmpty() ) {
+	kdDebug(0) << "Calling qApp->quit()" << endl;
 	qApp->quit();
+    } else {
+	for (KSMClient *c = clients.first(); c; c = clients.next()) {
+	    if (! c->wasPhase2)
+		return;
+	}
+	// the wm was not killed yet, do it
+	for (KSMClient *c = clients.first(); c; c = clients.next())
+	    SmsDie( c->connection() );
+    }
 }
 
 void KSMServer::timeoutQuit()
@@ -1207,13 +1218,15 @@
  */
 void KSMServer::restoreSession()
 {
+    kdDebug(0) << "KSMServer::restoreSession" << endl;
     upAndRunning( "restore session");
     KConfig* config = KGlobal::config();
     config->setGroup("Session" );
     int count =  config->readNumEntry( "count" );
+    bool wmFound = false;
     progress = count;
 
-    QStringList wmCommand = wm;
+    QStringList wmCommand;
     if ( !wm.isEmpty() ) {
 	// when we have a window manager, we start it first and give
 	// it some time before launching other processes. Results in a
@@ -1222,21 +1235,26 @@
 	for ( int i = 1; i <= count; i++ ) {
 	    QString n = QString::number(i);
 	    if ( wm == config->readEntry( QString("program")+n ) ) {
+		wmFound = true;
 		progress--;
 		wmCommand = config->readListEntry( QString("restartCommand")+n );
-	break;
+	        startApplication( wmCommand );
 	    }
 	}
     }
 
     publishProgress( progress, true );
 
-    if ( wmCommand.isEmpty() ) {
-	restoreSessionInternal();
-    } else {
-	startApplication( wmCommand );
+    if (wmFound) {
 	QTimer::singleShot( 2000, this, SLOT( restoreSessionInternal() ) );
-    }
+    } else if (! wm.isEmpty()) {
+	// window manager not found, but we have a default window manager...
+	// run it and restore the session
+	wmCommand = wm;
+	startApplication(wmCommand);
+        restoreSessionInternal();
+    } else
+	restoreSessionInternal();
 }
 
 /*!
Index: ksmserver/server.h
===================================================================
RCS file: /home/kde/kdebase/ksmserver/server.h,v
retrieving revision 1.15
diff -u -b -r1.15 server.h
--- ksmserver/server.h	2001/01/07 13:54:00	1.15
+++ ksmserver/server.h	2001/01/26 14:18:59
@@ -50,6 +50,7 @@
     uint saveYourselfDone : 1;
     uint pendingInteraction : 1;
     uint waitForPhase2 : 1;
+    uint wasPhase2 : 1;
 
     QList<SmProp> properties;
     SmProp* property( const char* name ) const;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic