2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-01-16 10:21:01 -05:00
|
|
|
const FocusCaretTracker = imports.ui.focusCaretTracker;
|
|
|
|
const Atspi = imports.gi.Atspi;
|
2011-08-29 11:11:22 -04:00
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gdk = imports.gi.Gdk;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Lang = imports.lang;
|
2015-03-10 12:49:56 -04:00
|
|
|
const Meta = imports.gi.Meta;
|
2011-08-29 11:11:22 -04:00
|
|
|
const Shell = imports.gi.Shell;
|
2012-11-10 16:47:57 -05:00
|
|
|
const Signals = imports.signals;
|
2011-08-29 11:11:22 -04:00
|
|
|
const St = imports.gi.St;
|
2016-07-20 11:50:55 -04:00
|
|
|
const InputSourceManager = imports.ui.status.keyboard;
|
2011-08-29 11:11:22 -04:00
|
|
|
|
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2012-11-18 10:17:21 -05:00
|
|
|
const Layout = imports.ui.layout;
|
2011-08-29 11:11:22 -04:00
|
|
|
const Main = imports.ui.main;
|
2018-01-23 10:45:46 -05:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2017-10-11 03:58:58 -04:00
|
|
|
const Tweener = imports.ui.tweener;
|
2018-01-23 10:45:46 -05:00
|
|
|
const Util = imports.misc.util;
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var KEYBOARD_REST_TIME = Layout.KEYBOARD_ANIMATION_TIME * 2 * 1000;
|
2017-08-05 06:21:30 -04:00
|
|
|
var KEY_LONG_PRESS_TIME = 250;
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2011-08-29 13:02:42 -04:00
|
|
|
const A11Y_APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications';
|
|
|
|
const SHOW_KEYBOARD = 'screen-keyboard-enabled';
|
|
|
|
|
2017-12-20 07:08:50 -05:00
|
|
|
/* KeyContainer puts keys in a grid where a 1:1 key takes this size */
|
|
|
|
const KEY_SIZE = 2;
|
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
const defaultKeysPre = [
|
2018-02-15 07:46:19 -05:00
|
|
|
[ [], [], [{ width: 1.5, level: 1, extraClassName: 'shift-key-lowercase' }], [{ label: '?123', width: 1.5, level: 2 }] ],
|
|
|
|
[ [], [], [{ width: 1.5, level: 0, extraClassName: 'shift-key-uppercase' }], [{ label: '?123', width: 1.5, level: 2 }] ],
|
2017-08-05 06:21:30 -04:00
|
|
|
[ [], [], [{ label: '=/<', width: 1.5, level: 3 }], [{ label: 'ABC', width: 1.5, level: 0 }] ],
|
|
|
|
[ [], [], [{ label: '?123', width: 1.5, level: 2 }], [{ label: 'ABC', width: 1.5, level: 0 }] ],
|
|
|
|
];
|
|
|
|
|
|
|
|
const defaultKeysPost = [
|
|
|
|
[ [{ label: '⌫', width: 1.5, keyval: Clutter.KEY_BackSpace }],
|
2018-02-15 07:46:19 -05:00
|
|
|
[{ width: 2, keyval: Clutter.KEY_Return, extraClassName: 'enter-key' }],
|
|
|
|
[{ width: 3, level: 1, right: true, extraClassName: 'shift-key-lowercase' }],
|
|
|
|
[{ width: 1.5, action: 'languageMenu', extraClassName: 'layout-key' }, { width: 1.5, action: 'hide', extraClassName: 'hide-key' }] ],
|
2017-08-05 06:21:30 -04:00
|
|
|
[ [{ label: '⌫', width: 1.5, keyval: Clutter.KEY_BackSpace }],
|
2018-02-15 07:46:19 -05:00
|
|
|
[{ width: 2, keyval: Clutter.KEY_Return, extraClassName: 'enter-key' }],
|
|
|
|
[{ width: 3, level: 0, right: true, extraClassName: 'shift-key-uppercase' }],
|
|
|
|
[{ width: 1.5, action: 'languageMenu', extraClassName: 'layout-key' }, { width: 1.5, action: 'hide', extraClassName: 'hide-key' }] ],
|
2017-08-05 06:21:30 -04:00
|
|
|
[ [{ label: '⌫', width: 1.5, keyval: Clutter.KEY_BackSpace }],
|
2018-02-15 07:46:19 -05:00
|
|
|
[{ width: 2, keyval: Clutter.KEY_Return, extraClassName: 'enter-key' }],
|
2017-08-05 06:21:30 -04:00
|
|
|
[{ label: '=/<', width: 3, level: 3, right: true }],
|
2018-02-15 07:46:19 -05:00
|
|
|
[{ width: 1.5, action: 'languageMenu', extraClassName: 'layout-key' }, { width: 1.5, action: 'hide', extraClassName: 'hide-key' }] ],
|
2017-08-05 06:21:30 -04:00
|
|
|
[ [{ label: '⌫', width: 1.5, keyval: Clutter.KEY_BackSpace }],
|
2018-02-15 07:46:19 -05:00
|
|
|
[{ width: 2, keyval: Clutter.KEY_Return, extraClassName: 'enter-key' }],
|
2017-08-05 06:21:30 -04:00
|
|
|
[{ label: '?123', width: 3, level: 2, right: true }],
|
2018-02-15 07:46:19 -05:00
|
|
|
[{ width: 1.5, action: 'languageMenu', extraClassName: 'layout-key' }, { width: 1.5, action: 'hide', extraClassName: 'hide-key' }] ],
|
2017-08-05 06:21:30 -04:00
|
|
|
];
|
|
|
|
|
2017-12-20 07:08:50 -05:00
|
|
|
var KeyContainer = new Lang.Class({
|
|
|
|
Name: 'KeyContainer',
|
|
|
|
Extends: St.Widget,
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2017-12-20 07:08:50 -05:00
|
|
|
let gridLayout = new Clutter.GridLayout({ orientation: Clutter.Orientation.HORIZONTAL,
|
|
|
|
column_homogeneous: true,
|
|
|
|
row_homogeneous: true });
|
|
|
|
this.parent({ layout_manager: gridLayout });
|
|
|
|
this._gridLayout = gridLayout;
|
|
|
|
this._currentRow = 0;
|
|
|
|
this._currentCol = 0;
|
|
|
|
this._maxCols = 0;
|
|
|
|
|
|
|
|
this._currentRow = null;
|
|
|
|
this._rows = [];
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
appendRow(length) {
|
2017-12-20 07:08:50 -05:00
|
|
|
this._currentRow++;
|
|
|
|
this._currentCol = 0;
|
|
|
|
|
|
|
|
let row = new Object();
|
|
|
|
row.keys = [];
|
|
|
|
row.width = 0;
|
|
|
|
this._rows.push(row);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
appendKey(key, width = 1, height = 1) {
|
2017-12-20 07:08:50 -05:00
|
|
|
let keyInfo = {
|
|
|
|
key,
|
|
|
|
left: this._currentCol,
|
|
|
|
top: this._currentRow,
|
|
|
|
width,
|
|
|
|
height
|
|
|
|
};
|
|
|
|
|
|
|
|
let row = this._rows[this._rows.length - 1];
|
|
|
|
row.keys.push(keyInfo);
|
|
|
|
row.width += width;
|
|
|
|
|
|
|
|
this._currentCol += width;
|
|
|
|
this._maxCols = Math.max(this._currentCol, this._maxCols);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_allocate(box, flags) {
|
2017-12-20 07:08:50 -05:00
|
|
|
if (box.get_width() > 0 && box.get_height() > 0 && this._maxCols > 0) {
|
|
|
|
let keyboardRatio = this._maxCols / this._rows.length;
|
|
|
|
let sizeRatio = box.get_width() / box.get_height();
|
|
|
|
|
|
|
|
if (sizeRatio >= keyboardRatio) {
|
|
|
|
/* Restrict horizontally */
|
|
|
|
let width = box.get_height() * keyboardRatio;
|
|
|
|
let diff = box.get_width() - width;
|
|
|
|
|
|
|
|
box.x1 += Math.floor(diff / 2);
|
|
|
|
box.x2 -= Math.ceil(diff / 2);
|
|
|
|
} else {
|
|
|
|
/* Restrict vertically */
|
|
|
|
let height = box.get_width() / keyboardRatio;
|
|
|
|
let diff = box.get_height() - height;
|
|
|
|
|
|
|
|
box.y1 += Math.floor(diff / 2);
|
|
|
|
box.y2 -= Math.floor(diff / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.parent (box, flags);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
layoutButtons() {
|
2017-12-20 07:08:50 -05:00
|
|
|
let nCol = 0, nRow = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < this._rows.length; i++) {
|
|
|
|
let row = this._rows[i];
|
|
|
|
|
|
|
|
/* When starting a new row, see if we need some padding */
|
|
|
|
if (nCol == 0) {
|
|
|
|
let diff = this._maxCols - row.width;
|
|
|
|
if (diff >= 1)
|
|
|
|
nCol = diff * KEY_SIZE / 2;
|
|
|
|
else
|
|
|
|
nCol = diff * KEY_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let j = 0; j < row.keys.length; j++) {
|
|
|
|
let keyInfo = row.keys[j];
|
|
|
|
let width = keyInfo.width * KEY_SIZE;
|
|
|
|
let height = keyInfo.height * KEY_SIZE;
|
|
|
|
|
|
|
|
this._gridLayout.attach(keyInfo.key, nCol, nRow, width, height);
|
|
|
|
nCol += width;
|
|
|
|
}
|
|
|
|
|
|
|
|
nRow += KEY_SIZE;
|
|
|
|
nCol = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-06 07:46:02 -05:00
|
|
|
var Suggestions = new Lang.Class({
|
|
|
|
Name: 'Suggestions',
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2017-12-06 07:46:02 -05:00
|
|
|
this.actor = new St.BoxLayout({ style_class: 'word-suggestions',
|
|
|
|
vertical: false });
|
|
|
|
this.actor.show();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
add(word, callback) {
|
2017-12-06 07:46:02 -05:00
|
|
|
let button = new St.Button({ label: word });
|
|
|
|
button.connect('clicked', callback);
|
|
|
|
this.actor.add(button);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
clear() {
|
2017-12-06 07:46:02 -05:00
|
|
|
this.actor.remove_all_children();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(Suggestions.prototype);
|
|
|
|
|
2018-01-23 10:45:46 -05:00
|
|
|
var LanguageSelectionPopup = new Lang.Class({
|
|
|
|
Name: 'LanguageSelectionPopup',
|
|
|
|
Extends: PopupMenu.PopupMenu,
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(actor) {
|
2018-01-23 10:45:46 -05:00
|
|
|
this.parent(actor, 0.5, St.Side.BOTTOM);
|
|
|
|
|
|
|
|
let inputSourceManager = InputSourceManager.getInputSourceManager();
|
|
|
|
let inputSources = inputSourceManager.inputSources;
|
|
|
|
|
|
|
|
for (let i in inputSources) {
|
|
|
|
let is = inputSources[i];
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this.addAction(is.displayName, () => {
|
2018-01-23 10:45:46 -05:00
|
|
|
inputSourceManager.activateInputSource(is, true);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2018-01-23 10:45:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2017-12-01 19:27:35 -05:00
|
|
|
this.addAction(_("Region & Language Settings"), this._launchSettings.bind(this));
|
2018-01-23 10:45:46 -05:00
|
|
|
this._capturedEventId = 0;
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._unmapId = actor.connect('notify::mapped', () => {
|
2018-01-23 10:45:46 -05:00
|
|
|
if (!actor.is_mapped())
|
|
|
|
this.close(true);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2018-01-23 10:45:46 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_launchSettings() {
|
2018-01-23 10:45:46 -05:00
|
|
|
Util.spawn(['gnome-control-center', 'region']);
|
|
|
|
this.close(true);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onCapturedEvent(actor, event) {
|
2018-01-23 10:45:46 -05:00
|
|
|
if (event.get_source() == this.actor ||
|
|
|
|
this.actor.contains(event.get_source()))
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
if (event.type() == Clutter.EventType.BUTTON_RELEASE || event.type() == Clutter.EventType.TOUCH_END)
|
|
|
|
this.close(true);
|
|
|
|
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
open(animate) {
|
2018-01-23 10:45:46 -05:00
|
|
|
this.parent(animate);
|
|
|
|
this._capturedEventId = global.stage.connect('captured-event',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onCapturedEvent.bind(this));
|
2018-01-23 10:45:46 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
close(animate) {
|
2018-01-23 10:45:46 -05:00
|
|
|
this.parent(animate);
|
|
|
|
if (this._capturedEventId != 0) {
|
|
|
|
global.stage.disconnect(this._capturedEventId);
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2018-01-23 10:45:46 -05:00
|
|
|
if (this._capturedEventId != 0)
|
|
|
|
global.stage.disconnect(this._capturedEventId);
|
|
|
|
if (this._unmapId != 0)
|
|
|
|
this.sourceActor.disconnect(this._unmapId);
|
|
|
|
this.parent();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var Key = new Lang.Class({
|
2011-11-20 12:56:27 -05:00
|
|
|
Name: 'Key',
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(key, extendedKeys) {
|
2018-02-15 07:46:19 -05:00
|
|
|
this.key = key || "";
|
2018-02-11 10:19:10 -05:00
|
|
|
this.keyButton = this._makeKey(this.key);
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
/* Add the key in a container, so keys can be padded without losing
|
|
|
|
* logical proportions between those.
|
|
|
|
*/
|
2018-02-11 10:19:10 -05:00
|
|
|
this.actor = new St.BoxLayout ({ style_class: 'key-container' });
|
|
|
|
this.actor.add(this.keyButton, { expand: true, x_fill: true });
|
2017-12-01 19:27:35 -05:00
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
this._extended_keys = extendedKeys;
|
|
|
|
this._extended_keyboard = null;
|
|
|
|
this._pressTimeoutId = 0;
|
2017-12-22 09:59:19 -05:00
|
|
|
this._capturedPress = false;
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
this._unmapId = 0;
|
2018-02-15 06:18:59 -05:00
|
|
|
this._longPress = false;
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDestroy() {
|
2014-09-19 20:44:45 -04:00
|
|
|
if (this._boxPointer) {
|
|
|
|
this._boxPointer.actor.destroy();
|
|
|
|
this._boxPointer = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ensureExtendedKeysPopup() {
|
2017-08-05 06:21:30 -04:00
|
|
|
if (this._extended_keys.length == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._boxPointer = new BoxPointer.BoxPointer(St.Side.BOTTOM,
|
|
|
|
{ x_fill: true,
|
|
|
|
y_fill: true,
|
|
|
|
x_align: St.Align.START });
|
|
|
|
this._boxPointer.actor.hide();
|
|
|
|
Main.layoutManager.addChrome(this._boxPointer.actor);
|
2018-02-11 10:19:10 -05:00
|
|
|
this._boxPointer.setPosition(this.keyButton, 0.5);
|
2017-08-05 06:21:30 -04:00
|
|
|
|
|
|
|
// Adds style to existing keyboard style to avoid repetition
|
|
|
|
this._boxPointer.actor.add_style_class_name('keyboard-subkeys');
|
|
|
|
this._getExtendedKeys();
|
2018-02-11 10:19:10 -05:00
|
|
|
this.keyButton._extended_keys = this._extended_keyboard;
|
2017-08-05 06:21:30 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getKeyval(key) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let unicode = String.charCodeAt(key, 0);
|
|
|
|
return Gdk.unicode_to_keyval(unicode);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_press(key) {
|
2017-08-05 06:21:30 -04:00
|
|
|
if (key != this.key || this._extended_keys.length == 0) {
|
2017-12-05 14:05:18 -05:00
|
|
|
this.emit('pressed', this._getKeyval(key), key);
|
2018-02-15 06:18:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key == this.key) {
|
2017-08-05 06:21:30 -04:00
|
|
|
this._pressTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
|
|
|
KEY_LONG_PRESS_TIME,
|
2017-10-30 20:38:18 -04:00
|
|
|
() => {
|
2018-02-15 06:18:59 -05:00
|
|
|
this._longPress = true;
|
2017-08-05 06:21:30 -04:00
|
|
|
this._pressTimeoutId = 0;
|
2018-02-15 06:18:59 -05:00
|
|
|
|
|
|
|
this.emit('long-press');
|
|
|
|
|
|
|
|
if (this._extended_keys.length > 0) {
|
|
|
|
this._touchPressed = false;
|
|
|
|
this.keyButton.set_hover(false);
|
|
|
|
this.keyButton.fake_release();
|
|
|
|
this._ensureExtendedKeysPopup();
|
|
|
|
this._showSubkeys();
|
|
|
|
}
|
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-08-05 06:21:30 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_release(key) {
|
2017-08-05 06:21:30 -04:00
|
|
|
if (this._pressTimeoutId != 0) {
|
|
|
|
GLib.source_remove(this._pressTimeoutId);
|
|
|
|
this._pressTimeoutId = 0;
|
|
|
|
}
|
|
|
|
|
2018-02-15 06:18:59 -05:00
|
|
|
if (!this._longPress && key == this.key && this._extended_keys.length > 0)
|
|
|
|
this.emit('pressed', this._getKeyval(key), key);
|
|
|
|
|
2017-12-05 14:05:18 -05:00
|
|
|
this.emit('released', this._getKeyval(key), key);
|
2017-12-22 09:59:19 -05:00
|
|
|
this._hideSubkeys();
|
2018-02-15 06:18:59 -05:00
|
|
|
this._longPress = false;
|
2017-12-22 09:59:19 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onCapturedEvent(actor, event) {
|
2017-12-22 09:59:19 -05:00
|
|
|
let type = event.type();
|
|
|
|
let press = (type == Clutter.EventType.BUTTON_PRESS || type == Clutter.EventType.TOUCH_BEGIN);
|
|
|
|
let release = (type == Clutter.EventType.BUTTON_RELEASE || type == Clutter.EventType.TOUCH_END);
|
|
|
|
|
|
|
|
if (event.get_source() == this._boxPointer.bin ||
|
|
|
|
this._boxPointer.bin.contains(event.get_source()))
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
if (press)
|
|
|
|
this._capturedPress = true;
|
|
|
|
else if (release && this._capturedPress)
|
|
|
|
this._hideSubkeys();
|
|
|
|
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_showSubkeys() {
|
2017-12-22 09:59:19 -05:00
|
|
|
this._boxPointer.show(BoxPointer.PopupAnimation.FULL);
|
|
|
|
this._capturedEventId = global.stage.connect('captured-event',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onCapturedEvent.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
this._unmapId = this.keyButton.connect('notify::mapped', () => {
|
2018-02-11 10:19:10 -05:00
|
|
|
if (!this.keyButton.is_mapped())
|
2017-12-22 09:59:19 -05:00
|
|
|
this._hideSubkeys();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-12-22 09:59:19 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_hideSubkeys() {
|
2017-12-22 09:59:19 -05:00
|
|
|
if (this._boxPointer)
|
|
|
|
this._boxPointer.hide(BoxPointer.PopupAnimation.FULL);
|
|
|
|
if (this._capturedEventId) {
|
|
|
|
global.stage.disconnect(this._capturedEventId);
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
}
|
|
|
|
if (this._unmapId) {
|
2018-02-11 10:19:10 -05:00
|
|
|
this.keyButton.disconnect(this._unmapId);
|
2017-12-22 09:59:19 -05:00
|
|
|
this._unmapId = 0;
|
|
|
|
}
|
|
|
|
this._capturedPress = false;
|
2017-08-05 06:21:30 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_makeKey(key) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let label = GLib.markup_escape_text(key, -1);
|
2011-08-29 11:11:22 -04:00
|
|
|
let button = new St.Button ({ label: label,
|
|
|
|
style_class: 'keyboard-key' });
|
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
button.keyWidth = 1;
|
2017-10-30 20:38:18 -04:00
|
|
|
button.connect('button-press-event', () => {
|
|
|
|
this._press(key);
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
});
|
|
|
|
button.connect('button-release-event', () => {
|
|
|
|
this._release(key);
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
});
|
|
|
|
button.connect('touch-event', (actor, event) => {
|
|
|
|
let device = event.get_device();
|
|
|
|
let sequence = event.get_event_sequence();
|
|
|
|
|
|
|
|
// We only handle touch events here on wayland. On X11
|
|
|
|
// we do get emulated pointer events, which already works
|
|
|
|
// for single-touch cases. Besides, the X11 passive touch grab
|
|
|
|
// set up by Mutter will make us see first the touch events
|
|
|
|
// and later the pointer events, so it will look like two
|
|
|
|
// unrelated series of events, we want to avoid double handling
|
|
|
|
// in these cases.
|
|
|
|
if (!Meta.is_wayland_compositor())
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 20:38:18 -04:00
|
|
|
|
|
|
|
if (!this._touchPressed &&
|
|
|
|
event.type() == Clutter.EventType.TOUCH_BEGIN) {
|
|
|
|
device.sequence_grab(sequence, actor);
|
|
|
|
this._touchPressed = true;
|
|
|
|
this._press(key);
|
|
|
|
} else if (this._touchPressed &&
|
|
|
|
event.type() == Clutter.EventType.TOUCH_END &&
|
|
|
|
device.sequence_get_grabbed_actor(sequence) == actor) {
|
|
|
|
device.sequence_ungrab(sequence);
|
|
|
|
this._touchPressed = false;
|
2017-08-05 06:21:30 -04:00
|
|
|
this._release(key);
|
2017-10-30 20:38:18 -04:00
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
});
|
2011-08-29 11:11:22 -04:00
|
|
|
|
|
|
|
return button;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getExtendedKeys() {
|
2017-08-05 06:21:30 -04:00
|
|
|
this._extended_keyboard = new St.BoxLayout({ style_class: 'key-container',
|
2011-08-29 11:11:22 -04:00
|
|
|
vertical: false });
|
|
|
|
for (let i = 0; i < this._extended_keys.length; ++i) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let extendedKey = this._extended_keys[i];
|
|
|
|
let key = this._makeKey(extendedKey);
|
2014-07-22 06:38:44 -04:00
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
key.extended_key = extendedKey;
|
2011-08-29 11:11:22 -04:00
|
|
|
this._extended_keyboard.add(key);
|
2017-08-05 06:21:30 -04:00
|
|
|
|
2018-02-11 10:19:10 -05:00
|
|
|
key.width = this.keyButton.width;
|
|
|
|
key.height = this.keyButton.height;
|
2011-08-29 11:11:22 -04:00
|
|
|
}
|
|
|
|
this._boxPointer.bin.add_actor(this._extended_keyboard);
|
|
|
|
},
|
|
|
|
|
2012-11-10 16:47:57 -05:00
|
|
|
get subkeys() {
|
|
|
|
return this._boxPointer;
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setWidth(width) {
|
2018-02-11 10:19:10 -05:00
|
|
|
this.keyButton.keyWidth = width;
|
2017-08-05 06:21:30 -04:00
|
|
|
},
|
2018-02-15 08:48:46 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setLatched(latched) {
|
2018-02-15 08:48:46 -05:00
|
|
|
if (latched)
|
|
|
|
this.keyButton.add_style_pseudo_class('latched');
|
|
|
|
else
|
|
|
|
this.keyButton.remove_style_pseudo_class('latched');
|
|
|
|
},
|
2017-08-05 06:21:30 -04:00
|
|
|
});
|
|
|
|
Signals.addSignalMethods(Key.prototype);
|
|
|
|
|
|
|
|
var KeyboardModel = new Lang.Class({
|
|
|
|
Name: 'KeyboardModel',
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(groupName) {
|
2017-08-05 06:21:30 -04:00
|
|
|
try {
|
|
|
|
this._model = this._loadModel(groupName);
|
|
|
|
} catch (e) {
|
|
|
|
this._model = this._loadModel('us');
|
2011-08-29 11:11:22 -04:00
|
|
|
}
|
2017-08-05 06:21:30 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_loadModel(groupName) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let file = Gio.File.new_for_uri('resource:///org/gnome/shell/osk-layouts/%s.json'.format(groupName));
|
|
|
|
let [success, contents] = file.load_contents(null);
|
|
|
|
|
|
|
|
return JSON.parse(contents);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getLevels() {
|
2017-08-05 06:21:30 -04:00
|
|
|
return this._model.levels;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getKeysForLevel(levelName) {
|
2017-08-05 06:21:30 -04:00
|
|
|
return this._model.levels.find(level => level == levelName);
|
2011-08-29 11:11:22 -04:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var Keyboard = new Lang.Class({
|
2017-01-16 10:21:01 -05:00
|
|
|
Name: 'Keyboard',
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2011-09-01 11:01:48 -04:00
|
|
|
this.actor = null;
|
2012-09-24 14:03:53 -04:00
|
|
|
this._focusInExtendedKeys = false;
|
2011-09-01 11:01:48 -04:00
|
|
|
|
2017-01-16 10:21:01 -05:00
|
|
|
this._focusCaretTracker = new FocusCaretTracker.FocusCaretTracker();
|
2017-12-01 19:27:35 -05:00
|
|
|
this._focusCaretTracker.connect('focus-changed', this._onFocusChanged.bind(this));
|
|
|
|
this._focusCaretTracker.connect('caret-moved', this._onCaretMoved.bind(this));
|
2018-01-23 10:45:46 -05:00
|
|
|
this._languagePopup = null;
|
2017-01-16 10:21:01 -05:00
|
|
|
this._currentAccessible = null;
|
|
|
|
this._caretTrackingEnabled = false;
|
|
|
|
this._updateCaretPositionId = 0;
|
2017-10-11 03:58:58 -04:00
|
|
|
this._currentFocusWindow = null;
|
|
|
|
this._originalWindowY = null;
|
2017-01-16 10:21:01 -05:00
|
|
|
|
2017-10-09 06:51:08 -04:00
|
|
|
this._enableKeyboard = false; // a11y settings value
|
|
|
|
this._enabled = false; // enabled state (by setting or device type)
|
2018-02-15 06:20:51 -05:00
|
|
|
this._latched = false; // current level is latched
|
2017-10-09 06:51:08 -04:00
|
|
|
|
2014-06-24 15:17:09 -04:00
|
|
|
this._a11yApplicationsSettings = new Gio.Settings({ schema_id: A11Y_APPLICATIONS_SCHEMA });
|
2017-12-01 19:27:35 -05:00
|
|
|
this._a11yApplicationsSettings.connect('changed', this._syncEnabled.bind(this));
|
2015-03-10 12:49:56 -04:00
|
|
|
this._lastDeviceId = null;
|
2017-12-06 07:46:02 -05:00
|
|
|
this._suggestions = null;
|
2015-03-10 12:49:56 -04:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
Meta.get_backend().connect('last-device-changed',
|
|
|
|
(backend, deviceId) => {
|
2015-03-10 12:49:56 -04:00
|
|
|
let manager = Clutter.DeviceManager.get_default();
|
|
|
|
let device = manager.get_device(deviceId);
|
|
|
|
|
|
|
|
if (device.get_device_name().indexOf('XTEST') < 0) {
|
|
|
|
this._lastDeviceId = deviceId;
|
2017-07-23 07:51:11 -04:00
|
|
|
this._syncEnabled();
|
2015-03-10 12:49:56 -04:00
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-08-05 06:21:30 -04:00
|
|
|
this._syncEnabled();
|
2012-10-30 11:46:18 -04:00
|
|
|
|
|
|
|
this._showIdleId = 0;
|
2012-11-18 10:17:21 -05:00
|
|
|
|
|
|
|
this._keyboardVisible = false;
|
2017-10-30 20:38:18 -04:00
|
|
|
Main.layoutManager.connect('keyboard-visible-changed', (o, visible) => {
|
2012-11-18 10:17:21 -05:00
|
|
|
this._keyboardVisible = visible;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2012-11-18 10:17:21 -05:00
|
|
|
this._keyboardRequested = false;
|
|
|
|
this._keyboardRestingId = 0;
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
Main.layoutManager.connect('monitors-changed', this._relayout.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
//Main.inputMethod.connect('cursor-location-changed', (o, rect) => {
|
2017-10-11 03:58:58 -04:00
|
|
|
// if (this._keyboardVisible) {
|
|
|
|
// let currentWindow = global.screen.get_display().focus_window;
|
|
|
|
// this.setCursorLocation(currentWindow, rect.get_x(), rect.get_y(),
|
|
|
|
// rect.get_width(), rect.get_height());
|
|
|
|
// }
|
2017-10-30 20:38:18 -04:00
|
|
|
//});
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-12-15 11:53:48 -05:00
|
|
|
get visible() {
|
|
|
|
return this._keyboardVisible;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setCaretTrackerEnabled(enabled) {
|
2017-01-16 10:21:01 -05:00
|
|
|
if (this._caretTrackingEnabled == enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._caretTrackingEnabled = enabled;
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
this._focusCaretTracker.registerFocusListener();
|
|
|
|
this._focusCaretTracker.registerCaretListener();
|
|
|
|
} else {
|
|
|
|
this._focusCaretTracker.deregisterFocusListener();
|
|
|
|
this._focusCaretTracker.deregisterCaretListener();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateCaretPosition(accessible) {
|
2017-01-16 10:21:01 -05:00
|
|
|
if (this._updateCaretPositionId)
|
|
|
|
GLib.source_remove(this._updateCaretPositionId);
|
2017-10-11 03:58:58 -04:00
|
|
|
if (!this._keyboardRequested)
|
|
|
|
return;
|
2017-10-30 20:38:18 -04:00
|
|
|
this._updateCaretPositionId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
|
2017-01-16 10:21:01 -05:00
|
|
|
this._updateCaretPositionId = 0;
|
|
|
|
|
|
|
|
let currentWindow = global.screen.get_display().focus_window;
|
2017-10-11 03:58:58 -04:00
|
|
|
if (!currentWindow) {
|
|
|
|
this.setCursorLocation(null);
|
2017-01-16 10:21:01 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-11 03:58:58 -04:00
|
|
|
}
|
2017-01-16 10:21:01 -05:00
|
|
|
|
|
|
|
let windowRect = currentWindow.get_frame_rect();
|
|
|
|
let text = accessible.get_text_iface();
|
|
|
|
let component = accessible.get_component_iface();
|
|
|
|
|
|
|
|
try {
|
|
|
|
let caretOffset = text.get_caret_offset();
|
|
|
|
let caretRect = text.get_character_extents(caretOffset, Atspi.CoordType.WINDOW);
|
|
|
|
let focusRect = component.get_extents(Atspi.CoordType.WINDOW);
|
|
|
|
|
|
|
|
if (caretRect.width == 0 && caretRect.height == 0)
|
|
|
|
caretRect = focusRect;
|
|
|
|
|
2017-10-11 03:58:58 -04:00
|
|
|
this.setCursorLocation(currentWindow, caretRect.x, caretRect.y, caretRect.width, caretRect.height);
|
2017-01-16 10:21:01 -05:00
|
|
|
} catch (e) {
|
|
|
|
log('Error updating caret position for OSK: ' + e.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-01-16 10:21:01 -05:00
|
|
|
|
|
|
|
GLib.Source.set_name_by_id(this._updateCaretPositionId, '[gnome-shell] this._updateCaretPosition');
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_focusIsTextEntry(accessible) {
|
2017-01-16 10:21:01 -05:00
|
|
|
try {
|
|
|
|
let role = accessible.get_role();
|
|
|
|
let stateSet = accessible.get_state_set();
|
|
|
|
return stateSet.contains(Atspi.StateType.EDITABLE) || role == Atspi.Role.TERMINAL;
|
|
|
|
} catch (e) {
|
|
|
|
log('Error determining accessible role: ' + e.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onFocusChanged(caretTracker, event) {
|
2017-01-16 10:21:01 -05:00
|
|
|
let accessible = event.source;
|
|
|
|
if (!this._focusIsTextEntry(accessible))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let focused = event.detail1 != 0;
|
|
|
|
if (focused) {
|
|
|
|
this._currentAccessible = accessible;
|
|
|
|
this._updateCaretPosition(accessible);
|
2017-01-16 10:36:21 -05:00
|
|
|
this.show(Main.layoutManager.focusIndex);
|
2017-01-16 10:21:01 -05:00
|
|
|
} else if (this._currentAccessible == accessible) {
|
|
|
|
this._currentAccessible = null;
|
2017-01-16 10:36:21 -05:00
|
|
|
this.hide();
|
2017-01-16 10:21:01 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onCaretMoved(caretTracker, event) {
|
2017-01-16 10:21:01 -05:00
|
|
|
let accessible = event.source;
|
|
|
|
if (this._currentAccessible == accessible)
|
|
|
|
this._updateCaretPosition(accessible);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_lastDeviceIsTouchscreen() {
|
2015-03-10 12:49:56 -04:00
|
|
|
if (!this._lastDeviceId)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let manager = Clutter.DeviceManager.get_default();
|
|
|
|
let device = manager.get_device(this._lastDeviceId);
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return device.get_device_type() == Clutter.InputDeviceType.TOUCHSCREEN_DEVICE;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_syncEnabled() {
|
2018-01-18 12:56:10 -05:00
|
|
|
let wasEnabled = this._enabled;
|
2017-10-09 06:51:08 -04:00
|
|
|
this._enableKeyboard = this._a11yApplicationsSettings.get_boolean(SHOW_KEYBOARD);
|
|
|
|
this._enabled = this._enableKeyboard || this._lastDeviceIsTouchscreen();
|
2017-08-05 06:21:30 -04:00
|
|
|
if (!this._enabled && !this._keyboardController)
|
2011-08-29 11:11:22 -04:00
|
|
|
return;
|
|
|
|
|
2017-10-09 06:51:08 -04:00
|
|
|
this._setCaretTrackerEnabled(this._enabled);
|
2017-01-16 10:21:01 -05:00
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
if (this._enabled && !this._keyboardController)
|
2017-10-09 06:53:04 -04:00
|
|
|
this._setupKeyboard();
|
2017-10-11 03:58:58 -04:00
|
|
|
else if (!this._enabled)
|
|
|
|
this.setCursorLocation(null);
|
2017-10-09 06:53:04 -04:00
|
|
|
|
2017-12-22 09:59:19 -05:00
|
|
|
if (!this._enabled && wasEnabled)
|
2017-07-23 07:51:11 -04:00
|
|
|
Main.layoutManager.hideKeyboard(true);
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_destroyKeyboard() {
|
2011-08-29 11:11:22 -04:00
|
|
|
if (this._keyboardNotifyId)
|
2017-08-05 06:21:30 -04:00
|
|
|
this._keyboardController.disconnect(this._keyboardNotifyId);
|
|
|
|
if (this._keyboardGroupsChangedId)
|
|
|
|
this._keyboardController.disconnect(this._keyboardGroupsChangedId);
|
2017-12-05 14:05:18 -05:00
|
|
|
if (this._keyboardStateId)
|
|
|
|
this._keyboardController.disconnect(this._keyboardStateId);
|
2011-08-29 11:11:22 -04:00
|
|
|
if (this._focusNotifyId)
|
|
|
|
global.stage.disconnect(this._focusNotifyId);
|
|
|
|
this._keyboard = null;
|
2011-09-01 11:01:48 -04:00
|
|
|
this.actor.destroy();
|
|
|
|
this.actor = null;
|
2018-01-23 10:45:46 -05:00
|
|
|
|
|
|
|
if (this._languagePopup) {
|
|
|
|
this._languagePopup.destroy();
|
|
|
|
this._languagePopup = null;
|
|
|
|
}
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setupKeyboard() {
|
2011-09-01 11:01:48 -04:00
|
|
|
this.actor = new St.BoxLayout({ name: 'keyboard', vertical: true, reactive: true });
|
|
|
|
Main.layoutManager.keyboardBox.add_actor(this.actor);
|
|
|
|
Main.layoutManager.trackChrome(this.actor);
|
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
this._keyboardController = new KeyboardController();
|
|
|
|
|
2011-08-29 11:11:22 -04:00
|
|
|
this._groups = {};
|
|
|
|
this._current_page = null;
|
|
|
|
|
2017-12-06 07:46:02 -05:00
|
|
|
this._suggestions = new Suggestions();
|
2017-10-30 20:38:18 -04:00
|
|
|
this._suggestions.connect('suggestion-clicked', (suggestions, str) => {
|
2017-12-06 07:46:02 -05:00
|
|
|
this._keyboardController.commitString(str);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-12-06 07:46:02 -05:00
|
|
|
this.actor.add(this._suggestions.actor,
|
|
|
|
{ x_align: St.Align.MIDDLE,
|
|
|
|
x_fill: false });
|
|
|
|
|
2018-01-23 11:03:02 -05:00
|
|
|
this._ensureKeysForGroup(this._keyboardController.getCurrentGroup());
|
|
|
|
this._setActiveLayer(0);
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
// Keyboard models are defined in LTR, we must override
|
|
|
|
// the locale setting in order to avoid flipping the
|
|
|
|
// keyboard on RTL locales.
|
2012-03-14 07:21:33 -04:00
|
|
|
this.actor.text_direction = Clutter.TextDirection.LTR;
|
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._keyboardNotifyId = this._keyboardController.connect('active-group', this._onGroupChanged.bind(this));
|
|
|
|
this._keyboardGroupsChangedId = this._keyboardController.connect('groups-changed', this._onKeyboardGroupsChanged.bind(this));
|
|
|
|
this._keyboardStateId = this._keyboardController.connect('panel-state', this._onKeyboardStateChanged.bind(this));
|
|
|
|
this._focusNotifyId = global.stage.connect('notify::key-focus', this._onKeyFocusChanged.bind(this));
|
2017-12-20 07:08:50 -05:00
|
|
|
|
|
|
|
this._relayout();
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onKeyFocusChanged() {
|
2011-08-29 11:11:22 -04:00
|
|
|
let focus = global.stage.key_focus;
|
|
|
|
|
2011-10-11 17:54:05 -04:00
|
|
|
// Showing an extended key popup and clicking a key from the extended keys
|
|
|
|
// will grab focus, but ignore that
|
2012-09-24 14:03:53 -04:00
|
|
|
let extendedKeysWereFocused = this._focusInExtendedKeys;
|
|
|
|
this._focusInExtendedKeys = focus && (focus._extended_keys || focus.extended_key);
|
|
|
|
if (this._focusInExtendedKeys || extendedKeysWereFocused)
|
2011-08-29 11:11:22 -04:00
|
|
|
return;
|
|
|
|
|
2011-11-03 20:22:00 -04:00
|
|
|
let time = global.get_current_time();
|
2012-10-30 11:46:18 -04:00
|
|
|
if (!(focus instanceof Clutter.Text)) {
|
2017-01-16 10:36:21 -05:00
|
|
|
this.hide();
|
2012-10-30 11:46:18 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-10 13:26:52 -04:00
|
|
|
if (!this._showIdleId) {
|
2017-10-30 20:38:18 -04:00
|
|
|
this._showIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
|
|
|
|
this.show(Main.layoutManager.focusIndex);
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
2017-01-16 10:36:21 -05:00
|
|
|
GLib.Source.set_name_by_id(this._showIdleId, '[gnome-shell] this.show');
|
2014-04-10 13:26:52 -04:00
|
|
|
}
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_createLayersForGroup(groupName) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let keyboardModel = new KeyboardModel(groupName);
|
2013-02-17 22:01:04 -05:00
|
|
|
let layers = {};
|
2017-08-05 06:21:30 -04:00
|
|
|
let levels = keyboardModel.getLevels();
|
|
|
|
for (let i = 0; i < levels.length; i++) {
|
|
|
|
let currentLevel = levels[i];
|
|
|
|
/* There are keyboard maps which consist of 3 levels (no uppercase,
|
|
|
|
* basically). We however make things consistent by skipping that
|
|
|
|
* second level.
|
|
|
|
*/
|
|
|
|
let level = (i >= 1 && levels.length == 3) ? i + 1 : i;
|
2017-12-20 07:08:50 -05:00
|
|
|
|
|
|
|
let layout = new KeyContainer();
|
2018-02-15 08:48:46 -05:00
|
|
|
layout.shiftKeys = [];
|
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
this._loadRows(currentLevel, level, levels.length, layout);
|
|
|
|
layers[level] = layout;
|
2017-12-20 07:08:50 -05:00
|
|
|
this.actor.add(layout, { expand: true });
|
|
|
|
layout.layoutButtons();
|
2013-02-17 22:01:04 -05:00
|
|
|
|
|
|
|
layout.hide();
|
|
|
|
}
|
|
|
|
return layers;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ensureKeysForGroup(group) {
|
2018-01-23 11:03:02 -05:00
|
|
|
if (!this._groups[group])
|
|
|
|
this._groups[group] = this._createLayersForGroup(group);
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_addRowKeys(keys, layout) {
|
2011-08-29 11:11:22 -04:00
|
|
|
for (let i = 0; i < keys.length; ++i) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let key = keys[i];
|
|
|
|
let button = new Key(key.shift(), key);
|
|
|
|
|
|
|
|
/* Space key gets special width, dependent on the number of surrounding keys */
|
|
|
|
if (button.key == ' ')
|
|
|
|
button.setWidth(keys.length <= 3 ? 5 : 3);
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
button.connect('pressed', (actor, keyval, str) => {
|
2017-12-05 14:05:18 -05:00
|
|
|
if (!Main.inputMethod.currentFocus ||
|
|
|
|
!this._keyboardController.commitString(str, true)) {
|
|
|
|
if (keyval != 0) {
|
|
|
|
this._keyboardController.keyvalPress(keyval);
|
|
|
|
button._keyvalPress = true;
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
button.connect('released', (actor, keyval, str) => {
|
2017-12-05 14:05:18 -05:00
|
|
|
if (keyval != 0) {
|
|
|
|
if (button._keyvalPress)
|
|
|
|
this._keyboardController.keyvalRelease(keyval);
|
|
|
|
button._keyvalPress = false;
|
|
|
|
}
|
2018-02-15 06:20:51 -05:00
|
|
|
|
|
|
|
if (!this._latched)
|
|
|
|
this._setActiveLayer(0);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-08-05 06:21:30 -04:00
|
|
|
|
2018-02-11 10:19:10 -05:00
|
|
|
layout.appendKey(button.actor, button.keyButton.keyWidth);
|
2017-08-05 06:21:30 -04:00
|
|
|
}
|
|
|
|
},
|
2012-11-10 16:47:57 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_popupLanguageMenu(keyActor) {
|
2018-01-23 10:45:46 -05:00
|
|
|
if (this._languagePopup)
|
|
|
|
this._languagePopup.destroy();
|
|
|
|
|
|
|
|
this._languagePopup = new LanguageSelectionPopup(keyActor);
|
|
|
|
Main.layoutManager.addChrome(this._languagePopup.actor);
|
|
|
|
this._languagePopup.open(true);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_loadDefaultKeys(keys, layout, numLevels, numKeys) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let extraButton;
|
|
|
|
for (let i = 0; i < keys.length; i++) {
|
|
|
|
let key = keys[i];
|
|
|
|
let keyval = key.keyval;
|
|
|
|
let switchToLevel = key.level;
|
|
|
|
let action = key.action;
|
|
|
|
|
|
|
|
extraButton = new Key(key.label, []);
|
|
|
|
|
2018-02-11 10:19:10 -05:00
|
|
|
extraButton.keyButton.add_style_class_name('default-key');
|
2017-08-05 06:21:30 -04:00
|
|
|
if (key.extraClassName != null)
|
2018-02-11 10:19:10 -05:00
|
|
|
extraButton.keyButton.add_style_class_name(key.extraClassName);
|
2017-08-05 06:21:30 -04:00
|
|
|
if (key.width != null)
|
|
|
|
extraButton.setWidth(key.width);
|
|
|
|
|
2018-02-11 10:19:10 -05:00
|
|
|
let actor = extraButton.keyButton;
|
2018-01-23 10:45:46 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
extraButton.connect('pressed', () => {
|
2018-02-15 06:20:51 -05:00
|
|
|
if (switchToLevel != null) {
|
|
|
|
this._setActiveLayer(switchToLevel);
|
|
|
|
// Shift only gets latched on long press
|
|
|
|
this._latched = (switchToLevel != 1);
|
|
|
|
} else if (keyval != null) {
|
2018-02-14 06:39:27 -05:00
|
|
|
this._keyboardController.keyvalPress(keyval);
|
2018-02-15 06:20:51 -05:00
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
extraButton.connect('released', () => {
|
2018-02-15 06:20:51 -05:00
|
|
|
if (keyval != null)
|
2017-08-05 06:21:30 -04:00
|
|
|
this._keyboardController.keyvalRelease(keyval);
|
|
|
|
else if (action == 'hide')
|
|
|
|
this.hide();
|
2018-01-23 10:45:46 -05:00
|
|
|
else if (action == 'languageMenu')
|
|
|
|
this._popupLanguageMenu(actor);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-08-05 06:21:30 -04:00
|
|
|
|
2018-02-15 08:48:46 -05:00
|
|
|
if (switchToLevel == 0) {
|
|
|
|
layout.shiftKeys.push(extraButton);
|
|
|
|
} else if (switchToLevel == 1) {
|
2017-10-30 20:38:18 -04:00
|
|
|
extraButton.connect('long-press', () => {
|
2018-02-15 06:20:51 -05:00
|
|
|
this._latched = true;
|
2018-02-15 08:48:46 -05:00
|
|
|
this._setCurrentLevelLatched(this._current_page, this._latched);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2018-02-15 06:20:51 -05:00
|
|
|
}
|
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
/* Fixup default keys based on the number of levels/keys */
|
2018-02-15 07:23:54 -05:00
|
|
|
if (switchToLevel == 1 && numLevels == 3) {
|
|
|
|
// Hide shift key if the keymap has no uppercase level
|
2017-08-05 06:21:30 -04:00
|
|
|
if (key.right) {
|
|
|
|
/* Only hide the key actor, so the container still takes space */
|
2018-02-11 10:19:10 -05:00
|
|
|
extraButton.keyButton.hide();
|
2017-08-05 06:21:30 -04:00
|
|
|
} else {
|
2018-02-11 10:19:10 -05:00
|
|
|
extraButton.actor.hide();
|
2017-08-05 06:21:30 -04:00
|
|
|
}
|
|
|
|
extraButton.setWidth(1.5);
|
|
|
|
} else if (key.right && numKeys > 8) {
|
|
|
|
extraButton.setWidth(2);
|
2018-02-15 07:23:54 -05:00
|
|
|
} else if (keyval == Clutter.KEY_Return && numKeys > 9) {
|
2017-08-05 06:21:30 -04:00
|
|
|
extraButton.setWidth(1.5);
|
2011-08-29 11:11:22 -04:00
|
|
|
}
|
2017-12-20 07:08:50 -05:00
|
|
|
|
2018-02-11 10:19:10 -05:00
|
|
|
layout.appendKey(extraButton.actor, extraButton.keyButton.keyWidth);
|
2011-08-29 11:11:22 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setCurrentLevelLatched(layout, latched) {
|
2018-02-15 08:48:46 -05:00
|
|
|
for (let i = 0; layout.shiftKeys[i]; i++) {
|
|
|
|
let key = layout.shiftKeys[i];
|
|
|
|
key.setLatched(latched);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getDefaultKeysForRow(row, numRows, level) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let pre, post;
|
|
|
|
|
|
|
|
/* The first 2 rows in defaultKeysPre/Post belong together with
|
|
|
|
* the first 2 rows on each keymap. On keymaps that have more than
|
|
|
|
* 4 rows, the last 2 default key rows must be respectively
|
|
|
|
* assigned to the 2 last keymap ones.
|
|
|
|
*/
|
|
|
|
if (row < 2) {
|
|
|
|
return [defaultKeysPre[level][row], defaultKeysPost[level][row]];
|
|
|
|
} else if (row >= numRows - 2) {
|
|
|
|
let defaultRow = row - (numRows - 2) + 2;
|
|
|
|
return [defaultKeysPre[level][defaultRow], defaultKeysPost[level][defaultRow]];
|
|
|
|
} else {
|
|
|
|
return [null, null];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_mergeRowKeys(layout, pre, row, post, numLevels) {
|
2017-08-05 06:21:30 -04:00
|
|
|
if (pre != null)
|
2017-12-20 07:08:50 -05:00
|
|
|
this._loadDefaultKeys(pre, layout, numLevels, row.length);
|
2017-08-05 06:21:30 -04:00
|
|
|
|
2017-12-20 07:08:50 -05:00
|
|
|
this._addRowKeys(row, layout);
|
2017-08-05 06:21:30 -04:00
|
|
|
|
|
|
|
if (post != null)
|
2017-12-20 07:08:50 -05:00
|
|
|
this._loadDefaultKeys(post, layout, numLevels, row.length);
|
2017-08-05 06:21:30 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_loadRows(model, level, numLevels, layout) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let rows = model.rows;
|
2011-08-29 11:11:22 -04:00
|
|
|
for (let i = 0; i < rows.length; ++i) {
|
2017-12-20 07:08:50 -05:00
|
|
|
layout.appendRow();
|
2017-08-05 06:21:30 -04:00
|
|
|
let [pre, post] = this._getDefaultKeysForRow(i, rows.length, level);
|
2017-12-20 07:08:50 -05:00
|
|
|
this._mergeRowKeys (layout, pre, rows[i], post, numLevels);
|
2017-12-05 16:41:32 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getGridSlots() {
|
2017-12-05 16:41:32 -05:00
|
|
|
let numOfHorizSlots = 0, numOfVertSlots;
|
|
|
|
let rows = this._current_page.get_children();
|
|
|
|
numOfVertSlots = rows.length;
|
2017-08-05 06:21:30 -04:00
|
|
|
|
2017-12-05 16:41:32 -05:00
|
|
|
for (let i = 0; i < rows.length; ++i) {
|
|
|
|
let keyboard_row = rows[i];
|
|
|
|
let keys = keyboard_row.get_children();
|
|
|
|
|
|
|
|
numOfHorizSlots = Math.max(numOfHorizSlots, keys.length);
|
2011-08-29 11:11:22 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:41:32 -05:00
|
|
|
return [numOfHorizSlots, numOfVertSlots];
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_relayout() {
|
2017-12-20 07:08:50 -05:00
|
|
|
if (this.actor == null)
|
2011-09-01 11:01:48 -04:00
|
|
|
return;
|
2012-10-14 12:57:45 -04:00
|
|
|
let monitor = Main.layoutManager.keyboardMonitor;
|
2011-08-29 11:11:22 -04:00
|
|
|
let maxHeight = monitor.height / 3;
|
|
|
|
this.actor.width = monitor.width;
|
2017-12-20 07:08:50 -05:00
|
|
|
this.actor.height = maxHeight;
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onGroupChanged() {
|
2018-01-23 11:03:02 -05:00
|
|
|
this._ensureKeysForGroup(this._keyboardController.getCurrentGroup());
|
2017-08-05 06:21:30 -04:00
|
|
|
this._setActiveLayer(0);
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onKeyboardGroupsChanged(keyboard) {
|
2017-08-05 06:21:30 -04:00
|
|
|
this._groups = [];
|
2018-02-11 10:15:14 -05:00
|
|
|
this._onGroupChanged();
|
2013-02-17 22:01:04 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onKeyboardStateChanged(controller, state) {
|
2017-12-05 14:05:18 -05:00
|
|
|
let enabled;
|
|
|
|
if (state == Clutter.InputPanelState.OFF)
|
|
|
|
enabled = false;
|
|
|
|
else if (state == Clutter.InputPanelState.ON)
|
|
|
|
enabled = true;
|
|
|
|
else if (state == Clutter.InputPanelState.TOGGLE)
|
|
|
|
enabled = (this._keyboardVisible == false);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
this.show(Main.layoutManager.focusIndex);
|
|
|
|
else
|
|
|
|
this.hide();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setActiveLayer(activeLevel) {
|
2017-08-05 06:21:30 -04:00
|
|
|
let activeGroupName = this._keyboardController.getCurrentGroup();
|
|
|
|
let layers = this._groups[activeGroupName];
|
2011-08-29 11:11:22 -04:00
|
|
|
|
|
|
|
if (this._current_page != null) {
|
2018-02-15 08:48:46 -05:00
|
|
|
this._setCurrentLevelLatched(this._current_page, false);
|
2011-08-29 11:11:22 -04:00
|
|
|
this._current_page.hide();
|
|
|
|
}
|
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
this._current_page = layers[activeLevel];
|
2011-08-29 11:11:22 -04:00
|
|
|
this._current_page.show();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
shouldTakeEvent(event) {
|
2012-09-21 10:58:03 -04:00
|
|
|
let actor = event.get_source();
|
|
|
|
return Main.layoutManager.keyboardBox.contains(actor) ||
|
2017-06-13 00:49:07 -04:00
|
|
|
!!actor._extended_keys || !!actor.extended_key;
|
2012-09-21 10:58:03 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_clearKeyboardRestTimer() {
|
2012-11-18 10:17:21 -05:00
|
|
|
if (!this._keyboardRestingId)
|
|
|
|
return;
|
|
|
|
GLib.source_remove(this._keyboardRestingId);
|
|
|
|
this._keyboardRestingId = 0;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
show(monitor) {
|
2017-10-09 06:51:08 -04:00
|
|
|
if (!this._enabled)
|
2017-01-16 10:36:21 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
this._clearShowIdle();
|
2012-11-18 10:17:21 -05:00
|
|
|
this._keyboardRequested = true;
|
|
|
|
|
|
|
|
if (this._keyboardVisible) {
|
|
|
|
if (monitor != Main.layoutManager.keyboardIndex) {
|
|
|
|
Main.layoutManager.keyboardIndex = monitor;
|
2017-12-20 07:08:50 -05:00
|
|
|
this._relayout();
|
2012-11-18 10:17:21 -05:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._clearKeyboardRestTimer();
|
|
|
|
this._keyboardRestingId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
|
|
|
KEYBOARD_REST_TIME,
|
2017-10-30 20:38:18 -04:00
|
|
|
() => {
|
2012-11-18 10:17:21 -05:00
|
|
|
this._clearKeyboardRestTimer();
|
|
|
|
this._show(monitor);
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(this._keyboardRestingId, '[gnome-shell] this._clearKeyboardRestTimer');
|
2012-11-18 10:17:21 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_show(monitor) {
|
2012-11-18 10:17:21 -05:00
|
|
|
if (!this._keyboardRequested)
|
|
|
|
return;
|
|
|
|
|
2017-10-11 03:58:58 -04:00
|
|
|
if (this._currentAccessible)
|
|
|
|
this._updateCaretPosition(this._currentAccessible);
|
2012-10-14 12:57:45 -04:00
|
|
|
Main.layoutManager.keyboardIndex = monitor;
|
2017-12-20 07:08:50 -05:00
|
|
|
this._relayout();
|
2011-08-29 11:11:22 -04:00
|
|
|
Main.layoutManager.showKeyboard();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
hide() {
|
2017-10-09 06:51:08 -04:00
|
|
|
if (!this._enabled)
|
2017-01-16 10:36:21 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
this._clearShowIdle();
|
2012-11-18 10:17:21 -05:00
|
|
|
this._keyboardRequested = false;
|
|
|
|
|
|
|
|
if (!this._keyboardVisible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._clearKeyboardRestTimer();
|
|
|
|
this._keyboardRestingId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
|
|
|
KEYBOARD_REST_TIME,
|
2017-10-30 20:38:18 -04:00
|
|
|
() => {
|
2012-11-18 10:17:21 -05:00
|
|
|
this._clearKeyboardRestTimer();
|
|
|
|
this._hide();
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(this._keyboardRestingId, '[gnome-shell] this._clearKeyboardRestTimer');
|
2012-11-18 10:17:21 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_hide() {
|
2012-11-18 10:17:21 -05:00
|
|
|
if (this._keyboardRequested)
|
|
|
|
return;
|
|
|
|
|
2011-08-29 11:11:22 -04:00
|
|
|
Main.layoutManager.hideKeyboard();
|
2017-10-11 03:58:58 -04:00
|
|
|
this.setCursorLocation(null);
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_hideSubkeys() {
|
2012-11-10 16:47:57 -05:00
|
|
|
if (this._subkeysBoxPointer) {
|
|
|
|
this._subkeysBoxPointer.hide(BoxPointer.PopupAnimation.FULL);
|
|
|
|
this._subkeysBoxPointer = null;
|
|
|
|
}
|
|
|
|
if (this._capturedEventId) {
|
|
|
|
this.actor.disconnect(this._capturedEventId);
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
}
|
|
|
|
this._capturedPress = false;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
resetSuggestions() {
|
2017-12-06 07:46:02 -05:00
|
|
|
if (this._suggestions)
|
|
|
|
this._suggestions.clear();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addSuggestion(text, callback) {
|
2017-12-06 07:46:02 -05:00
|
|
|
if (!this._suggestions)
|
|
|
|
return;
|
|
|
|
this._suggestions.add(text, callback);
|
|
|
|
this._suggestions.actor.show();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_clearShowIdle() {
|
2012-10-30 11:46:18 -04:00
|
|
|
if (!this._showIdleId)
|
|
|
|
return;
|
|
|
|
GLib.source_remove(this._showIdleId);
|
|
|
|
this._showIdleId = 0;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_windowSlideAnimationComplete(window, delta) {
|
2017-10-11 03:58:58 -04:00
|
|
|
// Synchronize window and actor positions again.
|
|
|
|
let windowActor = window.get_compositor_private();
|
|
|
|
let frameRect = window.get_frame_rect();
|
|
|
|
frameRect.y += delta;
|
|
|
|
window.move_frame(true, frameRect.x, frameRect.y);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_animateWindow(window, show, deltaY) {
|
2017-10-11 03:58:58 -04:00
|
|
|
let windowActor = window.get_compositor_private();
|
|
|
|
if (!windowActor)
|
2011-09-27 14:55:38 -04:00
|
|
|
return;
|
|
|
|
|
2017-10-11 03:58:58 -04:00
|
|
|
if (show) {
|
|
|
|
Tweener.addTween(windowActor,
|
|
|
|
{ y: windowActor.y - deltaY,
|
|
|
|
time: Layout.KEYBOARD_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: this._windowSlideAnimationComplete,
|
|
|
|
onCompleteParams: [window, -deltaY] });
|
|
|
|
} else {
|
|
|
|
Tweener.addTween(windowActor,
|
|
|
|
{ y: windowActor.y + deltaY,
|
|
|
|
time: Layout.KEYBOARD_ANIMATION_TIME,
|
|
|
|
transition: 'easeInQuad',
|
|
|
|
onComplete: this._windowSlideAnimationComplete,
|
|
|
|
onCompleteParams: [window, deltaY] });
|
|
|
|
}
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setCursorLocation(window, x, y , w, h) {
|
2017-10-11 03:58:58 -04:00
|
|
|
if (window == this._oskFocusWindow)
|
2011-09-27 14:55:38 -04:00
|
|
|
return;
|
|
|
|
|
2017-10-11 03:58:58 -04:00
|
|
|
if (this._oskFocusWindow) {
|
|
|
|
let display = global.screen.get_display();
|
|
|
|
|
|
|
|
if (display.get_grab_op() == Meta.GrabOp.NONE ||
|
|
|
|
display.get_focus_window() != this._oskFocusWindow)
|
|
|
|
this._animateWindow(this._oskFocusWindow, false, this._oskFocusWindowDelta);
|
|
|
|
|
|
|
|
this._oskFocusWindow = null;
|
|
|
|
this._oskFocusWindowDelta = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window) {
|
|
|
|
let monitor = Main.layoutManager.keyboardMonitor;
|
|
|
|
let keyboardHeight = Main.layoutManager.keyboardBox.height;
|
|
|
|
let frameRect = window.get_frame_rect();
|
|
|
|
let windowActor = window.get_compositor_private();
|
|
|
|
let delta = 0;
|
|
|
|
|
|
|
|
if (frameRect.y + y + h >= monitor.height - keyboardHeight)
|
|
|
|
delta = keyboardHeight;
|
|
|
|
|
|
|
|
this._animateWindow(window, true, delta);
|
|
|
|
this._oskFocusWindow = window;
|
|
|
|
this._oskFocusWindowDelta = delta;
|
|
|
|
}
|
2011-08-29 11:11:22 -04:00
|
|
|
},
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-08-29 11:11:22 -04:00
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
var KeyboardController = new Lang.Class({
|
|
|
|
Name: 'KeyboardController',
|
2015-04-02 18:18:07 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2016-07-20 11:50:55 -04:00
|
|
|
this.parent();
|
|
|
|
let deviceManager = Clutter.DeviceManager.get_default();
|
|
|
|
this._virtualDevice = deviceManager.create_virtual_device(Clutter.InputDeviceType.KEYBOARD_DEVICE);
|
|
|
|
|
|
|
|
this._inputSourceManager = InputSourceManager.getInputSourceManager();
|
|
|
|
this._sourceChangedId = this._inputSourceManager.connect('current-source-changed',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onSourceChanged.bind(this));
|
2016-07-20 11:50:55 -04:00
|
|
|
this._sourcesModifiedId = this._inputSourceManager.connect ('sources-changed',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onSourcesModified.bind(this));
|
2017-08-05 06:21:30 -04:00
|
|
|
this._currentSource = this._inputSourceManager.currentSource;
|
2017-12-05 14:05:18 -05:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
Main.inputMethod.connect('notify::content-purpose',
|
|
|
|
this._onContentPurposeHintsChanged.bind(this));
|
|
|
|
Main.inputMethod.connect('notify::content-hints',
|
|
|
|
this._onContentPurposeHintsChanged.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
Main.inputMethod.connect('input-panel-state', (o, state) => {
|
|
|
|
this.emit('panel-state', state);
|
|
|
|
});
|
2016-07-20 11:50:55 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onSourcesModified() {
|
2017-08-05 06:21:30 -04:00
|
|
|
this.emit('groups-changed');
|
2016-07-20 11:50:55 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onSourceChanged(inputSourceManager, oldSource) {
|
2016-07-20 11:50:55 -04:00
|
|
|
let source = inputSourceManager.currentSource;
|
2017-08-05 06:21:30 -04:00
|
|
|
this._currentSource = source;
|
|
|
|
this.emit('active-group', source.id);
|
2016-07-20 11:50:55 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onContentPurposeHintsChanged(method) {
|
2017-12-05 14:05:18 -05:00
|
|
|
let hints = method.content_hints;
|
|
|
|
let purpose = method.content_purpose;
|
|
|
|
|
|
|
|
// XXX: hook numeric/emoji/etc special keyboards
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getGroups() {
|
2016-07-20 11:50:55 -04:00
|
|
|
let inputSources = this._inputSourceManager.inputSources;
|
|
|
|
let groups = []
|
|
|
|
|
|
|
|
for (let i in inputSources) {
|
|
|
|
let is = inputSources[i];
|
2017-08-05 06:21:30 -04:00
|
|
|
groups[is.index] = is.xkbId;
|
2016-07-20 11:50:55 -04:00
|
|
|
}
|
|
|
|
|
2017-08-05 06:21:30 -04:00
|
|
|
return groups;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getCurrentGroup() {
|
2017-08-05 06:21:30 -04:00
|
|
|
return this._currentSource.xkbId;
|
2016-07-20 11:50:55 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
commitString(string, fromKey) {
|
2017-12-05 14:05:18 -05:00
|
|
|
if (string == null)
|
|
|
|
return false;
|
|
|
|
/* Let ibus methods fall through keyval emission */
|
|
|
|
if (fromKey && this._currentSource.type == InputSourceManager.INPUT_SOURCE_TYPE_IBUS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Main.inputMethod.commit(string);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
keyvalPress(keyval) {
|
2016-07-20 11:50:55 -04:00
|
|
|
this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
|
|
|
|
keyval, Clutter.KeyState.PRESSED);
|
2015-04-02 18:18:07 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
keyvalRelease(keyval) {
|
2016-07-20 11:50:55 -04:00
|
|
|
this._virtualDevice.notify_keyval(Clutter.get_current_event_time(),
|
|
|
|
keyval, Clutter.KeyState.RELEASED);
|
2015-04-02 18:18:07 -04:00
|
|
|
},
|
|
|
|
});
|
2017-08-05 06:21:30 -04:00
|
|
|
Signals.addSignalMethods(KeyboardController.prototype);
|