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.28 by pcg, Mon Feb 9 22:45:29 2004 UTC vs.
Revision 1.29 by pcg, Wed Feb 11 08:13:45 2004 UTC

93 pointer_ev (this, &rxvt_term::pointer_cb), 93 pointer_ev (this, &rxvt_term::pointer_cb),
94#endif 94#endif
95 check_ev (this, &rxvt_term::check_cb), 95 check_ev (this, &rxvt_term::check_cb),
96 destroy_ev (this, &rxvt_term::destroy_cb), 96 destroy_ev (this, &rxvt_term::destroy_cb),
97 pty_ev (this, &rxvt_term::pty_cb), 97 pty_ev (this, &rxvt_term::pty_cb),
98 incr_ev (this, &rxvt_term::incr_cb) 98 incr_ev (this, &rxvt_term::incr_cb),
99#ifdef USE_XIM
100 im_ev (this, &rxvt_term::im_cb)
101#endif
99{ 102{
100 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 103 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
101} 104}
102 105
103rxvt_term::~rxvt_term () 106rxvt_term::~rxvt_term ()
104{ 107{
108 if (cmd_fd >= 0)
109 close (cmd_fd);
110
105 scr_release (); 111 scr_release ();
106 112
107 free (locale); 113 free (locale);
108 free (codeset); 114 free (codeset);
109 115
111 privileged_ttydev (RESTORE); 117 privileged_ttydev (RESTORE);
112#endif 118#endif
113#ifdef UTMP_SUPPORT 119#ifdef UTMP_SUPPORT
114 privileged_utmp (RESTORE); 120 privileged_utmp (RESTORE);
115#endif 121#endif
116#ifdef USE_XIM
117 if (Input_Context)
118 {
119 XDestroyIC (Input_Context);
120 Input_Context = NULL;
121 }
122#endif
123
124 if (TermWin.parent[0])
125 XDestroyWindow (display->display, TermWin.parent[0]);
126 122
127 // TODO: free pixcolours, colours should become part of rxvt_display 123 // TODO: free pixcolours, colours should become part of rxvt_display
128 124
129 delete PixColors; 125 delete PixColors;
130 126
131 if (cmd_fd >= 0) 127 displays.put (display);
132 close (cmd_fd); 128}
133 129
130void
131rxvt_term::destroy ()
132{
134 if (display) 133 if (display)
135 displays.release (display);
136}
137
138void
139rxvt_term::destroy ()
140{
141 if (display)
142 { 134 {
135 if (TermWin.parent[0])
136 XDestroyWindow (display->display, TermWin.parent[0]);
137
143 termwin_ev.stop (display); 138 termwin_ev.stop (display);
144 vt_ev.stop (display); 139 vt_ev.stop (display);
140
141#ifdef USE_XIM
142 im_destroy ();
143 im_ev.stop (display);
144#endif
145#ifdef HAVE_SCROLLBARS 145#ifdef HAVE_SCROLLBARS
146 scrollbar_ev.stop (display); 146 scrollbar_ev.stop (display);
147#endif 147#endif
148#ifdef MENUBAR 148#ifdef MENUBAR
149 menubar_ev.stop (display); 149 menubar_ev.stop (display);
1057 1057
1058/* -------------------------------------------------------------------- * 1058/* -------------------------------------------------------------------- *
1059 * - X INPUT METHOD ROUTINES - * 1059 * - X INPUT METHOD ROUTINES - *
1060 * -------------------------------------------------------------------- */ 1060 * -------------------------------------------------------------------- */
1061#ifdef USE_XIM 1061#ifdef USE_XIM
1062
1062void 1063void
1063rxvt_term::set_size (XRectangle *size) 1064rxvt_term::im_set_size (XRectangle *size)
1064{ 1065{
1065 size->x = TermWin.int_bwidth; 1066 size->x = TermWin.int_bwidth;
1066 size->y = TermWin.int_bwidth; 1067 size->y = TermWin.int_bwidth;
1067 size->width = Width2Pixel(TermWin.ncol); 1068 size->width = Width2Pixel(TermWin.ncol);
1068 size->height = Height2Pixel(TermWin.nrow); 1069 size->height = Height2Pixel(TermWin.nrow);
1069} 1070}
1070 1071
1071void 1072void
1072rxvt_term::set_color (unsigned long *fg, unsigned long *bg) 1073rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg)
1073{ 1074{
1074 *fg = PixColors[Color_fg]; 1075 *fg = PixColors[Color_fg];
1075 *bg = PixColors[Color_bg]; 1076 *bg = PixColors[Color_bg];
1076} 1077}
1077 1078
1114 || event_type == SelectionNotify 1115 || event_type == SelectionNotify
1115 || event_type == ButtonRelease || event_type == FocusIn) 1116 || event_type == ButtonRelease || event_type == FocusIn)
1116 || !IMisRunning ()) 1117 || !IMisRunning ())
1117 return; 1118 return;
1118 1119
1119 set_position (&spot); 1120 im_set_position (&spot);
1120 1121
1121 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); 1122 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
1122 XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1123 XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1123 XFree(preedit_attr); 1124 XFree(preedit_attr);
1124} 1125}
1125 1126
1126void 1127void
1127rxvt_term::set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, 1128rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect,
1128 XRectangle * needed_rect) 1129 XRectangle * needed_rect)
1129{ 1130{
1130 int mbh, vtx = 0; 1131 int mbh, vtx = 0;
1131 1132
1132 if (scrollbar_visible () && !(Options & Opt_scrollBar_right)) 1133 if (scrollbar_visible () && !(Options & Opt_scrollBar_right))
1133 vtx = scrollbar_TotalWidth(); 1134 vtx = scrollbar_TotalWidth();
1146 1147
1147 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1); 1148 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1);
1148 status_rect->height = Height2Pixel(1); 1149 status_rect->height = Height2Pixel(1);
1149} 1150}
1150 1151
1151/* ARGSUSED */
1152/* EXTPROTO */
1153void 1152void
1154rxvt_IMDestroyCallback(XIM xim __attribute__ ((unused)), XPointer client_data 1153rxvt_term::im_destroy ()
1155 __attribute__ ((unused)), XPointer call_data
1156 __attribute__ ((unused)))
1157{ 1154{
1155 if (Input_Context)
1156 {
1157 XDestroyIC (Input_Context);
1158 GET_R->Input_Context = NULL; 1158 Input_Context = NULL;
1159 /* To avoid Segmentation Fault in C locale: Solaris only? */ 1159 }
1160 if (STRCMP (GET_R->locale, "C")) 1160
1161 XRegisterIMInstantiateCallback(GET_R->display->display, NULL, NULL, NULL, 1161 if (input_method)
1162 rxvt_IMInstantiateCallback, NULL); 1162 {
1163 display->put_xim (input_method);
1164 input_method = 0;
1165 }
1163} 1166}
1164 1167
1165/* 1168/*
1166 * Try to open a XIM with the current modifiers, then see if we can 1169 * Try to open a XIM with the current modifiers, then see if we can
1167 * open a suitable preedit type 1170 * open a suitable preedit type
1168 */ 1171 */
1169bool 1172bool
1170rxvt_term::IM_get_IC () 1173rxvt_term::IM_get_IC (const char *modifiers)
1171{ 1174{
1172 int i, j, found; 1175 int i, j, found;
1173 XIM xim; 1176 XIM xim;
1174 XPoint spot; 1177 XPoint spot;
1175 XRectangle rect, status_rect, needed_rect; 1178 XRectangle rect, status_rect, needed_rect;
1176 unsigned long fg, bg; 1179 unsigned long fg, bg;
1177 const char *p; 1180 const char *p;
1178 char **s; 1181 char **s;
1179 XIMStyles *xim_styles; 1182 XIMStyles *xim_styles;
1180 XVaNestedList preedit_attr, status_attr; 1183 XVaNestedList preedit_attr, status_attr;
1181 XIMCallback ximcallback; 1184
1185 if (!((p = XSetLocaleModifiers (modifiers)) && *p))
1186 return false;
1182 1187
1183 D_MAIN((stderr, "rxvt_IM_get_IC()")); 1188 D_MAIN((stderr, "rxvt_IM_get_IC()"));
1184 xim = XOpenIM (display->display, NULL, NULL, NULL); 1189 input_method = display->get_xim (locale, modifiers);
1185 if (xim == NULL) 1190 if (input_method == NULL)
1186 return False; 1191 return false;
1192
1193 xim = input_method->xim;
1187 1194
1188 xim_styles = NULL; 1195 xim_styles = NULL;
1189 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1196 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1190 || !xim_styles || !xim_styles->count_styles) 1197 || !xim_styles || !xim_styles->count_styles)
1191 { 1198 {
1192 XCloseIM(xim); 1199 display->put_xim (input_method);
1193 return False; 1200 return false;
1194 } 1201 }
1195 1202
1196 p = rs[Rs_preeditType] ? rs[Rs_preeditType] 1203 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root";
1197 : "OverTheSpot,OffTheSpot,Root";
1198 s = rxvt_splitcommastring(p); 1204 s = rxvt_splitcommastring(p);
1199 for (i = found = 0; !found && s[i]; i++) 1205 for (i = found = 0; !found && s[i]; i++)
1200 { 1206 {
1201 if (!STRCMP(s[i], "OverTheSpot")) 1207 if (!STRCMP(s[i], "OverTheSpot"))
1202 input_style = (XIMPreeditPosition | XIMStatusNothing); 1208 input_style = (XIMPreeditPosition | XIMStatusNothing);
1210 { 1216 {
1211 found = 1; 1217 found = 1;
1212 break; 1218 break;
1213 } 1219 }
1214 } 1220 }
1221
1215 for (i = 0; s[i]; i++) 1222 for (i = 0; s[i]; i++)
1216 free(s[i]); 1223 free (s[i]);
1224
1217 free(s); 1225 free (s);
1218 XFree(xim_styles); 1226 XFree (xim_styles);
1219 1227
1220 if (!found) 1228 if (!found)
1221 { 1229 {
1222 XCloseIM(xim); 1230 display->put_xim (input_method);
1223 return False; 1231 return false;
1224 } 1232 }
1225
1226 ximcallback.callback = rxvt_IMDestroyCallback;
1227
1228 /* XXX: not sure why we need this (as well as IC one below) */
1229 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL);
1230 1233
1231 preedit_attr = status_attr = NULL; 1234 preedit_attr = status_attr = NULL;
1232 1235
1233 if (input_style & XIMPreeditPosition) 1236 if (input_style & XIMPreeditPosition)
1234 { 1237 {
1235 set_size (&rect); 1238 im_set_size (&rect);
1236 set_position (&spot); 1239 im_set_position (&spot);
1237 set_color (&fg, &bg); 1240 im_set_color (&fg, &bg);
1238 1241
1239 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1242 preedit_attr = XVaCreateNestedList(0, XNArea, &rect,
1240 XNSpotLocation, &spot, 1243 XNSpotLocation, &spot,
1241 XNForeground, fg, XNBackground, bg, 1244 XNForeground, fg, XNBackground, bg,
1242 //XNFontSet, TermWin.fontset, 1245 //XNFontSet, TermWin.fontset,
1243 NULL); 1246 NULL);
1244 } 1247 }
1245 else if (input_style & XIMPreeditArea) 1248 else if (input_style & XIMPreeditArea)
1246 { 1249 {
1247 set_color (&fg, &bg); 1250 im_set_color (&fg, &bg);
1248 1251
1249 /* 1252 /*
1250 * The necessary width of preedit area is unknown 1253 * The necessary width of preedit area is unknown
1251 * until create input context. 1254 * until create input context.
1252 */ 1255 */
1253 needed_rect.width = 0; 1256 needed_rect.width = 0;
1254 1257
1255 set_preedit_area(&rect, &status_rect, &needed_rect); 1258 im_set_preedit_area (&rect, &status_rect, &needed_rect);
1256 1259
1257 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1260 preedit_attr = XVaCreateNestedList(0, XNArea, &rect,
1258 XNForeground, fg, XNBackground, bg, 1261 XNForeground, fg, XNBackground, bg,
1259 //XNFontSet, TermWin.fontset, 1262 //XNFontSet, TermWin.fontset,
1260 NULL); 1263 NULL);
1261 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, 1264 status_attr = XVaCreateNestedList(0, XNArea, &status_rect,
1262 XNForeground, fg, XNBackground, bg, 1265 XNForeground, fg, XNBackground, bg,
1263 //XNFontSet, TermWin.fontset, 1266 //XNFontSet, TermWin.fontset,
1264 NULL); 1267 NULL);
1265 } 1268 }
1269
1266 Input_Context = XCreateIC(xim, XNInputStyle, input_style, 1270 Input_Context = XCreateIC(xim, XNInputStyle, input_style,
1267 XNClientWindow, TermWin.parent[0], 1271 XNClientWindow, TermWin.parent[0],
1268 XNFocusWindow, TermWin.parent[0], 1272 XNFocusWindow, TermWin.parent[0],
1269 XNDestroyCallback, &ximcallback,
1270 preedit_attr ? XNPreeditAttributes : NULL, 1273 preedit_attr ? XNPreeditAttributes : NULL,
1271 preedit_attr, 1274 preedit_attr,
1272 status_attr ? XNStatusAttributes : NULL, 1275 status_attr ? XNStatusAttributes : NULL,
1273 status_attr, NULL); 1276 status_attr, NULL);
1274 if (preedit_attr) 1277 if (preedit_attr) XFree(preedit_attr);
1275 XFree(preedit_attr); 1278 if (status_attr) XFree(status_attr);
1276 if (status_attr) 1279
1277 XFree(status_attr);
1278 if (Input_Context == NULL) 1280 if (Input_Context == NULL)
1279 { 1281 {
1280 rxvt_print_error("failed to create input context"); 1282 rxvt_print_error("failed to create input context");
1281 XCloseIM(xim); 1283 display->put_xim (input_method);
1282 return False; 1284 return false;
1283 } 1285 }
1286
1284 if (input_style & XIMPreeditArea) 1287 if (input_style & XIMPreeditArea)
1285 IMSetStatusPosition (); 1288 IMSetStatusPosition ();
1289
1286 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); 1290 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection"));
1287 return True; 1291 return true;
1288} 1292}
1289 1293
1290/*
1291 * X manual pages and include files don't match on some systems:
1292 * some think this is an XIDProc and others an XIMProc so we can't
1293 * use the first argument - need to update this to be nice for
1294 * both types via some sort of configure detection
1295 */
1296/* ARGSUSED */
1297/* EXTPROTO */
1298void 1294void
1299rxvt_IMInstantiateCallback(Display * unused 1295rxvt_term::im_cb ()
1300 __attribute__ ((unused)), XPointer client_data
1301 __attribute__ ((unused)), XPointer call_data
1302 __attribute__ ((unused)))
1303{ 1296{
1304 int i, found, had_im; 1297 int i, found, had_im;
1305 const char *p; 1298 const char *p;
1306 char **s; 1299 char **s;
1307 char buf[IMBUFSIZ]; 1300 char buf[IMBUFSIZ];
1308 1301
1302 im_destroy ();
1303
1309 D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); 1304 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1310 if (GET_R->Input_Context) 1305 if (Input_Context)
1311 return; 1306 return;
1312 1307
1313#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1308#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1314 if (GET_R->rs[Rs_imLocale]) 1309 if (rs[Rs_imLocale])
1315 setlocale (LC_CTYPE, GET_R->rs[Rs_imLocale]); 1310 setlocale (LC_CTYPE, rs[Rs_imLocale]);
1316#endif 1311#endif
1317 1312
1318 p = GET_R->rs[Rs_inputMethod]; 1313 p = rs[Rs_inputMethod];
1319 if (p && *p) 1314 if (p && *p)
1320 { 1315 {
1321 bool found = false; 1316 bool found = false;
1322 1317
1323 s = rxvt_splitcommastring (p); 1318 s = rxvt_splitcommastring (p);
1325 { 1320 {
1326 if (*s[i]) 1321 if (*s[i])
1327 { 1322 {
1328 STRCPY (buf, "@im="); 1323 STRCPY (buf, "@im=");
1329 STRNCAT (buf, s[i], IMBUFSIZ - 5); 1324 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1330 if ((p = XSetLocaleModifiers (buf)) && *p && GET_R->IM_get_IC ()) 1325 if (IM_get_IC (buf))
1331 { 1326 {
1332 found = true; 1327 found = true;
1333 break; 1328 break;
1334 } 1329 }
1335 } 1330 }
1341 if (found) 1336 if (found)
1342 goto done; 1337 goto done;
1343 } 1338 }
1344 1339
1345 /* try with XMODIFIERS env. var. */ 1340 /* try with XMODIFIERS env. var. */
1346 if ((p = XSetLocaleModifiers ("")) && *p 1341 if (IM_get_IC (""))
1347 && GET_R->IM_get_IC ())
1348 goto done; 1342 goto done;
1349 1343
1350 /* try with no modifiers base IF the user didn't specify an IM */ 1344 /* try with no modifiers base IF the user didn't specify an IM */
1351 if ((p = XSetLocaleModifiers ("@im=none")) && *p 1345 if (IM_get_IC ("@im=none"))
1352 && GET_R->IM_get_IC () == True)
1353 goto done; 1346 goto done;
1354 1347
1355done: 1348done:
1356#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1349#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1357 if (GET_R->rs[Rs_imLocale]) 1350 if (rs[Rs_imLocale])
1358 setlocale (LC_CTYPE, GET_R->locale); 1351 setlocale (LC_CTYPE, locale);
1359#endif 1352#endif
1360} 1353}
1361 1354
1362void 1355void
1363rxvt_term::IMSetStatusPosition () 1356rxvt_term::IMSetStatusPosition ()
1373 /* Getting the necessary width of preedit area */ 1366 /* Getting the necessary width of preedit area */
1374 status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); 1367 status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL);
1375 XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL); 1368 XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL);
1376 XFree(status_attr); 1369 XFree(status_attr);
1377 1370
1378 set_preedit_area(&preedit_rect, &status_rect, needed_rect); 1371 im_set_preedit_area (&preedit_rect, &status_rect, needed_rect);
1379 1372
1380 preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); 1373 preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL);
1381 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); 1374 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL);
1382 1375
1383 XSetICValues(Input_Context, 1376 XSetICValues(Input_Context,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines