[maemo-developers] How to get a transparent GtkWindow (fremantle)

From: Cornelius Hald hald at icandy.de
Date: Thu Oct 29 19:12:19 EET 2009
Hi Luca,

create a window like this and then use cairo to draw on it:

GtkWidget *overlay = gtk_window_new(GTK_WINDOW_POPUP);
gtk_window_set_decorated(GTK_WINDOW(overlay), FALSE);
gtk_widget_set_size_request(overlay, 100 100);
gtk_window_set_resizable(GTK_WINDOW(overlay), FALSE);

GdkScreen *screen = gtk_widget_get_screen (widget);
gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));

gtk_widget_realize(overlay);


Cheers!
Conny



On Thu, 2009-10-29 at 17:29 +0100, Luca Donaggio wrote:
> I'm trying to create a transparent, non-decorated popup GtkWindow on
> top af my app HildonWindow and draw something on its underlying
> GdkWindow object using cairo.
> All I was able to obtain so far is a black (or whatever is the
> background colour of the selected theme) rectangle -ie it's not
> transparent and everything I paint in its GdkWindow with Cairo is not
> showed at all.
> Here is the code I'm using:
> 
> void create_image_details(GtkWidget *callerobj,app_data_t *myapp) {
>     PangoLayout *textbuff;
>     cairo_t *cr;
>     gint x0, y0, r, txtwidth, txtheight;
> 
>     /* For the widget itself let's use a GtkWindow */
>     if ((myapp->imgparamwin != NULL) &
> GTK_IS_WINDOW(myapp->imgparamwin))
> gtk_widget_destroy(myapp->imgparamwin);
>     myapp->imgparamwin = gtk_window_new(GTK_WINDOW_POPUP);
>     gtk_window_set_decorated(GTK_WINDOW (myapp->imgparamwin),FALSE);
>     gtk_window_set_opacity(GTK_WINDOW (myapp->imgparamwin),0);
>     gtk_widget_set_app_paintable(myapp->imgparamwin,TRUE);
>     gtk_widget_realize(myapp->imgparamwin);
>     /*
> gdk_window_set_back_pixmap(myapp->imgparamwin->window,NULL,FALSE); */
>     /* Get the Cairo context */
>     cr = gdk_cairo_create(GDK_DRAWABLE (myapp->imgparamwin->window));
>     textbuff = pango_cairo_create_layout(cr);
>     pango_layout_set_markup(textbuff,myapp->imgparam,-1);
>     pango_layout_get_pixel_size(textbuff,&txtwidth,&txtheight);
>     /* Draw a rounded rectangle */
>     
> [cairo stuff is here]
> 
>     cairo_destroy(cr);
>     g_object_unref(textbuff);
>     /* Show the widget */
>     gtk_window_resize(GTK_WINDOW (myapp->imgparamwin),txtwidth + (r *
> 2),txtheight + (r * 2));
>     gtk_window_move(GTK_WINDOW (myapp->imgparamwin),30,30);
> 
> gdk_window_reparent(myapp->imgparamwin->window,myapp->image->window,30,30);
>     gtk_widget_show_all(myapp->imgparamwin);
> }
> 
> The window dimension after the gtk_window_resize() are correct -ie the
> dimension of the PangoLayout containing the text to be rendered, so
> something is definitely going on under the hood... but nothing is
> displayed!
> If I add some widget to the popoup window (for example a GtkLabel with
> some text in it), it's rendered correctly, but, of course it's not
> transparent!
> 
> Any help, as always, is much appreciated!
> 
> Luca Donaggio
> _______________________________________________
> maemo-developers mailing list
> maemo-developers at maemo.org
> https://lists.maemo.org/mailman/listinfo/maemo-developers

More information about the maemo-developers mailing list