1 | /*--------------------------------*-C-*---------------------------------*; |
1 | /*--------------------------------*-C-*---------------------------------* |
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> |
7 | * - original version |
7 | * - original version |
… | |
… | |
44 | # include <termios.h> |
44 | # include <termios.h> |
45 | #endif |
45 | #endif |
46 | |
46 | |
47 | #include <cstring> |
47 | #include <cstring> |
48 | |
48 | |
|
|
49 | vector<rxvt_term *> rxvt_term::termlist; |
|
|
50 | |
49 | static char curlocale[128]; |
51 | static char curlocale[128]; |
50 | |
52 | |
51 | void |
53 | bool |
52 | rxvt_set_locale (const char *locale) |
54 | rxvt_set_locale (const char *locale) |
53 | { |
55 | { |
54 | if (locale && STRNCMP (locale, curlocale, 128)) |
56 | if (!locale || !STRNCMP (locale, curlocale, 128)) |
55 | { |
57 | return false; |
|
|
58 | |
56 | STRNCPY (curlocale, locale, 128); |
59 | STRNCPY (curlocale, locale, 128); |
57 | setlocale (LC_CTYPE, curlocale); |
60 | setlocale (LC_CTYPE, curlocale); |
58 | } |
61 | return true; |
59 | } |
62 | } |
60 | |
63 | |
61 | #if ENABLE_COMBINING |
64 | #if ENABLE_COMBINING |
62 | class rxvt_composite_vec rxvt_composite; |
65 | class rxvt_composite_vec rxvt_composite; |
63 | |
66 | |
… | |
… | |
152 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
155 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
153 | #endif |
156 | #endif |
154 | #ifdef TEXT_BLINK |
157 | #ifdef TEXT_BLINK |
155 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
158 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
156 | #endif |
159 | #endif |
|
|
160 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
161 | cont_scroll_ev (this, &rxvt_term::cont_scroll_cb), |
|
|
162 | #endif |
|
|
163 | #ifdef SELECTION_SCROLLING |
|
|
164 | sel_scroll_ev (this, &rxvt_term::sel_scroll_cb), |
|
|
165 | #endif |
|
|
166 | #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
|
|
167 | slip_wheel_ev (this, &rxvt_term::slip_wheel_cb), |
|
|
168 | #endif |
157 | #ifdef POINTER_BLANK |
169 | #ifdef POINTER_BLANK |
158 | pointer_ev (this, &rxvt_term::pointer_cb), |
170 | pointer_ev (this, &rxvt_term::pointer_cb), |
159 | #endif |
171 | #endif |
160 | #ifdef USE_XIM |
172 | #ifdef USE_XIM |
161 | im_ev (this, &rxvt_term::im_cb), |
173 | im_ev (this, &rxvt_term::im_cb), |
… | |
… | |
164 | destroy_ev (this, &rxvt_term::destroy_cb), |
176 | destroy_ev (this, &rxvt_term::destroy_cb), |
165 | pty_ev (this, &rxvt_term::pty_cb), |
177 | pty_ev (this, &rxvt_term::pty_cb), |
166 | incr_ev (this, &rxvt_term::incr_cb) |
178 | incr_ev (this, &rxvt_term::incr_cb) |
167 | { |
179 | { |
168 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
180 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
|
|
181 | |
|
|
182 | termlist.push_back (this); |
169 | } |
183 | } |
170 | |
184 | |
171 | rxvt_term::~rxvt_term () |
185 | rxvt_term::~rxvt_term () |
172 | { |
186 | { |
|
|
187 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
|
|
188 | |
173 | if (cmd_fd >= 0) |
189 | if (cmd_fd >= 0) |
174 | close (cmd_fd); |
190 | close (cmd_fd); |
175 | |
191 | |
176 | #ifndef NO_SETOWNER_TTYDEV |
192 | #ifndef NO_SETOWNER_TTYDEV |
177 | privileged_ttydev (RESTORE); |
193 | privileged_ttydev (RESTORE); |
… | |
… | |
279 | cursor_blink_ev.stop (); |
295 | cursor_blink_ev.stop (); |
280 | #endif |
296 | #endif |
281 | #ifdef TEXT_BLINK |
297 | #ifdef TEXT_BLINK |
282 | text_blink_ev.stop (); |
298 | text_blink_ev.stop (); |
283 | #endif |
299 | #endif |
|
|
300 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
301 | cont_scroll_ev.stop (); |
|
|
302 | #endif |
|
|
303 | #ifdef SELECTION_SCROLLING |
|
|
304 | sel_scroll_ev.stop (); |
|
|
305 | #endif |
284 | #ifdef POINTER_BLANK |
306 | #ifdef POINTER_BLANK |
285 | pointer_ev.stop (); |
307 | pointer_ev.stop (); |
286 | #endif |
308 | #endif |
287 | |
309 | |
288 | destroy_ev.start (0); |
310 | destroy_ev.start (0); |
… | |
… | |
405 | * SIGNAL HANDLING & EXIT HANDLER * |
427 | * SIGNAL HANDLING & EXIT HANDLER * |
406 | * ------------------------------------------------------------------------- */ |
428 | * ------------------------------------------------------------------------- */ |
407 | /* |
429 | /* |
408 | * Catch a SIGCHLD signal and exit if the direct child has died |
430 | * Catch a SIGCHLD signal and exit if the direct child has died |
409 | */ |
431 | */ |
|
|
432 | |
|
|
433 | void rxvt_term::child_exited (int pid) |
|
|
434 | { |
|
|
435 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
|
|
436 | if (pid == (*t)->cmd_pid) |
|
|
437 | { |
|
|
438 | (*t)->destroy (); |
|
|
439 | break; |
|
|
440 | } |
|
|
441 | } |
|
|
442 | |
410 | /* ARGSUSED */ |
443 | /* ARGSUSED */ |
411 | /* EXTPROTO */ |
444 | /* EXTPROTO */ |
412 | RETSIGTYPE |
445 | RETSIGTYPE |
413 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
446 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
414 | { |
447 | { |
415 | int pid, save_errno = errno; |
448 | int pid, save_errno = errno; |
|
|
449 | |
416 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
450 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
417 | ; |
451 | rxvt_term::child_exited (pid); |
|
|
452 | |
418 | errno = save_errno; |
453 | errno = save_errno; |
419 | |
|
|
420 | #if 0 |
|
|
421 | if (pid == cmd_pid) |
|
|
422 | exit (EXIT_SUCCESS); |
|
|
423 | #endif |
|
|
424 | } |
454 | } |
425 | |
455 | |
426 | /* |
456 | /* |
427 | * Catch a fatal signal and tidy up before quitting |
457 | * Catch a fatal signal and tidy up before quitting |
428 | */ |
458 | */ |
… | |
… | |
725 | max_height = MAX_ROWS * TermWin.fheight; |
755 | max_height = MAX_ROWS * TermWin.fheight; |
726 | |
756 | |
727 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
757 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
728 | |
758 | |
729 | sb_w = mb_h = 0; |
759 | sb_w = mb_h = 0; |
730 | window_vt_x = window_vt_y = 0; |
760 | window_vt_x = window_vt_y = TermWin.int_bwidth; |
|
|
761 | |
731 | if (scrollbar_visible ()) |
762 | if (scrollbar_visible ()) |
732 | { |
763 | { |
733 | sb_w = scrollbar_TotalWidth (); |
764 | sb_w = scrollbar_TotalWidth (); |
734 | szHint.base_width += sb_w; |
765 | szHint.base_width += sb_w; |
735 | if (! (Options & Opt_scrollBar_right)) |
766 | if (!(Options & Opt_scrollBar_right)) |
736 | window_vt_x = sb_w; |
767 | window_vt_x += sb_w; |
737 | } |
768 | } |
|
|
769 | |
738 | if (menubar_visible ()) |
770 | if (menubar_visible ()) |
739 | { |
771 | { |
740 | mb_h = menuBar_TotalHeight (); |
772 | mb_h = menuBar_TotalHeight (); |
741 | szHint.base_height += mb_h; |
773 | szHint.base_height += mb_h; |
742 | window_vt_y = mb_h; |
774 | window_vt_y += mb_h; |
743 | } |
775 | } |
|
|
776 | |
744 | szHint.width_inc = TermWin.fwidth; |
777 | szHint.width_inc = TermWin.fwidth; |
745 | szHint.height_inc = TermWin.fheight; |
778 | szHint.height_inc = TermWin.fheight; |
746 | szHint.min_width = szHint.base_width + szHint.width_inc; |
779 | szHint.min_width = szHint.base_width + szHint.width_inc; |
747 | szHint.min_height = szHint.base_height + szHint.height_inc; |
780 | szHint.min_height = szHint.base_height + szHint.height_inc; |
748 | |
781 | |
… | |
… | |
754 | else |
787 | else |
755 | { |
788 | { |
756 | MIN_IT (TermWin.width, max_width); |
789 | MIN_IT (TermWin.width, max_width); |
757 | szHint.width = szHint.base_width + TermWin.width; |
790 | szHint.width = szHint.base_width + TermWin.width; |
758 | } |
791 | } |
|
|
792 | |
759 | if (height && height - szHint.base_height < max_height) |
793 | if (height && height - szHint.base_height < max_height) |
760 | { |
794 | { |
761 | szHint.height = height; |
795 | szHint.height = height; |
762 | TermWin.height = height - szHint.base_height; |
796 | TermWin.height = height - szHint.base_height; |
763 | } |
797 | } |
764 | else |
798 | else |
765 | { |
799 | { |
766 | MIN_IT (TermWin.height, max_height); |
800 | MIN_IT (TermWin.height, max_height); |
767 | szHint.height = szHint.base_height + TermWin.height; |
801 | szHint.height = szHint.base_height + TermWin.height; |
768 | } |
802 | } |
|
|
803 | |
769 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
804 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
770 | window_sb_x = szHint.width - sb_w; |
805 | window_sb_x = szHint.width - sb_w; |
771 | |
806 | |
772 | if (recalc_x) |
807 | if (recalc_x) |
773 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
808 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
… | |
… | |
867 | /*----------------------------------------------------------------------*/ |
902 | /*----------------------------------------------------------------------*/ |
868 | /* xterm sequences - title, iconName, color (exptl) */ |
903 | /* xterm sequences - title, iconName, color (exptl) */ |
869 | void |
904 | void |
870 | rxvt_term::set_title (const char *str) |
905 | rxvt_term::set_title (const char *str) |
871 | { |
906 | { |
872 | #ifndef SMART_WINDOW_TITLE |
907 | #ifdef SMART_WINDOW_TITLE |
873 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
874 | #else |
|
|
875 | char *name; |
908 | char *name; |
876 | |
909 | |
877 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
910 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
878 | name = NULL; |
911 | name = NULL; |
879 | |
912 | |
880 | if (name == NULL || STRCMP (name, str)) |
913 | if (name == NULL || STRCMP (name, str)) |
|
|
914 | #endif |
881 | XStoreName (display->display, TermWin.parent[0], str); |
915 | XStoreName (display->display, TermWin.parent[0], str); |
882 | |
916 | |
|
|
917 | #ifdef SMART_WINDOW_TITLE |
883 | if (name) |
918 | if (name) |
884 | XFree (name); |
919 | XFree (name); |
885 | #endif |
920 | #endif |
886 | } |
921 | } |
887 | |
922 | |
888 | void |
923 | void |
889 | rxvt_term::set_icon_name (const char *str) |
924 | rxvt_term::set_icon_name (const char *str) |
890 | { |
925 | { |
891 | #ifndef SMART_WINDOW_TITLE |
926 | #ifdef SMART_WINDOW_TITLE |
892 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
893 | #else |
|
|
894 | char *name; |
927 | char *name; |
895 | |
928 | |
896 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
929 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
897 | name = NULL; |
930 | name = NULL; |
898 | |
931 | |
899 | if (name == NULL || STRCMP (name, str)) |
932 | if (name == NULL || STRCMP (name, str)) |
|
|
933 | #endif |
900 | XSetIconName (display->display, TermWin.parent[0], str); |
934 | XSetIconName (display->display, TermWin.parent[0], str); |
901 | |
935 | |
|
|
936 | #ifdef SMART_WINDOW_TITLE |
902 | if (name) |
937 | if (name) |
903 | XFree (name); |
938 | XFree (name); |
904 | #endif |
939 | #endif |
905 | } |
940 | } |
906 | |
941 | |
… | |
… | |
933 | PixColors[idx] = PixColors[minCOLOR + i]; |
968 | PixColors[idx] = PixColors[minCOLOR + i]; |
934 | SET_PIXCOLOR (idx); |
969 | SET_PIXCOLOR (idx); |
935 | goto Done; |
970 | goto Done; |
936 | } |
971 | } |
937 | } |
972 | } |
|
|
973 | |
938 | if (!rXParseAllocColor (& xcol, color)) |
974 | if (!rXParseAllocColor (& xcol, color)) |
939 | return; |
975 | return; |
|
|
976 | |
940 | /* XStoreColor (display->display, XCMAP, XColor*); */ |
977 | /* XStoreColor (display->display, XCMAP, XColor*); */ |
941 | |
978 | |
942 | /* |
979 | /* |
943 | * FIXME: should free colors here, but no idea how to do it so instead, |
980 | * FIXME: should free colors here, but no idea how to do it so instead, |
944 | * so just keep gobbling up the colormap |
981 | * so just keep gobbling up the colormap |
… | |
… | |
967 | |
1004 | |
968 | /* handle Color_BD, scrollbar background, etc. */ |
1005 | /* handle Color_BD, scrollbar background, etc. */ |
969 | |
1006 | |
970 | set_colorfgbg (); |
1007 | set_colorfgbg (); |
971 | recolour_cursor (); |
1008 | recolour_cursor (); |
972 | /* the only reasonable way to enforce a clean update */ |
1009 | scr_touch (true); |
973 | scr_poweron (); |
|
|
974 | } |
1010 | } |
975 | |
1011 | |
976 | #else |
1012 | #else |
977 | # define set_window_color (idx,color) ((void)0) |
1013 | # define set_window_color (idx,color) ((void)0) |
978 | #endif /* XTERM_COLOR_CHANGE */ |
1014 | #endif /* XTERM_COLOR_CHANGE */ |
979 | |
1015 | |
980 | void |
1016 | void |
981 | rxvt_term::recolour_cursor () |
1017 | rxvt_term::recolour_cursor () |
982 | { |
1018 | { |
983 | #if TODO |
|
|
984 | rxvt_color xcol[2]; |
1019 | XColor xcol[2]; |
985 | |
1020 | |
986 | xcol[0] = PixColors[Color_pointer]; |
1021 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColors[Color_pointer_fg] : PixColors[Color_fg]; |
987 | xcol[1] = PixColors[Color_bg]; |
1022 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColors[Color_pointer_bg] : PixColors[Color_bg]; |
988 | XQueryColors (display->display, XCMAP, xcol, 2); |
1023 | XQueryColors (display->display, XCMAP, xcol, 2); |
989 | XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); |
1024 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
990 | #endif |
|
|
991 | } |
1025 | } |
992 | |
1026 | |
993 | /*----------------------------------------------------------------------*/ |
1027 | /*----------------------------------------------------------------------*/ |
994 | /* |
1028 | /* |
995 | * find if fg/bg matches any of the normal (low-intensity) colors |
1029 | * find if fg/bg matches any of the normal (low-intensity) colors |
… | |
… | |
1065 | int old_width = szHint.width, old_height = szHint.height; |
1099 | int old_width = szHint.width, old_height = szHint.height; |
1066 | #endif |
1100 | #endif |
1067 | |
1101 | |
1068 | window_calc (width, height); |
1102 | window_calc (width, height); |
1069 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
1103 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
|
|
1104 | |
1070 | if (!ignoreparent) |
1105 | if (!ignoreparent) |
1071 | { |
1106 | { |
1072 | #ifdef SMART_RESIZE |
1107 | #ifdef SMART_RESIZE |
1073 | /* |
1108 | /* |
1074 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
1109 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
… | |
… | |
1109 | dy /= 2; |
1144 | dy /= 2; |
1110 | |
1145 | |
1111 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1146 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1112 | szHint.width, szHint.height); |
1147 | szHint.width, szHint.height); |
1113 | #else |
1148 | #else |
1114 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, |
1149 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); |
1115 | szHint.height); |
|
|
1116 | #endif |
1150 | #endif |
1117 | |
|
|
1118 | } |
1151 | } |
1119 | |
1152 | |
1120 | fix_screen = (TermWin.ncol != prev_ncol |
1153 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1121 | || TermWin.nrow != prev_nrow); |
|
|
1122 | |
1154 | |
1123 | if (fix_screen || width != old_width || height != old_height) |
1155 | if (fix_screen || width != old_width || height != old_height) |
1124 | { |
1156 | { |
1125 | if (scrollbar_visible ()) |
1157 | if (scrollbar_visible ()) |
1126 | { |
1158 | { |
1127 | XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, |
1159 | XMoveResizeWindow (display->display, scrollBar.win, |
|
|
1160 | window_sb_x, 0, |
1128 | 0, scrollbar_TotalWidth (), szHint.height); |
1161 | scrollbar_TotalWidth (), szHint.height); |
1129 | resize_scrollbar (); |
1162 | resize_scrollbar (); |
1130 | } |
1163 | } |
1131 | |
1164 | |
1132 | if (menubar_visible ()) |
1165 | if (menubar_visible ()) |
1133 | XMoveResizeWindow (display->display, menuBar.win, window_vt_x, |
1166 | XMoveResizeWindow (display->display, menuBar.win, |
|
|
1167 | window_vt_x, 0, |
1134 | 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1168 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1135 | |
1169 | |
1136 | XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, |
1170 | XMoveResizeWindow (display->display, TermWin.vt, |
1137 | window_vt_y, TermWin_TotalWidth (), |
1171 | window_vt_x, window_vt_y, |
1138 | TermWin_TotalHeight ()); |
1172 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1139 | scr_clear (height != old_height); |
1173 | scr_clear (); |
1140 | #ifdef XPM_BACKGROUND |
1174 | #ifdef XPM_BACKGROUND |
1141 | resize_pixmap (); |
1175 | resize_pixmap (); |
1142 | #endif |
1176 | #endif |
1143 | |
|
|
1144 | } |
1177 | } |
1145 | |
1178 | |
1146 | if (fix_screen || old_height == 0) |
1179 | if (fix_screen || old_height == 0) |
1147 | { |
1180 | { |
1148 | int curr_screen = -1; |
1181 | int curr_screen = -1; |