GTK窗口置顶资料整理

在GTK中提供了下列几种窗口置顶函数:

gtk_window_set_keep_above(GTK_WINDOW(window),TRUE); //xfce下不起作用

gtk_window_set_type_hint (GTK_WINDOW(window),GDK_WINDOW_TYPE_HINT_DOCK); // 大多数desk panel使用的方式

 

示例代码:

/**
* gcc always-top-window.c -o always-top-window `pkg-config --cflags --libs gtk+-2.0`
*/
#include <gtk/gtk.h>


void destroy( GtkWidget *widget,
              gpointer   data )
{
    gtk_main_quit ();
}

int main( int   argc, char *argv[] )
{

    GtkWidget *window;
    GtkWidget *button;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (G_OBJECT (window), "destroy",
                         G_CALLBACK (destroy), NULL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);

    button = gtk_button_new_with_label ("Hello World");
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
                              G_CALLBACK (gtk_widget_destroy),
                              window);

    gtk_container_add (GTK_CONTAINER (window), button);

     /* always on top */
    // type1: gtk_window_set_keep_above 
    // not work normal on xfce but can use on gnome
    // gtk_window_set_keep_above(GTK_WINDOW(window),TRUE);
    // type2: gtk_window_set_type_hint can use on xfce and gnome
    // gtk_window_stick() is [optional]
    gtk_window_set_type_hint (GTK_WINDOW(window),GDK_WINDOW_TYPE_HINT_DOCK);
    // gtk_window_set_type_hint (GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DESKTOP);
    // gtk_window_stick (GTK_WINDOW(window));
     
    gtk_widget_show (button);
    gtk_widget_show (window);

    gtk_main ();

    return 0;

}

你可能感兴趣的:(C++,c,C#,gcc)