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