[gnome-shell/wip/carlosg/osk-emoji-and-keypad: 11/11] keyboard: Implement keypad OSK panel



commit d7a530c1e287cbd9b4f1ee4ec2140600bb6d3190
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Jan 19 15:58:45 2019 +0100

    keyboard: Implement keypad OSK panel
    
    This is pretty ad-hoc, the panel is hooked so it shows right away on the
    right Clutter.InputContentPurpose.

 js/ui/keyboard.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 79 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index b03605132..10dc3881d 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -1048,6 +1048,50 @@ var EmojiSelection = new Lang.Class({
 });
 Signals.addSignalMethods(EmojiSelection.prototype);
 
+var Keypad = new Lang.Class({
+    Name: 'Keypad',
+
+    _init() {
+        let keys = [
+            { label: '1', keyval: Clutter.KEY_1, left: 0, top: 0 },
+            { label: '2', keyval: Clutter.KEY_2, left: 1, top: 0 },
+            { label: '3', keyval: Clutter.KEY_3, left: 2, top: 0 },
+            { label: '4', keyval: Clutter.KEY_4, left: 0, top: 1 },
+            { label: '5', keyval: Clutter.KEY_5, left: 1, top: 1 },
+            { label: '6', keyval: Clutter.KEY_6, left: 2, top: 1 },
+            { label: '7', keyval: Clutter.KEY_7, left: 0, top: 2 },
+            { label: '8', keyval: Clutter.KEY_8, left: 1, top: 2 },
+            { label: '9', keyval: Clutter.KEY_9, left: 2, top: 2 },
+            { label: '0', keyval: Clutter.KEY_0, left: 1, top: 3 },
+            { label: '⌫', keyval: Clutter.KEY_BackSpace, left: 3, top: 0 },
+            { keyval: Clutter.KEY_Return, extraClassName: 'enter-key', left: 3, top: 1, height: 2 },
+        ];
+
+        let gridLayout = new Clutter.GridLayout({ orientation: Clutter.Orientation.HORIZONTAL,
+                                                  column_homogeneous: true,
+                                                  row_homogeneous: true });
+        this.actor = new St.Widget({ layout_manager: gridLayout });
+
+        for (let i = 0; i < keys.length; i++) {
+            let cur = keys[i];
+            let key = new Key(cur.label || "", []);
+
+            if (keys[i].extraClassName)
+                key.keyButton.add_style_class_name(cur.extraClassName);
+
+            let w, h;
+            w = cur.width || 1;
+            h = cur.height || 1;
+            gridLayout.attach(key.actor, cur.left, cur.top, w, h);
+
+            key.connect('released', () => {
+                this.emit('keyval', cur.keyval);
+            });
+        }
+    },
+});
+Signals.addSignalMethods(Keypad.prototype);
+
 var Keyboard = new Lang.Class({
     Name: 'Keyboard',
 
@@ -1137,7 +1181,7 @@ var Keyboard = new Lang.Class({
 
     _syncEnabled() {
         let wasEnabled = this._enabled;
-        this._enableKeyboard = this._a11yApplicationsSettings.get_boolean(SHOW_KEYBOARD);
+        this._enableKeyboard = true;//this._a11yApplicationsSettings.get_boolean(SHOW_KEYBOARD);
         this._enabled = this._enableKeyboard || this._lastDeviceIsTouchscreen();
         if (!this._enabled && !this._keyboardController)
             return;
@@ -1160,6 +1204,8 @@ var Keyboard = new Lang.Class({
             this._keyboardController.disconnect(this._keyboardStateId);
         if (this._emojiKeyVisibleId)
             this._keyboardController.disconnect(this._emojiKeyVisibleId);
+        if (this._keypadVisibleId)
+            this._keyboardController.disconnect(this._keypadVisibleId);
         if (this._focusNotifyId)
             global.stage.disconnect(this._focusNotifyId);
         this._keyboard = null;
@@ -1200,6 +1246,15 @@ var Keyboard = new Lang.Class({
         this._aspectContainer.add_child(this._emojiSelection.actor);
         this._emojiSelection.actor.hide();
 
+        this._keypad = new Keypad();
+        this._keypad.connect('keyval', (keypad, keyval) => {
+            this._keyboardController.keyvalPress(keyval);
+            this._keyboardController.keyvalRelease(keyval);
+        });
+        this._aspectContainer.add_child(this._keypad.actor);
+        this._keypad.actor.hide();
+        this._keypadVisible = false;
+
         this._ensureKeysForGroup(this._keyboardController.getCurrentGroup());
         this._setActiveLayer(0);
 
@@ -1212,6 +1267,7 @@ var Keyboard = new Lang.Class({
         this._keyboardGroupsChangedId = this._keyboardController.connect('groups-changed', 
this._onKeyboardGroupsChanged.bind(this));
         this._keyboardStateId = this._keyboardController.connect('panel-state', 
this._onKeyboardStateChanged.bind(this));
         this._emojiKeyVisibleId = this._keyboardController.connect('emoji-visible', 
this._onEmojiKeyVisible.bind(this));
+        this._keypadVisibleId = this._keyboardController.connect('keypad-visible', 
this._onKeypadVisible.bind(this));
         this._focusNotifyId = global.stage.connect('notify::key-focus', this._onKeyFocusChanged.bind(this));
 
         this._relayout();
@@ -1387,11 +1443,15 @@ var Keyboard = new Lang.Class({
         }
     },
 
+    _updateCurrentPageVisible() {
+        if (this._current_page)
+            this._current_page.visible = !this._emojiActive && !this._keypadVisible;
+    },
+
     _setEmojiActive(active) {
         this._emojiActive = active;
         this._emojiSelection.actor.visible = this._emojiActive;
-        if (this._current_page)
-            this._current_page.visible = !this._emojiActive;
+        this._updateCurrentPageVisible();
     },
 
     _toggleEmoji() {
@@ -1478,6 +1538,15 @@ var Keyboard = new Lang.Class({
         this._onGroupChanged();
     },
 
+    _onKeypadVisible(controller, visible) {
+        if (visible == this._keypadVisible)
+            return;
+
+        this._keypadVisible = visible;
+        this._keypad.actor.visible = this._keypadVisible;
+        this._updateCurrentPageVisible();
+    },
+
     _onEmojiKeyVisible(controller, visible) {
         if (visible == this._emojiKeyVisible)
             return;
@@ -1514,7 +1583,7 @@ var Keyboard = new Lang.Class({
         }
 
         this._current_page = layers[activeLevel];
-        this._current_page.show();
+        this._updateCurrentPageVisible();
     },
 
     shouldTakeEvent(event) {
@@ -1737,16 +1806,20 @@ var KeyboardController = new Lang.Class({
         let hints = method.content_hints;
         let purpose = method.content_purpose;
         let emojiVisible = false;
+        let keypadVisible = false;
 
         if (purpose == Clutter.InputContentPurpose.NORMAL ||
             purpose == Clutter.InputContentPurpose.ALPHA ||
             purpose == Clutter.InputContentPurpose.PASSWORD ||
             purpose == Clutter.InputContentPurpose.TERMINAL)
             emojiVisible = true;
+        if (purpose == Clutter.InputContentPurpose.DIGITS ||
+            purpose == Clutter.InputContentPurpose.NUMBER ||
+            purpose == Clutter.InputContentPurpose.PHONE)
+            keypadVisible = true;
 
         this.emit('emoji-visible', emojiVisible)
-
-        // XXX: hook numeric/emoji/etc special keyboards
+        this.emit('keypad-visible', keypadVisible);
     },
 
     getGroups() {


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