Hi Luca,

have a look at this file:
https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/conboy/src/fullscreenmanager.c?revision=517&root=conboy&view=markup

The creation of the overlay window is done in fullscreen_ui_create() and
the cairo drawing on the window is in on_expose_event().

This code works. It creates a small semi-transparent window which is
shown over the main window. I first clear the surface, then I draw a
semi-transparent rectangle with a rounded upper-left corner and then I
add a pixmap with an alpha channel.

I think the most important parts are:

- Setting the color map of the window.
  gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap
(screen));

- Clearing the cairo surface.
  cairo_set_operator (ctx, CAIRO_OPERATOR_CLEAR);
  cairo_paint (ctx);


Hope that helps!
Conny


On Fri, 2009-10-30 at 14:36 +0100, Luca Donaggio wrote:
> Thanks Conny and Kimmo,
> 
> here are my progresses:
> 
> I'm able to draw to the GtkWindow using Cairo only if I do it in a
> callback attached to the expose event of the window itself, but I'm
> still getting no transparency!
> I'm sure this is the problem with the window manager that Kimmo
> pointed out, but I don't know how to set the override-redirect flag
> apart from passing the correct value inside a GdkWindowAttr struct
> when manually creating a GdkWindow with gdk_window_new(), but I'm not
> doing this manually, so I'm lost here!
> 
> Luca Donaggio
> 
> 2009/10/30 Kimmo Hämäläinen <kimmo.hamalai...@nokia.com>
>         On Thu, 2009-10-29 at 17:29 +0100, ext 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.
>         
>         
>         You may hit (at least) this hard-coded limitation:
>         http://maemo.gitorious.org/fremantle-hildon-
>         desktop/libmatchbox2/blobs/master/matchbox/core/mb-wm-client.c#line173
>         
>         Currently alpha in dialogs and application windows is ignored
>         because it
>         allows for optimisations in the compositor. But if you set the
>         override-
>         redirect flag for the window, that should go around that
>         (because the
>         type of your window would be MBWMClientTypeOverride).
>         
>         -Kimmo
>         
>         
>         > 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@maemo.org
> https://lists.maemo.org/mailman/listinfo/maemo-developers

_______________________________________________
maemo-developers mailing list
maemo-developers@maemo.org
https://lists.maemo.org/mailman/listinfo/maemo-developers

Reply via email to