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>
38 // see rxvttoolkit.C:xa_names, which must be kept in sync
69 #if ENABLE_TRANSPARENCY
78 // these are usually allocated by other subsystems, but we do it
79 // here to avoid a server roundtrip.
81 XA_XDCCC_LINEAR_RGB_CORRECTION,
82 XA_XDCCC_LINEAR_RGB_MATRICES,
83 XA_WM_COLORMAP_WINDOWS,
87 // various selection targets used by XIM
102 struct xevent_watcher;
104 template<class watcher>
105 struct event_vec : vector<watcher *>
107 void erase_unordered (unsigned int pos)
109 watcher *w = (*this)[this->size () - 1];
113 if (((*this)[pos] = w)) // '=' is correct!
120 int active; /* 0 == inactive, else index into respective vector */
122 bool is_active () { return active; }
124 rxvt_watcher () : active (0) { }
132 refcounted (const char *id);
133 bool ref_init () { return false; }
139 struct refcache : vector<T *>
141 T *get (const char *id);
151 /////////////////////////////////////////////////////////////////////////////
159 operator Drawable() { return drawable; }
162 XftDraw *xftdrawable;
163 operator XftDraw *();
166 rxvt_drawable (rxvt_screen *screen, Drawable drawable)
179 /////////////////////////////////////////////////////////////////////////////
182 struct rxvt_xim : refcounted
185 rxvt_display *display;
190 rxvt_xim (const char *id) : refcounted (id) { }
198 rxvt_display *display;
206 rxvt_drawable *scratch_area;
207 int scratch_w, scratch_h;
209 rxvt_drawable &scratch_drawable (int w, int h);
214 void set (rxvt_display *disp);
215 void select_visual (int bitdepth);
219 struct rxvt_display : refcounted
221 event_vec<xevent_watcher> xw;
223 ev::prepare flush_ev; void flush_cb (ev::prepare &w, int revents);
224 ev::io x_ev ; void x_cb (ev::io &w, int revents);
227 refcache<rxvt_xim> xims;
228 vector<im_watcher *> imw;
230 void im_change_cb ();
231 void im_change_check ();
238 rxvt_term *selection_owner;
245 rxvt_display (const char *id);
246 XrmDatabase get_resources (bool refresh);
256 Atom atom (const char *name);
257 void set_selection_owner (rxvt_term *owner);
259 void reg (xevent_watcher *w);
260 void unreg (xevent_watcher *w);
263 void reg (im_watcher *w);
264 void unreg (im_watcher *w);
266 rxvt_xim *get_xim (const char *locale, const char *modifiers);
267 void put_xim (rxvt_xim *xim);
272 struct im_watcher : rxvt_watcher, callback<void (void)> {
273 void start (rxvt_display *display)
278 void stop (rxvt_display *display)
280 display->unreg (this);
285 struct xevent_watcher : rxvt_watcher, callback<void (XEvent &)>
289 void start (rxvt_display *display, Window window)
291 this->window = window;
295 void stop (rxvt_display *display)
297 display->unreg (this);
301 extern refcache<rxvt_display> displays;
303 /////////////////////////////////////////////////////////////////////////////
305 typedef unsigned long Pixel;
309 unsigned short r, g, b, a;
311 enum { MIN_CC = 0x0000, MAX_CC = 0xffff };
316 rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC)
317 : r(r), g(g), b(b), a(a)
329 operator Pixel () const { return c.pixel; }
331 bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); }
332 bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); }
334 bool is_opaque () const
337 return c.color.alpha == rgba::MAX_CC;
343 bool alloc (rxvt_screen *screen, const rgba &color);
344 void free (rxvt_screen *screen);
346 void get (rgba &color);
347 void get (XColor &color);
349 bool set (rxvt_screen *screen, const char *name);
350 bool set (rxvt_screen *screen, const rgba &color);
352 void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0));
356 Pixmap trace_XCreatePixmap (const char *file, int line, Display *dpy, Window r, unsigned int w, unsigned int h, unsigned int d);
357 void trace_XFreePixmap (const char *file, int line, Display *dpy, Pixmap p);
359 # define XCreatePixmap(dpy,r,w,h,d) trace_XCreatePixmap (__FILE__,__LINE__,dpy,r,w,h,d)
360 # define XFreePixmap(dpy,p) trace_XFreePixmap (__FILE__,__LINE__,dpy,p)