]> icculus.org git repositories - mikachu/openbox.git/blob - render/color.c
dont need those includes no more
[mikachu/openbox.git] / render / color.c
1 #include <X11/Xlib.h>
2 #include <X11/Xutil.h>
3 #include "render.h"
4 #include "color.h"
5 #include "../kernel/openbox.h"
6 void color_allocate_gc(color_rgb *in)
7 {
8     XGCValues gcv;
9
10     gcv.foreground = in->pixel;
11     gcv.cap_style = CapProjecting;
12     in->gc = XCreateGC(ob_display, ob_root, GCForeground | GCCapStyle, &gcv);
13 }
14
15 color_rgb *color_parse(char *colorname)
16 {
17     g_assert(colorname != NULL);
18     // get rgb values from colorname                                  
19
20     XColor xcol;
21     xcol.red = 0;
22     xcol.green = 0;
23     xcol.blue = 0;
24     xcol.pixel = 0;
25     if (!XParseColor(ob_display, render_colormap, colorname, &xcol)) {
26         g_warning("unable to parse color '%s'", colorname);
27         return NULL;
28     }
29     return color_new(xcol.red >> 8, xcol.green >> 8, xcol.blue >> 8);
30 }
31
32 color_rgb *color_new(int r, int g, int b)
33 {
34 /* this should be replaced with something far cooler */
35     color_rgb *out;
36     XColor xcol;
37     xcol.red = (r << 8) | r;
38     xcol.green = (g << 8) | g;
39     xcol.blue = (b << 8) | b;
40     if (XAllocColor(ob_display, render_colormap, &xcol)) {
41         out = g_new(color_rgb, 1);
42         out->r = xcol.red >> 8;
43         out->g = xcol.green >> 8;
44         out->b = xcol.blue >> 8;
45         out->gc = None;
46         out->pixel = xcol.pixel;
47         return out;
48     }
49     return NULL;
50 }
51
52 void color_free(color_rgb *c)
53 {
54     if (c->gc != None)
55         XFreeGC(ob_display, c->gc);
56     free(c);
57 }