[gnome-shell] windowManager: Add a generic mechanism for filtering keybindings



commit 0d9f70492e6cd0b5505d8221feab00a0423ff1d0
Author: Florian MÃllner <fmuellner gnome org>
Date:   Sat Aug 11 02:53:38 2012 +0200

    windowManager: Add a generic mechanism for filtering keybindings
    
    Currently we hardcode the set of keybindings that are available in the
    overview; add a generic mechanism to specify in which KeybindingModes
    a keybinding should be available.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688202

 js/ui/windowManager.js |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index eb7570f..ddebde5 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -83,6 +83,8 @@ const WindowManager = new Lang.Class({
 
         this._animationBlockCount = 0;
 
+        this._allowedKeybindings = {};
+
         this._switchData = null;
         this._shellwm.connect('kill-switch-workspace', Lang.bind(this, this._switchWorkspaceDone));
         this._shellwm.connect('kill-window-effects', Lang.bind(this, function (shellwm, actor) {
@@ -143,6 +145,25 @@ const WindowManager = new Lang.Class({
         }));
     },
 
+    setCustomKeybindingHandler: function(name, modes, handler) {
+        if (Meta.keybindings_set_custom_handler(name, handler))
+            this.allowKeybinding(name, modes);
+    },
+
+    addKeybinding: function(name, settings, flags, modes, handler) {
+        if (global.display.add_keybinding(name, settings, flags, handler))
+            this.allowKeybinding(name, modes);
+    },
+
+    removeKeybinding: function(name) {
+        if (global.display.remove_keybinding(name))
+            this.allowKeybinding(name, Main.KeybindingMode.NONE);
+    },
+
+    allowKeybinding: function(name, modes) {
+        this._allowedKeybindings[name] = modes;
+    },
+
     blockAnimations: function() {
         this._animationBlockCount++;
     },
@@ -449,10 +470,15 @@ const WindowManager = new Lang.Class({
                 return false;
         }
 
-        if (Main.modalCount == 0 && binding.is_builtin())
+        // There's little sense in implementing a keybinding in mutter and
+        // not having it work in NORMAL mode; handle this case generically
+        // so we don't have to explicitly allow all builtin keybindings in
+        // NORMAL mode.
+        if (Main.keybindingMode == Main.KeybindingMode.NORMAL &&
+            binding.is_builtin())
             return false;
 
-        return true;
+        return !(this._allowedKeybindings[binding.get_name()] & Main.keybindingMode);
     },
 
     _switchWorkspace : function(shellwm, from, to, direction) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]