Commit 3739e7fe authored by Florian Müllner's avatar Florian Müllner

entryArea: Replay events instead of forcing focus on entry

Keeping key focus on the entry interferes with GtkPopover's modal
tracking, so allow moving the key focus away, but replay "normal"
key events to the entry.

https://bugzilla.gnome.org/show_bug.cgi?id=727039
parent d71c1328
const Gdk = imports.gi.Gdk;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const ChatView = imports.chatView;
......@@ -42,6 +43,12 @@ const EntryArea = new Lang.Class({
this.widget.connect('destroy', Lang.bind(this, this._onDestroy));
this.widget.connect('notify::sensitive', Lang.bind(this, this._onSensitiveChanged));
this.widget.connect('realize', Lang.bind(this,
function() {
let toplevel = this.widget.get_toplevel();
toplevel.connect('key-press-event',
Lang.bind(this, this._onKeyPressEvent));
}));
this._nickEntry = new Gtk.Entry();
this._nickEntry.width_chars = ChatView.MAX_NICK_CHARS
......@@ -78,20 +85,6 @@ const EntryArea = new Lang.Class({
this._ircParser.process(this._entry.text);
this._entry.text = '';
}));
this._entry.connect('notify::is-focus', Lang.bind(this,
function() {
if (!this.widget.sensitive)
return;
// HACK: force focus to the entry unless it was
// moved by keynav or moved to another entry
if (this.widget.get_toplevel().get_focus() instanceof Gtk.Entry)
return;
let device = Gtk.get_current_event_device();
if (!device || device.get_source() == Gdk.InputSource.KEYBOARD)
return;
this._entry.grab_focus();
}));
this.widget.show_all();
},
......@@ -108,6 +101,31 @@ const EntryArea = new Lang.Class({
this._completion.setCompletions(nicks);
},
_onKeyPressEvent: function(w, event) {
if (!this._entry.get_mapped())
return false;
if (this._entry.has_focus)
return false;
if (this._entry.get_toplevel().get_focus() instanceof Gtk.Entry)
return false;
let [, keyval] = event.get_keyval();
if (Gdk.keyval_to_unicode(keyval) == 0)
return false;
let [, state] = event.get_state();
if (state != 0)
return false;
this._entry.editable = false;
this._entry.grab_focus();
this._entry.editable = true;
this._entry.event(event);
return true;
},
_onSensitiveChanged: function() {
if (!this.widget.sensitive)
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment