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.45 by root, Wed Feb 1 01:58:47 2006 UTC vs.
Revision 1.49 by root, Thu Feb 2 14:41:00 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, NULL, NULL, NULL); 182 xim = XOpenIM (display->display, 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;
188 ximcallback.client_data = (XPointer)this; 188 ximcallback.client_data = (XPointer)this;
189 ximcallback.callback = im_destroy_cb; 189 ximcallback.callback = im_destroy_cb;
190 190
191 XSetIMValues (xim, XNDestroyCallback, &ximcallback, NULL); 191 XSetIMValues (xim, XNDestroyCallback, &ximcallback, 0);
192 192
193 return true; 193 return true;
194} 194}
195 195
196rxvt_xim::~rxvt_xim () 196rxvt_xim::~rxvt_xim ()
248, selection_owner (0) 248, selection_owner (0)
249{ 249{
250} 250}
251 251
252XrmDatabase 252XrmDatabase
253rxvt_display::get_resources () 253rxvt_display::get_resources (bool refresh)
254{ 254{
255 char *homedir = (char *)getenv ("HOME"); 255 char *homedir = (char *)getenv ("HOME");
256 char fname[1024]; 256 char fname[1024];
257 257
258 /* 258 /*
259 * get resources using the X library function 259 * get resources using the X library function
260 */ 260 */
261 char *displayResource, *xe; 261 char *displayResource, *xe;
262 XrmDatabase database, rdb1; 262 XrmDatabase rdb1, database = 0;
263
264 database = NULL;
265 263
266 // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 264 // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20
267 265
268 // 6. System wide per application default file. 266 // 6. System wide per application default file.
269 267
279 // 5. User's per application default file. 277 // 5. User's per application default file.
280 // none 278 // none
281 279
282 // 4. User's defaults file. 280 // 4. User's defaults file.
283 /* Get any Xserver defaults */ 281 /* Get any Xserver defaults */
282 if (refresh)
283 {
284 // fucking xlib keeps a copy of the rm string
285 Atom actual_type;
286 int actual_format;
287 unsigned long nitems, nremaining;
288 char *val = 0;
289
290#if XLIB_ILLEGAL_ACCESS
291 if (display->xdefaults)
292 XFree (display->xdefaults);
293#endif
294
295 if (XGetWindowProperty (display, root, XA_RESOURCE_MANAGER,
296 0L, 100000000L, False,
297 XA_STRING, &actual_type, &actual_format,
298 &nitems, &nremaining,
299 (unsigned char **)&val) == Success
300 && actual_type == XA_STRING
301 && actual_format == 8)
302 displayResource = val;
303 else
304 {
305 displayResource = 0;
306 if (val)
307 XFree(val);
308 }
309
310#if XLIB_ILLEGAL_ACCESS
311 display->xdefaults = displayResource;
312#endif
313 }
314 else
284 displayResource = XResourceManagerString (display); 315 displayResource = XResourceManagerString (display);
285 316
286 if (displayResource != NULL) 317 if (displayResource)
287 { 318 {
288 if ((rdb1 = XrmGetStringDatabase (displayResource))) 319 if ((rdb1 = XrmGetStringDatabase (displayResource)))
289 XrmMergeDatabases (rdb1, &database); 320 XrmMergeDatabases (rdb1, &database);
290 } 321 }
291 else if (homedir) 322 else if (homedir)
294 325
295 if ((rdb1 = XrmGetFileDatabase (fname))) 326 if ((rdb1 = XrmGetFileDatabase (fname)))
296 XrmMergeDatabases (rdb1, &database); 327 XrmMergeDatabases (rdb1, &database);
297 } 328 }
298 329
330#if !XLIB_ILLEGAL_ACCESS
331 if (refresh && displayResource)
332 XFree (displayResource);
333#endif
334
299 /* Get screen specific resources */ 335 /* Get screen specific resources */
300 displayResource = XScreenResourceString (ScreenOfDisplay (display, screen)); 336 displayResource = XScreenResourceString (ScreenOfDisplay (display, screen));
301 337
302 if (displayResource != NULL) 338 if (displayResource)
303 { 339 {
304 if ((rdb1 = XrmGetStringDatabase (displayResource))) 340 if ((rdb1 = XrmGetStringDatabase (displayResource)))
305 /* Merge with screen-independent resources */ 341 /* Merge with screen-independent resources */
306 XrmMergeDatabases (rdb1, &database); 342 XrmMergeDatabases (rdb1, &database);
307 343
348 display = XOpenDisplay (id); 384 display = XOpenDisplay (id);
349 385
350 if (!display) 386 if (!display)
351 return false; 387 return false;
352 388
353 screen = DefaultScreen (display); 389 screen = DefaultScreen (display);
354 root = DefaultRootWindow (display); 390 root = DefaultRootWindow (display);
355 391
356 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); 392 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA);
357 XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa); 393 XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa);
358 394
359 XrmSetDatabase (display, get_resources ()); 395 XrmSetDatabase (display, get_resources (false));
360 396
361#ifdef POINTER_BLANK 397#ifdef POINTER_BLANK
362 XColor blackcolour; 398 XColor blackcolour;
363 blackcolour.red = 0; 399 blackcolour.red = 0;
364 blackcolour.green = 0; 400 blackcolour.green = 0;
395 431
396void 432void
397rxvt_display::ref_next () 433rxvt_display::ref_next ()
398{ 434{
399 // TODO: somehow check wether the database files/resources changed 435 // TODO: somehow check wether the database files/resources changed
400 // before re-loading/parsing 436 // before affording re-loading/parsing
401 XrmDestroyDatabase (XrmGetDatabase (display)); 437 XrmDestroyDatabase (XrmGetDatabase (display));
402 XrmSetDatabase (display, get_resources ()); 438 XrmSetDatabase (display, get_resources (true));
403} 439}
404 440
405rxvt_display::~rxvt_display () 441rxvt_display::~rxvt_display ()
406{ 442{
407 if (!display) 443 if (!display)
508 544
509 selection_owner = owner; 545 selection_owner = owner;
510} 546}
511 547
512#ifdef USE_XIM 548#ifdef USE_XIM
549
513void rxvt_display::reg (im_watcher *w) 550void rxvt_display::reg (im_watcher *w)
514{ 551{
515 imw.push_back (w); 552 imw.push_back (w);
516} 553}
517 554
541 return xim; 578 return xim;
542} 579}
543 580
544void rxvt_display::put_xim (rxvt_xim *xim) 581void rxvt_display::put_xim (rxvt_xim *xim)
545{ 582{
546#if XLIB_IS_RACEFREE 583# if XLIB_IS_RACEFREE
547 xims.put (xim); 584 xims.put (xim);
548#endif 585# endif
549} 586}
587
550#endif 588#endif
551 589
552Atom rxvt_display::atom (const char *name) 590Atom rxvt_display::atom (const char *name)
553{ 591{
554 return XInternAtom (display, name, False); 592 return XInternAtom (display, name, False);
565rxvt_color::alloc (rxvt_screen *screen, const rgba &color) 603rxvt_color::alloc (rxvt_screen *screen, const rgba &color)
566{ 604{
567#if XFT 605#if XFT
568 XRenderPictFormat *format; 606 XRenderPictFormat *format;
569 607
570 // FUCKING Xft gets it wrong, of course, so work around it 608 // FUCKING Xft gets it wrong, of course, so work around it.
571 // transparency users should eat shit and die, and then 609 // Transparency users should eat shit and die, and then
572 // XRenderQueryPictIndexValues themselves plenty. 610 // XRenderQueryPictIndexValues themselves plenty.
573 if ((screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor) 611 if ((screen->visual->c_class == TrueColor)
574 && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual))) 612 && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual)))
575 { 613 {
576 // the fun lies in doing everything manually... 614 // the fun lies in doing everything manually...
577 c.color.red = color.r; 615 c.color.red = color.r;
578 c.color.green = color.g; 616 c.color.green = color.g;
596 d.alpha = color.a; 634 d.alpha = color.a;
597 635
598 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); 636 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c);
599 } 637 }
600#else 638#else
601 if (screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor)
602 {
603 c.red = color.g; 639 c.red = color.r;
604 c.green = color.g; 640 c.green = color.g;
605 c.blue = color.g; 641 c.blue = color.b;
642
643 if (screen->visual->c_class == TrueColor)
644 {
606 c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) 645 c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask ))
607 / rgba::MAX_CC) << ctz (screen->visual->red_mask ) 646 / rgba::MAX_CC) << ctz (screen->visual->red_mask )
608 | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) 647 | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask))
609 / rgba::MAX_CC) << ctz (screen->visual->green_mask) 648 / rgba::MAX_CC) << ctz (screen->visual->green_mask)
610 | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) 649 | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask ))
611 / rgba::MAX_CC) << ctz (screen->visual->blue_mask ); 650 / rgba::MAX_CC) << ctz (screen->visual->blue_mask );
612 651
613 return true; 652 return true;
614 } 653 }
654 else if (XAllocColor (screen->xdisp, screen->cmap, &c))
655 return true;
615 else 656 else
616 {
617 c.red = color.r;
618 c.green = color.g;
619 c.blue = color.b;
620
621 if (XAllocColor (screen->xdisp, screen->cmap, &c))
622 return true;
623 else
624 c.pixel = (color.r + color.g + color.b) > 128*3 657 c.pixel = (color.r + color.g + color.b) > 128*3
625 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)) 658 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp))
626 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)); 659 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp));
627 }
628#endif 660#endif
629 661
630 return false; 662 return false;
631} 663}
632 664
635{ 667{
636 rgba c; 668 rgba c;
637 char eos; 669 char eos;
638 int skip; 670 int skip;
639 671
672 // parse the nonstandard "[alphapercent]" prefix
640 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) 673 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip))
641 { 674 {
642 c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a); 675 c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a);
643 name += skip; 676 name += skip;
644 } 677 }
645 else 678 else
646 c.a = rgba::MAX_CC; 679 c.a = rgba::MAX_CC;
647 680
648 // parse the non-standard rgba format 681 // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format
649 if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%hx/%hx/%hx/%hx%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))
650 { 683 {
651 XColor xc, xc_exact; 684 XColor xc, xc_exact;
652 685
653 if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) 686 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
654 { 687 {
732 color.b = c.blue; 765 color.b = c.blue;
733 color.a = rgba::MAX_CC; 766 color.a = rgba::MAX_CC;
734#endif 767#endif
735} 768}
736 769
770void
771rxvt_color::get (XColor &color)
772{
773 rgba c;
774 get (c);
775
776 color.red = c.r;
777 color.green = c.g;
778 color.blue = c.b;
779 color.pixel = (Pixel)*this;
780}
781
737void 782void
738rxvt_color::free (rxvt_screen *screen) 783rxvt_color::free (rxvt_screen *screen)
739{ 784{
740#if XFT 785#if XFT
741 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); 786 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines