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.4 by pcg, Tue Nov 25 15:25:17 2003 UTC vs.
Revision 1.10 by pcg, Wed Dec 3 23:19:44 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: main.c 2 * File: main.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: main.C,v 1.4 2003/11/25 15:25:17 pcg Exp $ 4 * $Id: main.C,v 1.10 2003/12/03 23:19:44 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
65 blink_ev (this, &rxvt_term::blink_cb),
66#endif
67#ifdef POINTER_BLANK
68 pointer_ev (this, &rxvt_term::pointer_cb),
69#endif
64 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)
65{ 73{
66 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 74 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
67} 75}
68 76
69rxvt_term::~rxvt_term () 77rxvt_term::~rxvt_term ()
70{ 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
71 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;
72} 126}
73 127
74/*----------------------------------------------------------------------*/ 128/*----------------------------------------------------------------------*/
75/* rxvt_init() */ 129/* rxvt_init() */
76/* LIBPROTO */ 130/* LIBPROTO */
77rxvt_t 131rxvt_t
78rxvt_init(int argc, const char *const *argv) 132rxvt_init (int argc, const char *const *argv)
79{ 133{
80 SET_R(new rxvt_term); 134 SET_R (new rxvt_term);
81 dR; 135 dR;
82 136
83 if (!R->init_vars () || !R->init (argc, argv)) 137 if (!R->init_vars () || !R->init (argc, argv))
84 { 138 {
85 delete R; 139 delete R;
86 return NULL; 140 return NULL;
87 } 141 }
88 142
89 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);
90} 174}
91 175
92bool 176bool
93rxvt_term::init (int argc, const char *const *argv) 177rxvt_term::init (int argc, const char *const *argv)
94{ 178{
126#endif 210#endif
127 211
128#if 0 212#if 0
129#ifdef DEBUG_X 213#ifdef DEBUG_X
130 XSynchronize(Xdisplay, True); 214 XSynchronize(Xdisplay, True);
131 XSetErrorHandler((XErrorHandler) abort);
132#else
133 XSetErrorHandler((XErrorHandler) rxvt_xerror_handler);
134#endif 215#endif
135#endif 216#endif
136 217
137#ifdef HAVE_SCROLLBARS 218#ifdef HAVE_SCROLLBARS
138 if (Options & Opt_scrollBar) 219 if (Options & Opt_scrollBar)
155 rxvt_init_env (this); 236 rxvt_init_env (this);
156 rxvt_init_command (this, cmd_argv); 237 rxvt_init_command (this, cmd_argv);
157 238
158 x_ev.start (Xfd, EVENT_READ); 239 x_ev.start (Xfd, EVENT_READ);
159 pty_ev.start (cmd_fd, EVENT_READ); 240 pty_ev.start (cmd_fd, EVENT_READ);
241
242 check_ev.start ();
243
244 process_x_events ();
160 245
161 return true; 246 return true;
162} 247}
163 248
164/* ------------------------------------------------------------------------- * 249/* ------------------------------------------------------------------------- *
170/* ARGSUSED */ 255/* ARGSUSED */
171/* EXTPROTO */ 256/* EXTPROTO */
172RETSIGTYPE 257RETSIGTYPE
173rxvt_Child_signal(int sig __attribute__ ((unused))) 258rxvt_Child_signal(int sig __attribute__ ((unused)))
174{ 259{
175 dR;
176 int pid, save_errno = errno; 260 int pid, save_errno = errno;
177
178 do {
179 errno = 0;
180 } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); 261 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
262 ;
263 errno = save_errno;
181 264
265#if 0
182 if (pid == R->cmd_pid) 266 if (pid == R->cmd_pid)
183 exit(EXIT_SUCCESS); 267 exit (EXIT_SUCCESS);
184 268#endif
185 errno = save_errno;
186 signal(SIGCHLD, rxvt_Child_signal);
187} 269}
188 270
189/* 271/*
190 * Catch a fatal signal and tidy up before quitting 272 * Catch a fatal signal and tidy up before quitting
191 */ 273 */
205/* INTPROTO */ 287/* INTPROTO */
206int 288int
207rxvt_xerror_handler(const Display * display 289rxvt_xerror_handler(const Display * display
208 __attribute__ ((unused)), const XErrorEvent * event) 290 __attribute__ ((unused)), const XErrorEvent * event)
209{ 291{
210 dR; 292 dR;
211 293
212 if (R->allowedxerror == -1) { 294 if (R->allowedxerror == -1)
213 R->allowedxerror = event->error_code; 295 R->allowedxerror = event->error_code;
214 return 0; /* ignored anyway */ 296 else
215 } 297 {
216 rxvt_print_error("XError: Request: %d . %d, Error: %d", 298 rxvt_print_error("XError: Request: %d . %d, Error: %d",
217 event->request_code, event->minor_code, 299 event->request_code, event->minor_code,
218 event->error_code); 300 event->error_code);
219/* XXX: probably should call rxvt_clean_exit() bypassing X routines */ 301
220 exit(EXIT_FAILURE); 302 R->destroy ();
221/* NOTREACHED */ 303 }
304
305 return 0;
222} 306}
223 307
224/*----------------------------------------------------------------------*/ 308/*----------------------------------------------------------------------*/
225/* 309/*
226 * Exit gracefully, clearing the utmp entry and restoring tty attributes 310 * Exit gracefully, clearing the utmp entry and restoring tty attributes
227 * TODO: if debugging, this should free up any known resources if we can 311 * TODO: if debugging, this should free up any known resources if we can
228 */ 312 */
229/* EXTPROTO */ 313/* EXTPROTO */
230void 314void
231rxvt_clean_exit(void) 315rxvt_clean_exit ()
232{ 316{
233 dR; 317 dR;
234 318
235#ifdef DEBUG_SCREEN 319 R->destroy ();
236 rxvt_scr_release(aR);
237#endif
238#ifndef NO_SETOWNER_TTYDEV
239 rxvt_privileged_ttydev(aR_ RESTORE);
240#endif
241#ifdef UTMP_SUPPORT
242 rxvt_privileged_utmp(aR_ RESTORE);
243#endif
244#ifdef USE_XIM
245 if (R->Input_Context != NULL) {
246 XDestroyIC(R->Input_Context);
247 R->Input_Context = NULL;
248 }
249#endif
250} 320}
251 321
252/* ------------------------------------------------------------------------- * 322/* ------------------------------------------------------------------------- *
253 * MEMORY ALLOCATION WRAPPERS * 323 * MEMORY ALLOCATION WRAPPERS *
254 * ------------------------------------------------------------------------- */ 324 * ------------------------------------------------------------------------- */
546/*----------------------------------------------------------------------*/ 616/*----------------------------------------------------------------------*/
547/* 617/*
548 * Tell the teletype handler what size the window is. 618 * Tell the teletype handler what size the window is.
549 * Called after a window size change. 619 * Called after a window size change.
550 */ 620 */
551/* EXTPROTO */
552void 621void
553rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) 622rxvt_term::tt_winch ()
554{ 623{
555 struct winsize ws; 624 struct winsize ws;
556 625
557 if (fd < 0) 626 if (cmd_fd < 0)
558 return; 627 return;
628
559 ws.ws_col = col; 629 ws.ws_col = TermWin.ncol;
560 ws.ws_row = row; 630 ws.ws_row = TermWin.nrow;
561 ws.ws_xpixel = ws.ws_ypixel = 0; 631 ws.ws_xpixel = ws.ws_ypixel = 0;
562#ifndef DEBUG_SIZE 632#ifndef DEBUG_SIZE
563 (void)ioctl(fd, TIOCSWINSZ, &ws); 633 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws);
564#else 634#else
565 if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { 635 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0)
566 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 636 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd));
567 }
568# ifdef SIGWINCH 637# ifdef SIGWINCH
569 else if (pid) /* force through to the command */ 638 else if (cmd_pid) /* force through to the command */
570 kill(pid, SIGWINCH); 639 kill (cmd_pid, SIGWINCH);
571# endif 640# endif
572#endif 641#endif
573} 642}
574 643
575/*----------------------------------------------------------------------*/ 644/*----------------------------------------------------------------------*/
994 return; 1063 return;
995} 1064}
996 1065
997/* INTPROTO */ 1066/* INTPROTO */
998void 1067void
999rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, 1068rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect,
1000 XRectangle * needed_rect) 1069 XRectangle * needed_rect)
1001{ 1070{
1002 int mbh, vtx = 0; 1071 int mbh, vtx = 0;
1003 1072
1004 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) 1073 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right))
1005 vtx = scrollbar_TotalWidth(); 1074 vtx = scrollbar_TotalWidth();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines