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.6 by pcg, Tue Nov 25 17:11:33 2003 UTC vs.
Revision 1.9 by pcg, Tue Dec 2 21:49:46 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: main.c 2 * File: main.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: main.C,v 1.6 2003/11/25 17:11:33 pcg Exp $ 4 * $Id: main.C,v 1.9 2003/12/02 21:49:46 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)
71{ 73{
72 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 74 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
73} 75}
74 76
75rxvt_term::~rxvt_term () 77rxvt_term::~rxvt_term ()
76{ 78{
79 rxvt_scr_release (this);
80
81#ifndef NO_SETOWNER_TTYDEV
82 rxvt_privileged_ttydev (this, RESTORE);
83#endif
84#ifdef UTMP_SUPPORT
85 rxvt_privileged_utmp (this, RESTORE);
86#endif
87#ifdef USE_XIM
88 if (Input_Context != NULL)
89 {
90 XDestroyIC (Input_Context);
91 Input_Context = NULL;
92 }
93#endif
94
95 if (cmd_fd >= 0)
96 close (cmd_fd);
97
98 if (Xfd >= 0)
99 XCloseDisplay (Xdisplay);
100
77 delete PixColors; 101 delete PixColors;
102}
103
104void
105rxvt_term::destroy ()
106{
107 check_ev.stop ();
108 pty_ev.stop ();
109 x_ev.stop ();
110#ifdef CURSOR_BLINK
111 blink_ev.stop ();
112#endif
113#ifdef POINTER_BLANK
114 pointer_ev.stop ();
115#endif
116
117 destroy_ev.start (0);
118}
119
120void
121rxvt_term::destroy_cb (time_watcher &w)
122{
123 SET_R (this);
124
125 delete this;
78} 126}
79 127
80/*----------------------------------------------------------------------*/ 128/*----------------------------------------------------------------------*/
81/* rxvt_init() */ 129/* rxvt_init() */
82/* LIBPROTO */ 130/* LIBPROTO */
83rxvt_t 131rxvt_t
84rxvt_init(int argc, const char *const *argv) 132rxvt_init (int argc, const char *const *argv)
85{ 133{
86 SET_R(new rxvt_term); 134 SET_R (new rxvt_term);
87 dR; 135 dR;
88 136
89 if (!R->init_vars () || !R->init (argc, argv)) 137 if (!R->init_vars () || !R->init (argc, argv))
90 { 138 {
91 delete R; 139 delete R;
92 return NULL; 140 return NULL;
93 } 141 }
94 142
95 return R; 143 return R;
144}
145
146/* EXTPROTO */
147void
148rxvt_init_signals ()
149{
150/* install exit handler for cleanup */
151#if 0
152#ifdef HAVE_ATEXIT
153 atexit(rxvt_clean_exit);
154#else
155#endif
156#endif
157
158 struct sigaction sa;
159
160 sigfillset (&sa.sa_mask);
161 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
162 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
163 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
164 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
165 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
166 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
167 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
168
169/* need to trap SIGURG for SVR4 (Unixware) rlogin */
170/* signal (SIGURG, SIG_DFL); */
171
172 XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
173 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
96} 174}
97 175
98bool 176bool
99rxvt_term::init (int argc, const char *const *argv) 177rxvt_term::init (int argc, const char *const *argv)
100{ 178{
132#endif 210#endif
133 211
134#if 0 212#if 0
135#ifdef DEBUG_X 213#ifdef DEBUG_X
136 XSynchronize(Xdisplay, True); 214 XSynchronize(Xdisplay, True);
137 XSetErrorHandler((XErrorHandler) abort);
138#else
139 XSetErrorHandler((XErrorHandler) rxvt_xerror_handler);
140#endif 215#endif
141#endif 216#endif
142 217
143#ifdef HAVE_SCROLLBARS 218#ifdef HAVE_SCROLLBARS
144 if (Options & Opt_scrollBar) 219 if (Options & Opt_scrollBar)
161 rxvt_init_env (this); 236 rxvt_init_env (this);
162 rxvt_init_command (this, cmd_argv); 237 rxvt_init_command (this, cmd_argv);
163 238
164 x_ev.start (Xfd, EVENT_READ); 239 x_ev.start (Xfd, EVENT_READ);
165 pty_ev.start (cmd_fd, EVENT_READ); 240 pty_ev.start (cmd_fd, EVENT_READ);
241
242 check_ev.start ();
166 243
167 return true; 244 return true;
168} 245}
169 246
170/* ------------------------------------------------------------------------- * 247/* ------------------------------------------------------------------------- *
176/* ARGSUSED */ 253/* ARGSUSED */
177/* EXTPROTO */ 254/* EXTPROTO */
178RETSIGTYPE 255RETSIGTYPE
179rxvt_Child_signal(int sig __attribute__ ((unused))) 256rxvt_Child_signal(int sig __attribute__ ((unused)))
180{ 257{
181 dR;
182 int pid, save_errno = errno; 258 int pid, save_errno = errno;
183
184 do {
185 errno = 0;
186 } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); 259 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
260 ;
261 errno = save_errno;
187 262
263#if 0
188 if (pid == R->cmd_pid) 264 if (pid == R->cmd_pid)
189 exit(EXIT_SUCCESS); 265 exit (EXIT_SUCCESS);
190 266#endif
191 errno = save_errno;
192 signal(SIGCHLD, rxvt_Child_signal);
193} 267}
194 268
195/* 269/*
196 * Catch a fatal signal and tidy up before quitting 270 * Catch a fatal signal and tidy up before quitting
197 */ 271 */
211/* INTPROTO */ 285/* INTPROTO */
212int 286int
213rxvt_xerror_handler(const Display * display 287rxvt_xerror_handler(const Display * display
214 __attribute__ ((unused)), const XErrorEvent * event) 288 __attribute__ ((unused)), const XErrorEvent * event)
215{ 289{
216 dR; 290 dR;
217 291
218 if (R->allowedxerror == -1) { 292 if (R->allowedxerror == -1)
219 R->allowedxerror = event->error_code; 293 R->allowedxerror = event->error_code;
220 return 0; /* ignored anyway */ 294 else
221 } 295 {
222 rxvt_print_error("XError: Request: %d . %d, Error: %d", 296 rxvt_print_error("XError: Request: %d . %d, Error: %d",
223 event->request_code, event->minor_code, 297 event->request_code, event->minor_code,
224 event->error_code); 298 event->error_code);
225/* XXX: probably should call rxvt_clean_exit() bypassing X routines */ 299
226 exit(EXIT_FAILURE); 300 R->destroy ();
227/* NOTREACHED */ 301 }
302
303 return 0;
228} 304}
229 305
230/*----------------------------------------------------------------------*/ 306/*----------------------------------------------------------------------*/
231/* 307/*
232 * Exit gracefully, clearing the utmp entry and restoring tty attributes 308 * Exit gracefully, clearing the utmp entry and restoring tty attributes
233 * TODO: if debugging, this should free up any known resources if we can 309 * TODO: if debugging, this should free up any known resources if we can
234 */ 310 */
235/* EXTPROTO */ 311/* EXTPROTO */
236void 312void
237rxvt_clean_exit(void) 313rxvt_clean_exit ()
238{ 314{
239 dR; 315 dR;
240 316
241#ifdef DEBUG_SCREEN 317 R->destroy ();
242 rxvt_scr_release(aR);
243#endif
244#ifndef NO_SETOWNER_TTYDEV
245 rxvt_privileged_ttydev(aR_ RESTORE);
246#endif
247#ifdef UTMP_SUPPORT
248 rxvt_privileged_utmp(aR_ RESTORE);
249#endif
250#ifdef USE_XIM
251 if (R->Input_Context != NULL) {
252 XDestroyIC(R->Input_Context);
253 R->Input_Context = NULL;
254 }
255#endif
256} 318}
257 319
258/* ------------------------------------------------------------------------- * 320/* ------------------------------------------------------------------------- *
259 * MEMORY ALLOCATION WRAPPERS * 321 * MEMORY ALLOCATION WRAPPERS *
260 * ------------------------------------------------------------------------- */ 322 * ------------------------------------------------------------------------- */
552/*----------------------------------------------------------------------*/ 614/*----------------------------------------------------------------------*/
553/* 615/*
554 * Tell the teletype handler what size the window is. 616 * Tell the teletype handler what size the window is.
555 * Called after a window size change. 617 * Called after a window size change.
556 */ 618 */
557/* EXTPROTO */
558void 619void
559rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) 620rxvt_term::tt_winch ()
560{ 621{
561 struct winsize ws; 622 struct winsize ws;
562 623
563 if (fd < 0) 624 if (cmd_fd < 0)
564 return; 625 return;
626
565 ws.ws_col = col; 627 ws.ws_col = TermWin.ncol;
566 ws.ws_row = row; 628 ws.ws_row = TermWin.nrow;
567 ws.ws_xpixel = ws.ws_ypixel = 0; 629 ws.ws_xpixel = ws.ws_ypixel = 0;
568#ifndef DEBUG_SIZE 630#ifndef DEBUG_SIZE
569 (void)ioctl(fd, TIOCSWINSZ, &ws); 631 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws);
570#else 632#else
571 if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { 633 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0)
572 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 634 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd));
573 }
574# ifdef SIGWINCH 635# ifdef SIGWINCH
575 else if (pid) /* force through to the command */ 636 else if (cmd_pid) /* force through to the command */
576 kill(pid, SIGWINCH); 637 kill (cmd_pid, SIGWINCH);
577# endif 638# endif
578#endif 639#endif
579} 640}
580 641
581/*----------------------------------------------------------------------*/ 642/*----------------------------------------------------------------------*/
1000 return; 1061 return;
1001} 1062}
1002 1063
1003/* INTPROTO */ 1064/* INTPROTO */
1004void 1065void
1005rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, 1066rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect,
1006 XRectangle * needed_rect) 1067 XRectangle * needed_rect)
1007{ 1068{
1008 int mbh, vtx = 0; 1069 int mbh, vtx = 0;
1009 1070
1010 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) 1071 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right))
1011 vtx = scrollbar_TotalWidth(); 1072 vtx = scrollbar_TotalWidth();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines