1

我试图让我的 GtkWindow 在 Windows 后端透明,但程序失败。我使用 gtk+ 3.6.1 似乎 gdk_window_set_opacity() 函数不起作用所以还有其他解决方案吗?这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include "gtk/gtk.h"

int main( int argc, char *argv[] )
{
    gboolean user_func( GtkWidget *wid,
                        cairo_t *cr,
                        gpointer user_data );
    gtk_init( &argc, &argv );
    GtkWidget *win = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    gtk_window_set_title( GTK_WINDOW( win ), "Translucent window");
    g_signal_connect( G_OBJECT( win ), "draw", G_CALLBACK( user_func ), NULL );
    gtk_widget_show( win );
    gtk_main();
    return 0;
}

gboolean user_func( GtkWidget *wid,
                    cairo_t *cr,
                    gpointer user_data )
{
    GdkWindow *window = gtk_widget_get_window( wid );
    printf("bbbb\n");                                // for debuging purpose
       gdk_window_set_opacity( window, 0.5 );
    printf("bonjour\n");                             // for debuging purpose
    cairo_set_source_rgba( cr, 0.0, 0.0, 1.0, 0.5 );
    cairo_paint( cr );
    GTK_WIDGET_GET_CLASS( wid )->draw( wid, cr );
    return TRUE;
}

此致。

4

0 回答 0