1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: main.C,v 1.15 2003/12/18 05:45:11 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> |
… | |
… | |
49 | static char curlocale[128]; |
49 | static char curlocale[128]; |
50 | |
50 | |
51 | void |
51 | void |
52 | rxvt_set_locale (const char *locale) |
52 | rxvt_set_locale (const char *locale) |
53 | { |
53 | { |
54 | if (locale && strncmp (locale, curlocale, 128)) |
54 | if (locale && STRNCMP (locale, curlocale, 128)) |
55 | { |
55 | { |
56 | strncpy (curlocale, locale, 128); |
56 | STRNCPY (curlocale, locale, 128); |
57 | setlocale (LC_CTYPE, curlocale); |
57 | setlocale (LC_CTYPE, curlocale); |
58 | } |
58 | } |
59 | } |
59 | } |
60 | |
60 | |
61 | void * |
61 | void * |
… | |
… | |
202 | * 2. chown tty on some systems |
202 | * 2. chown tty on some systems |
203 | */ |
203 | */ |
204 | rxvt_privileges (this, SAVE); |
204 | rxvt_privileges (this, SAVE); |
205 | rxvt_privileges (this, IGNORE); |
205 | rxvt_privileges (this, IGNORE); |
206 | |
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 | |
|
|
214 | init_secondary (); |
207 | init_secondary (); |
215 | |
208 | |
216 | const char **cmd_argv = init_resources (argc, argv); |
209 | const char **cmd_argv = init_resources (argc, argv); |
|
|
210 | |
|
|
211 | set_locale (""); |
217 | |
212 | |
218 | #if (MENUBAR_MAX) |
213 | #if (MENUBAR_MAX) |
219 | rxvt_menubar_read (this, rs[Rs_menu]); |
214 | rxvt_menubar_read (this, rs[Rs_menu]); |
220 | #endif |
215 | #endif |
221 | #ifdef HAVE_SCROLLBARS |
216 | #ifdef HAVE_SCROLLBARS |
… | |
… | |
1073 | preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); |
1068 | preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); |
1074 | XSetICValues(R->Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1069 | XSetICValues(R->Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1075 | XFree(preedit_attr); |
1070 | XFree(preedit_attr); |
1076 | } |
1071 | } |
1077 | |
1072 | |
1078 | /* EXTPROTO */ |
|
|
1079 | void |
|
|
1080 | rxvt_setTermFontSet(pR_ int idx) |
|
|
1081 | { |
|
|
1082 | char *string; |
|
|
1083 | long length; |
|
|
1084 | int success = 0; |
|
|
1085 | |
|
|
1086 | if (idx < 0 || idx >= MAX_NFONTS) |
|
|
1087 | return; |
|
|
1088 | } |
|
|
1089 | |
|
|
1090 | /* INTPROTO */ |
1073 | /* INTPROTO */ |
1091 | void |
1074 | void |
1092 | rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1075 | rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1093 | XRectangle * needed_rect) |
1076 | XRectangle * needed_rect) |
1094 | { |
1077 | { |
… | |
… | |
1126 | R->Input_Context = NULL; |
1109 | R->Input_Context = NULL; |
1127 | /* To avoid Segmentation Fault in C locale: Solaris only? */ |
1110 | /* To avoid Segmentation Fault in C locale: Solaris only? */ |
1128 | if (STRCMP(R->locale, "C")) |
1111 | if (STRCMP(R->locale, "C")) |
1129 | XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL, |
1112 | XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL, |
1130 | rxvt_IMInstantiateCallback, NULL); |
1113 | rxvt_IMInstantiateCallback, NULL); |
|
|
1114 | } |
|
|
1115 | |
|
|
1116 | /* |
|
|
1117 | * Try to open a XIM with the current modifiers, then see if we can |
|
|
1118 | * open a suitable preedit type |
|
|
1119 | */ |
|
|
1120 | static Bool |
|
|
1121 | rxvt_IM_get_IC (pR) |
|
|
1122 | { |
|
|
1123 | int i, j, found; |
|
|
1124 | XIM xim; |
|
|
1125 | XPoint spot; |
|
|
1126 | XRectangle rect, status_rect, needed_rect; |
|
|
1127 | unsigned long fg, bg; |
|
|
1128 | const char *p; |
|
|
1129 | char **s; |
|
|
1130 | XIMStyles *xim_styles; |
|
|
1131 | XVaNestedList preedit_attr, status_attr; |
|
|
1132 | XIMCallback ximcallback; |
|
|
1133 | |
|
|
1134 | D_MAIN((stderr, "rxvt_IM_get_IC()")); |
|
|
1135 | xim = XOpenIM (R->Xdisplay, NULL, NULL, NULL); |
|
|
1136 | if (xim == NULL) |
|
|
1137 | return False; |
|
|
1138 | |
|
|
1139 | xim_styles = NULL; |
|
|
1140 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
|
|
1141 | || !xim_styles || !xim_styles->count_styles) { |
|
|
1142 | XCloseIM(xim); |
|
|
1143 | return False; |
|
|
1144 | } |
|
|
1145 | |
|
|
1146 | p = R->rs[Rs_preeditType] ? R->rs[Rs_preeditType] |
|
|
1147 | : "OverTheSpot,OffTheSpot,Root"; |
|
|
1148 | s = rxvt_splitcommastring(p); |
|
|
1149 | for (i = found = 0; !found && s[i]; i++) { |
|
|
1150 | if (!STRCMP(s[i], "OverTheSpot")) |
|
|
1151 | R->input_style = (XIMPreeditPosition | XIMStatusNothing); |
|
|
1152 | else if (!STRCMP(s[i], "OffTheSpot")) |
|
|
1153 | R->input_style = (XIMPreeditArea | XIMStatusArea); |
|
|
1154 | else if (!STRCMP(s[i], "Root")) |
|
|
1155 | R->input_style = (XIMPreeditNothing | XIMStatusNothing); |
|
|
1156 | |
|
|
1157 | for (j = 0; j < xim_styles->count_styles; j++) |
|
|
1158 | if (R->input_style == xim_styles->supported_styles[j]) { |
|
|
1159 | found = 1; |
|
|
1160 | break; |
|
|
1161 | } |
|
|
1162 | } |
|
|
1163 | for (i = 0; s[i]; i++) |
|
|
1164 | free(s[i]); |
|
|
1165 | free(s); |
|
|
1166 | XFree(xim_styles); |
|
|
1167 | |
|
|
1168 | if (!found) { |
|
|
1169 | XCloseIM(xim); |
|
|
1170 | return False; |
|
|
1171 | } |
|
|
1172 | |
|
|
1173 | ximcallback.callback = rxvt_IMDestroyCallback; |
|
|
1174 | |
|
|
1175 | /* XXX: not sure why we need this (as well as IC one below) */ |
|
|
1176 | XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL); |
|
|
1177 | |
|
|
1178 | preedit_attr = status_attr = NULL; |
|
|
1179 | |
|
|
1180 | if (R->input_style & XIMPreeditPosition) { |
|
|
1181 | rxvt_setSize(aR_ & rect); |
|
|
1182 | rxvt_setPosition(aR_ & spot); |
|
|
1183 | rxvt_setColor(aR_ & fg, &bg); |
|
|
1184 | |
|
|
1185 | preedit_attr = XVaCreateNestedList(0, XNArea, &rect, |
|
|
1186 | XNSpotLocation, &spot, |
|
|
1187 | XNForeground, fg, XNBackground, bg, |
|
|
1188 | //XNFontSet, R->TermWin.fontset, |
|
|
1189 | NULL); |
|
|
1190 | } else if (R->input_style & XIMPreeditArea) { |
|
|
1191 | rxvt_setColor(aR_ & fg, &bg); |
|
|
1192 | |
|
|
1193 | /* |
|
|
1194 | * The necessary width of preedit area is unknown |
|
|
1195 | * until create input context. |
|
|
1196 | */ |
|
|
1197 | needed_rect.width = 0; |
|
|
1198 | |
|
|
1199 | rxvt_setPreeditArea(aR_ & rect, &status_rect, &needed_rect); |
|
|
1200 | |
|
|
1201 | preedit_attr = XVaCreateNestedList(0, XNArea, &rect, |
|
|
1202 | XNForeground, fg, XNBackground, bg, |
|
|
1203 | //XNFontSet, R->TermWin.fontset, |
|
|
1204 | NULL); |
|
|
1205 | status_attr = XVaCreateNestedList(0, XNArea, &status_rect, |
|
|
1206 | XNForeground, fg, XNBackground, bg, |
|
|
1207 | //XNFontSet, R->TermWin.fontset, |
|
|
1208 | NULL); |
|
|
1209 | } |
|
|
1210 | R->Input_Context = XCreateIC(xim, XNInputStyle, R->input_style, |
|
|
1211 | XNClientWindow, R->TermWin.parent[0], |
|
|
1212 | XNFocusWindow, R->TermWin.parent[0], |
|
|
1213 | XNDestroyCallback, &ximcallback, |
|
|
1214 | preedit_attr ? XNPreeditAttributes : NULL, |
|
|
1215 | preedit_attr, |
|
|
1216 | status_attr ? XNStatusAttributes : NULL, |
|
|
1217 | status_attr, NULL); |
|
|
1218 | if (preedit_attr) |
|
|
1219 | XFree(preedit_attr); |
|
|
1220 | if (status_attr) |
|
|
1221 | XFree(status_attr); |
|
|
1222 | if (R->Input_Context == NULL) { |
|
|
1223 | rxvt_print_error("failed to create input context"); |
|
|
1224 | XCloseIM(xim); |
|
|
1225 | return False; |
|
|
1226 | } |
|
|
1227 | if (R->input_style & XIMPreeditArea) |
|
|
1228 | rxvt_IMSetStatusPosition(aR); |
|
|
1229 | D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); |
|
|
1230 | return True; |
1131 | } |
1231 | } |
1132 | |
1232 | |
1133 | /* |
1233 | /* |
1134 | * X manual pages and include files don't match on some systems: |
1234 | * X manual pages and include files don't match on some systems: |
1135 | * some think this is an XIDProc and others an XIMProc so we can't |
1235 | * some think this is an XIDProc and others an XIMProc so we can't |
… | |
… | |
1202 | if (R->rs[Rs_imLocale]) |
1302 | if (R->rs[Rs_imLocale]) |
1203 | setlocale (LC_CTYPE, R->locale); |
1303 | setlocale (LC_CTYPE, R->locale); |
1204 | #endif |
1304 | #endif |
1205 | } |
1305 | } |
1206 | |
1306 | |
1207 | /* |
|
|
1208 | * Try to open a XIM with the current modifiers, then see if we can |
|
|
1209 | * open a suitable preedit type |
|
|
1210 | */ |
|
|
1211 | /* INTPROTO */ |
|
|
1212 | Bool |
|
|
1213 | rxvt_IM_get_IC(pR) |
|
|
1214 | { |
|
|
1215 | int i, j, found; |
|
|
1216 | XIM xim; |
|
|
1217 | XPoint spot; |
|
|
1218 | XRectangle rect, status_rect, needed_rect; |
|
|
1219 | unsigned long fg, bg; |
|
|
1220 | const char *p; |
|
|
1221 | char **s; |
|
|
1222 | XIMStyles *xim_styles; |
|
|
1223 | XVaNestedList preedit_attr, status_attr; |
|
|
1224 | XIMCallback ximcallback; |
|
|
1225 | |
|
|
1226 | D_MAIN((stderr, "rxvt_IM_get_IC()")); |
|
|
1227 | xim = XOpenIM(R->Xdisplay, NULL, NULL, NULL); |
|
|
1228 | if (xim == NULL) |
|
|
1229 | return False; |
|
|
1230 | |
|
|
1231 | xim_styles = NULL; |
|
|
1232 | if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) |
|
|
1233 | || !xim_styles || !xim_styles->count_styles) { |
|
|
1234 | XCloseIM(xim); |
|
|
1235 | return False; |
|
|
1236 | } |
|
|
1237 | |
|
|
1238 | p = R->rs[Rs_preeditType] ? R->rs[Rs_preeditType] |
|
|
1239 | : "OverTheSpot,OffTheSpot,Root"; |
|
|
1240 | s = rxvt_splitcommastring(p); |
|
|
1241 | for (i = found = 0; !found && s[i]; i++) { |
|
|
1242 | if (!STRCMP(s[i], "OverTheSpot")) |
|
|
1243 | R->input_style = (XIMPreeditPosition | XIMStatusNothing); |
|
|
1244 | else if (!STRCMP(s[i], "OffTheSpot")) |
|
|
1245 | R->input_style = (XIMPreeditArea | XIMStatusArea); |
|
|
1246 | else if (!STRCMP(s[i], "Root")) |
|
|
1247 | R->input_style = (XIMPreeditNothing | XIMStatusNothing); |
|
|
1248 | |
|
|
1249 | for (j = 0; j < xim_styles->count_styles; j++) |
|
|
1250 | if (R->input_style == xim_styles->supported_styles[j]) { |
|
|
1251 | found = 1; |
|
|
1252 | break; |
|
|
1253 | } |
|
|
1254 | } |
|
|
1255 | for (i = 0; s[i]; i++) |
|
|
1256 | free(s[i]); |
|
|
1257 | free(s); |
|
|
1258 | XFree(xim_styles); |
|
|
1259 | |
|
|
1260 | if (!found) { |
|
|
1261 | XCloseIM(xim); |
|
|
1262 | return False; |
|
|
1263 | } |
|
|
1264 | |
|
|
1265 | ximcallback.callback = rxvt_IMDestroyCallback; |
|
|
1266 | |
|
|
1267 | /* XXX: not sure why we need this (as well as IC one below) */ |
|
|
1268 | XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL); |
|
|
1269 | |
|
|
1270 | preedit_attr = status_attr = NULL; |
|
|
1271 | |
|
|
1272 | if (R->input_style & XIMPreeditPosition) { |
|
|
1273 | rxvt_setSize(aR_ & rect); |
|
|
1274 | rxvt_setPosition(aR_ & spot); |
|
|
1275 | rxvt_setColor(aR_ & fg, &bg); |
|
|
1276 | |
|
|
1277 | preedit_attr = XVaCreateNestedList(0, XNArea, &rect, |
|
|
1278 | XNSpotLocation, &spot, |
|
|
1279 | XNForeground, fg, XNBackground, bg, |
|
|
1280 | //XNFontSet, R->TermWin.fontset, |
|
|
1281 | NULL); |
|
|
1282 | } else if (R->input_style & XIMPreeditArea) { |
|
|
1283 | rxvt_setColor(aR_ & fg, &bg); |
|
|
1284 | |
|
|
1285 | /* |
|
|
1286 | * The necessary width of preedit area is unknown |
|
|
1287 | * until create input context. |
|
|
1288 | */ |
|
|
1289 | needed_rect.width = 0; |
|
|
1290 | |
|
|
1291 | rxvt_setPreeditArea(aR_ & rect, &status_rect, &needed_rect); |
|
|
1292 | |
|
|
1293 | preedit_attr = XVaCreateNestedList(0, XNArea, &rect, |
|
|
1294 | XNForeground, fg, XNBackground, bg, |
|
|
1295 | //XNFontSet, R->TermWin.fontset, |
|
|
1296 | NULL); |
|
|
1297 | status_attr = XVaCreateNestedList(0, XNArea, &status_rect, |
|
|
1298 | XNForeground, fg, XNBackground, bg, |
|
|
1299 | //XNFontSet, R->TermWin.fontset, |
|
|
1300 | NULL); |
|
|
1301 | } |
|
|
1302 | R->Input_Context = XCreateIC(xim, XNInputStyle, R->input_style, |
|
|
1303 | XNClientWindow, R->TermWin.parent[0], |
|
|
1304 | XNFocusWindow, R->TermWin.parent[0], |
|
|
1305 | XNDestroyCallback, &ximcallback, |
|
|
1306 | preedit_attr ? XNPreeditAttributes : NULL, |
|
|
1307 | preedit_attr, |
|
|
1308 | status_attr ? XNStatusAttributes : NULL, |
|
|
1309 | status_attr, NULL); |
|
|
1310 | if (preedit_attr) |
|
|
1311 | XFree(preedit_attr); |
|
|
1312 | if (status_attr) |
|
|
1313 | XFree(status_attr); |
|
|
1314 | if (R->Input_Context == NULL) { |
|
|
1315 | rxvt_print_error("failed to create input context"); |
|
|
1316 | XCloseIM(xim); |
|
|
1317 | return False; |
|
|
1318 | } |
|
|
1319 | if (R->input_style & XIMPreeditArea) |
|
|
1320 | rxvt_IMSetStatusPosition(aR); |
|
|
1321 | D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); |
|
|
1322 | return True; |
|
|
1323 | } |
|
|
1324 | |
|
|
1325 | /* EXTPROTO */ |
1307 | /* EXTPROTO */ |
1326 | void |
1308 | void |
1327 | rxvt_IMSetStatusPosition(pR) |
1309 | rxvt_IMSetStatusPosition(pR) |
1328 | { |
1310 | { |
1329 | XRectangle preedit_rect, status_rect, *needed_rect; |
1311 | XRectangle preedit_rect, status_rect, *needed_rect; |