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.50 by root, Thu Feb 2 18:04:46 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;
205 205
206void 206void
207rxvt_screen::set (rxvt_display *disp) 207rxvt_screen::set (rxvt_display *disp)
208{ 208{
209 display = disp; 209 display = disp;
210 xdisp = disp->display; 210 dpy = disp->dpy;
211 211
212 Screen *screen = ScreenOfDisplay (xdisp, disp->screen); 212 Screen *screen = ScreenOfDisplay (dpy, disp->screen);
213 213
214 depth = DefaultDepthOfScreen (screen); 214 depth = DefaultDepthOfScreen (screen);
215 visual = DefaultVisualOfScreen (screen); 215 visual = DefaultVisualOfScreen (screen);
216 cmap = DefaultColormapOfScreen (screen); 216 cmap = DefaultColormapOfScreen (screen);
217} 217}
222 set (disp); 222 set (disp);
223 223
224#if XFT 224#if XFT
225 XVisualInfo vinfo; 225 XVisualInfo vinfo;
226 226
227 if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo)) 227 if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo))
228 { 228 {
229 depth = bitdepth; 229 depth = bitdepth;
230 visual = vinfo.visual; 230 visual = vinfo.visual;
231 cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); 231 cmap = XCreateColormap (dpy, disp->root, visual, AllocNone);
232 } 232 }
233#endif 233#endif
234} 234}
235 235
236void 236void
237rxvt_screen::clear () 237rxvt_screen::clear ()
238{ 238{
239 if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (xdisp, display->screen))) 239 if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (dpy, display->screen)))
240 XFreeColormap (xdisp, cmap); 240 XFreeColormap (dpy, cmap);
241} 241}
242 242
243///////////////////////////////////////////////////////////////////////////// 243/////////////////////////////////////////////////////////////////////////////
244 244
245rxvt_display::rxvt_display (const char *id) 245rxvt_display::rxvt_display (const char *id)
286 int actual_format; 286 int actual_format;
287 unsigned long nitems, nremaining; 287 unsigned long nitems, nremaining;
288 char *val = 0; 288 char *val = 0;
289 289
290#if XLIB_ILLEGAL_ACCESS 290#if XLIB_ILLEGAL_ACCESS
291 if (display->xdefaults) 291 if (dpy->xdefaults)
292 XFree (display->xdefaults); 292 XFree (dpy->xdefaults);
293#endif 293#endif
294 294
295 if (XGetWindowProperty (display, root, XA_RESOURCE_MANAGER, 295 if (XGetWindowProperty (dpy, root, XA_RESOURCE_MANAGER,
296 0L, 100000000L, False, 296 0L, 100000000L, False,
297 XA_STRING, &actual_type, &actual_format, 297 XA_STRING, &actual_type, &actual_format,
298 &nitems, &nremaining, 298 &nitems, &nremaining,
299 (unsigned char **)&val) == Success 299 (unsigned char **)&val) == Success
300 && actual_type == XA_STRING 300 && actual_type == XA_STRING
306 if (val) 306 if (val)
307 XFree(val); 307 XFree(val);
308 } 308 }
309 309
310#if XLIB_ILLEGAL_ACCESS 310#if XLIB_ILLEGAL_ACCESS
311 display->xdefaults = displayResource; 311 dpy->xdefaults = displayResource;
312#endif 312#endif
313 } 313 }
314 else 314 else
315 displayResource = XResourceManagerString (display); 315 displayResource = XResourceManagerString (dpy);
316 316
317 if (displayResource) 317 if (displayResource)
318 { 318 {
319 if ((rdb1 = XrmGetStringDatabase (displayResource))) 319 if ((rdb1 = XrmGetStringDatabase (displayResource)))
320 XrmMergeDatabases (rdb1, &database); 320 XrmMergeDatabases (rdb1, &database);
331 if (refresh && displayResource) 331 if (refresh && displayResource)
332 XFree (displayResource); 332 XFree (displayResource);
333#endif 333#endif
334 334
335 /* Get screen specific resources */ 335 /* Get screen specific resources */
336 displayResource = XScreenResourceString (ScreenOfDisplay (display, screen)); 336 displayResource = XScreenResourceString (ScreenOfDisplay (dpy, screen));
337 337
338 if (displayResource) 338 if (displayResource)
339 { 339 {
340 if ((rdb1 = XrmGetStringDatabase (displayResource))) 340 if ((rdb1 = XrmGetStringDatabase (displayResource)))
341 /* Merge with screen-independent resources */ 341 /* Merge with screen-independent resources */
371 if (id[0] == ':') 371 if (id[0] == ':')
372 { 372 {
373 val = rxvt_malloc (5 + strlen (id) + 1); 373 val = rxvt_malloc (5 + strlen (id) + 1);
374 strcpy (val, "unix/"); 374 strcpy (val, "unix/");
375 strcat (val, id); 375 strcat (val, id);
376 display = XOpenDisplay (val); 376 dpy = XOpenDisplay (val);
377 free (val); 377 free (val);
378 } 378 }
379 else 379 else
380#endif 380#endif
381 display = 0; 381 dpy = 0;
382 382
383 if (!display) 383 if (!dpy)
384 display = XOpenDisplay (id); 384 dpy = XOpenDisplay (id);
385 385
386 if (!display) 386 if (!dpy)
387 return false; 387 return false;
388 388
389 screen = DefaultScreen (display); 389 screen = DefaultScreen (dpy);
390 root = DefaultRootWindow (display); 390 root = DefaultRootWindow (dpy);
391 391
392 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); 392 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA);
393 XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa); 393 XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa);
394 394
395 XrmSetDatabase (display, get_resources (false)); 395 XrmSetDatabase (dpy, get_resources (false));
396 396
397#ifdef POINTER_BLANK 397#ifdef POINTER_BLANK
398 XColor blackcolour; 398 XColor blackcolour;
399 blackcolour.red = 0; 399 blackcolour.red = 0;
400 blackcolour.green = 0; 400 blackcolour.green = 0;
401 blackcolour.blue = 0; 401 blackcolour.blue = 0;
402 Font f = XLoadFont (display, "fixed"); 402 Font f = XLoadFont (dpy, "fixed");
403 blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', 403 blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ',
404 &blackcolour, &blackcolour); 404 &blackcolour, &blackcolour);
405 XUnloadFont (display, f); 405 XUnloadFont (dpy, f);
406#endif 406#endif
407 407
408 int fd = XConnectionNumber (display); 408 int fd = XConnectionNumber (dpy);
409 409
410#ifndef NO_SLOW_LINK_SUPPORT 410#ifndef NO_SLOW_LINK_SUPPORT
411 // try to detect wether we have a local connection. 411 // try to detect wether we have a local connection.
412 // assume unix domains socket == local, everything else not 412 // assume unix domains socket == local, everything else not
413 // TODO: might want to check for inet/127.0.0.1 413 // TODO: might want to check for inet/127.0.0.1
420#endif 420#endif
421 421
422 x_ev.start (fd, EVENT_READ); 422 x_ev.start (fd, EVENT_READ);
423 fcntl (fd, F_SETFD, FD_CLOEXEC); 423 fcntl (fd, F_SETFD, FD_CLOEXEC);
424 424
425 XSelectInput (display, root, PropertyChangeMask); 425 XSelectInput (dpy, root, PropertyChangeMask);
426 426
427 flush (); 427 flush ();
428 428
429 return true; 429 return true;
430} 430}
432void 432void
433rxvt_display::ref_next () 433rxvt_display::ref_next ()
434{ 434{
435 // TODO: somehow check wether the database files/resources changed 435 // TODO: somehow check wether the database files/resources changed
436 // before affording re-loading/parsing 436 // before affording re-loading/parsing
437 XrmDestroyDatabase (XrmGetDatabase (display)); 437 XrmDestroyDatabase (XrmGetDatabase (dpy));
438 XrmSetDatabase (display, get_resources (true)); 438 XrmSetDatabase (dpy, get_resources (true));
439} 439}
440 440
441rxvt_display::~rxvt_display () 441rxvt_display::~rxvt_display ()
442{ 442{
443 if (!display) 443 if (!dpy)
444 return; 444 return;
445 445
446#ifdef POINTER_BLANK 446#ifdef POINTER_BLANK
447 XFreeCursor (display, blank_cursor); 447 XFreeCursor (dpy, blank_cursor);
448#endif 448#endif
449 x_ev.stop (); 449 x_ev.stop ();
450#ifdef USE_XIM 450#ifdef USE_XIM
451 xims.clear (); 451 xims.clear ();
452#endif 452#endif
453 XCloseDisplay (display); 453 XCloseDisplay (dpy);
454} 454}
455 455
456#ifdef USE_XIM 456#ifdef USE_XIM
457void rxvt_display::im_change_cb () 457void rxvt_display::im_change_cb ()
458{ 458{
466 // registers, as xlib crashes due to a race otherwise. 466 // registers, as xlib crashes due to a race otherwise.
467 Atom actual_type, *atoms; 467 Atom actual_type, *atoms;
468 int actual_format; 468 int actual_format;
469 unsigned long nitems, bytes_after; 469 unsigned long nitems, bytes_after;
470 470
471 if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L, 471 if (XGetWindowProperty (dpy, root, xa[XA_XIM_SERVERS], 0L, 1000000L,
472 False, XA_ATOM, &actual_type, &actual_format, 472 False, XA_ATOM, &actual_type, &actual_format,
473 &nitems, &bytes_after, (unsigned char **)&atoms) 473 &nitems, &bytes_after, (unsigned char **)&atoms)
474 != Success ) 474 != Success )
475 return; 475 return;
476 476
477 if (actual_type == XA_ATOM && actual_format == 32) 477 if (actual_type == XA_ATOM && actual_format == 32)
478 for (int i = 0; i < nitems; i++) 478 for (int i = 0; i < nitems; i++)
479 if (XGetSelectionOwner (display, atoms[i])) 479 if (XGetSelectionOwner (dpy, atoms[i]))
480 { 480 {
481 im_change_cb (); 481 im_change_cb ();
482 break; 482 break;
483 } 483 }
484 484
489void rxvt_display::x_cb (io_watcher &w, short revents) 489void rxvt_display::x_cb (io_watcher &w, short revents)
490{ 490{
491 do 491 do
492 { 492 {
493 XEvent xev; 493 XEvent xev;
494 XNextEvent (display, &xev); 494 XNextEvent (dpy, &xev);
495 495
496#ifdef USE_XIM 496#ifdef USE_XIM
497 if (!XFilterEvent (&xev, None)) 497 if (!XFilterEvent (&xev, None))
498 { 498 {
499 if (xev.type == PropertyNotify 499 if (xev.type == PropertyNotify
510 } 510 }
511#ifdef USE_XIM 511#ifdef USE_XIM
512 } 512 }
513#endif 513#endif
514 } 514 }
515 while (XEventsQueued (display, QueuedAlready)); 515 while (XEventsQueued (dpy, QueuedAlready));
516 516
517 XFlush (display); 517 XFlush (dpy);
518} 518}
519 519
520void rxvt_display::flush () 520void rxvt_display::flush ()
521{ 521{
522 if (XEventsQueued (display, QueuedAlready)) 522 if (XEventsQueued (dpy, QueuedAlready))
523 x_cb (x_ev, EVENT_READ); 523 x_cb (x_ev, EVENT_READ);
524 524
525 XFlush (display); 525 XFlush (dpy);
526} 526}
527 527
528void rxvt_display::reg (xevent_watcher *w) 528void rxvt_display::reg (xevent_watcher *w)
529{ 529{
530 xw.push_back (w); 530 xw.push_back (w);
587 587
588#endif 588#endif
589 589
590Atom rxvt_display::atom (const char *name) 590Atom rxvt_display::atom (const char *name)
591{ 591{
592 return XInternAtom (display, name, False); 592 return XInternAtom (dpy, name, False);
593} 593}
594 594
595///////////////////////////////////////////////////////////////////////////// 595/////////////////////////////////////////////////////////////////////////////
596 596
597template class refcache<rxvt_display>; 597template class refcache<rxvt_display>;
607 607
608 // FUCKING Xft gets it wrong, of course, so work around it. 608 // FUCKING Xft gets it wrong, of course, so work around it.
609 // Transparency users should eat shit and die, and then 609 // Transparency users should eat shit and die, and then
610 // XRenderQueryPictIndexValues themselves plenty. 610 // XRenderQueryPictIndexValues themselves plenty.
611 if ((screen->visual->c_class == TrueColor) 611 if ((screen->visual->c_class == TrueColor)
612 && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual))) 612 && (format = XRenderFindVisualFormat (screen->dpy, screen->visual)))
613 { 613 {
614 // the fun lies in doing everything manually... 614 // the fun lies in doing everything manually...
615 c.color.red = color.r; 615 c.color.red = color.r;
616 c.color.green = color.g; 616 c.color.green = color.g;
617 c.color.blue = color.b; 617 c.color.blue = color.b;
631 d.red = color.r; 631 d.red = color.r;
632 d.green = color.g; 632 d.green = color.g;
633 d.blue = color.b; 633 d.blue = color.b;
634 d.alpha = color.a; 634 d.alpha = color.a;
635 635
636 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); 636 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c);
637 } 637 }
638#else 638#else
639 c.red = color.r; 639 c.red = color.r;
640 c.green = color.g; 640 c.green = color.g;
641 c.blue = color.b; 641 c.blue = color.b;
649 | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) 649 | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask ))
650 / rgba::MAX_CC) << ctz (screen->visual->blue_mask ); 650 / rgba::MAX_CC) << ctz (screen->visual->blue_mask );
651 651
652 return true; 652 return true;
653 } 653 }
654 else if (XAllocColor (screen->xdisp, screen->cmap, &c)) 654 else if (XAllocColor (screen->dpy, screen->cmap, &c))
655 return true; 655 return true;
656 else 656 else
657 c.pixel = (color.r + color.g + color.b) > 128*3 657 c.pixel = (color.r + color.g + color.b) > 128*3
658 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)) 658 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
659 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)); 659 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
660#endif 660#endif
661 661
662 return false; 662 return false;
663} 663}
664 664
681 // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format 681 // 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)) 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))
683 { 683 {
684 XColor xc, xc_exact; 684 XColor xc, xc_exact;
685 685
686 if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) 686 if (XParseColor (screen->dpy, screen->cmap, name, &xc))
687 { 687 {
688 c.r = xc.red; 688 c.r = xc.red;
689 c.g = xc.green; 689 c.g = xc.green;
690 c.b = xc.blue; 690 c.b = xc.blue;
691 } 691 }
719 for (int i = 0; i < cmap_size; i++) 719 for (int i = 0; i < cmap_size; i++)
720 colors [i].pixel = i; 720 colors [i].pixel = i;
721 721
722 // many kilobytes transfer per colour, but pseudocolor isn't worth 722 // many kilobytes transfer per colour, but pseudocolor isn't worth
723 // many extra optimisations. 723 // many extra optimisations.
724 XQueryColors (screen->xdisp, screen->cmap, colors, cmap_size); 724 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
725 725
726 int diff = 0x7fffffffUL; 726 int diff = 0x7fffffffUL;
727 XColor *best = colors; 727 XColor *best = colors;
728 728
729 for (int i = 0; i < cmap_size; i++) 729 for (int i = 0; i < cmap_size; i++)
781 781
782void 782void
783rxvt_color::free (rxvt_screen *screen) 783rxvt_color::free (rxvt_screen *screen)
784{ 784{
785#if XFT 785#if XFT
786 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); 786 XftColorFree (screen->dpy, screen->visual, screen->cmap, &c);
787#else 787#else
788 XFreeColors (screen->xdisp, screen->cmap, &c.pixel, 1, AllPlanes); 788 XFreeColors (screen->dpy, screen->cmap, &c.pixel, 1, AllPlanes);
789#endif 789#endif
790} 790}
791 791
792void 792void
793rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to) 793rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines