[maemo-commits] [maemo-commits] r12171 - in projects/haf/trunk/hildon-desktop: . libhildondesktop src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu Jun 7 13:42:55 EEST 2007
- Previous message: [maemo-commits] r12170 - in projects/haf/tags/hildon-plugin-settings: . 0.0.1 0.0.1/data 0.0.1/debian 0.0.1/src
- Next message: [maemo-commits] r12172 - in projects/haf/trunk/hildon-desktop: . policies
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: jobi Date: 2007-06-07 13:42:53 +0300 (Thu, 07 Jun 2007) New Revision: 12171 Added: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.c projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.h Modified: projects/haf/trunk/hildon-desktop/ChangeLog projects/haf/trunk/hildon-desktop/libhildondesktop/Makefile.am projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-toggle-button.c projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-home-area.c projects/haf/trunk/hildon-desktop/src/hd-panel-window.c Log: 2007-06-07 Johan Bilien <johan.bilien at nokia.com> * libhildondesktop/hildon-desktop-picture.[ch]: - added - helpers for creating XRender Pictures from pixbufs or pixmaps * libhildondesktop/hildon-home-area.c, libhildondesktop/hildon-desktop-toggle-button.c, src/hd-panel-window.c: - use these helpers Modified: projects/haf/trunk/hildon-desktop/ChangeLog =================================================================== --- projects/haf/trunk/hildon-desktop/ChangeLog 2007-06-07 10:37:30 UTC (rev 12170) +++ projects/haf/trunk/hildon-desktop/ChangeLog 2007-06-07 10:42:53 UTC (rev 12171) @@ -1,3 +1,13 @@ +2007-06-07 Johan Bilien <johan.bilien at nokia.com> + + * libhildondesktop/hildon-desktop-picture.[ch]: + - added + - helpers for creating XRender Pictures from pixbufs or pixmaps + * libhildondesktop/hildon-home-area.c, + libhildondesktop/hildon-desktop-toggle-button.c, + src/hd-panel-window.c: + - use these helpers + 2007-06-06 Moises Martinez <moises.martinez at nokia.com> * libhildondesktop/hildon-home-area.c: Added stdlib.h Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/Makefile.am =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/Makefile.am 2007-06-07 10:37:30 UTC (rev 12170) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/Makefile.am 2007-06-07 10:42:53 UTC (rev 12171) @@ -20,6 +20,7 @@ hildon-desktop-panel-expandable.h \ hildon-desktop-notification-manager.h \ hildon-desktop-toggle-button.h\ + hildon-desktop-picture.h \ statusbar-item.h \ statusbar-item-socket.h \ tasknavigator-item.h \ @@ -107,6 +108,8 @@ hildon-desktop-notification-manager.c \ hildon-desktop-toggle-button.h \ hildon-desktop-toggle-button.c \ + hildon-desktop-picture.c \ + hildon-desktop-picture.h \ statusbar-item.h \ statusbar-item.c \ statusbar-item-socket.h \ Added: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.c =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.c 2007-06-07 10:37:30 UTC (rev 12170) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.c 2007-06-07 10:42:53 UTC (rev 12171) @@ -0,0 +1,294 @@ +/* + * This file is part of hildon-desktop + * + * Copyright (C) 2007 Nokia Corporation. + * + * Author: Johan Bilien <johan.bilien at nokia.com> + * Contact: Karoliina Salminen <karoliina.t.salminen at nokia.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <X11/extensions/Xrender.h> +#include <gdk/gdkx.h> +#include <gdk/gdk.h> +#include <stdlib.h> /* malloc */ + +#include "hildon-desktop-picture.h" + +void +hildon_desktop_picture_and_mask_from_file (const gchar *filename, + Picture *picture, + Picture *mask, + gint *width, + gint *height) +{ + GError *error = NULL; + GdkPixbuf *pixbuf = NULL; + Pixmap pixmap = None, mask_pixmap = None; + gint pw, ph; + XRenderPictFormat *format; + XRenderPictureAttributes pa; + XImage *image = NULL, *mask_image = NULL; + char *data = NULL, *mask_data = NULL; + char *d = NULL, *md = NULL; + guchar *p = NULL, *line = NULL, *endofline, *end; + gint rowstride; + gboolean alpha, color; + GC gc; + XGCValues gc_values = {0}; + + g_return_if_fail (filename); + if (!picture && !mask) + return; + + pixbuf = gdk_pixbuf_new_from_file (filename, &error); + + if (error) + { + g_warning ("Could not load background image: %s", + error->message); + g_error_free (error); + return; + } + + pw = gdk_pixbuf_get_width (pixbuf); + ph = gdk_pixbuf_get_height (pixbuf); + alpha = gdk_pixbuf_get_has_alpha (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + +#if 0 + g_debug ("Loaded pixbuf from %s, %ix%i, alpha: %i, rawstride: %i", + background_name, + pw, + ph, + alpha, + rowstride); +#endif + + alpha = (alpha && mask != NULL); + color = (picture != NULL); + + gdk_error_trap_push (); + if (color) + pixmap = XCreatePixmap (GDK_DISPLAY (), + DefaultRootWindow (GDK_DISPLAY ()), + pw, + ph, + 32); + + if (alpha) + mask_pixmap = XCreatePixmap (GDK_DISPLAY (), + DefaultRootWindow (GDK_DISPLAY ()), + pw, + ph, + 8); + + if (gdk_error_trap_pop ()) + { + if (pixmap) + XFreePixmap (GDK_DISPLAY (), pixmap); + if (mask_pixmap) + XFreePixmap (GDK_DISPLAY (), mask_pixmap); + + g_object_unref (pixbuf); + return; + } + + if (color) + { + /* Use malloc here because it is freed by Xlib */ + data = (gchar *) malloc (pw*ph*4); + + image = XCreateImage (GDK_DISPLAY (), + None, + 32, /* depth */ + ZPixmap, + 0, /* offset */ + data, + pw, + ph, + 8, + pw * 4); + } + + if (alpha) + { + mask_data = (gchar*) malloc (pw*ph); + mask_image = XCreateImage (GDK_DISPLAY (), + None, + 8, /* depth */ + ZPixmap, + 0, /* offset */ + mask_data, + pw, + ph, + 8, + pw); + } + + p = gdk_pixbuf_get_pixels (pixbuf); + md = mask_data; + d = data; + end = p + rowstride*ph; + + for (line = p; line < end ; line += rowstride) + { + p = line; + endofline = p + (alpha?4:3) * pw; + + for (p = line; p < endofline; p += (alpha?4:3), md++, d+=4) + { + +#define r ((guint32)(*(p))) +#define g ((guint32)(*(p+1))) +#define b ((guint32)(*(p+2))) +#define a (*(p+3)) + if (color) + { + guint32 pixel = + ((r << 16) & 0x00FF0000 ) | + ((g << 8) & 0x0000FF00) | + ((b) & 0x000000FF ); + + pixel |= 0xFF000000; + + *((guint32 *)d) = pixel; + } + + if (alpha) + *md = a; + } +#undef r +#undef g +#undef b +#undef a + + } + + g_object_unref (pixbuf); + + gdk_error_trap_push (); + + if (color) + { + gc = XCreateGC (GDK_DISPLAY (), + pixmap, + 0, + &gc_values); + + XPutImage (GDK_DISPLAY (), + pixmap, + gc, + image, + 0, 0, + 0, 0, + pw, ph); + + XFreeGC (GDK_DISPLAY (), gc); + XDestroyImage (image); + } + + if (alpha) + { + gc = XCreateGC (GDK_DISPLAY (), + mask_pixmap, + 0, + &gc_values); + + XPutImage (GDK_DISPLAY (), + mask_pixmap, + gc, + mask_image, + 0, 0, + 0, 0, + pw, ph); + + XFreeGC (GDK_DISPLAY (), gc); + XDestroyImage (mask_image); + } + + + if (color) + { + format = XRenderFindStandardFormat (GDK_DISPLAY(), + PictStandardARGB32); + + pa.repeat = True; + *picture = XRenderCreatePicture (GDK_DISPLAY (), + pixmap, + format, + CPRepeat, + &pa); + XFreePixmap (GDK_DISPLAY (), + pixmap); + + } + + if (alpha) + { + format = XRenderFindStandardFormat (GDK_DISPLAY(), + PictStandardA8); + + *mask = XRenderCreatePicture (GDK_DISPLAY (), + mask_pixmap, + format, + CPRepeat, + &pa); + XFreePixmap (GDK_DISPLAY (), + mask_pixmap); + } + + if (width) + *width = pw; + + if (height) + *height = ph; + + if (gdk_error_trap_pop ()) + g_warning ("X Error while loading picture from file"); +} + +Picture +hildon_desktop_picture_from_drawable (GdkDrawable *drawable) +{ + Picture picture; + GdkVisual *visual; + XRenderPictFormat *format; + XRenderPictureAttributes pa = {0}; + + g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), None); + + visual = gdk_drawable_get_visual (drawable); + + format = XRenderFindVisualFormat (GDK_DISPLAY (), + GDK_VISUAL_XVISUAL (visual)); + + if (format == NULL) + return None; + + picture = XRenderCreatePicture (GDK_DISPLAY (), + GDK_DRAWABLE_XID (drawable), + format, + 0, + &pa); + + return picture; +} Added: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.h =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.h 2007-06-07 10:37:30 UTC (rev 12170) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.h 2007-06-07 10:42:53 UTC (rev 12171) @@ -0,0 +1,42 @@ +/* + * This file is part of hildon-desktop + * + * Copyright (C) 2007 Nokia Corporation. + * + * Author: Johan Bilien <johan bilien at nokia.com> + * Contact: Karoliina Salminen <karoliina.t.salminen at nokia.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#ifndef __HILDON_DESKTOP_PICTURE_H__ +#define __HILDON_DESKTOP_PICTURE_H__ + +#include <X11/extensions/Xrender.h> + +G_BEGIN_DECLS + +void hildon_desktop_picture_and_mask_from_file (const gchar *filename, + Picture *picture, + Picture *mask, + gint *width, + gint *height); + +Picture hildon_desktop_picture_from_drawable (GdkDrawable *drawable); + +G_END_DECLS + +#endif /* __HILDON_DESKTOP_TOGGLE_BUTTON_H__ */ Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-toggle-button.c =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-toggle-button.c 2007-06-07 10:37:30 UTC (rev 12170) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-toggle-button.c 2007-06-07 10:42:53 UTC (rev 12171) @@ -26,15 +26,12 @@ #include <config.h> #endif -#ifdef HAVE_X_COMPOSITE -#include <X11/extensions/Xrender.h> -#include <gdk/gdkx.h> -#include <stdlib.h> /* malloc */ -#endif - #include "hildon-desktop-toggle-button.h" #ifdef HAVE_X_COMPOSITE + +#include <libhildondesktop/hildon-desktop-picture.h> +#include <gdk/gdkx.h> static gboolean hildon_desktop_toggle_button_expose (GtkWidget *widget, GdkEventExpose *event); static void hildon_desktop_toggle_button_style_set (GtkWidget *widget, @@ -93,8 +90,6 @@ GdkVisual *visual; gint x_offset, y_offset; Picture picture = None; - XRenderPictFormat *format; - XRenderPictureAttributes pa = {0}; gboolean picture_is_ours = FALSE; button = GTK_BUTTON (widget); @@ -107,23 +102,13 @@ visual = gdk_drawable_get_visual (drawable); - format = XRenderFindVisualFormat (GDK_DISPLAY (), - GDK_VISUAL_XVISUAL (visual)); - - if (format == None) - return FALSE; - picture = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawable), "picture")); if (picture == None) { picture_is_ours = TRUE; - picture = XRenderCreatePicture (GDK_DISPLAY (), - GDK_DRAWABLE_XID (drawable), - format, - 0, - &pa); + picture = hildon_desktop_picture_from_drawable (drawable); } if (priv->pressed_picture != None && button->depressed) @@ -161,188 +146,6 @@ } static void -load_picture (const gchar *filename, - Window window, - Picture *picture, - Picture *mask) -{ - XRenderPictureAttributes pa = {}; - XRenderPictFormat *format; - GdkPixbuf *pixbuf; - GError *error = NULL; - gboolean alpha; - XImage *image, *mask_image = NULL; - Pixmap pixmap, mask_pixmap = None; - GC gc; - XGCValues gc_values = {0}; - gint pw, ph; - guchar *pdata; - gchar *data, *mask_data = NULL; - guint i; - - *picture = *mask = None; - - if (!filename) - return; - - pixbuf = gdk_pixbuf_new_from_file (filename, &error); - - if (error) - { - g_warning (error->message); - g_error_free (error); - return; - } - - alpha = gdk_pixbuf_get_has_alpha (pixbuf); - pw = gdk_pixbuf_get_width (pixbuf); - ph = gdk_pixbuf_get_height (pixbuf); - pdata = gdk_pixbuf_get_pixels (pixbuf); - - g_debug ("loaded pixbuf %s: \n%ix%i alpha: %i", filename, pw, ph, alpha); - - pixmap = XCreatePixmap (GDK_DISPLAY (), - window, - pw, - ph, - 32); - - if (alpha) - mask_pixmap = XCreatePixmap (GDK_DISPLAY (), - window, - pw, - ph, - 8); - - /* Use malloc here because it is freed by Xlib */ - data = (gchar *) malloc (pw*ph*4); - - image = XCreateImage (GDK_DISPLAY (), - None, - 32, - ZPixmap, - 0, /* offset */ - data, - pw, - ph, - 8, - pw * 4); - - format = XRenderFindStandardFormat (GDK_DISPLAY (), - PictStandardARGB32); - - if (alpha) - { - mask_data = (gchar *) malloc (pw*ph); - mask_image = XCreateImage (GDK_DISPLAY (), - None, - 8, /* depth */ - ZPixmap, - 0, /* offset */ - mask_data, - pw, - ph, - 8, - pw); - } - - for (i = 0; i < pw * ph; i++) - { - -#define r ((guint32)(pdata[(alpha?4:3)*i])) -#define g ((guint32)(pdata[(alpha?4:3)*i+1])) -#define b ((guint32)(pdata[(alpha?4:3)*i+2])) -#define a ((pdata[4*i+3])) - guint32 pixel = - ((r << 16) & 0x00FF0000 ) | - ((g << 8) & 0x0000FF00) | - ((b) & 0x000000FF ); - - -#if 0 - /* FIXME: Treat non-RGBA visuals */ - if (visual->depth == 32) - pixel |= ((a << 24) & 0xFF000000); -#endif - - ((guint32 *)data)[i] = pixel; - - if (alpha) - mask_data[i] = a; -#undef r -#undef g -#undef b -#undef a - - } - - gc = XCreateGC (GDK_DISPLAY (), - pixmap, - 0, - &gc_values); - - XPutImage (GDK_DISPLAY (), - pixmap, - gc, - image, - 0, 0, - 0, 0, - pw, ph); - - XFreeGC (GDK_DISPLAY (), gc); - XDestroyImage (image); - - if (alpha) - { - gc = XCreateGC (GDK_DISPLAY (), - mask_pixmap, - 0, - &gc_values); - - XPutImage (GDK_DISPLAY (), - mask_pixmap, - gc, - mask_image, - 0, 0, - 0, 0, - pw, ph); - - XFreeGC (GDK_DISPLAY (), gc); - XDestroyImage (mask_image); - } - - g_object_unref (pixbuf); - pa.repeat = True; - *picture = XRenderCreatePicture (GDK_DISPLAY (), - pixmap, - format, - CPRepeat, - &pa); - - XFreePixmap (GDK_DISPLAY (), - pixmap); - - if (alpha) - { - XRenderPictFormat *mask_format; - - mask_format = XRenderFindStandardFormat (GDK_DISPLAY(), - PictStandardA8); - - *mask = XRenderCreatePicture (GDK_DISPLAY (), - mask_pixmap, - mask_format, - CPRepeat, - &pa); - - XFreePixmap (GDK_DISPLAY (), - mask_pixmap); - - } - -} - -static void hildon_desktop_toggle_button_style_set (GtkWidget *widget, GtkStyle *old_style) { HildonDesktopToggleButtonPrivate *priv = @@ -366,12 +169,11 @@ priv->focus_picture_mask = None; } - load_picture (widget->style->rc_style->bg_pixmap_name[GTK_STATE_PRELIGHT], - GDK_WINDOW_XID (widget->window), - &priv->focus_picture, - &priv->focus_picture_mask); + hildon_desktop_picture_and_mask_from_file (widget->style->rc_style->bg_pixmap_name[GTK_STATE_PRELIGHT], + &priv->focus_picture, + &priv->focus_picture_mask, + NULL, NULL); - if (priv->pressed_picture != None) { XRenderFreePicture (GDK_DISPLAY (), @@ -386,10 +188,10 @@ priv->pressed_picture_mask = None; } - load_picture (widget->style->rc_style->bg_pixmap_name[GTK_STATE_ACTIVE], - GDK_WINDOW_XID (widget->window), - &priv->pressed_picture, - &priv->pressed_picture_mask); + hildon_desktop_picture_and_mask_from_file (widget->style->rc_style->bg_pixmap_name[GTK_STATE_ACTIVE], + &priv->pressed_picture, + &priv->pressed_picture_mask, + NULL, NULL); } static void Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-home-area.c =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-home-area.c 2007-06-07 10:37:30 UTC (rev 12170) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-home-area.c 2007-06-07 10:42:53 UTC (rev 12171) @@ -34,6 +34,8 @@ #include <X11/extensions/Xcomposite.h> #include <X11/extensions/Xdamage.h> #include <X11/extensions/Xrender.h> + +#include <libhildondesktop/hildon-desktop-picture.h> #endif #include <errno.h> @@ -1051,15 +1053,7 @@ GtkWidget *child) { HildonHomeAreaPriv *priv; - GdkPixbuf *pixbuf = NULL; - GC gc; - XGCValues gc_values; - XRenderPictureAttributes pa; - XRenderPictFormat *format; - XImage *image; - Pixmap pixmap; ChildData *child_data; - GError *error = NULL; const gchar *mask_file_name = NULL; priv = HILDON_HOME_AREA_GET_PRIVATE (area); @@ -1079,117 +1073,15 @@ mask_file_name = child->style->rc_style->bg_pixmap_name[GTK_STATE_PRELIGHT]; - if (mask_file_name) - { - pixbuf = gdk_pixbuf_new_from_file (mask_file_name, - &error); - } + if (!mask_file_name) + return; - if (error) - { - g_warning ("Could not open alpha mask from style: %s", error->message); - g_error_free (error); + hildon_desktop_picture_and_mask_from_file (mask_file_name, + NULL, + &child_data->alpha_mask_unscaled, + &child_data->background_width, + &child_data->background_height); - pixbuf = NULL; - } - - if (pixbuf) - { - gchar *data; - guchar *pixbuf_data; - guint i; - gint pw, ph; - - child_data->background_width = pw = gdk_pixbuf_get_width (pixbuf); - child_data->background_height = ph = gdk_pixbuf_get_height (pixbuf); - - pixmap = XCreatePixmap (GDK_DISPLAY (), - GDK_WINDOW_XID (GTK_WIDGET (area)->window), - pw, - ph, - 8); - - /* Use malloc here because it is freed by Xlib */ - data = (gchar *) malloc (pw*ph); - - image = XCreateImage (GDK_DISPLAY (), - None, - 8, /* depth */ - ZPixmap, - 0, /* offset */ - data, - pw, - ph, - 8, - pw); - - pixbuf_data = gdk_pixbuf_get_pixels (pixbuf); - - for (i = 0; i < pw * ph; i++) - { - data[i] = pixbuf_data[4*i + 3]; - } - - gc = XCreateGC (GDK_DISPLAY (), - pixmap, - 0, - &gc_values); - - XPutImage (GDK_DISPLAY (), - pixmap, - gc, - image, - 0, 0, - 0, 0, - pw, ph); - - XFreeGC (GDK_DISPLAY (), gc); - XDestroyImage (image); - g_object_unref (pixbuf); - } - else - { - pixmap = XCreatePixmap (GDK_DISPLAY (), - GDK_WINDOW_XID (GTK_WIDGET (area)->window), - 1, - 1, - 8); - } - - if (pixmap == None) - { - g_warning ("Could not create pixmap for alpha_channel"); - return; - } - - format = XRenderFindStandardFormat (GDK_DISPLAY (), - PictStandardA8); - - pa.repeat = True; - child_data->alpha_mask_unscaled = XRenderCreatePicture (GDK_DISPLAY (), - pixmap, - format, - CPRepeat, - &pa); - - if (!pixbuf) - { - XRenderColor c = {0}; - -/* c.alpha = priv->default_alpha * 0xffff;*/ - c.alpha = 0xFFFF; - - XRenderFillRectangle (GDK_DISPLAY (), - PictOpSrc, - child_data->alpha_mask_unscaled, - &c, - 0, 0, 1, 1); - - child_data->alpha_mask_unscaled = None; - } - - XFreePixmap (GDK_DISPLAY (), pixmap); - } static void @@ -1433,8 +1325,6 @@ XRectangle rectangle; XserverRegion region; GdkDrawable *drawable; - XRenderPictFormat *format; - XRenderPictureAttributes pa; Window *wchildren, root, parent; int n_children, i; @@ -1448,17 +1338,8 @@ rectangle.width = event->area.width; rectangle.height = event->area.height; - format = XRenderFindVisualFormat (GDK_DISPLAY(), - GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (drawable))); + priv->picture = hildon_desktop_picture_from_drawable (drawable); - pa.subwindow_mode = IncludeInferiors; - - priv->picture = XRenderCreatePicture (GDK_DISPLAY (), - GDK_DRAWABLE_XID (drawable), - format, - CPSubwindowMode, - &pa); - region = XFixesCreateRegion (GDK_DISPLAY (), &rectangle, 1); Modified: projects/haf/trunk/hildon-desktop/src/hd-panel-window.c =================================================================== --- projects/haf/trunk/hildon-desktop/src/hd-panel-window.c 2007-06-07 10:37:30 UTC (rev 12170) +++ projects/haf/trunk/hildon-desktop/src/hd-panel-window.c 2007-06-07 10:42:53 UTC (rev 12171) @@ -34,14 +34,12 @@ #include "hd-panel-window.h" #ifdef HAVE_X_COMPOSITE -#include <X11/extensions/Xrender.h> +#include <libhildondesktop/hildon-desktop-picture.h> #include <X11/extensions/Xdamage.h> #include <X11/extensions/Xcomposite.h> #include <gdk/gdkx.h> -#include <stdlib.h> /*malloc*/ - #include <libhildonwm/hd-wm.h> #endif @@ -79,207 +77,34 @@ { HDPanelWindowPrivate *priv = HD_PANEL_WINDOW (widget)->priv; const gchar *filename; - XRenderPictFormat *format; - XRenderPictureAttributes pa; - GdkPixbuf *pixbuf = NULL; - XImage *image = NULL, *mask_image = NULL; - Pixmap pixmap = None, mask_pixmap = None; - GC gc; - XGCValues gc_values = {0}; - guchar *p = NULL, *line = NULL, *endofline, *end; - char *data = NULL, *mask_data = NULL, *d, *md; - GError *error = NULL; - gint pw, ph, rowstride; - gboolean alpha; if (!GTK_WIDGET_REALIZED (widget) || !widget->style || !widget->style->rc_style) return; - if (priv->background_picture) + if (priv->background_picture != None) { XRenderFreePicture (GDK_DISPLAY (), priv->background_picture); priv->background_picture = None; } + if (priv->background_mask != None) + { + XRenderFreePicture (GDK_DISPLAY (), + priv->background_mask); + priv->background_mask = None; + } + filename = widget->style->rc_style->bg_pixmap_name[GTK_STATE_NORMAL]; if (!filename) return; - pixbuf = gdk_pixbuf_new_from_file (filename, &error); - - if (error) - { - g_warning ("Could not load background image: %s", - error->message); - g_error_free (error); - return; - } - - - pw = gdk_pixbuf_get_width (pixbuf); - ph = gdk_pixbuf_get_height (pixbuf); - alpha = gdk_pixbuf_get_has_alpha (pixbuf); - rowstride = gdk_pixbuf_get_rowstride (pixbuf); - - g_debug ("Loaded: %s, %ix%i, rowstride: %i, alpha: %i", - filename, - pw, - ph, - rowstride, - alpha); - - pixmap = XCreatePixmap (GDK_DISPLAY (), - GDK_WINDOW_XID (widget->window), - pw, - ph, - 32); - - if (alpha) - mask_pixmap = XCreatePixmap (GDK_DISPLAY (), - GDK_WINDOW_XID (widget->window), - pw, - ph, - 8); - - /* Use malloc here because it is freed by Xlib */ - data = (gchar *) malloc (pw*ph*4); - - image = XCreateImage (GDK_DISPLAY (), - None, - 32, /* depth */ - ZPixmap, - 0, /* offset */ - data, - pw, - ph, - 8, - pw * 4); - - if (alpha) - { - mask_data = (gchar*) malloc (pw*ph); - mask_image = XCreateImage (GDK_DISPLAY (), - None, - 8, /* depth */ - ZPixmap, - 0, /* offset */ - mask_data, - pw, - ph, - 8, - pw); - } - - p = gdk_pixbuf_get_pixels (pixbuf); - md = mask_data; - d = data; - end = p + rowstride*ph; - - for (line = p; line < end ; line += rowstride) - { - p = line; - endofline = p + (alpha?4:3) * pw; - - for (p = line; p < endofline; p += (alpha?4:3), md++, d+=4) - { - -#define r ((guint32)(*(p))) -#define g ((guint32)(*(p+1))) -#define b ((guint32)(*(p+2))) -#define a (*(p+3)) - guint32 pixel = - ((r << 16) & 0x00FF0000 ) | - ((g << 8) & 0x0000FF00) | - ((b) & 0x000000FF ); - - pixel |= 0xFF000000; - - *((guint32 *)d) = pixel; - - if (alpha) - *md = a; - } -#undef r -#undef g -#undef b -#undef a - - } - - - gc = XCreateGC (GDK_DISPLAY (), - pixmap, - 0, - &gc_values); - - XPutImage (GDK_DISPLAY (), - pixmap, - gc, - image, - 0, 0, - 0, 0, - pw, ph); - - XFreeGC (GDK_DISPLAY (), gc); - XDestroyImage (image); - - if (alpha) - { - gc = XCreateGC (GDK_DISPLAY (), - mask_pixmap, - 0, - &gc_values); - - XPutImage (GDK_DISPLAY (), - mask_pixmap, - gc, - mask_image, - 0, 0, - 0, 0, - pw, ph); - - XFreeGC (GDK_DISPLAY (), gc); - XDestroyImage (mask_image); - } - - - g_object_unref (pixbuf); - - format = XRenderFindStandardFormat (GDK_DISPLAY(), - PictStandardARGB32); - - pa.repeat = True; - priv->background_picture = XRenderCreatePicture (GDK_DISPLAY (), - pixmap, - format, - CPRepeat, - &pa); - - if (alpha) - { - format = XRenderFindStandardFormat (GDK_DISPLAY(), - PictStandardA8); - - priv->background_mask = XRenderCreatePicture (GDK_DISPLAY (), - mask_pixmap, - format, - CPRepeat, - &pa); - } - - - XFreePixmap (GDK_DISPLAY (), - pixmap); - - if (alpha) - { - XFreePixmap (GDK_DISPLAY (), - mask_pixmap); - } - + hildon_desktop_picture_and_mask_from_file (filename, + &priv->background_picture, + &priv->background_mask, + NULL, NULL); } static void @@ -300,9 +125,6 @@ GdkDrawable *drawable; gint x_offset, y_offset; Picture picture; - GdkVisual *visual; - XRenderPictFormat *format; - XRenderPictureAttributes pa = {0}; gboolean result; gdk_window_get_internal_paint_info (widget->window, @@ -310,17 +132,8 @@ &x_offset, &y_offset); - visual = gdk_drawable_get_visual (drawable); + picture = hildon_desktop_picture_from_drawable (drawable); - format = XRenderFindVisualFormat (GDK_DISPLAY (), - GDK_VISUAL_XVISUAL (visual)); - - picture = XRenderCreatePicture (GDK_DISPLAY (), - GDK_DRAWABLE_XID (drawable), - format, - 0, - &pa); - g_object_set_data (G_OBJECT (drawable), "picture", GINT_TO_POINTER (picture)); @@ -363,7 +176,7 @@ } -return FALSE; + return FALSE; } static gboolean @@ -475,46 +288,30 @@ if (desktop_window != None) { - XRenderPictureAttributes pa = {0}; - XRenderPictFormat *format; - XWindowAttributes wa = {0}; - Status s; - gdk_error_trap_push (); - s = XGetWindowAttributes (GDK_DISPLAY (), - desktop_window, - &wa); - if (gdk_error_trap_pop () || s == 0) - { - g_warning ("Could not retrieve window attributes for the desktop " - "window"); - return; - } - - format = XRenderFindVisualFormat (GDK_DISPLAY (), - wa.visual); - - if (format == None) - return; - XCompositeRedirectWindow (GDK_DISPLAY (), desktop_window, CompositeRedirectAutomatic); - priv->home_picture = XRenderCreatePicture (GDK_DISPLAY (), - desktop_window, - format, - 0, - &pa); - priv->home_damage = XDamageCreate (GDK_DISPLAY (), desktop_window, XDamageReportNonEmpty); + if (gdk_error_trap_pop ()) + { + g_warning ("Could not redirect the desktop " + "window"); + return; + } + priv->home_gwindow = gdk_window_foreign_new (desktop_window); + if (GDK_IS_WINDOW (priv->home_gwindow)) { + priv->home_picture = + hildon_desktop_picture_from_drawable (priv->home_gwindow); + gdk_window_add_filter (priv->home_gwindow, (GdkFilterFunc) hd_panel_window_home_window_filter, @@ -683,11 +480,6 @@ window); } -#if 0 - gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); - gtk_widget_set_double_buffered (GTK_WIDGET (window), FALSE); -#endif - window->priv = HD_PANEL_WINDOW_GET_PRIVATE (window); #endif }
- Previous message: [maemo-commits] r12170 - in projects/haf/tags/hildon-plugin-settings: . 0.0.1 0.0.1/data 0.0.1/debian 0.0.1/src
- Next message: [maemo-commits] r12172 - in projects/haf/trunk/hildon-desktop: . policies
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]