Using the blur property for applications

Discuss Core development and Core patches

Using the blur property for applications

Postby FunkyM » Sun Mar 18, 2007 4:09 am

I have modified the gnome-main-menu to support composited drawing.
Additionally, I wanted to blur the transparent parts with the compiz blur hint which seems to fail.

The related code is simply:
Code: Select all
if(priv->have_alpha) {
      long data[2];
      data[0] = 2; /* threshold */
      data[1] = 0; /* filter */
      
      XChangeProperty (
         xdisplay,
         GDK_WINDOW_XID (priv->slab_window->window),
         XInternAtom (xdisplay, "_COMPIZ_WM_WINDOW_BLUR", FALSE),
         XA_INTEGER,
         32,
         PropModeReplace, (guchar *) data,
         2);
}


Any ideas why it doesn't work? Maybe due to the window being created with glade?

The patches for the change are available here and currently it looks like this (note the terminal with blur):

Image
FunkyM
Member
 
Posts: 100
Joined: Wed Nov 08, 2006 5:55 pm
Location: Germany

Postby wfarr » Sun Mar 18, 2007 6:03 am

Nice start.


I'd be even more excited if the GNOME people included Recently Used Applications support so I didn't have to disable it on my SLAB built from SVN on Ubuntu. =/
[SIZE="1"]"Men will never be free until the last king is strangled with the entrails of the last priest." ~ Denis Diderot[/SIZE]

VACATION MODE
wfarr
 
Posts: 410
Joined: Wed Dec 06, 2006 10:38 pm
Location: Atlanta, GA

Postby lowfi » Sun Mar 18, 2007 7:28 am

You have to enable alpha_blur otherwise it won't work. Setting the blur atom doesn't make any difference. It's only useful if want a specific region to be blurred and not the whole transparent area or if you want a different filter for your window (but i think compiz just ignores the filter type atm).
lowfi
Member
 
Posts: 57
Joined: Wed Nov 08, 2006 3:33 pm

Postby lowfi » Sun Mar 18, 2007 8:39 am

Here is some demo code which uses regions.

And i think i found a bug in the blur plugin. If i move the transparent window over a firefox window, the region suddenly doesn't work anymore and whole window becomes blurred. If i move the window to another position above the firefox window the region works again. Very strange.

Maybe it's a bug in my app, but that's unlikely :)

Can somebody confirm this?

Code: Select all
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>

#define GRAVITY_NORTHWEST ((1 << 0) | (1 << 2))
#define BLUR_REGION TRUE

static gboolean
expose (GtkWidget *win, GdkEventExpose *eev, gpointer rect)
{
   cairo_t *cr;
   
   cr = gdk_cairo_create (win->window);
   cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
   cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5);
   cairo_paint (cr);

   cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
   gdk_cairo_rectangle (cr, (GdkRectangle *) rect);
   cairo_fill_preserve (cr);
   cairo_set_source_rgba (cr, 0.0, 0.5, 1.0, 0.8);
   cairo_stroke (cr);

   cairo_destroy (cr);

   return TRUE;
}

static void
set_compiz_blur (GdkWindow *window, GdkRectangle *rect)
{
   Display *dpy;
   long data [8];
   guint n = 0;
   
    dpy = GDK_DISPLAY_XDISPLAY(gdk_display_get_default ());

    data[n++] = 2;
    data[n++] = 0;
   
    if (rect) {
      data[n++] = GRAVITY_NORTHWEST;
      data[n++] = rect->x;
      data[n++] = rect->y;
      data[n++] = GRAVITY_NORTHWEST;
      data[n++] = rect->x + rect->width;
      data[n++] = rect->y + rect->height;
   }

    XChangeProperty (dpy, GDK_WINDOW_XID(window),
                XInternAtom (dpy, "_COMPIZ_WM_WINDOW_BLUR", FALSE),
                XA_INTEGER, 32, PropModeReplace, (guchar *)data, n);
}

int
main (int argc, char **argv)
{
   GtkWidget *win;
   GdkColormap *cm;
   GdkRectangle rect;

   gtk_init (&argc, &argv);
   
   rect.x      = 100;
   rect.y      = 100;
   rect.width  = 400;
   rect.height = 200;
   
   win = gtk_window_new (GTK_WINDOW_TOPLEVEL);   
   gtk_widget_set_app_paintable (win, TRUE);
   gtk_widget_set_size_request (win, 600, 400);

   cm = gdk_screen_get_rgba_colormap (gtk_widget_get_screen (win));   
   gtk_widget_set_colormap (win, cm);
   g_object_unref (cm);
   
   g_signal_connect (G_OBJECT(win), "delete-event", G_CALLBACK(gtk_main_quit), NULL);
   g_signal_connect (G_OBJECT(win), "expose-event", G_CALLBACK(expose), (gpointer)&rect);

   gtk_widget_show (win);
   
   if (BLUR_REGION)
      set_compiz_blur (win->window, &rect);
   else
      set_compiz_blur (win->window, NULL);   

   gtk_main ();
   
   return 0;
}


btw, forum attachments would rock :wink:
lowfi
Member
 
Posts: 57
Joined: Wed Nov 08, 2006 3:33 pm

Postby FunkyM » Sun Mar 18, 2007 9:02 am

Your (cool) example works correctly for me, even over Firefox windows.
I use alpha_blur and updated the screenshot to reflect this.

My problem might be caused by the applet API creating another window and embedding the slab-main-menu, thus I think I need to set the hint on that one instead (just curious how to retrieve it).

Once that works I'll set it to only apply blur to the transparent region.
FunkyM
Member
 
Posts: 100
Joined: Wed Nov 08, 2006 5:55 pm
Location: Germany

Postby FunkyM » Sun Mar 18, 2007 10:47 am

Thanks, it's working now. I guess due to Glade the realization order is a bit different for the windows, thus I had tried to put the property change into the allocate callback which worked out.

Image
FunkyM
Member
 
Posts: 100
Joined: Wed Nov 08, 2006 5:55 pm
Location: Germany


Return to Compiz Core Development

Who is online

Users browsing this forum: No registered users and 0 guests

cron