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.5 by pcg, Tue Nov 25 15:44:38 2003 UTC vs.
Revision 1.14 by pcg, Thu Dec 18 00:29:29 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: main.c 2 * File: main.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: main.C,v 1.5 2003/11/25 15:44:38 pcg Exp $ 4 * $Id: main.C,v 1.14 2003/12/18 00:29:29 pcg Exp $
5 * 5 *
6 * All portions of code are copyright by their respective author/s. 6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
8 * - original version 8 * - original version
9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> 9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
58{ 58{
59 free (p); 59 free (p);
60} 60}
61 61
62rxvt_term::rxvt_term () 62rxvt_term::rxvt_term ()
63: pty_ev (this, &rxvt_term::pty_cb), 63: pty_ev (this, &rxvt_term::pty_cb),
64#ifdef CURSOR_BLINK 64#ifdef CURSOR_BLINK
65 blink_ev (this, &rxvt_term::blink_cb), 65 blink_ev (this, &rxvt_term::blink_cb),
66#endif 66#endif
67#ifdef POINTER_BLANK
68 pointer_ev (this, &rxvt_term::pointer_cb),
69#endif
67 x_ev (this, &rxvt_term::x_cb) 70 x_ev (this, &rxvt_term::x_cb),
71 destroy_ev (this, &rxvt_term::destroy_cb),
72 check_ev (this, &rxvt_term::check_cb),
73 incr_ev (this, &rxvt_term::incr_cb)
68{ 74{
69 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 75 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
70} 76}
71 77
72rxvt_term::~rxvt_term () 78rxvt_term::~rxvt_term ()
73{ 79{
80 scr_release ();
81
82#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
83 free (locale);
84#endif
85#ifndef NO_SETOWNER_TTYDEV
86 rxvt_privileged_ttydev (this, RESTORE);
87#endif
88#ifdef UTMP_SUPPORT
89 rxvt_privileged_utmp (this, RESTORE);
90#endif
91#ifdef USE_XIM
92 if (Input_Context != NULL)
93 {
94 XDestroyIC (Input_Context);
95 Input_Context = NULL;
96 }
97#endif
98
99 if (cmd_fd >= 0)
100 close (cmd_fd);
101
102 if (Xfd >= 0)
103 XCloseDisplay (Xdisplay);
104
74 delete PixColors; 105 delete PixColors;
106}
107
108void
109rxvt_term::destroy ()
110{
111 check_ev.stop ();
112 pty_ev.stop ();
113 x_ev.stop ();
114#ifdef CURSOR_BLINK
115 blink_ev.stop ();
116#endif
117#ifdef POINTER_BLANK
118 pointer_ev.stop ();
119#endif
120
121 destroy_ev.start (0);
122}
123
124void
125rxvt_term::destroy_cb (time_watcher &w)
126{
127 SET_R (this);
128
129 delete this;
75} 130}
76 131
77/*----------------------------------------------------------------------*/ 132/*----------------------------------------------------------------------*/
78/* rxvt_init() */ 133/* rxvt_init() */
79/* LIBPROTO */ 134/* LIBPROTO */
80rxvt_t 135rxvt_t
81rxvt_init(int argc, const char *const *argv) 136rxvt_init (int argc, const char *const *argv)
82{ 137{
83 SET_R(new rxvt_term); 138 SET_R (new rxvt_term);
84 dR; 139 dR;
85 140
86 if (!R->init_vars () || !R->init (argc, argv)) 141 if (!R->init_vars () || !R->init (argc, argv))
87 { 142 {
88 delete R; 143 delete R;
89 return NULL; 144 return NULL;
90 } 145 }
91 146
92 return R; 147 return R;
148}
149
150/* EXTPROTO */
151void
152rxvt_init_signals ()
153{
154/* install exit handler for cleanup */
155#if 0
156#ifdef HAVE_ATEXIT
157 atexit(rxvt_clean_exit);
158#else
159#endif
160#endif
161
162 struct sigaction sa;
163
164 sigfillset (&sa.sa_mask);
165 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
166 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
167 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
168 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
169 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
170 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
171 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
172
173/* need to trap SIGURG for SVR4 (Unixware) rlogin */
174/* signal (SIGURG, SIG_DFL); */
175
176 XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
177 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
93} 178}
94 179
95bool 180bool
96rxvt_term::init (int argc, const char *const *argv) 181rxvt_term::init (int argc, const char *const *argv)
97{ 182{
121 206
122 rxvt_Create_Windows (this, argc, argv); 207 rxvt_Create_Windows (this, argc, argv);
123 208
124 rxvt_init_xlocale (this); 209 rxvt_init_xlocale (this);
125 210
126 rxvt_scr_reset (this); /* initialize screen */ 211 scr_reset (); /* initialize screen */
127#ifdef RXVT_GRAPHICS 212#ifdef RXVT_GRAPHICS
128 rxvt_Gr_reset (this); /* reset graphics */ 213 rxvt_Gr_reset (this); /* reset graphics */
129#endif 214#endif
130 215
131#if 0 216#if 0
132#ifdef DEBUG_X 217#ifdef DEBUG_X
133 XSynchronize(Xdisplay, True); 218 XSynchronize(Xdisplay, True);
134 XSetErrorHandler((XErrorHandler) abort);
135#else
136 XSetErrorHandler((XErrorHandler) rxvt_xerror_handler);
137#endif 219#endif
138#endif 220#endif
139 221
140#ifdef HAVE_SCROLLBARS 222#ifdef HAVE_SCROLLBARS
141 if (Options & Opt_scrollBar) 223 if (Options & Opt_scrollBar)
158 rxvt_init_env (this); 240 rxvt_init_env (this);
159 rxvt_init_command (this, cmd_argv); 241 rxvt_init_command (this, cmd_argv);
160 242
161 x_ev.start (Xfd, EVENT_READ); 243 x_ev.start (Xfd, EVENT_READ);
162 pty_ev.start (cmd_fd, EVENT_READ); 244 pty_ev.start (cmd_fd, EVENT_READ);
245
246 check_ev.start ();
247
248 process_x_events ();
163 249
164 return true; 250 return true;
165} 251}
166 252
167/* ------------------------------------------------------------------------- * 253/* ------------------------------------------------------------------------- *
173/* ARGSUSED */ 259/* ARGSUSED */
174/* EXTPROTO */ 260/* EXTPROTO */
175RETSIGTYPE 261RETSIGTYPE
176rxvt_Child_signal(int sig __attribute__ ((unused))) 262rxvt_Child_signal(int sig __attribute__ ((unused)))
177{ 263{
178 dR;
179 int pid, save_errno = errno; 264 int pid, save_errno = errno;
180
181 do {
182 errno = 0;
183 } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); 265 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
266 ;
267 errno = save_errno;
184 268
269#if 0
185 if (pid == R->cmd_pid) 270 if (pid == R->cmd_pid)
186 exit(EXIT_SUCCESS); 271 exit (EXIT_SUCCESS);
187 272#endif
188 errno = save_errno;
189 signal(SIGCHLD, rxvt_Child_signal);
190} 273}
191 274
192/* 275/*
193 * Catch a fatal signal and tidy up before quitting 276 * Catch a fatal signal and tidy up before quitting
194 */ 277 */
208/* INTPROTO */ 291/* INTPROTO */
209int 292int
210rxvt_xerror_handler(const Display * display 293rxvt_xerror_handler(const Display * display
211 __attribute__ ((unused)), const XErrorEvent * event) 294 __attribute__ ((unused)), const XErrorEvent * event)
212{ 295{
213 dR; 296 dR;
214 297
215 if (R->allowedxerror == -1) { 298 if (R->allowedxerror == -1)
216 R->allowedxerror = event->error_code; 299 R->allowedxerror = event->error_code;
217 return 0; /* ignored anyway */ 300 else
218 } 301 {
219 rxvt_print_error("XError: Request: %d . %d, Error: %d", 302 rxvt_print_error("XError: Request: %d . %d, Error: %d",
220 event->request_code, event->minor_code, 303 event->request_code, event->minor_code,
221 event->error_code); 304 event->error_code);
222/* XXX: probably should call rxvt_clean_exit() bypassing X routines */ 305
223 exit(EXIT_FAILURE); 306 R->destroy ();
224/* NOTREACHED */ 307 }
308
309 return 0;
225} 310}
226 311
227/*----------------------------------------------------------------------*/ 312/*----------------------------------------------------------------------*/
228/* 313/*
229 * Exit gracefully, clearing the utmp entry and restoring tty attributes 314 * Exit gracefully, clearing the utmp entry and restoring tty attributes
230 * TODO: if debugging, this should free up any known resources if we can 315 * TODO: if debugging, this should free up any known resources if we can
231 */ 316 */
232/* EXTPROTO */ 317/* EXTPROTO */
233void 318void
234rxvt_clean_exit(void) 319rxvt_clean_exit ()
235{ 320{
236 dR; 321 dR;
237 322
238#ifdef DEBUG_SCREEN 323 R->destroy ();
239 rxvt_scr_release(aR);
240#endif
241#ifndef NO_SETOWNER_TTYDEV
242 rxvt_privileged_ttydev(aR_ RESTORE);
243#endif
244#ifdef UTMP_SUPPORT
245 rxvt_privileged_utmp(aR_ RESTORE);
246#endif
247#ifdef USE_XIM
248 if (R->Input_Context != NULL) {
249 XDestroyIC(R->Input_Context);
250 R->Input_Context = NULL;
251 }
252#endif
253} 324}
254 325
255/* ------------------------------------------------------------------------- * 326/* ------------------------------------------------------------------------- *
256 * MEMORY ALLOCATION WRAPPERS * 327 * MEMORY ALLOCATION WRAPPERS *
257 * ------------------------------------------------------------------------- */ 328 * ------------------------------------------------------------------------- */
549/*----------------------------------------------------------------------*/ 620/*----------------------------------------------------------------------*/
550/* 621/*
551 * Tell the teletype handler what size the window is. 622 * Tell the teletype handler what size the window is.
552 * Called after a window size change. 623 * Called after a window size change.
553 */ 624 */
554/* EXTPROTO */
555void 625void
556rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) 626rxvt_term::tt_winch ()
557{ 627{
558 struct winsize ws; 628 struct winsize ws;
559 629
560 if (fd < 0) 630 if (cmd_fd < 0)
561 return; 631 return;
632
562 ws.ws_col = col; 633 ws.ws_col = TermWin.ncol;
563 ws.ws_row = row; 634 ws.ws_row = TermWin.nrow;
564 ws.ws_xpixel = ws.ws_ypixel = 0; 635 ws.ws_xpixel = ws.ws_ypixel = 0;
565#ifndef DEBUG_SIZE 636#ifndef DEBUG_SIZE
566 (void)ioctl(fd, TIOCSWINSZ, &ws); 637 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws);
567#else 638#else
568 if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { 639 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0)
569 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 640 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd));
570 }
571# ifdef SIGWINCH 641# ifdef SIGWINCH
572 else if (pid) /* force through to the command */ 642 else if (cmd_pid) /* force through to the command */
573 kill(pid, SIGWINCH); 643 kill (cmd_pid, SIGWINCH);
574# endif 644# endif
575#endif 645#endif
576} 646}
577 647
578/*----------------------------------------------------------------------*/ 648/*----------------------------------------------------------------------*/
873 uint16_t old_ncol = R->prev_ncol; 943 uint16_t old_ncol = R->prev_ncol;
874 944
875 /* scr_reset only works on the primary screen */ 945 /* scr_reset only works on the primary screen */
876 if (R->old_height) /* this is not the first time through */ 946 if (R->old_height) /* this is not the first time through */
877 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); 947 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY);
948
878 rxvt_scr_reset(aR); 949 R->scr_reset();
950
879 if (curr_screen >= 0) { /* this is not the first time through */ 951 if (curr_screen >= 0) { /* this is not the first time through */
880 rxvt_scr_change_screen(aR_ curr_screen); 952 rxvt_scr_change_screen(aR_ curr_screen);
881 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); 953 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0));
882 } 954 }
883 } 955 }
997 return; 1069 return;
998} 1070}
999 1071
1000/* INTPROTO */ 1072/* INTPROTO */
1001void 1073void
1002rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, 1074rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect,
1003 XRectangle * needed_rect) 1075 XRectangle * needed_rect)
1004{ 1076{
1005 int mbh, vtx = 0; 1077 int mbh, vtx = 0;
1006 1078
1007 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) 1079 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right))
1008 vtx = scrollbar_TotalWidth(); 1080 vtx = scrollbar_TotalWidth();
1052rxvt_IMInstantiateCallback(Display * unused 1124rxvt_IMInstantiateCallback(Display * unused
1053 __attribute__ ((unused)), XPointer client_data 1125 __attribute__ ((unused)), XPointer client_data
1054 __attribute__ ((unused)), XPointer call_data 1126 __attribute__ ((unused)), XPointer call_data
1055 __attribute__ ((unused))) 1127 __attribute__ ((unused)))
1056{ 1128{
1057 dR; 1129 dR;
1058 int i, found, had_im; 1130 int i, found, had_im;
1059 const char *p; 1131 const char *p;
1060 char **s; 1132 char **s;
1061 char buf[IMBUFSIZ]; 1133 char buf[IMBUFSIZ];
1062 1134
1063 D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); 1135 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1064 if (R->Input_Context) 1136 if (R->Input_Context)
1065 return; 1137 return;
1066 1138
1067 found = had_im = 0; 1139#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1140 if (R->rs[Rs_imLocale])
1141 setlocale (LC_CTYPE, R->rs[Rs_imLocale]);
1142#endif
1143
1068 p = R->rs[Rs_inputMethod]; 1144 p = R->rs[Rs_inputMethod];
1069 if (p && *p) { 1145 if (p && *p)
1070 had_im = 1; 1146 {
1147 bool found = false;
1148
1071 s = rxvt_splitcommastring(p); 1149 s = rxvt_splitcommastring (p);
1072 for (i = 0; s[i]; i++) { 1150 for (i = 0; s[i]; i++)
1151 {
1073 if (*s[i]) { 1152 if (*s[i])
1153 {
1074 STRCPY(buf, "@im="); 1154 STRCPY (buf, "@im=");
1075 STRNCAT(buf, s[i], IMBUFSIZ - 5); 1155 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1076 if ((p = XSetLocaleModifiers(buf)) != NULL && *p 1156 if ((p = XSetLocaleModifiers (buf)) && *p
1077 && (rxvt_IM_get_IC(aR) == True)) { 1157 && rxvt_IM_get_IC (aR))
1158 {
1078 found = 1; 1159 found = true;
1079 break; 1160 break;
1080 } 1161 }
1081 } 1162 }
1082 } 1163 }
1083 for (i = 0; s[i]; i++) 1164 for (i = 0; s[i]; i++)
1084 free(s[i]); 1165 free(s[i]);
1085 free(s); 1166 free(s);
1086 } 1167
1087 if (found) 1168 if (found)
1088 return; 1169 goto done;
1170 }
1089 1171
1090/* try with XMODIFIERS env. var. */ 1172/* try with XMODIFIERS env. var. */
1091 if ((p = XSetLocaleModifiers("")) != NULL && *p) { 1173 if ((p = XSetLocaleModifiers ("")) && *p
1092 rxvt_IM_get_IC(aR); 1174 && rxvt_IM_get_IC (aR))
1093 return; 1175 goto done;
1094 }
1095 1176
1096/* try with no modifiers base IF the user didn't specify an IM */ 1177/* try with no modifiers base IF the user didn't specify an IM */
1097 if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p 1178 if ((p = XSetLocaleModifiers ("@im=none")) && *p
1098 && rxvt_IM_get_IC(aR) == True) 1179 && rxvt_IM_get_IC (aR) == True)
1099 return; 1180 goto done;
1181
1182done:
1183#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1184 if (R->rs[Rs_imLocale])
1185 setlocale (LC_CTYPE, R->locale);
1186#endif
1100} 1187}
1101 1188
1102/* 1189/*
1103 * Try to open a XIM with the current modifiers, then see if we can 1190 * Try to open a XIM with the current modifiers, then see if we can
1104 * open a suitable preedit type 1191 * open a suitable preedit type

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines