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.51 by root, Sat Feb 18 14:14:43 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines