I am using gtk-rs
and want to be able to detect when any key is pressed.
From some searching online, it seems like the way to do that in C is with gtk_widget_add_events
and then g_signal_connect
. This answer has a good explanation.
In Rust, I can call Widget::add_events
. I also found several definitions for g_signal_connect_*
. But, these functions are unsafe
, undocumented, and seem to take C types as arguments.
My question is:
- In order to use
gobject_sys::g_signal_connect_closure
, how do I create aGObject
andGClosure
. In Rust? Can rust structs and closures be converted to that? - Is there a better and more idiomatic way to listen for key events? I have trouble believing that doing such a basic thing would require such an esoteric interface. I have seen some support for specific keyboard shortcuts or keyboard acceleration groups but I haven't been able to find any documentation or examples for just listening for key press events.