[maemo-commits] [maemo-commits] r11854 - in projects/haf/trunk/hildon-desktop: . libhildondesktop src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri May 25 15:38:15 EEST 2007
Author: jobi
Date: 2007-05-25 15:38:14 +0300 (Fri, 25 May 2007)
New Revision: 11854

Modified:
   projects/haf/trunk/hildon-desktop/ChangeLog
   projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-home-item.c
   projects/haf/trunk/hildon-desktop/src/hd-panel-window.c
Log:

2007-05-25  Johan Bilien  <johan.bilien at nokia.com>

	* src/hd-panel-window.c:
	- add _style_set to load a background picture
	- add _realize to call _style_set initially
	- paint the background picture in the expose handler



Modified: projects/haf/trunk/hildon-desktop/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-desktop/ChangeLog	2007-05-25 12:20:02 UTC (rev 11853)
+++ projects/haf/trunk/hildon-desktop/ChangeLog	2007-05-25 12:38:14 UTC (rev 11854)
@@ -1,3 +1,10 @@
+2007-05-25  Johan Bilien  <johan.bilien at nokia.com>
+
+	* src/hd-panel-window.c:
+	- add _style_set to load a background picture
+	- add _realize to call _style_set initially
+	- paint the background picture in the expose handler
+
 2007-05-24  Moises Martinez  <moises.martinez at nokia.com>
 
 	* src/hd-switcher-menu.c: 

Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-home-item.c
===================================================================
--- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-home-item.c	2007-05-25 12:20:02 UTC (rev 11853)
+++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-home-item.c	2007-05-25 12:38:14 UTC (rev 11854)
@@ -206,7 +206,7 @@
   static GType etype = 0;
   if (etype == 0)
     {
-    
+
       static const GEnumValue values[] = {
           { HILDON_DESKTOP_HOME_ITEM_RESIZE_NONE,
             "HILDON_DESKTOP_HOME_ITEM_RESIZE_NONE",
@@ -1592,7 +1592,7 @@
 
   if (GTK_WIDGET_CLASS (parent_class)->key_press_event)
     return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event);
-    
+
   return FALSE;
 }
 
@@ -1608,7 +1608,7 @@
 
   if (GTK_WIDGET_CLASS (parent_class)->key_release_event)
     return GTK_WIDGET_CLASS (parent_class)->key_release_event (widget, event);
-    
+
   return FALSE;
 }
 
@@ -1634,7 +1634,7 @@
   g_return_val_if_fail (applet, FALSE);
 
   priv = HILDON_DESKTOP_HOME_ITEM_GET_PRIVATE (applet);
-  
+
   return priv->layout_mode;
 }
 
@@ -1646,7 +1646,7 @@
   g_return_if_fail (applet);
 
   priv = HILDON_DESKTOP_HOME_ITEM_GET_PRIVATE (applet);
-  
+
   if (priv->layout_mode != layout_mode)
     {
       g_object_notify (G_OBJECT (applet), "layout-mode");
@@ -1665,9 +1665,9 @@
 {
   HildonDesktopHomeItemPriv      *priv;
   g_return_val_if_fail (applet, FALSE);
-  
+
   priv = HILDON_DESKTOP_HOME_ITEM_GET_PRIVATE (applet);
-  
+
   return priv->resize_type;
 }
 
@@ -1679,7 +1679,7 @@
   g_return_if_fail (applet);
 
   priv = HILDON_DESKTOP_HOME_ITEM_GET_PRIVATE (applet);
-          
+
   if (priv->resize_type != resize_type)
     {
       g_object_notify (G_OBJECT (applet), "resize-type");
@@ -1694,9 +1694,9 @@
   GtkWindow                 *window;
   GtkWidget                 *item = NULL;
   g_return_val_if_fail (applet, NULL);
-  
+
   priv = HILDON_DESKTOP_HOME_ITEM_GET_PRIVATE (applet);
-  
+
   window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (applet)));
 
   g_signal_emit_by_name (applet, "settings", window, &item);

Modified: projects/haf/trunk/hildon-desktop/src/hd-panel-window.c
===================================================================
--- projects/haf/trunk/hildon-desktop/src/hd-panel-window.c	2007-05-25 12:20:02 UTC (rev 11853)
+++ projects/haf/trunk/hildon-desktop/src/hd-panel-window.c	2007-05-25 12:38:14 UTC (rev 11854)
@@ -37,8 +37,11 @@
 #include <X11/extensions/Xrender.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
 
@@ -62,8 +65,222 @@
   Picture       home_picture;
   Damage        home_damage;
   GdkWindow    *home_gwindow;
+
+  Picture       background_picture;
+  Picture       background_mask;
 };
 
+
+static void
+hd_panel_window_style_set (GtkWidget   *widget,
+                           GtkStyle    *old_style)
+{
+  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)
+    {
+      XRenderFreePicture (GDK_DISPLAY (),
+                          priv->background_picture);
+      priv->background_picture = None;
+    }
+
+  filename = widget->style->rc_style->bg_pixmap_name[GTK_STATE_PRELIGHT];
+
+  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);
+
+  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);
+    }
+
+}
+
+static void
+hd_panel_window_realize (GtkWidget     *widget)
+{
+  GTK_WIDGET_CLASS (hd_panel_window_parent_class)->realize (widget);
+
+  hd_panel_window_style_set (widget, widget->style);
+}
+
 static gboolean
 hd_panel_window_expose (GtkWidget *widget,
                         GdkEventExpose *event)
@@ -106,12 +323,26 @@
                         None,
                         picture,
                         x + event->area.x, y + event->area.y,
-                        0, 0,
+                        x + event->area.x, y + event->area.y,
                         event->area.x - x_offset,
                         event->area.y - y_offset,
                         event->area.width,
                         event->area.height);
 
+      if (priv->background_picture != None)
+        XRenderComposite (GDK_DISPLAY (),
+                          PictOpOver,
+                          priv->background_picture,
+                          priv->background_mask,
+                          picture,
+                          x + event->area.x, y + event->area.y,
+                          x + event->area.x, y + event->area.y,
+                          event->area.x - x_offset,
+                          event->area.y - y_offset,
+                          event->area.width,
+                          event->area.height);
+
+
       XRenderFreePicture (GDK_DISPLAY (),
                           picture);
 
@@ -148,7 +379,7 @@
       rect.width = ev->area.width;
       rect.height = ev->area.height;
 
-      parts = XFixesCreateRegion (GDK_DISPLAY (), 0, 0);
+      parts = XFixesCreateRegion (GDK_DISPLAY (), &ev->area, 1);
       XDamageSubtract (GDK_DISPLAY (), ev->damage, None, parts);
       XFixesDestroyRegion (GDK_DISPLAY (), parts);
 
@@ -349,6 +580,8 @@
     gint composite_event_base;
 
     widget_class->expose_event = hd_panel_window_expose;
+    widget_class->style_set    = hd_panel_window_style_set;
+    widget_class->realize      = hd_panel_window_realize;
 
     if (XDamageQueryExtension (GDK_DISPLAY (),
                                &klass->xdamage_event_base,


More information about the maemo-commits mailing list