keyboard: Separate keyval action notification

Add a distinct signal for keys defining a keyval to have it handled
via event emulation.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3162>
This commit is contained in:
Carlos Garnacho 2024-01-30 10:59:14 +01:00
parent 4d71d9f46d
commit f0b18c9ccc

View File

@ -223,6 +223,7 @@ const Key = GObject.registerClass({
'long-press': {},
'pressed': {},
'released': {},
'keyval': {param_types: [GObject.TYPE_UINT]},
'commit': {param_types: [GObject.TYPE_UINT, GObject.TYPE_STRING]},
},
}, class Key extends St.BoxLayout {
@ -316,15 +317,16 @@ const Key = GObject.registerClass({
this._pressTimeoutId = 0;
}
let keyval;
if (button === this.keyButton)
keyval = this._keyval;
if (!keyval && commitString)
keyval = this._getKeyvalFromString(commitString);
console.assert(keyval !== undefined, 'Need keyval or commitString');
if (this._pressed && (commitString || keyval))
this.emit('commit', keyval, commitString || '');
if (this._pressed) {
if (this._keyval && button === this.keyButton)
this.emit('keyval', this._keyval);
else if (commitString) {
const keyval = this._getKeyvalFromString(commitString);
this.emit('commit', keyval, commitString);
} else {
console.error('Need keyval or commitString');
}
}
this.emit('released');
this._hideSubkeys();
@ -1437,6 +1439,13 @@ export const Keyboard = GObject.registerClass({
keyval: key.keyval,
}, strings);
if (key.keyval) {
button.connect('keyval', (_actor, keyval) => {
this._keyboardController.keyvalPress(keyval);
this._keyboardController.keyvalRelease(keyval);
});
}
if (key.action !== 'modifier') {
button.connect('commit', (_actor, keyval, str) => {
this._commitAction(keyval, str).then(() => {