PDA

View Full Version : Using the blur property for applications


FunkyM
March 18th, 2007, 03:09 AM
I have modified the gnome-main-menu (http://svn.gnome.org/viewcvs/gnome-main-menu/trunk/) 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:
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 (http://bugzilla.gnome.org/show_bug.cgi?id=419840) and currently it looks like this (note the terminal with blur):

http://media.sukimashita.com/temp/10-gnome-main-menu-2.png

wfarr
March 18th, 2007, 05: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. =/

lowfi
March 18th, 2007, 06: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
March 18th, 2007, 07: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?

#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:

FunkyM
March 18th, 2007, 08: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
March 18th, 2007, 09: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.

http://media.sukimashita.com/temp/10-gnome-main-menu-3.png