1 /*----------------------------------------------------------------------*
2 * File: rxvttoolkit.h - provide toolkit-functionality for rxvt.
3 *----------------------------------------------------------------------*
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *----------------------------------------------------------------------*/
23 #ifndef RXVT_TOOLKIT_H
24 #define RXVT_TOOLKIT_H
29 # include <X11/Xft/Xft.h>
39 // see rxvttoolkit.C:xa_names, which must be kept in sync
79 // these are usually allocated by other subsystens, but we do it
80 // here to avoid a server roundtrip.
82 XA_XDCCC_LINEAR_RGB_CORRECTION,
83 XA_XDCCC_LINEAR_RGB_MATRICES,
84 XA_WM_COLORMAP_WINDOWS,
88 // various selection targets used by XIM
103 struct xevent_watcher;
109 refcounted (const char *id);
110 bool ref_init () { return false; }
116 struct refcache : vector<T *> {
117 T *get (const char *id);
127 /////////////////////////////////////////////////////////////////////////////
131 struct rxvt_drawable {
134 operator Drawable() { return drawable; }
137 XftDraw *xftdrawable;
138 operator XftDraw *();
141 rxvt_drawable (rxvt_screen *screen, Drawable drawable)
154 /////////////////////////////////////////////////////////////////////////////
157 struct rxvt_xim : refcounted {
159 rxvt_display *display;
164 rxvt_xim (const char *id) : refcounted (id) { }
171 rxvt_display *display;
179 rxvt_drawable *scratch_area;
180 int scratch_w, scratch_h;
182 rxvt_drawable &scratch_drawable (int w, int h);
187 void set (rxvt_display *disp);
188 void set (rxvt_display *disp, int bitdepth);
192 struct rxvt_display : refcounted {
193 io_manager_vec<xevent_watcher> xw;
195 io_watcher x_ev; void x_cb (io_watcher &w, short revents);
198 refcache<rxvt_xim> xims;
199 vector<im_watcher *> imw;
201 void im_change_cb ();
202 void im_change_check ();
209 rxvt_term *selection_owner;
216 rxvt_display (const char *id);
217 XrmDatabase get_resources (bool refresh);
223 Atom atom (const char *name);
224 void set_selection_owner (rxvt_term *owner);
226 void reg (xevent_watcher *w);
227 void unreg (xevent_watcher *w);
230 void reg (im_watcher *w);
231 void unreg (im_watcher *w);
233 rxvt_xim *get_xim (const char *locale, const char *modifiers);
234 void put_xim (rxvt_xim *xim);
239 struct im_watcher : watcher, callback0<void> {
240 template<class O1, class O2>
241 im_watcher (O1 *object, void (O2::*method) ())
242 : callback0<void> (object,method)
245 void start (rxvt_display *display)
249 void stop (rxvt_display *display)
251 display->unreg (this);
256 struct xevent_watcher : watcher, callback1<void, XEvent &> {
259 template<class O1, class O2>
260 xevent_watcher (O1 *object, void (O2::*method) (XEvent &))
261 : callback1<void, XEvent &> (object,method)
264 void start (rxvt_display *display, Window window)
266 this->window = window;
269 void stop (rxvt_display *display)
271 display->unreg (this);
275 extern refcache<rxvt_display> displays;
277 /////////////////////////////////////////////////////////////////////////////
279 typedef unsigned long Pixel;
282 unsigned short r, g, b, a;
284 enum { MIN_CC = 0x0000, MAX_CC = 0xffff };
289 rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC)
290 : r(r), g(g), b(b), a(a)
301 operator Pixel () const { return c.pixel; }
303 bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); }
304 bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); }
306 bool alloc (rxvt_screen *screen, const rgba &color);
307 void free (rxvt_screen *screen);
309 void get (rgba &color);
310 void get (XColor &color);
312 bool set (rxvt_screen *screen, const char *name);
313 bool set (rxvt_screen *screen, const rgba &color);
315 void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0));