… | |
… | |
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 | |
|
|
51 | vector<rxvt_term *> rxvt_term::termlist; |
51 | vector<rxvt_term *> rxvt_term::termlist; |
52 | |
52 | |
53 | static char curlocale[128]; |
53 | static char curlocale[128], savelocale[128]; |
54 | |
54 | |
55 | bool |
55 | bool |
56 | rxvt_set_locale (const char *locale) |
56 | rxvt_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 | |
|
|
66 | bool |
|
|
67 | rxvt_push_locale (const char *locale) |
|
|
68 | { |
|
|
69 | strcpy (savelocale, curlocale); |
|
|
70 | rxvt_set_locale (locale); |
|
|
71 | } |
|
|
72 | |
|
|
73 | void |
|
|
74 | rxvt_pop_locale () |
|
|
75 | { |
|
|
76 | rxvt_set_locale (savelocale); |
64 | } |
77 | } |
65 | |
78 | |
66 | #if ENABLE_COMBINING |
79 | #if ENABLE_COMBINING |
67 | class rxvt_composite_vec rxvt_composite; |
80 | class rxvt_composite_vec rxvt_composite; |
68 | |
81 | |
… | |
… | |
193 | pty.put (); |
206 | pty.put (); |
194 | } |
207 | } |
195 | |
208 | |
196 | rxvt_term::~rxvt_term () |
209 | rxvt_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 |
… | |
… | |
284 | delete argv; |
299 | delete argv; |
285 | |
300 | |
286 | #ifdef KEYSYM_RESOURCE |
301 | #ifdef KEYSYM_RESOURCE |
287 | delete keyboard; |
302 | delete keyboard; |
288 | #endif |
303 | #endif |
|
|
304 | } |
|
|
305 | |
|
|
306 | void |
|
|
307 | rxvt_term::child_exit () |
|
|
308 | { |
|
|
309 | cmd_pid = 0; |
|
|
310 | |
|
|
311 | if (!OPTION (Opt_hold)) |
|
|
312 | destroy (); |
289 | } |
313 | } |
290 | |
314 | |
291 | void |
315 | void |
292 | rxvt_term::destroy () |
316 | rxvt_term::destroy () |
293 | { |
317 | { |
… | |
… | |
458 | |
482 | |
459 | #if MENUBAR_MAX |
483 | #if MENUBAR_MAX |
460 | menubar_read (rs[Rs_menu]); |
484 | menubar_read (rs[Rs_menu]); |
461 | #endif |
485 | #endif |
462 | #ifdef HAVE_SCROLLBARS |
486 | #ifdef HAVE_SCROLLBARS |
463 | if (options & Opt_scrollBar) |
487 | if (OPTION (Opt_scrollBar)) |
464 | scrollBar.setIdle (); /* set existence for size calculations */ |
488 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
489 | #endif |
|
|
490 | |
|
|
491 | #if ENABLE_PERL |
|
|
492 | if (!rs[Rs_perl_ext_1]) |
|
|
493 | rs[Rs_perl_ext_1] = "default"; |
|
|
494 | |
|
|
495 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
496 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
497 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
498 | { |
|
|
499 | rxvt_perl.init (); |
|
|
500 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
501 | } |
465 | #endif |
502 | #endif |
466 | |
503 | |
467 | create_windows (argc, argv); |
504 | create_windows (argc, argv); |
468 | |
505 | |
469 | dDisp; |
506 | dDisp; |
… | |
… | |
475 | #if 0 |
512 | #if 0 |
476 | XSynchronize (disp, True); |
513 | XSynchronize (disp, True); |
477 | #endif |
514 | #endif |
478 | |
515 | |
479 | #ifdef HAVE_SCROLLBARS |
516 | #ifdef HAVE_SCROLLBARS |
480 | if (options & Opt_scrollBar) |
517 | if (OPTION (Opt_scrollBar)) |
481 | resize_scrollbar (); /* create and map scrollbar */ |
518 | resize_scrollbar (); /* create and map scrollbar */ |
482 | #endif |
519 | #endif |
483 | #if (MENUBAR_MAX) |
520 | #if (MENUBAR_MAX) |
484 | if (menubar_visible ()) |
521 | if (menubar_visible ()) |
485 | XMapWindow (disp, menuBar.win); |
522 | XMapWindow (disp, menuBar.win); |
486 | #endif |
523 | #endif |
487 | #ifdef TRANSPARENT |
524 | #ifdef TRANSPARENT |
488 | if (options & Opt_transparent) |
525 | if (OPTION (Opt_transparent)) |
489 | { |
526 | { |
490 | XSelectInput (disp, display->root, PropertyChangeMask); |
527 | XSelectInput (disp, display->root, PropertyChangeMask); |
491 | check_our_parents (); |
528 | check_our_parents (); |
492 | rootwin_ev.start (display, display->root); |
529 | rootwin_ev.start (display, display->root); |
493 | } |
530 | } |
… | |
… | |
500 | |
537 | |
501 | init_command (cmd_argv); |
538 | init_command (cmd_argv); |
502 | |
539 | |
503 | free (cmd_argv); |
540 | free (cmd_argv); |
504 | |
541 | |
|
|
542 | if (pty.pty >= 0) |
505 | pty_ev.start (pty.pty, EVENT_READ); |
543 | pty_ev.start (pty.pty, EVENT_READ); |
506 | |
544 | |
507 | check_ev.start (); |
545 | check_ev.start (); |
|
|
546 | |
|
|
547 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
508 | |
548 | |
509 | return true; |
549 | return true; |
510 | } |
550 | } |
511 | |
551 | |
512 | static struct sig_handlers |
552 | static struct sig_handlers |
… | |
… | |
520 | |
560 | |
521 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
561 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
522 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
562 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
523 | if (pid == (*t)->cmd_pid) |
563 | if (pid == (*t)->cmd_pid) |
524 | { |
564 | { |
525 | (*t)->destroy (); |
565 | (*t)->child_exit (); |
526 | break; |
566 | break; |
527 | } |
567 | } |
528 | } |
568 | } |
529 | |
569 | |
530 | /* |
570 | /* |
… | |
… | |
670 | |
710 | |
671 | #ifdef UTMP_SUPPORT |
711 | #ifdef UTMP_SUPPORT |
672 | void |
712 | void |
673 | rxvt_term::privileged_utmp (rxvt_privaction action) |
713 | rxvt_term::privileged_utmp (rxvt_privaction action) |
674 | { |
714 | { |
675 | if ((options & Opt_utmpInhibit) |
715 | if (OPTION (Opt_utmpInhibit) |
676 | || !pty.name || !*pty.name) |
716 | || !pty.name || !*pty.name) |
677 | return; |
717 | return; |
678 | |
718 | |
679 | rxvt_privileges (RESTORE); |
719 | rxvt_privileges (RESTORE); |
680 | |
720 | |
… | |
… | |
718 | if (rs[Rs_geometry]) |
758 | if (rs[Rs_geometry]) |
719 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
759 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
720 | |
760 | |
721 | if (flags & WidthValue) |
761 | if (flags & WidthValue) |
722 | { |
762 | { |
723 | ncol = BOUND_POSITIVE_INT16 (w); |
763 | ncol = clamp (w, 0, std::numeric_limits<int16_t>::max ()); |
724 | szHint.flags |= USSize; |
764 | szHint.flags |= USSize; |
725 | } |
765 | } |
726 | |
766 | |
727 | if (flags & HeightValue) |
767 | if (flags & HeightValue) |
728 | { |
768 | { |
729 | nrow = BOUND_POSITIVE_INT16 (h); |
769 | nrow = clamp (h, 0, std::numeric_limits<int16_t>::max ()); |
730 | szHint.flags |= USSize; |
770 | szHint.flags |= USSize; |
731 | } |
771 | } |
732 | |
772 | |
733 | if (flags & XValue) |
773 | if (flags & XValue) |
734 | { |
774 | { |
… | |
… | |
772 | |
812 | |
773 | if (scrollbar_visible ()) |
813 | if (scrollbar_visible ()) |
774 | { |
814 | { |
775 | sb_w = scrollbar_TotalWidth (); |
815 | sb_w = scrollbar_TotalWidth (); |
776 | szHint.base_width += sb_w; |
816 | szHint.base_width += sb_w; |
777 | if (!(options & Opt_scrollBar_right)) |
817 | if (!OPTION (Opt_scrollBar_right)) |
778 | window_vt_x += sb_w; |
818 | window_vt_x += sb_w; |
779 | } |
819 | } |
780 | |
820 | |
781 | if (menubar_visible ()) |
821 | if (menubar_visible ()) |
782 | { |
822 | { |
… | |
… | |
795 | szHint.width = newwidth; |
835 | szHint.width = newwidth; |
796 | width = newwidth - szHint.base_width; |
836 | width = newwidth - szHint.base_width; |
797 | } |
837 | } |
798 | else |
838 | else |
799 | { |
839 | { |
800 | MIN_IT (width, max_width); |
840 | min_it (width, max_width); |
801 | szHint.width = szHint.base_width + width; |
841 | szHint.width = szHint.base_width + width; |
802 | } |
842 | } |
803 | |
843 | |
804 | if (newheight && newheight - szHint.base_height < max_height) |
844 | if (newheight && newheight - szHint.base_height < max_height) |
805 | { |
845 | { |
806 | szHint.height = newheight; |
846 | szHint.height = newheight; |
807 | height = newheight - szHint.base_height; |
847 | height = newheight - szHint.base_height; |
808 | } |
848 | } |
809 | else |
849 | else |
810 | { |
850 | { |
811 | MIN_IT (height, max_height); |
851 | min_it (height, max_height); |
812 | szHint.height = szHint.base_height + height; |
852 | szHint.height = szHint.base_height + height; |
813 | } |
853 | } |
814 | |
854 | |
815 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
855 | if (scrollbar_visible () && OPTION (Opt_scrollBar_right)) |
816 | window_sb_x = szHint.width - sb_w; |
856 | window_sb_x = szHint.width - sb_w; |
817 | |
857 | |
818 | if (recalc_x) |
858 | if (recalc_x) |
819 | szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; |
859 | szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; |
820 | if (recalc_y) |
860 | if (recalc_y) |
… | |
… | |
889 | prop.height += lineSpace; |
929 | prop.height += lineSpace; |
890 | fs->set_prop (prop); |
930 | fs->set_prop (prop); |
891 | |
931 | |
892 | fwidth = prop.width; |
932 | fwidth = prop.width; |
893 | fheight = prop.height; |
933 | fheight = prop.height; |
894 | fweight = prop.weight; |
934 | fbase = prop.ascent; |
895 | fslant = prop.slant; |
|
|
896 | fbase = (*fs)[1]->ascent; |
|
|
897 | |
935 | |
898 | for (int style = 1; style < 4; style++) |
936 | for (int style = 1; style < 4; style++) |
899 | { |
937 | { |
900 | #if ENABLE_STYLES |
938 | #if ENABLE_STYLES |
901 | const char *res = rs[Rs_font + style]; |
939 | const char *res = rs[Rs_font + style]; |
… | |
… | |
935 | return true; |
973 | return true; |
936 | } |
974 | } |
937 | |
975 | |
938 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
976 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
939 | { |
977 | { |
940 | // TODO: SMART_WINDOW_TITLE |
|
|
941 | XChangeProperty (display->display, parent[0], |
978 | XChangeProperty (display->display, parent[0], |
942 | prop, XA_STRING, 8, PropModeReplace, |
979 | prop, XA_STRING, 8, PropModeReplace, |
943 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
980 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
944 | } |
981 | } |
945 | |
982 | |
946 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
983 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
947 | { |
984 | { |
948 | // TODO: SMART_WINDOW_TITLE |
|
|
949 | wchar_t *ws = rxvt_mbstowcs (str, len); |
985 | wchar_t *ws = rxvt_mbstowcs (str, len); |
950 | char *s = rxvt_wcstoutf8 (ws); |
986 | char *s = rxvt_wcstoutf8 (ws); |
951 | |
987 | |
952 | XChangeProperty (display->display, parent[0], |
988 | XChangeProperty (display->display, parent[0], |
953 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
989 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
… | |
… | |
994 | i = atoi (color); |
1030 | i = atoi (color); |
995 | |
1031 | |
996 | if (i >= 8 && i <= 15) |
1032 | if (i >= 8 && i <= 15) |
997 | { /* bright colors */ |
1033 | { /* bright colors */ |
998 | i -= 8; |
1034 | i -= 8; |
999 | # ifndef NO_BRIGHTCOLOR |
|
|
1000 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1035 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1001 | SET_PIXCOLOR (idx); |
1036 | SET_PIXCOLOR (idx); |
1002 | goto done; |
1037 | goto done; |
1003 | # endif |
|
|
1004 | } |
1038 | } |
1005 | |
1039 | |
1006 | if (i >= 0 && i <= 7) |
1040 | if (i >= 0 && i <= 7) |
1007 | { /* normal colors */ |
1041 | { /* normal colors */ |
1008 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1042 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
… | |
… | |
1192 | } |
1226 | } |
1193 | |
1227 | |
1194 | if (menubar_visible ()) |
1228 | if (menubar_visible ()) |
1195 | XMoveResizeWindow (disp, menuBar.win, |
1229 | XMoveResizeWindow (disp, menuBar.win, |
1196 | window_vt_x, 0, |
1230 | window_vt_x, 0, |
1197 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1231 | width, menuBar_TotalHeight ()); |
1198 | |
1232 | |
1199 | XMoveResizeWindow (disp, vt, |
1233 | XMoveResizeWindow (disp, vt, |
1200 | window_vt_x, window_vt_y, |
1234 | window_vt_x, window_vt_y, |
1201 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1235 | width, height); |
1202 | |
1236 | |
1203 | scr_clear (); |
1237 | scr_clear (); |
1204 | #ifdef XPM_BACKGROUND |
1238 | #ifdef XPM_BACKGROUND |
1205 | resize_pixmap (); |
1239 | resize_pixmap (); |
1206 | #endif |
1240 | #endif |