1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: main.C,v 1.8 2003/11/27 10:12:10 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> |
… | |
… | |
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) |
71 | destroy_ev (this, &rxvt_term::destroy_cb), |
|
|
72 | check_ev (this, &rxvt_term::check_cb) |
72 | { |
73 | { |
73 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
74 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
74 | } |
75 | } |
75 | |
76 | |
76 | rxvt_term::~rxvt_term () |
77 | rxvt_term::~rxvt_term () |
… | |
… | |
101 | } |
102 | } |
102 | |
103 | |
103 | void |
104 | void |
104 | rxvt_term::destroy () |
105 | rxvt_term::destroy () |
105 | { |
106 | { |
|
|
107 | check_ev.stop (); |
106 | pty_ev.stop (); |
108 | pty_ev.stop (); |
107 | x_ev.stop (); |
109 | x_ev.stop (); |
108 | #ifdef CURSOR_BLINK |
110 | #ifdef CURSOR_BLINK |
109 | blink_ev.stop (); |
111 | blink_ev.stop (); |
110 | #endif |
112 | #endif |
… | |
… | |
125 | |
127 | |
126 | /*----------------------------------------------------------------------*/ |
128 | /*----------------------------------------------------------------------*/ |
127 | /* rxvt_init() */ |
129 | /* rxvt_init() */ |
128 | /* LIBPROTO */ |
130 | /* LIBPROTO */ |
129 | rxvt_t |
131 | rxvt_t |
130 | rxvt_init(int argc, const char *const *argv) |
132 | rxvt_init (int argc, const char *const *argv) |
131 | { |
133 | { |
132 | SET_R(new rxvt_term); |
134 | SET_R (new rxvt_term); |
133 | dR; |
135 | dR; |
134 | |
136 | |
135 | if (!R->init_vars () || !R->init (argc, argv)) |
137 | if (!R->init_vars () || !R->init (argc, argv)) |
136 | { |
138 | { |
137 | delete R; |
139 | delete R; |
… | |
… | |
148 | /* install exit handler for cleanup */ |
150 | /* install exit handler for cleanup */ |
149 | #if 0 |
151 | #if 0 |
150 | #ifdef HAVE_ATEXIT |
152 | #ifdef HAVE_ATEXIT |
151 | atexit(rxvt_clean_exit); |
153 | atexit(rxvt_clean_exit); |
152 | #else |
154 | #else |
153 | # ifdef HAVE_ON_EXIT |
|
|
154 | on_exit(rxvt_clean_exit, NULL); /* non-ANSI exit handler */ |
|
|
155 | # endif |
|
|
156 | #endif |
155 | #endif |
157 | #endif |
156 | #endif |
158 | |
157 | |
159 | struct sigaction sa; |
158 | struct sigaction sa; |
160 | |
159 | |
161 | sigfillset (&sa.sa_mask); |
160 | sigfillset (&sa.sa_mask); |
162 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
161 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
163 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGHUP , &sa, 0); //TODO, also: SIGPIPE |
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); |
164 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
165 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
165 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
166 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
166 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
167 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
167 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
168 | |
168 | |
… | |
… | |
237 | rxvt_init_command (this, cmd_argv); |
237 | rxvt_init_command (this, cmd_argv); |
238 | |
238 | |
239 | x_ev.start (Xfd, EVENT_READ); |
239 | x_ev.start (Xfd, EVENT_READ); |
240 | pty_ev.start (cmd_fd, EVENT_READ); |
240 | pty_ev.start (cmd_fd, EVENT_READ); |
241 | |
241 | |
242 | flush (); |
242 | check_ev.start (); |
|
|
243 | |
|
|
244 | process_x_events (); |
243 | |
245 | |
244 | return true; |
246 | return true; |
245 | } |
247 | } |
246 | |
248 | |
247 | /* ------------------------------------------------------------------------- * |
249 | /* ------------------------------------------------------------------------- * |
… | |
… | |
614 | /*----------------------------------------------------------------------*/ |
616 | /*----------------------------------------------------------------------*/ |
615 | /* |
617 | /* |
616 | * Tell the teletype handler what size the window is. |
618 | * Tell the teletype handler what size the window is. |
617 | * Called after a window size change. |
619 | * Called after a window size change. |
618 | */ |
620 | */ |
619 | /* EXTPROTO */ |
|
|
620 | void |
621 | void |
621 | rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) |
622 | rxvt_term::tt_winch () |
622 | { |
623 | { |
623 | struct winsize ws; |
624 | struct winsize ws; |
624 | |
625 | |
625 | if (fd < 0) |
626 | if (cmd_fd < 0) |
626 | return; |
627 | return; |
|
|
628 | |
627 | ws.ws_col = col; |
629 | ws.ws_col = TermWin.ncol; |
628 | ws.ws_row = row; |
630 | ws.ws_row = TermWin.nrow; |
629 | ws.ws_xpixel = ws.ws_ypixel = 0; |
631 | ws.ws_xpixel = ws.ws_ypixel = 0; |
630 | #ifndef DEBUG_SIZE |
632 | #ifndef DEBUG_SIZE |
631 | (void)ioctl(fd, TIOCSWINSZ, &ws); |
633 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
632 | #else |
634 | #else |
633 | if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { |
635 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
634 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
636 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
635 | } |
|
|
636 | # ifdef SIGWINCH |
637 | # ifdef SIGWINCH |
637 | else if (pid) /* force through to the command */ |
638 | else if (cmd_pid) /* force through to the command */ |
638 | kill(pid, SIGWINCH); |
639 | kill (cmd_pid, SIGWINCH); |
639 | # endif |
640 | # endif |
640 | #endif |
641 | #endif |
641 | } |
642 | } |
642 | |
643 | |
643 | /*----------------------------------------------------------------------*/ |
644 | /*----------------------------------------------------------------------*/ |
… | |
… | |
1062 | return; |
1063 | return; |
1063 | } |
1064 | } |
1064 | |
1065 | |
1065 | /* INTPROTO */ |
1066 | /* INTPROTO */ |
1066 | void |
1067 | void |
1067 | rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1068 | rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1068 | XRectangle * needed_rect) |
1069 | XRectangle * needed_rect) |
1069 | { |
1070 | { |
1070 | int mbh, vtx = 0; |
1071 | int mbh, vtx = 0; |
1071 | |
1072 | |
1072 | if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) |
1073 | if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) |
1073 | vtx = scrollbar_TotalWidth(); |
1074 | vtx = scrollbar_TotalWidth(); |