From f563424417c2c77c8483efb795da48b43ab30abb Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 15 Mar 2021 14:50:31 +0800 Subject: [PATCH] keyboard: Fix display keyboard layout crash with some input methods Some ibus input method will use the current keyboard layout, and return "default" as the keyboard layout. When this happens, display the current keyboard layout instead. Fixes #3863. Part-of: --- js/misc/keyboardManager.js | 4 ++++ js/ui/status/keyboard.js | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/js/misc/keyboardManager.js b/js/misc/keyboardManager.js index 29fc3b761..142e2f419 100644 --- a/js/misc/keyboardManager.js +++ b/js/misc/keyboardManager.js @@ -156,4 +156,8 @@ var KeyboardManager = class { let options = this._xkbOptions.join(','); return options; } + + get currentLayout() { + return this._current; + } }; diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js index e34b60313..bc50f3d37 100644 --- a/js/ui/status/keyboard.js +++ b/js/ui/status/keyboard.js @@ -772,6 +772,10 @@ var InputSourceManager = class { get inputSources() { return this._inputSources; } + + get keyboardManager() { + return this._keyboardManager; + } }; Signals.addSignalMethods(InputSourceManager.prototype); @@ -1059,6 +1063,14 @@ class InputSourceIndicator extends PanelMenu.Button { xkbLayout = engineDesc.get_layout(); xkbVariant = engineDesc.get_layout_variant(); } + + // The `default` layout from ibus engine means to + // use the current keyboard layout. + if (xkbLayout === 'default') { + const current = this._inputSourceManager.keyboardManager.currentLayout; + xkbLayout = current.layout; + xkbVariant = current.variant; + } } if (!xkbLayout || xkbLayout.length == 0)