Gtk focus component widget

I created a composite widget with webkit_webview widgets stored in a scrollable window using the gtkvbox base widget. How to make the main gtkvbox widget in focus when any of the widgets it contains has focus? In particular, I'm trying to add an accelerator that should only be active when the composite widget is in focus. To determine if the composite widget is in focus, I call gtk_widget_get_focused () and then iterate over the widget parents to populate the search for the base widget. There seems to be a better way.

+3
source share
1 answer

Only one widget at a time can have a global input focus, which is the focus that the user sees on the screen and where keystrokes appear. If gtk_widget_has_focus(widget)returns TRUE, it widgethas a global input focus. You cannot have web browsing and vbox has global input focus at the same time.

What you can do is call gtk_container_get_focus_child()in the composite widget, and if the return value is a composite widget, then the focus is somewhere inside the composite widget.

Or you can connect to the signals "focus-in-event", and "focus-out-event"in the composite widget. I am sure that they will notify you when one of the contained widgets gains or loses focus. (Remember to call gdk_window_set_events(widget->window, gdk_window_get_events(widget->window) | GDK_FOCUS_CHANGE_MASK)your widget first, as described in the GTK docs.)

+1
source

Source: https://habr.com/ru/post/1720637/


All Articles