[maemo-commits] [maemo-commits] r13629 - in projects/haf/trunk/hildon-desktop: . background-manager libhildondesktop src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu Sep 6 09:34:49 EEST 2007
- Previous message: [maemo-commits] r13628 - projects/haf/tags/hildon-application-framework
- Next message: [maemo-commits] r13630 - in projects/haf/trunk/hildon-desktop: . libhildondesktop
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: jobi Date: 2007-09-06 09:34:46 +0300 (Thu, 06 Sep 2007) New Revision: 13629 Modified: projects/haf/trunk/hildon-desktop/ChangeLog projects/haf/trunk/hildon-desktop/background-manager/background-manager.c projects/haf/trunk/hildon-desktop/background-manager/background-manager.h projects/haf/trunk/hildon-desktop/background-manager/background-manager.xml.in projects/haf/trunk/hildon-desktop/background-manager/hbm-background.c projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.c projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.h projects/haf/trunk/hildon-desktop/src/hd-home-background.c Log: 2007-09-06 Johan Bilien <johan.bilien at nokia.com> * libhildondesktop/hildon-desktop-picture.[ch]: - added _picture_from_color * background-manager/background-manager.{c,h,xml.in}: - pass the picture identifier as argument, the picture is now expected to be created on client side - don't pass the background color any longer * background-manager/hbm-background.[ch]: - added picture property - do not create a new picture but paint on the provided one * src/hd-home-background.c: create a picture before passing it to the background manager. Fixes: NB#66928 Modified: projects/haf/trunk/hildon-desktop/ChangeLog =================================================================== --- projects/haf/trunk/hildon-desktop/ChangeLog 2007-09-05 16:37:46 UTC (rev 13628) +++ projects/haf/trunk/hildon-desktop/ChangeLog 2007-09-06 06:34:46 UTC (rev 13629) @@ -1,3 +1,18 @@ +2007-09-06 Johan Bilien <johan.bilien at nokia.com> + + * libhildondesktop/hildon-desktop-picture.[ch]: + - added _picture_from_color + * background-manager/background-manager.{c,h,xml.in}: + - pass the picture identifier as argument, the picture is now + expected to be created on client side + - don't pass the background color any longer + * background-manager/hbm-background.[ch]: + - added picture property + - do not create a new picture but paint on the provided one + * src/hd-home-background.c: create a picture before passing + it to the background manager. + Fixes: NB#66928 + 2007-09-05 Johan Bilien <johan.bilien at nokia.com> * libhildondesktop/hildon-home-area.[ch]: removed the "batch_add" Modified: projects/haf/trunk/hildon-desktop/background-manager/background-manager.c =================================================================== --- projects/haf/trunk/hildon-desktop/background-manager/background-manager.c 2007-09-05 16:37:46 UTC (rev 13628) +++ projects/haf/trunk/hildon-desktop/background-manager/background-manager.c 2007-09-06 06:34:46 UTC (rev 13629) @@ -93,22 +93,17 @@ /* RPC method */ gboolean background_manager_set_background (BackgroundManager *manager, - gint window_xid, + gint picture, + guint width, + guint height, const gchar *filename, const gchar *cache, - guint16 red, - guint16 green, - guint16 blue, BackgroundMode mode, - gint *picture_xid, GError **error) { - HBMBackground *background; + HildonDesktopBackground *background; GdkDisplay *display; - GdkColor color; - GdkWindow *window; GError *local_error = NULL; - gint width, height; const gchar *display_name; g_debug ("set_background on %s, cache as %s", filename, cache); @@ -136,35 +131,18 @@ return FALSE; } - window = gdk_window_foreign_new_for_display (display, window_xid); - - if (!window) - { - g_set_error (error, - background_manager_error_quark (), - BACKGROUND_MANAGER_ERROR_WINDOW, - "Window %x not found", - window_xid); - return FALSE; - } - - color.red = red; - color.blue = blue; - color.green = green; - - gdk_drawable_get_size (GDK_DRAWABLE (window), &width, &height); - background = g_object_new (HBM_TYPE_BACKGROUND, + "picture", picture, "filename", filename, "cache", cache, "mode", mode, - "color", &color, "width", width, "height", height, "display", display, NULL); - *picture_xid = hbm_background_render (background, &local_error); + hildon_desktop_background_apply (background, NULL, &local_error); + g_idle_add ((GSourceFunc)g_main_loop_quit, main_loop); if (local_error) @@ -173,7 +151,6 @@ return FALSE; } - XSetCloseDownMode (GDK_DISPLAY_XDISPLAY(display), RetainTemporary); gdk_flush (); gdk_display_close (display); Modified: projects/haf/trunk/hildon-desktop/background-manager/background-manager.h =================================================================== --- projects/haf/trunk/hildon-desktop/background-manager/background-manager.h 2007-09-05 16:37:46 UTC (rev 13628) +++ projects/haf/trunk/hildon-desktop/background-manager/background-manager.h 2007-09-06 06:34:46 UTC (rev 13629) @@ -95,14 +95,12 @@ gboolean background_manager_set_background (BackgroundManager *manager, - gint window_xid, + gint picture, + guint width, + guint height, const gchar *filename, const gchar *cache, - guint16 red, - guint16 green, - guint16 blue, BackgroundMode mode, - gint *pixmap_xid, GError **error); Modified: projects/haf/trunk/hildon-desktop/background-manager/background-manager.xml.in =================================================================== --- projects/haf/trunk/hildon-desktop/background-manager/background-manager.xml.in 2007-09-05 16:37:46 UTC (rev 13628) +++ projects/haf/trunk/hildon-desktop/background-manager/background-manager.xml.in 2007-09-06 06:34:46 UTC (rev 13629) @@ -3,14 +3,12 @@ <node name="/"> <interface name="@HILDON_BACKGROUND_MANAGER_INTERFACE@"> <method name="SetBackground"> - <arg type="i" name="window_id"/> + <arg type="i" name="picture_id"/> + <arg type="i" name="width"/> + <arg type="i" name="height"/> <arg type="s" name="filename"/> <arg type="s" name="cache"/> - <arg type="i" name="red"/> - <arg type="i" name="green"/> - <arg type="i" name="blue"/> <arg type="i" name="mode"/> - <arg type="i" direction="out" name="pixmap_id"/> </method> </interface> </node> Modified: projects/haf/trunk/hildon-desktop/background-manager/hbm-background.c =================================================================== --- projects/haf/trunk/hildon-desktop/background-manager/hbm-background.c 2007-09-05 16:37:46 UTC (rev 13628) +++ projects/haf/trunk/hildon-desktop/background-manager/hbm-background.c 2007-09-06 06:34:46 UTC (rev 13629) @@ -65,12 +65,17 @@ static void hbm_background_finalize (GObject *object); +static void hbm_background_apply (HildonDesktopBackground *background, + GdkWindow *window, + GError **error); + enum { PROP_WIDTH = 1, PROP_HEIGHT, - PROP_DISPLAY + PROP_DISPLAY, + PROP_PICTURE }; struct _HBMBackgroundPrivate @@ -110,15 +115,19 @@ static void hbm_background_class_init (HBMBackgroundClass *klass) { - GObjectClass *object_class; - GParamSpec *pspec; + GObjectClass *object_class; + HildonDesktopBackgroundClass *background_class; + GParamSpec *pspec; object_class = G_OBJECT_CLASS (klass); + background_class = HILDON_DESKTOP_BACKGROUND_CLASS (klass); object_class->set_property = hbm_background_set_property; object_class->get_property = hbm_background_get_property; object_class->finalize = hbm_background_finalize; + background_class->apply = hbm_background_apply; + pspec = g_param_spec_int ("width", "width", "Width of the background to render", @@ -154,6 +163,19 @@ PROP_DISPLAY, pspec); + pspec = g_param_spec_int ("picture", + "picture", + "The Picture XID on which the image shall be " + "rendered", + 0, + G_MAXINT, + None, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT); + + g_object_class_install_property (object_class, + PROP_PICTURE, + pspec); + g_type_class_add_private (klass, sizeof (HBMBackgroundPrivate)); } @@ -183,6 +205,9 @@ case PROP_DISPLAY: priv->display = g_value_get_object (value); break; + case PROP_PICTURE: + priv->picture = (Picture)g_value_get_int (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -209,6 +234,9 @@ case PROP_DISPLAY: g_value_set_object (value, priv->display); break; + case PROP_PICTURE: + g_value_set_int (value, (gint)priv->picture); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -594,58 +622,6 @@ } static void -hbm_background_create_picture (HBMBackground *background) -{ - HBMBackgroundPrivate *priv = background->priv; - XRenderPictFormat *format; - XRenderPictureAttributes pa = {0}; - XRenderColor color = {0}; - Pixmap pixmap; - Display *xdisplay; - GdkColor *gcolor = NULL; - - xdisplay = GDK_DISPLAY_XDISPLAY (priv->display); - - pixmap = XCreatePixmap (xdisplay, - DefaultRootWindow (xdisplay), - priv->width, - priv->height, - 24); - - pa.repeat = True; - - format = XRenderFindStandardFormat (xdisplay, PictStandardRGB24); - priv->picture = XRenderCreatePicture (xdisplay, - pixmap, - format, - CPRepeat, - &pa); - - g_object_get (background, - "color", &gcolor, - NULL); - - color.alpha = 0xFFFF; - - if (gcolor) - { - color.red = gcolor->red; - color.green = gcolor->green; - color.blue = gcolor->blue; - } - - XRenderFillRectangle (xdisplay, - PictOpSrc, - priv->picture, - &color, - 0, 0, - priv->width, priv->height); - - XFreePixmap (xdisplay, pixmap); - -} - -static void hbm_background_crop_pixbuf (HBMBackground *background) { HBMBackgroundPrivate *priv = background->priv; @@ -802,32 +778,30 @@ } -Picture -hbm_background_render (HBMBackground *background, GError **error) +static void +hbm_background_apply (HildonDesktopBackground *background, + GdkWindow *window, + GError **error) { - HBMBackgroundPrivate *priv = background->priv; + HBMBackgroundPrivate *priv = HBM_BACKGROUND (background)->priv; GError *local_error = NULL; - g_return_val_if_fail (HBM_IS_BACKGROUND (background), None); - - hbm_background_load_pixbuf (background, &local_error); + hbm_background_load_pixbuf (HBM_BACKGROUND (background), &local_error); if (local_error) goto error; if (priv->pixbuf) - hbm_background_crop_pixbuf (background); + { + hbm_background_crop_pixbuf (HBM_BACKGROUND (background)); + hbm_background_composite_pixbuf (HBM_BACKGROUND (background)); + } - hbm_background_create_picture (background); + return; - if (priv->pixbuf) - hbm_background_composite_pixbuf (background); - - return priv->picture; - error: g_debug ("Got error %i %i %s", local_error->domain, local_error->code, local_error->message); g_propagate_error (error, local_error); - return None; + return; } Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.c =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.c 2007-09-05 16:37:46 UTC (rev 13628) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.c 2007-09-06 06:34:46 UTC (rev 13629) @@ -320,3 +320,63 @@ return picture; } + +Picture +hildon_desktop_picture_from_color (GdkColor *gcolor, + guint width, + guint height) +{ + Picture picture; + XRenderPictFormat *format = NULL; + XRenderPictureAttributes pa = {0}; + XRenderColor color = {0}; + Pixmap pixmap; + + g_return_val_if_fail (gcolor, None); + + gdk_error_trap_push (); + pixmap = XCreatePixmap (GDK_DISPLAY (), + DefaultRootWindow (GDK_DISPLAY ()), + width, + height, + /* FIXME: Give depth as argument */ + 24); + if (gdk_error_trap_pop ()) goto x_error; + + pa.repeat = True; + format = XRenderFindStandardFormat (GDK_DISPLAY (), PictStandardRGB24); + + g_return_val_if_fail (format, None); + + gdk_error_trap_push (); + picture = XRenderCreatePicture (GDK_DISPLAY (), + pixmap, + format, + CPRepeat, + &pa); + + if (gdk_error_trap_pop ()) goto x_error; + + color.alpha = 0xFFFF; + color.red = gcolor->red; + color.green = gcolor->green; + color.blue = gcolor->blue; + + gdk_error_trap_push (); + XRenderFillRectangle (GDK_DISPLAY (), + PictOpSrc, + picture, + &color, + 0, 0, + width, height); + if (gdk_error_trap_pop ()) goto x_error; + + XFreePixmap (GDK_DISPLAY (), pixmap); + + return picture; + +x_error: + g_critical ("X Error when creating picture from picture from color"); + return None; + +} Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.h =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.h 2007-09-05 16:37:46 UTC (rev 13628) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-picture.h 2007-09-06 06:34:46 UTC (rev 13629) @@ -42,6 +42,10 @@ Picture hildon_desktop_picture_from_drawable (GdkDrawable *drawable); +Picture hildon_desktop_picture_from_color (GdkColor *color, + guint width, + guint height); + G_END_DECLS #endif /* __HILDON_DESKTOP_TOGGLE_BUTTON_H__ */ Modified: projects/haf/trunk/hildon-desktop/src/hd-home-background.c =================================================================== --- projects/haf/trunk/hildon-desktop/src/hd-home-background.c 2007-09-05 16:37:46 UTC (rev 13628) +++ projects/haf/trunk/hildon-desktop/src/hd-home-background.c 2007-09-06 06:34:46 UTC (rev 13629) @@ -25,6 +25,8 @@ #include "hd-home-background.h" #include "background-manager/hildon-background-manager.h" +#include <libhildondesktop/hildon-desktop-picture.h> + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -401,13 +403,14 @@ DBusGProxy *background_manager_proxy; DBusGConnection *connection; GError *local_error = NULL; - gint pixmap_xid; gint32 top_offset, bottom_offset, right_offset, left_offset; gchar *filename; gchar *cache; gchar *new_cache = NULL; gchar *file_to_use; + guint width, height; GdkColor *color; + Picture picture; HildonDesktopBackgroundMode mode; g_return_if_fail (HD_IS_HOME_BACKGROUND (background) && window); @@ -442,6 +445,10 @@ file_to_use = filename; } + gdk_drawable_get_size (window, &width, &height); + picture = hildon_desktop_picture_from_color (color, width, height); + g_return_if_fail (picture != None); + background_manager_proxy = dbus_g_proxy_new_for_name (connection, HILDON_BACKGROUND_MANAGER_SERVICE, @@ -451,17 +458,18 @@ top_offset = bottom_offset = right_offset = left_offset = 0; #define S(string) (string?string:"") org_maemo_hildon_background_manager_set_background (background_manager_proxy, - GDK_WINDOW_XID (window), + picture, + width, + height, S(file_to_use), S(cache), - color->red, - color->green, - color->blue, mode, - &pixmap_xid, error); #undef S + if (error) + XRenderFreePicture (GDK_DISPLAY (), picture); + if (new_cache && !error) g_object_set (background, "cache", new_cache, @@ -478,33 +486,29 @@ gpointer user_data; GdkWindow *window; gchar *new_cache; + Picture picture; }; static void hd_home_background_apply_async_dbus_callback (DBusGProxy *proxy, - gint picture_id, GError *error, struct cb_data *data) { if (data->background->priv->cancelled) { + XRenderFreePicture (GDK_DISPLAY (), data->picture); g_free (data); return; } if (error) { + XRenderFreePicture (GDK_DISPLAY (), data->picture); goto cleanup; } - if (!picture_id) - { - g_warning ("No picture id returned"); - goto cleanup; - } - cleanup: if (!error && data->new_cache) g_object_set (data->background, @@ -513,7 +517,7 @@ if (data->callback) data->callback (HILDON_DESKTOP_BACKGROUND (data->background), - picture_id, + data->picture, error, data->user_data); @@ -540,6 +544,7 @@ gchar *new_cache = NULL; gchar *file_to_use; GdkColor *color; + guint width, height; HildonDesktopBackgroundMode mode; g_return_if_fail (HD_IS_HOME_BACKGROUND (background) && window); @@ -592,6 +597,8 @@ file_to_use = filename; } + gdk_drawable_get_size (window, &width, &height); + data = g_new (struct cb_data, 1); data->callback = cb; @@ -599,19 +606,21 @@ data->user_data = user_data; data->window = window; data->new_cache = new_cache; + data->picture = hildon_desktop_picture_from_color (color, width, height); + g_return_if_fail (data->picture != None); + priv->cancelled = FALSE; /* Here goes */ #define S(string) (string?string:"") org_maemo_hildon_background_manager_set_background_async (background_manager_proxy, - GDK_WINDOW_XID (window), + data->picture, + width, + height, S(file_to_use), S(cache), - color->red, - color->green, - color->blue, mode, (org_maemo_hildon_background_manager_set_background_reply) hd_home_background_apply_async_dbus_callback, data);
- Previous message: [maemo-commits] r13628 - projects/haf/tags/hildon-application-framework
- Next message: [maemo-commits] r13630 - in projects/haf/trunk/hildon-desktop: . libhildondesktop
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]