]> git.decadent.org.uk Git - ion3.git/blob - de/colour.c
[svn-inject] Installing original source of ion3
[ion3.git] / de / colour.c
1 /*
2  * ion/de/colour.h
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2006. 
5  *
6  * Ion is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <ioncore/common.h>
13 #include "colour.h"
14
15
16 bool de_alloc_colour(WRootWin *rootwin, DEColour *ret, const char *name)
17 {
18     XColor c;
19     bool ok=FALSE;
20
21     if(name==NULL)
22         return FALSE;
23
24     if(XParseColor(ioncore_g.dpy, rootwin->default_cmap, name, &c)){
25         ok=XAllocColor(ioncore_g.dpy, rootwin->default_cmap, &c);
26         if(ok)
27             *ret=c.pixel;
28     }
29     
30     return ok;
31 }
32
33
34 bool de_duplicate_colour(WRootWin *rootwin, DEColour in, DEColour *out)
35 {
36     XColor c;
37     c.pixel=in;
38     XQueryColor(ioncore_g.dpy, rootwin->default_cmap, &c);
39     if(XAllocColor(ioncore_g.dpy, rootwin->default_cmap, &c)){
40         *out=c.pixel;
41         return TRUE;
42     }
43     return FALSE;
44 }
45
46
47 void de_free_colour_group(WRootWin *rootwin, DEColourGroup *cg)
48 {
49     DEColour pixels[5];
50     
51     pixels[0]=cg->bg;
52     pixels[1]=cg->fg;
53     pixels[2]=cg->hl;
54     pixels[3]=cg->sh;
55     pixels[4]=cg->pad;
56     
57     XFreeColors(ioncore_g.dpy, rootwin->default_cmap, pixels, 5, 0);
58     
59     if(cg->spec!=NULL){
60         free(cg->spec);
61         cg->spec=NULL;
62     }
63 }
64
65
66 void de_free_colour(WRootWin *rootwin, DEColour col)
67 {
68     DEColour pixels[1];
69     
70     pixels[0]=col;
71     
72     XFreeColors(ioncore_g.dpy, rootwin->default_cmap, pixels, 1, 0);
73 }
74