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.73 by root, Fri Jul 30 14:59:12 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
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
171rxvt_term::~rxvt_term () 185rxvt_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);
226 XDestroyWindow (display->display, TermWin.parent[0]); 242 XDestroyWindow (display->display, TermWin.parent[0]);
227 } 243 }
228 244
229 // TODO: free pixcolours, colours should become part of rxvt_display 245 // TODO: free pixcolours, colours should become part of rxvt_display
230 246
231 delete PixColors; 247 delete PixColorsFocused;
248#ifdef OFF_FOCUS_FADING
249 delete PixColorsUnFocused;
250#endif
232 251
233 displays.put (display); 252 displays.put (display);
234 253
235 scr_release (); 254 scr_release ();
236 255
279 cursor_blink_ev.stop (); 298 cursor_blink_ev.stop ();
280#endif 299#endif
281#ifdef TEXT_BLINK 300#ifdef TEXT_BLINK
282 text_blink_ev.stop (); 301 text_blink_ev.stop ();
283#endif 302#endif
303#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
304 cont_scroll_ev.stop ();
305#endif
306#ifdef SELECTION_SCROLLING
307 sel_scroll_ev.stop ();
308#endif
284#ifdef POINTER_BLANK 309#ifdef POINTER_BLANK
285 pointer_ev.stop (); 310 pointer_ev.stop ();
286#endif 311#endif
287 312
288 destroy_ev.start (0); 313 destroy_ev.start (0);
405 * SIGNAL HANDLING & EXIT HANDLER * 430 * SIGNAL HANDLING & EXIT HANDLER *
406 * ------------------------------------------------------------------------- */ 431 * ------------------------------------------------------------------------- */
407/* 432/*
408 * Catch a SIGCHLD signal and exit if the direct child has died 433 * Catch a SIGCHLD signal and exit if the direct child has died
409 */ 434 */
435
436void rxvt_term::child_exited (int pid)
437{
438 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
439 if (pid == (*t)->cmd_pid)
440 {
441 (*t)->destroy ();
442 break;
443 }
444}
445
410/* ARGSUSED */ 446/* ARGSUSED */
411/* EXTPROTO */ 447/* EXTPROTO */
412RETSIGTYPE 448RETSIGTYPE
413rxvt_Child_signal (int sig __attribute__ ((unused))) 449rxvt_Child_signal (int sig __attribute__ ((unused)))
414{ 450{
415 int pid, save_errno = errno; 451 int pid, save_errno = errno;
452
416 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) 453 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
417 ; 454 rxvt_term::child_exited (pid);
455
418 errno = save_errno; 456 errno = save_errno;
419
420#if 0
421 if (pid == cmd_pid)
422 exit (EXIT_SUCCESS);
423#endif
424} 457}
425 458
426/* 459/*
427 * Catch a fatal signal and tidy up before quitting 460 * Catch a fatal signal and tidy up before quitting
428 */ 461 */
725 max_height = MAX_ROWS * TermWin.fheight; 758 max_height = MAX_ROWS * TermWin.fheight;
726 759
727 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; 760 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth;
728 761
729 sb_w = mb_h = 0; 762 sb_w = mb_h = 0;
730 window_vt_x = window_vt_y = 0; 763 window_vt_x = window_vt_y = TermWin.int_bwidth;
764
731 if (scrollbar_visible ()) 765 if (scrollbar_visible ())
732 { 766 {
733 sb_w = scrollbar_TotalWidth (); 767 sb_w = scrollbar_TotalWidth ();
734 szHint.base_width += sb_w; 768 szHint.base_width += sb_w;
735 if (! (Options & Opt_scrollBar_right)) 769 if (!(Options & Opt_scrollBar_right))
736 window_vt_x = sb_w; 770 window_vt_x += sb_w;
737 } 771 }
772
738 if (menubar_visible ()) 773 if (menubar_visible ())
739 { 774 {
740 mb_h = menuBar_TotalHeight (); 775 mb_h = menuBar_TotalHeight ();
741 szHint.base_height += mb_h; 776 szHint.base_height += mb_h;
742 window_vt_y = mb_h; 777 window_vt_y += mb_h;
743 } 778 }
779
744 szHint.width_inc = TermWin.fwidth; 780 szHint.width_inc = TermWin.fwidth;
745 szHint.height_inc = TermWin.fheight; 781 szHint.height_inc = TermWin.fheight;
746 szHint.min_width = szHint.base_width + szHint.width_inc; 782 szHint.min_width = szHint.base_width + szHint.width_inc;
747 szHint.min_height = szHint.base_height + szHint.height_inc; 783 szHint.min_height = szHint.base_height + szHint.height_inc;
748 784
754 else 790 else
755 { 791 {
756 MIN_IT (TermWin.width, max_width); 792 MIN_IT (TermWin.width, max_width);
757 szHint.width = szHint.base_width + TermWin.width; 793 szHint.width = szHint.base_width + TermWin.width;
758 } 794 }
795
759 if (height && height - szHint.base_height < max_height) 796 if (height && height - szHint.base_height < max_height)
760 { 797 {
761 szHint.height = height; 798 szHint.height = height;
762 TermWin.height = height - szHint.base_height; 799 TermWin.height = height - szHint.base_height;
763 } 800 }
764 else 801 else
765 { 802 {
766 MIN_IT (TermWin.height, max_height); 803 MIN_IT (TermWin.height, max_height);
767 szHint.height = szHint.base_height + TermWin.height; 804 szHint.height = szHint.base_height + TermWin.height;
768 } 805 }
806
769 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 807 if (scrollbar_visible () && (Options & Opt_scrollBar_right))
770 window_sb_x = szHint.width - sb_w; 808 window_sb_x = szHint.width - sb_w;
771 809
772 if (recalc_x) 810 if (recalc_x)
773 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 811 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
867/*----------------------------------------------------------------------*/ 905/*----------------------------------------------------------------------*/
868/* xterm sequences - title, iconName, color (exptl) */ 906/* xterm sequences - title, iconName, color (exptl) */
869void 907void
870rxvt_term::set_title (const char *str) 908rxvt_term::set_title (const char *str)
871{ 909{
872#ifndef SMART_WINDOW_TITLE 910#ifdef SMART_WINDOW_TITLE
873 XStoreName (display->display, TermWin.parent[0], str);
874#else
875 char *name; 911 char *name;
876 912
877 if (!XFetchName (display->display, TermWin.parent[0], &name)) 913 if (!XFetchName (display->display, TermWin.parent[0], &name))
878 name = NULL; 914 name = NULL;
879 915
880 if (name == NULL || STRCMP (name, str)) 916 if (name == NULL || STRCMP (name, str))
917#endif
881 XStoreName (display->display, TermWin.parent[0], str); 918 XStoreName (display->display, TermWin.parent[0], str);
882 919
920#ifdef SMART_WINDOW_TITLE
883 if (name) 921 if (name)
884 XFree (name); 922 XFree (name);
885#endif 923#endif
886} 924}
887 925
888void 926void
889rxvt_term::set_icon_name (const char *str) 927rxvt_term::set_icon_name (const char *str)
890{ 928{
891#ifndef SMART_WINDOW_TITLE 929#ifdef SMART_WINDOW_TITLE
892 XSetIconName (display->display, TermWin.parent[0], str);
893#else
894 char *name; 930 char *name;
895 931
896 if (!XGetIconName (display->display, TermWin.parent[0], &name)) 932 if (!XGetIconName (display->display, TermWin.parent[0], &name))
897 name = NULL; 933 name = NULL;
898 934
899 if (name == NULL || STRCMP (name, str)) 935 if (name == NULL || STRCMP (name, str))
936#endif
900 XSetIconName (display->display, TermWin.parent[0], str); 937 XSetIconName (display->display, TermWin.parent[0], str);
901 938
939#ifdef SMART_WINDOW_TITLE
902 if (name) 940 if (name)
903 XFree (name); 941 XFree (name);
904#endif 942#endif
905} 943}
906 944
920 i = atoi (color); 958 i = atoi (color);
921 if (i >= 8 && i <= 15) 959 if (i >= 8 && i <= 15)
922 { /* bright colors */ 960 { /* bright colors */
923 i -= 8; 961 i -= 8;
924# ifndef NO_BRIGHTCOLOR 962# ifndef NO_BRIGHTCOLOR
925 PixColors[idx] = PixColors[minBrightCOLOR + i]; 963 PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i];
926 SET_PIXCOLOR (idx); 964 SET_PIXCOLOR (idx);
927 goto Done; 965 goto Done;
928# endif 966# endif
929 967
930 } 968 }
931 if (i >= 0 && i <= 7) 969 if (i >= 0 && i <= 7)
932 { /* normal colors */ 970 { /* normal colors */
933 PixColors[idx] = PixColors[minCOLOR + i]; 971 PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i];
934 SET_PIXCOLOR (idx); 972 SET_PIXCOLOR (idx);
935 goto Done; 973 goto Done;
936 } 974 }
937 } 975 }
976
938 if (!rXParseAllocColor (& xcol, color)) 977 if (!rXParseAllocColor (& xcol, color))
939 return; 978 return;
979
940 /* XStoreColor (display->display, XCMAP, XColor*); */ 980 /* XStoreColor (display->display, XCMAP, XColor*); */
941 981
942 /* 982 /*
943 * FIXME: should free colors here, but no idea how to do it so instead, 983 * FIXME: should free colors here, but no idea how to do it so instead,
944 * so just keep gobbling up the colormap 984 * so just keep gobbling up the colormap
953 XFreeColors (display->display, XCMAP, (PixColors + idx), 1, 993 XFreeColors (display->display, XCMAP, (PixColors + idx), 1,
954 DisplayPlanes (display->display, display->screen)); 994 DisplayPlanes (display->display, display->screen));
955 } 995 }
956# endif 996# endif
957 997
958 PixColors[idx] = xcol; 998 PixColorsFocused[idx] = xcol;
959 SET_PIXCOLOR (idx); 999 SET_PIXCOLOR (idx);
960 1000
961 /* XSetWindowAttributes attr; */ 1001 /* XSetWindowAttributes attr; */
962 /* Cursor cursor; */ 1002 /* Cursor cursor; */
963Done: 1003Done:
1004#ifdef OFF_FOCUS_FADING
1005 PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade]));
1006#endif
964 if (idx == Color_bg && ! (Options & Opt_transparent)) 1007 if (idx == Color_bg && ! (Options & Opt_transparent))
965 XSetWindowBackground (display->display, TermWin.vt, 1008 XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]);
966 PixColors[Color_bg]);
967 1009
968 /* handle Color_BD, scrollbar background, etc. */ 1010 /* handle Color_BD, scrollbar background, etc. */
969 1011
970 set_colorfgbg (); 1012 set_colorfgbg ();
971 recolour_cursor (); 1013 recolour_cursor ();
972 /* the only reasonable way to enforce a clean update */ 1014 scr_touch (true);
973 scr_poweron ();
974} 1015}
975 1016
976#else 1017#else
977# define set_window_color (idx,color) ((void)0) 1018# define set_window_color (idx,color) ((void)0)
978#endif /* XTERM_COLOR_CHANGE */ 1019#endif /* XTERM_COLOR_CHANGE */
979 1020
980void 1021void
981rxvt_term::recolour_cursor () 1022rxvt_term::recolour_cursor ()
982{ 1023{
983#if TODO
984 rxvt_color xcol[2]; 1024 XColor xcol[2];
985 1025
986 xcol[0] = PixColors[Color_pointer]; 1026 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg];
987 xcol[1] = PixColors[Color_bg]; 1027 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg];
988 XQueryColors (display->display, XCMAP, xcol, 2); 1028 XQueryColors (display->display, XCMAP, xcol, 2);
989 XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); 1029 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
990#endif
991} 1030}
992 1031
993/*----------------------------------------------------------------------*/ 1032/*----------------------------------------------------------------------*/
994/* 1033/*
995 * find if fg/bg matches any of the normal (low-intensity) colors 1034 * find if fg/bg matches any of the normal (low-intensity) colors
1065 int old_width = szHint.width, old_height = szHint.height; 1104 int old_width = szHint.width, old_height = szHint.height;
1066#endif 1105#endif
1067 1106
1068 window_calc (width, height); 1107 window_calc (width, height);
1069 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); 1108 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint);
1109
1070 if (!ignoreparent) 1110 if (!ignoreparent)
1071 { 1111 {
1072#ifdef SMART_RESIZE 1112#ifdef SMART_RESIZE
1073 /* 1113 /*
1074 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> 1114 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt>
1109 dy /= 2; 1149 dy /= 2;
1110 1150
1111 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, 1151 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy,
1112 szHint.width, szHint.height); 1152 szHint.width, szHint.height);
1113#else 1153#else
1114 XResizeWindow (display->display, TermWin.parent[0], szHint.width, 1154 XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height);
1115 szHint.height);
1116#endif 1155#endif
1117
1118 } 1156 }
1119 1157
1120 fix_screen = (TermWin.ncol != prev_ncol 1158 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow;
1121 || TermWin.nrow != prev_nrow);
1122 1159
1123 if (fix_screen || width != old_width || height != old_height) 1160 if (fix_screen || width != old_width || height != old_height)
1124 { 1161 {
1125 if (scrollbar_visible ()) 1162 if (scrollbar_visible ())
1126 { 1163 {
1127 XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, 1164 XMoveResizeWindow (display->display, scrollBar.win,
1165 window_sb_x, 0,
1128 0, scrollbar_TotalWidth (), szHint.height); 1166 scrollbar_TotalWidth (), szHint.height);
1129 resize_scrollbar (); 1167 resize_scrollbar ();
1130 } 1168 }
1131 1169
1132 if (menubar_visible ()) 1170 if (menubar_visible ())
1133 XMoveResizeWindow (display->display, menuBar.win, window_vt_x, 1171 XMoveResizeWindow (display->display, menuBar.win,
1172 window_vt_x, 0,
1134 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); 1173 TermWin_TotalWidth (), menuBar_TotalHeight ());
1135 1174
1136 XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, 1175 XMoveResizeWindow (display->display, TermWin.vt,
1137 window_vt_y, TermWin_TotalWidth (), 1176 window_vt_x, window_vt_y,
1138 TermWin_TotalHeight ()); 1177 TermWin_TotalWidth (), TermWin_TotalHeight ());
1139 scr_clear (height != old_height); 1178 scr_clear ();
1140#ifdef XPM_BACKGROUND 1179#ifdef XPM_BACKGROUND
1141 resize_pixmap (); 1180 resize_pixmap ();
1142#endif 1181#endif
1143
1144 } 1182 }
1145 1183
1146 if (fix_screen || old_height == 0) 1184 if (fix_screen || old_height == 0)
1147 { 1185 {
1148 int curr_screen = -1; 1186 int curr_screen = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines