]> git.decadent.org.uk Git - ion3.git/blob - de/colour.c
4fb3b1dabf5ec1a17026b7122d9e9606ad353732
[ion3.git] / de / colour.c
1 /*
2  * ion/de/colour.h
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2008. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <ioncore/common.h>
10 #include "colour.h"
11
12
13 bool de_alloc_colour(WRootWin *rootwin, DEColour *ret, const char *name)
14 {
15     XColor c;
16     bool ok=FALSE;
17
18     if(name==NULL)
19         return FALSE;
20
21     if(XParseColor(ioncore_g.dpy, rootwin->default_cmap, name, &c)){
22         ok=XAllocColor(ioncore_g.dpy, rootwin->default_cmap, &c);
23         if(ok)
24             *ret=c.pixel;
25     }
26     
27     return ok;
28 }
29
30
31 bool de_duplicate_colour(WRootWin *rootwin, DEColour in, DEColour *out)
32 {
33     XColor c;
34     c.pixel=in;
35     XQueryColor(ioncore_g.dpy, rootwin->default_cmap, &c);
36     if(XAllocColor(ioncore_g.dpy, rootwin->default_cmap, &c)){
37         *out=c.pixel;
38         return TRUE;
39     }
40     return FALSE;
41 }
42
43
44 void de_free_colour_group(WRootWin *rootwin, DEColourGroup *cg)
45 {
46     DEColour pixels[5];
47     
48     pixels[0]=cg->bg;
49     pixels[1]=cg->fg;
50     pixels[2]=cg->hl;
51     pixels[3]=cg->sh;
52     pixels[4]=cg->pad;
53     
54     XFreeColors(ioncore_g.dpy, rootwin->default_cmap, pixels, 5, 0);
55     
56     gr_stylespec_unalloc(&cg->spec);
57 }
58
59
60 void de_free_colour(WRootWin *rootwin, DEColour col)
61 {
62     DEColour pixels[1];
63     
64     pixels[0]=col;
65     
66     XFreeColors(ioncore_g.dpy, rootwin->default_cmap, pixels, 1, 0);
67 }
68