ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtcolor.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtcolor.C (file contents):
Revision 1.6 by pcg, Wed Feb 11 08:13:45 2004 UTC vs.
Revision 1.14 by pcg, Thu Apr 8 20:31:45 2004 UTC

1/*--------------------------------*-C-*---------------------------------*
2 * File: rxvtcolor.C
3 *----------------------------------------------------------------------*
4 *
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
7 *
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.
12 *
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.
17 *
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 *----------------------------------------------------------------------*/
22
1#include "../config.h" 23#include "../config.h"
2#include <rxvt.h> 24#include <rxvt.h>
3#include <rxvtcolor.h> 25#include <rxvtcolor.h>
4 26
5#include <unistd.h> 27#include <unistd.h>
6#include <fcntl.h> 28#include <fcntl.h>
29
30class byteorder byteorder;
31
32byteorder::byteorder ()
33{
34 union {
35 uint32_t u;
36 uint8_t b[4];
37 } w;
38
39 w.b[0] = 0x11;
40 w.b[1] = 0x22;
41 w.b[2] = 0x33;
42 w.b[3] = 0x44;
43
44 e = w.u;
45}
7 46
8refcounted::refcounted (const char *id) 47refcounted::refcounted (const char *id)
9{ 48{
10 this->id = STRDUP (id); 49 this->id = STRDUP (id);
11} 50}
102 141
103///////////////////////////////////////////////////////////////////////////// 142/////////////////////////////////////////////////////////////////////////////
104 143
105rxvt_display::rxvt_display (const char *id) 144rxvt_display::rxvt_display (const char *id)
106: refcounted (id) 145: refcounted (id)
107, x_watcher (this, &rxvt_display::x_event) 146, x_ev (this, &rxvt_display::x_cb)
108, selection_owner (0) 147, selection_owner (0)
109{ 148{
110} 149}
111 150
112bool rxvt_display::init () 151bool rxvt_display::init ()
113{ 152{
114 display = XOpenDisplay (id); 153 display = XOpenDisplay (id);
154
155 if (!display)
156 return false;
115 157
116 screen = DefaultScreen (display); 158 screen = DefaultScreen (display);
117 root = DefaultRootWindow (display); 159 root = DefaultRootWindow (display);
118 visual = DefaultVisual (display, screen); 160 visual = DefaultVisual (display, screen);
119 cmap = DefaultColormap (display, screen); 161 cmap = DefaultColormap (display, screen);
137 } 179 }
138 } 180 }
139#endif 181#endif
140 182
141 int fd = XConnectionNumber (display); 183 int fd = XConnectionNumber (display);
142 x_watcher.start (fd, EVENT_READ); 184 x_ev.start (fd, EVENT_READ);
143 fcntl (fd, F_SETFL, FD_CLOEXEC); 185 fcntl (fd, F_SETFD, FD_CLOEXEC);
144 186
145 XSelectInput (display, root, PropertyChangeMask); 187 XSelectInput (display, root, PropertyChangeMask);
146 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); 188 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0);
147 189
190 flush ();
191
148 return true; 192 return true;
149} 193}
150 194
151rxvt_display::~rxvt_display () 195rxvt_display::~rxvt_display ()
152{ 196{
153 x_watcher.stop (); 197 x_ev.stop ();
154 198
199 if (display)
155 XCloseDisplay (display); 200 XCloseDisplay (display);
156} 201}
157 202
158void rxvt_display::im_change_cb () 203void rxvt_display::im_change_cb ()
159{ 204{
160 for (im_watcher **i = imw.begin (); i != imw.end (); ++i) 205 for (im_watcher **i = imw.begin (); i != imw.end (); ++i)
161 (*i)->call (); 206 (*i)->call ();
162} 207}
163 208
164void rxvt_display::x_event (io_watcher &w, short revents) 209void rxvt_display::x_cb (io_watcher &w, short revents)
165{ 210{
166 do 211 do
167 { 212 {
168 XEvent xev; 213 XEvent xev;
169 XNextEvent (display, &xev); 214 XNextEvent (display, &xev);
182 else if (xw[i]->window == xev.xany.window) 227 else if (xw[i]->window == xev.xany.window)
183 xw[i]->call (xev); 228 xw[i]->call (xev);
184 } 229 }
185 } 230 }
186 while (XPending (display)); 231 while (XPending (display));
232
233 flush ();
234}
235
236void rxvt_display::flush ()
237{
238 for (;;)
239 {
240 XFlush (display);
241
242 if (!XPending (display))
243 break;
244
245 x_cb (x_ev, 0);
246 }
187} 247}
188 248
189void rxvt_display::reg (xevent_watcher *w) 249void rxvt_display::reg (xevent_watcher *w)
190{ 250{
191 xw.push_back (w); 251 xw.push_back (w);
216 selection_owner = owner; 276 selection_owner = owner;
217} 277}
218 278
219rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers) 279rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers)
220{ 280{
221 // asprintf is a GNU and *BSD extension.. sorry...
222 char *id; 281 char *id;
282 int l, m;
223 283
224 if (asprintf (&id, "%s\n%s", locale, modifiers) < 0) 284 l = strlen (locale);
285 m = strlen (modifiers);
286
287 if (!(id = (char *)malloc (l + m + 2)))
225 return 0; 288 return 0;
226 289
290 memcpy (id, locale, l); id[l] = '\n';
291 memcpy (id + l + 1, modifiers, m); id[l + m + 1] = 0;
292
227 rxvt_xim *xim = xims.get (id); 293 rxvt_xim *xim = xims.get (id);
228 294
229 free (id); 295 free (id);
230 296
231 return xim; 297 return xim;
232} 298}
233 299
234void rxvt_display::put_xim (rxvt_xim *xim) 300void rxvt_display::put_xim (rxvt_xim *xim)
235{ 301{
236 xims.put (xim); 302 xims.put (xim);
303}
304
305Atom rxvt_display::atom (const char *name)
306{
307 return XInternAtom (display, name, False);
237} 308}
238 309
239///////////////////////////////////////////////////////////////////////////// 310/////////////////////////////////////////////////////////////////////////////
240 311
241template refcache<rxvt_display>; 312template refcache<rxvt_display>;
322rxvt_color::free (rxvt_display *display) 393rxvt_color::free (rxvt_display *display)
323{ 394{
324#if XFT 395#if XFT
325 XftColorFree (display->display, display->visual, display->cmap, &c); 396 XftColorFree (display->display, display->visual, display->cmap, &c);
326#else 397#else
327 XFreeColors (display->display, display->cmap, &c, 1, AllPlanes); 398 XFreeColors (display->display, display->cmap, &p, 1, AllPlanes);
328#endif 399#endif
329} 400}
330 401

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines