keyboard: Show in an idle on clutter key focus changes

It's common to do actor.grab_key_focus() before the actor is mapped
which means that we can't reliably determine where the actor is at
notify::key-focus time and thus might end up showing the keyboard on
the wrong monitor.

This is happening, in particular, with the run dialog. Delaying until
we hit the main loop allows us to know where the actor finally is
before showing the OSK.

https://bugzilla.gnome.org/show_bug.cgi?id=685856
This commit is contained in:
Rui Matos 2012-10-30 16:46:18 +01:00 committed by Matthias Clasen
parent fa1420b384
commit f07fee538d

View File

@ -182,6 +182,8 @@ const Keyboard = new Lang.Class({
this._a11yApplicationsSettings = new Gio.Settings({ schema: A11Y_APPLICATIONS_SCHEMA }); this._a11yApplicationsSettings = new Gio.Settings({ schema: A11Y_APPLICATIONS_SCHEMA });
this._a11yApplicationsSettings.connect('changed', Lang.bind(this, this._settingsChanged)); this._a11yApplicationsSettings.connect('changed', Lang.bind(this, this._settingsChanged));
this._settingsChanged(); this._settingsChanged();
this._showIdleId = 0;
}, },
init: function () { init: function () {
@ -273,10 +275,14 @@ const Keyboard = new Lang.Class({
return; return;
let time = global.get_current_time(); let time = global.get_current_time();
if (focus instanceof Clutter.Text) if (!(focus instanceof Clutter.Text)) {
this.Show(time);
else
this.Hide(time); this.Hide(time);
return;
}
if (!this._showIdleId)
this._showIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE,
Lang.bind(this, function() { this.Show(time); }));
}, },
_addKeys: function () { _addKeys: function () {
@ -502,6 +508,13 @@ const Keyboard = new Lang.Class({
return one - two; return one - two;
}, },
_clearShowIdle: function() {
if (!this._showIdleId)
return;
GLib.source_remove(this._showIdleId);
this._showIdleId = 0;
},
// D-Bus methods // D-Bus methods
Show: function(timestamp) { Show: function(timestamp) {
if (!this._enableKeyboard) if (!this._enableKeyboard)
@ -510,6 +523,8 @@ const Keyboard = new Lang.Class({
if (this._compareTimestamp(timestamp, this._timestamp) < 0) if (this._compareTimestamp(timestamp, this._timestamp) < 0)
return; return;
this._clearShowIdle();
if (timestamp != Clutter.CURRENT_TIME) if (timestamp != Clutter.CURRENT_TIME)
this._timestamp = timestamp; this._timestamp = timestamp;
this.show(Main.layoutManager.focusIndex); this.show(Main.layoutManager.focusIndex);
@ -522,6 +537,8 @@ const Keyboard = new Lang.Class({
if (this._compareTimestamp(timestamp, this._timestamp) < 0) if (this._compareTimestamp(timestamp, this._timestamp) < 0)
return; return;
this._clearShowIdle();
if (timestamp != Clutter.CURRENT_TIME) if (timestamp != Clutter.CURRENT_TIME)
this._timestamp = timestamp; this._timestamp = timestamp;
this.hide(); this.hide();