Search code examples
cgtk3

How to set focus to a window in GTK3?


I have 2 windows: the first is the main one and the second is the window_histogram one. I want to click on a certain area of the first one, and then the second one gets the focus. I have this in the first window, so when it is clicked, these lines are executed:

gtk_widget_set_can_focus (combobox_widget,TRUE);
gtk_window_set_focus(GTK_WINDOW(window_histogram),combobox_widget);

However, the second window, does not get the focus. I have also tried this:

gtk_window_set_focus (GTK_WINDOW(window_histogram), NULL);

And this:

gtk_widget_set_can_focus (combobox_widget, TRUE);
gtk_widget_grab_focus(combobox_widget);

But none of them have worked and the second window remains unfocused. What can I try? (Feel free to require more details).


Solution

  • I believe you are looking for gtk_window_present. This will show the window and bring it to the front. Note that this may not work properly on Windows.