1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: main.C,v 1.7 2003/11/26 10:42:34 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 | |
… | |
… | |
65 | blink_ev (this, &rxvt_term::blink_cb), |
79 | blink_ev (this, &rxvt_term::blink_cb), |
66 | #endif |
80 | #endif |
67 | #ifdef POINTER_BLANK |
81 | #ifdef POINTER_BLANK |
68 | pointer_ev (this, &rxvt_term::pointer_cb), |
82 | pointer_ev (this, &rxvt_term::pointer_cb), |
69 | #endif |
83 | #endif |
70 | 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) |
71 | { |
88 | { |
72 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
89 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
73 | } |
90 | } |
74 | |
91 | |
75 | rxvt_term::~rxvt_term () |
92 | rxvt_term::~rxvt_term () |
76 | { |
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 | |
77 | 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; |
78 | } |
144 | } |
79 | |
145 | |
80 | /*----------------------------------------------------------------------*/ |
146 | /*----------------------------------------------------------------------*/ |
81 | /* rxvt_init() */ |
147 | /* rxvt_init() */ |
82 | /* LIBPROTO */ |
148 | /* LIBPROTO */ |
83 | rxvt_t |
149 | rxvt_t |
84 | rxvt_init(int argc, const char *const *argv) |
150 | rxvt_init (int argc, const char *const *argv) |
85 | { |
151 | { |
86 | SET_R(new rxvt_term); |
152 | SET_R (new rxvt_term); |
87 | dR; |
153 | dR; |
88 | |
154 | |
89 | if (!R->init_vars () || !R->init (argc, argv)) |
155 | if (!R->init_vars () || !R->init (argc, argv)) |
90 | { |
156 | { |
91 | delete R; |
157 | delete R; |
… | |
… | |
93 | } |
159 | } |
94 | |
160 | |
95 | return R; |
161 | return R; |
96 | } |
162 | } |
97 | |
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 | |
98 | bool |
194 | bool |
99 | rxvt_term::init (int argc, const char *const *argv) |
195 | rxvt_term::init (int argc, const char *const *argv) |
100 | { |
196 | { |
101 | dR;//TODO (scrollbar, setidle) |
|
|
102 | |
|
|
103 | /* |
197 | /* |
104 | * Save and then give up any super-user privileges |
198 | * Save and then give up any super-user privileges |
105 | * 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. |
106 | * We should only need to be root in these cases: |
200 | * We should only need to be root in these cases: |
107 | * 1. write utmp entries on some systems |
201 | * 1. write utmp entries on some systems |
108 | * 2. chown tty on some systems |
202 | * 2. chown tty on some systems |
109 | */ |
203 | */ |
110 | rxvt_privileges (this, SAVE); |
204 | rxvt_privileges (this, SAVE); |
111 | rxvt_privileges (this, IGNORE); |
205 | rxvt_privileges (this, IGNORE); |
112 | |
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 | |
113 | rxvt_init_secondary (this); |
214 | init_secondary (); |
114 | |
215 | |
115 | const char **cmd_argv = rxvt_init_resources (this, argc, argv); |
216 | const char **cmd_argv = init_resources (argc, argv); |
116 | |
217 | |
117 | #if (MENUBAR_MAX) |
218 | #if (MENUBAR_MAX) |
118 | rxvt_menubar_read (this, rs[Rs_menu]); |
219 | rxvt_menubar_read (this, rs[Rs_menu]); |
119 | #endif |
220 | #endif |
120 | #ifdef HAVE_SCROLLBARS |
221 | #ifdef HAVE_SCROLLBARS |
121 | if (Options & Opt_scrollBar) |
222 | if (Options & Opt_scrollBar) |
122 | scrollbar_setIdle (); /* set existence for size calculations */ |
223 | scrollBar.setIdle (); /* set existence for size calculations */ |
123 | #endif |
224 | #endif |
124 | |
225 | |
125 | rxvt_Create_Windows (this, argc, argv); |
226 | rxvt_Create_Windows (this, argc, argv); |
126 | |
227 | |
127 | rxvt_init_xlocale (this); |
228 | init_xlocale (); |
128 | |
229 | |
129 | rxvt_scr_reset (this); /* initialize screen */ |
230 | scr_reset (); /* initialize screen */ |
130 | #ifdef RXVT_GRAPHICS |
231 | #ifdef RXVT_GRAPHICS |
131 | rxvt_Gr_reset (this); /* reset graphics */ |
232 | rxvt_Gr_reset (this); /* reset graphics */ |
132 | #endif |
233 | #endif |
133 | |
234 | |
134 | #if 0 |
235 | #if 0 |
135 | #ifdef DEBUG_X |
236 | #ifdef DEBUG_X |
136 | XSynchronize(Xdisplay, True); |
237 | XSynchronize(Xdisplay, True); |
137 | XSetErrorHandler((XErrorHandler) abort); |
|
|
138 | #else |
|
|
139 | XSetErrorHandler((XErrorHandler) rxvt_xerror_handler); |
|
|
140 | #endif |
238 | #endif |
141 | #endif |
239 | #endif |
142 | |
240 | |
143 | #ifdef HAVE_SCROLLBARS |
241 | #ifdef HAVE_SCROLLBARS |
144 | if (Options & Opt_scrollBar) |
242 | if (Options & Opt_scrollBar) |
… | |
… | |
156 | } |
254 | } |
157 | #endif |
255 | #endif |
158 | XMapWindow (Xdisplay, TermWin.vt); |
256 | XMapWindow (Xdisplay, TermWin.vt); |
159 | XMapWindow (Xdisplay, TermWin.parent[0]); |
257 | XMapWindow (Xdisplay, TermWin.parent[0]); |
160 | |
258 | |
161 | rxvt_init_env (this); |
259 | init_env (); |
162 | rxvt_init_command (this, cmd_argv); |
260 | init_command (cmd_argv); |
163 | |
261 | |
164 | x_ev.start (Xfd, EVENT_READ); |
262 | x_ev.start (Xfd, EVENT_READ); |
165 | pty_ev.start (cmd_fd, EVENT_READ); |
263 | pty_ev.start (cmd_fd, EVENT_READ); |
166 | |
264 | |
167 | flush (); |
265 | check_ev.start (); |
|
|
266 | |
|
|
267 | process_x_events (); |
168 | |
268 | |
169 | return true; |
269 | return true; |
170 | } |
270 | } |
171 | |
271 | |
172 | /* ------------------------------------------------------------------------- * |
272 | /* ------------------------------------------------------------------------- * |
… | |
… | |
178 | /* ARGSUSED */ |
278 | /* ARGSUSED */ |
179 | /* EXTPROTO */ |
279 | /* EXTPROTO */ |
180 | RETSIGTYPE |
280 | RETSIGTYPE |
181 | rxvt_Child_signal(int sig __attribute__ ((unused))) |
281 | rxvt_Child_signal(int sig __attribute__ ((unused))) |
182 | { |
282 | { |
183 | dR; |
|
|
184 | int pid, save_errno = errno; |
283 | int pid, save_errno = errno; |
185 | |
|
|
186 | do { |
|
|
187 | errno = 0; |
|
|
188 | } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); |
284 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
|
|
285 | ; |
|
|
286 | errno = save_errno; |
189 | |
287 | |
|
|
288 | #if 0 |
190 | if (pid == R->cmd_pid) |
289 | if (pid == R->cmd_pid) |
191 | exit(EXIT_SUCCESS); |
290 | exit (EXIT_SUCCESS); |
192 | |
291 | #endif |
193 | errno = save_errno; |
|
|
194 | signal(SIGCHLD, rxvt_Child_signal); |
|
|
195 | } |
292 | } |
196 | |
293 | |
197 | /* |
294 | /* |
198 | * Catch a fatal signal and tidy up before quitting |
295 | * Catch a fatal signal and tidy up before quitting |
199 | */ |
296 | */ |
… | |
… | |
213 | /* INTPROTO */ |
310 | /* INTPROTO */ |
214 | int |
311 | int |
215 | rxvt_xerror_handler(const Display * display |
312 | rxvt_xerror_handler(const Display * display |
216 | __attribute__ ((unused)), const XErrorEvent * event) |
313 | __attribute__ ((unused)), const XErrorEvent * event) |
217 | { |
314 | { |
218 | dR; |
315 | dR; |
219 | |
316 | |
220 | if (R->allowedxerror == -1) { |
317 | if (R->allowedxerror == -1) |
221 | R->allowedxerror = event->error_code; |
318 | R->allowedxerror = event->error_code; |
222 | return 0; /* ignored anyway */ |
319 | else |
223 | } |
320 | { |
224 | rxvt_print_error("XError: Request: %d . %d, Error: %d", |
321 | rxvt_print_error("XError: Request: %d . %d, Error: %d", |
225 | event->request_code, event->minor_code, |
322 | event->request_code, event->minor_code, |
226 | event->error_code); |
323 | event->error_code); |
227 | /* XXX: probably should call rxvt_clean_exit() bypassing X routines */ |
324 | |
228 | exit(EXIT_FAILURE); |
325 | R->destroy (); |
229 | /* NOTREACHED */ |
326 | } |
|
|
327 | |
|
|
328 | return 0; |
230 | } |
329 | } |
231 | |
330 | |
232 | /*----------------------------------------------------------------------*/ |
331 | /*----------------------------------------------------------------------*/ |
233 | /* |
332 | /* |
234 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
333 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
235 | * 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 |
236 | */ |
335 | */ |
237 | /* EXTPROTO */ |
336 | /* EXTPROTO */ |
238 | void |
337 | void |
239 | rxvt_clean_exit(void) |
338 | rxvt_clean_exit () |
240 | { |
339 | { |
241 | dR; |
340 | dR; |
242 | |
341 | |
243 | #ifdef DEBUG_SCREEN |
342 | R->destroy (); |
244 | rxvt_scr_release(aR); |
|
|
245 | #endif |
|
|
246 | #ifndef NO_SETOWNER_TTYDEV |
|
|
247 | rxvt_privileged_ttydev(aR_ RESTORE); |
|
|
248 | #endif |
|
|
249 | #ifdef UTMP_SUPPORT |
|
|
250 | rxvt_privileged_utmp(aR_ RESTORE); |
|
|
251 | #endif |
|
|
252 | #ifdef USE_XIM |
|
|
253 | if (R->Input_Context != NULL) { |
|
|
254 | XDestroyIC(R->Input_Context); |
|
|
255 | R->Input_Context = NULL; |
|
|
256 | } |
|
|
257 | #endif |
|
|
258 | } |
343 | } |
259 | |
344 | |
260 | /* ------------------------------------------------------------------------- * |
345 | /* ------------------------------------------------------------------------- * |
261 | * MEMORY ALLOCATION WRAPPERS * |
346 | * MEMORY ALLOCATION WRAPPERS * |
262 | * ------------------------------------------------------------------------- */ |
347 | * ------------------------------------------------------------------------- */ |
… | |
… | |
554 | /*----------------------------------------------------------------------*/ |
639 | /*----------------------------------------------------------------------*/ |
555 | /* |
640 | /* |
556 | * Tell the teletype handler what size the window is. |
641 | * Tell the teletype handler what size the window is. |
557 | * Called after a window size change. |
642 | * Called after a window size change. |
558 | */ |
643 | */ |
559 | /* EXTPROTO */ |
|
|
560 | void |
644 | void |
561 | rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) |
645 | rxvt_term::tt_winch () |
562 | { |
646 | { |
563 | struct winsize ws; |
647 | struct winsize ws; |
564 | |
648 | |
565 | if (fd < 0) |
649 | if (cmd_fd < 0) |
566 | return; |
650 | return; |
|
|
651 | |
567 | ws.ws_col = col; |
652 | ws.ws_col = TermWin.ncol; |
568 | ws.ws_row = row; |
653 | ws.ws_row = TermWin.nrow; |
569 | ws.ws_xpixel = ws.ws_ypixel = 0; |
654 | ws.ws_xpixel = ws.ws_ypixel = 0; |
570 | #ifndef DEBUG_SIZE |
655 | #ifndef DEBUG_SIZE |
571 | (void)ioctl(fd, TIOCSWINSZ, &ws); |
656 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
572 | #else |
657 | #else |
573 | if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { |
658 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
574 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
659 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
575 | } |
|
|
576 | # ifdef SIGWINCH |
660 | # ifdef SIGWINCH |
577 | else if (pid) /* force through to the command */ |
661 | else if (cmd_pid) /* force through to the command */ |
578 | kill(pid, SIGWINCH); |
662 | kill (cmd_pid, SIGWINCH); |
579 | # endif |
663 | # endif |
580 | #endif |
664 | #endif |
581 | } |
665 | } |
582 | |
666 | |
583 | /*----------------------------------------------------------------------*/ |
667 | /*----------------------------------------------------------------------*/ |
… | |
… | |
696 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, |
780 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, |
697 | R->PixColors[Color_bg]); |
781 | R->PixColors[Color_bg]); |
698 | |
782 | |
699 | /* handle Color_BD, scrollbar background, etc. */ |
783 | /* handle Color_BD, scrollbar background, etc. */ |
700 | |
784 | |
701 | rxvt_set_colorfgbg(aR); |
785 | rxvt_set_colorfgbg (aR); |
702 | rxvt_recolour_cursor(aR); |
786 | R->recolour_cursor (); |
703 | /* the only reasonable way to enforce a clean update */ |
787 | /* the only reasonable way to enforce a clean update */ |
704 | rxvt_scr_poweron(aR); |
788 | rxvt_scr_poweron (aR); |
705 | } |
789 | } |
706 | |
790 | |
707 | #else |
791 | #else |
708 | # define rxvt_set_window_color(aR_ idx,color) ((void)0) |
792 | # define rxvt_set_window_color(aR_ idx,color) ((void)0) |
709 | #endif /* XTERM_COLOR_CHANGE */ |
793 | #endif /* XTERM_COLOR_CHANGE */ |
710 | |
794 | |
711 | /* EXTPROTO */ |
|
|
712 | void |
795 | void |
713 | rxvt_recolour_cursor(pR) |
796 | rxvt_term::recolour_cursor () |
714 | { |
797 | { |
715 | rxvt_color xcol[2]; |
|
|
716 | |
|
|
717 | #if TODO |
798 | #if TODO |
|
|
799 | rxvt_color xcol[2]; |
|
|
800 | |
718 | xcol[0] = R->PixColors[Color_pointer]; |
801 | xcol[0] = PixColors[Color_pointer]; |
719 | xcol[1] = R->PixColors[Color_bg]; |
802 | xcol[1] = PixColors[Color_bg]; |
720 | XQueryColors(R->Xdisplay, XCMAP, xcol, 2); |
803 | XQueryColors (Xdisplay, XCMAP, xcol, 2); |
721 | XRecolorCursor(R->Xdisplay, R->TermWin_cursor, &(xcol[0]), &(xcol[1])); |
804 | XRecolorCursor (Xdisplay, TermWin_cursor, &(xcol[0]), &(xcol[1])); |
722 | #endif |
805 | #endif |
723 | } |
806 | } |
724 | |
807 | |
725 | /*----------------------------------------------------------------------*/ |
808 | /*----------------------------------------------------------------------*/ |
726 | /* |
809 | /* |
… | |
… | |
878 | uint16_t old_ncol = R->prev_ncol; |
961 | uint16_t old_ncol = R->prev_ncol; |
879 | |
962 | |
880 | /* scr_reset only works on the primary screen */ |
963 | /* scr_reset only works on the primary screen */ |
881 | if (R->old_height) /* this is not the first time through */ |
964 | if (R->old_height) /* this is not the first time through */ |
882 | curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); |
965 | curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); |
|
|
966 | |
883 | rxvt_scr_reset(aR); |
967 | R->scr_reset(); |
|
|
968 | |
884 | if (curr_screen >= 0) { /* this is not the first time through */ |
969 | if (curr_screen >= 0) { /* this is not the first time through */ |
885 | rxvt_scr_change_screen(aR_ curr_screen); |
970 | rxvt_scr_change_screen(aR_ curr_screen); |
886 | rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); |
971 | rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); |
887 | } |
972 | } |
888 | } |
973 | } |
… | |
… | |
1002 | return; |
1087 | return; |
1003 | } |
1088 | } |
1004 | |
1089 | |
1005 | /* INTPROTO */ |
1090 | /* INTPROTO */ |
1006 | void |
1091 | void |
1007 | rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1092 | rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1008 | XRectangle * needed_rect) |
1093 | XRectangle * needed_rect) |
1009 | { |
1094 | { |
1010 | int mbh, vtx = 0; |
1095 | int mbh, vtx = 0; |
1011 | |
1096 | |
1012 | if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) |
1097 | if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) |
1013 | vtx = scrollbar_TotalWidth(); |
1098 | vtx = scrollbar_TotalWidth(); |
… | |
… | |
1057 | rxvt_IMInstantiateCallback(Display * unused |
1142 | rxvt_IMInstantiateCallback(Display * unused |
1058 | __attribute__ ((unused)), XPointer client_data |
1143 | __attribute__ ((unused)), XPointer client_data |
1059 | __attribute__ ((unused)), XPointer call_data |
1144 | __attribute__ ((unused)), XPointer call_data |
1060 | __attribute__ ((unused))) |
1145 | __attribute__ ((unused))) |
1061 | { |
1146 | { |
1062 | dR; |
1147 | dR; |
1063 | int i, found, had_im; |
1148 | int i, found, had_im; |
1064 | const char *p; |
1149 | const char *p; |
1065 | char **s; |
1150 | char **s; |
1066 | char buf[IMBUFSIZ]; |
1151 | char buf[IMBUFSIZ]; |
1067 | |
1152 | |
1068 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1153 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1069 | if (R->Input_Context) |
1154 | if (R->Input_Context) |
1070 | return; |
1155 | return; |
1071 | |
1156 | |
1072 | 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 | |
1073 | p = R->rs[Rs_inputMethod]; |
1162 | p = R->rs[Rs_inputMethod]; |
1074 | if (p && *p) { |
1163 | if (p && *p) |
1075 | had_im = 1; |
1164 | { |
|
|
1165 | bool found = false; |
|
|
1166 | |
1076 | s = rxvt_splitcommastring(p); |
1167 | s = rxvt_splitcommastring (p); |
1077 | for (i = 0; s[i]; i++) { |
1168 | for (i = 0; s[i]; i++) |
|
|
1169 | { |
1078 | if (*s[i]) { |
1170 | if (*s[i]) |
|
|
1171 | { |
1079 | STRCPY(buf, "@im="); |
1172 | STRCPY (buf, "@im="); |
1080 | STRNCAT(buf, s[i], IMBUFSIZ - 5); |
1173 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1081 | if ((p = XSetLocaleModifiers(buf)) != NULL && *p |
1174 | if ((p = XSetLocaleModifiers (buf)) && *p |
1082 | && (rxvt_IM_get_IC(aR) == True)) { |
1175 | && rxvt_IM_get_IC (aR)) |
|
|
1176 | { |
1083 | found = 1; |
1177 | found = true; |
1084 | break; |
1178 | break; |
1085 | } |
1179 | } |
1086 | } |
1180 | } |
1087 | } |
1181 | } |
1088 | for (i = 0; s[i]; i++) |
1182 | for (i = 0; s[i]; i++) |
1089 | free(s[i]); |
1183 | free(s[i]); |
1090 | free(s); |
1184 | free(s); |
1091 | } |
1185 | |
1092 | if (found) |
1186 | if (found) |
1093 | return; |
1187 | goto done; |
|
|
1188 | } |
1094 | |
1189 | |
1095 | /* try with XMODIFIERS env. var. */ |
1190 | /* try with XMODIFIERS env. var. */ |
1096 | if ((p = XSetLocaleModifiers("")) != NULL && *p) { |
1191 | if ((p = XSetLocaleModifiers ("")) && *p |
1097 | rxvt_IM_get_IC(aR); |
1192 | && rxvt_IM_get_IC (aR)) |
1098 | return; |
1193 | goto done; |
1099 | } |
|
|
1100 | |
1194 | |
1101 | /* 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 */ |
1102 | if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p |
1196 | if ((p = XSetLocaleModifiers ("@im=none")) && *p |
1103 | && rxvt_IM_get_IC(aR) == True) |
1197 | && rxvt_IM_get_IC (aR) == True) |
1104 | 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 |
1105 | } |
1205 | } |
1106 | |
1206 | |
1107 | /* |
1207 | /* |
1108 | * 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 |
1109 | * open a suitable preedit type |
1209 | * open a suitable preedit type |