Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep transient window on top in GTK+

Tags:

gtk

I am porting a large (100+ files) 8 year old GTK+ application from Red Hat 2.4 to Ubuntu Lucid. It's a full screen application for an industrial control panel, the operator is not able to access the underlying OS.

It has various popups (eg a touch keyboard) which can appear in front of the main application. However, when I compile and run it on Ubuntu Lucid the popups remain hidden behind the main screen.

This program which uses the same GTK+ calls as the application demonstrates the problem:

#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gprintf.h>


int main(int argc, char *argv[])
{
    GtkWidget *mainwindow;
    GtkWidget *popwindow;
    GtkWidget *label;

    gtk_init(&argc, &argv);

    mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(mainwindow), GTK_WIN_POS_CENTER);
    gtk_window_set_decorated(GTK_WINDOW(mainwindow), FALSE);
    gtk_window_fullscreen(GTK_WINDOW(mainwindow));
    gtk_widget_show_all(mainwindow);

    popwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_keep_above(GTK_WINDOW(popwindow), TRUE);
    gtk_window_set_modal(GTK_WINDOW(popwindow), TRUE);
    gtk_window_set_decorated (GTK_WINDOW (popwindow), FALSE);
    gtk_window_set_resizable (GTK_WINDOW(popwindow), FALSE);
    gtk_window_set_position( GTK_WINDOW (popwindow), (GtkWindowPosition)GTK_WIN_POS_CENTER);
    gtk_window_set_transient_for(GTK_WINDOW(popwindow),GTK_WINDOW(mainwindow));

    label = gtk_label_new(g_strdup_printf ("My GTK version is %d.%d.%d", gtk_major_version, gtk_minor_version, gtk_micro_version));
    gtk_container_add(GTK_CONTAINER(popwindow), label);
    gtk_widget_show(label);
    gtk_widget_show(popwindow);

    gtk_main();

    return 0;
}

The popup remains hidden, and it can only be seen if you Alt-Tab to a different window (not the mainwindow). If I remove the call to gtk_window_set_transient_for() then the popup does appear, but the desktop panel also appears giving access to the underlying operating system.

Is there any way to get the desired behavior? Ubuntu Lucid uses GTK+ 2.20.1

Thanks for any help

Richard

like image 280
user977870 Avatar asked Feb 21 '23 16:02

user977870


1 Answers

Use gtk_window_present() to actually raise the popup in the stacking order:

gtk_window_present (GTK_WINDOW (popwindow));
like image 184
kalev Avatar answered Apr 05 '23 22:04

kalev