[fractal/wip/christopherdavis/fix-tab-completion] autocomplete: Use key-press-event instead of button-press-event
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/wip/christopherdavis/fix-tab-completion] autocomplete: Use key-press-event instead of button-press-event
- Date: Sun, 30 Aug 2020 20:39:12 +0000 (UTC)
commit 0761f739f573ee5a53581d04a9a9ff814fe0599c
Author: Christopher Davis <brainblasted disroot org>
Date: Sun Aug 30 13:36:29 2020 -0700
autocomplete: Use key-press-event instead of button-press-event
New versions of gtk-rs are more pedantic about the type
you'll get when connecting to and emitting these signals, causing a crash whenever the user pressed a
navigation button
while autocompletion was open.
Closes https://gitlab.gnome.org/GNOME/fractal/-/issues/669
fractal-gtk/src/widgets/autocomplete.rs | 44 ++++++++++++++++++---------------
1 file changed, 24 insertions(+), 20 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/autocomplete.rs b/fractal-gtk/src/widgets/autocomplete.rs
index c68eb40e..5be90826 100644
--- a/fractal-gtk/src/widgets/autocomplete.rs
+++ b/fractal-gtk/src/widgets/autocomplete.rs
@@ -175,7 +175,7 @@ impl Autocomplete {
};
if let Some(w) = widget {
let ev: &gdk::Event = ev;
- let _ = w.emit("button-press-event", &[ev]);
+ let _ = w.emit("key-press-event", &[ev]);
}
} else if ev.get_keyval() != gdk::keys::constants::Tab {
return glib::signal::Inhibit(false);
@@ -190,7 +190,7 @@ impl Autocomplete {
let widget = { own.borrow_mut().autocomplete_arrow(-1) };
if let Some(w) = widget {
let ev: &gdk::Event = ev;
- let _ = w.emit("button-press-event", &[ev]);
+ let _ = w.emit("key-press-event", &[ev]);
}
}
/* Arrow key */
@@ -203,7 +203,7 @@ impl Autocomplete {
if let Some(w) = widget {
let ev: &gdk::Event = ev;
- let _ = w.emit("button-press-event", &[ev]);
+ let _ = w.emit("key-press-event", &[ev]);
}
}
_ => return glib::signal::Inhibit(false),
@@ -281,31 +281,35 @@ impl Autocomplete {
};
let widget_list = { own.borrow_mut().autocomplete_show_popover(list) };
for (alias, widget) in widget_list.iter() {
- widget.connect_button_press_event(clone!(
+ widget.connect_key_press_event(clone!(
@strong own,
@strong alias
=> move |_, ev| {
own.borrow_mut().autocomplete_insert(alias.clone());
- if ev.is::<gdk::EventKey>() {
- let ev = {
- let ev: &gdk::Event = ev;
-
- ev.clone()
- .downcast::<gdk::EventKey>()
- .unwrap()
- };
- /* Submit on enter */
- if ev.get_keyval() == gdk::keys::constants::Return
- || ev.get_keyval() == gdk::keys::constants::Tab
- {
- own.borrow_mut().autocomplete_enter();
- }
- }
- else if ev.is::<gdk::EventButton>() {
+ let ev = {
+ let ev: &gdk::Event = ev;
+
+ ev.clone()
+ .downcast::<gdk::EventKey>()
+ .unwrap()
+ };
+ /* Submit on enter */
+ if ev.get_keyval() == gdk::keys::constants::Return
+ || ev.get_keyval() == gdk::keys::constants::Tab
+ {
own.borrow_mut().autocomplete_enter();
}
Inhibit(true)
}));
+
+ widget.connect_button_press_event(clone!(
+ @strong own,
+ @strong alias
+ => move |_, _| {
+ own.borrow_mut().autocomplete_insert(alias.clone());
+ own.borrow_mut().autocomplete_enter();
+ Inhibit(true)
+ }));
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]