… | |
… | |
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" |
35 | |
37 | |
36 | #include <limits> |
38 | #include <limits> |
37 | |
39 | |
38 | #include <csignal> |
40 | #include <csignal> |
39 | #include <cstring> |
41 | #include <cstring> |
… | |
… | |
44 | |
46 | |
45 | #ifdef HAVE_TERMIOS_H |
47 | #ifdef HAVE_TERMIOS_H |
46 | # include <termios.h> |
48 | # include <termios.h> |
47 | #endif |
49 | #endif |
48 | |
50 | |
49 | #ifdef KEYSYM_RESOURCE |
51 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
50 | # include "keyboard.h" |
52 | static uid_t saved_euid; |
|
|
53 | static gid_t saved_egid; |
51 | #endif |
54 | #endif |
|
|
55 | |
|
|
56 | bool |
|
|
57 | rxvt_tainted () |
|
|
58 | { |
|
|
59 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
60 | return getuid () != saved_euid || getgid () != saved_egid; |
|
|
61 | #else |
|
|
62 | return false; |
|
|
63 | #endif |
|
|
64 | } |
52 | |
65 | |
53 | vector<rxvt_term *> rxvt_term::termlist; |
66 | vector<rxvt_term *> rxvt_term::termlist; |
54 | |
67 | |
55 | static char curlocale[128]; |
68 | static char curlocale[128], savelocale[128]; |
56 | |
69 | |
57 | bool |
70 | bool |
58 | rxvt_set_locale (const char *locale) |
71 | rxvt_set_locale (const char *locale) |
59 | { |
72 | { |
60 | if (!locale || !strncmp (locale, curlocale, 128)) |
73 | if (!locale || !strncmp (locale, curlocale, 128)) |
61 | return false; |
74 | return false; |
62 | |
75 | |
63 | strncpy (curlocale, locale, 128); |
76 | strncpy (curlocale, locale, 128); |
64 | setlocale (LC_CTYPE, curlocale); |
77 | setlocale (LC_CTYPE, curlocale); |
65 | return true; |
78 | return true; |
|
|
79 | } |
|
|
80 | |
|
|
81 | void |
|
|
82 | rxvt_push_locale (const char *locale) |
|
|
83 | { |
|
|
84 | strcpy (savelocale, curlocale); |
|
|
85 | rxvt_set_locale (locale); |
|
|
86 | } |
|
|
87 | |
|
|
88 | void |
|
|
89 | rxvt_pop_locale () |
|
|
90 | { |
|
|
91 | rxvt_set_locale (savelocale); |
66 | } |
92 | } |
67 | |
93 | |
68 | #if ENABLE_COMBINING |
94 | #if ENABLE_COMBINING |
69 | class rxvt_composite_vec rxvt_composite; |
95 | class rxvt_composite_vec rxvt_composite; |
70 | |
96 | |
… | |
… | |
195 | pty.put (); |
221 | pty.put (); |
196 | } |
222 | } |
197 | |
223 | |
198 | rxvt_term::~rxvt_term () |
224 | rxvt_term::~rxvt_term () |
199 | { |
225 | { |
|
|
226 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
|
|
227 | |
200 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
228 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
201 | |
229 | |
202 | emergency_cleanup (); |
230 | emergency_cleanup (); |
203 | |
231 | |
204 | #if ENABLE_STYLES |
232 | #if ENABLE_STYLES |
… | |
… | |
286 | delete argv; |
314 | delete argv; |
287 | |
315 | |
288 | #ifdef KEYSYM_RESOURCE |
316 | #ifdef KEYSYM_RESOURCE |
289 | delete keyboard; |
317 | delete keyboard; |
290 | #endif |
318 | #endif |
|
|
319 | } |
|
|
320 | |
|
|
321 | void |
|
|
322 | rxvt_term::child_exit () |
|
|
323 | { |
|
|
324 | cmd_pid = 0; |
|
|
325 | |
|
|
326 | if (!OPTION (Opt_hold)) |
|
|
327 | destroy (); |
291 | } |
328 | } |
292 | |
329 | |
293 | void |
330 | void |
294 | rxvt_term::destroy () |
331 | rxvt_term::destroy () |
295 | { |
332 | { |
… | |
… | |
442 | /*----------------------------------------------------------------------*/ |
479 | /*----------------------------------------------------------------------*/ |
443 | bool |
480 | bool |
444 | rxvt_term::init (int argc, const char *const *argv) |
481 | rxvt_term::init (int argc, const char *const *argv) |
445 | { |
482 | { |
446 | SET_R (this); |
483 | SET_R (this); |
|
|
484 | TEMP_ENV; // few things in X do not call setlocale :( |
447 | |
485 | |
448 | set_locale (""); |
486 | set_locale (""); |
449 | |
487 | |
450 | if (!init_vars ()) |
488 | if (!init_vars ()) |
451 | return false; |
489 | return false; |
… | |
… | |
460 | |
498 | |
461 | #if MENUBAR_MAX |
499 | #if MENUBAR_MAX |
462 | menubar_read (rs[Rs_menu]); |
500 | menubar_read (rs[Rs_menu]); |
463 | #endif |
501 | #endif |
464 | #ifdef HAVE_SCROLLBARS |
502 | #ifdef HAVE_SCROLLBARS |
465 | if (options & Opt_scrollBar) |
503 | if (OPTION (Opt_scrollBar)) |
466 | scrollBar.setIdle (); /* set existence for size calculations */ |
504 | scrollBar.setIdle (); /* set existence for size calculations */ |
467 | #endif |
505 | #endif |
468 | |
506 | |
|
|
507 | #if ENABLE_PERL |
|
|
508 | if (!rs[Rs_perl_ext_1]) |
|
|
509 | rs[Rs_perl_ext_1] = "default"; |
|
|
510 | |
|
|
511 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
512 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
513 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
514 | { |
|
|
515 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
516 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
|
|
517 | if (rxvt_tainted ()) |
|
|
518 | { |
|
|
519 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
|
|
520 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
521 | { |
|
|
522 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
|
|
523 | rs[Rs_perl_lib] = 0; |
|
|
524 | rs[Rs_perl_eval] = 0; |
|
|
525 | } |
|
|
526 | } |
|
|
527 | #endif |
|
|
528 | rxvt_perl.init (); |
|
|
529 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
530 | } |
|
|
531 | #endif |
|
|
532 | |
469 | create_windows (argc, argv); |
533 | create_windows (argc, argv); |
470 | |
534 | |
471 | dDisp; |
535 | dDisp; |
472 | |
536 | |
473 | init_xlocale (); |
537 | init_xlocale (); |
474 | |
538 | |
475 | scr_reset (); /* initialize screen */ |
539 | scr_reset (); // initialize screen |
476 | |
540 | |
477 | #if 0 |
541 | #if 0 |
478 | XSynchronize (disp, True); |
542 | XSynchronize (disp, True); |
479 | #endif |
543 | #endif |
480 | |
544 | |
481 | #ifdef HAVE_SCROLLBARS |
545 | #ifdef HAVE_SCROLLBARS |
482 | if (options & Opt_scrollBar) |
546 | if (OPTION (Opt_scrollBar)) |
483 | resize_scrollbar (); /* create and map scrollbar */ |
547 | resize_scrollbar (); /* create and map scrollbar */ |
484 | #endif |
548 | #endif |
485 | #if (MENUBAR_MAX) |
549 | #if (MENUBAR_MAX) |
486 | if (menubar_visible ()) |
550 | if (menubar_visible ()) |
487 | XMapWindow (disp, menuBar.win); |
551 | XMapWindow (disp, menuBar.win); |
488 | #endif |
552 | #endif |
489 | #ifdef TRANSPARENT |
553 | #ifdef TRANSPARENT |
490 | if (options & Opt_transparent) |
554 | if (OPTION (Opt_transparent)) |
491 | { |
555 | { |
492 | XSelectInput (disp, display->root, PropertyChangeMask); |
556 | XSelectInput (disp, display->root, PropertyChangeMask); |
493 | check_our_parents (); |
557 | check_our_parents (); |
494 | rootwin_ev.start (display, display->root); |
558 | rootwin_ev.start (display, display->root); |
495 | } |
559 | } |
… | |
… | |
502 | |
566 | |
503 | init_command (cmd_argv); |
567 | init_command (cmd_argv); |
504 | |
568 | |
505 | free (cmd_argv); |
569 | free (cmd_argv); |
506 | |
570 | |
|
|
571 | if (pty.pty >= 0) |
507 | pty_ev.start (pty.pty, EVENT_READ); |
572 | pty_ev.start (pty.pty, EVENT_READ); |
508 | |
573 | |
509 | check_ev.start (); |
574 | check_ev.start (); |
|
|
575 | |
|
|
576 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
510 | |
577 | |
511 | return true; |
578 | return true; |
512 | } |
579 | } |
513 | |
580 | |
514 | static struct sig_handlers |
581 | static struct sig_handlers |
… | |
… | |
522 | |
589 | |
523 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
590 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
524 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
591 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
525 | if (pid == (*t)->cmd_pid) |
592 | if (pid == (*t)->cmd_pid) |
526 | { |
593 | { |
527 | (*t)->destroy (); |
594 | (*t)->child_exit (); |
528 | break; |
595 | break; |
529 | } |
596 | } |
530 | } |
597 | } |
531 | |
598 | |
532 | /* |
599 | /* |
… | |
… | |
575 | /* signal (SIGURG, SIG_DFL); */ |
642 | /* signal (SIGURG, SIG_DFL); */ |
576 | |
643 | |
577 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
644 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
578 | // TODO: handle this with exceptions and tolerate the memory loss |
645 | // TODO: handle this with exceptions and tolerate the memory loss |
579 | XSetIOErrorHandler (rxvt_xioerror_handler); |
646 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
647 | |
|
|
648 | XrmInitialize (); |
580 | } |
649 | } |
581 | |
650 | |
582 | /* ------------------------------------------------------------------------- * |
651 | /* ------------------------------------------------------------------------- * |
583 | * MEMORY ALLOCATION WRAPPERS * |
652 | * MEMORY ALLOCATION WRAPPERS * |
584 | * ------------------------------------------------------------------------- */ |
653 | * ------------------------------------------------------------------------- */ |
… | |
… | |
620 | * ------------------------------------------------------------------------- */ |
689 | * ------------------------------------------------------------------------- */ |
621 | /* take care of suid/sgid super-user (root) privileges */ |
690 | /* take care of suid/sgid super-user (root) privileges */ |
622 | void |
691 | void |
623 | rxvt_privileges (rxvt_privaction action) |
692 | rxvt_privileges (rxvt_privaction action) |
624 | { |
693 | { |
625 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
626 | static uid_t euid; |
|
|
627 | static gid_t egid; |
|
|
628 | #endif |
|
|
629 | |
|
|
630 | #if ! defined(__CYGWIN32__) |
694 | #if ! defined(__CYGWIN32__) |
631 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
695 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
632 | /* setreuid () is the poor man's setuid (), seteuid () */ |
696 | /* setreuid () is the poor man's setuid (), seteuid () */ |
633 | # define seteuid(a) setreuid(-1, (a)) |
697 | # define seteuid(a) setreuid(-1, (a)) |
634 | # define setegid(a) setregid(-1, (a)) |
698 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
644 | */ |
708 | */ |
645 | seteuid (getuid ()); |
709 | seteuid (getuid ()); |
646 | setegid (getgid ()); |
710 | setegid (getgid ()); |
647 | break; |
711 | break; |
648 | case SAVE: |
712 | case SAVE: |
649 | euid = geteuid (); |
713 | saved_euid = geteuid (); |
650 | egid = getegid (); |
714 | saved_egid = getegid (); |
651 | break; |
715 | break; |
652 | case RESTORE: |
716 | case RESTORE: |
653 | seteuid (euid); |
717 | seteuid (saved_euid); |
654 | setegid (egid); |
718 | setegid (saved_egid); |
655 | break; |
719 | break; |
656 | } |
720 | } |
657 | # else |
721 | # else |
658 | switch (action) |
722 | switch (action) |
659 | { |
723 | { |
… | |
… | |
672 | |
736 | |
673 | #ifdef UTMP_SUPPORT |
737 | #ifdef UTMP_SUPPORT |
674 | void |
738 | void |
675 | rxvt_term::privileged_utmp (rxvt_privaction action) |
739 | rxvt_term::privileged_utmp (rxvt_privaction action) |
676 | { |
740 | { |
677 | if ((options & Opt_utmpInhibit) |
741 | if (OPTION (Opt_utmpInhibit) |
678 | || !pty.name || !*pty.name) |
742 | || !pty.name || !*pty.name) |
679 | return; |
743 | return; |
680 | |
744 | |
681 | rxvt_privileges (RESTORE); |
745 | rxvt_privileges (RESTORE); |
682 | |
746 | |
… | |
… | |
774 | |
838 | |
775 | if (scrollbar_visible ()) |
839 | if (scrollbar_visible ()) |
776 | { |
840 | { |
777 | sb_w = scrollbar_TotalWidth (); |
841 | sb_w = scrollbar_TotalWidth (); |
778 | szHint.base_width += sb_w; |
842 | szHint.base_width += sb_w; |
779 | if (!(options & Opt_scrollBar_right)) |
843 | if (!OPTION (Opt_scrollBar_right)) |
780 | window_vt_x += sb_w; |
844 | window_vt_x += sb_w; |
781 | } |
845 | } |
782 | |
846 | |
783 | if (menubar_visible ()) |
847 | if (menubar_visible ()) |
784 | { |
848 | { |
… | |
… | |
812 | { |
876 | { |
813 | min_it (height, max_height); |
877 | min_it (height, max_height); |
814 | szHint.height = szHint.base_height + height; |
878 | szHint.height = szHint.base_height + height; |
815 | } |
879 | } |
816 | |
880 | |
817 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
881 | if (scrollbar_visible () && OPTION (Opt_scrollBar_right)) |
818 | window_sb_x = szHint.width - sb_w; |
882 | window_sb_x = szHint.width - sb_w; |
819 | |
883 | |
820 | if (recalc_x) |
884 | if (recalc_x) |
821 | szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; |
885 | szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; |
822 | if (recalc_y) |
886 | if (recalc_y) |
… | |
… | |
891 | prop.height += lineSpace; |
955 | prop.height += lineSpace; |
892 | fs->set_prop (prop); |
956 | fs->set_prop (prop); |
893 | |
957 | |
894 | fwidth = prop.width; |
958 | fwidth = prop.width; |
895 | fheight = prop.height; |
959 | fheight = prop.height; |
896 | fbase = (*fs)[1]->ascent; |
960 | fbase = prop.ascent; |
897 | |
961 | |
898 | for (int style = 1; style < 4; style++) |
962 | for (int style = 1; style < 4; style++) |
899 | { |
963 | { |
900 | #if ENABLE_STYLES |
964 | #if ENABLE_STYLES |
901 | const char *res = rs[Rs_font + style]; |
965 | const char *res = rs[Rs_font + style]; |
… | |
… | |
935 | return true; |
999 | return true; |
936 | } |
1000 | } |
937 | |
1001 | |
938 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
1002 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
939 | { |
1003 | { |
940 | // TODO: SMART_WINDOW_TITLE |
|
|
941 | XChangeProperty (display->display, parent[0], |
1004 | XChangeProperty (display->display, parent[0], |
942 | prop, XA_STRING, 8, PropModeReplace, |
1005 | prop, XA_STRING, 8, PropModeReplace, |
943 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
1006 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
944 | } |
1007 | } |
945 | |
1008 | |
946 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
1009 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
947 | { |
1010 | { |
948 | // TODO: SMART_WINDOW_TITLE |
|
|
949 | wchar_t *ws = rxvt_mbstowcs (str, len); |
1011 | wchar_t *ws = rxvt_mbstowcs (str, len); |
950 | char *s = rxvt_wcstoutf8 (ws); |
1012 | char *s = rxvt_wcstoutf8 (ws); |
951 | |
1013 | |
952 | XChangeProperty (display->display, parent[0], |
1014 | XChangeProperty (display->display, parent[0], |
953 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
1015 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
… | |
… | |
994 | i = atoi (color); |
1056 | i = atoi (color); |
995 | |
1057 | |
996 | if (i >= 8 && i <= 15) |
1058 | if (i >= 8 && i <= 15) |
997 | { /* bright colors */ |
1059 | { /* bright colors */ |
998 | i -= 8; |
1060 | i -= 8; |
999 | # ifndef NO_BRIGHTCOLOR |
|
|
1000 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1061 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1001 | SET_PIXCOLOR (idx); |
1062 | SET_PIXCOLOR (idx); |
1002 | goto done; |
1063 | goto done; |
1003 | # endif |
|
|
1004 | } |
1064 | } |
1005 | |
1065 | |
1006 | if (i >= 0 && i <= 7) |
1066 | if (i >= 0 && i <= 7) |
1007 | { /* normal colors */ |
1067 | { /* normal colors */ |
1008 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1068 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
… | |
… | |
1192 | } |
1252 | } |
1193 | |
1253 | |
1194 | if (menubar_visible ()) |
1254 | if (menubar_visible ()) |
1195 | XMoveResizeWindow (disp, menuBar.win, |
1255 | XMoveResizeWindow (disp, menuBar.win, |
1196 | window_vt_x, 0, |
1256 | window_vt_x, 0, |
1197 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1257 | width, menuBar_TotalHeight ()); |
1198 | |
1258 | |
1199 | XMoveResizeWindow (disp, vt, |
1259 | XMoveResizeWindow (disp, vt, |
1200 | window_vt_x, window_vt_y, |
1260 | window_vt_x, window_vt_y, |
1201 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1261 | width, height); |
1202 | |
1262 | |
1203 | scr_clear (); |
1263 | scr_clear (); |
1204 | #ifdef XPM_BACKGROUND |
1264 | #ifdef XPM_BACKGROUND |
1205 | resize_pixmap (); |
1265 | resize_pixmap (); |
1206 | #endif |
1266 | #endif |
… | |
… | |
1386 | XRectangle rect, status_rect, needed_rect; |
1446 | XRectangle rect, status_rect, needed_rect; |
1387 | unsigned long fg, bg; |
1447 | unsigned long fg, bg; |
1388 | const char *p; |
1448 | const char *p; |
1389 | char **s; |
1449 | char **s; |
1390 | XIMStyles *xim_styles; |
1450 | XIMStyles *xim_styles; |
|
|
1451 | |
|
|
1452 | TEMP_ENV; |
1391 | |
1453 | |
1392 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1454 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1393 | return false; |
1455 | return false; |
1394 | |
1456 | |
1395 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1457 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |