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.7 by pcg, Wed Nov 26 10:42:34 2003 UTC vs.
Revision 1.16 by pcg, Thu Dec 18 07:31:19 2003 UTC

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.16 2003/12/18 07:31:19 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
49static char curlocale[128];
50
51void
52rxvt_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
47void * 61void *
48rxvt_term::operator new (size_t s) 62rxvt_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
75rxvt_term::~rxvt_term () 92rxvt_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
122void
123rxvt_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
138void
139rxvt_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 */
83rxvt_t 149rxvt_t
84rxvt_init(int argc, const char *const *argv) 150rxvt_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 */
165void
166rxvt_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
98bool 194bool
99rxvt_term::init (int argc, const char *const *argv) 195rxvt_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
113 rxvt_init_secondary (this); 207 init_secondary ();
114 208
115 const char **cmd_argv = rxvt_init_resources (this, argc, argv); 209 const char **cmd_argv = init_resources (argc, argv);
210
211 set_locale ("");
116 212
117#if (MENUBAR_MAX) 213#if (MENUBAR_MAX)
118 rxvt_menubar_read (this, rs[Rs_menu]); 214 rxvt_menubar_read (this, rs[Rs_menu]);
119#endif 215#endif
120#ifdef HAVE_SCROLLBARS 216#ifdef HAVE_SCROLLBARS
121 if (Options & Opt_scrollBar) 217 if (Options & Opt_scrollBar)
122 scrollbar_setIdle (); /* set existence for size calculations */ 218 scrollBar.setIdle (); /* set existence for size calculations */
123#endif 219#endif
124 220
125 rxvt_Create_Windows (this, argc, argv); 221 rxvt_Create_Windows (this, argc, argv);
126 222
127 rxvt_init_xlocale (this); 223 init_xlocale ();
128 224
129 rxvt_scr_reset (this); /* initialize screen */ 225 scr_reset (); /* initialize screen */
130#ifdef RXVT_GRAPHICS 226#ifdef RXVT_GRAPHICS
131 rxvt_Gr_reset (this); /* reset graphics */ 227 rxvt_Gr_reset (this); /* reset graphics */
132#endif 228#endif
133 229
134#if 0 230#if 0
135#ifdef DEBUG_X 231#ifdef DEBUG_X
136 XSynchronize(Xdisplay, True); 232 XSynchronize(Xdisplay, True);
137 XSetErrorHandler((XErrorHandler) abort);
138#else
139 XSetErrorHandler((XErrorHandler) rxvt_xerror_handler);
140#endif 233#endif
141#endif 234#endif
142 235
143#ifdef HAVE_SCROLLBARS 236#ifdef HAVE_SCROLLBARS
144 if (Options & Opt_scrollBar) 237 if (Options & Opt_scrollBar)
156 } 249 }
157#endif 250#endif
158 XMapWindow (Xdisplay, TermWin.vt); 251 XMapWindow (Xdisplay, TermWin.vt);
159 XMapWindow (Xdisplay, TermWin.parent[0]); 252 XMapWindow (Xdisplay, TermWin.parent[0]);
160 253
161 rxvt_init_env (this); 254 init_env ();
162 rxvt_init_command (this, cmd_argv); 255 init_command (cmd_argv);
163 256
164 x_ev.start (Xfd, EVENT_READ); 257 x_ev.start (Xfd, EVENT_READ);
165 pty_ev.start (cmd_fd, EVENT_READ); 258 pty_ev.start (cmd_fd, EVENT_READ);
166 259
167 flush (); 260 check_ev.start ();
261
262 process_x_events ();
168 263
169 return true; 264 return true;
170} 265}
171 266
172/* ------------------------------------------------------------------------- * 267/* ------------------------------------------------------------------------- *
178/* ARGSUSED */ 273/* ARGSUSED */
179/* EXTPROTO */ 274/* EXTPROTO */
180RETSIGTYPE 275RETSIGTYPE
181rxvt_Child_signal(int sig __attribute__ ((unused))) 276rxvt_Child_signal(int sig __attribute__ ((unused)))
182{ 277{
183 dR;
184 int pid, save_errno = errno; 278 int pid, save_errno = errno;
185
186 do {
187 errno = 0;
188 } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); 279 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
280 ;
281 errno = save_errno;
189 282
283#if 0
190 if (pid == R->cmd_pid) 284 if (pid == R->cmd_pid)
191 exit(EXIT_SUCCESS); 285 exit (EXIT_SUCCESS);
192 286#endif
193 errno = save_errno;
194 signal(SIGCHLD, rxvt_Child_signal);
195} 287}
196 288
197/* 289/*
198 * Catch a fatal signal and tidy up before quitting 290 * Catch a fatal signal and tidy up before quitting
199 */ 291 */
213/* INTPROTO */ 305/* INTPROTO */
214int 306int
215rxvt_xerror_handler(const Display * display 307rxvt_xerror_handler(const Display * display
216 __attribute__ ((unused)), const XErrorEvent * event) 308 __attribute__ ((unused)), const XErrorEvent * event)
217{ 309{
218 dR; 310 dR;
219 311
220 if (R->allowedxerror == -1) { 312 if (R->allowedxerror == -1)
221 R->allowedxerror = event->error_code; 313 R->allowedxerror = event->error_code;
222 return 0; /* ignored anyway */ 314 else
223 } 315 {
224 rxvt_print_error("XError: Request: %d . %d, Error: %d", 316 rxvt_print_error("XError: Request: %d . %d, Error: %d",
225 event->request_code, event->minor_code, 317 event->request_code, event->minor_code,
226 event->error_code); 318 event->error_code);
227/* XXX: probably should call rxvt_clean_exit() bypassing X routines */ 319
228 exit(EXIT_FAILURE); 320 R->destroy ();
229/* NOTREACHED */ 321 }
322
323 return 0;
230} 324}
231 325
232/*----------------------------------------------------------------------*/ 326/*----------------------------------------------------------------------*/
233/* 327/*
234 * Exit gracefully, clearing the utmp entry and restoring tty attributes 328 * Exit gracefully, clearing the utmp entry and restoring tty attributes
235 * TODO: if debugging, this should free up any known resources if we can 329 * TODO: if debugging, this should free up any known resources if we can
236 */ 330 */
237/* EXTPROTO */ 331/* EXTPROTO */
238void 332void
239rxvt_clean_exit(void) 333rxvt_clean_exit ()
240{ 334{
241 dR; 335 dR;
242 336
243#ifdef DEBUG_SCREEN 337 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} 338}
259 339
260/* ------------------------------------------------------------------------- * 340/* ------------------------------------------------------------------------- *
261 * MEMORY ALLOCATION WRAPPERS * 341 * MEMORY ALLOCATION WRAPPERS *
262 * ------------------------------------------------------------------------- */ 342 * ------------------------------------------------------------------------- */
554/*----------------------------------------------------------------------*/ 634/*----------------------------------------------------------------------*/
555/* 635/*
556 * Tell the teletype handler what size the window is. 636 * Tell the teletype handler what size the window is.
557 * Called after a window size change. 637 * Called after a window size change.
558 */ 638 */
559/* EXTPROTO */
560void 639void
561rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) 640rxvt_term::tt_winch ()
562{ 641{
563 struct winsize ws; 642 struct winsize ws;
564 643
565 if (fd < 0) 644 if (cmd_fd < 0)
566 return; 645 return;
646
567 ws.ws_col = col; 647 ws.ws_col = TermWin.ncol;
568 ws.ws_row = row; 648 ws.ws_row = TermWin.nrow;
569 ws.ws_xpixel = ws.ws_ypixel = 0; 649 ws.ws_xpixel = ws.ws_ypixel = 0;
570#ifndef DEBUG_SIZE 650#ifndef DEBUG_SIZE
571 (void)ioctl(fd, TIOCSWINSZ, &ws); 651 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws);
572#else 652#else
573 if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { 653 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0)
574 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 654 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd));
575 }
576# ifdef SIGWINCH 655# ifdef SIGWINCH
577 else if (pid) /* force through to the command */ 656 else if (cmd_pid) /* force through to the command */
578 kill(pid, SIGWINCH); 657 kill (cmd_pid, SIGWINCH);
579# endif 658# endif
580#endif 659#endif
581} 660}
582 661
583/*----------------------------------------------------------------------*/ 662/*----------------------------------------------------------------------*/
696 XSetWindowBackground(R->Xdisplay, R->TermWin.vt, 775 XSetWindowBackground(R->Xdisplay, R->TermWin.vt,
697 R->PixColors[Color_bg]); 776 R->PixColors[Color_bg]);
698 777
699/* handle Color_BD, scrollbar background, etc. */ 778/* handle Color_BD, scrollbar background, etc. */
700 779
701 rxvt_set_colorfgbg(aR); 780 rxvt_set_colorfgbg (aR);
702 rxvt_recolour_cursor(aR); 781 R->recolour_cursor ();
703/* the only reasonable way to enforce a clean update */ 782/* the only reasonable way to enforce a clean update */
704 rxvt_scr_poweron(aR); 783 rxvt_scr_poweron (aR);
705} 784}
706 785
707#else 786#else
708# define rxvt_set_window_color(aR_ idx,color) ((void)0) 787# define rxvt_set_window_color(aR_ idx,color) ((void)0)
709#endif /* XTERM_COLOR_CHANGE */ 788#endif /* XTERM_COLOR_CHANGE */
710 789
711/* EXTPROTO */
712void 790void
713rxvt_recolour_cursor(pR) 791rxvt_term::recolour_cursor ()
714{ 792{
715 rxvt_color xcol[2];
716
717#if TODO 793#if TODO
794 rxvt_color xcol[2];
795
718 xcol[0] = R->PixColors[Color_pointer]; 796 xcol[0] = PixColors[Color_pointer];
719 xcol[1] = R->PixColors[Color_bg]; 797 xcol[1] = PixColors[Color_bg];
720 XQueryColors(R->Xdisplay, XCMAP, xcol, 2); 798 XQueryColors (Xdisplay, XCMAP, xcol, 2);
721 XRecolorCursor(R->Xdisplay, R->TermWin_cursor, &(xcol[0]), &(xcol[1])); 799 XRecolorCursor (Xdisplay, TermWin_cursor, &(xcol[0]), &(xcol[1]));
722#endif 800#endif
723} 801}
724 802
725/*----------------------------------------------------------------------*/ 803/*----------------------------------------------------------------------*/
726/* 804/*
878 uint16_t old_ncol = R->prev_ncol; 956 uint16_t old_ncol = R->prev_ncol;
879 957
880 /* scr_reset only works on the primary screen */ 958 /* scr_reset only works on the primary screen */
881 if (R->old_height) /* this is not the first time through */ 959 if (R->old_height) /* this is not the first time through */
882 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); 960 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY);
961
883 rxvt_scr_reset(aR); 962 R->scr_reset();
963
884 if (curr_screen >= 0) { /* this is not the first time through */ 964 if (curr_screen >= 0) { /* this is not the first time through */
885 rxvt_scr_change_screen(aR_ curr_screen); 965 rxvt_scr_change_screen(aR_ curr_screen);
886 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); 966 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0));
887 } 967 }
888 } 968 }
988 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); 1068 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
989 XSetICValues(R->Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1069 XSetICValues(R->Input_Context, XNPreeditAttributes, preedit_attr, NULL);
990 XFree(preedit_attr); 1070 XFree(preedit_attr);
991} 1071}
992 1072
993/* EXTPROTO */
994void
995rxvt_setTermFontSet(pR_ int idx)
996{
997 char *string;
998 long length;
999 int success = 0;
1000
1001 if (idx < 0 || idx >= MAX_NFONTS)
1002 return;
1003}
1004
1005/* INTPROTO */ 1073/* INTPROTO */
1006void 1074void
1007rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, 1075rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect,
1008 XRectangle * needed_rect) 1076 XRectangle * needed_rect)
1009{ 1077{
1010 int mbh, vtx = 0; 1078 int mbh, vtx = 0;
1011 1079
1012 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) 1080 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right))
1013 vtx = scrollbar_TotalWidth(); 1081 vtx = scrollbar_TotalWidth();
1044 XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL, 1112 XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL,
1045 rxvt_IMInstantiateCallback, NULL); 1113 rxvt_IMInstantiateCallback, NULL);
1046} 1114}
1047 1115
1048/* 1116/*
1049 * X manual pages and include files don't match on some systems:
1050 * some think this is an XIDProc and others an XIMProc so we can't
1051 * use the first argument - need to update this to be nice for
1052 * both types via some sort of configure detection
1053 */
1054/* ARGSUSED */
1055/* EXTPROTO */
1056void
1057rxvt_IMInstantiateCallback(Display * unused
1058 __attribute__ ((unused)), XPointer client_data
1059 __attribute__ ((unused)), XPointer call_data
1060 __attribute__ ((unused)))
1061{
1062 dR;
1063 int i, found, had_im;
1064 const char *p;
1065 char **s;
1066 char buf[IMBUFSIZ];
1067
1068 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1069 if (R->Input_Context)
1070 return;
1071
1072 found = had_im = 0;
1073 p = R->rs[Rs_inputMethod];
1074 if (p && *p) {
1075 had_im = 1;
1076 s = rxvt_splitcommastring(p);
1077 for (i = 0; s[i]; i++) {
1078 if (*s[i]) {
1079 STRCPY(buf, "@im=");
1080 STRNCAT(buf, s[i], IMBUFSIZ - 5);
1081 if ((p = XSetLocaleModifiers(buf)) != NULL && *p
1082 && (rxvt_IM_get_IC(aR) == True)) {
1083 found = 1;
1084 break;
1085 }
1086 }
1087 }
1088 for (i = 0; s[i]; i++)
1089 free(s[i]);
1090 free(s);
1091 }
1092 if (found)
1093 return;
1094
1095/* try with XMODIFIERS env. var. */
1096 if ((p = XSetLocaleModifiers("")) != NULL && *p) {
1097 rxvt_IM_get_IC(aR);
1098 return;
1099 }
1100
1101/* try with no modifiers base IF the user didn't specify an IM */
1102 if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p
1103 && rxvt_IM_get_IC(aR) == True)
1104 return;
1105}
1106
1107/*
1108 * Try to open a XIM with the current modifiers, then see if we can 1117 * Try to open a XIM with the current modifiers, then see if we can
1109 * open a suitable preedit type 1118 * open a suitable preedit type
1110 */ 1119 */
1111/* INTPROTO */ 1120static Bool
1112Bool
1113rxvt_IM_get_IC(pR) 1121rxvt_IM_get_IC (pR)
1114{ 1122{
1115 int i, j, found; 1123 int i, j, found;
1116 XIM xim; 1124 XIM xim;
1117 XPoint spot; 1125 XPoint spot;
1118 XRectangle rect, status_rect, needed_rect; 1126 XRectangle rect, status_rect, needed_rect;
1122 XIMStyles *xim_styles; 1130 XIMStyles *xim_styles;
1123 XVaNestedList preedit_attr, status_attr; 1131 XVaNestedList preedit_attr, status_attr;
1124 XIMCallback ximcallback; 1132 XIMCallback ximcallback;
1125 1133
1126 D_MAIN((stderr, "rxvt_IM_get_IC()")); 1134 D_MAIN((stderr, "rxvt_IM_get_IC()"));
1127 xim = XOpenIM(R->Xdisplay, NULL, NULL, NULL); 1135 xim = XOpenIM (R->Xdisplay, NULL, NULL, NULL);
1128 if (xim == NULL) 1136 if (xim == NULL)
1129 return False; 1137 return False;
1130 1138
1131 xim_styles = NULL; 1139 xim_styles = NULL;
1132 if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) 1140 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1133 || !xim_styles || !xim_styles->count_styles) { 1141 || !xim_styles || !xim_styles->count_styles) {
1134 XCloseIM(xim); 1142 XCloseIM(xim);
1135 return False; 1143 return False;
1136 } 1144 }
1137 1145
1162 return False; 1170 return False;
1163 } 1171 }
1164 1172
1165 ximcallback.callback = rxvt_IMDestroyCallback; 1173 ximcallback.callback = rxvt_IMDestroyCallback;
1166 1174
1167/* XXX: not sure why we need this (as well as IC one below) */ 1175 /* XXX: not sure why we need this (as well as IC one below) */
1168 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL); 1176 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL);
1169 1177
1170 preedit_attr = status_attr = NULL; 1178 preedit_attr = status_attr = NULL;
1171 1179
1172 if (R->input_style & XIMPreeditPosition) { 1180 if (R->input_style & XIMPreeditPosition) {
1220 rxvt_IMSetStatusPosition(aR); 1228 rxvt_IMSetStatusPosition(aR);
1221 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); 1229 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection"));
1222 return True; 1230 return True;
1223} 1231}
1224 1232
1233/*
1234 * X manual pages and include files don't match on some systems:
1235 * some think this is an XIDProc and others an XIMProc so we can't
1236 * use the first argument - need to update this to be nice for
1237 * both types via some sort of configure detection
1238 */
1239/* ARGSUSED */
1240/* EXTPROTO */
1241void
1242rxvt_IMInstantiateCallback(Display * unused
1243 __attribute__ ((unused)), XPointer client_data
1244 __attribute__ ((unused)), XPointer call_data
1245 __attribute__ ((unused)))
1246{
1247 dR;
1248 int i, found, had_im;
1249 const char *p;
1250 char **s;
1251 char buf[IMBUFSIZ];
1252
1253 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1254 if (R->Input_Context)
1255 return;
1256
1257#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1258 if (R->rs[Rs_imLocale])
1259 setlocale (LC_CTYPE, R->rs[Rs_imLocale]);
1260#endif
1261
1262 p = R->rs[Rs_inputMethod];
1263 if (p && *p)
1264 {
1265 bool found = false;
1266
1267 s = rxvt_splitcommastring (p);
1268 for (i = 0; s[i]; i++)
1269 {
1270 if (*s[i])
1271 {
1272 STRCPY (buf, "@im=");
1273 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1274 if ((p = XSetLocaleModifiers (buf)) && *p
1275 && rxvt_IM_get_IC (aR))
1276 {
1277 found = true;
1278 break;
1279 }
1280 }
1281 }
1282 for (i = 0; s[i]; i++)
1283 free(s[i]);
1284 free(s);
1285
1286 if (found)
1287 goto done;
1288 }
1289
1290/* try with XMODIFIERS env. var. */
1291 if ((p = XSetLocaleModifiers ("")) && *p
1292 && rxvt_IM_get_IC (aR))
1293 goto done;
1294
1295/* try with no modifiers base IF the user didn't specify an IM */
1296 if ((p = XSetLocaleModifiers ("@im=none")) && *p
1297 && rxvt_IM_get_IC (aR) == True)
1298 goto done;
1299
1300done:
1301#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1302 if (R->rs[Rs_imLocale])
1303 setlocale (LC_CTYPE, R->locale);
1304#endif
1305}
1306
1225/* EXTPROTO */ 1307/* EXTPROTO */
1226void 1308void
1227rxvt_IMSetStatusPosition(pR) 1309rxvt_IMSetStatusPosition(pR)
1228{ 1310{
1229 XRectangle preedit_rect, status_rect, *needed_rect; 1311 XRectangle preedit_rect, status_rect, *needed_rect;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines