[gnome-applets/wip/segeiger/height-for-width: 4/7] windowpicker/task-item.c: Reorder and cleanup code in draw function



commit feacd339f3bb511246324ddb9293ed7c4441c834
Author: Sebastian Geiger <sbastig gmx net>
Date:   Mon Jun 8 21:13:43 2015 +0200

    windowpicker/task-item.c: Reorder and cleanup code in draw function

 windowpicker/src/task-item.c |   38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)
---
diff --git a/windowpicker/src/task-item.c b/windowpicker/src/task-item.c
index fb6756e..bdad6b3 100644
--- a/windowpicker/src/task-item.c
+++ b/windowpicker/src/task-item.c
@@ -327,26 +327,17 @@ static gboolean task_item_draw (
     TaskItem *item = TASK_ITEM (widget);
     TaskItemPrivate *priv = item->priv;
     g_return_val_if_fail (WNCK_IS_WINDOW (priv->window), FALSE);
+
     cr = gdk_cairo_create (gtk_widget_get_window(widget));
     GdkRectangle area;
     GdkPixbuf *pbuf;
     area = priv->area;
-    pbuf = priv->pixbuf;
-    gint size = MIN (area.height, area.width) - 9;
     gboolean active = wnck_window_is_active (priv->window);
-    /* load the GSettings key for gray icons */
-    gboolean icons_greyscale = wp_applet_get_icons_greyscale (priv->windowPickerApplet);
     gboolean attention = wnck_window_or_transient_needs_attention (priv->window);
-    if (GDK_IS_PIXBUF (pbuf) &&
-        gdk_pixbuf_get_width (pbuf) != size &&
-        gdk_pixbuf_get_height (pbuf) != size)
-    {
-        g_object_unref (pbuf);
-        pbuf = NULL;
-    }
+
     if (active) { /* paint frame around the icon */
-        /* We add -1 for x to make it bigger to the left
-         * and +1 for width to make it bigger at the right */
+        /* We add +1 for x and y, and reduce the height and width by -2 to avoid drawing outside the visible 
area.
+         * This effectively shrinks the rectangle by one pixel on each side. */
         cairo_rectangle (cr, area.x + 1, area.y + 1, area.width - 2, area.height - 2);
         cairo_set_source_rgba (cr, .8, .8, .8, .2);
         cairo_fill_preserve (cr);
@@ -372,9 +363,21 @@ static gboolean task_item_draw (
         cairo_set_source (cr, glow_pattern);
         cairo_paint (cr);
     }
+    gint size = MIN (area.height, area.width) - 9;
+    pbuf = priv->pixbuf;
+    if (GDK_IS_PIXBUF (pbuf) &&
+        gdk_pixbuf_get_width (pbuf) != size &&
+        gdk_pixbuf_get_height (pbuf) != size)
+    {
+        g_object_unref (pbuf);
+        pbuf = NULL;
+    }
     if (!pbuf) {
         pbuf = priv->pixbuf = task_item_sized_pixbuf_for_window (item, priv->window, size);
     }
+
+    /* load the GSettings key for gray icons */
+    gboolean icons_greyscale = wp_applet_get_icons_greyscale (priv->windowPickerApplet);
     if (active || priv->mouse_over || attention || !icons_greyscale) {
         gdk_cairo_set_source_pixbuf (
             cr,
@@ -407,19 +410,20 @@ static gboolean task_item_draw (
             (area.y + (area.height - gdk_pixbuf_get_height (desat)) / 2));
         g_object_unref (desat);
     }
+    gdouble alpha;
     if (!priv->mouse_over && attention) { /* urgent */
         GTimeVal current_time;
         g_get_current_time (&current_time);
         gdouble ms = (
             current_time.tv_sec - priv->urgent_time.tv_sec) * 1000 +
             (current_time.tv_usec - priv->urgent_time.tv_usec) / 1000;
-        gdouble alpha = .66 + (cos (3.15 * ms / 600) / 3);
-        cairo_paint_with_alpha (cr, alpha);
+        alpha = .66 + (cos (3.15 * ms / 600) / 3);
     } else if (priv->mouse_over || active || !icons_greyscale) { /* focused */
-        cairo_paint (cr);
+        alpha = 1.0;
     } else { /* not focused */
-        cairo_paint_with_alpha (cr, .65);
+        alpha = .65;
     }
+    cairo_paint_with_alpha (cr, alpha);
     cairo_destroy (cr);
     return FALSE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]