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.15 2003/12/18 05:45:11 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> |
… | |
… | |
42 | |
42 | |
43 | #ifdef HAVE_TERMIOS_H |
43 | #ifdef HAVE_TERMIOS_H |
44 | # include <termios.h> |
44 | # include <termios.h> |
45 | #endif |
45 | #endif |
46 | |
46 | |
|
|
47 | #include <cstring> |
|
|
48 | |
|
|
49 | static char curlocale[128]; |
|
|
50 | |
|
|
51 | void |
|
|
52 | rxvt_set_locale (const char *locale) |
|
|
53 | { |
|
|
54 | if (locale && strncmp (locale, curlocale, 128)) |
|
|
55 | { |
|
|
56 | strncpy (curlocale, locale, 128); |
|
|
57 | setlocale (LC_CTYPE, curlocale); |
|
|
58 | } |
|
|
59 | } |
|
|
60 | |
47 | void * |
61 | void * |
48 | rxvt_term::operator new (size_t s) |
62 | rxvt_term::operator new (size_t s) |
49 | { |
63 | { |
50 | void *p = malloc (s); |
64 | void *p = malloc (s); |
51 | |
65 | |
… | |
… | |
58 | { |
72 | { |
59 | free (p); |
73 | free (p); |
60 | } |
74 | } |
61 | |
75 | |
62 | rxvt_term::rxvt_term () |
76 | rxvt_term::rxvt_term () |
63 | : pty_ev(this, &rxvt_term::pty_cb), |
77 | : pty_ev (this, &rxvt_term::pty_cb), |
|
|
78 | #ifdef CURSOR_BLINK |
|
|
79 | blink_ev (this, &rxvt_term::blink_cb), |
|
|
80 | #endif |
|
|
81 | #ifdef POINTER_BLANK |
|
|
82 | pointer_ev (this, &rxvt_term::pointer_cb), |
|
|
83 | #endif |
64 | x_ev (this, &rxvt_term::x_cb) |
84 | x_ev (this, &rxvt_term::x_cb), |
|
|
85 | destroy_ev (this, &rxvt_term::destroy_cb), |
|
|
86 | check_ev (this, &rxvt_term::check_cb), |
|
|
87 | incr_ev (this, &rxvt_term::incr_cb) |
65 | { |
88 | { |
66 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
89 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
67 | } |
90 | } |
68 | |
91 | |
69 | rxvt_term::~rxvt_term () |
92 | rxvt_term::~rxvt_term () |
70 | { |
93 | { |
|
|
94 | scr_release (); |
|
|
95 | |
|
|
96 | free (locale); |
|
|
97 | free (codeset); |
|
|
98 | |
|
|
99 | #ifndef NO_SETOWNER_TTYDEV |
|
|
100 | rxvt_privileged_ttydev (this, RESTORE); |
|
|
101 | #endif |
|
|
102 | #ifdef UTMP_SUPPORT |
|
|
103 | rxvt_privileged_utmp (this, RESTORE); |
|
|
104 | #endif |
|
|
105 | #ifdef USE_XIM |
|
|
106 | if (Input_Context != NULL) |
|
|
107 | { |
|
|
108 | XDestroyIC (Input_Context); |
|
|
109 | Input_Context = NULL; |
|
|
110 | } |
|
|
111 | #endif |
|
|
112 | |
|
|
113 | if (cmd_fd >= 0) |
|
|
114 | close (cmd_fd); |
|
|
115 | |
|
|
116 | if (Xfd >= 0) |
|
|
117 | XCloseDisplay (Xdisplay); |
|
|
118 | |
71 | delete PixColors; |
119 | delete PixColors; |
|
|
120 | } |
|
|
121 | |
|
|
122 | void |
|
|
123 | rxvt_term::destroy () |
|
|
124 | { |
|
|
125 | check_ev.stop (); |
|
|
126 | pty_ev.stop (); |
|
|
127 | x_ev.stop (); |
|
|
128 | #ifdef CURSOR_BLINK |
|
|
129 | blink_ev.stop (); |
|
|
130 | #endif |
|
|
131 | #ifdef POINTER_BLANK |
|
|
132 | pointer_ev.stop (); |
|
|
133 | #endif |
|
|
134 | |
|
|
135 | destroy_ev.start (0); |
|
|
136 | } |
|
|
137 | |
|
|
138 | void |
|
|
139 | rxvt_term::destroy_cb (time_watcher &w) |
|
|
140 | { |
|
|
141 | SET_R (this); |
|
|
142 | |
|
|
143 | delete this; |
72 | } |
144 | } |
73 | |
145 | |
74 | /*----------------------------------------------------------------------*/ |
146 | /*----------------------------------------------------------------------*/ |
75 | /* rxvt_init() */ |
147 | /* rxvt_init() */ |
76 | /* LIBPROTO */ |
148 | /* LIBPROTO */ |
77 | rxvt_t |
149 | rxvt_t |
78 | rxvt_init(int argc, const char *const *argv) |
150 | rxvt_init (int argc, const char *const *argv) |
79 | { |
151 | { |
80 | SET_R(new rxvt_term); |
152 | SET_R (new rxvt_term); |
81 | dR; |
153 | dR; |
82 | |
154 | |
83 | if (!R->init_vars () || !R->init (argc, argv)) |
155 | if (!R->init_vars () || !R->init (argc, argv)) |
84 | { |
156 | { |
85 | delete R; |
157 | delete R; |
… | |
… | |
87 | } |
159 | } |
88 | |
160 | |
89 | return R; |
161 | return R; |
90 | } |
162 | } |
91 | |
163 | |
|
|
164 | /* EXTPROTO */ |
|
|
165 | void |
|
|
166 | rxvt_init_signals () |
|
|
167 | { |
|
|
168 | /* install exit handler for cleanup */ |
|
|
169 | #if 0 |
|
|
170 | #ifdef HAVE_ATEXIT |
|
|
171 | atexit(rxvt_clean_exit); |
|
|
172 | #else |
|
|
173 | #endif |
|
|
174 | #endif |
|
|
175 | |
|
|
176 | struct sigaction sa; |
|
|
177 | |
|
|
178 | sigfillset (&sa.sa_mask); |
|
|
179 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
180 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
181 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
182 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
183 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
184 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
185 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
186 | |
|
|
187 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
188 | /* signal (SIGURG, SIG_DFL); */ |
|
|
189 | |
|
|
190 | XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
191 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
|
|
192 | } |
|
|
193 | |
92 | bool |
194 | bool |
93 | rxvt_term::init (int argc, const char *const *argv) |
195 | rxvt_term::init (int argc, const char *const *argv) |
94 | { |
196 | { |
95 | dR;//TODO (scrollbar, setidle) |
|
|
96 | |
|
|
97 | /* |
197 | /* |
98 | * Save and then give up any super-user privileges |
198 | * Save and then give up any super-user privileges |
99 | * If we need privileges in any area then we must specifically request it. |
199 | * If we need privileges in any area then we must specifically request it. |
100 | * We should only need to be root in these cases: |
200 | * We should only need to be root in these cases: |
101 | * 1. write utmp entries on some systems |
201 | * 1. write utmp entries on some systems |
102 | * 2. chown tty on some systems |
202 | * 2. chown tty on some systems |
103 | */ |
203 | */ |
104 | rxvt_privileges (this, SAVE); |
204 | rxvt_privileges (this, SAVE); |
105 | rxvt_privileges (this, IGNORE); |
205 | rxvt_privileges (this, IGNORE); |
106 | |
206 | |
|
|
207 | #if HAVE_XSETLOCALE || HAVE_SETLOCALE |
|
|
208 | locale = strdup (setlocale (LC_CTYPE, "")); |
|
|
209 | #endif |
|
|
210 | #if HAVE_NL_LANGINFO |
|
|
211 | codeset = strdup (nl_langinfo (CODESET)); |
|
|
212 | #endif |
|
|
213 | |
107 | rxvt_init_secondary (this); |
214 | init_secondary (); |
108 | |
215 | |
109 | const char **cmd_argv = rxvt_init_resources (this, argc, argv); |
216 | const char **cmd_argv = init_resources (argc, argv); |
110 | |
217 | |
111 | #if (MENUBAR_MAX) |
218 | #if (MENUBAR_MAX) |
112 | rxvt_menubar_read (this, rs[Rs_menu]); |
219 | rxvt_menubar_read (this, rs[Rs_menu]); |
113 | #endif |
220 | #endif |
114 | #ifdef HAVE_SCROLLBARS |
221 | #ifdef HAVE_SCROLLBARS |
115 | if (Options & Opt_scrollBar) |
222 | if (Options & Opt_scrollBar) |
116 | scrollbar_setIdle (); /* set existence for size calculations */ |
223 | scrollBar.setIdle (); /* set existence for size calculations */ |
117 | #endif |
224 | #endif |
118 | |
225 | |
119 | rxvt_Create_Windows (this, argc, argv); |
226 | rxvt_Create_Windows (this, argc, argv); |
120 | |
227 | |
121 | rxvt_init_xlocale (this); |
228 | init_xlocale (); |
122 | |
229 | |
123 | rxvt_scr_reset (this); /* initialize screen */ |
230 | scr_reset (); /* initialize screen */ |
124 | #ifdef RXVT_GRAPHICS |
231 | #ifdef RXVT_GRAPHICS |
125 | rxvt_Gr_reset (this); /* reset graphics */ |
232 | rxvt_Gr_reset (this); /* reset graphics */ |
126 | #endif |
233 | #endif |
127 | |
234 | |
128 | #if 0 |
235 | #if 0 |
129 | #ifdef DEBUG_X |
236 | #ifdef DEBUG_X |
130 | XSynchronize(Xdisplay, True); |
237 | XSynchronize(Xdisplay, True); |
131 | XSetErrorHandler((XErrorHandler) abort); |
|
|
132 | #else |
|
|
133 | XSetErrorHandler((XErrorHandler) rxvt_xerror_handler); |
|
|
134 | #endif |
238 | #endif |
135 | #endif |
239 | #endif |
136 | |
240 | |
137 | #ifdef HAVE_SCROLLBARS |
241 | #ifdef HAVE_SCROLLBARS |
138 | if (Options & Opt_scrollBar) |
242 | if (Options & Opt_scrollBar) |
… | |
… | |
150 | } |
254 | } |
151 | #endif |
255 | #endif |
152 | XMapWindow (Xdisplay, TermWin.vt); |
256 | XMapWindow (Xdisplay, TermWin.vt); |
153 | XMapWindow (Xdisplay, TermWin.parent[0]); |
257 | XMapWindow (Xdisplay, TermWin.parent[0]); |
154 | |
258 | |
155 | rxvt_init_env (this); |
259 | init_env (); |
156 | rxvt_init_command (this, cmd_argv); |
260 | init_command (cmd_argv); |
157 | |
261 | |
158 | x_ev.start (Xfd, EVENT_READ); |
262 | x_ev.start (Xfd, EVENT_READ); |
159 | pty_ev.start (cmd_fd, EVENT_READ); |
263 | pty_ev.start (cmd_fd, EVENT_READ); |
|
|
264 | |
|
|
265 | check_ev.start (); |
|
|
266 | |
|
|
267 | process_x_events (); |
160 | |
268 | |
161 | return true; |
269 | return true; |
162 | } |
270 | } |
163 | |
271 | |
164 | /* ------------------------------------------------------------------------- * |
272 | /* ------------------------------------------------------------------------- * |
… | |
… | |
170 | /* ARGSUSED */ |
278 | /* ARGSUSED */ |
171 | /* EXTPROTO */ |
279 | /* EXTPROTO */ |
172 | RETSIGTYPE |
280 | RETSIGTYPE |
173 | rxvt_Child_signal(int sig __attribute__ ((unused))) |
281 | rxvt_Child_signal(int sig __attribute__ ((unused))) |
174 | { |
282 | { |
175 | dR; |
|
|
176 | int pid, save_errno = errno; |
283 | int pid, save_errno = errno; |
177 | |
|
|
178 | do { |
|
|
179 | errno = 0; |
|
|
180 | } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); |
284 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
|
|
285 | ; |
|
|
286 | errno = save_errno; |
181 | |
287 | |
|
|
288 | #if 0 |
182 | if (pid == R->cmd_pid) |
289 | if (pid == R->cmd_pid) |
183 | exit(EXIT_SUCCESS); |
290 | exit (EXIT_SUCCESS); |
184 | |
291 | #endif |
185 | errno = save_errno; |
|
|
186 | signal(SIGCHLD, rxvt_Child_signal); |
|
|
187 | } |
292 | } |
188 | |
293 | |
189 | /* |
294 | /* |
190 | * Catch a fatal signal and tidy up before quitting |
295 | * Catch a fatal signal and tidy up before quitting |
191 | */ |
296 | */ |
… | |
… | |
205 | /* INTPROTO */ |
310 | /* INTPROTO */ |
206 | int |
311 | int |
207 | rxvt_xerror_handler(const Display * display |
312 | rxvt_xerror_handler(const Display * display |
208 | __attribute__ ((unused)), const XErrorEvent * event) |
313 | __attribute__ ((unused)), const XErrorEvent * event) |
209 | { |
314 | { |
210 | dR; |
315 | dR; |
211 | |
316 | |
212 | if (R->allowedxerror == -1) { |
317 | if (R->allowedxerror == -1) |
213 | R->allowedxerror = event->error_code; |
318 | R->allowedxerror = event->error_code; |
214 | return 0; /* ignored anyway */ |
319 | else |
215 | } |
320 | { |
216 | rxvt_print_error("XError: Request: %d . %d, Error: %d", |
321 | rxvt_print_error("XError: Request: %d . %d, Error: %d", |
217 | event->request_code, event->minor_code, |
322 | event->request_code, event->minor_code, |
218 | event->error_code); |
323 | event->error_code); |
219 | /* XXX: probably should call rxvt_clean_exit() bypassing X routines */ |
324 | |
220 | exit(EXIT_FAILURE); |
325 | R->destroy (); |
221 | /* NOTREACHED */ |
326 | } |
|
|
327 | |
|
|
328 | return 0; |
222 | } |
329 | } |
223 | |
330 | |
224 | /*----------------------------------------------------------------------*/ |
331 | /*----------------------------------------------------------------------*/ |
225 | /* |
332 | /* |
226 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
333 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
227 | * TODO: if debugging, this should free up any known resources if we can |
334 | * TODO: if debugging, this should free up any known resources if we can |
228 | */ |
335 | */ |
229 | /* EXTPROTO */ |
336 | /* EXTPROTO */ |
230 | void |
337 | void |
231 | rxvt_clean_exit(void) |
338 | rxvt_clean_exit () |
232 | { |
339 | { |
233 | dR; |
340 | dR; |
234 | |
341 | |
235 | #ifdef DEBUG_SCREEN |
342 | 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 | } |
343 | } |
251 | |
344 | |
252 | /* ------------------------------------------------------------------------- * |
345 | /* ------------------------------------------------------------------------- * |
253 | * MEMORY ALLOCATION WRAPPERS * |
346 | * MEMORY ALLOCATION WRAPPERS * |
254 | * ------------------------------------------------------------------------- */ |
347 | * ------------------------------------------------------------------------- */ |
… | |
… | |
546 | /*----------------------------------------------------------------------*/ |
639 | /*----------------------------------------------------------------------*/ |
547 | /* |
640 | /* |
548 | * Tell the teletype handler what size the window is. |
641 | * Tell the teletype handler what size the window is. |
549 | * Called after a window size change. |
642 | * Called after a window size change. |
550 | */ |
643 | */ |
551 | /* EXTPROTO */ |
|
|
552 | void |
644 | void |
553 | rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) |
645 | rxvt_term::tt_winch () |
554 | { |
646 | { |
555 | struct winsize ws; |
647 | struct winsize ws; |
556 | |
648 | |
557 | if (fd < 0) |
649 | if (cmd_fd < 0) |
558 | return; |
650 | return; |
|
|
651 | |
559 | ws.ws_col = col; |
652 | ws.ws_col = TermWin.ncol; |
560 | ws.ws_row = row; |
653 | ws.ws_row = TermWin.nrow; |
561 | ws.ws_xpixel = ws.ws_ypixel = 0; |
654 | ws.ws_xpixel = ws.ws_ypixel = 0; |
562 | #ifndef DEBUG_SIZE |
655 | #ifndef DEBUG_SIZE |
563 | (void)ioctl(fd, TIOCSWINSZ, &ws); |
656 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
564 | #else |
657 | #else |
565 | if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { |
658 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
566 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
659 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
567 | } |
|
|
568 | # ifdef SIGWINCH |
660 | # ifdef SIGWINCH |
569 | else if (pid) /* force through to the command */ |
661 | else if (cmd_pid) /* force through to the command */ |
570 | kill(pid, SIGWINCH); |
662 | kill (cmd_pid, SIGWINCH); |
571 | # endif |
663 | # endif |
572 | #endif |
664 | #endif |
573 | } |
665 | } |
574 | |
666 | |
575 | /*----------------------------------------------------------------------*/ |
667 | /*----------------------------------------------------------------------*/ |
… | |
… | |
688 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, |
780 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, |
689 | R->PixColors[Color_bg]); |
781 | R->PixColors[Color_bg]); |
690 | |
782 | |
691 | /* handle Color_BD, scrollbar background, etc. */ |
783 | /* handle Color_BD, scrollbar background, etc. */ |
692 | |
784 | |
693 | rxvt_set_colorfgbg(aR); |
785 | rxvt_set_colorfgbg (aR); |
694 | rxvt_recolour_cursor(aR); |
786 | R->recolour_cursor (); |
695 | /* the only reasonable way to enforce a clean update */ |
787 | /* the only reasonable way to enforce a clean update */ |
696 | rxvt_scr_poweron(aR); |
788 | rxvt_scr_poweron (aR); |
697 | } |
789 | } |
698 | |
790 | |
699 | #else |
791 | #else |
700 | # define rxvt_set_window_color(aR_ idx,color) ((void)0) |
792 | # define rxvt_set_window_color(aR_ idx,color) ((void)0) |
701 | #endif /* XTERM_COLOR_CHANGE */ |
793 | #endif /* XTERM_COLOR_CHANGE */ |
702 | |
794 | |
703 | /* EXTPROTO */ |
|
|
704 | void |
795 | void |
705 | rxvt_recolour_cursor(pR) |
796 | rxvt_term::recolour_cursor () |
706 | { |
797 | { |
707 | rxvt_color xcol[2]; |
|
|
708 | |
|
|
709 | #if TODO |
798 | #if TODO |
|
|
799 | rxvt_color xcol[2]; |
|
|
800 | |
710 | xcol[0] = R->PixColors[Color_pointer]; |
801 | xcol[0] = PixColors[Color_pointer]; |
711 | xcol[1] = R->PixColors[Color_bg]; |
802 | xcol[1] = PixColors[Color_bg]; |
712 | XQueryColors(R->Xdisplay, XCMAP, xcol, 2); |
803 | XQueryColors (Xdisplay, XCMAP, xcol, 2); |
713 | XRecolorCursor(R->Xdisplay, R->TermWin_cursor, &(xcol[0]), &(xcol[1])); |
804 | XRecolorCursor (Xdisplay, TermWin_cursor, &(xcol[0]), &(xcol[1])); |
714 | #endif |
805 | #endif |
715 | } |
806 | } |
716 | |
807 | |
717 | /*----------------------------------------------------------------------*/ |
808 | /*----------------------------------------------------------------------*/ |
718 | /* |
809 | /* |
… | |
… | |
870 | uint16_t old_ncol = R->prev_ncol; |
961 | uint16_t old_ncol = R->prev_ncol; |
871 | |
962 | |
872 | /* scr_reset only works on the primary screen */ |
963 | /* scr_reset only works on the primary screen */ |
873 | if (R->old_height) /* this is not the first time through */ |
964 | if (R->old_height) /* this is not the first time through */ |
874 | curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); |
965 | curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); |
|
|
966 | |
875 | rxvt_scr_reset(aR); |
967 | R->scr_reset(); |
|
|
968 | |
876 | if (curr_screen >= 0) { /* this is not the first time through */ |
969 | if (curr_screen >= 0) { /* this is not the first time through */ |
877 | rxvt_scr_change_screen(aR_ curr_screen); |
970 | rxvt_scr_change_screen(aR_ curr_screen); |
878 | rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); |
971 | rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); |
879 | } |
972 | } |
880 | } |
973 | } |
… | |
… | |
994 | return; |
1087 | return; |
995 | } |
1088 | } |
996 | |
1089 | |
997 | /* INTPROTO */ |
1090 | /* INTPROTO */ |
998 | void |
1091 | void |
999 | rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1092 | rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1000 | XRectangle * needed_rect) |
1093 | XRectangle * needed_rect) |
1001 | { |
1094 | { |
1002 | int mbh, vtx = 0; |
1095 | int mbh, vtx = 0; |
1003 | |
1096 | |
1004 | if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) |
1097 | if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) |
1005 | vtx = scrollbar_TotalWidth(); |
1098 | vtx = scrollbar_TotalWidth(); |
… | |
… | |
1049 | rxvt_IMInstantiateCallback(Display * unused |
1142 | rxvt_IMInstantiateCallback(Display * unused |
1050 | __attribute__ ((unused)), XPointer client_data |
1143 | __attribute__ ((unused)), XPointer client_data |
1051 | __attribute__ ((unused)), XPointer call_data |
1144 | __attribute__ ((unused)), XPointer call_data |
1052 | __attribute__ ((unused))) |
1145 | __attribute__ ((unused))) |
1053 | { |
1146 | { |
1054 | dR; |
1147 | dR; |
1055 | int i, found, had_im; |
1148 | int i, found, had_im; |
1056 | const char *p; |
1149 | const char *p; |
1057 | char **s; |
1150 | char **s; |
1058 | char buf[IMBUFSIZ]; |
1151 | char buf[IMBUFSIZ]; |
1059 | |
1152 | |
1060 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1153 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1061 | if (R->Input_Context) |
1154 | if (R->Input_Context) |
1062 | return; |
1155 | return; |
1063 | |
1156 | |
1064 | found = had_im = 0; |
1157 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1158 | if (R->rs[Rs_imLocale]) |
|
|
1159 | setlocale (LC_CTYPE, R->rs[Rs_imLocale]); |
|
|
1160 | #endif |
|
|
1161 | |
1065 | p = R->rs[Rs_inputMethod]; |
1162 | p = R->rs[Rs_inputMethod]; |
1066 | if (p && *p) { |
1163 | if (p && *p) |
1067 | had_im = 1; |
1164 | { |
|
|
1165 | bool found = false; |
|
|
1166 | |
1068 | s = rxvt_splitcommastring(p); |
1167 | s = rxvt_splitcommastring (p); |
1069 | for (i = 0; s[i]; i++) { |
1168 | for (i = 0; s[i]; i++) |
|
|
1169 | { |
1070 | if (*s[i]) { |
1170 | if (*s[i]) |
|
|
1171 | { |
1071 | STRCPY(buf, "@im="); |
1172 | STRCPY (buf, "@im="); |
1072 | STRNCAT(buf, s[i], IMBUFSIZ - 5); |
1173 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1073 | if ((p = XSetLocaleModifiers(buf)) != NULL && *p |
1174 | if ((p = XSetLocaleModifiers (buf)) && *p |
1074 | && (rxvt_IM_get_IC(aR) == True)) { |
1175 | && rxvt_IM_get_IC (aR)) |
|
|
1176 | { |
1075 | found = 1; |
1177 | found = true; |
1076 | break; |
1178 | break; |
1077 | } |
1179 | } |
1078 | } |
1180 | } |
1079 | } |
1181 | } |
1080 | for (i = 0; s[i]; i++) |
1182 | for (i = 0; s[i]; i++) |
1081 | free(s[i]); |
1183 | free(s[i]); |
1082 | free(s); |
1184 | free(s); |
1083 | } |
1185 | |
1084 | if (found) |
1186 | if (found) |
1085 | return; |
1187 | goto done; |
|
|
1188 | } |
1086 | |
1189 | |
1087 | /* try with XMODIFIERS env. var. */ |
1190 | /* try with XMODIFIERS env. var. */ |
1088 | if ((p = XSetLocaleModifiers("")) != NULL && *p) { |
1191 | if ((p = XSetLocaleModifiers ("")) && *p |
1089 | rxvt_IM_get_IC(aR); |
1192 | && rxvt_IM_get_IC (aR)) |
1090 | return; |
1193 | goto done; |
1091 | } |
|
|
1092 | |
1194 | |
1093 | /* try with no modifiers base IF the user didn't specify an IM */ |
1195 | /* try with no modifiers base IF the user didn't specify an IM */ |
1094 | if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p |
1196 | if ((p = XSetLocaleModifiers ("@im=none")) && *p |
1095 | && rxvt_IM_get_IC(aR) == True) |
1197 | && rxvt_IM_get_IC (aR) == True) |
1096 | return; |
1198 | goto done; |
|
|
1199 | |
|
|
1200 | done: |
|
|
1201 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1202 | if (R->rs[Rs_imLocale]) |
|
|
1203 | setlocale (LC_CTYPE, R->locale); |
|
|
1204 | #endif |
1097 | } |
1205 | } |
1098 | |
1206 | |
1099 | /* |
1207 | /* |
1100 | * Try to open a XIM with the current modifiers, then see if we can |
1208 | * Try to open a XIM with the current modifiers, then see if we can |
1101 | * open a suitable preedit type |
1209 | * open a suitable preedit type |