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