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

List:       kde-commits
Subject:    [kde-workspace/farhad_hf/lockscreen] /: Move the "Lock Session"
From:       Alex Merry <kde () randomguy3 ! me ! uk>
Date:       2011-08-11 13:40:12
Message-ID: 20110811134012.26E69A60A4 () git ! kde ! org
[Download RAW message or body]

Git commit 6c3c8fef5552a1511a2857a5d838cc274f8be783 by Alex Merry.
Committed on 09/08/2011 at 14:38.
Pushed by alexmerry into branch 'farhad_hf/lockscreen'.

Move the "Lock Session" shortcut to kwin from krunner

Registration of the "Lock Session" global shortcut is now in KWin (which
manages session locking) rather than KRunner (which may not even be
running on netbooks, for example).

Actually, kwin already registered a "Lock Screen" shortcut, but it was
in conflict with KRunner.  This commit also moves the registration from
kwinbindings.cpp to the SaverEngine class (in a similar style to
tabbox).

M  +0    -1    kwin/workspace.h
M  +38   -0    kwin/screenlocker/screensaver/saverengine.cpp
M  +1    -5    kwin/useractions.cpp
M  +0    -10   krunner/krunnerapp.cpp
M  +0    -1    kwin/kwinbindings.cpp
M  +3    -0    kwin/screenlocker/screensaver/saverengine.h

http://commits.kde.org/kde-workspace/6c3c8fef5552a1511a2857a5d838cc274f8be783

diff --git a/krunner/krunnerapp.cpp b/krunner/krunnerapp.cpp
index 55ac5ca..a4ebb30 100644
--- a/krunner/krunnerapp.cpp
+++ b/krunner/krunnerapp.cpp
@@ -151,16 +151,6 @@ void KRunnerApp::initialize()
         connect(a, SIGNAL(triggered(bool)), SLOT(switchUser()));
     }
 
-    //FIXME: lock/logout should be in the session management runner which also \
                provides similar
-    // functions
-#ifdef Q_WS_X11
-    if (KAuthorized::authorize(QLatin1String("lock_screen"))) {
-        a = m_actionCollection->addAction(QLatin1String("Lock Session"));
-        a->setText(i18n("Lock Session"));
-        connect(a, SIGNAL(triggered(bool)), this, SLOT(lock()));
-    }
-#endif
-
     //Setup the interface after we have set up the actions
     //TODO: if !KAuthorized::authorize("run_comand") (and !"switch_user" i suppose?)
     //      then we probably don't need the interface at all. would be another place
diff --git a/kwin/kwinbindings.cpp b/kwin/kwinbindings.cpp
index 40bba26..0d81857 100644
--- a/kwin/kwinbindings.cpp
+++ b/kwin/kwinbindings.cpp
@@ -158,7 +158,6 @@ for (int i = 0; i < 8; ++i) {
 }
 DEF(I18N_NOOP("Window to Next Screen"),            0, slotWindowToNextScreen());
 DEF(I18N_NOOP("Show Desktop"),                     0, slotToggleShowDesktop());
-DEF(I18N_NOOP("Lock Screen"), Qt::ALT+Qt::CTRL+Qt::Key_L, slotLockScreen());
 
 a = actionCollection->addAction("Group:Desktop Switching");
 a->setText(i18n("Desktop Switching"));
diff --git a/kwin/screenlocker/screensaver/saverengine.cpp \
b/kwin/screenlocker/screensaver/saverengine.cpp index 6c15be6..f6de216 100644
--- a/kwin/screenlocker/screensaver/saverengine.cpp
+++ b/kwin/screenlocker/screensaver/saverengine.cpp
@@ -11,6 +11,10 @@
 #include "screensaveradaptor.h"
 #include "kscreensaveradaptor.h"
 
+#include <kaction.h>
+#include <kactioncollection.h>
+#include <kauthorized.h>
+#include <kglobalaccel.h>
 #include <kstandarddirs.h>
 #include <kapplication.h>
 #include <kservicegroup.h>
@@ -21,6 +25,8 @@
 #include <QFile>
 #include <QX11Info>
 #include <QDBusConnection>
+#include <QDBusInterface>
+#include <QDBusReply>
 #include <QDBusServiceWatcher>
 #include <assert.h>
 #include <stdlib.h>
@@ -30,6 +36,9 @@
 #include "xautolock_c.h"
 extern xautolock_corner_t xautolock_corners[ 4 ];
 
+// needed for calling the kglobalaccel D-Bus interface in initShortcuts
+Q_DECLARE_METATYPE(QList<int>)
+
 //===========================================================================
 //
 // Screen saver engine. Doesn't handle the actual screensaver window,
@@ -108,6 +117,35 @@ SaverEngine::~SaverEngine()
                     mXExposures);
 }
 
+void SaverEngine::initShortcuts(KActionCollection* keys)
+{
+    if (KAuthorized::authorize(QLatin1String("lock_screen"))) {
+        // first make krunner forget its old shortcut
+        // we do this directly using the D-Bus interface, as KGlobalAccel/KAction \
has +        // no nice way of doing this (other than registering and deregistering \
the +        // krunner shortcut every time)
+        QDBusInterface accelIface("org.kde.kglobalaccel", "/kglobalaccel", \
"org.kde.KGlobalAccel"); +        QStringList krunnerShortcutId;
+        krunnerShortcutId << QLatin1String("krunner") << QLatin1String("Lock \
Session") << "" << ""; +        QDBusReply<QList<int> > reply = \
accelIface.call("shortcut", krunnerShortcutId); +        int shortcut = -1;
+        if (reply.isValid() && reply.value().size() == 1) {
+            shortcut = reply.value().at(0);
+            kDebug() << "Existing krunner shortcut for Lock Session found:" << \
KShortcut(shortcut).toString(); +        }
+        accelIface.call(QDBus::NoBlock, "unRegister", krunnerShortcutId);
+
+        KAction *a = keys->addAction(QLatin1String("Lock Session"));
+        a->setText(i18n("Lock Session"));
+        a->setGlobalShortcut(KShortcut(Qt::ALT+Qt::CTRL+Qt::Key_L));
+        if (shortcut >= 0) {
+            // if there was a krunner shortcut, use that
+            a->setGlobalShortcut(KShortcut(shortcut), KAction::ActiveShortcut, \
KAction::NoAutoloading); +        }
+        connect(a, SIGNAL(triggered(bool)), this, SLOT(Lock()));
+    }
+}
+
 //---------------------------------------------------------------------------
 
 void SaverEngine::Lock()
diff --git a/kwin/screenlocker/screensaver/saverengine.h \
b/kwin/screenlocker/screensaver/saverengine.h index 3384d4a..2621025 100644
--- a/kwin/screenlocker/screensaver/saverengine.h
+++ b/kwin/screenlocker/screensaver/saverengine.h
@@ -14,6 +14,7 @@
 #include <QDBusMessage>
 
 class QDBusServiceWatcher;
+class KActionCollection;
 class KProcess;
 
 #include "xautolock.h"
@@ -43,6 +44,8 @@ public:
     SaverEngine();
     ~SaverEngine();
 
+    void initShortcuts(KActionCollection* keys);
+
 public Q_SLOTS:
     /**
      * Lock the screen now even if the screensaver does not lock by default.
diff --git a/kwin/useractions.cpp b/kwin/useractions.cpp
index 44685b9..089d7f4 100644
--- a/kwin/useractions.cpp
+++ b/kwin/useractions.cpp
@@ -564,6 +564,7 @@ void Workspace::initShortcuts()
         tab_box->initShortcuts(actionCollection);
     }
 #endif
+    m_saver.initShortcuts(actionCollection);
     discardPopup(); // so that it's recreated next time
 }
 
@@ -1728,11 +1729,6 @@ bool Workspace::shortcutAvailable(const KShortcut& cut, \
Client* ignore) const  return true;
 }
 
-void Workspace::slotLockScreen()
-{
-    m_saver.Lock();
-}
-
 } // namespace
 
 
diff --git a/kwin/workspace.h b/kwin/workspace.h
index 2b4c8e9..5ee13ac 100644
--- a/kwin/workspace.h
+++ b/kwin/workspace.h
@@ -648,7 +648,6 @@ public slots:
     void slotToggleFloating();
     void slotNextTileLayout();
     void slotPreviousTileLayout();
-    void slotLockScreen();
     // Changes the focused client
     void slotFocusTileLeft();
     void slotFocusTileRight();


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

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