2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-08-29 15:11:22 +00:00
|
|
|
|
|
|
|
const Caribou = imports.gi.Caribou;
|
|
|
|
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 16:49:56 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
2011-08-29 15:11:22 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2012-11-10 21:47:57 +00:00
|
|
|
const Signals = imports.signals;
|
2011-08-29 15:11:22 +00:00
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2012-11-18 15:17:21 +00:00
|
|
|
const Layout = imports.ui.layout;
|
2011-08-29 15:11:22 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
|
|
|
|
2012-11-18 15:17:21 +00:00
|
|
|
const KEYBOARD_REST_TIME = Layout.KEYBOARD_ANIMATION_TIME * 2 * 1000;
|
|
|
|
|
2011-08-29 15:11:22 +00:00
|
|
|
const KEYBOARD_SCHEMA = 'org.gnome.shell.keyboard';
|
|
|
|
const KEYBOARD_TYPE = 'keyboard-type';
|
|
|
|
|
2011-08-29 17:02:42 +00:00
|
|
|
const A11Y_APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications';
|
|
|
|
const SHOW_KEYBOARD = 'screen-keyboard-enabled';
|
|
|
|
|
2013-07-23 15:23:10 +00:00
|
|
|
const CURSOR_BUS_NAME = 'org.gnome.SettingsDaemon.Cursor';
|
|
|
|
const CURSOR_OBJECT_PATH = '/org/gnome/SettingsDaemon/Cursor';
|
|
|
|
|
|
|
|
const CARIBOU_BUS_NAME = 'org.gnome.Caribou.Daemon';
|
|
|
|
const CARIBOU_OBJECT_PATH = '/org/gnome/Caribou/Daemon';
|
|
|
|
|
2013-10-24 21:51:58 +00:00
|
|
|
const CaribouKeyboardIface = '<node> \
|
|
|
|
<interface name="org.gnome.Caribou.Keyboard"> \
|
|
|
|
<method name="Show"> \
|
|
|
|
<arg type="u" direction="in" /> \
|
|
|
|
</method> \
|
|
|
|
<method name="Hide"> \
|
|
|
|
<arg type="u" direction="in" /> \
|
|
|
|
</method> \
|
|
|
|
<method name="SetCursorLocation"> \
|
|
|
|
<arg type="i" direction="in" /> \
|
|
|
|
<arg type="i" direction="in" /> \
|
|
|
|
<arg type="i" direction="in" /> \
|
|
|
|
<arg type="i" direction="in" /> \
|
|
|
|
</method> \
|
|
|
|
<method name="SetEntryLocation"> \
|
|
|
|
<arg type="i" direction="in" /> \
|
|
|
|
<arg type="i" direction="in" /> \
|
|
|
|
<arg type="i" direction="in" /> \
|
|
|
|
<arg type="i" direction="in" /> \
|
|
|
|
</method> \
|
|
|
|
<property name="Name" access="read" type="s" /> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
2011-08-29 15:11:22 +00:00
|
|
|
|
2013-07-23 15:23:10 +00:00
|
|
|
const CaribouDaemonIface = '<node> \
|
|
|
|
<interface name="org.gnome.Caribou.Daemon"> \
|
|
|
|
<method name="Run" /> \
|
|
|
|
<method name="Quit" /> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
|
|
|
|
|
|
|
const CaribouDaemonProxy = Gio.DBusProxy.makeProxyWrapper(CaribouDaemonIface);
|
|
|
|
|
2011-11-20 17:56:27 +00:00
|
|
|
const Key = new Lang.Class({
|
|
|
|
Name: 'Key',
|
2011-08-29 15:11:22 +00:00
|
|
|
|
|
|
|
_init : function(key) {
|
|
|
|
this._key = key;
|
2014-07-22 10:38:44 +00:00
|
|
|
this.actor = this._makeKey(key, GLib.markup_escape_text(key.label, -1));
|
2014-09-20 00:44:45 +00:00
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
2011-08-29 15:11:22 +00:00
|
|
|
|
|
|
|
this._extended_keys = this._key.get_extended_keys();
|
|
|
|
this._extended_keyboard = null;
|
|
|
|
|
2011-09-30 21:30:47 +00:00
|
|
|
if (this._key.name == 'Control_L' || this._key.name == 'Alt_L')
|
2011-08-29 15:11:22 +00:00
|
|
|
this._key.latch = true;
|
|
|
|
|
|
|
|
if (this._extended_keys.length > 0) {
|
|
|
|
this._key.connect('notify::show-subkeys', Lang.bind(this, this._onShowSubkeysChanged));
|
|
|
|
this._boxPointer = new BoxPointer.BoxPointer(St.Side.BOTTOM,
|
|
|
|
{ x_fill: true,
|
|
|
|
y_fill: true,
|
|
|
|
x_align: St.Align.START });
|
|
|
|
// Adds style to existing keyboard style to avoid repetition
|
|
|
|
this._boxPointer.actor.add_style_class_name('keyboard-subkeys');
|
|
|
|
this._getExtendedKeys();
|
|
|
|
this.actor._extended_keys = this._extended_keyboard;
|
|
|
|
this._boxPointer.actor.hide();
|
2012-05-22 20:16:31 +00:00
|
|
|
Main.layoutManager.addChrome(this._boxPointer.actor);
|
2011-08-29 15:11:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-09-20 00:44:45 +00:00
|
|
|
_onDestroy: function() {
|
|
|
|
if (this._boxPointer) {
|
|
|
|
this._boxPointer.actor.destroy();
|
|
|
|
this._boxPointer = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-07-22 10:38:44 +00:00
|
|
|
_makeKey: function (key, label) {
|
2011-08-29 15:11:22 +00:00
|
|
|
let button = new St.Button ({ label: label,
|
|
|
|
style_class: 'keyboard-key' });
|
|
|
|
|
|
|
|
button.key_width = this._key.width;
|
2013-11-29 18:17:34 +00:00
|
|
|
button.connect('button-press-event', Lang.bind(this,
|
|
|
|
function () {
|
2014-07-22 10:38:44 +00:00
|
|
|
key.press();
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}));
|
|
|
|
button.connect('button-release-event', Lang.bind(this,
|
|
|
|
function () {
|
2014-07-22 10:38:44 +00:00
|
|
|
key.release();
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}));
|
2011-08-29 15:11:22 +00:00
|
|
|
|
|
|
|
return button;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getUnichar: function(key) {
|
|
|
|
let keyval = key.keyval;
|
|
|
|
let unichar = Gdk.keyval_to_unicode(keyval);
|
|
|
|
if (unichar) {
|
|
|
|
return String.fromCharCode(unichar);
|
|
|
|
} else {
|
|
|
|
return key.name;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getExtendedKeys: function () {
|
|
|
|
this._extended_keyboard = new St.BoxLayout({ style_class: 'keyboard-layout',
|
|
|
|
vertical: false });
|
|
|
|
for (let i = 0; i < this._extended_keys.length; ++i) {
|
|
|
|
let extended_key = this._extended_keys[i];
|
|
|
|
let label = this._getUnichar(extended_key);
|
2014-07-22 10:38:44 +00:00
|
|
|
let key = this._makeKey(extended_key, label);
|
|
|
|
|
2011-08-29 15:11:22 +00:00
|
|
|
key.extended_key = extended_key;
|
|
|
|
this._extended_keyboard.add(key);
|
|
|
|
}
|
|
|
|
this._boxPointer.bin.add_actor(this._extended_keyboard);
|
|
|
|
},
|
|
|
|
|
2012-11-10 21:47:57 +00:00
|
|
|
get subkeys() {
|
|
|
|
return this._boxPointer;
|
2011-08-29 15:11:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onShowSubkeysChanged: function () {
|
|
|
|
if (this._key.show_subkeys) {
|
|
|
|
this._boxPointer.actor.raise_top();
|
|
|
|
this._boxPointer.setPosition(this.actor, 0.5);
|
2012-11-10 21:47:57 +00:00
|
|
|
this.emit('show-subkeys');
|
|
|
|
this.actor.fake_release();
|
2011-08-29 15:11:22 +00:00
|
|
|
this.actor.set_hover(false);
|
|
|
|
} else {
|
2012-11-10 21:47:57 +00:00
|
|
|
this.emit('hide-subkeys');
|
2011-08-29 15:11:22 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2012-11-10 21:47:57 +00:00
|
|
|
Signals.addSignalMethods(Key.prototype);
|
2011-08-29 15:11:22 +00:00
|
|
|
|
2011-11-20 17:56:27 +00:00
|
|
|
const Keyboard = new Lang.Class({
|
|
|
|
// HACK: we can't set Name, because it collides with Name dbus property
|
|
|
|
// Name: 'Keyboard',
|
2011-08-29 15:11:22 +00:00
|
|
|
|
|
|
|
_init: function () {
|
2011-11-20 16:52:50 +00:00
|
|
|
this._impl = Gio.DBusExportedObject.wrapJSObject(CaribouKeyboardIface, this);
|
|
|
|
this._impl.export(Gio.DBus.session, '/org/gnome/Caribou/Keyboard');
|
2011-08-29 15:11:22 +00:00
|
|
|
|
2011-09-01 15:01:48 +00:00
|
|
|
this.actor = null;
|
2012-09-24 15:02:13 +00:00
|
|
|
this._focusInTray = false;
|
2012-09-24 18:03:53 +00:00
|
|
|
this._focusInExtendedKeys = false;
|
2011-09-01 15:01:48 +00:00
|
|
|
|
2012-07-20 13:59:53 +00:00
|
|
|
this._timestamp = global.display.get_current_time_roundtrip();
|
2011-08-29 15:11:22 +00:00
|
|
|
|
2014-06-24 19:17:09 +00:00
|
|
|
this._keyboardSettings = new Gio.Settings({ schema_id: KEYBOARD_SCHEMA });
|
2013-07-23 15:23:10 +00:00
|
|
|
this._keyboardSettings.connect('changed', Lang.bind(this, this._sync));
|
2014-06-24 19:17:09 +00:00
|
|
|
this._a11yApplicationsSettings = new Gio.Settings({ schema_id: A11Y_APPLICATIONS_SCHEMA });
|
2013-07-23 15:23:10 +00:00
|
|
|
this._a11yApplicationsSettings.connect('changed', Lang.bind(this, this._sync));
|
|
|
|
this._watchNameId = Gio.bus_watch_name(Gio.BusType.SESSION, CURSOR_BUS_NAME, 0,
|
|
|
|
Lang.bind(this, this._sync),
|
|
|
|
Lang.bind(this, this._sync));
|
2014-11-06 07:40:34 +00:00
|
|
|
this._daemonProxy = null;
|
2015-03-10 16:49:56 +00:00
|
|
|
this._lastDeviceId = null;
|
|
|
|
|
2015-04-02 22:18:07 +00:00
|
|
|
if (Meta.is_wayland_compositor() &&
|
|
|
|
Caribou.DisplayAdapter.set_default)
|
|
|
|
Caribou.DisplayAdapter.set_default(new ShellWaylandAdapter());
|
|
|
|
|
2015-03-10 16:49:56 +00:00
|
|
|
Meta.get_backend().connect('last-device-changed', Lang.bind(this,
|
|
|
|
function (backend, deviceId) {
|
|
|
|
let manager = Clutter.DeviceManager.get_default();
|
|
|
|
let device = manager.get_device(deviceId);
|
|
|
|
|
|
|
|
if (device.get_device_name().indexOf('XTEST') < 0) {
|
|
|
|
this._lastDeviceId = deviceId;
|
|
|
|
this._sync();
|
|
|
|
}
|
|
|
|
}));
|
2013-07-23 15:23:10 +00:00
|
|
|
this._sync();
|
2012-10-30 15:46:18 +00:00
|
|
|
|
|
|
|
this._showIdleId = 0;
|
2012-11-10 21:47:57 +00:00
|
|
|
this._subkeysBoxPointer = null;
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
this._capturedPress = false;
|
2012-11-18 15:17:21 +00:00
|
|
|
|
|
|
|
this._keyboardVisible = false;
|
|
|
|
Main.layoutManager.connect('keyboard-visible-changed', Lang.bind(this, function(o, visible) {
|
|
|
|
this._keyboardVisible = visible;
|
|
|
|
}));
|
|
|
|
this._keyboardRequested = false;
|
|
|
|
this._keyboardRestingId = 0;
|
2011-08-29 15:11:22 +00:00
|
|
|
|
2013-01-28 06:52:37 +00:00
|
|
|
Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._redraw));
|
2011-09-01 15:01:48 +00:00
|
|
|
this._redraw();
|
2011-08-29 15:11:22 +00:00
|
|
|
},
|
|
|
|
|
2015-03-10 16:49:56 +00:00
|
|
|
_lastDeviceIsTouchscreen: function () {
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2013-07-23 15:23:10 +00:00
|
|
|
_sync: function () {
|
|
|
|
this._enableKeyboard = this._a11yApplicationsSettings.get_boolean(SHOW_KEYBOARD) ||
|
2015-03-10 16:49:56 +00:00
|
|
|
this._lastDeviceIsTouchscreen();
|
2011-08-29 15:11:22 +00:00
|
|
|
if (!this._enableKeyboard && !this._keyboard)
|
|
|
|
return;
|
|
|
|
if (this._enableKeyboard && this._keyboard &&
|
|
|
|
this._keyboard.keyboard_type == this._keyboardSettings.get_string(KEYBOARD_TYPE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._keyboard)
|
|
|
|
this._destroyKeyboard();
|
2011-09-27 19:11:12 +00:00
|
|
|
|
2013-01-31 22:40:51 +00:00
|
|
|
if (this._enableKeyboard)
|
|
|
|
this._setupKeyboard();
|
|
|
|
else
|
2011-08-29 15:11:22 +00:00
|
|
|
Main.layoutManager.hideKeyboard(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
_destroyKeyboard: function() {
|
|
|
|
if (this._keyboardNotifyId)
|
|
|
|
this._keyboard.disconnect(this._keyboardNotifyId);
|
2013-02-18 03:01:04 +00:00
|
|
|
if (this._keyboardGroupAddedId)
|
|
|
|
this._keyboard.disconnect(this._keyboardGroupAddedId);
|
|
|
|
if (this._keyboardGroupRemovedId)
|
|
|
|
this._keyboard.disconnect(this._keyboardGroupRemovedId);
|
2011-08-29 15:11:22 +00:00
|
|
|
if (this._focusNotifyId)
|
|
|
|
global.stage.disconnect(this._focusNotifyId);
|
|
|
|
this._keyboard = null;
|
2011-09-01 15:01:48 +00:00
|
|
|
this.actor.destroy();
|
|
|
|
this.actor = null;
|
2011-08-29 15:11:22 +00:00
|
|
|
|
|
|
|
this._destroySource();
|
2014-11-06 07:40:34 +00:00
|
|
|
if (this._daemonProxy) {
|
|
|
|
this._daemonProxy.QuitRemote(function (result, error) {
|
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this._daemonProxy = null;
|
|
|
|
}
|
2011-08-29 15:11:22 +00:00
|
|
|
},
|
|
|
|
|
2013-01-31 22:40:51 +00:00
|
|
|
_setupKeyboard: function() {
|
2014-11-06 07:40:34 +00:00
|
|
|
if (!this._daemonProxy) {
|
|
|
|
this._daemonProxy = new CaribouDaemonProxy(Gio.DBus.session, CARIBOU_BUS_NAME,
|
|
|
|
CARIBOU_OBJECT_PATH,
|
|
|
|
Lang.bind(this, function(proxy, error) {
|
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2013-07-23 15:23:10 +00:00
|
|
|
this._daemonProxy.RunRemote(function (result, error) {
|
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-01 15:01:48 +00:00
|
|
|
this.actor = new St.BoxLayout({ name: 'keyboard', vertical: true, reactive: true });
|
|
|
|
Main.layoutManager.keyboardBox.add_actor(this.actor);
|
|
|
|
Main.layoutManager.trackChrome(this.actor);
|
|
|
|
|
2011-08-29 15:11:22 +00:00
|
|
|
this._keyboard = new Caribou.KeyboardModel({ keyboard_type: this._keyboardSettings.get_string(KEYBOARD_TYPE) });
|
|
|
|
this._groups = {};
|
|
|
|
this._current_page = null;
|
|
|
|
|
|
|
|
// Initialize keyboard key measurements
|
|
|
|
this._numOfHorizKeys = 0;
|
|
|
|
this._numOfVertKeys = 0;
|
|
|
|
|
|
|
|
this._addKeys();
|
|
|
|
|
2012-03-14 11:21:33 +00:00
|
|
|
// Keys should be layout according to the group, not the
|
|
|
|
// locale; as Caribou already provides the expected layout,
|
|
|
|
// this means enforcing LTR for all locales.
|
|
|
|
this.actor.text_direction = Clutter.TextDirection.LTR;
|
|
|
|
|
2011-08-29 15:11:22 +00:00
|
|
|
this._keyboardNotifyId = this._keyboard.connect('notify::active-group', Lang.bind(this, this._onGroupChanged));
|
2013-02-18 03:01:04 +00:00
|
|
|
this._keyboardGroupAddedId = this._keyboard.connect('group-added', Lang.bind(this, this._onGroupAdded));
|
|
|
|
this._keyboardGroupRemovedId = this._keyboard.connect('group-removed', Lang.bind(this, this._onGroupRemoved));
|
2011-08-29 15:11:22 +00:00
|
|
|
this._focusNotifyId = global.stage.connect('notify::key-focus', Lang.bind(this, this._onKeyFocusChanged));
|
2011-09-27 19:11:12 +00:00
|
|
|
|
2013-01-31 22:40:51 +00:00
|
|
|
this._createSource();
|
2011-08-29 15:11:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyFocusChanged: function () {
|
|
|
|
let focus = global.stage.key_focus;
|
|
|
|
|
2011-10-11 21:54:05 +00:00
|
|
|
// Showing an extended key popup and clicking a key from the extended keys
|
|
|
|
// will grab focus, but ignore that
|
2012-09-24 18:03:53 +00:00
|
|
|
let extendedKeysWereFocused = this._focusInExtendedKeys;
|
|
|
|
this._focusInExtendedKeys = focus && (focus._extended_keys || focus.extended_key);
|
|
|
|
if (this._focusInExtendedKeys || extendedKeysWereFocused)
|
2011-08-29 15:11:22 +00:00
|
|
|
return;
|
|
|
|
|
2012-09-24 15:02:13 +00:00
|
|
|
// Ignore focus changes caused by message tray showing/hiding
|
|
|
|
let trayWasFocused = this._focusInTray;
|
|
|
|
this._focusInTray = (focus && Main.messageTray.actor.contains(focus));
|
|
|
|
if (this._focusInTray || trayWasFocused)
|
|
|
|
return;
|
|
|
|
|
2011-11-04 00:22:00 +00:00
|
|
|
let time = global.get_current_time();
|
2012-10-30 15:46:18 +00:00
|
|
|
if (!(focus instanceof Clutter.Text)) {
|
2011-09-27 19:11:12 +00:00
|
|
|
this.Hide(time);
|
2012-10-30 15:46:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-10 17:26:52 +00:00
|
|
|
if (!this._showIdleId) {
|
|
|
|
this._showIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE,
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this.Show(time);
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
}));
|
|
|
|
GLib.Source.set_name_by_id(this._showIdleId, '[gnome-shell] this.Show');
|
|
|
|
}
|
2011-08-29 15:11:22 +00:00
|
|
|
},
|
|
|
|
|
2013-02-18 03:01:04 +00:00
|
|
|
_createLayersForGroup: function (gname) {
|
|
|
|
let group = this._keyboard.get_group(gname);
|
|
|
|
group.connect('notify::active-level', Lang.bind(this, this._onLevelChanged));
|
|
|
|
let layers = {};
|
|
|
|
let levels = group.get_levels();
|
|
|
|
for (let j = 0; j < levels.length; ++j) {
|
|
|
|
let lname = levels[j];
|
|
|
|
let level = group.get_level(lname);
|
|
|
|
let layout = new St.BoxLayout({ style_class: 'keyboard-layout',
|
|
|
|
vertical: true });
|
|
|
|
this._loadRows(level, layout);
|
|
|
|
layers[lname] = layout;
|
|
|
|
this.actor.add(layout, { x_fill: false });
|
|
|
|
|
|
|
|
layout.hide();
|
|
|
|
}
|
|
|
|
return layers;
|
|
|
|
},
|
|
|
|
|
2011-08-29 15:11:22 +00:00
|
|
|
_addKeys: function () {
|
|
|
|
let groups = this._keyboard.get_groups();
|
|
|
|
for (let i = 0; i < groups.length; ++i) {
|
|
|
|
let gname = groups[i];
|
2013-02-18 03:01:04 +00:00
|
|
|
this._groups[gname] = this._createLayersForGroup(gname);
|
2011-08-29 15:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._setActiveLayer();
|
|
|
|
},
|
|
|
|
|
2012-11-10 21:47:57 +00:00
|
|
|
_onCapturedEvent: function(actor, event) {
|
|
|
|
let type = event.type();
|
|
|
|
let press = type == Clutter.EventType.BUTTON_PRESS;
|
|
|
|
let release = type == Clutter.EventType.BUTTON_RELEASE;
|
|
|
|
|
|
|
|
if (press)
|
|
|
|
this._capturedPress = true;
|
|
|
|
else if (release && this._capturedPress)
|
|
|
|
this._hideSubkeys();
|
|
|
|
|
2013-11-29 18:17:34 +00:00
|
|
|
return Clutter.EVENT_STOP;
|
2012-11-10 21:47:57 +00:00
|
|
|
},
|
|
|
|
|
2011-08-29 15:11:22 +00:00
|
|
|
_addRows : function (keys, layout) {
|
|
|
|
let keyboard_row = new St.BoxLayout();
|
|
|
|
for (let i = 0; i < keys.length; ++i) {
|
|
|
|
let children = keys[i].get_children();
|
|
|
|
let left_box = new St.BoxLayout({ style_class: 'keyboard-row' });
|
2012-08-20 03:22:37 +00:00
|
|
|
let center_box = new St.BoxLayout({ style_class: 'keyboard-row' });
|
|
|
|
let right_box = new St.BoxLayout({ style_class: 'keyboard-row' });
|
2011-08-29 15:11:22 +00:00
|
|
|
for (let j = 0; j < children.length; ++j) {
|
|
|
|
if (this._numOfHorizKeys == 0)
|
|
|
|
this._numOfHorizKeys = children.length;
|
|
|
|
let key = children[j];
|
|
|
|
let button = new Key(key);
|
|
|
|
|
2012-08-20 03:22:37 +00:00
|
|
|
switch (key.align) {
|
|
|
|
case 'right':
|
2011-08-29 15:11:22 +00:00
|
|
|
right_box.add(button.actor);
|
2012-08-20 03:22:37 +00:00
|
|
|
break;
|
|
|
|
case 'center':
|
|
|
|
center_box.add(button.actor);
|
|
|
|
break;
|
|
|
|
case 'left':
|
|
|
|
default:
|
2011-08-29 15:11:22 +00:00
|
|
|
left_box.add(button.actor);
|
2012-08-20 03:22:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-09-30 21:30:47 +00:00
|
|
|
if (key.name == 'Caribou_Prefs') {
|
2011-08-29 15:11:22 +00:00
|
|
|
key.connect('key-released', Lang.bind(this, this.hide));
|
|
|
|
}
|
2012-11-10 21:47:57 +00:00
|
|
|
|
|
|
|
button.connect('show-subkeys', Lang.bind(this, function() {
|
|
|
|
if (this._subkeysBoxPointer)
|
|
|
|
this._subkeysBoxPointer.hide(BoxPointer.PopupAnimation.FULL);
|
|
|
|
this._subkeysBoxPointer = button.subkeys;
|
|
|
|
this._subkeysBoxPointer.show(BoxPointer.PopupAnimation.FULL);
|
|
|
|
if (!this._capturedEventId)
|
|
|
|
this._capturedEventId = this.actor.connect('captured-event',
|
|
|
|
Lang.bind(this, this._onCapturedEvent));
|
|
|
|
}));
|
|
|
|
button.connect('hide-subkeys', Lang.bind(this, function() {
|
|
|
|
this._hideSubkeys();
|
|
|
|
}));
|
2011-08-29 15:11:22 +00:00
|
|
|
}
|
|
|
|
keyboard_row.add(left_box, { expand: true, x_fill: false, x_align: St.Align.START });
|
2012-08-20 03:22:37 +00:00
|
|
|
keyboard_row.add(center_box, { expand: true, x_fill: false, x_align: St.Align.MIDDLE });
|
2011-08-29 15:11:22 +00:00
|
|
|
keyboard_row.add(right_box, { expand: true, x_fill: false, x_align: St.Align.END });
|
|
|
|
}
|
|
|
|
layout.add(keyboard_row);
|
|
|
|
},
|
|
|
|
|
|
|
|
_loadRows : function (level, layout) {
|
|
|
|
let rows = level.get_rows();
|
|
|
|
for (let i = 0; i < rows.length; ++i) {
|
|
|
|
let row = rows[i];
|
|
|
|
if (this._numOfVertKeys == 0)
|
|
|
|
this._numOfVertKeys = rows.length;
|
|
|
|
this._addRows(row.get_columns(), layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_redraw: function () {
|
2011-09-01 15:01:48 +00:00
|
|
|
if (!this._enableKeyboard)
|
|
|
|
return;
|
|
|
|
|
2012-10-14 16:57:45 +00:00
|
|
|
let monitor = Main.layoutManager.keyboardMonitor;
|
2011-08-29 15:11:22 +00:00
|
|
|
let maxHeight = monitor.height / 3;
|
|
|
|
this.actor.width = monitor.width;
|
|
|
|
|
|
|
|
let layout = this._current_page;
|
|
|
|
let verticalSpacing = layout.get_theme_node().get_length('spacing');
|
|
|
|
let padding = layout.get_theme_node().get_length('padding');
|
|
|
|
|
|
|
|
let box = layout.get_children()[0].get_children()[0];
|
|
|
|
let horizontalSpacing = box.get_theme_node().get_length('spacing');
|
|
|
|
let allHorizontalSpacing = (this._numOfHorizKeys - 1) * horizontalSpacing;
|
|
|
|
let keyWidth = Math.floor((this.actor.width - allHorizontalSpacing - 2 * padding) / this._numOfHorizKeys);
|
|
|
|
|
|
|
|
let allVerticalSpacing = (this._numOfVertKeys - 1) * verticalSpacing;
|
|
|
|
let keyHeight = Math.floor((maxHeight - allVerticalSpacing - 2 * padding) / this._numOfVertKeys);
|
|
|
|
|
|
|
|
let keySize = Math.min(keyWidth, keyHeight);
|
|
|
|
this.actor.height = keySize * this._numOfVertKeys + allVerticalSpacing + 2 * padding;
|
|
|
|
|
|
|
|
let rows = this._current_page.get_children();
|
|
|
|
for (let i = 0; i < rows.length; ++i) {
|
|
|
|
let keyboard_row = rows[i];
|
|
|
|
let boxes = keyboard_row.get_children();
|
|
|
|
for (let j = 0; j < boxes.length; ++j) {
|
|
|
|
let keys = boxes[j].get_children();
|
|
|
|
for (let k = 0; k < keys.length; ++k) {
|
|
|
|
let child = keys[k];
|
|
|
|
child.width = keySize * child.key_width;
|
|
|
|
child.height = keySize;
|
|
|
|
if (child._extended_keys) {
|
|
|
|
let extended_keys = child._extended_keys.get_children();
|
|
|
|
for (let n = 0; n < extended_keys.length; ++n) {
|
|
|
|
let extended_key = extended_keys[n];
|
|
|
|
extended_key.width = keySize;
|
|
|
|
extended_key.height = keySize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onLevelChanged: function () {
|
|
|
|
this._setActiveLayer();
|
|
|
|
this._redraw();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onGroupChanged: function () {
|
|
|
|
this._setActiveLayer();
|
|
|
|
this._redraw();
|
|
|
|
},
|
|
|
|
|
2013-02-18 03:01:04 +00:00
|
|
|
_onGroupAdded: function (keyboard, gname) {
|
2013-02-20 10:10:29 +00:00
|
|
|
this._groups[gname] = this._createLayersForGroup(gname);
|
2013-02-18 03:01:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onGroupRemoved: function (keyboard, gname) {
|
2013-02-20 10:10:29 +00:00
|
|
|
delete this._groups[gname];
|
2013-02-18 03:01:04 +00:00
|
|
|
},
|
|
|
|
|
2011-08-29 15:11:22 +00:00
|
|
|
_setActiveLayer: function () {
|
|
|
|
let active_group_name = this._keyboard.active_group;
|
|
|
|
let active_group = this._keyboard.get_group(active_group_name);
|
|
|
|
let active_level = active_group.active_level;
|
|
|
|
let layers = this._groups[active_group_name];
|
|
|
|
|
|
|
|
if (this._current_page != null) {
|
|
|
|
this._current_page.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._current_page = layers[active_level];
|
|
|
|
this._current_page.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
_createSource: function () {
|
|
|
|
if (this._source == null) {
|
|
|
|
this._source = new KeyboardSource(this);
|
|
|
|
Main.messageTray.add(this._source);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_destroySource: function () {
|
|
|
|
if (this._source) {
|
|
|
|
this._source.destroy();
|
|
|
|
this._source = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-09-21 14:58:03 +00:00
|
|
|
shouldTakeEvent: function(event) {
|
|
|
|
let actor = event.get_source();
|
|
|
|
return Main.layoutManager.keyboardBox.contains(actor) ||
|
|
|
|
actor._extended_keys || actor.extended_key;
|
|
|
|
},
|
|
|
|
|
2012-11-18 15:17:21 +00:00
|
|
|
_clearKeyboardRestTimer: function() {
|
|
|
|
if (!this._keyboardRestingId)
|
|
|
|
return;
|
|
|
|
GLib.source_remove(this._keyboardRestingId);
|
|
|
|
this._keyboardRestingId = 0;
|
|
|
|
},
|
|
|
|
|
2012-10-14 16:57:45 +00:00
|
|
|
show: function (monitor) {
|
2012-11-18 15:17:21 +00:00
|
|
|
this._keyboardRequested = true;
|
|
|
|
|
|
|
|
if (this._keyboardVisible) {
|
|
|
|
if (monitor != Main.layoutManager.keyboardIndex) {
|
|
|
|
Main.layoutManager.keyboardIndex = monitor;
|
|
|
|
this._redraw();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._clearKeyboardRestTimer();
|
|
|
|
this._keyboardRestingId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
|
|
|
KEYBOARD_REST_TIME,
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._clearKeyboardRestTimer();
|
|
|
|
this._show(monitor);
|
2013-11-29 00:45:39 +00:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2012-11-18 15:17:21 +00:00
|
|
|
}));
|
2014-04-10 17:26:52 +00:00
|
|
|
GLib.Source.set_name_by_id(this._keyboardRestingId, '[gnome-shell] this._clearKeyboardRestTimer');
|
2012-11-18 15:17:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_show: function(monitor) {
|
|
|
|
if (!this._keyboardRequested)
|
|
|
|
return;
|
|
|
|
|
2012-10-14 16:57:45 +00:00
|
|
|
Main.layoutManager.keyboardIndex = monitor;
|
2011-08-29 15:11:22 +00:00
|
|
|
this._redraw();
|
|
|
|
Main.layoutManager.showKeyboard();
|
|
|
|
this._destroySource();
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function () {
|
2012-11-18 15:17:21 +00:00
|
|
|
this._keyboardRequested = false;
|
|
|
|
|
|
|
|
if (!this._keyboardVisible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._clearKeyboardRestTimer();
|
|
|
|
this._keyboardRestingId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
|
|
|
KEYBOARD_REST_TIME,
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._clearKeyboardRestTimer();
|
|
|
|
this._hide();
|
2013-11-29 00:45:39 +00:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2012-11-18 15:17:21 +00:00
|
|
|
}));
|
2014-04-10 17:26:52 +00:00
|
|
|
GLib.Source.set_name_by_id(this._keyboardRestingId, '[gnome-shell] this._clearKeyboardRestTimer');
|
2012-11-18 15:17:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_hide: function() {
|
|
|
|
if (this._keyboardRequested)
|
|
|
|
return;
|
|
|
|
|
2012-11-10 21:47:57 +00:00
|
|
|
this._hideSubkeys();
|
2011-08-29 15:11:22 +00:00
|
|
|
Main.layoutManager.hideKeyboard();
|
|
|
|
this._createSource();
|
|
|
|
},
|
|
|
|
|
2012-11-10 21:47:57 +00:00
|
|
|
_hideSubkeys: function() {
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2011-08-29 15:11:22 +00:00
|
|
|
_moveTemporarily: function () {
|
|
|
|
let currentWindow = global.screen.get_display().focus_window;
|
2014-09-18 21:02:45 +00:00
|
|
|
let rect = currentWindow.get_frame_rect();
|
2011-08-29 15:11:22 +00:00
|
|
|
|
|
|
|
let newX = rect.x;
|
|
|
|
let newY = 3 * this.actor.height / 2;
|
|
|
|
currentWindow.move_frame(true, newX, newY);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setLocation: function (x, y) {
|
|
|
|
if (y >= 2 * this.actor.height)
|
|
|
|
this._moveTemporarily();
|
|
|
|
},
|
|
|
|
|
2012-07-20 13:59:53 +00:00
|
|
|
// _compareTimestamp:
|
|
|
|
//
|
|
|
|
// Compare two timestamps taking into account
|
|
|
|
// CURRENT_TIME (0)
|
|
|
|
_compareTimestamp: function(one, two) {
|
|
|
|
if (one == two)
|
|
|
|
return 0;
|
|
|
|
if (one == Clutter.CURRENT_TIME)
|
|
|
|
return 1;
|
|
|
|
if (two == Clutter.CURRENT_TIME)
|
|
|
|
return -1;
|
|
|
|
return one - two;
|
|
|
|
},
|
|
|
|
|
2012-10-30 15:46:18 +00:00
|
|
|
_clearShowIdle: function() {
|
|
|
|
if (!this._showIdleId)
|
|
|
|
return;
|
|
|
|
GLib.source_remove(this._showIdleId);
|
|
|
|
this._showIdleId = 0;
|
|
|
|
},
|
|
|
|
|
2011-08-29 15:11:22 +00:00
|
|
|
// D-Bus methods
|
|
|
|
Show: function(timestamp) {
|
2011-09-27 18:55:38 +00:00
|
|
|
if (!this._enableKeyboard)
|
|
|
|
return;
|
|
|
|
|
2012-07-20 13:59:53 +00:00
|
|
|
if (this._compareTimestamp(timestamp, this._timestamp) < 0)
|
2011-08-29 15:11:22 +00:00
|
|
|
return;
|
|
|
|
|
2012-10-30 15:46:18 +00:00
|
|
|
this._clearShowIdle();
|
|
|
|
|
2012-07-20 13:59:53 +00:00
|
|
|
if (timestamp != Clutter.CURRENT_TIME)
|
|
|
|
this._timestamp = timestamp;
|
2012-10-14 16:57:45 +00:00
|
|
|
this.show(Main.layoutManager.focusIndex);
|
2011-08-29 15:11:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Hide: function(timestamp) {
|
2011-09-27 18:55:38 +00:00
|
|
|
if (!this._enableKeyboard)
|
|
|
|
return;
|
|
|
|
|
2012-07-20 13:59:53 +00:00
|
|
|
if (this._compareTimestamp(timestamp, this._timestamp) < 0)
|
2011-08-29 15:11:22 +00:00
|
|
|
return;
|
|
|
|
|
2012-10-30 15:46:18 +00:00
|
|
|
this._clearShowIdle();
|
|
|
|
|
2012-07-20 13:59:53 +00:00
|
|
|
if (timestamp != Clutter.CURRENT_TIME)
|
|
|
|
this._timestamp = timestamp;
|
2011-08-29 15:11:22 +00:00
|
|
|
this.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
SetCursorLocation: function(x, y, w, h) {
|
2011-09-27 18:55:38 +00:00
|
|
|
if (!this._enableKeyboard)
|
|
|
|
return;
|
|
|
|
|
2011-09-21 16:47:39 +00:00
|
|
|
// this._setLocation(x, y);
|
2011-08-29 15:11:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
SetEntryLocation: function(x, y, w, h) {
|
2011-09-27 18:55:38 +00:00
|
|
|
if (!this._enableKeyboard)
|
|
|
|
return;
|
|
|
|
|
2011-09-21 16:47:39 +00:00
|
|
|
// this._setLocation(x, y);
|
2011-08-29 15:11:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get Name() {
|
|
|
|
return 'gnome-shell';
|
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2011-08-29 15:11:22 +00:00
|
|
|
|
2011-11-20 15:12:02 +00:00
|
|
|
const KeyboardSource = new Lang.Class({
|
|
|
|
Name: 'KeyboardSource',
|
|
|
|
Extends: MessageTray.Source,
|
2011-08-29 15:11:22 +00:00
|
|
|
|
|
|
|
_init: function(keyboard) {
|
|
|
|
this._keyboard = keyboard;
|
2012-05-30 13:58:37 +00:00
|
|
|
this.parent(_("Keyboard"), 'input-keyboard-symbolic');
|
2012-09-21 15:21:25 +00:00
|
|
|
this.keepTrayOnSummaryClick = true;
|
2011-08-29 15:11:22 +00:00
|
|
|
},
|
|
|
|
|
2012-11-02 15:09:04 +00:00
|
|
|
handleSummaryClick: function(button) {
|
2011-08-29 15:11:22 +00:00
|
|
|
this.open();
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
open: function() {
|
2012-10-14 16:57:45 +00:00
|
|
|
// Show the OSK below the message tray
|
|
|
|
this._keyboard.show(Main.layoutManager.bottomIndex);
|
2011-08-29 15:11:22 +00:00
|
|
|
}
|
2011-11-20 15:12:02 +00:00
|
|
|
});
|
2015-04-02 22:18:07 +00:00
|
|
|
|
|
|
|
const ShellWaylandAdapter = new Lang.Class({
|
|
|
|
Name: 'ShellWaylandAdapter',
|
|
|
|
Extends: Caribou.XAdapter,
|
|
|
|
|
|
|
|
vfunc_keyval_press: function(keyval) {
|
|
|
|
let focus = global.stage.get_key_focus();
|
|
|
|
if (focus instanceof Clutter.Text)
|
|
|
|
Shell.util_text_insert_keyval(focus, keyval);
|
|
|
|
else
|
|
|
|
this.parent(keyval);
|
|
|
|
},
|
|
|
|
|
|
|
|
vfunc_keyval_release: function(keyval) {
|
|
|
|
let focus = global.stage.get_key_focus();
|
|
|
|
if (focus instanceof Clutter.Text)
|
|
|
|
return; // do nothing
|
|
|
|
else
|
|
|
|
this.parent(keyval);
|
|
|
|
},
|
|
|
|
});
|