| 1 |
#ifndef RXVT_COLOR_H |
| 2 |
#define RXVT_COLOR_H |
| 3 |
|
| 4 |
#include <X11/Xlib.h> |
| 5 |
|
| 6 |
#if XFT |
| 7 |
# include <X11/Xft/Xft.h> |
| 8 |
#endif |
| 9 |
|
| 10 |
#include "iom.h" |
| 11 |
|
| 12 |
#include "rxvtlib.h" |
| 13 |
#include "rxvtstl.h" |
| 14 |
|
| 15 |
#include "callback.h" |
| 16 |
|
| 17 |
extern class byteorder { |
| 18 |
uint32_t e; |
| 19 |
public: |
| 20 |
byteorder (); |
| 21 |
|
| 22 |
bool big_endian () { return e == 0x11223344; }; |
| 23 |
bool network () { return e == 0x11223344; }; |
| 24 |
bool little_endian () { return e == 0x44332211; }; |
| 25 |
bool vax () { return e == 0x44332211; }; |
| 26 |
} byteorder; |
| 27 |
|
| 28 |
struct rxvt_term; |
| 29 |
|
| 30 |
struct im_watcher; |
| 31 |
struct xevent_watcher; |
| 32 |
|
| 33 |
struct refcounted { |
| 34 |
int referenced; |
| 35 |
char *id; |
| 36 |
|
| 37 |
refcounted (const char *id); |
| 38 |
bool init () { return false; } |
| 39 |
~refcounted (); |
| 40 |
}; |
| 41 |
|
| 42 |
template<class T> |
| 43 |
struct refcache : vector<T *> { |
| 44 |
T *get (const char *id); |
| 45 |
void put (T *obj); |
| 46 |
~refcache (); |
| 47 |
}; |
| 48 |
|
| 49 |
///////////////////////////////////////////////////////////////////////////// |
| 50 |
|
| 51 |
#ifdef USE_XIM |
| 52 |
struct rxvt_xim : refcounted { |
| 53 |
void destroy (); |
| 54 |
rxvt_display *display; |
| 55 |
|
| 56 |
//public |
| 57 |
XIM xim; |
| 58 |
|
| 59 |
rxvt_xim (const char *id) : refcounted (id) { } |
| 60 |
bool init (); |
| 61 |
~rxvt_xim (); |
| 62 |
}; |
| 63 |
#endif |
| 64 |
|
| 65 |
struct rxvt_display : refcounted { |
| 66 |
Atom xa_xim_servers; |
| 67 |
|
| 68 |
io_manager_vec<xevent_watcher> xw; |
| 69 |
|
| 70 |
io_watcher x_ev; void x_cb (io_watcher &w, short revents); |
| 71 |
|
| 72 |
#ifdef USE_XIM |
| 73 |
refcache<rxvt_xim> xims; |
| 74 |
vector<im_watcher *> imw; |
| 75 |
|
| 76 |
void im_change_cb (); |
| 77 |
#endif |
| 78 |
|
| 79 |
//public |
| 80 |
Display *display; |
| 81 |
int depth; |
| 82 |
int screen; |
| 83 |
Visual *visual; |
| 84 |
Colormap cmap; |
| 85 |
Window root; |
| 86 |
rxvt_term *selection_owner; |
| 87 |
#ifndef NO_SLOW_LINK_SUPPORT |
| 88 |
bool is_local; |
| 89 |
#endif |
| 90 |
|
| 91 |
rxvt_display (const char *id); |
| 92 |
bool init (); |
| 93 |
~rxvt_display (); |
| 94 |
|
| 95 |
void flush (); |
| 96 |
|
| 97 |
void set_selection_owner (rxvt_term *owner); |
| 98 |
|
| 99 |
void reg (xevent_watcher *w); |
| 100 |
void unreg (xevent_watcher *w); |
| 101 |
|
| 102 |
#ifdef USE_XIM |
| 103 |
void reg (im_watcher *w); |
| 104 |
void unreg (im_watcher *w); |
| 105 |
|
| 106 |
rxvt_xim *get_xim (const char *locale, const char *modifiers); |
| 107 |
void put_xim (rxvt_xim *xim); |
| 108 |
#endif |
| 109 |
|
| 110 |
Atom atom (const char *name); |
| 111 |
}; |
| 112 |
|
| 113 |
#ifdef USE_XIM |
| 114 |
struct im_watcher : watcher, callback0<void> { |
| 115 |
template<class O1, class O2> |
| 116 |
im_watcher (O1 *object, void (O2::*method) ()) |
| 117 |
: callback0<void> (object,method) |
| 118 |
{ } |
| 119 |
|
| 120 |
void start (rxvt_display *display) |
| 121 |
{ |
| 122 |
display->reg (this); |
| 123 |
} |
| 124 |
void stop (rxvt_display *display) |
| 125 |
{ |
| 126 |
display->unreg (this); |
| 127 |
} |
| 128 |
}; |
| 129 |
#endif |
| 130 |
|
| 131 |
struct xevent_watcher : watcher, callback1<void, XEvent &> { |
| 132 |
Window window; |
| 133 |
|
| 134 |
template<class O1, class O2> |
| 135 |
xevent_watcher (O1 *object, void (O2::*method) (XEvent &)) |
| 136 |
: callback1<void, XEvent &> (object,method) |
| 137 |
{ } |
| 138 |
|
| 139 |
void start (rxvt_display *display, Window window) |
| 140 |
{ |
| 141 |
this->window = window; |
| 142 |
display->reg (this); |
| 143 |
} |
| 144 |
void stop (rxvt_display *display) |
| 145 |
{ |
| 146 |
display->unreg (this); |
| 147 |
} |
| 148 |
}; |
| 149 |
|
| 150 |
extern refcache<rxvt_display> displays; |
| 151 |
|
| 152 |
///////////////////////////////////////////////////////////////////////////// |
| 153 |
|
| 154 |
typedef unsigned long Pixel; |
| 155 |
|
| 156 |
struct rxvt_color { |
| 157 |
#if XFT |
| 158 |
XftColor c; |
| 159 |
operator Pixel () const { return c.pixel; } |
| 160 |
#else |
| 161 |
Pixel p; |
| 162 |
operator Pixel () const { return p; } |
| 163 |
#endif |
| 164 |
|
| 165 |
bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); } |
| 166 |
bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); } |
| 167 |
|
| 168 |
void get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb); |
| 169 |
|
| 170 |
bool set (rxvt_display *display, Pixel p); |
| 171 |
bool set (rxvt_display *display, const char *name); |
| 172 |
bool set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb); |
| 173 |
|
| 174 |
rxvt_color fade (rxvt_display *, int percent); |
| 175 |
|
| 176 |
void free (rxvt_display *display); |
| 177 |
}; |
| 178 |
|
| 179 |
#endif |
| 180 |
|