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.13 by pcg, Wed Dec 17 09:00:35 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.13 2003/12/17 09:00:35 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 scr_release ();
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{
124 203
125 rxvt_Create_Windows (this, argc, argv); 204 rxvt_Create_Windows (this, argc, argv);
126 205
127 rxvt_init_xlocale (this); 206 rxvt_init_xlocale (this);
128 207
129 rxvt_scr_reset (this); /* initialize screen */ 208 scr_reset (); /* initialize screen */
130#ifdef RXVT_GRAPHICS 209#ifdef RXVT_GRAPHICS
131 rxvt_Gr_reset (this); /* reset graphics */ 210 rxvt_Gr_reset (this); /* reset graphics */
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)
161 rxvt_init_env (this); 237 rxvt_init_env (this);
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);
242
243 check_ev.start ();
244
245 process_x_events ();
166 246
167 return true; 247 return true;
168} 248}
169 249
170/* ------------------------------------------------------------------------- * 250/* ------------------------------------------------------------------------- *
176/* ARGSUSED */ 256/* ARGSUSED */
177/* EXTPROTO */ 257/* EXTPROTO */
178RETSIGTYPE 258RETSIGTYPE
179rxvt_Child_signal(int sig __attribute__ ((unused))) 259rxvt_Child_signal(int sig __attribute__ ((unused)))
180{ 260{
181 dR;
182 int pid, save_errno = errno; 261 int pid, save_errno = errno;
183
184 do {
185 errno = 0;
186 } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); 262 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
263 ;
264 errno = save_errno;
187 265
266#if 0
188 if (pid == R->cmd_pid) 267 if (pid == R->cmd_pid)
189 exit(EXIT_SUCCESS); 268 exit (EXIT_SUCCESS);
190 269#endif
191 errno = save_errno;
192 signal(SIGCHLD, rxvt_Child_signal);
193} 270}
194 271
195/* 272/*
196 * Catch a fatal signal and tidy up before quitting 273 * Catch a fatal signal and tidy up before quitting
197 */ 274 */
211/* INTPROTO */ 288/* INTPROTO */
212int 289int
213rxvt_xerror_handler(const Display * display 290rxvt_xerror_handler(const Display * display
214 __attribute__ ((unused)), const XErrorEvent * event) 291 __attribute__ ((unused)), const XErrorEvent * event)
215{ 292{
216 dR; 293 dR;
217 294
218 if (R->allowedxerror == -1) { 295 if (R->allowedxerror == -1)
219 R->allowedxerror = event->error_code; 296 R->allowedxerror = event->error_code;
220 return 0; /* ignored anyway */ 297 else
221 } 298 {
222 rxvt_print_error("XError: Request: %d . %d, Error: %d", 299 rxvt_print_error("XError: Request: %d . %d, Error: %d",
223 event->request_code, event->minor_code, 300 event->request_code, event->minor_code,
224 event->error_code); 301 event->error_code);
225/* XXX: probably should call rxvt_clean_exit() bypassing X routines */ 302
226 exit(EXIT_FAILURE); 303 R->destroy ();
227/* NOTREACHED */ 304 }
305
306 return 0;
228} 307}
229 308
230/*----------------------------------------------------------------------*/ 309/*----------------------------------------------------------------------*/
231/* 310/*
232 * Exit gracefully, clearing the utmp entry and restoring tty attributes 311 * Exit gracefully, clearing the utmp entry and restoring tty attributes
233 * 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
234 */ 313 */
235/* EXTPROTO */ 314/* EXTPROTO */
236void 315void
237rxvt_clean_exit(void) 316rxvt_clean_exit ()
238{ 317{
239 dR; 318 dR;
240 319
241#ifdef DEBUG_SCREEN 320 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} 321}
257 322
258/* ------------------------------------------------------------------------- * 323/* ------------------------------------------------------------------------- *
259 * MEMORY ALLOCATION WRAPPERS * 324 * MEMORY ALLOCATION WRAPPERS *
260 * ------------------------------------------------------------------------- */ 325 * ------------------------------------------------------------------------- */
552/*----------------------------------------------------------------------*/ 617/*----------------------------------------------------------------------*/
553/* 618/*
554 * Tell the teletype handler what size the window is. 619 * Tell the teletype handler what size the window is.
555 * Called after a window size change. 620 * Called after a window size change.
556 */ 621 */
557/* EXTPROTO */
558void 622void
559rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) 623rxvt_term::tt_winch ()
560{ 624{
561 struct winsize ws; 625 struct winsize ws;
562 626
563 if (fd < 0) 627 if (cmd_fd < 0)
564 return; 628 return;
629
565 ws.ws_col = col; 630 ws.ws_col = TermWin.ncol;
566 ws.ws_row = row; 631 ws.ws_row = TermWin.nrow;
567 ws.ws_xpixel = ws.ws_ypixel = 0; 632 ws.ws_xpixel = ws.ws_ypixel = 0;
568#ifndef DEBUG_SIZE 633#ifndef DEBUG_SIZE
569 (void)ioctl(fd, TIOCSWINSZ, &ws); 634 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws);
570#else 635#else
571 if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { 636 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0)
572 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 637 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd));
573 }
574# ifdef SIGWINCH 638# ifdef SIGWINCH
575 else if (pid) /* force through to the command */ 639 else if (cmd_pid) /* force through to the command */
576 kill(pid, SIGWINCH); 640 kill (cmd_pid, SIGWINCH);
577# endif 641# endif
578#endif 642#endif
579} 643}
580 644
581/*----------------------------------------------------------------------*/ 645/*----------------------------------------------------------------------*/
876 uint16_t old_ncol = R->prev_ncol; 940 uint16_t old_ncol = R->prev_ncol;
877 941
878 /* scr_reset only works on the primary screen */ 942 /* scr_reset only works on the primary screen */
879 if (R->old_height) /* this is not the first time through */ 943 if (R->old_height) /* this is not the first time through */
880 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); 944 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY);
945
881 rxvt_scr_reset(aR); 946 R->scr_reset();
947
882 if (curr_screen >= 0) { /* this is not the first time through */ 948 if (curr_screen >= 0) { /* this is not the first time through */
883 rxvt_scr_change_screen(aR_ curr_screen); 949 rxvt_scr_change_screen(aR_ curr_screen);
884 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); 950 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0));
885 } 951 }
886 } 952 }
1000 return; 1066 return;
1001} 1067}
1002 1068
1003/* INTPROTO */ 1069/* INTPROTO */
1004void 1070void
1005rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, 1071rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect,
1006 XRectangle * needed_rect) 1072 XRectangle * needed_rect)
1007{ 1073{
1008 int mbh, vtx = 0; 1074 int mbh, vtx = 0;
1009 1075
1010 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) 1076 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right))
1011 vtx = scrollbar_TotalWidth(); 1077 vtx = scrollbar_TotalWidth();
1055rxvt_IMInstantiateCallback(Display * unused 1121rxvt_IMInstantiateCallback(Display * unused
1056 __attribute__ ((unused)), XPointer client_data 1122 __attribute__ ((unused)), XPointer client_data
1057 __attribute__ ((unused)), XPointer call_data 1123 __attribute__ ((unused)), XPointer call_data
1058 __attribute__ ((unused))) 1124 __attribute__ ((unused)))
1059{ 1125{
1060 dR; 1126 dR;
1061 int i, found, had_im; 1127 int i, found, had_im;
1062 const char *p; 1128 const char *p;
1063 char **s; 1129 char **s;
1064 char buf[IMBUFSIZ]; 1130 char buf[IMBUFSIZ];
1065 1131
1066 D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); 1132 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1067 if (R->Input_Context) 1133 if (R->Input_Context)
1068 return; 1134 return;
1069 1135
1070 found = had_im = 0;
1071 p = R->rs[Rs_inputMethod]; 1136 p = R->rs[Rs_inputMethod];
1072 if (p && *p) { 1137 if (p && *p)
1073 had_im = 1; 1138 {
1139 bool found = false;
1140
1074 s = rxvt_splitcommastring(p); 1141 s = rxvt_splitcommastring (p);
1075 for (i = 0; s[i]; i++) { 1142 for (i = 0; s[i]; i++)
1143 {
1076 if (*s[i]) { 1144 if (*s[i])
1145 {
1077 STRCPY(buf, "@im="); 1146 STRCPY (buf, "@im=");
1078 STRNCAT(buf, s[i], IMBUFSIZ - 5); 1147 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1079 if ((p = XSetLocaleModifiers(buf)) != NULL && *p 1148 if ((p = XSetLocaleModifiers (buf)) && *p
1080 && (rxvt_IM_get_IC(aR) == True)) { 1149 && rxvt_IM_get_IC (aR))
1150 {
1081 found = 1; 1151 found = true;
1082 break; 1152 break;
1083 } 1153 }
1084 } 1154 }
1085 } 1155 }
1086 for (i = 0; s[i]; i++) 1156 for (i = 0; s[i]; i++)
1087 free(s[i]); 1157 free(s[i]);
1088 free(s); 1158 free(s);
1089 } 1159
1090 if (found) 1160 if (found)
1091 return; 1161 return;
1162 }
1092 1163
1093/* try with XMODIFIERS env. var. */ 1164/* try with XMODIFIERS env. var. */
1094 if ((p = XSetLocaleModifiers("")) != NULL && *p) { 1165 if ((p = XSetLocaleModifiers ("")) && *p
1095 rxvt_IM_get_IC(aR); 1166 && rxvt_IM_get_IC (aR))
1096 return; 1167 return;
1097 }
1098 1168
1099/* try with no modifiers base IF the user didn't specify an IM */ 1169/* try with no modifiers base IF the user didn't specify an IM */
1100 if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p 1170 if ((p = XSetLocaleModifiers ("@im=none")) && *p
1101 && rxvt_IM_get_IC(aR) == True) 1171 && rxvt_IM_get_IC (aR) == True)
1102 return; 1172 return;
1103} 1173}
1104 1174
1105/* 1175/*
1106 * Try to open a XIM with the current modifiers, then see if we can 1176 * Try to open a XIM with the current modifiers, then see if we can
1107 * open a suitable preedit type 1177 * open a suitable preedit type

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines