[gnome-shell/wip/carlosg/osk-cldr: 33/34] keyboard: Move extended keys pop up/down into the Key object



commit 510019710ac05b41afbc219a203b615cbacece79
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Dec 22 15:59:19 2017 +0100

    keyboard: Move extended keys pop up/down into the Key object
    
    We do not need the parent Keyboard object to handle those specially, the
    code can be self-contained enough. The Key object will simply emit
    pressed/released events containing the keycode/string, be it from the
    parent key or one contained in the BoxPointer.

 js/ui/keyboard.js |   91 +++++++++++++++++++++++++++--------------------------
 1 files changed, 46 insertions(+), 45 deletions(-)
---
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index 64e2698..1aedb4e 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -191,6 +191,9 @@ var Key = new Lang.Class({
         this._extended_keys = extendedKeys;
         this._extended_keyboard = null;
         this._pressTimeoutId = 0;
+        this._capturedPress = false;
+        this._capturedEventId = 0;
+        this._unmapId = 0;
     },
 
     _onDestroy: function() {
@@ -237,7 +240,7 @@ var Key = new Lang.Class({
                                                         this._ensureExtendedKeysPopup();
                                                         this.actor.fake_release();
                                                         this.actor.set_hover(false);
-                                                        this.emit('show-subkeys');
+                                                        this._showSubkeys();
                                                         return GLib.SOURCE_REMOVE;
                                                     }));
         }
@@ -251,6 +254,48 @@ var Key = new Lang.Class({
         }
 
         this.emit('released', this._getKeyval(key), key);
+        this._hideSubkeys();
+    },
+
+    _onCapturedEvent: function(actor, event) {
+        let type = event.type();
+        let press = (type == Clutter.EventType.BUTTON_PRESS || type == Clutter.EventType.TOUCH_BEGIN);
+        let release = (type == Clutter.EventType.BUTTON_RELEASE || type == Clutter.EventType.TOUCH_END);
+
+        if (event.get_source() == this._boxPointer.bin ||
+            this._boxPointer.bin.contains(event.get_source()))
+            return Clutter.EVENT_PROPAGATE;
+
+        if (press)
+            this._capturedPress = true;
+        else if (release && this._capturedPress)
+            this._hideSubkeys();
+
+        return Clutter.EVENT_STOP;
+    },
+
+    _showSubkeys: function() {
+        this._boxPointer.show(BoxPointer.PopupAnimation.FULL);
+        this._capturedEventId = global.stage.connect('captured-event',
+                                                     Lang.bind(this, this._onCapturedEvent));
+        this._unmapId = this.actor.connect('notify::mapped', Lang.bind(this, function() {
+            if (!this.actor.is_mapped())
+                this._hideSubkeys();
+        }));
+    },
+
+    _hideSubkeys: function() {
+        if (this._boxPointer)
+            this._boxPointer.hide(BoxPointer.PopupAnimation.FULL);
+        if (this._capturedEventId) {
+            global.stage.disconnect(this._capturedEventId);
+            this._capturedEventId = 0;
+        }
+        if (this._unmapId) {
+            this.actor.disconnect(this._unmapId);
+            this._unmapId = 0;
+        }
+        this._capturedPress = false;
     },
 
     _makeKey: function (key) {
@@ -393,9 +438,6 @@ var Keyboard = new Lang.Class({
         this._syncEnabled();
 
         this._showIdleId = 0;
-        this._subkeysBoxPointer = null;
-        this._capturedEventId = 0;
-        this._capturedPress = false;
 
         this._keyboardVisible = false;
         Main.layoutManager.connect('keyboard-visible-changed', Lang.bind(this, function(o, visible) {
@@ -525,7 +567,6 @@ var Keyboard = new Lang.Class({
             // Don't show it here, we wait for the caret tracker to tell us so.
             this._setupKeyboard();
         } else if (!this._enableKeyboard) {
-            this._hideSubkeys();
             Main.layoutManager.hideKeyboard(true);
         }
     },
@@ -632,19 +673,6 @@ var Keyboard = new Lang.Class({
         this._setActiveLayer(0);
     },
 
-    _onCapturedEvent: function(actor, event) {
-        let type = event.type();
-        let press = (type == Clutter.EventType.BUTTON_PRESS || type == Clutter.EventType.TOUCH_BEGIN);
-        let release = (type == Clutter.EventType.BUTTON_RELEASE || type == Clutter.EventType.TOUCH_END);
-
-        if (press)
-            this._capturedPress = true;
-        else if (release && this._capturedPress)
-            this._hideSubkeys();
-
-        return Clutter.EVENT_STOP;
-    },
-
     _addRowKeys : function (keys, layout) {
         for (let i = 0; i < keys.length; ++i) {
             let key = keys[i];
@@ -654,20 +682,7 @@ var Keyboard = new Lang.Class({
             if (button.key == ' ')
                 button.setWidth(keys.length <= 3 ? 5 : 3);
 
-            button.connect('show-subkeys', Lang.bind(this, function() {
-                if (this._subkeysBoxPointer)
-                    this._subkeysBoxPointer.hide(BoxPointer.PopupAnimation.FULL);
-                this._subkeysBoxPointer = button.subkeys;
-                this._subkeysBoxPointer.show(BoxPointer.PopupAnimation.FULL);
-                if (!this._capturedEventId)
-                    this._capturedEventId = this.actor.connect('captured-event',
-                                                               Lang.bind(this, this._onCapturedEvent));
-            }));
-            button.connect('hide-subkeys', Lang.bind(this, function() {
-                this._hideSubkeys();
-            }));
             button.connect('pressed', Lang.bind(this, function(actor, keyval, str) {
-                this._hideSubkeys();
                 if (!this._keyboardController.commitString(str, true)) {
                     if (keyval != 0) {
                         this._keyboardController.keyvalPress(keyval);
@@ -676,7 +691,6 @@ var Keyboard = new Lang.Class({
                 }
             }));
             button.connect('released', Lang.bind(this, function(actor, keyval, str) {
-                this._hideSubkeys();
                 if (keyval != 0 && button._keyvalPress)
                     this._keyboardController.keyvalRelease(keyval);
             }));
@@ -907,22 +921,9 @@ var Keyboard = new Lang.Class({
         if (this._keyboardRequested)
             return;
 
-        this._hideSubkeys();
         Main.layoutManager.hideKeyboard();
     },
 
-    _hideSubkeys: function() {
-        if (this._subkeysBoxPointer) {
-            this._subkeysBoxPointer.hide(BoxPointer.PopupAnimation.FULL);
-            this._subkeysBoxPointer = null;
-        }
-        if (this._capturedEventId) {
-            this.actor.disconnect(this._capturedEventId);
-            this._capturedEventId = 0;
-        }
-        this._capturedPress = false;
-    },
-
     resetSuggestions: function(suggestions) {
         this._suggestions.clear();
         this._suggestions.actor.hide();


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