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 |
struct rxvt_term; |
18 |
|
19 |
struct im_watcher; |
20 |
struct xevent_watcher; |
21 |
|
22 |
struct refcounted { |
23 |
int referenced; |
24 |
char *id; |
25 |
|
26 |
refcounted (const char *id); |
27 |
bool init () { } |
28 |
~refcounted (); |
29 |
}; |
30 |
|
31 |
template<class T> |
32 |
struct refcache : vector<T *> { |
33 |
T *get (const char *id); |
34 |
void put (T *obj); |
35 |
~refcache (); |
36 |
}; |
37 |
|
38 |
///////////////////////////////////////////////////////////////////////////// |
39 |
|
40 |
struct rxvt_xim : refcounted { |
41 |
void destroy (); |
42 |
rxvt_display *display; |
43 |
|
44 |
//public |
45 |
XIM xim; |
46 |
|
47 |
rxvt_xim (const char *id) : refcounted (id) { } |
48 |
bool init (); |
49 |
~rxvt_xim (); |
50 |
}; |
51 |
|
52 |
struct rxvt_display : refcounted { |
53 |
Atom xa_xim_servers; |
54 |
|
55 |
rxvt_term *selection_owner; |
56 |
|
57 |
io_manager_vec<xevent_watcher> xw; |
58 |
|
59 |
io_watcher x_watcher; void x_event (io_watcher &w, short revents); |
60 |
|
61 |
refcache<rxvt_xim> xims; |
62 |
vector<im_watcher *> imw; |
63 |
|
64 |
void im_change_cb (); |
65 |
|
66 |
//public |
67 |
Display *display; |
68 |
int depth; |
69 |
int screen; |
70 |
Visual *visual; |
71 |
Colormap cmap; |
72 |
Window root; |
73 |
|
74 |
rxvt_display (const char *id); |
75 |
bool init (); |
76 |
~rxvt_display (); |
77 |
|
78 |
void reg (xevent_watcher *w); |
79 |
void unreg (xevent_watcher *w); |
80 |
void reg (im_watcher *w); |
81 |
void unreg (im_watcher *w); |
82 |
|
83 |
void set_selection_owner (rxvt_term *owner); |
84 |
|
85 |
rxvt_xim *get_xim (const char *locale, const char *modifiers); |
86 |
void put_xim (rxvt_xim *xim); |
87 |
}; |
88 |
|
89 |
struct im_watcher : watcher, callback0<void> { |
90 |
template<class O1, class O2> |
91 |
im_watcher (O1 *object, void (O2::*method)()) |
92 |
: callback0<void>(object,method) |
93 |
{ } |
94 |
|
95 |
void start (rxvt_display *display) |
96 |
{ |
97 |
display->reg (this); |
98 |
} |
99 |
void stop (rxvt_display *display) |
100 |
{ |
101 |
display->unreg (this); |
102 |
} |
103 |
}; |
104 |
|
105 |
struct xevent_watcher : watcher, callback1<void, XEvent &> { |
106 |
Window window; |
107 |
|
108 |
template<class O1, class O2> |
109 |
xevent_watcher (O1 *object, void (O2::*method)(XEvent &)) |
110 |
: callback1<void, XEvent &>(object,method) |
111 |
{ } |
112 |
|
113 |
void start (rxvt_display *display, Window window) |
114 |
{ |
115 |
this->window = window; |
116 |
display->reg (this); |
117 |
} |
118 |
void stop (rxvt_display *display) |
119 |
{ |
120 |
display->unreg (this); |
121 |
} |
122 |
}; |
123 |
|
124 |
extern refcache<rxvt_display> displays; |
125 |
|
126 |
///////////////////////////////////////////////////////////////////////////// |
127 |
|
128 |
typedef unsigned long Pixel; |
129 |
|
130 |
struct rxvt_color { |
131 |
#if XFT |
132 |
XftColor c; |
133 |
operator Pixel() const { return c.pixel; } |
134 |
#else |
135 |
Pixel p; |
136 |
operator Pixel() const { return p; } |
137 |
#endif |
138 |
|
139 |
bool operator == (const rxvt_color &b) const { return Pixel(*this) == Pixel(b); } |
140 |
bool operator != (const rxvt_color &b) const { return Pixel(*this) != Pixel(b); } |
141 |
|
142 |
void get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb); |
143 |
|
144 |
bool set (rxvt_display *display, Pixel p); |
145 |
bool set (rxvt_display *display, const char *name); |
146 |
bool set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb); |
147 |
|
148 |
void free (rxvt_display *display); |
149 |
}; |
150 |
|
151 |
#endif |
152 |
|