[Goodies-commits] r3669 - in ristretto/trunk: . src

Stephan Arts stephan at xfce.org
Tue Dec 4 18:15:38 CET 2007


Author: stephan
Date: 2007-12-04 17:15:38 +0000 (Tue, 04 Dec 2007)
New Revision: 3669

Modified:
   ristretto/trunk/ChangeLog
   ristretto/trunk/src/main.c
Log:
Remove the accidental gtk 2.12 dep



Modified: ristretto/trunk/ChangeLog
===================================================================
--- ristretto/trunk/ChangeLog	2007-12-03 21:51:24 UTC (rev 3668)
+++ ristretto/trunk/ChangeLog	2007-12-04 17:15:38 UTC (rev 3669)
@@ -1,4 +1,9 @@
-xxxx-xx-xx:
+2007-xx-xx:
+	* src/main.c:
+	  - Fix store and load functions for background-color, functions used
+	    where only available since gtk 2.12.
+
+2007-12-01: Release 0.0.14
 	* src/main_window.c:
 	  - Add keyboard-shortcuts for rotating
 	  - Fix modification of bg-color using preferences dialog

Modified: ristretto/trunk/src/main.c
===================================================================
--- ristretto/trunk/src/main.c	2007-12-03 21:51:24 UTC (rev 3668)
+++ ristretto/trunk/src/main.c	2007-12-04 17:15:38 UTC (rev 3669)
@@ -50,6 +50,149 @@
     { NULL }
 };
 
+#if GTK_CHECK_VERSION(2,12,0)
+#define RSTTO_COLOR_PARSE gdk_color_parse
+#define RSTTO_COLOR_TO_STRING gdk_color_to_string
+#else
+gboolean
+rstto_color_parse(const gchar *string, GdkColor *color)
+{
+    gint i;
+    guint16 red = 0;
+    guint16 green = 0;
+    guint16 blue = 0;
+    g_return_val_if_fail(string != NULL, FALSE);
+    /* Check is the string is long enough tp contain #rrrrggggbbbb
+     */
+    if(strlen(string) != 13)
+        return FALSE;
+    if(string[0] != '#')
+        return FALSE;
+
+    /* red */
+    for(i = 1; i < 5; ++i)
+    {
+        if(string[i] >= '0' && string[i] <= '9')
+        {
+            red |= (string[i] ^ 0x30);
+        }
+        else
+        {
+            if(string[i] >= 'a' && string[i] <= 'f')
+            {
+                red |= ((string[i] ^ 0x60)+9);
+            }
+            else
+            {
+                return FALSE;
+            }
+        }
+        if (i < 4)
+            red = red << 4;
+    }
+
+    /* green */
+    for(i = 5; i < 9; ++i)
+    {
+        if(string[i] >= '0' && string[i] <= '9')
+        {
+            green |= (string[i] ^ 0x30);
+        }
+        else
+        {
+            if(string[i] >= 'a' && string[i] <= 'f')
+            {
+                green |= ((string[i] ^ 0x60)+9);
+            }
+            else
+            {
+                return FALSE;
+            }
+        }
+
+        if (i < 8)
+            green = green << 4;
+
+    }
+
+    /* blue */
+    for(i = 9; i < 13; ++i)
+    {
+        if(string[i] >= '0' && string[i] <= '9')
+        {
+            blue |= (string[i] ^ 0x30);
+        }
+        else
+        {
+            if(string[i] >= 'a' && string[i] <= 'f')
+            {
+                blue |= ((string[i] ^ 0x60)+9);
+            }
+            else
+            {
+                return FALSE;
+            }
+        }
+        if (i < 12)
+            blue = blue << 4;
+    }
+
+    color->red = red;
+    color->green = green;
+    color->blue = blue;
+    return TRUE;
+}
+
+gchar *
+rstto_color_to_string(const GdkColor *color)
+{
+    gint i;
+    gchar *color_string = g_new0(gchar, 14);
+
+    color_string[0] = '#';
+
+    for(i = 0; i < 4; ++i)
+    {
+        if(((color->red >> (4*i))&0x000f) < 0xA)
+        {
+           color_string[1+3-i] = (((color->red >> (4*i))&0x000f)|0x0030);
+        }
+        else
+        {
+           color_string[1+3-i] = ((((color->red >> (4*i))&0x000f)|0x0060)-9);
+        }
+    }
+
+    for(i = 0; i < 4; ++i)
+    {
+        if(((color->green >> (4*i))&0x000f) < 0xA)
+        {
+           color_string[5+3-i] = (((color->green >> (4*i))&0x000f)|0x0030);
+        }
+        else
+        {
+           color_string[5+3-i] = ((((color->green >> (4*i))&0x000f)|0x0060)-9);
+        }
+    }
+
+    for(i = 0; i < 4; ++i)
+    {
+        if(((color->blue >> (4*i))&0x000f) < 0xA)
+        {
+           color_string[9+3-i] = (((color->blue >> (4*i))&0x000f)|0x0030);
+        }
+        else
+        {
+           color_string[9+3-i] = ((((color->blue >> (4*i))&0x000f)|0x0060)-9);
+        }
+    }
+
+    return color_string;
+}
+#define RSTTO_COLOR_PARSE(string, color) rstto_color_parse(string, color)
+#define RSTTO_COLOR_TO_STRING(color) rstto_color_to_string(color)
+#endif
+
 int main(int argc, char **argv)
 {
     GdkColor *bg_color = NULL;
@@ -100,7 +243,7 @@
     {
         const gchar *color = xfce_rc_read_entry(xfce_rc, "BgColor", "#000000000000");
         bg_color = g_new0(GdkColor, 1);
-        if(!gdk_color_parse(color, bg_color))
+        if(!RSTTO_COLOR_PARSE(color, bg_color))
         {
             g_debug("parse failed");
         }
@@ -438,7 +581,7 @@
     if (bg_color)
     {
         xfce_rc_write_bool_entry(xfce_rc, "OverrideBgColor", TRUE);
-        xfce_rc_write_entry(xfce_rc, "BgColor", gdk_color_to_string(bg_color));
+        xfce_rc_write_entry(xfce_rc, "BgColor", RSTTO_COLOR_TO_STRING(bg_color));
     }
     else
     {




More information about the Goodies-commits mailing list