| 1 |
pcg |
1.1 |
#include "../config.h" |
| 2 |
|
|
#include <rxvt.h> |
| 3 |
|
|
|
| 4 |
|
|
// TODO: free colors again |
| 5 |
|
|
|
| 6 |
|
|
bool |
| 7 |
|
|
rxvt_color::set (pR_ Pixel p) |
| 8 |
|
|
{ |
| 9 |
|
|
#if XFT |
| 10 |
|
|
XColor xc; |
| 11 |
|
|
|
| 12 |
|
|
xc.pixel = p; |
| 13 |
pcg |
1.2 |
if (!XQueryColor (R->Xdisplay, R->Xcmap, &xc)) |
| 14 |
pcg |
1.1 |
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 (R->Xdisplay, |
| 25 |
pcg |
1.2 |
R->Xvisual, |
| 26 |
|
|
R->Xcmap, |
| 27 |
pcg |
1.1 |
&d, |
| 28 |
|
|
&c); |
| 29 |
|
|
#else |
| 30 |
|
|
this->p = p; |
| 31 |
|
|
#endif |
| 32 |
|
|
|
| 33 |
|
|
return true; |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
bool |
| 37 |
|
|
rxvt_color::set (pR_ const char *name) |
| 38 |
|
|
{ |
| 39 |
|
|
XColor xc; |
| 40 |
|
|
|
| 41 |
pcg |
1.2 |
if (XParseColor (R->Xdisplay, R->Xcmap, name, &xc)) |
| 42 |
pcg |
1.1 |
return set (aR_ xc.red, xc.green, xc.blue); |
| 43 |
|
|
|
| 44 |
|
|
return false; |
| 45 |
|
|
} |
| 46 |
|
|
|
| 47 |
|
|
bool |
| 48 |
|
|
rxvt_color::set (pR_ 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 |
pcg |
1.2 |
if (XAllocColor (R->Xdisplay, R->Xcmap, &xc)) |
| 58 |
pcg |
1.1 |
return set (aR_ xc.pixel); |
| 59 |
|
|
|
| 60 |
|
|
return false; |
| 61 |
|
|
} |
| 62 |
|
|
|
| 63 |
|
|
void |
| 64 |
|
|
rxvt_color::get (pR_ 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 |
pcg |
1.2 |
XQueryColor (R->Xdisplay, R->Xcmap, &c); |
| 75 |
pcg |
1.1 |
|
| 76 |
|
|
cr = c.red; |
| 77 |
|
|
cg = c.green; |
| 78 |
|
|
cb = c.blue; |
| 79 |
|
|
#endif |
| 80 |
|
|
} |
| 81 |
|
|
|