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.149 by root, Sun Dec 18 00:59:42 2005 UTC vs.
Revision 1.166 by root, Sun Jan 8 07:55:36 2006 UTC

11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> 11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA>
12 * - extensive modifications 12 * - extensive modifications
13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
15 * - extensive modifications 15 * - extensive modifications
16 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 16 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
17 * 17 *
18 * This program is free software; you can redistribute it and/or modify 18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by 19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or 20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version. 21 * (at your option) any later version.
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *---------------------------------------------------------------------*/ 31 *---------------------------------------------------------------------*/
32 32
33#include "../config.h" /* NECESSARY */ 33#include "../config.h" /* NECESSARY */
34#include "rxvt.h" /* NECESSARY */ 34#include "rxvt.h" /* NECESSARY */
35#include "keyboard.h"
36#include "rxvtperl.h"
37
38#include <limits>
35 39
36#include <csignal> 40#include <csignal>
37#include <cstring> 41#include <cstring>
38 42
39#ifdef TTY_GID_SUPPORT 43#ifdef TTY_GID_SUPPORT
42 46
43#ifdef HAVE_TERMIOS_H 47#ifdef HAVE_TERMIOS_H
44# include <termios.h> 48# include <termios.h>
45#endif 49#endif
46 50
47#ifdef KEYSYM_RESOURCE
48# include "keyboard.h"
49#endif
50
51vector<rxvt_term *> rxvt_term::termlist; 51vector<rxvt_term *> rxvt_term::termlist;
52 52
53static char curlocale[128]; 53static char curlocale[128], savelocale[128];
54 54
55bool 55bool
56rxvt_set_locale (const char *locale) 56rxvt_set_locale (const char *locale)
57{ 57{
58 if (!locale || !strncmp (locale, curlocale, 128)) 58 if (!locale || !strncmp (locale, curlocale, 128))
59 return false; 59 return false;
60 60
61 strncpy (curlocale, locale, 128); 61 strncpy (curlocale, locale, 128);
62 setlocale (LC_CTYPE, curlocale); 62 setlocale (LC_CTYPE, curlocale);
63 return true; 63 return true;
64}
65
66bool
67rxvt_push_locale (const char *locale)
68{
69 strcpy (savelocale, curlocale);
70 rxvt_set_locale (locale);
71}
72
73void
74rxvt_pop_locale ()
75{
76 rxvt_set_locale (savelocale);
64} 77}
65 78
66#if ENABLE_COMBINING 79#if ENABLE_COMBINING
67class rxvt_composite_vec rxvt_composite; 80class rxvt_composite_vec rxvt_composite;
68 81
193 pty.put (); 206 pty.put ();
194} 207}
195 208
196rxvt_term::~rxvt_term () 209rxvt_term::~rxvt_term ()
197{ 210{
211 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END));
212
198 termlist.erase (find (termlist.begin (), termlist.end(), this)); 213 termlist.erase (find (termlist.begin (), termlist.end(), this));
199 214
200 emergency_cleanup (); 215 emergency_cleanup ();
201 216
202#if ENABLE_STYLES 217#if ENABLE_STYLES
259 274
260 delete pix_colors_focused; 275 delete pix_colors_focused;
261#if OFF_FOCUS_FADING 276#if OFF_FOCUS_FADING
262 delete pix_colors_unfocused; 277 delete pix_colors_unfocused;
263#endif 278#endif
279#if USE_XGETDEFAULT
280 XrmDestroyDatabase (xrmdatabase);
281#endif
264 282
265 displays.put (display); 283 displays.put (display);
266 284
267 scr_release (); 285 scr_release ();
268 286
284 delete argv; 302 delete argv;
285 303
286#ifdef KEYSYM_RESOURCE 304#ifdef KEYSYM_RESOURCE
287 delete keyboard; 305 delete keyboard;
288#endif 306#endif
307}
308
309void
310rxvt_term::child_exit ()
311{
312 cmd_pid = 0;
313
314 if (!OPTION (Opt_hold))
315 destroy ();
289} 316}
290 317
291void 318void
292rxvt_term::destroy () 319rxvt_term::destroy ()
293{ 320{
458 485
459#if MENUBAR_MAX 486#if MENUBAR_MAX
460 menubar_read (rs[Rs_menu]); 487 menubar_read (rs[Rs_menu]);
461#endif 488#endif
462#ifdef HAVE_SCROLLBARS 489#ifdef HAVE_SCROLLBARS
463 if (options & Opt_scrollBar) 490 if (OPTION (Opt_scrollBar))
464 scrollBar.setIdle (); /* set existence for size calculations */ 491 scrollBar.setIdle (); /* set existence for size calculations */
492#endif
493
494#if ENABLE_PERL
495 if (!rs[Rs_perl_ext_1])
496 rs[Rs_perl_ext_1] = "default";
497
498 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
499 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
500 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
501 {
502 rxvt_perl.init ();
503 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
504 }
465#endif 505#endif
466 506
467 create_windows (argc, argv); 507 create_windows (argc, argv);
468 508
469 dDisp; 509 dDisp;
475#if 0 515#if 0
476 XSynchronize (disp, True); 516 XSynchronize (disp, True);
477#endif 517#endif
478 518
479#ifdef HAVE_SCROLLBARS 519#ifdef HAVE_SCROLLBARS
480 if (options & Opt_scrollBar) 520 if (OPTION (Opt_scrollBar))
481 resize_scrollbar (); /* create and map scrollbar */ 521 resize_scrollbar (); /* create and map scrollbar */
482#endif 522#endif
483#if (MENUBAR_MAX) 523#if (MENUBAR_MAX)
484 if (menubar_visible ()) 524 if (menubar_visible ())
485 XMapWindow (disp, menuBar.win); 525 XMapWindow (disp, menuBar.win);
486#endif 526#endif
487#ifdef TRANSPARENT 527#ifdef TRANSPARENT
488 if (options & Opt_transparent) 528 if (OPTION (Opt_transparent))
489 { 529 {
490 XSelectInput (disp, display->root, PropertyChangeMask); 530 XSelectInput (disp, display->root, PropertyChangeMask);
491 check_our_parents (); 531 check_our_parents ();
492 rootwin_ev.start (display, display->root); 532 rootwin_ev.start (display, display->root);
493 } 533 }
500 540
501 init_command (cmd_argv); 541 init_command (cmd_argv);
502 542
503 free (cmd_argv); 543 free (cmd_argv);
504 544
545 if (pty.pty >= 0)
505 pty_ev.start (pty.pty, EVENT_READ); 546 pty_ev.start (pty.pty, EVENT_READ);
506 547
507 check_ev.start (); 548 check_ev.start ();
549
550 HOOK_INVOKE ((this, HOOK_START, DT_END));
508 551
509 return true; 552 return true;
510} 553}
511 554
512static struct sig_handlers 555static struct sig_handlers
520 563
521 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) 564 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
522 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 565 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
523 if (pid == (*t)->cmd_pid) 566 if (pid == (*t)->cmd_pid)
524 { 567 {
525 (*t)->destroy (); 568 (*t)->child_exit ();
526 break; 569 break;
527 } 570 }
528 } 571 }
529 572
530 /* 573 /*
573 /* signal (SIGURG, SIG_DFL); */ 616 /* signal (SIGURG, SIG_DFL); */
574 617
575 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 618 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
576 // TODO: handle this with exceptions and tolerate the memory loss 619 // TODO: handle this with exceptions and tolerate the memory loss
577 XSetIOErrorHandler (rxvt_xioerror_handler); 620 XSetIOErrorHandler (rxvt_xioerror_handler);
621
622#ifdef USE_XGETDEFAULT
623 XrmInitialize ();
624#endif
578} 625}
579 626
580/* ------------------------------------------------------------------------- * 627/* ------------------------------------------------------------------------- *
581 * MEMORY ALLOCATION WRAPPERS * 628 * MEMORY ALLOCATION WRAPPERS *
582 * ------------------------------------------------------------------------- */ 629 * ------------------------------------------------------------------------- */
670 717
671#ifdef UTMP_SUPPORT 718#ifdef UTMP_SUPPORT
672void 719void
673rxvt_term::privileged_utmp (rxvt_privaction action) 720rxvt_term::privileged_utmp (rxvt_privaction action)
674{ 721{
675 if ((options & Opt_utmpInhibit) 722 if (OPTION (Opt_utmpInhibit)
676 || !pty.name || !*pty.name) 723 || !pty.name || !*pty.name)
677 return; 724 return;
678 725
679 rxvt_privileges (RESTORE); 726 rxvt_privileges (RESTORE);
680 727
718 if (rs[Rs_geometry]) 765 if (rs[Rs_geometry])
719 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); 766 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h);
720 767
721 if (flags & WidthValue) 768 if (flags & WidthValue)
722 { 769 {
723 ncol = BOUND_POSITIVE_INT16 (w); 770 ncol = clamp (w, 0, std::numeric_limits<int16_t>::max ());
724 szHint.flags |= USSize; 771 szHint.flags |= USSize;
725 } 772 }
726 773
727 if (flags & HeightValue) 774 if (flags & HeightValue)
728 { 775 {
729 nrow = BOUND_POSITIVE_INT16 (h); 776 nrow = clamp (h, 0, std::numeric_limits<int16_t>::max ());
730 szHint.flags |= USSize; 777 szHint.flags |= USSize;
731 } 778 }
732 779
733 if (flags & XValue) 780 if (flags & XValue)
734 { 781 {
772 819
773 if (scrollbar_visible ()) 820 if (scrollbar_visible ())
774 { 821 {
775 sb_w = scrollbar_TotalWidth (); 822 sb_w = scrollbar_TotalWidth ();
776 szHint.base_width += sb_w; 823 szHint.base_width += sb_w;
777 if (!(options & Opt_scrollBar_right)) 824 if (!OPTION (Opt_scrollBar_right))
778 window_vt_x += sb_w; 825 window_vt_x += sb_w;
779 } 826 }
780 827
781 if (menubar_visible ()) 828 if (menubar_visible ())
782 { 829 {
795 szHint.width = newwidth; 842 szHint.width = newwidth;
796 width = newwidth - szHint.base_width; 843 width = newwidth - szHint.base_width;
797 } 844 }
798 else 845 else
799 { 846 {
800 MIN_IT (width, max_width); 847 min_it (width, max_width);
801 szHint.width = szHint.base_width + width; 848 szHint.width = szHint.base_width + width;
802 } 849 }
803 850
804 if (newheight && newheight - szHint.base_height < max_height) 851 if (newheight && newheight - szHint.base_height < max_height)
805 { 852 {
806 szHint.height = newheight; 853 szHint.height = newheight;
807 height = newheight - szHint.base_height; 854 height = newheight - szHint.base_height;
808 } 855 }
809 else 856 else
810 { 857 {
811 MIN_IT (height, max_height); 858 min_it (height, max_height);
812 szHint.height = szHint.base_height + height; 859 szHint.height = szHint.base_height + height;
813 } 860 }
814 861
815 if (scrollbar_visible () && (options & Opt_scrollBar_right)) 862 if (scrollbar_visible () && OPTION (Opt_scrollBar_right))
816 window_sb_x = szHint.width - sb_w; 863 window_sb_x = szHint.width - sb_w;
817 864
818 if (recalc_x) 865 if (recalc_x)
819 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; 866 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth;
820 if (recalc_y) 867 if (recalc_y)
889 prop.height += lineSpace; 936 prop.height += lineSpace;
890 fs->set_prop (prop); 937 fs->set_prop (prop);
891 938
892 fwidth = prop.width; 939 fwidth = prop.width;
893 fheight = prop.height; 940 fheight = prop.height;
894 fweight = prop.weight; 941 fbase = prop.ascent;
895 fslant = prop.slant;
896 fbase = (*fs)[1]->ascent;
897 942
898 for (int style = 1; style < 4; style++) 943 for (int style = 1; style < 4; style++)
899 { 944 {
900#if ENABLE_STYLES 945#if ENABLE_STYLES
901 const char *res = rs[Rs_font + style]; 946 const char *res = rs[Rs_font + style];
935 return true; 980 return true;
936} 981}
937 982
938void rxvt_term::set_string_property (Atom prop, const char *str, int len) 983void rxvt_term::set_string_property (Atom prop, const char *str, int len)
939{ 984{
940 // TODO: SMART_WINDOW_TITLE
941 XChangeProperty (display->display, parent[0], 985 XChangeProperty (display->display, parent[0],
942 prop, XA_STRING, 8, PropModeReplace, 986 prop, XA_STRING, 8, PropModeReplace,
943 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 987 (const unsigned char *)str, len >= 0 ? len : strlen (str));
944} 988}
945 989
946void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 990void rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
947{ 991{
948 // TODO: SMART_WINDOW_TITLE
949 wchar_t *ws = rxvt_mbstowcs (str, len); 992 wchar_t *ws = rxvt_mbstowcs (str, len);
950 char *s = rxvt_wcstoutf8 (ws); 993 char *s = rxvt_wcstoutf8 (ws);
951 994
952 XChangeProperty (display->display, parent[0], 995 XChangeProperty (display->display, parent[0],
953 prop, xa[XA_UTF8_STRING], 8, PropModeReplace, 996 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
994 i = atoi (color); 1037 i = atoi (color);
995 1038
996 if (i >= 8 && i <= 15) 1039 if (i >= 8 && i <= 15)
997 { /* bright colors */ 1040 { /* bright colors */
998 i -= 8; 1041 i -= 8;
999# ifndef NO_BRIGHTCOLOR
1000 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 1042 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
1001 SET_PIXCOLOR (idx); 1043 SET_PIXCOLOR (idx);
1002 goto done; 1044 goto done;
1003# endif
1004 } 1045 }
1005 1046
1006 if (i >= 0 && i <= 7) 1047 if (i >= 0 && i <= 7)
1007 { /* normal colors */ 1048 { /* normal colors */
1008 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1049 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1192 } 1233 }
1193 1234
1194 if (menubar_visible ()) 1235 if (menubar_visible ())
1195 XMoveResizeWindow (disp, menuBar.win, 1236 XMoveResizeWindow (disp, menuBar.win,
1196 window_vt_x, 0, 1237 window_vt_x, 0,
1197 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1238 width, menuBar_TotalHeight ());
1198 1239
1199 XMoveResizeWindow (disp, vt, 1240 XMoveResizeWindow (disp, vt,
1200 window_vt_x, window_vt_y, 1241 window_vt_x, window_vt_y,
1201 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1242 width, height);
1202 1243
1203 scr_clear (); 1244 scr_clear ();
1204#ifdef XPM_BACKGROUND 1245#ifdef XPM_BACKGROUND
1205 resize_pixmap (); 1246 resize_pixmap ();
1206#endif 1247#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines