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.60 by pcg, Sun Mar 28 02:07:08 2004 UTC vs.
Revision 1.67 by pcg, Sun May 9 18:19:49 2004 UTC

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
49vector<rxvt_term *> rxvt_term::termlist;
50
49static char curlocale[128]; 51static char curlocale[128];
50 52
51void 53bool
52rxvt_set_locale (const char *locale) 54rxvt_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
62class rxvt_composite_vec rxvt_composite; 65class 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
171rxvt_term::~rxvt_term () 176rxvt_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
418void 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 */
412RETSIGTYPE 430RETSIGTYPE
413rxvt_Child_signal (int sig __attribute__ ((unused))) 431rxvt_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 */
726 741
727 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; 742 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth;
728 743
729 sb_w = mb_h = 0; 744 sb_w = mb_h = 0;
730 window_vt_x = window_vt_y = 0; 745 window_vt_x = window_vt_y = 0;
746
731 if (scrollbar_visible ()) 747 if (scrollbar_visible ())
732 { 748 {
733 sb_w = scrollbar_TotalWidth (); 749 sb_w = scrollbar_TotalWidth ();
734 szHint.base_width += sb_w; 750 szHint.base_width += sb_w;
735 if (! (Options & Opt_scrollBar_right)) 751 if (! (Options & Opt_scrollBar_right))
736 window_vt_x = sb_w; 752 window_vt_x = sb_w;
737 } 753 }
754
738 if (menubar_visible ()) 755 if (menubar_visible ())
739 { 756 {
740 mb_h = menuBar_TotalHeight (); 757 mb_h = menuBar_TotalHeight ();
741 szHint.base_height += mb_h; 758 szHint.base_height += mb_h;
742 window_vt_y = mb_h; 759 window_vt_y = mb_h;
743 } 760 }
761
744 szHint.width_inc = TermWin.fwidth; 762 szHint.width_inc = TermWin.fwidth;
745 szHint.height_inc = TermWin.fheight; 763 szHint.height_inc = TermWin.fheight;
746 szHint.min_width = szHint.base_width + szHint.width_inc; 764 szHint.min_width = szHint.base_width + szHint.width_inc;
747 szHint.min_height = szHint.base_height + szHint.height_inc; 765 szHint.min_height = szHint.base_height + szHint.height_inc;
748 766
754 else 772 else
755 { 773 {
756 MIN_IT (TermWin.width, max_width); 774 MIN_IT (TermWin.width, max_width);
757 szHint.width = szHint.base_width + TermWin.width; 775 szHint.width = szHint.base_width + TermWin.width;
758 } 776 }
777
759 if (height && height - szHint.base_height < max_height) 778 if (height && height - szHint.base_height < max_height)
760 { 779 {
761 szHint.height = height; 780 szHint.height = height;
762 TermWin.height = height - szHint.base_height; 781 TermWin.height = height - szHint.base_height;
763 } 782 }
764 else 783 else
765 { 784 {
766 MIN_IT (TermWin.height, max_height); 785 MIN_IT (TermWin.height, max_height);
767 szHint.height = szHint.base_height + TermWin.height; 786 szHint.height = szHint.base_height + TermWin.height;
768 } 787 }
788
769 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 789 if (scrollbar_visible () && (Options & Opt_scrollBar_right))
770 window_sb_x = szHint.width - sb_w; 790 window_sb_x = szHint.width - sb_w;
771 791
772 if (recalc_x) 792 if (recalc_x)
773 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 793 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
867/*----------------------------------------------------------------------*/ 887/*----------------------------------------------------------------------*/
868/* xterm sequences - title, iconName, color (exptl) */ 888/* xterm sequences - title, iconName, color (exptl) */
869void 889void
870rxvt_term::set_title (const char *str) 890rxvt_term::set_title (const char *str)
871{ 891{
872#ifndef SMART_WINDOW_TITLE 892#ifdef SMART_WINDOW_TITLE
873 XStoreName (display->display, TermWin.parent[0], str);
874#else
875 char *name; 893 char *name;
876 894
877 if (!XFetchName (display->display, TermWin.parent[0], &name)) 895 if (!XFetchName (display->display, TermWin.parent[0], &name))
878 name = NULL; 896 name = NULL;
879 897
880 if (name == NULL || STRCMP (name, str)) 898 if (name == NULL || STRCMP (name, str))
899#endif
881 XStoreName (display->display, TermWin.parent[0], str); 900 XStoreName (display->display, TermWin.parent[0], str);
882 901
902#ifdef SMART_WINDOW_TITLE
883 if (name) 903 if (name)
884 XFree (name); 904 XFree (name);
885#endif 905#endif
886} 906}
887 907
888void 908void
889rxvt_term::set_icon_name (const char *str) 909rxvt_term::set_icon_name (const char *str)
890{ 910{
891#ifndef SMART_WINDOW_TITLE 911#ifdef SMART_WINDOW_TITLE
892 XSetIconName (display->display, TermWin.parent[0], str);
893#else
894 char *name; 912 char *name;
895 913
896 if (!XGetIconName (display->display, TermWin.parent[0], &name)) 914 if (!XGetIconName (display->display, TermWin.parent[0], &name))
897 name = NULL; 915 name = NULL;
898 916
899 if (name == NULL || STRCMP (name, str)) 917 if (name == NULL || STRCMP (name, str))
918#endif
900 XSetIconName (display->display, TermWin.parent[0], str); 919 XSetIconName (display->display, TermWin.parent[0], str);
901 920
921#ifdef SMART_WINDOW_TITLE
902 if (name) 922 if (name)
903 XFree (name); 923 XFree (name);
904#endif 924#endif
905} 925}
906 926
933 PixColors[idx] = PixColors[minCOLOR + i]; 953 PixColors[idx] = PixColors[minCOLOR + i];
934 SET_PIXCOLOR (idx); 954 SET_PIXCOLOR (idx);
935 goto Done; 955 goto Done;
936 } 956 }
937 } 957 }
958
938 if (!rXParseAllocColor (& xcol, color)) 959 if (!rXParseAllocColor (& xcol, color))
939 return; 960 return;
961
940 /* XStoreColor (display->display, XCMAP, XColor*); */ 962 /* XStoreColor (display->display, XCMAP, XColor*); */
941 963
942 /* 964 /*
943 * FIXME: should free colors here, but no idea how to do it so instead, 965 * FIXME: should free colors here, but no idea how to do it so instead,
944 * so just keep gobbling up the colormap 966 * so just keep gobbling up the colormap
967 989
968 /* handle Color_BD, scrollbar background, etc. */ 990 /* handle Color_BD, scrollbar background, etc. */
969 991
970 set_colorfgbg (); 992 set_colorfgbg ();
971 recolour_cursor (); 993 recolour_cursor ();
972 /* the only reasonable way to enforce a clean update */ 994 scr_touch (true);
973 scr_poweron ();
974} 995}
975 996
976#else 997#else
977# define set_window_color (idx,color) ((void)0) 998# define set_window_color (idx,color) ((void)0)
978#endif /* XTERM_COLOR_CHANGE */ 999#endif /* XTERM_COLOR_CHANGE */
979 1000
980void 1001void
981rxvt_term::recolour_cursor () 1002rxvt_term::recolour_cursor ()
982{ 1003{
983#if TODO
984 rxvt_color xcol[2]; 1004 XColor xcol[2];
985 1005
986 xcol[0] = PixColors[Color_pointer]; 1006 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColors[Color_pointer_fg] : PixColors[Color_fg];
987 xcol[1] = PixColors[Color_bg]; 1007 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColors[Color_pointer_bg] : PixColors[Color_bg];
988 XQueryColors (display->display, XCMAP, xcol, 2); 1008 XQueryColors (display->display, XCMAP, xcol, 2);
989 XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); 1009 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
990#endif
991} 1010}
992 1011
993/*----------------------------------------------------------------------*/ 1012/*----------------------------------------------------------------------*/
994/* 1013/*
995 * find if fg/bg matches any of the normal (low-intensity) colors 1014 * find if fg/bg matches any of the normal (low-intensity) colors
1065 int old_width = szHint.width, old_height = szHint.height; 1084 int old_width = szHint.width, old_height = szHint.height;
1066#endif 1085#endif
1067 1086
1068 window_calc (width, height); 1087 window_calc (width, height);
1069 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); 1088 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint);
1089
1070 if (!ignoreparent) 1090 if (!ignoreparent)
1071 { 1091 {
1072#ifdef SMART_RESIZE 1092#ifdef SMART_RESIZE
1073 /* 1093 /*
1074 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> 1094 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt>
1109 dy /= 2; 1129 dy /= 2;
1110 1130
1111 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, 1131 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy,
1112 szHint.width, szHint.height); 1132 szHint.width, szHint.height);
1113#else 1133#else
1114 XResizeWindow (display->display, TermWin.parent[0], szHint.width, 1134 XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height);
1115 szHint.height);
1116#endif 1135#endif
1117
1118 } 1136 }
1119 1137
1120 fix_screen = (TermWin.ncol != prev_ncol 1138 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow;
1121 || TermWin.nrow != prev_nrow);
1122 1139
1123 if (fix_screen || width != old_width || height != old_height) 1140 if (fix_screen || width != old_width || height != old_height)
1124 { 1141 {
1125 if (scrollbar_visible ()) 1142 if (scrollbar_visible ())
1126 { 1143 {
1127 XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, 1144 XMoveResizeWindow (display->display, scrollBar.win,
1145 window_sb_x, 0,
1128 0, scrollbar_TotalWidth (), szHint.height); 1146 scrollbar_TotalWidth (), szHint.height);
1129 resize_scrollbar (); 1147 resize_scrollbar ();
1130 } 1148 }
1131 1149
1132 if (menubar_visible ()) 1150 if (menubar_visible ())
1133 XMoveResizeWindow (display->display, menuBar.win, window_vt_x, 1151 XMoveResizeWindow (display->display, menuBar.win,
1152 window_vt_x, 0,
1134 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); 1153 TermWin_TotalWidth (), menuBar_TotalHeight ());
1135 1154
1136 XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, 1155 XMoveResizeWindow (display->display, TermWin.vt,
1137 window_vt_y, TermWin_TotalWidth (), 1156 window_vt_x, window_vt_y,
1138 TermWin_TotalHeight ()); 1157 TermWin_TotalWidth (), TermWin_TotalHeight ());
1139 scr_clear (height != old_height); 1158 scr_clear ();
1140#ifdef XPM_BACKGROUND 1159#ifdef XPM_BACKGROUND
1141 resize_pixmap (); 1160 resize_pixmap ();
1142#endif 1161#endif
1143
1144 } 1162 }
1145 1163
1146 if (fix_screen || old_height == 0) 1164 if (fix_screen || old_height == 0)
1147 { 1165 {
1148 int curr_screen = -1; 1166 int curr_screen = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines