misc: Toggle IBus OSK capability on OSK visibility

Newer versions of IBus (> 1.5.26) have the IBUS_CAP_OSK capability
which can be used to hint the active IM about an OSK driving input as
opposed to a physical keyboard. This may be used by IMs to tweak their
behavior to suit OSKs better.

Add the GNOME Shell side handling for this capability, and toggle it
on whenever the OSK is visible.

Since this is a far too new enum value and we don't want such new
IBus dependency, this change plays fast and loose with JS guarantees,
since a logical OR with an undefined value results in the other operand
unmodified it will work for older versions where the capability does not
exist and thus we want nothing extra enabled.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2415>
This commit is contained in:
Carlos Garnacho 2022-08-09 16:00:33 +02:00 committed by Marge Bot
parent 4871eba8bf
commit 23bfd08b3c
2 changed files with 12 additions and 1 deletions

View File

@ -3,6 +3,7 @@
const { Clutter, GLib, Gio, GObject, IBus } = imports.gi;
const Keyboard = imports.ui.status.keyboard;
const Main = imports.ui.main;
Gio._promisify(IBus.Bus.prototype,
'create_input_context_async', 'create_input_context_async_finish');
@ -42,6 +43,9 @@ class InputMethod extends Clutter.InputMethod {
_updateCapabilities() {
let caps = IBus.Capabilite.PREEDIT_TEXT | IBus.Capabilite.FOCUS | IBus.Capabilite.SURROUNDING_TEXT;
if (Main.keyboard.visible)
caps |= IBus.Capabilite.OSK;
if (this._context)
this._context.set_capabilities(caps);
}
@ -72,10 +76,14 @@ class InputMethod extends Clutter.InputMethod {
this._context.connect('forward-key-event', this._onForwardKeyEvent.bind(this));
this._context.connect('destroy', this._clear.bind(this));
Main.keyboard.connectObject('visibility-changed', () => this._updateCapabilities());
this._updateCapabilities();
}
_clear() {
Main.keyboard.disconnectObject(this);
if (this._cancellable) {
this._cancellable.cancel();
this._cancellable = null;

View File

@ -1180,8 +1180,10 @@ var Keypad = GObject.registerClass({
}
});
var KeyboardManager = class KeyBoardManager {
var KeyboardManager = class extends Signals.EventEmitter {
constructor() {
super();
this._keyboard = null;
this._a11yApplicationsSettings = new Gio.Settings({ schema_id: A11Y_APPLICATIONS_SCHEMA });
this._a11yApplicationsSettings.connect('changed', this._syncEnabled.bind(this));
@ -1237,6 +1239,7 @@ var KeyboardManager = class KeyBoardManager {
if (enabled && !this._keyboard) {
this._keyboard = new Keyboard();
this._keyboard.connect('visibility-changed', () => {
this.emit('visibility-changed');
this._bottomDragAction.enabled = !this._keyboard.visible;
});
} else if (!enabled && this._keyboard) {