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.167 by root, Sun Jan 8 08:43:11 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 51#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
48# include "keyboard.h" 52static uid_t saved_euid;
53static gid_t saved_egid;
49#endif 54#endif
50 55
51vector<rxvt_term *> rxvt_term::termlist; 56vector<rxvt_term *> rxvt_term::termlist;
52 57
53static char curlocale[128]; 58static char curlocale[128], savelocale[128];
54 59
55bool 60bool
56rxvt_set_locale (const char *locale) 61rxvt_set_locale (const char *locale)
57{ 62{
58 if (!locale || !strncmp (locale, curlocale, 128)) 63 if (!locale || !strncmp (locale, curlocale, 128))
59 return false; 64 return false;
60 65
61 strncpy (curlocale, locale, 128); 66 strncpy (curlocale, locale, 128);
62 setlocale (LC_CTYPE, curlocale); 67 setlocale (LC_CTYPE, curlocale);
63 return true; 68 return true;
69}
70
71bool
72rxvt_push_locale (const char *locale)
73{
74 strcpy (savelocale, curlocale);
75 rxvt_set_locale (locale);
76}
77
78void
79rxvt_pop_locale ()
80{
81 rxvt_set_locale (savelocale);
64} 82}
65 83
66#if ENABLE_COMBINING 84#if ENABLE_COMBINING
67class rxvt_composite_vec rxvt_composite; 85class rxvt_composite_vec rxvt_composite;
68 86
193 pty.put (); 211 pty.put ();
194} 212}
195 213
196rxvt_term::~rxvt_term () 214rxvt_term::~rxvt_term ()
197{ 215{
216 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END));
217
198 termlist.erase (find (termlist.begin (), termlist.end(), this)); 218 termlist.erase (find (termlist.begin (), termlist.end(), this));
199 219
200 emergency_cleanup (); 220 emergency_cleanup ();
201 221
202#if ENABLE_STYLES 222#if ENABLE_STYLES
259 279
260 delete pix_colors_focused; 280 delete pix_colors_focused;
261#if OFF_FOCUS_FADING 281#if OFF_FOCUS_FADING
262 delete pix_colors_unfocused; 282 delete pix_colors_unfocused;
263#endif 283#endif
284#if USE_XGETDEFAULT
285 XrmDestroyDatabase (xrmdatabase);
286#endif
264 287
265 displays.put (display); 288 displays.put (display);
266 289
267 scr_release (); 290 scr_release ();
268 291
284 delete argv; 307 delete argv;
285 308
286#ifdef KEYSYM_RESOURCE 309#ifdef KEYSYM_RESOURCE
287 delete keyboard; 310 delete keyboard;
288#endif 311#endif
312}
313
314void
315rxvt_term::child_exit ()
316{
317 cmd_pid = 0;
318
319 if (!OPTION (Opt_hold))
320 destroy ();
289} 321}
290 322
291void 323void
292rxvt_term::destroy () 324rxvt_term::destroy ()
293{ 325{
458 490
459#if MENUBAR_MAX 491#if MENUBAR_MAX
460 menubar_read (rs[Rs_menu]); 492 menubar_read (rs[Rs_menu]);
461#endif 493#endif
462#ifdef HAVE_SCROLLBARS 494#ifdef HAVE_SCROLLBARS
463 if (options & Opt_scrollBar) 495 if (OPTION (Opt_scrollBar))
464 scrollBar.setIdle (); /* set existence for size calculations */ 496 scrollBar.setIdle (); /* set existence for size calculations */
497#endif
498
499#if ENABLE_PERL
500 if (!rs[Rs_perl_ext_1])
501 rs[Rs_perl_ext_1] = "default";
502
503 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
504 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
505 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
506 {
507 bool tainted = false;
508
509#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
510 // ignore some perl-related arguments if some bozo installed us set[ug]id
511 if (getuid () != saved_euid || getgid () != saved_egid)
512 {
513 tainted = true;
514
515 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
516 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
517 {
518 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
519 rs[Rs_perl_lib] = 0;
520 rs[Rs_perl_eval] = "our $tainted = 1";
521 }
522 }
523#endif
524 rxvt_perl.init (tainted);
525 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
526 }
465#endif 527#endif
466 528
467 create_windows (argc, argv); 529 create_windows (argc, argv);
468 530
469 dDisp; 531 dDisp;
475#if 0 537#if 0
476 XSynchronize (disp, True); 538 XSynchronize (disp, True);
477#endif 539#endif
478 540
479#ifdef HAVE_SCROLLBARS 541#ifdef HAVE_SCROLLBARS
480 if (options & Opt_scrollBar) 542 if (OPTION (Opt_scrollBar))
481 resize_scrollbar (); /* create and map scrollbar */ 543 resize_scrollbar (); /* create and map scrollbar */
482#endif 544#endif
483#if (MENUBAR_MAX) 545#if (MENUBAR_MAX)
484 if (menubar_visible ()) 546 if (menubar_visible ())
485 XMapWindow (disp, menuBar.win); 547 XMapWindow (disp, menuBar.win);
486#endif 548#endif
487#ifdef TRANSPARENT 549#ifdef TRANSPARENT
488 if (options & Opt_transparent) 550 if (OPTION (Opt_transparent))
489 { 551 {
490 XSelectInput (disp, display->root, PropertyChangeMask); 552 XSelectInput (disp, display->root, PropertyChangeMask);
491 check_our_parents (); 553 check_our_parents ();
492 rootwin_ev.start (display, display->root); 554 rootwin_ev.start (display, display->root);
493 } 555 }
500 562
501 init_command (cmd_argv); 563 init_command (cmd_argv);
502 564
503 free (cmd_argv); 565 free (cmd_argv);
504 566
567 if (pty.pty >= 0)
505 pty_ev.start (pty.pty, EVENT_READ); 568 pty_ev.start (pty.pty, EVENT_READ);
506 569
507 check_ev.start (); 570 check_ev.start ();
571
572 HOOK_INVOKE ((this, HOOK_START, DT_END));
508 573
509 return true; 574 return true;
510} 575}
511 576
512static struct sig_handlers 577static struct sig_handlers
520 585
521 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) 586 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
522 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 587 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
523 if (pid == (*t)->cmd_pid) 588 if (pid == (*t)->cmd_pid)
524 { 589 {
525 (*t)->destroy (); 590 (*t)->child_exit ();
526 break; 591 break;
527 } 592 }
528 } 593 }
529 594
530 /* 595 /*
573 /* signal (SIGURG, SIG_DFL); */ 638 /* signal (SIGURG, SIG_DFL); */
574 639
575 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 640 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
576 // TODO: handle this with exceptions and tolerate the memory loss 641 // TODO: handle this with exceptions and tolerate the memory loss
577 XSetIOErrorHandler (rxvt_xioerror_handler); 642 XSetIOErrorHandler (rxvt_xioerror_handler);
643
644#ifdef USE_XGETDEFAULT
645 XrmInitialize ();
646#endif
578} 647}
579 648
580/* ------------------------------------------------------------------------- * 649/* ------------------------------------------------------------------------- *
581 * MEMORY ALLOCATION WRAPPERS * 650 * MEMORY ALLOCATION WRAPPERS *
582 * ------------------------------------------------------------------------- */ 651 * ------------------------------------------------------------------------- */
618 * ------------------------------------------------------------------------- */ 687 * ------------------------------------------------------------------------- */
619/* take care of suid/sgid super-user (root) privileges */ 688/* take care of suid/sgid super-user (root) privileges */
620void 689void
621rxvt_privileges (rxvt_privaction action) 690rxvt_privileges (rxvt_privaction action)
622{ 691{
623#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
624 static uid_t euid;
625 static gid_t egid;
626#endif
627
628#if ! defined(__CYGWIN32__) 692#if ! defined(__CYGWIN32__)
629# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 693# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
630 /* setreuid () is the poor man's setuid (), seteuid () */ 694 /* setreuid () is the poor man's setuid (), seteuid () */
631# define seteuid(a) setreuid(-1, (a)) 695# define seteuid(a) setreuid(-1, (a))
632# define setegid(a) setregid(-1, (a)) 696# define setegid(a) setregid(-1, (a))
642 */ 706 */
643 seteuid (getuid ()); 707 seteuid (getuid ());
644 setegid (getgid ()); 708 setegid (getgid ());
645 break; 709 break;
646 case SAVE: 710 case SAVE:
647 euid = geteuid (); 711 saved_euid = geteuid ();
648 egid = getegid (); 712 saved_egid = getegid ();
649 break; 713 break;
650 case RESTORE: 714 case RESTORE:
651 seteuid (euid); 715 seteuid (saved_euid);
652 setegid (egid); 716 setegid (saved_egid);
653 break; 717 break;
654 } 718 }
655# else 719# else
656 switch (action) 720 switch (action)
657 { 721 {
670 734
671#ifdef UTMP_SUPPORT 735#ifdef UTMP_SUPPORT
672void 736void
673rxvt_term::privileged_utmp (rxvt_privaction action) 737rxvt_term::privileged_utmp (rxvt_privaction action)
674{ 738{
675 if ((options & Opt_utmpInhibit) 739 if (OPTION (Opt_utmpInhibit)
676 || !pty.name || !*pty.name) 740 || !pty.name || !*pty.name)
677 return; 741 return;
678 742
679 rxvt_privileges (RESTORE); 743 rxvt_privileges (RESTORE);
680 744
718 if (rs[Rs_geometry]) 782 if (rs[Rs_geometry])
719 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); 783 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h);
720 784
721 if (flags & WidthValue) 785 if (flags & WidthValue)
722 { 786 {
723 ncol = BOUND_POSITIVE_INT16 (w); 787 ncol = clamp (w, 0, std::numeric_limits<int16_t>::max ());
724 szHint.flags |= USSize; 788 szHint.flags |= USSize;
725 } 789 }
726 790
727 if (flags & HeightValue) 791 if (flags & HeightValue)
728 { 792 {
729 nrow = BOUND_POSITIVE_INT16 (h); 793 nrow = clamp (h, 0, std::numeric_limits<int16_t>::max ());
730 szHint.flags |= USSize; 794 szHint.flags |= USSize;
731 } 795 }
732 796
733 if (flags & XValue) 797 if (flags & XValue)
734 { 798 {
772 836
773 if (scrollbar_visible ()) 837 if (scrollbar_visible ())
774 { 838 {
775 sb_w = scrollbar_TotalWidth (); 839 sb_w = scrollbar_TotalWidth ();
776 szHint.base_width += sb_w; 840 szHint.base_width += sb_w;
777 if (!(options & Opt_scrollBar_right)) 841 if (!OPTION (Opt_scrollBar_right))
778 window_vt_x += sb_w; 842 window_vt_x += sb_w;
779 } 843 }
780 844
781 if (menubar_visible ()) 845 if (menubar_visible ())
782 { 846 {
795 szHint.width = newwidth; 859 szHint.width = newwidth;
796 width = newwidth - szHint.base_width; 860 width = newwidth - szHint.base_width;
797 } 861 }
798 else 862 else
799 { 863 {
800 MIN_IT (width, max_width); 864 min_it (width, max_width);
801 szHint.width = szHint.base_width + width; 865 szHint.width = szHint.base_width + width;
802 } 866 }
803 867
804 if (newheight && newheight - szHint.base_height < max_height) 868 if (newheight && newheight - szHint.base_height < max_height)
805 { 869 {
806 szHint.height = newheight; 870 szHint.height = newheight;
807 height = newheight - szHint.base_height; 871 height = newheight - szHint.base_height;
808 } 872 }
809 else 873 else
810 { 874 {
811 MIN_IT (height, max_height); 875 min_it (height, max_height);
812 szHint.height = szHint.base_height + height; 876 szHint.height = szHint.base_height + height;
813 } 877 }
814 878
815 if (scrollbar_visible () && (options & Opt_scrollBar_right)) 879 if (scrollbar_visible () && OPTION (Opt_scrollBar_right))
816 window_sb_x = szHint.width - sb_w; 880 window_sb_x = szHint.width - sb_w;
817 881
818 if (recalc_x) 882 if (recalc_x)
819 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; 883 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth;
820 if (recalc_y) 884 if (recalc_y)
889 prop.height += lineSpace; 953 prop.height += lineSpace;
890 fs->set_prop (prop); 954 fs->set_prop (prop);
891 955
892 fwidth = prop.width; 956 fwidth = prop.width;
893 fheight = prop.height; 957 fheight = prop.height;
894 fweight = prop.weight; 958 fbase = prop.ascent;
895 fslant = prop.slant;
896 fbase = (*fs)[1]->ascent;
897 959
898 for (int style = 1; style < 4; style++) 960 for (int style = 1; style < 4; style++)
899 { 961 {
900#if ENABLE_STYLES 962#if ENABLE_STYLES
901 const char *res = rs[Rs_font + style]; 963 const char *res = rs[Rs_font + style];
935 return true; 997 return true;
936} 998}
937 999
938void rxvt_term::set_string_property (Atom prop, const char *str, int len) 1000void rxvt_term::set_string_property (Atom prop, const char *str, int len)
939{ 1001{
940 // TODO: SMART_WINDOW_TITLE
941 XChangeProperty (display->display, parent[0], 1002 XChangeProperty (display->display, parent[0],
942 prop, XA_STRING, 8, PropModeReplace, 1003 prop, XA_STRING, 8, PropModeReplace,
943 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 1004 (const unsigned char *)str, len >= 0 ? len : strlen (str));
944} 1005}
945 1006
946void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 1007void rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
947{ 1008{
948 // TODO: SMART_WINDOW_TITLE
949 wchar_t *ws = rxvt_mbstowcs (str, len); 1009 wchar_t *ws = rxvt_mbstowcs (str, len);
950 char *s = rxvt_wcstoutf8 (ws); 1010 char *s = rxvt_wcstoutf8 (ws);
951 1011
952 XChangeProperty (display->display, parent[0], 1012 XChangeProperty (display->display, parent[0],
953 prop, xa[XA_UTF8_STRING], 8, PropModeReplace, 1013 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
994 i = atoi (color); 1054 i = atoi (color);
995 1055
996 if (i >= 8 && i <= 15) 1056 if (i >= 8 && i <= 15)
997 { /* bright colors */ 1057 { /* bright colors */
998 i -= 8; 1058 i -= 8;
999# ifndef NO_BRIGHTCOLOR
1000 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 1059 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
1001 SET_PIXCOLOR (idx); 1060 SET_PIXCOLOR (idx);
1002 goto done; 1061 goto done;
1003# endif
1004 } 1062 }
1005 1063
1006 if (i >= 0 && i <= 7) 1064 if (i >= 0 && i <= 7)
1007 { /* normal colors */ 1065 { /* normal colors */
1008 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1066 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1192 } 1250 }
1193 1251
1194 if (menubar_visible ()) 1252 if (menubar_visible ())
1195 XMoveResizeWindow (disp, menuBar.win, 1253 XMoveResizeWindow (disp, menuBar.win,
1196 window_vt_x, 0, 1254 window_vt_x, 0,
1197 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1255 width, menuBar_TotalHeight ());
1198 1256
1199 XMoveResizeWindow (disp, vt, 1257 XMoveResizeWindow (disp, vt,
1200 window_vt_x, window_vt_y, 1258 window_vt_x, window_vt_y,
1201 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1259 width, height);
1202 1260
1203 scr_clear (); 1261 scr_clear ();
1204#ifdef XPM_BACKGROUND 1262#ifdef XPM_BACKGROUND
1205 resize_pixmap (); 1263 resize_pixmap ();
1206#endif 1264#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines