[gnome-shell/wip/is-switch-fixes: 1/4] status/keyboard: Synchronize input source switching with key events
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/is-switch-fixes: 1/4] status/keyboard: Synchronize input source switching with key events
- Date: Fri, 5 Apr 2013 16:15:31 +0000 (UTC)
commit b6079581340a18d0c69e744ee6cc0673ef65f706
Author: Rui Matos <tiagomatos gmail com>
Date: Wed Mar 27 01:01:33 2013 +0100
status/keyboard: Synchronize input source switching with key events
Currently we simply set the gsettings key when activating an input
source. This obviously introduces a time window, between the event that
activates the switch and when the switch is complete, under which key
events are being delivered to applications and interpreted according
to the previous input source.
The patches in bug 696996 introduce a DBus API in g-s-d that allows us
to know when an input source if effectively active. Using that and
freezing keyboard events in the X server until we hear back from g-s-d
we can ensure that events won't be misinterpreted after an input
source switch.
https://bugzilla.gnome.org/show_bug.cgi?id=697007
js/ui/status/keyboard.js | 45 +++++++++++++++++++++++++++++++++++++++++----
1 files changed, 41 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js
index 3dc173b..0aaf90c 100644
--- a/js/ui/status/keyboard.js
+++ b/js/ui/status/keyboard.js
@@ -33,6 +33,36 @@ const KEY_INPUT_SOURCES = 'sources';
const INPUT_SOURCE_TYPE_XKB = 'xkb';
const INPUT_SOURCE_TYPE_IBUS = 'ibus';
+// This is longest we'll keep the keyboard frozen until an input
+// source is active.
+const MAX_INPUT_SOURCE_ACTIVATION_TIME = 2000; // ms
+
+const BUS_NAME = 'org.gnome.SettingsDaemon.Keyboard';
+const OBJECT_PATH = '/org/gnome/SettingsDaemon/Keyboard';
+
+const KeyboardManagerInterface =
+<interface name="org.gnome.SettingsDaemon.Keyboard">
+<method name="SetInputSource">
+ <arg type="u" direction="in" />
+</method>
+</interface>;
+
+const KeyboardManagerProxy = Gio.DBusProxy.makeProxyWrapper(KeyboardManagerInterface);
+
+function releaseKeyboard() {
+ if (Main.modalCount > 0)
+ global.display.unfreeze_keyboard(global.get_current_time());
+ else
+ global.display.ungrab_keyboard(global.get_current_time());
+}
+
+function holdKeyboard() {
+ if (Main.modalCount > 0)
+ global.display.freeze_keyboard(global.get_current_time());
+ else
+ global.display.grab_keyboard(global.get_current_time());
+}
+
const IBusManager = new Lang.Class({
Name: 'IBusManager',
@@ -230,6 +260,7 @@ const InputSource = new Lang.Class({
},
activate: function() {
+ holdKeyboard();
this.emit('activate');
},
});
@@ -364,6 +395,12 @@ const InputSourceIndicator = new Lang.Class({
this._ibusManager.connect('property-updated', Lang.bind(this, this._ibusPropertyUpdated));
this._inputSourcesChanged();
+ this._keyboardManager = new KeyboardManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
+ function(proxy, error) {
+ if (error)
+ log(error.message);
+ });
+
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this._showLayoutItem = this.menu.addAction(_("Show Keyboard Layout"), Lang.bind(this,
this._showLayout));
@@ -487,10 +524,10 @@ const InputSourceIndicator = new Lang.Class({
let is = new InputSource(type, id, displayName, shortName, i);
is.connect('activate', Lang.bind(this, function() {
- if (this._currentSource && this._currentSource.index == is.index)
- return;
- this._settings.set_value(KEY_CURRENT_INPUT_SOURCE,
- GLib.Variant.new_uint32(is.index));
+ let inVariant = new GLib.Variant('(u)', [is.index]);
+ this._keyboardManager.call('SetInputSource', inVariant, 0,
+ MAX_INPUT_SOURCE_ACTIVATION_TIME,
+ null, releaseKeyboard);
}));
if (!(is.shortName in inputSourcesByShortName))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]