Blame SOURCES/0001-Add-extra-osk-keys-extension.patch

f6a177
From 2ebc78ce92ae615d36ae80420b737b6f1583c7c8 Mon Sep 17 00:00:00 2001
f6a177
From: rpm-build <rpm-build>
f6a177
Date: Fri, 9 Aug 2019 14:46:44 +0200
f6a177
Subject: [PATCH] Add extra-osk-keys extension
f6a177
f6a177
Originally improveosk by Simon Schumann,
f6a177
https://extensions.gnome.org/extension/1631/improve-onscreen-keyboard/
f6a177
---
f6a177
 extensions/extra-osk-keys/extension.js     | 230 +++++++++++++++++++++
f6a177
 extensions/extra-osk-keys/meson.build      |   5 +
f6a177
 extensions/extra-osk-keys/metadata.json.in |  10 +
f6a177
 extensions/extra-osk-keys/stylesheet.css   |   6 +
f6a177
 meson.build                                |   1 +
f6a177
 5 files changed, 252 insertions(+)
f6a177
 create mode 100644 extensions/extra-osk-keys/extension.js
f6a177
 create mode 100644 extensions/extra-osk-keys/meson.build
f6a177
 create mode 100644 extensions/extra-osk-keys/metadata.json.in
f6a177
 create mode 100644 extensions/extra-osk-keys/stylesheet.css
f6a177
f6a177
diff --git a/extensions/extra-osk-keys/extension.js b/extensions/extra-osk-keys/extension.js
f6a177
new file mode 100644
f6a177
index 0000000..23221d7
f6a177
--- /dev/null
f6a177
+++ b/extensions/extra-osk-keys/extension.js
f6a177
@@ -0,0 +1,230 @@
f6a177
+
f6a177
+const St = imports.gi.St;
f6a177
+const Main = imports.ui.main;
f6a177
+const Keyboard = imports.ui.keyboard;
f6a177
+const EdgeDragAction = imports.ui.edgeDragAction;
f6a177
+const Shell = imports.gi.Shell;
f6a177
+const Lang = imports.lang;
f6a177
+const Clutter = imports.gi.Clutter;
f6a177
+const Workspace = imports.ui.workspace
f6a177
+const Tweener = imports.ui.tweener;
f6a177
+const Overview = imports.ui.overview;
f6a177
+const Layout = imports.ui.layout;
f6a177
+
f6a177
+var defaultKeyboardDelay;
f6a177
+var Backup_DefaultKeysForRow;
f6a177
+var Backup_contructor;
f6a177
+var Backup_keyvalPress;
f6a177
+var Backup_keyvalRelease;
f6a177
+
f6a177
+
f6a177
+function init() {
f6a177
+    defaultKeyboardDelay = Layout.KEYBOARD_ANIMATION_TIME;
f6a177
+    Backup_DefaultKeysForRow = Keyboard.Keyboard.prototype['_getDefaultKeysForRow'];
f6a177
+    Backup_contructor = Keyboard.KeyboardController.prototype['constructor'];
f6a177
+    Backup_keyvalPress = Keyboard.KeyboardController.prototype['keyvalPress'];
f6a177
+    Backup_keyvalRelease = Keyboard.KeyboardController.prototype['keyvalRelease'];
f6a177
+}
f6a177
+
f6a177
+function enable() {
f6a177
+    Main.layoutManager.removeChrome(Main.layoutManager.keyboardBox);
f6a177
+
f6a177
+    var KeyboardIsSetup = true;
f6a177
+    try {
f6a177
+      Main.keyboard._destroyKeyboard();
f6a177
+    } catch (e) {
f6a177
+        if(e instanceof TypeError) {
f6a177
+            // In case the keyboard is currently disabled in accessability settings, attempting to _destroyKeyboard() yields a TypeError ("TypeError: this.actor is null")
f6a177
+            // This doesn't affect functionality, so proceed as usual. The only difference is that we do not automatically _setupKeyboard at the end of this enable() (let the user enable the keyboard in accessability settings)
f6a177
+            KeyboardIsSetup = false;
f6a177
+        } else {
f6a177
+            // Something different happened
f6a177
+            throw e;
f6a177
+        }
f6a177
+    }
f6a177
+    
f6a177
+
f6a177
+    Keyboard.Keyboard.prototype['_getDefaultKeysForRow'] = function(row, numRows, level) {
f6a177
+        
f6a177
+        let defaultKeysPreMod = [
f6a177
+            [ [{ label: 'Esc', width: 1, keyval: Clutter.KEY_Escape }], [{ label: '↹', width: 1.5, keyval: Clutter.KEY_Tab }], [{ width: 1.5, level: 1, extraClassName: 'shift-key-lowercase' }], [{ label: 'Ctrl', width: 1, keyval: Clutter.KEY_Control_L, extraClassName: 'control-key' }, { label: '◆', width: 1, keyval: Clutter.KEY_Super_L, extraClassName: 'super-key' }, { label: 'Alt', width: 1, keyval: Clutter.KEY_Alt_L, extraClassName: 'alt-key' }] ],
f6a177
+            [ [{ label: 'Esc', width: 1, keyval: Clutter.KEY_Escape }], [{ label: '↹', width: 1.5, keyval: Clutter.KEY_Tab }], [{ width: 1.5, level: 0, extraClassName: 'shift-key-uppercase' }], [{ label: 'Ctrl', width: 1, keyval: Clutter.KEY_Control_L, extraClassName: 'control-key' }, { label: '◆', width: 1, keyval: Clutter.KEY_Super_L, extraClassName: 'super-key' }, { label: 'Alt', width: 1, keyval: Clutter.KEY_Alt_L, extraClassName: 'alt-key' }] ],
f6a177
+            [ [{ label: 'Esc', width: 1, keyval: Clutter.KEY_Escape }], [{ label: '↹', width: 1.5, keyval: Clutter.KEY_Tab }], [{ label: '=/
f6a177
+            [ [{ label: 'Esc', width: 1, keyval: Clutter.KEY_Escape }], [{ label: '↹', width: 1.5, keyval: Clutter.KEY_Tab }], [{ label: '?123', width: 1.5, level: 2 }], [{ label: 'Ctrl', width: 1, keyval: Clutter.KEY_Control_L, extraClassName: 'control-key' }, { label: '◆', width: 1, keyval: Clutter.KEY_Super_L, extraClassName: 'super-key' }, { label: 'Alt', width: 1, keyval: Clutter.KEY_Alt_L, extraClassName: 'alt-key' }] ],
f6a177
+        ];
f6a177
+
f6a177
+    
f6a177
+        let defaultKeysPostMod = [
f6a177
+            [ [{ label: '⌫', width: 1.5, keyval: Clutter.KEY_BackSpace }, { label: '⌦', width: 1, keyval: Clutter.KEY_Delete }, { width: 1, action: 'hide', extraClassName: 'hide-key' }],
f6a177
+              [{ width: 2, keyval: Clutter.KEY_Return, extraClassName: 'enter-key' }, { width: 1.5, action: 'languageMenu', extraClassName: 'layout-key' }],
f6a177
+              [{ width: 3, level: 1, right: true, extraClassName: 'shift-key-lowercase' }, { label: '?123', width: 1.5, level: 2 }],
f6a177
+              [{ label: '←', width: 1, keyval: Clutter.KEY_Left }, { label: '↑', width: 1, keyval: Clutter.KEY_Up }, { label: '↓', width: 1, keyval: Clutter.KEY_Down }, { label: '→', width: 1, keyval: Clutter.KEY_Right }] ],
f6a177
+            [ [{ label: '⌫', width: 1.5, keyval: Clutter.KEY_BackSpace }, { label: '⌦', width: 1, keyval: Clutter.KEY_Delete }, { width: 1, action: 'hide', extraClassName: 'hide-key' }],
f6a177
+              [{ width: 2, keyval: Clutter.KEY_Return, extraClassName: 'enter-key' }, { width: 1.5, action: 'languageMenu', extraClassName: 'layout-key' }],
f6a177
+              [{ width: 3, level: 0, right: true, extraClassName: 'shift-key-uppercase' }, { label: '?123', width: 1.5, level: 2 }],
f6a177
+              [{ label: '←', width: 1, keyval: Clutter.KEY_Left }, { label: '↑', width: 1, keyval: Clutter.KEY_Up }, { label: '↓', width: 1, keyval: Clutter.KEY_Down }, { label: '→', width: 1, keyval: Clutter.KEY_Right }] ],
f6a177
+            [ [{ label: '⌫', width: 1.5, keyval: Clutter.KEY_BackSpace }, { label: '⌦', width: 1, keyval: Clutter.KEY_Delete }, { width: 1, action: 'hide', extraClassName: 'hide-key' }],
f6a177
+              [{ width: 2, keyval: Clutter.KEY_Return, extraClassName: 'enter-key' }, { width: 1.5, action: 'languageMenu', extraClassName: 'layout-key' }],
f6a177
+              [{ label: '=/
f6a177
+              [{ label: '←', width: 1, keyval: Clutter.KEY_Left }, { label: '↑', width: 1, keyval: Clutter.KEY_Up }, { label: '↓', width: 1, keyval: Clutter.KEY_Down }, { label: '→', width: 1, keyval: Clutter.KEY_Right }] ],
f6a177
+            [ [{ label: 'F1', width: 1, keyval: Clutter.KEY_F1 }, { label: 'F2', width: 1, keyval: Clutter.KEY_F2 }, { label: 'F3', width: 1, keyval: Clutter.KEY_F3 }, { label: '⌫', width: 1.5, keyval: Clutter.KEY_BackSpace }, { label: '⌦', width: 1, keyval: Clutter.KEY_Delete }, { width: 1, action: 'hide', extraClassName: 'hide-key' }],
f6a177
+              [{ label: 'F4', width: 1, keyval: Clutter.KEY_F4 }, { label: 'F5', width: 1, keyval: Clutter.KEY_F5 }, { label: 'F6', width: 1, keyval: Clutter.KEY_F6 }, { width: 2, keyval: Clutter.KEY_Return, extraClassName: 'enter-key' }, { width: 1.5, action: 'languageMenu', extraClassName: 'layout-key' }],
f6a177
+              [{ label: 'F7', width: 1, keyval: Clutter.KEY_F7 }, { label: 'F8', width: 1, keyval: Clutter.KEY_F8 }, { label: 'F9', width: 1, keyval: Clutter.KEY_F9 }, { label: '?123', width: 3, level: 2, right: true }, { label: 'ABC', width: 1.5, level: 0 }],
f6a177
+              [{ label: 'F10', width: 1, keyval: Clutter.KEY_F10 }, { label: 'F11', width: 1, keyval: Clutter.KEY_F11 }, { label: 'F12', width: 1, keyval: Clutter.KEY_F12 }, { label: '←', width: 1, keyval: Clutter.KEY_Left }, { label: '↑', width: 1, keyval: Clutter.KEY_Up }, { label: '↓', width: 1, keyval: Clutter.KEY_Down }, { label: '→', width: 1, keyval: Clutter.KEY_Right }] ],
f6a177
+        ];
f6a177
+
f6a177
+    
f6a177
+        let pre, post;
f6a177
+
f6a177
+        /* The first 2 rows in defaultKeysPre/Post belong together with
f6a177
+         * the first 2 rows on each keymap. On keymaps that have more than
f6a177
+         * 4 rows, the last 2 default key rows must be respectively
f6a177
+         * assigned to the 2 last keymap ones.
f6a177
+         */
f6a177
+        if (row < 2) {
f6a177
+            return [defaultKeysPreMod[level][row], defaultKeysPostMod[level][row]];
f6a177
+        } else if (row >= numRows - 2) {
f6a177
+            let defaultRow = row - (numRows - 2) + 2;
f6a177
+            return [defaultKeysPreMod[level][defaultRow], defaultKeysPostMod[level][defaultRow]];
f6a177
+        } else {
f6a177
+            return [null, null];
f6a177
+        }
f6a177
+    }
f6a177
+    
f6a177
+    Keyboard.KeyboardController.prototype['constructor'] = function() {
f6a177
+        let deviceManager = Clutter.DeviceManager.get_default();
f6a177
+        this._virtualDevice = deviceManager.create_virtual_device(Clutter.InputDeviceType.KEYBOARD_DEVICE);
f6a177
+
f6a177
+        this._inputSourceManager = InputSourceManager.getInputSourceManager();
f6a177
+        this._sourceChangedId = this._inputSourceManager.connect('current-source-changed',
f6a177
+                                                                 this._onSourceChanged.bind(this));
f6a177
+        this._sourcesModifiedId = this._inputSourceManager.connect ('sources-changed',
f6a177
+                                                                    this._onSourcesModified.bind(this));
f6a177
+        this._currentSource = this._inputSourceManager.currentSource;
f6a177
+        
f6a177
+        this._controlActive = false;
f6a177
+        this._superActive = false;
f6a177
+        this._altActive = false;
f6a177
+
f6a177
+        Main.inputMethod.connect('notify::content-purpose',
f6a177
+                                 this._onContentPurposeHintsChanged.bind(this));
f6a177
+        Main.inputMethod.connect('notify::content-hints',
f6a177
+                                 this._onContentPurposeHintsChanged.bind(this));
f6a177
+        Main.inputMethod.connect('input-panel-state', (o, state) => {
f6a177
+            this.emit('panel-state', state);
f6a177
+        });
f6a177
+    }
f6a177
+
f6a177
+    
f6a177
+    Keyboard.KeyboardController.prototype['keyvalPress'] = function(keyval) {
f6a177
+        if(keyval==Clutter.KEY_Control_L) {
f6a177
+            this._controlActive = !this._controlActive; // This allows to revert an accidental tap on Ctrl by tapping on it again
f6a177
+        }
f6a177
+        if(keyval==Clutter.KEY_Super_L) {
f6a177
+            this._superActive = !this._superActive;
f6a177
+        }
f6a177
+        if(keyval==Clutter.KEY_Alt_L) {
f6a177
+            this._altActive = !this._altActive;
f6a177
+        }
f6a177
+        
f6a177
+        if(this._controlActive)
f6a177
+        {
f6a177
+            this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                              Clutter.KEY_Control_L, Clutter.KeyState.PRESSED);
f6a177
+            Main.layoutManager.keyboardBox.add_style_class_name("control-key-latched");
f6a177
+        } else {
f6a177
+            this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                              Clutter.KEY_Control_L, Clutter.KeyState.RELEASED);
f6a177
+            Main.layoutManager.keyboardBox.remove_style_class_name("control-key-latched");
f6a177
+        }
f6a177
+        if(this._superActive)
f6a177
+        {
f6a177
+            this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                              Clutter.KEY_Super_L, Clutter.KeyState.PRESSED);
f6a177
+            Main.layoutManager.keyboardBox.add_style_class_name("super-key-latched");
f6a177
+        } else {
f6a177
+            this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                              Clutter.KEY_Super_L, Clutter.KeyState.RELEASED);
f6a177
+            Main.layoutManager.keyboardBox.remove_style_class_name("super-key-latched");
f6a177
+        }
f6a177
+        if(this._altActive)
f6a177
+        {
f6a177
+            this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                              Clutter.KEY_Alt_L, Clutter.KeyState.PRESSED);
f6a177
+            Main.layoutManager.keyboardBox.add_style_class_name("alt-key-latched");
f6a177
+        } else {
f6a177
+            this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                              Clutter.KEY_Alt_L, Clutter.KeyState.RELEASED);
f6a177
+            Main.layoutManager.keyboardBox.remove_style_class_name("alt-key-latched");
f6a177
+        }
f6a177
+        this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                          keyval, Clutter.KeyState.PRESSED);
f6a177
+    }
f6a177
+
f6a177
+    
f6a177
+    Keyboard.KeyboardController.prototype['keyvalRelease'] = function(keyval) {
f6a177
+        if(keyval==Clutter.KEY_Control_L || keyval==Clutter.KEY_Alt_L || keyval==Clutter.KEY_Super_L) {
f6a177
+            return;
f6a177
+        }
f6a177
+        
f6a177
+        this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                          keyval, Clutter.KeyState.RELEASED);
f6a177
+
f6a177
+        if(this._controlActive)
f6a177
+        {
f6a177
+            this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                              Clutter.KEY_Control_L, Clutter.KeyState.RELEASED);
f6a177
+            this._controlActive = false;
f6a177
+            Main.layoutManager.keyboardBox.remove_style_class_name("control-key-latched");
f6a177
+        }
f6a177
+        if(this._superActive)
f6a177
+        {
f6a177
+            this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                              Clutter.KEY_Super_L, Clutter.KeyState.RELEASED);
f6a177
+            this._superActive = false;
f6a177
+            Main.layoutManager.keyboardBox.remove_style_class_name("super-key-latched");
f6a177
+        }
f6a177
+        if(this._altActive)
f6a177
+        {
f6a177
+            this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
f6a177
+                                              Clutter.KEY_Alt_L, Clutter.KeyState.RELEASED);
f6a177
+            this._altActive = false;
f6a177
+            Main.layoutManager.keyboardBox.remove_style_class_name("alt-key-latched");
f6a177
+        }
f6a177
+
f6a177
+    }
f6a177
+
f6a177
+    Layout.KEYBOARD_ANIMATION_TIME = 0;
f6a177
+    if(KeyboardIsSetup) {
f6a177
+        Main.keyboard._setupKeyboard();
f6a177
+    }
f6a177
+    Main.layoutManager.addChrome(   Main.layoutManager.keyboardBox, { affectsStruts: true, trackFullscreen: false });
f6a177
+}
f6a177
+
f6a177
+function disable() {
f6a177
+    Main.layoutManager.removeChrome(Main.layoutManager.keyboardBox);
f6a177
+    
f6a177
+    var KeyboardIsSetup = true;
f6a177
+    try {
f6a177
+      Main.keyboard._destroyKeyboard();
f6a177
+    } catch (e) {
f6a177
+        if(e instanceof TypeError) {
f6a177
+            // In case the keyboard is currently disabled in accessability settings, attempting to _destroyKeyboard() yields a TypeError ("TypeError: this.actor is null")
f6a177
+            // This doesn't affect functionality, so proceed as usual. The only difference is that we do not automatically _setupKeyboard at the end of this enable() (let the user enable the keyboard in accessability settings)
f6a177
+            KeyboardIsSetup = false;
f6a177
+        } else {
f6a177
+            // Something different happened
f6a177
+            throw e;
f6a177
+        }
f6a177
+    }
f6a177
+    
f6a177
+    Keyboard.Keyboard.prototype['_getDefaultKeysForRow'] = Backup_DefaultKeysForRow;
f6a177
+    Keyboard.KeyboardController.prototype['constructor'] = Backup_contructor;
f6a177
+    Keyboard.KeyboardController.prototype['keyvalPress'] = Backup_keyvalPress;
f6a177
+    Keyboard.KeyboardController.prototype['keyvalRelease'] = Backup_keyvalRelease;
f6a177
+    Layout.KEYBOARD_ANIMATION_TIME = defaultKeyboardDelay;
f6a177
+    if(KeyboardIsSetup) {
f6a177
+        Main.keyboard._setupKeyboard();
f6a177
+    }
f6a177
+    Main.layoutManager.addChrome(   Main.layoutManager.keyboardBox);
f6a177
+}
f6a177
diff --git a/extensions/extra-osk-keys/meson.build b/extensions/extra-osk-keys/meson.build
f6a177
new file mode 100644
f6a177
index 0000000..48504f6
f6a177
--- /dev/null
f6a177
+++ b/extensions/extra-osk-keys/meson.build
f6a177
@@ -0,0 +1,5 @@
f6a177
+extension_data += configure_file(
f6a177
+  input: metadata_name + '.in',
f6a177
+  output: metadata_name,
f6a177
+  configuration: metadata_conf
f6a177
+)
f6a177
diff --git a/extensions/extra-osk-keys/metadata.json.in b/extensions/extra-osk-keys/metadata.json.in
f6a177
new file mode 100644
f6a177
index 0000000..39dfdd3
f6a177
--- /dev/null
f6a177
+++ b/extensions/extra-osk-keys/metadata.json.in
f6a177
@@ -0,0 +1,10 @@
f6a177
+{
f6a177
+"extension-id": "@extension_id@",
f6a177
+"uuid": "@uuid@",
f6a177
+"gettext-domain": "@gettext_domain@",
f6a177
+"name": "Extra Onscreen Keyboard Keys",
f6a177
+"description": "Adds extra keys to gnome-shell onscreen keyboard.",
f6a177
+"original-authors": [ "simon.schumann@web.de" ],
f6a177
+"shell-version": [ "@shell_current@" ],
f6a177
+"url": "@url@"
f6a177
+}
f6a177
diff --git a/extensions/extra-osk-keys/stylesheet.css b/extensions/extra-osk-keys/stylesheet.css
f6a177
new file mode 100644
f6a177
index 0000000..010cfb3
f6a177
--- /dev/null
f6a177
+++ b/extensions/extra-osk-keys/stylesheet.css
f6a177
@@ -0,0 +1,6 @@
f6a177
+.control-key-latched .control-key,
f6a177
+.super-key-latched .super-key,
f6a177
+.alt-key-latched .alt-key {
f6a177
+      background-color: #55a54c;
f6a177
+}
f6a177
+
f6a177
diff --git a/meson.build b/meson.build
f6a177
index df2be33..fa4aa9c 100644
f6a177
--- a/meson.build
f6a177
+++ b/meson.build
f6a177
@@ -56,6 +56,7 @@ all_extensions += [
f6a177
   'dash-to-dock',
f6a177
   'disable-screenshield',
f6a177
   'example',
f6a177
+  'extra-osk-keys',
f6a177
   'native-window-placement',
f6a177
   'no-hot-corner',
f6a177
   'panel-favorites',
f6a177
-- 
f6a177
2.23.0.rc1
f6a177