This patch set should prevent for following bug tracked on:
https://bugs.kde.org/show_bug.cgi?id=282639

From 509d2f1ece2fdee371032e155769f744dc18d525 Mon Sep 17 00:00:00 2001
From: Aaron Seigo <[email protected]>
Date: Fri, 30 Sep 2011 14:31:55 +0200
Subject: [PATCH 1/3] attempt to make requestShutdown more friendly: non-blocking, not require a sync of the xserver

---
libs/kworkspace/kworkspace.cpp |   14 +++++---------
libs/kworkspace/kworkspace.h   |    4 +---
2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/libs/kworkspace/kworkspace.cpp b/libs/kworkspace/kworkspace.cpp
index 0b4146e..96a435b 100644
--- a/libs/kworkspace/kworkspace.cpp
+++ b/libs/kworkspace/kworkspace.cpp
@@ -174,29 +174,25 @@ static void cleanup_sm()
}
#endif

-bool requestShutDown(
-    ShutdownConfirm confirm, ShutdownType sdtype, ShutdownMode sdmode )
+void requestShutDown(ShutdownConfirm confirm, ShutdownType sdtype, ShutdownMode sdmode)
{
#ifdef Q_WS_X11
-    QApplication::syncX();
-    kapp->updateRemoteUserTimestamp( "org.kde.ksmserver" );
    /*  use ksmserver's dcop interface if necessary  */
    if ( confirm == ShutdownConfirmYes ||
         sdtype != ShutdownTypeDefault ||
         sdmode != ShutdownModeDefault )
    {
        org::kde::KSMServerInterface ksmserver("org.kde.ksmserver", "/KSMServer", QDBusConnection::sessionBus());
-        QDBusReply<void> reply = ksmserver.logout((int)confirm,  (int)sdtype,  (int)sdmode);
-        return (reply.isValid());
+        ksmserver.logout((int)confirm,  (int)sdtype,  (int)sdmode);
+        return;
    }
+
    if( helper == NULL )
    {
        helper = new KRequestShutdownHelper();
        qAddPostRoutine(cleanup_sm);
    }
-    return helper->requestShutdown( confirm );
-#else
-    return false;
+    helper->requestShutdown( confirm );
#endif
}

diff --git a/libs/kworkspace/kworkspace.h b/libs/kworkspace/kworkspace.h
index 2516c3a..8868bf6 100644
--- a/libs/kworkspace/kworkspace.h
+++ b/libs/kworkspace/kworkspace.h
@@ -110,10 +110,8 @@ namespace KWorkSpace
   * ShutdownConfirm
   * @param sdtype The action to take after logging out. ShutdownType
   * @param sdmode If/When the action should be taken. ShutdownMode
-   * @return true on success, false if the session manager could not be
-   * contacted.
   */
-  KDE_EXPORT bool requestShutDown( ShutdownConfirm confirm = ShutdownConfirmDefault,
+  KDE_EXPORT void requestShutDown( ShutdownConfirm confirm = ShutdownConfirmDefault,
                                   ShutdownType    sdtype  = ShutdownTypeDefault,
                                   ShutdownMode    sdmode  = ShutdownModeDefault );

--
1.7.4.1

From a40c435195b07268a409ae83e9fbc1086be7c253 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maurice=20de=20la=20Fert=C3=A9?= <[email protected]>
Date: Mon, 3 Oct 2011 23:02:36 +0200
Subject: [PATCH 2/3] update the user timestamp before showing the dialog

should prevent focus stealing preventing related issues where the dialog
goes behind other windows; this functionality was moved from libkworkspace

Conflicts:

       ksmserver/shutdown.cpp
---
ksmserver/shutdown.cpp |   22 +++++++++++-----------
1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/ksmserver/shutdown.cpp b/ksmserver/shutdown.cpp
index a083545..d86ccaa 100644
--- a/ksmserver/shutdown.cpp
+++ b/ksmserver/shutdown.cpp
@@ -58,15 +58,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <QTimer>
#include <QtDBus/QtDBus>

-#include <klocale.h>
-#include <kglobal.h>
-#include <kconfig.h>
-#include <kstandarddirs.h>
-#include <kapplication.h>
-#include <ktemporaryfile.h>
-#include <kconfiggroup.h>
-#include <knotification.h>
-#include <kdisplaymanager.h>
+#include <KApplication>
+#include <KConfig>
+#include <KConfigGroup>
+#include <KGlobal>
+#include <KLocale>
+#include <KNotification>
+#include <KStandardDirs>
+#include <KTemporaryFile>
+#include <kworkspace/kdisplaymanager.h>
#include "server.h"
#include "global.h"
#include "client.h"
@@ -152,9 +152,9 @@ void KSMServer::shutdown( KWorkSpace::ShutdownConfirm confirm,
    dialogActive = true;
    QString bopt;
    if ( !logoutConfirmed ) {
+        KApplication::kApplication()->updateUserTimestamp();
        KSMShutdownFeedback::start(); // make the screen gray
-        logoutConfirmed =
-            KSMShutdownDlg::confirmShutdown( maysd, choose, sdtype, bopt );
+        logoutConfirmed = KSMShutdownDlg::confirmShutdown( maysd, choose, sdtype, bopt );
        // ###### We can't make the screen remain gray while talking to the apps,
        // because this prevents interaction ("do you want to save", etc.)
        // TODO: turn the feedback widget into a list of apps to be closed,
--
1.7.4.1

From 61534bb9236c78632637f35429f0d66128089119 Mon Sep 17 00:00:00 2001
From: Aaron Seigo <[email protected]>
Date: Mon, 26 Sep 2011 14:57:53 +0200
Subject: [PATCH 3/3] simplify usage of requestShutDown

---
.../desktop/applets/kickoff/core/itemhandlers.cpp  |    3 ---
plasma/generic/applets/lock_logout/lockout.cpp     |    6 +-----
.../containmentactions/contextmenu/menu.cpp        |    7 ++-----
3 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/plasma/desktop/applets/kickoff/core/itemhandlers.cpp b/plasma/desktop/applets/kickoff/core/itemhandlers.cpp
index 7364fc8..4e83c37 100644
--- a/plasma/desktop/applets/kickoff/core/itemhandlers.cpp
+++ b/plasma/desktop/applets/kickoff/core/itemhandlers.cpp
@@ -160,10 +160,7 @@ void LeaveItemHandler::logout()
        type = KWorkSpace::ShutdownTypeHalt;
    }

-//FIXME: the proper fix is to implement the KWorkSpace methods for Windows
-#ifndef Q_WS_WIN
    KWorkSpace::requestShutDown(confirm, type);
-#endif
}

void LeaveItemHandler::lock()
diff --git a/plasma/generic/applets/lock_logout/lockout.cpp b/plasma/generic/applets/lock_logout/lockout.cpp
index ecd8736..9a1a3bb 100644
--- a/plasma/generic/applets/lock_logout/lockout.cpp
+++ b/plasma/generic/applets/lock_logout/lockout.cpp
@@ -274,11 +274,7 @@ void LockOut::clickLogout()
    }

    kDebug()<<"LockOut:: logout clicked ";
-#ifndef Q_OS_WIN
-    KWorkSpace::requestShutDown( KWorkSpace::ShutdownConfirmDefault,
-                                 KWorkSpace::ShutdownTypeDefault,
-                                 KWorkSpace::ShutdownModeDefault);
-#endif
+    KWorkSpace::requestShutDown();
}

void LockOut::clickSwitchUser()
diff --git a/plasma/generic/containmentactions/contextmenu/menu.cpp b/plasma/generic/containmentactions/contextmenu/menu.cpp
index a328c8d..33f07e7 100644
--- a/plasma/generic/containmentactions/contextmenu/menu.cpp
+++ b/plasma/generic/containmentactions/contextmenu/menu.cpp
@@ -242,11 +242,8 @@ void ContextMenu::logout()
    if (!KAuthorized::authorizeKAction("logout")) {
        return;
    }
-#ifndef Q_WS_WIN
-    KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmDefault,
-                                KWorkSpace::ShutdownTypeDefault,
-                                KWorkSpace::ShutdownModeDefault);
-#endif
+
+    KWorkSpace::requestShutDown();
}

QWidget* ContextMenu::createConfigurationInterface(QWidget* parent)
--
1.7.4.1