[gnome-shell/wip/message-tray: 16/16] messageTray: Grab keyboard and mouse focus when revealed



commit 82d7e38d219a5c0f4dabcedffb5ff130c4aa08ba
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Aug 6 21:52:49 2012 +0200

    messageTray: Grab keyboard and mouse focus when revealed
    
    Clicking outside the tray, pressing ESC or the "toggle-message-tray"
    keybinding hides the tray.
    
    Fixes: https://bugzilla.gnome.org/677215

 js/ui/messageTray.js |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 4d00b12..ef48651 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1502,6 +1502,8 @@ const MessageTray = new Lang.Class({
         this._inFullscreen = false;
         this._tweening = 0;
         this._windowsShifted = 0;
+        this._buttonReleaseId = 0;
+        this._keyReleaseId = 0;
 
         this._corner = new Clutter.Rectangle({ width: 1,
                                                height: 1,
@@ -2013,6 +2015,36 @@ const MessageTray = new Lang.Class({
         this._updateState();
     },
 
+    _onButtonRelease: function(actor, event) {
+        let [x, y] = event.get_coords();
+        if (x < this.actor.x ||
+            y < this.actor.y ||
+            x > this.actor.x + this.actor.width ||
+            y > this.actor.y + this.actor.height)
+            this.toggle();
+
+        return false;
+    },
+
+    _onKeyRelease: function(actor, event) {
+        let keysym = event.get_key_symbol();
+        let state = event.get_state();
+        let settings = new Gio.Settings({ schema: SHELL_KEYBINDINGS_SCHEMA });
+        let toggle_bindings = settings.get_strv('toggle-message-tray');
+
+        if (keysym == Clutter.KEY_Escape) {
+            this.toggle();
+        } else {
+            for (let i = 0; i < toggle_bindings.length; i++) {
+                let [key, mod] = Gtk.accelerator_parse(toggle_bindings[i]);
+                if ((keysym == key) && (state & mod))
+                    this.toggle();
+            }
+        }
+
+        return false;
+    },
+
     _showTray: function() {
         // Bail out if we are in the middle of tweening the tray or the
         // windows.
@@ -2052,6 +2084,14 @@ const MessageTray = new Lang.Class({
             this._windowsShifted++;
             this._tweening++;
         }
+
+        Main.pushModal(this.actor);
+
+        this._buttonReleaseId = global.stage.connect('button-release-event',
+            Lang.bind(this, this._onButtonRelease));
+
+        this._keyReleaseId = global.stage.connect('key-release-event',
+            Lang.bind(this, this._onKeyRelease));
     },
 
     _hideTray: function() {
@@ -2095,6 +2135,18 @@ const MessageTray = new Lang.Class({
                              });
             this._tweening++;
         }
+
+        Main.popModal(this.actor);
+
+        if (this._buttonReleaseId > 0) {
+            global.stage.disconnect(this._buttonReleaseId);
+            this._buttonReleaseId = 0;
+        }
+
+        if (this._keyReleaseId > 0) {
+            global.stage.disconnect(this._keyReleaseId);
+            this._keyReleaseId = 0;
+        }
     },
 
     _onIdleMonitorWatch: function(monitor, id, userBecameIdle) {



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