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

Comparing rxvt-unicode/src/rxvttoolkit.C (file contents):
Revision 1.49 by root, Thu Feb 2 14:41:00 2006 UTC vs.
Revision 1.55 by root, Sun Feb 19 16:55:03 2006 UTC

26 26
27#include <unistd.h> 27#include <unistd.h>
28#include <fcntl.h> 28#include <fcntl.h>
29 29
30#include <sys/utsname.h> 30#include <sys/utsname.h>
31
32#ifndef NO_SLOW_LINK_SUPPORT
33# include <sys/socket.h> 31#include <sys/socket.h>
34# include <sys/un.h> 32#include <sys/un.h>
35#endif
36 33
37#if XFT 34#if XFT
38# include <X11/extensions/Xrender.h> 35# include <X11/extensions/Xrender.h>
39#endif 36#endif
40 37
177bool 174bool
178rxvt_xim::ref_init () 175rxvt_xim::ref_init ()
179{ 176{
180 display = GET_R->display; //HACK: TODO 177 display = GET_R->display; //HACK: TODO
181 178
182 xim = XOpenIM (display->display, 0, 0, 0); 179 xim = XOpenIM (display->dpy, 0, 0, 0);
183 180
184 if (!xim) 181 if (!xim)
185 return false; 182 return false;
186 183
187 XIMCallback ximcallback; 184 XIMCallback ximcallback;
201 198
202#endif 199#endif
203 200
204///////////////////////////////////////////////////////////////////////////// 201/////////////////////////////////////////////////////////////////////////////
205 202
203#if XFT
204rxvt_drawable::~rxvt_drawable ()
205{
206 if (xftdrawable)
207 XftDrawDestroy (xftdrawable);
208}
209
210rxvt_drawable::operator XftDraw *()
211{
212 if (!xftdrawable)
213 xftdrawable = XftDrawCreate (screen->dpy, drawable, screen->visual, screen->cmap);
214
215 return xftdrawable;
216}
217#endif
218
219/////////////////////////////////////////////////////////////////////////////
220
221#if XFT
222
223// not strictly necessary as it is only used with superclass of zero_initialised
224rxvt_screen::rxvt_screen ()
225: scratch_area (0)
226{
227}
228
229rxvt_drawable &rxvt_screen::scratch_drawable (int w, int h)
230{
231 // it's actually faster to re-allocate every time. don't ask me
232 // why, but its likely no big deal there are no roundtrips
233 // (I think/hope).
234 if (!scratch_area || w > scratch_w || h > scratch_h || 1/*D*/)
235 {
236 if (scratch_area)
237 {
238 XFreePixmap (dpy, scratch_area->drawable);
239 delete scratch_area;
240 }
241
242 Pixmap pm = XCreatePixmap (dpy, RootWindowOfScreen (ScreenOfDisplay (dpy, display->screen)),
243 scratch_w = w, scratch_h = h, depth);
244
245 scratch_area = new rxvt_drawable (this, pm);
246 }
247
248 return *scratch_area;
249}
250
251#endif
252
206void 253void
207rxvt_screen::set (rxvt_display *disp) 254rxvt_screen::set (rxvt_display *disp)
208{ 255{
209 display = disp; 256 display = disp;
210 xdisp = disp->display; 257 dpy = disp->dpy;
211 258
212 Screen *screen = ScreenOfDisplay (xdisp, disp->screen); 259 Screen *screen = ScreenOfDisplay (dpy, disp->screen);
213 260
214 depth = DefaultDepthOfScreen (screen); 261 depth = DefaultDepthOfScreen (screen);
215 visual = DefaultVisualOfScreen (screen); 262 visual = DefaultVisualOfScreen (screen);
216 cmap = DefaultColormapOfScreen (screen); 263 cmap = DefaultColormapOfScreen (screen);
217} 264}
222 set (disp); 269 set (disp);
223 270
224#if XFT 271#if XFT
225 XVisualInfo vinfo; 272 XVisualInfo vinfo;
226 273
227 if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo)) 274 if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo))
228 { 275 {
229 depth = bitdepth; 276 depth = bitdepth;
230 visual = vinfo.visual; 277 visual = vinfo.visual;
231 cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); 278 cmap = XCreateColormap (dpy, disp->root, visual, AllocNone);
232 } 279 }
233#endif 280#endif
234} 281}
235 282
236void 283void
237rxvt_screen::clear () 284rxvt_screen::clear ()
238{ 285{
286#if XFT
287 if (scratch_area)
288 {
289 XFreePixmap (dpy, scratch_area->drawable);
290 delete scratch_area;
291 }
292#endif
293
239 if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (xdisp, display->screen))) 294 if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (dpy, display->screen)))
240 XFreeColormap (xdisp, cmap); 295 XFreeColormap (dpy, cmap);
241} 296}
242 297
243///////////////////////////////////////////////////////////////////////////// 298/////////////////////////////////////////////////////////////////////////////
244 299
245rxvt_display::rxvt_display (const char *id) 300rxvt_display::rxvt_display (const char *id)
286 int actual_format; 341 int actual_format;
287 unsigned long nitems, nremaining; 342 unsigned long nitems, nremaining;
288 char *val = 0; 343 char *val = 0;
289 344
290#if XLIB_ILLEGAL_ACCESS 345#if XLIB_ILLEGAL_ACCESS
291 if (display->xdefaults) 346 if (dpy->xdefaults)
292 XFree (display->xdefaults); 347 XFree (dpy->xdefaults);
293#endif 348#endif
294 349
295 if (XGetWindowProperty (display, root, XA_RESOURCE_MANAGER, 350 if (XGetWindowProperty (dpy, RootWindow (dpy, 0), XA_RESOURCE_MANAGER,
296 0L, 100000000L, False, 351 0L, 100000000L, False,
297 XA_STRING, &actual_type, &actual_format, 352 XA_STRING, &actual_type, &actual_format,
298 &nitems, &nremaining, 353 &nitems, &nremaining,
299 (unsigned char **)&val) == Success 354 (unsigned char **)&val) == Success
300 && actual_type == XA_STRING 355 && actual_type == XA_STRING
306 if (val) 361 if (val)
307 XFree(val); 362 XFree(val);
308 } 363 }
309 364
310#if XLIB_ILLEGAL_ACCESS 365#if XLIB_ILLEGAL_ACCESS
311 display->xdefaults = displayResource; 366 dpy->xdefaults = displayResource;
312#endif 367#endif
313 } 368 }
314 else 369 else
315 displayResource = XResourceManagerString (display); 370 displayResource = XResourceManagerString (dpy);
316 371
317 if (displayResource) 372 if (displayResource)
318 { 373 {
319 if ((rdb1 = XrmGetStringDatabase (displayResource))) 374 if ((rdb1 = XrmGetStringDatabase (displayResource)))
320 XrmMergeDatabases (rdb1, &database); 375 XrmMergeDatabases (rdb1, &database);
331 if (refresh && displayResource) 386 if (refresh && displayResource)
332 XFree (displayResource); 387 XFree (displayResource);
333#endif 388#endif
334 389
335 /* Get screen specific resources */ 390 /* Get screen specific resources */
336 displayResource = XScreenResourceString (ScreenOfDisplay (display, screen)); 391 displayResource = XScreenResourceString (ScreenOfDisplay (dpy, screen));
337 392
338 if (displayResource) 393 if (displayResource)
339 { 394 {
340 if ((rdb1 = XrmGetStringDatabase (displayResource))) 395 if ((rdb1 = XrmGetStringDatabase (displayResource)))
341 /* Merge with screen-independent resources */ 396 /* Merge with screen-independent resources */
371 if (id[0] == ':') 426 if (id[0] == ':')
372 { 427 {
373 val = rxvt_malloc (5 + strlen (id) + 1); 428 val = rxvt_malloc (5 + strlen (id) + 1);
374 strcpy (val, "unix/"); 429 strcpy (val, "unix/");
375 strcat (val, id); 430 strcat (val, id);
376 display = XOpenDisplay (val); 431 dpy = XOpenDisplay (val);
377 free (val); 432 free (val);
378 } 433 }
379 else 434 else
380#endif 435#endif
381 display = 0; 436 dpy = 0;
382 437
383 if (!display) 438 if (!dpy)
384 display = XOpenDisplay (id); 439 dpy = XOpenDisplay (id);
385 440
386 if (!display) 441 if (!dpy)
387 return false; 442 return false;
388 443
389 screen = DefaultScreen (display); 444 screen = DefaultScreen (dpy);
390 root = DefaultRootWindow (display); 445 root = DefaultRootWindow (dpy);
391 446
392 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); 447 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA);
393 XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa); 448 XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa);
394 449
395 XrmSetDatabase (display, get_resources (false)); 450 XrmSetDatabase (dpy, get_resources (false));
396 451
397#ifdef POINTER_BLANK 452#ifdef POINTER_BLANK
398 XColor blackcolour; 453 XColor blackcolour;
399 blackcolour.red = 0; 454 blackcolour.red = 0;
400 blackcolour.green = 0; 455 blackcolour.green = 0;
401 blackcolour.blue = 0; 456 blackcolour.blue = 0;
402 Font f = XLoadFont (display, "fixed"); 457 Font f = XLoadFont (dpy, "fixed");
403 blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', 458 blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ',
404 &blackcolour, &blackcolour); 459 &blackcolour, &blackcolour);
405 XUnloadFont (display, f); 460 XUnloadFont (dpy, f);
406#endif 461#endif
407 462
408 int fd = XConnectionNumber (display); 463 int fd = XConnectionNumber (dpy);
409 464
410#ifndef NO_SLOW_LINK_SUPPORT
411 // try to detect wether we have a local connection. 465 // try to detect wether we have a local connection.
412 // assume unix domains socket == local, everything else not 466 // assume unix domains socket == local, everything else not
413 // TODO: might want to check for inet/127.0.0.1 467 // TODO: might want to check for inet/127.0.0.1
414 is_local = 0; 468 is_local = 0;
415 sockaddr_un sa; 469 sockaddr_un sa;
416 socklen_t sl = sizeof (sa); 470 socklen_t sl = sizeof (sa);
417 471
418 if (!getsockname (fd, (sockaddr *)&sa, &sl)) 472 if (!getsockname (fd, (sockaddr *)&sa, &sl))
419 is_local = sa.sun_family == AF_LOCAL; 473 is_local = sa.sun_family == AF_LOCAL;
420#endif
421 474
422 x_ev.start (fd, EVENT_READ); 475 x_ev.start (fd, EVENT_READ);
423 fcntl (fd, F_SETFD, FD_CLOEXEC); 476 fcntl (fd, F_SETFD, FD_CLOEXEC);
424 477
425 XSelectInput (display, root, PropertyChangeMask); 478 XSelectInput (dpy, root, PropertyChangeMask);
426 479
427 flush (); 480 flush ();
428 481
429 return true; 482 return true;
430} 483}
432void 485void
433rxvt_display::ref_next () 486rxvt_display::ref_next ()
434{ 487{
435 // TODO: somehow check wether the database files/resources changed 488 // TODO: somehow check wether the database files/resources changed
436 // before affording re-loading/parsing 489 // before affording re-loading/parsing
437 XrmDestroyDatabase (XrmGetDatabase (display)); 490 XrmDestroyDatabase (XrmGetDatabase (dpy));
438 XrmSetDatabase (display, get_resources (true)); 491 XrmSetDatabase (dpy, get_resources (true));
439} 492}
440 493
441rxvt_display::~rxvt_display () 494rxvt_display::~rxvt_display ()
442{ 495{
443 if (!display) 496 if (!dpy)
444 return; 497 return;
445 498
446#ifdef POINTER_BLANK 499#ifdef POINTER_BLANK
447 XFreeCursor (display, blank_cursor); 500 XFreeCursor (dpy, blank_cursor);
448#endif 501#endif
449 x_ev.stop (); 502 x_ev.stop ();
450#ifdef USE_XIM 503#ifdef USE_XIM
451 xims.clear (); 504 xims.clear ();
452#endif 505#endif
453 XCloseDisplay (display); 506 XCloseDisplay (dpy);
454} 507}
455 508
456#ifdef USE_XIM 509#ifdef USE_XIM
457void rxvt_display::im_change_cb () 510void rxvt_display::im_change_cb ()
458{ 511{
466 // registers, as xlib crashes due to a race otherwise. 519 // registers, as xlib crashes due to a race otherwise.
467 Atom actual_type, *atoms; 520 Atom actual_type, *atoms;
468 int actual_format; 521 int actual_format;
469 unsigned long nitems, bytes_after; 522 unsigned long nitems, bytes_after;
470 523
471 if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L, 524 if (XGetWindowProperty (dpy, root, xa[XA_XIM_SERVERS], 0L, 1000000L,
472 False, XA_ATOM, &actual_type, &actual_format, 525 False, XA_ATOM, &actual_type, &actual_format,
473 &nitems, &bytes_after, (unsigned char **)&atoms) 526 &nitems, &bytes_after, (unsigned char **)&atoms)
474 != Success ) 527 != Success )
475 return; 528 return;
476 529
477 if (actual_type == XA_ATOM && actual_format == 32) 530 if (actual_type == XA_ATOM && actual_format == 32)
478 for (int i = 0; i < nitems; i++) 531 for (int i = 0; i < nitems; i++)
479 if (XGetSelectionOwner (display, atoms[i])) 532 if (XGetSelectionOwner (dpy, atoms[i]))
480 { 533 {
481 im_change_cb (); 534 im_change_cb ();
482 break; 535 break;
483 } 536 }
484 537
489void rxvt_display::x_cb (io_watcher &w, short revents) 542void rxvt_display::x_cb (io_watcher &w, short revents)
490{ 543{
491 do 544 do
492 { 545 {
493 XEvent xev; 546 XEvent xev;
494 XNextEvent (display, &xev); 547 XNextEvent (dpy, &xev);
495 548
496#ifdef USE_XIM 549#ifdef USE_XIM
497 if (!XFilterEvent (&xev, None)) 550 if (!XFilterEvent (&xev, None))
498 { 551 {
499 if (xev.type == PropertyNotify 552 if (xev.type == PropertyNotify
510 } 563 }
511#ifdef USE_XIM 564#ifdef USE_XIM
512 } 565 }
513#endif 566#endif
514 } 567 }
515 while (XEventsQueued (display, QueuedAlready)); 568 while (XEventsQueued (dpy, QueuedAlready));
516 569
517 XFlush (display); 570 XFlush (dpy);
518} 571}
519 572
520void rxvt_display::flush () 573void rxvt_display::flush ()
521{ 574{
522 if (XEventsQueued (display, QueuedAlready)) 575 if (XEventsQueued (dpy, QueuedAlready))
523 x_cb (x_ev, EVENT_READ); 576 x_cb (x_ev, EVENT_READ);
524 577
525 XFlush (display); 578 XFlush (dpy);
526} 579}
527 580
528void rxvt_display::reg (xevent_watcher *w) 581void rxvt_display::reg (xevent_watcher *w)
529{ 582{
530 xw.push_back (w); 583 xw.push_back (w);
587 640
588#endif 641#endif
589 642
590Atom rxvt_display::atom (const char *name) 643Atom rxvt_display::atom (const char *name)
591{ 644{
592 return XInternAtom (display, name, False); 645 return XInternAtom (dpy, name, False);
593} 646}
594 647
595///////////////////////////////////////////////////////////////////////////// 648/////////////////////////////////////////////////////////////////////////////
596 649
597template class refcache<rxvt_display>; 650template class refcache<rxvt_display>;
607 660
608 // FUCKING Xft gets it wrong, of course, so work around it. 661 // FUCKING Xft gets it wrong, of course, so work around it.
609 // Transparency users should eat shit and die, and then 662 // Transparency users should eat shit and die, and then
610 // XRenderQueryPictIndexValues themselves plenty. 663 // XRenderQueryPictIndexValues themselves plenty.
611 if ((screen->visual->c_class == TrueColor) 664 if ((screen->visual->c_class == TrueColor)
612 && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual))) 665 && (format = XRenderFindVisualFormat (screen->dpy, screen->visual)))
613 { 666 {
614 // the fun lies in doing everything manually... 667 // the fun lies in doing everything manually...
615 c.color.red = color.r; 668 c.color.red = color.r;
616 c.color.green = color.g; 669 c.color.green = color.g;
617 c.color.blue = color.b; 670 c.color.blue = color.b;
631 d.red = color.r; 684 d.red = color.r;
632 d.green = color.g; 685 d.green = color.g;
633 d.blue = color.b; 686 d.blue = color.b;
634 d.alpha = color.a; 687 d.alpha = color.a;
635 688
636 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); 689 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c);
637 } 690 }
638#else 691#else
639 c.red = color.r; 692 c.red = color.r;
640 c.green = color.g; 693 c.green = color.g;
641 c.blue = color.b; 694 c.blue = color.b;
649 | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) 702 | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask ))
650 / rgba::MAX_CC) << ctz (screen->visual->blue_mask ); 703 / rgba::MAX_CC) << ctz (screen->visual->blue_mask );
651 704
652 return true; 705 return true;
653 } 706 }
654 else if (XAllocColor (screen->xdisp, screen->cmap, &c)) 707 else if (XAllocColor (screen->dpy, screen->cmap, &c))
655 return true; 708 return true;
656 else 709 else
657 c.pixel = (color.r + color.g + color.b) > 128*3 710 c.pixel = (color.r + color.g + color.b) > 128*3
658 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)) 711 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
659 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)); 712 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
660#endif 713#endif
661 714
662 return false; 715 return false;
663} 716}
664 717
681 // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format 734 // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format
682 if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) 735 if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos))
683 { 736 {
684 XColor xc, xc_exact; 737 XColor xc, xc_exact;
685 738
686 if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) 739 if (XParseColor (screen->dpy, screen->cmap, name, &xc))
687 { 740 {
688 c.r = xc.red; 741 c.r = xc.red;
689 c.g = xc.green; 742 c.g = xc.green;
690 c.b = xc.blue; 743 c.b = xc.blue;
691 } 744 }
719 for (int i = 0; i < cmap_size; i++) 772 for (int i = 0; i < cmap_size; i++)
720 colors [i].pixel = i; 773 colors [i].pixel = i;
721 774
722 // many kilobytes transfer per colour, but pseudocolor isn't worth 775 // many kilobytes transfer per colour, but pseudocolor isn't worth
723 // many extra optimisations. 776 // many extra optimisations.
724 XQueryColors (screen->xdisp, screen->cmap, colors, cmap_size); 777 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
725 778
726 int diff = 0x7fffffffUL; 779 int diff = 0x7fffffffUL;
727 XColor *best = colors; 780 XColor *best = colors;
728 781
729 for (int i = 0; i < cmap_size; i++) 782 for (int i = 0; i < cmap_size; i++)
780} 833}
781 834
782void 835void
783rxvt_color::free (rxvt_screen *screen) 836rxvt_color::free (rxvt_screen *screen)
784{ 837{
838 if (screen->visual->c_class == TrueColor)
839 return; // nothing to do
840
785#if XFT 841#if XFT
786 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); 842 XftColorFree (screen->dpy, screen->visual, screen->cmap, &c);
787#else 843#else
788 XFreeColors (screen->xdisp, screen->cmap, &c.pixel, 1, AllPlanes); 844 XFreeColors (screen->dpy, screen->cmap, &c.pixel, 1, AllPlanes);
789#endif 845#endif
790} 846}
791 847
792void 848void
793rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to) 849rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines