[gnome-shell/wip/carlosg/osk-updates: 20/40] keyboard: Add/handle "modifier" action keys
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/carlosg/osk-updates: 20/40] keyboard: Add/handle "modifier" action keys
- Date: Sat, 2 Jul 2022 01:40:48 +0000 (UTC)
commit 60cd254ac158920efc1270b44b9c9746bcd5bd7e
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Apr 16 13:06:09 2022 +0200
keyboard: Add/handle "modifier" action keys
These keys are handled so that the related modifier keyval (e.g. left
control) is toggled on, and flushed on the next non-modifier key
press submission.
js/ui/keyboard.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 64 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index dbd3481a8f..f08a25adf7 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -493,15 +493,15 @@ var Key = GObject.registerClass({
}
setLatched(latched) {
- if (!this._icon)
- return;
-
- if (latched) {
+ if (latched)
this.keyButton.add_style_pseudo_class('latched');
- this._icon.icon_name = 'keyboard-caps-lock-symbolic';
- } else {
+ else
this.keyButton.remove_style_pseudo_class('latched');
- this._icon.icon_name = 'keyboard-shift-symbolic';
+
+ /* Shift keys have icons */
+ if (this._icon) {
+ this._icon.icon_name = latched
+ ? 'keyboard-caps-lock-symbolic' : 'keyboard-shift-symbolic';
}
}
});
@@ -1288,6 +1288,8 @@ var Keyboard = GObject.registerClass({
this._focusWindowStartY = null;
this._latched = false; // current level is latched
+ this._modifiers = [];
+ this._modifierKeys = {};
this._suggestions = null;
this._emojiKeyVisible = Meta.is_wayland_compositor();
@@ -1497,11 +1499,22 @@ var Keyboard = GObject.registerClass({
button.setWidth(key.width);
button.connect('commit', (actor, keyval, str) => {
+ /* These are emitted later on */
+ if (key.action === 'modifier')
+ return;
+
if (str === '' || !Main.inputMethod.currentFocus ||
+ this._modifiers.length > 0 ||
!this._keyboardController.commitString(str, true)) {
if (keyval != 0) {
+ this._forwardModifiers(this._modifiers, true);
this._keyboardController.keyvalPress(keyval);
- this._keyboardController.keyvalRelease(keyval);
+ GLib.timeout_add(GLib.PRIORITY_DEFAULT, 50, () => {
+ this._keyboardController.keyvalRelease(keyval);
+ this._forwardModifiers(this._modifiers, false);
+ this._disableAllModifiers();
+ return GLib.SOURCE_REMOVE;
+ });
}
}
@@ -1515,6 +1528,8 @@ var Keyboard = GObject.registerClass({
this._popupLanguageMenu(button);
} else if (key.action === 'emoji') {
this._toggleEmoji();
+ } else if (key.action === 'modifier') {
+ this._toggleModifier(key.keyval);
} else if (!this._longPressed && key.action === 'levelSwitch') {
this._setActiveLayer(key.level);
this._setLatched(
@@ -1537,6 +1552,12 @@ var Keyboard = GObject.registerClass({
}
}
+ if (key.action === 'modifier') {
+ let modifierKeys = this._modifierKeys[key.keyval] || [];
+ modifierKeys.push(button);
+ this._modifierKeys[key.keyval] = modifierKeys;
+ }
+
if (key.action || key.keyval)
button.keyButton.add_style_class_name('default-key');
@@ -1549,6 +1570,39 @@ var Keyboard = GObject.registerClass({
this._setCurrentLevelLatched(this._currentPage, this._latched);
}
+ _setModifierEnabled(keyval, enabled) {
+ const idx = this._modifiers.indexOf(keyval);
+ if (enabled && idx === -1)
+ this._modifiers.push(keyval);
+ else if (!enabled)
+ this._modifiers.splice(idx, 1);
+
+ for (const key of this._modifierKeys[keyval])
+ key.setLatched(enabled);
+ }
+
+ _toggleModifier(keyval) {
+ const isActive = this._modifiers.indexOf(keyval) !== -1;
+ this._setModifierEnabled(keyval, !isActive);
+ }
+
+ _forwardModifiers(modifiers, press) {
+ for (const keyval of modifiers) {
+ if (press)
+ this._keyboardController.keyvalPress(keyval);
+ else
+ this._keyboardController.keyvalRelease(keyval);
+ }
+ }
+
+ _disableAllModifiers() {
+ // The modifier list is modified inside the loop
+ while (this._modifiers.length > 0) {
+ const keyval = this._modifiers[0];
+ this._setModifierEnabled(keyval, false);
+ }
+ }
+
_popupLanguageMenu(keyActor) {
if (this._languagePopup)
this._languagePopup.destroy();
@@ -1694,6 +1748,7 @@ var Keyboard = GObject.registerClass({
delete this._currentPage._destroyID;
}
+ this._disableAllModifiers();
this._currentPage = currentPage;
this._currentPage._destroyID = this._currentPage.connect('destroy', () => {
this._currentPage = null;
@@ -1774,6 +1829,7 @@ var Keyboard = GObject.registerClass({
this._animateHide();
this.setCursorLocation(null);
+ this._disableAllModifiers();
}
_animateShow() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]