keyboard: Detect taps close to the cursor caret on X11

Try to bring some feature parity wrt OSK being toggled on. Set up
a gesture that triggers on taps nearby the text caret position, as
reported by ibus.
This commit is contained in:
Carlos Garnacho 2020-05-12 16:41:45 +02:00
parent 79aeabcf76
commit f68fd6068f

View File

@ -529,6 +529,43 @@ var KeyboardModel = class {
} }
}; };
var IMFocusAction = GObject.registerClass({
Signals: {
'activated': {},
},
}, class IMFocusAction extends Clutter.GestureAction {
constructor() {
this.parent();
this.set_n_touch_points(1);
this.set_threshold_trigger_edge(Clutter.GestureTriggerEdge.BEFORE);
this._rect = null;
}
vfunc_gesture_prepare(actor) {
let event = this.get_last_event(0);
if (event.type() != Clutter.EventType.TOUCH_BEGIN)
return false;
let [x, y] = event.get_coords();
if (this._rect &&
x >= this._rect.x - 40 &&
x < this._rect.x + this._rect.width + 40 &&
y >= this._rect.y - 40 &&
y < this._rect.y + this._rect.height + 40) {
this.emit('activated');
}
// Action work is already done
return false;
}
setFocusRect(rect) {
this._rect = rect;
}
});
var FocusTracker = class { var FocusTracker = class {
constructor() { constructor() {
this._currentWindow = null; this._currentWindow = null;
@ -1210,6 +1247,15 @@ class Keyboard extends St.BoxLayout {
this._suggestions = null; this._suggestions = null;
this._emojiKeyVisible = Meta.is_wayland_compositor(); this._emojiKeyVisible = Meta.is_wayland_compositor();
this._imFocusAction = new IMFocusAction();
this._imFocusAction.connect('activated', () => {
/* Valid for X11 clients only */
if (Main.inputMethod.currentFocus)
return;
this.open(Main.layoutManager.focusIndex);
});
global.stage.add_action(this._imFocusAction);
this._focusTracker = new FocusTracker(); this._focusTracker = new FocusTracker();
this._connectSignal(this._focusTracker, 'position-changed', this._connectSignal(this._focusTracker, 'position-changed',
this._onFocusPositionChanged.bind(this)); this._onFocusPositionChanged.bind(this));
@ -1217,14 +1263,17 @@ class Keyboard extends St.BoxLayout {
this._delayedAnimFocusWindow = null; this._delayedAnimFocusWindow = null;
this._animFocusedWindow = null; this._animFocusedWindow = null;
this._oskFocusWindow = null; this._oskFocusWindow = null;
this._imFocusAction.setFocusRect(null);
}); });
// Valid only for X11 // Valid only for X11
if (!Meta.is_wayland_compositor()) { if (!Meta.is_wayland_compositor()) {
this._connectSignal(this._focusTracker, 'focus-changed', (_tracker, focused) => { this._connectSignal(this._focusTracker, 'focus-changed', (_tracker, focused) => {
if (focused) if (focused) {
this.open(Main.layoutManager.focusIndex); this.open(Main.layoutManager.focusIndex);
else } else {
this.close(); this.close();
this._imFocusAction.setFocusRect(null);
}
}); });
} }
@ -1264,6 +1313,7 @@ class Keyboard extends St.BoxLayout {
_onFocusPositionChanged(focusTracker) { _onFocusPositionChanged(focusTracker) {
let rect = focusTracker.getCurrentRect(); let rect = focusTracker.getCurrentRect();
this.setCursorLocation(focusTracker.currentWindow, rect.x, rect.y, rect.width, rect.height); this.setCursorLocation(focusTracker.currentWindow, rect.x, rect.y, rect.width, rect.height);
this._imFocusAction.setFocusRect(rect);
} }
_onDestroy() { _onDestroy() {