How to manage windows navigation with GTK library C++

I'm using GTK library to make a simple GUI for my application but I'm getting some problem to manage windows navigation. In particular, I'm not able to come back from a windows to the previous one displayed on the screen. I've already tried multiple possibilities such as: gtk_window_set_focus, gtk_window_present but they don't work. Here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
void callback(GtkWidget *wid, gpointer ptr)
{
    GtkWidget *win = static_cast<GtkWidget*>(ptr);
    gtk_window_fullscreen(GTK_WINDOW(win));
        
}


int main() {

gtk_init(NULL,NULL);
GtkWidget *window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window1), "1th window");
gtk_window_fullscreen(GTK_WINDOW(window1));
GtkWidget *btn1 = gtk_button_new_with_label ("Go to 2th window");
gtk_container_add (GTK_CONTAINER (window1), btn1);
gtk_widget_show_all(window1);


GtkWidget *window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window2), "2th window");
//gtk_window_fullscreen(GTK_WINDOW(window2));
GtkWidget *btn2 = gtk_button_new_with_label ("Go back to 1th window");
gtk_container_add (GTK_CONTAINER (window2), btn2);
g_signal_connect(window1,"delete-event",G_CALLBACK(gtk_main_quit),NULL);
g_signal_connect(window2,"delete-event",G_CALLBACK(gtk_main_quit),NULL);
g_signal_connect (btn1, "clicked", G_CALLBACK (callback),window2);
g_signal_connect (btn2, "clicked", G_CALLBACK (callback),window1);

gtk_widget_show_all(window2);

gtk_main();
return 0;
}


The problem is that when I push btn2, even if callback function is invoked, I'm not able to see previous window
Last edited on
Have you figured this out yet?

IIRC fullscreen assumes that the fullscreen window has total control. You must un-fullscreen all other windows before setting focus and fullscreening the window you wish.

It is also possible that mouse events are interfering with it. Try setting a (short) timer to do the deed some time after the button callback is done. 150 ms is plenty of time, but not enough that the user will notice the delay.

Sorry, haven't tried to compile and replicate.
Topic archived. No new replies allowed.