Fixed gradients to actually use both end colors
[monky] / src / colours.c
index cfa60e5..f839f2f 100644 (file)
@@ -1,4 +1,7 @@
-/* Conky, a system monitor, based on torsmo
+/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+ * vim: ts=4 sw=4 noet ai cindent syntax=c
+ *
+ * Conky, a system monitor, based on torsmo
  *
  * Any original torsmo code is licensed under the BSD license
  *
@@ -7,7 +10,7 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
@@ -49,7 +52,7 @@ static void set_up_gradient(void)
                colour_depth = 16;
        }
        if (colour_depth != 24 && colour_depth != 16) {
-               ERR("using non-standard colour depth, gradients may look like a "
+               NORM_ERR("using non-standard colour depth, gradients may look like a "
                        "lolly-pop");
        }
 
@@ -116,7 +119,7 @@ unsigned long *do_gradient(int width, unsigned long first_colour, unsigned long
        for (i = 0; i < width; i++) {
                int red3 = 0, green3 = 0, blue3 = 0;    // colour components
 
-               float factor = ((float)(i + 1) / width);
+               float factor = ((float) i / (width - 1));
 
                /* the '+ 0.5' bit rounds our floats to ints properly */
                if (red1 >= red2) {
@@ -160,3 +163,30 @@ unsigned long *do_gradient(int width, unsigned long first_colour, unsigned long
        return colours;
 }
 
+#ifdef X11
+long get_x11_color(const char *name)
+{
+       XColor color;
+
+       color.pixel = 0;
+       if (!XParseColor(display, DefaultColormap(display, screen), name, &color)) {
+               /* lets check if it's a hex colour with the # missing in front
+                * if yes, then do something about it */
+               char newname[DEFAULT_TEXT_BUFFER_SIZE];
+
+               newname[0] = '#';
+               strncpy(&newname[1], name, DEFAULT_TEXT_BUFFER_SIZE - 1);
+               /* now lets try again */
+               if (!XParseColor(display, DefaultColormap(display, screen), &newname[0],
+                                       &color)) {
+                       NORM_ERR("can't parse X color '%s'", name);
+                       return 0xFF00FF;
+               }
+       }
+       if (!XAllocColor(display, DefaultColormap(display, screen), &color)) {
+               NORM_ERR("can't allocate X color '%s'", name);
+       }
+
+       return (long) color.pixel;
+}
+#endif