From 4d67fdbd6824615b6f7abd5a984bbc29e2945244 Mon Sep 17 00:00:00 2001 From: jlempen Date: Sun, 12 Feb 2023 21:10:38 +0100 Subject: [PATCH] Prevent switching layout in terminal mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new override for the getCurrentGroup() function in order to prevent the on-screen keyboard from switching to the ùs-extended.json` layout in terminal mode, as our layout is already extended now. --- src/extension.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/extension.js b/src/extension.js index 8d4c67d..a4c63e2 100644 --- a/src/extension.js +++ b/src/extension.js @@ -11,6 +11,7 @@ let _oskA11yApplicationsSettings; let backup_lastDeviceIsTouchScreen; let backup_relayout; let backup_touchMode; +let backup_getCurrentGroup; let currentSeat; let _indicator; let settings; @@ -78,10 +79,28 @@ function override_relayout() { } } +function override_getCurrentGroup() { + // Special case for Korean, if Hangul mode is disabled, use the 'us' keymap + if (this._currentSource.id === 'hangul') { + const inputSourceManager = InputSourceManager.getInputSourceManager(); + const currentSource = inputSourceManager.currentSource; + let prop; + for (let i = 0; (prop = currentSource.properties.get(i)) !== null; ++i) { + if (prop.get_key() === 'InputMode' && + prop.get_prop_type() === IBus.PropType.TOGGLE && + prop.get_state() !== IBus.PropState.CHECKED) + return 'us'; + } + } + return this._currentSource.xkbId; +} + function enable_overrides() { Keyboard.Keyboard.prototype["_relayout"] = override_relayout; Keyboard.KeyboardManager.prototype["_lastDeviceIsTouchscreen"] = override_lastDeviceIsTouchScreen; + Keyboard.KeyboardController.prototype["getCurrentGroup"] = + override_getCurrentGroup; // Unregister original osk layouts resource file getDefaultLayouts()._unregister(); @@ -94,6 +113,8 @@ function disable_overrides() { Keyboard.Keyboard.prototype["_relayout"] = backup_relayout; Keyboard.KeyboardManager.prototype["_lastDeviceIsTouchscreen"] = backup_lastDeviceIsTouchScreen; + Keyboard.KeyboardController.prototype["getCurrentGroup"] = + backup_getCurrentGroup; // Unregister modified osk layouts resource file getModifiedLayouts()._unregister(); @@ -140,6 +161,9 @@ function init() { backup_lastDeviceIsTouchScreen = Keyboard.KeyboardManager._lastDeviceIsTouchscreen; + backup_getCurrentGroup = + Keyboard.KeyboardController.getCurrentGroup; + currentSeat = Clutter.get_default_backend().get_default_seat(); backup_touchMode = currentSeat.get_touch_mode; }