1

I have a GTK window with two elements, an Entry that functions as a search input and a ListBox that displays search results. When the ListBox has focus (e.g. the user is navigating it with arrow keys) I'd like to direct any character key presses they make to the search input Entry instead of the ListBox.

I'd appreciate any pointers on redirecting the target of certain GTK events or any other way to handle this situation. I'm using gtk-rs, but I imagine any language's GTK solution will be enough for me to go on.

Thanks!

Michael
  • 462
  • 1
  • 6
  • 18

2 Answers2

0

Ooo that's a tricky one. You can tinker with a widgets event mask and add event handlers to a widget see https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-add-events

Custom event handlers can be a steep learning curve though.

Paul Childs
  • 229
  • 2
  • 9
0

This is exactly what I'm doing here: https://github.com/jimmykarily/fuzzygui/blob/7ddb72ad712e7afa5bfcb2d06b435b74caeb8140/main.go#L88

(actually the whole gui is exactly what you describe, I wouldn't be surprised if you were actually trying to implement the same tool :D ).

All you got to do basically is connect to the event on the main window and make sure you "grab focus" on the element that is supposed to handle that event. If it's an arrow key, you grab focus on the listbox. If it's anything else you grab focus on the entry. I used GrabFocusWithoutSelecting for the entry because GrabFocus deleted the text in the entry when it was called.

I also handled "Return" and "Escape" differently, you may find that useful too.