1 |
#include "../config.h" |
2 |
#include <rxvt.h> |
3 |
|
4 |
// TODO: free colors again |
5 |
|
6 |
bool |
7 |
rxvt_color::set (rxvt_term *t, Pixel p) |
8 |
{ |
9 |
#if XFT |
10 |
XColor xc; |
11 |
|
12 |
xc.pixel = p; |
13 |
if (!XQueryColor (t->Xdisplay, t->Xcmap, &xc)) |
14 |
return false; |
15 |
|
16 |
XRenderColor d; |
17 |
|
18 |
d.red = xc.red; |
19 |
d.green = xc.green; |
20 |
d.blue = xc.blue; |
21 |
d.alpha = 0xffff; |
22 |
|
23 |
return |
24 |
XftColorAllocValue (t->Xdisplay, |
25 |
t->Xvisual, |
26 |
t->Xcmap, |
27 |
&d, |
28 |
&c); |
29 |
#else |
30 |
this->p = p; |
31 |
#endif |
32 |
|
33 |
return true; |
34 |
} |
35 |
|
36 |
bool |
37 |
rxvt_color::set (rxvt_term *t, const char *name) |
38 |
{ |
39 |
XColor xc; |
40 |
|
41 |
if (XParseColor (t->Xdisplay, t->Xcmap, name, &xc)) |
42 |
return set (t, xc.red, xc.green, xc.blue); |
43 |
|
44 |
return false; |
45 |
} |
46 |
|
47 |
bool |
48 |
rxvt_color::set (rxvt_term *t, unsigned short cr, unsigned short cg, unsigned short cb) |
49 |
{ |
50 |
XColor xc; |
51 |
|
52 |
xc.red = cr; |
53 |
xc.green = cg; |
54 |
xc.blue = cb; |
55 |
xc.flags = DoRed | DoGreen | DoBlue; |
56 |
|
57 |
if (XAllocColor (t->Xdisplay, t->Xcmap, &xc)) |
58 |
return set (t, xc.pixel); |
59 |
|
60 |
return false; |
61 |
} |
62 |
|
63 |
void |
64 |
rxvt_color::get (rxvt_term *t, unsigned short &cr, unsigned short &cg, unsigned short &cb) |
65 |
{ |
66 |
#if XFT |
67 |
cr = c.color.red; |
68 |
cg = c.color.green; |
69 |
cb = c.color.blue; |
70 |
#else |
71 |
XColor c; |
72 |
|
73 |
c.pixel = p; |
74 |
XQueryColor (t->Xdisplay, t->Xcmap, &c); |
75 |
|
76 |
cr = c.red; |
77 |
cg = c.green; |
78 |
cb = c.blue; |
79 |
#endif |
80 |
} |
81 |
|