keyboard: Unify OSK key commit handling in single-state signal
Instead of having callers handle pressed+released, emit string commits on a distinct signal that is emitted all at once during release. This also unifies the behavior of keys that have an extended keys popup and not wrt press/release behavior and key repeat. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2278>
This commit is contained in:
parent
2e30fc2cbc
commit
ce80e16173
@ -299,8 +299,9 @@ var Key = GObject.registerClass({
|
|||||||
Signals: {
|
Signals: {
|
||||||
'activated': {},
|
'activated': {},
|
||||||
'long-press': {},
|
'long-press': {},
|
||||||
'pressed': { param_types: [GObject.TYPE_UINT, GObject.TYPE_STRING] },
|
'pressed': {},
|
||||||
'released': { param_types: [GObject.TYPE_UINT, GObject.TYPE_STRING] },
|
'released': {},
|
||||||
|
'commit': {param_types: [GObject.TYPE_UINT, GObject.TYPE_STRING]},
|
||||||
},
|
},
|
||||||
}, class Key extends St.BoxLayout {
|
}, class Key extends St.BoxLayout {
|
||||||
_init(params, extendedKeys = []) {
|
_init(params, extendedKeys = []) {
|
||||||
@ -354,13 +355,10 @@ var Key = GObject.registerClass({
|
|||||||
return Clutter.unicode_to_keysym(unicode);
|
return Clutter.unicode_to_keysym(unicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
_press(button, commitString) {
|
_press(button) {
|
||||||
this.emit('activated');
|
this.emit('activated');
|
||||||
|
|
||||||
let keyval;
|
|
||||||
|
|
||||||
if (button === this.keyButton) {
|
if (button === this.keyButton) {
|
||||||
keyval = this._keyval;
|
|
||||||
this._pressTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
this._pressTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
||||||
KEY_LONG_PRESS_TIME,
|
KEY_LONG_PRESS_TIME,
|
||||||
() => {
|
() => {
|
||||||
@ -380,11 +378,8 @@ var Key = GObject.registerClass({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!keyval)
|
this.emit('pressed');
|
||||||
keyval = this._getKeyvalFromString(commitString);
|
this._pressed = true;
|
||||||
|
|
||||||
if (this._extendedKeys.length === 0)
|
|
||||||
this.emit('pressed', keyval, commitString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_release(button, commitString) {
|
_release(button, commitString) {
|
||||||
@ -400,11 +395,12 @@ var Key = GObject.registerClass({
|
|||||||
keyval = this._getKeyvalFromString(commitString);
|
keyval = this._getKeyvalFromString(commitString);
|
||||||
console.assert(keyval !== undefined, 'Need keyval or commitString');
|
console.assert(keyval !== undefined, 'Need keyval or commitString');
|
||||||
|
|
||||||
if (this._extendedKeys.length > 0)
|
if (this._pressed && (commitString || keyval))
|
||||||
this.emit('pressed', keyval, commitString);
|
this.emit('commit', keyval, commitString || '');
|
||||||
|
|
||||||
this.emit('released', keyval, commitString);
|
this.emit('released');
|
||||||
this._hideSubkeys();
|
this._hideSubkeys();
|
||||||
|
this._pressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel() {
|
cancel() {
|
||||||
@ -917,7 +913,7 @@ var EmojiPager = GObject.registerClass({
|
|||||||
key.connect('long-press', () => {
|
key.connect('long-press', () => {
|
||||||
this._panAction.cancel();
|
this._panAction.cancel();
|
||||||
});
|
});
|
||||||
key.connect('released', (actor, keyval, str) => {
|
key.connect('commit', (actor, keyval, str) => {
|
||||||
if (this._currentKey != key)
|
if (this._currentKey != key)
|
||||||
return;
|
return;
|
||||||
this._currentKey = null;
|
this._currentKey = null;
|
||||||
@ -1543,20 +1539,13 @@ var Keyboard = GObject.registerClass({
|
|||||||
if (key.width !== null)
|
if (key.width !== null)
|
||||||
button.setWidth(key.width);
|
button.setWidth(key.width);
|
||||||
|
|
||||||
button.connect('pressed', (actor, keyval, str) => {
|
button.connect('commit', (actor, keyval, str) => {
|
||||||
if (!Main.inputMethod.currentFocus ||
|
if (str === '' || !Main.inputMethod.currentFocus ||
|
||||||
!this._keyboardController.commitString(str, true)) {
|
!this._keyboardController.commitString(str, true)) {
|
||||||
if (keyval != 0) {
|
if (keyval != 0) {
|
||||||
this._keyboardController.keyvalPress(keyval);
|
this._keyboardController.keyvalPress(keyval);
|
||||||
button._keyvalPress = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
button.connect('released', (actor, keyval, _str) => {
|
|
||||||
if (keyval != 0) {
|
|
||||||
if (button._keyvalPress)
|
|
||||||
this._keyboardController.keyvalRelease(keyval);
|
this._keyboardController.keyvalRelease(keyval);
|
||||||
button._keyvalPress = false;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._latched)
|
if (!this._latched)
|
||||||
|
Loading…
Reference in New Issue
Block a user