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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines