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.7 by pcg, Wed Nov 26 10:42:34 2003 UTC vs.
Revision 1.12 by pcg, Tue Dec 16 23:04:13 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: main.c 2 * File: main.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: main.C,v 1.7 2003/11/26 10:42:34 pcg Exp $ 4 * $Id: main.C,v 1.12 2003/12/16 23:04:13 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>
65 blink_ev (this, &rxvt_term::blink_cb), 65 blink_ev (this, &rxvt_term::blink_cb),
66#endif 66#endif
67#ifdef POINTER_BLANK 67#ifdef POINTER_BLANK
68 pointer_ev (this, &rxvt_term::pointer_cb), 68 pointer_ev (this, &rxvt_term::pointer_cb),
69#endif 69#endif
70 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)
71{ 74{
72 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 75 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
73} 76}
74 77
75rxvt_term::~rxvt_term () 78rxvt_term::~rxvt_term ()
76{ 79{
80 rxvt_scr_release (this);
81
82#ifndef NO_SETOWNER_TTYDEV
83 rxvt_privileged_ttydev (this, RESTORE);
84#endif
85#ifdef UTMP_SUPPORT
86 rxvt_privileged_utmp (this, RESTORE);
87#endif
88#ifdef USE_XIM
89 if (Input_Context != NULL)
90 {
91 XDestroyIC (Input_Context);
92 Input_Context = NULL;
93 }
94#endif
95
96 if (cmd_fd >= 0)
97 close (cmd_fd);
98
99 if (Xfd >= 0)
100 XCloseDisplay (Xdisplay);
101
77 delete PixColors; 102 delete PixColors;
103}
104
105void
106rxvt_term::destroy ()
107{
108 check_ev.stop ();
109 pty_ev.stop ();
110 x_ev.stop ();
111#ifdef CURSOR_BLINK
112 blink_ev.stop ();
113#endif
114#ifdef POINTER_BLANK
115 pointer_ev.stop ();
116#endif
117
118 destroy_ev.start (0);
119}
120
121void
122rxvt_term::destroy_cb (time_watcher &w)
123{
124 SET_R (this);
125
126 delete this;
78} 127}
79 128
80/*----------------------------------------------------------------------*/ 129/*----------------------------------------------------------------------*/
81/* rxvt_init() */ 130/* rxvt_init() */
82/* LIBPROTO */ 131/* LIBPROTO */
83rxvt_t 132rxvt_t
84rxvt_init(int argc, const char *const *argv) 133rxvt_init (int argc, const char *const *argv)
85{ 134{
86 SET_R(new rxvt_term); 135 SET_R (new rxvt_term);
87 dR; 136 dR;
88 137
89 if (!R->init_vars () || !R->init (argc, argv)) 138 if (!R->init_vars () || !R->init (argc, argv))
90 { 139 {
91 delete R; 140 delete R;
92 return NULL; 141 return NULL;
93 } 142 }
94 143
95 return R; 144 return R;
145}
146
147/* EXTPROTO */
148void
149rxvt_init_signals ()
150{
151/* install exit handler for cleanup */
152#if 0
153#ifdef HAVE_ATEXIT
154 atexit(rxvt_clean_exit);
155#else
156#endif
157#endif
158
159 struct sigaction sa;
160
161 sigfillset (&sa.sa_mask);
162 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
163 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
164 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
165 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
166 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
167 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
168 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
169
170/* need to trap SIGURG for SVR4 (Unixware) rlogin */
171/* signal (SIGURG, SIG_DFL); */
172
173 XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
174 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
96} 175}
97 176
98bool 177bool
99rxvt_term::init (int argc, const char *const *argv) 178rxvt_term::init (int argc, const char *const *argv)
100{ 179{
132#endif 211#endif
133 212
134#if 0 213#if 0
135#ifdef DEBUG_X 214#ifdef DEBUG_X
136 XSynchronize(Xdisplay, True); 215 XSynchronize(Xdisplay, True);
137 XSetErrorHandler((XErrorHandler) abort);
138#else
139 XSetErrorHandler((XErrorHandler) rxvt_xerror_handler);
140#endif 216#endif
141#endif 217#endif
142 218
143#ifdef HAVE_SCROLLBARS 219#ifdef HAVE_SCROLLBARS
144 if (Options & Opt_scrollBar) 220 if (Options & Opt_scrollBar)
162 rxvt_init_command (this, cmd_argv); 238 rxvt_init_command (this, cmd_argv);
163 239
164 x_ev.start (Xfd, EVENT_READ); 240 x_ev.start (Xfd, EVENT_READ);
165 pty_ev.start (cmd_fd, EVENT_READ); 241 pty_ev.start (cmd_fd, EVENT_READ);
166 242
167 flush (); 243 check_ev.start ();
244
245 process_x_events ();
168 246
169 return true; 247 return true;
170} 248}
171 249
172/* ------------------------------------------------------------------------- * 250/* ------------------------------------------------------------------------- *
178/* ARGSUSED */ 256/* ARGSUSED */
179/* EXTPROTO */ 257/* EXTPROTO */
180RETSIGTYPE 258RETSIGTYPE
181rxvt_Child_signal(int sig __attribute__ ((unused))) 259rxvt_Child_signal(int sig __attribute__ ((unused)))
182{ 260{
183 dR;
184 int pid, save_errno = errno; 261 int pid, save_errno = errno;
185
186 do {
187 errno = 0;
188 } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); 262 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
263 ;
264 errno = save_errno;
189 265
266#if 0
190 if (pid == R->cmd_pid) 267 if (pid == R->cmd_pid)
191 exit(EXIT_SUCCESS); 268 exit (EXIT_SUCCESS);
192 269#endif
193 errno = save_errno;
194 signal(SIGCHLD, rxvt_Child_signal);
195} 270}
196 271
197/* 272/*
198 * Catch a fatal signal and tidy up before quitting 273 * Catch a fatal signal and tidy up before quitting
199 */ 274 */
213/* INTPROTO */ 288/* INTPROTO */
214int 289int
215rxvt_xerror_handler(const Display * display 290rxvt_xerror_handler(const Display * display
216 __attribute__ ((unused)), const XErrorEvent * event) 291 __attribute__ ((unused)), const XErrorEvent * event)
217{ 292{
218 dR; 293 dR;
219 294
220 if (R->allowedxerror == -1) { 295 if (R->allowedxerror == -1)
221 R->allowedxerror = event->error_code; 296 R->allowedxerror = event->error_code;
222 return 0; /* ignored anyway */ 297 else
223 } 298 {
224 rxvt_print_error("XError: Request: %d . %d, Error: %d", 299 rxvt_print_error("XError: Request: %d . %d, Error: %d",
225 event->request_code, event->minor_code, 300 event->request_code, event->minor_code,
226 event->error_code); 301 event->error_code);
227/* XXX: probably should call rxvt_clean_exit() bypassing X routines */ 302
228 exit(EXIT_FAILURE); 303 R->destroy ();
229/* NOTREACHED */ 304 }
305
306 return 0;
230} 307}
231 308
232/*----------------------------------------------------------------------*/ 309/*----------------------------------------------------------------------*/
233/* 310/*
234 * Exit gracefully, clearing the utmp entry and restoring tty attributes 311 * Exit gracefully, clearing the utmp entry and restoring tty attributes
235 * TODO: if debugging, this should free up any known resources if we can 312 * TODO: if debugging, this should free up any known resources if we can
236 */ 313 */
237/* EXTPROTO */ 314/* EXTPROTO */
238void 315void
239rxvt_clean_exit(void) 316rxvt_clean_exit ()
240{ 317{
241 dR; 318 dR;
242 319
243#ifdef DEBUG_SCREEN 320 R->destroy ();
244 rxvt_scr_release(aR);
245#endif
246#ifndef NO_SETOWNER_TTYDEV
247 rxvt_privileged_ttydev(aR_ RESTORE);
248#endif
249#ifdef UTMP_SUPPORT
250 rxvt_privileged_utmp(aR_ RESTORE);
251#endif
252#ifdef USE_XIM
253 if (R->Input_Context != NULL) {
254 XDestroyIC(R->Input_Context);
255 R->Input_Context = NULL;
256 }
257#endif
258} 321}
259 322
260/* ------------------------------------------------------------------------- * 323/* ------------------------------------------------------------------------- *
261 * MEMORY ALLOCATION WRAPPERS * 324 * MEMORY ALLOCATION WRAPPERS *
262 * ------------------------------------------------------------------------- */ 325 * ------------------------------------------------------------------------- */
554/*----------------------------------------------------------------------*/ 617/*----------------------------------------------------------------------*/
555/* 618/*
556 * Tell the teletype handler what size the window is. 619 * Tell the teletype handler what size the window is.
557 * Called after a window size change. 620 * Called after a window size change.
558 */ 621 */
559/* EXTPROTO */
560void 622void
561rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) 623rxvt_term::tt_winch ()
562{ 624{
563 struct winsize ws; 625 struct winsize ws;
564 626
565 if (fd < 0) 627 if (cmd_fd < 0)
566 return; 628 return;
629
567 ws.ws_col = col; 630 ws.ws_col = TermWin.ncol;
568 ws.ws_row = row; 631 ws.ws_row = TermWin.nrow;
569 ws.ws_xpixel = ws.ws_ypixel = 0; 632 ws.ws_xpixel = ws.ws_ypixel = 0;
570#ifndef DEBUG_SIZE 633#ifndef DEBUG_SIZE
571 (void)ioctl(fd, TIOCSWINSZ, &ws); 634 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws);
572#else 635#else
573 if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { 636 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0)
574 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 637 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd));
575 }
576# ifdef SIGWINCH 638# ifdef SIGWINCH
577 else if (pid) /* force through to the command */ 639 else if (cmd_pid) /* force through to the command */
578 kill(pid, SIGWINCH); 640 kill (cmd_pid, SIGWINCH);
579# endif 641# endif
580#endif 642#endif
581} 643}
582 644
583/*----------------------------------------------------------------------*/ 645/*----------------------------------------------------------------------*/
1002 return; 1064 return;
1003} 1065}
1004 1066
1005/* INTPROTO */ 1067/* INTPROTO */
1006void 1068void
1007rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, 1069rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect,
1008 XRectangle * needed_rect) 1070 XRectangle * needed_rect)
1009{ 1071{
1010 int mbh, vtx = 0; 1072 int mbh, vtx = 0;
1011 1073
1012 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) 1074 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right))
1013 vtx = scrollbar_TotalWidth(); 1075 vtx = scrollbar_TotalWidth();
1057rxvt_IMInstantiateCallback(Display * unused 1119rxvt_IMInstantiateCallback(Display * unused
1058 __attribute__ ((unused)), XPointer client_data 1120 __attribute__ ((unused)), XPointer client_data
1059 __attribute__ ((unused)), XPointer call_data 1121 __attribute__ ((unused)), XPointer call_data
1060 __attribute__ ((unused))) 1122 __attribute__ ((unused)))
1061{ 1123{
1062 dR; 1124 dR;
1063 int i, found, had_im; 1125 int i, found, had_im;
1064 const char *p; 1126 const char *p;
1065 char **s; 1127 char **s;
1066 char buf[IMBUFSIZ]; 1128 char buf[IMBUFSIZ];
1067 1129
1068 D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); 1130 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1069 if (R->Input_Context) 1131 if (R->Input_Context)
1070 return; 1132 return;
1071 1133
1072 found = had_im = 0;
1073 p = R->rs[Rs_inputMethod]; 1134 p = R->rs[Rs_inputMethod];
1074 if (p && *p) { 1135 if (p && *p)
1075 had_im = 1; 1136 {
1137 bool found = false;
1138
1076 s = rxvt_splitcommastring(p); 1139 s = rxvt_splitcommastring (p);
1077 for (i = 0; s[i]; i++) { 1140 for (i = 0; s[i]; i++)
1141 {
1078 if (*s[i]) { 1142 if (*s[i])
1143 {
1079 STRCPY(buf, "@im="); 1144 STRCPY (buf, "@im=");
1080 STRNCAT(buf, s[i], IMBUFSIZ - 5); 1145 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1081 if ((p = XSetLocaleModifiers(buf)) != NULL && *p 1146 if ((p = XSetLocaleModifiers (buf)) && *p
1082 && (rxvt_IM_get_IC(aR) == True)) { 1147 && rxvt_IM_get_IC (aR))
1148 {
1083 found = 1; 1149 found = true;
1084 break; 1150 break;
1085 } 1151 }
1086 } 1152 }
1087 } 1153 }
1088 for (i = 0; s[i]; i++) 1154 for (i = 0; s[i]; i++)
1089 free(s[i]); 1155 free(s[i]);
1090 free(s); 1156 free(s);
1091 } 1157
1092 if (found) 1158 if (found)
1093 return; 1159 return;
1160 }
1094 1161
1095/* try with XMODIFIERS env. var. */ 1162/* try with XMODIFIERS env. var. */
1096 if ((p = XSetLocaleModifiers("")) != NULL && *p) { 1163 if ((p = XSetLocaleModifiers ("")) && *p
1097 rxvt_IM_get_IC(aR); 1164 && rxvt_IM_get_IC (aR))
1098 return; 1165 return;
1099 }
1100 1166
1101/* try with no modifiers base IF the user didn't specify an IM */ 1167/* try with no modifiers base IF the user didn't specify an IM */
1102 if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p 1168 if ((p = XSetLocaleModifiers ("@im=none")) && *p
1103 && rxvt_IM_get_IC(aR) == True) 1169 && rxvt_IM_get_IC (aR) == True)
1104 return; 1170 return;
1105} 1171}
1106 1172
1107/* 1173/*
1108 * Try to open a XIM with the current modifiers, then see if we can 1174 * Try to open a XIM with the current modifiers, then see if we can
1109 * open a suitable preedit type 1175 * open a suitable preedit type

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines