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 | |
… | |
… | |
164 | destroy_ev (this, &rxvt_term::destroy_cb), |
167 | destroy_ev (this, &rxvt_term::destroy_cb), |
165 | pty_ev (this, &rxvt_term::pty_cb), |
168 | pty_ev (this, &rxvt_term::pty_cb), |
166 | incr_ev (this, &rxvt_term::incr_cb) |
169 | incr_ev (this, &rxvt_term::incr_cb) |
167 | { |
170 | { |
168 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
171 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
|
|
172 | |
|
|
173 | termlist.push_back (this); |
169 | } |
174 | } |
170 | |
175 | |
171 | rxvt_term::~rxvt_term () |
176 | rxvt_term::~rxvt_term () |
172 | { |
177 | { |
|
|
178 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
|
|
179 | |
173 | if (cmd_fd >= 0) |
180 | if (cmd_fd >= 0) |
174 | close (cmd_fd); |
181 | close (cmd_fd); |
175 | |
182 | |
176 | #ifndef NO_SETOWNER_TTYDEV |
183 | #ifndef NO_SETOWNER_TTYDEV |
177 | privileged_ttydev (RESTORE); |
184 | privileged_ttydev (RESTORE); |
… | |
… | |
405 | * SIGNAL HANDLING & EXIT HANDLER * |
412 | * SIGNAL HANDLING & EXIT HANDLER * |
406 | * ------------------------------------------------------------------------- */ |
413 | * ------------------------------------------------------------------------- */ |
407 | /* |
414 | /* |
408 | * Catch a SIGCHLD signal and exit if the direct child has died |
415 | * Catch a SIGCHLD signal and exit if the direct child has died |
409 | */ |
416 | */ |
|
|
417 | |
|
|
418 | void rxvt_term::child_exited (int pid) |
|
|
419 | { |
|
|
420 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
|
|
421 | if (pid == (*t)->cmd_pid) |
|
|
422 | { |
|
|
423 | (*t)->destroy (); |
|
|
424 | break; |
|
|
425 | } |
|
|
426 | } |
|
|
427 | |
410 | /* ARGSUSED */ |
428 | /* ARGSUSED */ |
411 | /* EXTPROTO */ |
429 | /* EXTPROTO */ |
412 | RETSIGTYPE |
430 | RETSIGTYPE |
413 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
431 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
414 | { |
432 | { |
415 | int pid, save_errno = errno; |
433 | int pid, save_errno = errno; |
|
|
434 | |
416 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
435 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
417 | ; |
436 | rxvt_term::child_exited (pid); |
|
|
437 | |
418 | errno = save_errno; |
438 | errno = save_errno; |
419 | |
|
|
420 | #if 0 |
|
|
421 | if (pid == cmd_pid) |
|
|
422 | exit (EXIT_SUCCESS); |
|
|
423 | #endif |
|
|
424 | } |
439 | } |
425 | |
440 | |
426 | /* |
441 | /* |
427 | * Catch a fatal signal and tidy up before quitting |
442 | * Catch a fatal signal and tidy up before quitting |
428 | */ |
443 | */ |
… | |
… | |
867 | /*----------------------------------------------------------------------*/ |
882 | /*----------------------------------------------------------------------*/ |
868 | /* xterm sequences - title, iconName, color (exptl) */ |
883 | /* xterm sequences - title, iconName, color (exptl) */ |
869 | void |
884 | void |
870 | rxvt_term::set_title (const char *str) |
885 | rxvt_term::set_title (const char *str) |
871 | { |
886 | { |
872 | #ifndef SMART_WINDOW_TITLE |
887 | #ifdef SMART_WINDOW_TITLE |
873 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
874 | #else |
|
|
875 | char *name; |
888 | char *name; |
876 | |
889 | |
877 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
890 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
878 | name = NULL; |
891 | name = NULL; |
879 | |
892 | |
880 | if (name == NULL || STRCMP (name, str)) |
893 | if (name == NULL || STRCMP (name, str)) |
|
|
894 | #endif |
881 | XStoreName (display->display, TermWin.parent[0], str); |
895 | XStoreName (display->display, TermWin.parent[0], str); |
882 | |
896 | |
|
|
897 | #ifdef SMART_WINDOW_TITLE |
883 | if (name) |
898 | if (name) |
884 | XFree (name); |
899 | XFree (name); |
885 | #endif |
900 | #endif |
886 | } |
901 | } |
887 | |
902 | |
888 | void |
903 | void |
889 | rxvt_term::set_icon_name (const char *str) |
904 | rxvt_term::set_icon_name (const char *str) |
890 | { |
905 | { |
891 | #ifndef SMART_WINDOW_TITLE |
906 | #ifdef SMART_WINDOW_TITLE |
892 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
893 | #else |
|
|
894 | char *name; |
907 | char *name; |
895 | |
908 | |
896 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
909 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
897 | name = NULL; |
910 | name = NULL; |
898 | |
911 | |
899 | if (name == NULL || STRCMP (name, str)) |
912 | if (name == NULL || STRCMP (name, str)) |
|
|
913 | #endif |
900 | XSetIconName (display->display, TermWin.parent[0], str); |
914 | XSetIconName (display->display, TermWin.parent[0], str); |
901 | |
915 | |
|
|
916 | #ifdef SMART_WINDOW_TITLE |
902 | if (name) |
917 | if (name) |
903 | XFree (name); |
918 | XFree (name); |
904 | #endif |
919 | #endif |
905 | } |
920 | } |
906 | |
921 | |
… | |
… | |
933 | PixColors[idx] = PixColors[minCOLOR + i]; |
948 | PixColors[idx] = PixColors[minCOLOR + i]; |
934 | SET_PIXCOLOR (idx); |
949 | SET_PIXCOLOR (idx); |
935 | goto Done; |
950 | goto Done; |
936 | } |
951 | } |
937 | } |
952 | } |
|
|
953 | |
938 | if (!rXParseAllocColor (& xcol, color)) |
954 | if (!rXParseAllocColor (& xcol, color)) |
939 | return; |
955 | return; |
|
|
956 | |
940 | /* XStoreColor (display->display, XCMAP, XColor*); */ |
957 | /* XStoreColor (display->display, XCMAP, XColor*); */ |
941 | |
958 | |
942 | /* |
959 | /* |
943 | * FIXME: should free colors here, but no idea how to do it so instead, |
960 | * FIXME: should free colors here, but no idea how to do it so instead, |
944 | * so just keep gobbling up the colormap |
961 | * so just keep gobbling up the colormap |
… | |
… | |
967 | |
984 | |
968 | /* handle Color_BD, scrollbar background, etc. */ |
985 | /* handle Color_BD, scrollbar background, etc. */ |
969 | |
986 | |
970 | set_colorfgbg (); |
987 | set_colorfgbg (); |
971 | recolour_cursor (); |
988 | recolour_cursor (); |
972 | /* the only reasonable way to enforce a clean update */ |
989 | scr_touch (true); |
973 | scr_poweron (); |
|
|
974 | } |
990 | } |
975 | |
991 | |
976 | #else |
992 | #else |
977 | # define set_window_color (idx,color) ((void)0) |
993 | # define set_window_color (idx,color) ((void)0) |
978 | #endif /* XTERM_COLOR_CHANGE */ |
994 | #endif /* XTERM_COLOR_CHANGE */ |
979 | |
995 | |
980 | void |
996 | void |
981 | rxvt_term::recolour_cursor () |
997 | rxvt_term::recolour_cursor () |
982 | { |
998 | { |
983 | #if TODO |
|
|
984 | rxvt_color xcol[2]; |
999 | XColor xcol[2]; |
985 | |
1000 | |
986 | xcol[0] = PixColors[Color_pointer]; |
1001 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColors[Color_pointer_fg] : PixColors[Color_fg]; |
987 | xcol[1] = PixColors[Color_bg]; |
1002 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColors[Color_pointer_bg] : PixColors[Color_bg]; |
988 | XQueryColors (display->display, XCMAP, xcol, 2); |
1003 | XQueryColors (display->display, XCMAP, xcol, 2); |
989 | XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); |
1004 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
990 | #endif |
|
|
991 | } |
1005 | } |
992 | |
1006 | |
993 | /*----------------------------------------------------------------------*/ |
1007 | /*----------------------------------------------------------------------*/ |
994 | /* |
1008 | /* |
995 | * find if fg/bg matches any of the normal (low-intensity) colors |
1009 | * find if fg/bg matches any of the normal (low-intensity) colors |