[maemo-commits] [maemo-commits] r13632 - in projects/haf/trunk/hildon-home-webshortcut: . plugin

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu Sep 6 10:00:31 EEST 2007
Author: jobi
Date: 2007-09-06 10:00:29 +0300 (Thu, 06 Sep 2007)
New Revision: 13632

Modified:
   projects/haf/trunk/hildon-home-webshortcut/ChangeLog
   projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.c
   projects/haf/trunk/hildon-home-webshortcut/plugin/hildon-home-webshortcut.c
Log:

2007-09-06  Johan Bilien  <johan.bilien at nokia.com>

	* plugin/hws-background.c:
	- ported to new background-manager API
	- create the picture on client side and pass it to background-manager
	for drawing
	* plugin/hildon-home-webshortcut.c:
	- apply the background in both _realize or _size_allocate, whoever
	comes last



Modified: projects/haf/trunk/hildon-home-webshortcut/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-home-webshortcut/ChangeLog	2007-09-06 06:58:24 UTC (rev 13631)
+++ projects/haf/trunk/hildon-home-webshortcut/ChangeLog	2007-09-06 07:00:29 UTC (rev 13632)
@@ -1,3 +1,13 @@
+2007-09-06  Johan Bilien  <johan.bilien at nokia.com>
+
+	* plugin/hws-background.c:
+	- ported to new background-manager API
+	- create the picture on client side and pass it to background-manager
+	for drawing
+	* plugin/hildon-home-webshortcut.c:
+	- apply the background in both _realize or _size_allocate, whoever
+	comes last
+
 2007-08-31  Johan Bilien  <johan.bilien at nokia.com>
 
 	* configure.ac: 1.9.6

Modified: projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.c
===================================================================
--- projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.c	2007-09-06 06:58:24 UTC (rev 13631)
+++ projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.c	2007-09-06 07:00:29 UTC (rev 13632)
@@ -25,6 +25,7 @@
 #include "hhws-background.h"
 
 #include <libhildondesktop/hildon-background-manager.h>
+#include <libhildondesktop/hildon-desktop-picture.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -259,13 +260,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;
   GdkColor             *color;
+  guint                 width, height;
+  Picture               picture;
   HildonDesktopBackgroundMode   mode;
 
   g_return_if_fail (HHWS_IS_BACKGROUND (background) && window);
@@ -300,6 +302,13 @@
     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,
@@ -309,14 +318,12 @@
   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
 
@@ -325,6 +332,9 @@
                   "cache", new_cache,
                   NULL);
 
+  if (error)
+    XRenderFreePicture (GDK_DISPLAY (), picture);
+
   g_free (new_cache);
 
 }
@@ -336,33 +346,28 @@
   gpointer                              user_data;
   GdkWindow                            *window;
   gchar                                *new_cache;
+  Picture                               picture;
 };
 
 
 static void
 hhws_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,
@@ -371,7 +376,7 @@
 
   if (data->callback)
     data->callback (HILDON_DESKTOP_BACKGROUND (data->background),
-                    picture_id,
+                    data->picture,
                     error,
                     data->user_data);
 
@@ -398,6 +403,7 @@
   gchar                    *new_cache = NULL;
   gchar                    *file_to_use;
   GdkColor                 *color;
+  guint                     width, height;
   HildonDesktopBackgroundMode   mode;
 
   g_return_if_fail (HHWS_IS_BACKGROUND (background) && window);
@@ -449,6 +455,8 @@
     file_to_use = filename;
   }
 
+  gdk_drawable_get_size (window, &width, &height);
+
   data = g_new (struct cb_data, 1);
 
   data->callback = cb;
@@ -456,6 +464,10 @@
   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;
 
@@ -463,12 +475,11 @@
 #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) hhws_background_apply_async_dbus_callback,
                                                  data);

Modified: projects/haf/trunk/hildon-home-webshortcut/plugin/hildon-home-webshortcut.c
===================================================================
--- projects/haf/trunk/hildon-home-webshortcut/plugin/hildon-home-webshortcut.c	2007-09-06 06:58:24 UTC (rev 13631)
+++ projects/haf/trunk/hildon-home-webshortcut/plugin/hildon-home-webshortcut.c	2007-09-06 07:00:29 UTC (rev 13632)
@@ -736,20 +736,24 @@
 static void
 hhws_realize (GtkWidget *widget)
 {
-  HildonDesktopBackground      *background;
-  HhwsPrivate                  *priv = HHWS (widget)->priv;
 
   GTK_WIDGET_CLASS (hhws_parent_class)->realize (widget);
 
-  background = g_object_new (HHWS_TYPE_BACKGROUND,
-                             NULL);
+  if (widget->allocation.width != 1 || widget->allocation.height != 1)
+  {
+    HildonDesktopBackground    *background;
+    HhwsPrivate                *priv = HHWS (widget)->priv;
 
-  hildon_desktop_background_load (background, NULL, NULL);
-  priv->image = g_strdup (hildon_desktop_background_get_filename (background));
-  hhws_apply_background (HHWS (widget), background);
+    background = g_object_new (HHWS_TYPE_BACKGROUND,
+                               NULL);
 
-  g_object_unref (background);
+    hildon_desktop_background_load (background, NULL, NULL);
+    g_free (priv->image);
+    priv->image = g_strdup (hildon_desktop_background_get_filename (background));
+    hhws_apply_background (HHWS (widget), background);
 
+    g_object_unref (background);
+  }
 }
 
 static gboolean
@@ -808,6 +812,39 @@
   return FALSE;
 }
 
+static void
+hhws_size_request (GtkWidget *widget, GtkRequisition *requisition)
+{
+  requisition->width = HILDON_HOME_WS_WIDTH;
+  requisition->height = HILDON_HOME_WS_HEIGHT;
+}
+
+static void
+hhws_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+  GtkAllocation old_allocation = widget->allocation;
+
+  GTK_WIDGET_CLASS (hhws_parent_class)->size_allocate (widget, allocation);
+
+  if (GTK_WIDGET_REALIZED (widget) &&
+      (old_allocation.width  != allocation->width ||
+       old_allocation.height != allocation->height))
+  {
+    HildonDesktopBackground    *background;
+    HhwsPrivate                *priv = HHWS (widget)->priv;
+
+    background = g_object_new (HHWS_TYPE_BACKGROUND,
+                               NULL);
+
+    hildon_desktop_background_load (background, NULL, NULL);
+    g_free  (priv->image);
+    priv->image = g_strdup (hildon_desktop_background_get_filename (background));
+    hhws_apply_background (HHWS (widget), background);
+
+    g_object_unref (background);
+  }
+}
+
 static GtkWidget *
 hhws_create_csm (Hhws *hhws)
 {
@@ -895,10 +932,6 @@
   priv->gconf_client = gconf_client_get_default ();
   hhws_load_configuration (hhws);
 
-  gtk_widget_set_size_request (GTK_WIDGET (hhws),
-                               HILDON_HOME_WS_WIDTH,
-                               HILDON_HOME_WS_HEIGHT);
-
   priv->csm = hhws_create_csm (hhws);
 
   gtk_widget_tap_and_hold_setup (GTK_WIDGET (hhws),
@@ -932,6 +965,8 @@
   widget_class->button_release_event = hhws_button_release;
   widget_class->expose_event         = hhws_expose;
   widget_class->realize              = hhws_realize;
+  widget_class->size_request         = hhws_size_request;
+  widget_class->size_allocate        = hhws_size_allocate;
 
   object_class->destroy = hhws_destroy;
 


More information about the maemo-commits mailing list