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

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.201 by root, Wed Jan 25 00:57:57 2006 UTC vs.
Revision 1.234 by root, Sat Jun 9 13:04:27 2007 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: main.C 2 * File: main.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
56static char curlocale[128], savelocale[128]; 56static char curlocale[128], savelocale[128];
57 57
58bool 58bool
59rxvt_set_locale (const char *locale) NOTHROW 59rxvt_set_locale (const char *locale) NOTHROW
60{ 60{
61 int size = strlen (locale) + 1;
62
63 if (size > sizeof (curlocale))
64 rxvt_fatal ("locale string too long, aborting.\n");
65
61 if (!locale || !strncmp (locale, curlocale, 128)) 66 if (!locale || !memcmp (locale, curlocale, size))
62 return false; 67 return false;
63 68
64 strncpy (curlocale, locale, 128); 69 memcpy (curlocale, locale, size);
65 setlocale (LC_CTYPE, curlocale); 70 setlocale (LC_CTYPE, curlocale);
66 return true; 71 return true;
67} 72}
68 73
69void 74void
143} 148}
144#endif 149#endif
145 150
146rxvt_term::rxvt_term () 151rxvt_term::rxvt_term ()
147 : 152 :
148#if TRANSPARENT 153#if TRANSPARENT || ENABLE_PERL
149 rootwin_ev (this, &rxvt_term::rootwin_cb), 154 rootwin_ev (this, &rxvt_term::rootwin_cb),
155 check_our_parents_ev(this, &rxvt_term::check_our_parents_cb),
150#endif 156#endif
151#ifdef HAVE_SCROLLBARS 157#ifdef HAVE_SCROLLBARS
152 scrollbar_ev (this, &rxvt_term::x_cb), 158 scrollbar_ev (this, &rxvt_term::x_cb),
153#endif 159#endif
154#ifdef CURSOR_BLINK 160#ifdef CURSOR_BLINK
198void rxvt_term::emergency_cleanup () 204void rxvt_term::emergency_cleanup ()
199{ 205{
200 if (cmd_pid) 206 if (cmd_pid)
201 kill (-cmd_pid, SIGHUP); 207 kill (-cmd_pid, SIGHUP);
202 208
209 pty_ev.stop ();
203 delete pty; pty = 0; 210 delete pty; pty = 0;
204} 211}
205 212
206rxvt_term::~rxvt_term () 213rxvt_term::~rxvt_term ()
207{ 214{
216#endif 223#endif
217 delete fontset[0]; 224 delete fontset[0];
218 225
219 if (display) 226 if (display)
220 { 227 {
221 dDisp;
222
223 selection_clear (); 228 selection_clear ();
224 229
225#ifdef USE_XIM 230#ifdef USE_XIM
226 im_destroy (); 231 im_destroy ();
227#endif 232#endif
228#ifdef XTERM_SCROLLBAR 233#ifdef XTERM_SCROLLBAR
229 if (xscrollbarGC) XFreeGC (disp, xscrollbarGC); 234 if (xscrollbarGC) XFreeGC (dpy, xscrollbarGC);
230 if (ShadowGC) XFreeGC (disp, ShadowGC); 235 if (ShadowGC) XFreeGC (dpy, ShadowGC);
231#endif 236#endif
232#ifdef PLAIN_SCROLLBAR 237#ifdef PLAIN_SCROLLBAR
233 if (pscrollbarGC) XFreeGC (disp, pscrollbarGC); 238 if (pscrollbarGC) XFreeGC (dpy, pscrollbarGC);
234#endif 239#endif
235#ifdef NEXT_SCROLLBAR 240#ifdef NEXT_SCROLLBAR
236 if (blackGC) XFreeGC (disp, blackGC); 241 if (blackGC) XFreeGC (dpy, blackGC);
237 if (whiteGC) XFreeGC (disp, whiteGC); 242 if (whiteGC) XFreeGC (dpy, whiteGC);
238 if (grayGC) XFreeGC (disp, grayGC); 243 if (grayGC) XFreeGC (dpy, grayGC);
239 if (darkGC) XFreeGC (disp, darkGC); 244 if (darkGC) XFreeGC (dpy, darkGC);
240 if (stippleGC) XFreeGC (disp, stippleGC); 245 if (stippleGC) XFreeGC (dpy, stippleGC);
241 if (dimple) XFreePixmap (disp, dimple); 246 if (dimple) XFreePixmap (dpy, dimple);
242 if (upArrow) XFreePixmap (disp, upArrow); 247 if (upArrow) XFreePixmap (dpy, upArrow);
243 if (downArrow) XFreePixmap (disp, downArrow); 248 if (downArrow) XFreePixmap (dpy, downArrow);
244 if (upArrowHi) XFreePixmap (disp, upArrowHi); 249 if (upArrowHi) XFreePixmap (dpy, upArrowHi);
245 if (downArrowHi) XFreePixmap (disp, downArrowHi); 250 if (downArrowHi) XFreePixmap (dpy, downArrowHi);
246#endif 251#endif
247#ifdef RXVT_SCROLLBAR 252#ifdef RXVT_SCROLLBAR
248 if (topShadowGC) XFreeGC (disp, topShadowGC); 253 if (topShadowGC) XFreeGC (dpy, topShadowGC);
249 if (botShadowGC) XFreeGC (disp, botShadowGC); 254 if (botShadowGC) XFreeGC (dpy, botShadowGC);
250 if (scrollbarGC) XFreeGC (disp, scrollbarGC); 255 if (scrollbarGC) XFreeGC (dpy, scrollbarGC);
251#endif 256#endif
252 if (gc) XFreeGC (disp, gc); 257 if (gc) XFreeGC (dpy, gc);
253 258
254 delete drawable; 259 delete drawable;
255 // destroy all windows 260 // destroy all windows
256 if (parent[0]) 261 if (parent[0])
257 XDestroyWindow (disp, parent[0]); 262 XDestroyWindow (dpy, parent[0]);
258 }
259 263
260 // TODO: free pixcolours, colours should become part of rxvt_display 264 for (int i = 0; i < TOTAL_COLORS; i++)
261 delete pix_colors_focused; 265 if (ISSET_PIXCOLOR (i))
266 {
267 pix_colors_focused [i].free (this);
262#if OFF_FOCUS_FADING 268#if OFF_FOCUS_FADING
269 pix_colors_unfocused [i].free (this);
270#endif
271 }
272
273 clear ();
274 }
275
276 delete [] pix_colors_focused;
277#if OFF_FOCUS_FADING
263 delete pix_colors_unfocused; 278 delete [] pix_colors_unfocused;
264#endif 279#endif
265 280
266 displays.put (display); 281 displays.put (display);
267 282
268 scr_release (); 283 scr_release ();
271 for (int i = 0; i < allocated.size (); i++) 286 for (int i = 0; i < allocated.size (); i++)
272 free (allocated [i]); 287 free (allocated [i]);
273 288
274 free (selection.text); 289 free (selection.text);
275 // TODO: manage env vars in child only(!) 290 // TODO: manage env vars in child only(!)
276 free (env_windowid);
277 free (env_display); 291 free (env_display);
278 free (env_term); 292 free (env_term);
279 free (env_colorfgbg);
280 free (locale); 293 free (locale);
281 free (v_buffer); 294 free (v_buffer);
282 free (incr_buf); 295 free (incr_buf);
283 296
284 delete envv; 297 delete envv;
295{ 308{
296 HOOK_INVOKE ((this, HOOK_CHILD_EXIT, DT_INT, status, DT_END)); 309 HOOK_INVOKE ((this, HOOK_CHILD_EXIT, DT_INT, status, DT_END));
297 310
298 cmd_pid = 0; 311 cmd_pid = 0;
299 312
300 if (!OPTION (Opt_hold)) 313 if (!option (Opt_hold))
301 destroy (); 314 destroy ();
302} 315}
303 316
304void 317void
305rxvt_term::destroy () 318rxvt_term::destroy ()
319 im_ev.stop (display); 332 im_ev.stop (display);
320#endif 333#endif
321#if HAVE_SCROLLBARS 334#if HAVE_SCROLLBARS
322 scrollbar_ev.stop (display); 335 scrollbar_ev.stop (display);
323#endif 336#endif
324#if TRANSPARENT 337#if TRANSPARENT || ENABLE_PERL
325 rootwin_ev.stop (display); 338 rootwin_ev.stop (display);
326#endif 339#endif
327 incr_ev.stop (); 340 incr_ev.stop ();
328 termwin_ev.stop (display); 341 termwin_ev.stop (display);
329 vt_ev.stop (display); 342 vt_ev.stop (display);
370{ 383{
371 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 384 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
372 (*t)->emergency_cleanup (); 385 (*t)->emergency_cleanup ();
373} 386}
374 387
375#if ENABLE_FRILLS 388#if !ENABLE_MINIMAL
376static void 389static void
377print_x_error (Display *dpy, XErrorEvent *event) 390print_x_error (Display *dpy, XErrorEvent *event)
378{ 391{
379 char buffer[BUFSIZ]; 392 char buffer[BUFSIZ];
380 char mesg[BUFSIZ]; 393 char mesg[BUFSIZ];
428 GET_R->allowedxerror = event->error_code; 441 GET_R->allowedxerror = event->error_code;
429 else 442 else
430 { 443 {
431 // GET_R is most likely not the terminal which caused the error, 444 // GET_R is most likely not the terminal which caused the error,
432 // so just output the error and continue 445 // so just output the error and continue
433#if ENABLE_FRILLS 446#if ENABLE_MINIMAL
447 old_xerror_handler (display, event);
448#else
434 print_x_error (display, event); 449 print_x_error (display, event);
435#else
436 old_xerror_handler (display, event);
437#endif 450#endif
438 } 451 }
439 452
440 return 0; 453 return 0;
441} 454}
469#ifdef KEYSYM_RESOURCE 482#ifdef KEYSYM_RESOURCE
470 keyboard->register_done (); 483 keyboard->register_done ();
471#endif 484#endif
472 485
473#ifdef HAVE_SCROLLBARS 486#ifdef HAVE_SCROLLBARS
474 if (OPTION (Opt_scrollBar)) 487 if (option (Opt_scrollBar))
475 scrollBar.setIdle (); /* set existence for size calculations */ 488 scrollBar.setIdle (); /* set existence for size calculations */
476#endif 489#endif
477 490
478 pty = ptytty::create (); 491 pty = ptytty::create ();
479 492
480 create_windows (argc, argv); 493 create_windows (argc, argv);
481 494
482 dDisp;
483
484 init_xlocale (); 495 init_xlocale ();
485 496
486 scr_reset (); // initialize screen 497 scr_reset (); // initialize screen
487 498
488#if 0 499#if 0
489 XSynchronize (disp, True); 500 XSynchronize (dpy, True);
490#endif 501#endif
491 502
492#ifdef HAVE_SCROLLBARS 503#ifdef HAVE_SCROLLBARS
493 if (OPTION (Opt_scrollBar)) 504 if (option (Opt_scrollBar))
494 resize_scrollbar (); /* create and map scrollbar */ 505 resize_scrollbar (); /* create and map scrollbar */
495#endif 506#endif
496#ifdef TRANSPARENT 507#ifdef TRANSPARENT
497 if (OPTION (Opt_transparent)) 508 if (option (Opt_transparent))
498 { 509 {
499 XSelectInput (disp, display->root, PropertyChangeMask); 510 XSelectInput (dpy, display->root, PropertyChangeMask);
500 check_our_parents (); 511 check_our_parents ();
501 rootwin_ev.start (display, display->root); 512 rootwin_ev.start (display, display->root);
502 } 513 }
503#endif 514#endif
515#if ENABLE_PERL
516 rootwin_ev.start (display, display->root);
517#endif
504 518
505 set_colorfgbg (); 519 set_colorfgbg ();
506 520
507 init_command (cmd_argv); 521 init_command (cmd_argv);
508 522
513 527
514 check_ev.start (); 528 check_ev.start ();
515 529
516 HOOK_INVOKE ((this, HOOK_START, DT_END)); 530 HOOK_INVOKE ((this, HOOK_START, DT_END));
517 531
532#if ENABLE_XEMBED
533 if (rs[Rs_embed])
534 {
535 long info[2] = { 0, XEMBED_MAPPED };
536
537 XChangeProperty (dpy, parent[0], xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO],
538 32, PropModeReplace, (unsigned char *)&info, 2);
539 }
540#endif
541
518 XMapWindow (disp, vt); 542 XMapWindow (dpy, vt);
519 XMapWindow (disp, parent[0]); 543 XMapWindow (dpy, parent[0]);
520 544
521 return true; 545 return true;
522} 546}
523 547
524static struct sig_handlers 548static struct sig_handlers
614{ 638{
615 short recalc_x, recalc_y; 639 short recalc_x, recalc_y;
616 int x, y, sb_w, flags; 640 int x, y, sb_w, flags;
617 unsigned int w, h; 641 unsigned int w, h;
618 unsigned int max_width, max_height; 642 unsigned int max_width, max_height;
619 dDisp;
620 643
621 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; 644 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity;
622 szHint.win_gravity = NorthWestGravity; 645 szHint.win_gravity = NorthWestGravity;
623 /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ 646 /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */
624 647
686 709
687 if (scrollBar.state) 710 if (scrollBar.state)
688 { 711 {
689 sb_w = scrollbar_TotalWidth (); 712 sb_w = scrollbar_TotalWidth ();
690 szHint.base_width += sb_w; 713 szHint.base_width += sb_w;
714
691 if (!OPTION (Opt_scrollBar_right)) 715 if (!option (Opt_scrollBar_right))
692 window_vt_x += sb_w; 716 window_vt_x += sb_w;
693 } 717 }
694 718
695 szHint.width_inc = fwidth; 719 szHint.width_inc = fwidth;
696 szHint.height_inc = fheight; 720 szHint.height_inc = fheight;
697 szHint.min_width = szHint.base_width + szHint.width_inc; 721 szHint.min_width = szHint.base_width + szHint.width_inc;
698 szHint.min_height = szHint.base_height + szHint.height_inc; 722 szHint.min_height = szHint.base_height + szHint.height_inc;
699 723
700 if (newwidth && newwidth - szHint.base_width < max_width) 724 if (newwidth && newwidth - szHint.base_width < max_width)
701 { 725 {
702 szHint.width = newwidth; 726 szHint.width = newwidth;
717 { 741 {
718 min_it (height, max_height); 742 min_it (height, max_height);
719 szHint.height = szHint.base_height + height; 743 szHint.height = szHint.base_height + height;
720 } 744 }
721 745
722 if (scrollBar.state && OPTION (Opt_scrollBar_right)) 746 if (scrollBar.state && option (Opt_scrollBar_right))
723 window_sb_x = szHint.width - sb_w; 747 window_sb_x = szHint.width - sb_w;
724 748
725 if (recalc_x) 749 if (recalc_x)
726 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; 750 szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth;
751
727 if (recalc_y) 752 if (recalc_y)
728 szHint.y += DisplayHeight (disp, display->screen) - szHint.height - 2 * ext_bwidth; 753 szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth;
729 754
730 ncol = width / fwidth; 755 ncol = width / fwidth;
731 nrow = height / fheight; 756 nrow = height / fheight;
732} 757}
733 758
788 delete fontset[0]; 813 delete fontset[0];
789 fontset[0] = fs; 814 fontset[0] = fs;
790 815
791 prop = (*fs)[1]->properties (); 816 prop = (*fs)[1]->properties ();
792 prop.height += lineSpace; 817 prop.height += lineSpace;
818
793 fs->set_prop (prop); 819 fs->set_prop (prop, false);
794 820
795 fwidth = prop.width; 821 fwidth = prop.width;
796 fheight = prop.height; 822 fheight = prop.height;
797 fbase = prop.ascent; 823 fbase = prop.ascent;
798 824
807 { 833 {
808 fontset[style] = fs = new rxvt_fontset (this); 834 fontset[style] = fs = new rxvt_fontset (this);
809 rxvt_fontprop prop2 = prop; 835 rxvt_fontprop prop2 = prop;
810 836
811 if (res) 837 if (res)
812 prop2.weight = prop2.slant = rxvt_fontprop::unset; 838 {
839 fs->populate (res);
840 fs->set_prop (prop2, false);
841 }
813 else 842 else
814 { 843 {
815 res = fontset[0]->fontdesc; 844 fs->populate (fontset[0]->fontdesc);
816 845
817 if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; 846 if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold;
818 if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; 847 if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic;
848
849 fs->set_prop (prop2, true);
819 } 850 }
820 851
821 fs->populate (res);
822 fs->set_prop (prop2);
823 } 852 }
824#else 853#else
825 fontset[style] = fontset[0]; 854 fontset[style] = fontset[0];
826#endif 855#endif
827 } 856 }
836 return true; 865 return true;
837} 866}
838 867
839void rxvt_term::set_string_property (Atom prop, const char *str, int len) 868void rxvt_term::set_string_property (Atom prop, const char *str, int len)
840{ 869{
841 XChangeProperty (display->display, parent[0], 870 XChangeProperty (dpy, parent[0],
842 prop, XA_STRING, 8, PropModeReplace, 871 prop, XA_STRING, 8, PropModeReplace,
843 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 872 (const unsigned char *)str, len >= 0 ? len : strlen (str));
844} 873}
845 874
846void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 875void rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
847{ 876{
848 wchar_t *ws = rxvt_mbstowcs (str, len); 877 wchar_t *ws = rxvt_mbstowcs (str, len);
849 char *s = rxvt_wcstoutf8 (ws); 878 char *s = rxvt_wcstoutf8 (ws);
850 879
851 XChangeProperty (display->display, parent[0], 880 XChangeProperty (dpy, parent[0],
852 prop, xa[XA_UTF8_STRING], 8, PropModeReplace, 881 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
853 (const unsigned char *)s, strlen (s)); 882 (const unsigned char *)s, strlen (s));
854 883
855 free (s); 884 free (s);
856 free (ws); 885 free (ws);
881void 910void
882rxvt_term::set_window_color (int idx, const char *color) 911rxvt_term::set_window_color (int idx, const char *color)
883{ 912{
884 rxvt_color xcol; 913 rxvt_color xcol;
885 int i; 914 int i;
886 915
887 if (color == NULL || *color == '\0') 916 if (color == NULL || *color == '\0')
888 return; 917 return;
918
919 color = strdup (color);
920 allocated.push_back ((void *)color);
921 rs[Rs_color + idx] = color;
889 922
890 /* handle color aliases */ 923 /* handle color aliases */
891 if (isdigit (*color)) 924 if (isdigit (*color))
892 { 925 {
893 i = atoi (color); 926 i = atoi (color);
894 927
895 if (i >= 8 && i <= 15) 928 if (i >= 8 && i <= 15)
896 { /* bright colors */ 929 { /* bright colors */
897 i -= 8; 930 i -= 8;
898 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 931 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
899 SET_PIXCOLOR (idx);
900 goto done; 932 goto done;
901 } 933 }
902 934
903 if (i >= 0 && i <= 7) 935 if (i >= 0 && i <= 7)
904 { /* normal colors */ 936 { /* normal colors */
905 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 937 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
906 SET_PIXCOLOR (idx);
907 goto done; 938 goto done;
908 } 939 }
909 } 940 }
910 941
911 if (!rXParseAllocColor (&xcol, color)) 942 set_color (xcol, color);
912 return;
913
914 /* XStoreColor (display->display, display->cmap, XColor*); */
915 943
916 /* 944 /*
917 * FIXME: should free colors here, but no idea how to do it so instead, 945 * FIXME: should free colors here, but no idea how to do it so instead,
918 * so just keep gobbling up the colormap 946 * so just keep gobbling up the colormap
919 */ 947 */
920# if 0
921 for (i = Color_Black; i <= Color_White; i++)
922 if (pix_colors[idx] == pix_colors[i])
923 break;
924 if (i > Color_White)
925 {
926 /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */
927 XFreeColors (display->display, display->cmap, (pix_colors + idx), 1,
928 DisplayPlanes (display->display, display->screen));
929 }
930# endif
931 948
932 pix_colors_focused[idx] = xcol; 949 pix_colors_focused[idx] = xcol;
933 SET_PIXCOLOR (idx);
934 950
935 /* XSetWindowAttributes attr; */ 951 /* XSetWindowAttributes attr; */
936 /* Cursor cursor; */ 952 /* Cursor cursor; */
937done: 953done:
938
939#if OFF_FOCUS_FADING
940 if (rs[Rs_fade])
941 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]), pix_colors[Color_fade]);
942#endif
943
944 /*TODO: handle Color_BD, scrollbar background, etc. */ 954 /*TODO: handle Color_BD, scrollbar background, etc. */
945 955
956 update_fade_color (idx);
946 recolour_cursor (); 957 recolour_cursor ();
947 scr_recolour (); 958 scr_recolour ();
948} 959}
949 960
950#else 961#else
952#endif /* XTERM_COLOR_CHANGE */ 963#endif /* XTERM_COLOR_CHANGE */
953 964
954void 965void
955rxvt_term::recolour_cursor () 966rxvt_term::recolour_cursor ()
956{ 967{
957 XColor xcol[2]; 968 XColor fg, bg;
958 969
959 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) 970 (ISSET_PIXCOLOR (Color_pointer_fg)
960 ? pix_colors_focused[Color_pointer_fg] 971 ? pix_colors_focused[Color_pointer_fg]
961 : pix_colors_focused[Color_fg]; 972 : pix_colors_focused[Color_fg]).get (fg);
973
962 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) 974 (ISSET_PIXCOLOR (Color_pointer_bg)
963 ? pix_colors_focused[Color_pointer_bg] 975 ? pix_colors_focused[Color_pointer_bg]
964 : pix_colors_focused[Color_bg]; 976 : pix_colors_focused[Color_bg]).get (bg);
965 977
966 XQueryColors (display->display, display->cmap, xcol, 2); 978 XRecolorCursor (dpy, TermWin_cursor, &fg, &bg);
967 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
968} 979}
969 980
970/*----------------------------------------------------------------------*/ 981/*----------------------------------------------------------------------*/
971/* 982/*
972 * find if fg/bg matches any of the normal (low-intensity) colors 983 * find if fg/bg matches any of the normal (low-intensity) colors
976{ 987{
977 unsigned int i; 988 unsigned int i;
978 const char *xpmb = "\0"; 989 const char *xpmb = "\0";
979 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; 990 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
980 991
981 env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
982 strcpy (fstr, "default"); 992 strcpy (fstr, "default");
983 strcpy (bstr, "default"); 993 strcpy (bstr, "default");
984 for (i = Color_Black; i <= Color_White; i++) 994 for (i = Color_Black; i <= Color_White; i++)
985 if (pix_colors[Color_fg] == pix_colors[i]) 995 if (pix_colors[Color_fg] == pix_colors[i])
986 { 996 {
1001 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 1011 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
1002} 1012}
1003 1013
1004/*----------------------------------------------------------------------*/ 1014/*----------------------------------------------------------------------*/
1005 1015
1006int 1016bool
1007rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 1017rxvt_term::set_color (rxvt_color &color, const char *name)
1008{ 1018{
1009 if (!screen_in_out->set (display, colour)) 1019 if (color.set (this, name))
1010 {
1011 rxvt_warn ("can't get colour '%s', continuing without.\n", colour);
1012 return false;
1013 }
1014
1015 return true; 1020 return true;
1021
1022 rxvt_warn ("can't get colour '%s', continuing without.\n", name);
1023 return false;
1024}
1025
1026void
1027rxvt_term::alias_color (int dst, int src)
1028{
1029 pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]);
1016} 1030}
1017 1031
1018/* -------------------------------------------------------------------- * 1032/* -------------------------------------------------------------------- *
1019 * - WINDOW RESIZING - * 1033 * - WINDOW RESIZING - *
1020 * -------------------------------------------------------------------- */ 1034 * -------------------------------------------------------------------- */
1022rxvt_term::resize_all_windows (unsigned int newwidth, unsigned int newheight, int ignoreparent) 1036rxvt_term::resize_all_windows (unsigned int newwidth, unsigned int newheight, int ignoreparent)
1023{ 1037{
1024 int fix_screen; 1038 int fix_screen;
1025 int old_width = szHint.width; 1039 int old_width = szHint.width;
1026 int old_height = szHint.height; 1040 int old_height = szHint.height;
1027 dDisp;
1028 1041
1029 window_calc (newwidth, newheight); 1042 window_calc (newwidth, newheight);
1043
1044 if (!HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END)))
1030 XSetWMNormalHints (disp, parent[0], &szHint); 1045 XSetWMNormalHints (dpy, parent[0], &szHint);
1031 1046
1032 if (!ignoreparent) 1047 if (!ignoreparent)
1033 { 1048 {
1034#ifdef SMART_RESIZE 1049#ifdef SMART_RESIZE
1035 /* 1050 /*
1039 int x, y, x1, y1; 1054 int x, y, x1, y1;
1040 int dx, dy; 1055 int dx, dy;
1041 unsigned int unused_w1, unused_h1, unused_b1, unused_d1; 1056 unsigned int unused_w1, unused_h1, unused_b1, unused_d1;
1042 Window unused_cr; 1057 Window unused_cr;
1043 1058
1044 XTranslateCoordinates (disp, parent[0], display->root, 1059 XTranslateCoordinates (dpy, parent[0], display->root,
1045 0, 0, &x, &y, &unused_cr); 1060 0, 0, &x, &y, &unused_cr);
1046 XGetGeometry (disp, parent[0], &unused_cr, &x1, &y1, 1061 XGetGeometry (dpy, parent[0], &unused_cr, &x1, &y1,
1047 &unused_w1, &unused_h1, &unused_b1, &unused_d1); 1062 &unused_w1, &unused_h1, &unused_b1, &unused_d1);
1048 /* 1063 /*
1049 * if display->root isn't the parent window, a WM will probably have offset 1064 * if display->root isn't the parent window, a WM will probably have offset
1050 * our position for handles and decorations. Counter it 1065 * our position for handles and decorations. Counter it
1051 */ 1066 */
1053 { 1068 {
1054 x -= x1; 1069 x -= x1;
1055 y -= y1; 1070 y -= y1;
1056 } 1071 }
1057 1072
1058 x1 = (DisplayWidth (disp, display->screen) - old_width ) / 2; 1073 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2;
1059 y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; 1074 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2;
1060 dx = old_width - szHint.width; 1075 dx = old_width - szHint.width;
1061 dy = old_height - szHint.height; 1076 dy = old_height - szHint.height;
1062 1077
1063 /* Check position of the center of the window */ 1078 /* Check position of the center of the window */
1064 if (x < x1) /* left half */ 1079 if (x < x1) /* left half */
1068 if (y < y1) /* top half */ 1083 if (y < y1) /* top half */
1069 dy = 0; 1084 dy = 0;
1070 else if (y == y1) /* exact center */ 1085 else if (y == y1) /* exact center */
1071 dy /= 2; 1086 dy /= 2;
1072 1087
1073 XMoveResizeWindow (disp, parent[0], x + dx, y + dy, 1088 XMoveResizeWindow (dpy, parent[0], x + dx, y + dy,
1074 szHint.width, szHint.height); 1089 szHint.width, szHint.height);
1075#else 1090#else
1076 XResizeWindow (disp, parent[0], szHint.width, szHint.height); 1091 XResizeWindow (dpy, parent[0], szHint.width, szHint.height);
1077#endif 1092#endif
1078 } 1093 }
1079 1094
1080 fix_screen = ncol != prev_ncol || nrow != prev_nrow; 1095 fix_screen = ncol != prev_ncol || nrow != prev_nrow;
1081 1096
1082 if (fix_screen || newwidth != old_width || newheight != old_height) 1097 if (fix_screen || newwidth != old_width || newheight != old_height)
1083 { 1098 {
1084 if (scrollBar.state) 1099 if (scrollBar.state)
1085 { 1100 {
1086 XMoveResizeWindow (disp, scrollBar.win, 1101 XMoveResizeWindow (dpy, scrollBar.win,
1087 window_sb_x, 0, 1102 window_sb_x, 0,
1088 scrollbar_TotalWidth (), szHint.height); 1103 scrollbar_TotalWidth (), szHint.height);
1089 resize_scrollbar (); 1104 resize_scrollbar ();
1090 } 1105 }
1091 1106
1092 XMoveResizeWindow (disp, vt, 1107 XMoveResizeWindow (dpy, vt,
1093 window_vt_x, window_vt_y, 1108 window_vt_x, window_vt_y,
1094 width, height); 1109 width, height);
1095 1110
1096 scr_clear (); 1111 scr_clear ();
1097#ifdef XPM_BACKGROUND 1112#ifdef XPM_BACKGROUND
1100 } 1115 }
1101 1116
1102 if (fix_screen || old_height == 0) 1117 if (fix_screen || old_height == 0)
1103 scr_reset (); 1118 scr_reset ();
1104 1119
1120 // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version
1121 //scr_touch (false);
1122
1105#ifdef XPM_BACKGROUND 1123#ifdef XPM_BACKGROUND
1106 if (pixmap) 1124 if (pixmap)
1107 scr_touch (false); 1125 scr_touch (false);
1108#endif 1126#endif
1109 1127
1110#ifdef USE_XIM 1128#ifdef USE_XIM
1111 IMSetStatusPosition (); 1129 IMSetPosition ();
1112#endif 1130#endif
1113} 1131}
1114 1132
1115/* 1133/*
1116 * Set the width/height of the vt window in characters. Units are pixels. 1134 * Set the width/height of the vt window in characters. Units are pixels.
1121{ 1139{
1122 XWindowAttributes wattr; 1140 XWindowAttributes wattr;
1123 1141
1124 if (newwidth == 0 || newheight == 0) 1142 if (newwidth == 0 || newheight == 0)
1125 { 1143 {
1126 XGetWindowAttributes (display->display, display->root, &wattr); 1144 XGetWindowAttributes (dpy, display->root, &wattr);
1127 1145
1128 if (newwidth == 0) 1146 if (newwidth == 0)
1129 newwidth = wattr.width - szHint.base_width; 1147 newwidth = wattr.width - szHint.base_width;
1130 if (newheight == 0) 1148 if (newheight == 0)
1131 newheight = wattr.height - szHint.base_height; 1149 newheight = wattr.height - szHint.base_height;
1145#ifdef USE_XIM 1163#ifdef USE_XIM
1146 1164
1147void 1165void
1148rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) 1166rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg)
1149{ 1167{
1150 fg = pix_colors[Color_fg]; 1168 fg = pix_colors [Color_fg];
1151 bg = pix_colors[Color_bg]; 1169 bg = pix_colors [Color_bg];
1152} 1170}
1153 1171
1154void 1172void
1155rxvt_term::im_set_size (XRectangle &size) 1173rxvt_term::im_set_size (XRectangle &size)
1156{ 1174{
1193 strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1211 strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */
1194 1212
1195 if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ 1213 if ((p = strchr (server + 1, '@')) != NULL) /* first one only */
1196 *p = '\0'; 1214 *p = '\0';
1197 1215
1198 atom = XInternAtom (display->display, server, False); 1216 atom = XInternAtom (dpy, server, False);
1199 win = XGetSelectionOwner (display->display, atom); 1217 win = XGetSelectionOwner (dpy, atom);
1200 1218
1201 if (win != None) 1219 if (win != None)
1202 return True; 1220 return True;
1203 } 1221 }
1204 1222
1211 XPoint nspot; 1229 XPoint nspot;
1212 XVaNestedList preedit_attr; 1230 XVaNestedList preedit_attr;
1213 1231
1214 if (!Input_Context 1232 if (!Input_Context
1215 || !focus 1233 || !focus
1216 || !(input_style & XIMPreeditPosition)) 1234 || !(input_style & (XIMPreeditPosition | XIMPreeditCallbacks)))
1217 return; 1235 return;
1218 1236
1219 im_set_position (nspot); 1237 im_set_position (nspot);
1220 1238
1221 if (nspot.x == spot.x && nspot.y == spot.y) 1239 if (nspot.x == spot.x && nspot.y == spot.y)
1428 "*", 1446 "*",
1429 fheight, 1447 fheight,
1430 fheight + 1, fheight - 1, 1448 fheight + 1, fheight - 1,
1431 fheight - 2, fheight + 2); 1449 fheight - 2, fheight + 2);
1432 1450
1433 fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat, 1451 fs = XCreateFontSet (dpy, rs[Rs_imFont] ? rs[Rs_imFont] : pat,
1434 &missing_charset_list, &missing_charset_count, &def_string); 1452 &missing_charset_list, &missing_charset_count, &def_string);
1435 1453
1436 if (missing_charset_list) 1454 if (missing_charset_list)
1437 XFreeStringList (missing_charset_list); 1455 XFreeStringList (missing_charset_list);
1438 1456
1479 XNBackground, bg, 1497 XNBackground, bg,
1480 XNArea, &status_rect, 1498 XNArea, &status_rect,
1481 XNFontSet, fs, 1499 XNFontSet, fs,
1482 NULL); 1500 NULL);
1483 } 1501 }
1502#if ENABLE_XIM_ONTHESPOT
1484 else if (input_style & XIMPreeditCallbacks) 1503 else if (input_style & XIMPreeditCallbacks)
1485 { 1504 {
1505 im_set_position (spot);
1506
1486 xcb[0].client_data = (XPointer)this; xcb[0].callback = (XIMProc)xim_preedit_start; 1507 xcb[0].client_data = (XPointer)this; xcb[0].callback = (XIMProc)xim_preedit_start;
1487 xcb[1].client_data = (XPointer)this; xcb[1].callback = (XIMProc)xim_preedit_done; 1508 xcb[1].client_data = (XPointer)this; xcb[1].callback = (XIMProc)xim_preedit_done;
1488 xcb[2].client_data = (XPointer)this; xcb[2].callback = (XIMProc)xim_preedit_draw; 1509 xcb[2].client_data = (XPointer)this; xcb[2].callback = (XIMProc)xim_preedit_draw;
1489#if 0 1510# if 0
1490 xcb[3].client_data = (XPointer)this; xcb[3].callback = (XIMProc)xim_preedit_caret; 1511 xcb[3].client_data = (XPointer)this; xcb[3].callback = (XIMProc)xim_preedit_caret;
1491#endif 1512# endif
1492 1513
1493 preedit_attr = XVaCreateNestedList (0, 1514 preedit_attr = XVaCreateNestedList (0,
1515 XNSpotLocation, &spot,
1494 XNPreeditStartCallback, &xcb[0], 1516 XNPreeditStartCallback, &xcb[0],
1495 XNPreeditDoneCallback , &xcb[1], 1517 XNPreeditDoneCallback , &xcb[1],
1496 XNPreeditDrawCallback , &xcb[2], 1518 XNPreeditDrawCallback , &xcb[2],
1497#if 0 1519# if 0
1498 XNPreeditCaretCallback, &xcb[3], 1520 XNPreeditCaretCallback, &xcb[3],
1499#endif 1521# endif
1500 NULL); 1522 NULL);
1501 } 1523 }
1524#endif
1502 1525
1503 Input_Context = XCreateIC (xim, 1526 Input_Context = XCreateIC (xim,
1504 XNInputStyle, input_style, 1527 XNInputStyle, input_style,
1505 XNClientWindow, vt, 1528 XNClientWindow, vt,
1506 XNFocusWindow, parent[0], 1529 XNFocusWindow, parent[0],
1508 preedit_attr, 1531 preedit_attr,
1509 status_attr ? XNStatusAttributes : NULL, 1532 status_attr ? XNStatusAttributes : NULL,
1510 status_attr, NULL); 1533 status_attr, NULL);
1511 1534
1512 if (preedit_attr) XFree (preedit_attr); 1535 if (preedit_attr) XFree (preedit_attr);
1513 if (status_attr) XFree (status_attr); 1536 if (status_attr) XFree (status_attr);
1514 if (fs) XFreeFontSet (display->display, fs); 1537 if (fs) XFreeFontSet (dpy, fs);
1515 1538
1516 if (Input_Context == NULL) 1539 if (Input_Context == NULL)
1517 { 1540 {
1518 rxvt_warn ("failed to create input context, continuing without XIM.\n"); 1541 rxvt_warn ("failed to create input context, continuing without XIM.\n");
1519 im_destroy (); 1542 im_destroy ();
1524 // unfortunately, only the focus window is used by XIM, hard to fix 1547 // unfortunately, only the focus window is used by XIM, hard to fix
1525 if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL)) 1548 if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL))
1526 vt_select_input (); 1549 vt_select_input ();
1527#endif 1550#endif
1528 1551
1529 if (input_style & XIMPreeditArea)
1530 IMSetStatusPosition (); 1552 IMSetPosition ();
1531 1553
1532 return true; 1554 return true;
1533} 1555}
1534 1556
1535void 1557void
1593 SET_LOCALE (locale); 1615 SET_LOCALE (locale);
1594#endif 1616#endif
1595} 1617}
1596 1618
1597void 1619void
1598rxvt_term::IMSetStatusPosition () 1620rxvt_term::IMSetPosition ()
1599{ 1621{
1600 XRectangle preedit_rect, status_rect, *needed_rect; 1622 XRectangle preedit_rect, status_rect, *needed_rect;
1601 XVaNestedList preedit_attr, status_attr; 1623 XVaNestedList preedit_attr, status_attr;
1602 1624
1603 if (!Input_Context 1625 if (!Input_Context
1604 || !focus 1626 || !focus
1605 || !(input_style & XIMPreeditArea) 1627 || !(input_style & (XIMPreeditArea | XIMPreeditPosition))
1606 || !IMisRunning ()) 1628 || !IMisRunning ())
1607 return; 1629 return;
1608 1630
1631 if (input_style & XIMPreeditPosition)
1632 {
1633 im_set_size (preedit_rect);
1634 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
1635
1636 XSetICValues (Input_Context,
1637 XNPreeditAttributes, preedit_attr, NULL);
1638 }
1639 else
1640 {
1609 /* Getting the necessary width of preedit area */ 1641 /* Getting the necessary width of preedit area */
1610 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); 1642 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL);
1611 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); 1643 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL);
1612 XFree (status_attr); 1644 XFree (status_attr);
1613 1645
1614 im_set_preedit_area (preedit_rect, status_rect, *needed_rect); 1646 im_set_preedit_area (preedit_rect, status_rect, *needed_rect);
1615 XFree (needed_rect); 1647 XFree (needed_rect);
1616 1648
1617 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); 1649 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
1618 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); 1650 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL);
1619 1651
1620 XSetICValues (Input_Context, 1652 XSetICValues (Input_Context,
1621 XNPreeditAttributes, preedit_attr, 1653 XNPreeditAttributes, preedit_attr,
1622 XNStatusAttributes, status_attr, NULL); 1654 XNStatusAttributes, status_attr,
1655 NULL);
1623 1656
1657 XFree (status_attr);
1658 }
1659
1624 XFree (preedit_attr); 1660 XFree (preedit_attr);
1625 XFree (status_attr);
1626} 1661}
1627#endif /* USE_XIM */ 1662#endif /* USE_XIM */
1628 1663
1629/*----------------------- end-of-file (C source) -----------------------*/ 1664/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines