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.31 by pcg, Fri Feb 13 12:11:05 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;
126 delete TermWin.fontset;
130 127
131 if (cmd_fd >= 0) 128 displays.put (display);
132 close (cmd_fd); 129}
133 130
131void
132rxvt_term::destroy ()
133{
134 if (display) 134 if (display)
135 displays.release (display);
136}
137
138void
139rxvt_term::destroy ()
140{
141 if (display)
142 { 135 {
136 if (TermWin.parent[0])
137 XDestroyWindow (display->display, TermWin.parent[0]);
138
139 rootwin_ev.stop (display);
143 termwin_ev.stop (display); 140 termwin_ev.stop (display);
144 vt_ev.stop (display); 141 vt_ev.stop (display);
142
143#ifdef USE_XIM
144 im_destroy ();
145 im_ev.stop (display);
146#endif
145#ifdef HAVE_SCROLLBARS 147#ifdef HAVE_SCROLLBARS
146 scrollbar_ev.stop (display); 148 scrollbar_ev.stop (display);
147#endif 149#endif
148#ifdef MENUBAR 150#ifdef MENUBAR
149 menubar_ev.stop (display); 151 menubar_ev.stop (display);
321 */ 323 */
322/* EXTPROTO */ 324/* EXTPROTO */
323RETSIGTYPE 325RETSIGTYPE
324rxvt_Exit_signal(int sig) 326rxvt_Exit_signal(int sig)
325{ 327{
326 signal(sig, SIG_DFL); 328 signal (sig, SIG_DFL);
327#ifdef DEBUG_CMD 329#ifdef DEBUG_CMD
328 rxvt_print_error("signal %d", sig); 330 rxvt_print_error ("signal %d", sig);
329#endif 331#endif
330 rxvt_clean_exit(); 332 rxvt_clean_exit();
331 kill(getpid(), sig); 333 kill (getpid (), sig);
332} 334}
333 335
334/* INTPROTO */ 336/* INTPROTO */
335int 337int
336rxvt_xerror_handler (Display *display, XErrorEvent *event) 338rxvt_xerror_handler (Display *display, XErrorEvent *event)
353 */ 355 */
354/* EXTPROTO */ 356/* EXTPROTO */
355void 357void
356rxvt_clean_exit () 358rxvt_clean_exit ()
357{ 359{
360 // TODO: rxvtd should clean up all ressources
361 if (GET_R)
358 GET_R->destroy (); 362 GET_R->destroy ();
359} 363}
360 364
361/* ------------------------------------------------------------------------- * 365/* ------------------------------------------------------------------------- *
362 * MEMORY ALLOCATION WRAPPERS * 366 * MEMORY ALLOCATION WRAPPERS *
363 * ------------------------------------------------------------------------- */ 367 * ------------------------------------------------------------------------- */
1057 1061
1058/* -------------------------------------------------------------------- * 1062/* -------------------------------------------------------------------- *
1059 * - X INPUT METHOD ROUTINES - * 1063 * - X INPUT METHOD ROUTINES - *
1060 * -------------------------------------------------------------------- */ 1064 * -------------------------------------------------------------------- */
1061#ifdef USE_XIM 1065#ifdef USE_XIM
1066
1062void 1067void
1063rxvt_term::set_size (XRectangle *size) 1068rxvt_term::im_set_size (XRectangle *size)
1064{ 1069{
1065 size->x = TermWin.int_bwidth; 1070 size->x = TermWin.int_bwidth;
1066 size->y = TermWin.int_bwidth; 1071 size->y = TermWin.int_bwidth;
1067 size->width = Width2Pixel(TermWin.ncol); 1072 size->width = Width2Pixel(TermWin.ncol);
1068 size->height = Height2Pixel(TermWin.nrow); 1073 size->height = Height2Pixel(TermWin.nrow);
1069} 1074}
1070 1075
1071void 1076void
1072rxvt_term::set_color (unsigned long *fg, unsigned long *bg) 1077rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg)
1073{ 1078{
1074 *fg = PixColors[Color_fg]; 1079 *fg = PixColors[Color_fg];
1075 *bg = PixColors[Color_bg]; 1080 *bg = PixColors[Color_bg];
1076} 1081}
1077 1082
1114 || event_type == SelectionNotify 1119 || event_type == SelectionNotify
1115 || event_type == ButtonRelease || event_type == FocusIn) 1120 || event_type == ButtonRelease || event_type == FocusIn)
1116 || !IMisRunning ()) 1121 || !IMisRunning ())
1117 return; 1122 return;
1118 1123
1119 set_position (&spot); 1124 im_set_position (&spot);
1120 1125
1121 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); 1126 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
1122 XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1127 XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1123 XFree(preedit_attr); 1128 XFree(preedit_attr);
1124} 1129}
1125 1130
1126void 1131void
1127rxvt_term::set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, 1132rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect,
1128 XRectangle * needed_rect) 1133 XRectangle * needed_rect)
1129{ 1134{
1130 int mbh, vtx = 0; 1135 int mbh, vtx = 0;
1131 1136
1132 if (scrollbar_visible () && !(Options & Opt_scrollBar_right)) 1137 if (scrollbar_visible () && !(Options & Opt_scrollBar_right))
1133 vtx = scrollbar_TotalWidth(); 1138 vtx = scrollbar_TotalWidth();
1146 1151
1147 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1); 1152 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1);
1148 status_rect->height = Height2Pixel(1); 1153 status_rect->height = Height2Pixel(1);
1149} 1154}
1150 1155
1151/* ARGSUSED */
1152/* EXTPROTO */
1153void 1156void
1154rxvt_IMDestroyCallback(XIM xim __attribute__ ((unused)), XPointer client_data 1157rxvt_term::im_destroy ()
1155 __attribute__ ((unused)), XPointer call_data
1156 __attribute__ ((unused)))
1157{ 1158{
1159 if (Input_Context)
1160 {
1161 XDestroyIC (Input_Context);
1158 GET_R->Input_Context = NULL; 1162 Input_Context = NULL;
1159 /* To avoid Segmentation Fault in C locale: Solaris only? */ 1163 }
1160 if (STRCMP (GET_R->locale, "C")) 1164
1161 XRegisterIMInstantiateCallback(GET_R->display->display, NULL, NULL, NULL, 1165 if (input_method)
1162 rxvt_IMInstantiateCallback, NULL); 1166 {
1167 display->put_xim (input_method);
1168 input_method = 0;
1169 }
1163} 1170}
1164 1171
1165/* 1172/*
1166 * Try to open a XIM with the current modifiers, then see if we can 1173 * Try to open a XIM with the current modifiers, then see if we can
1167 * open a suitable preedit type 1174 * open a suitable preedit type
1168 */ 1175 */
1169bool 1176bool
1170rxvt_term::IM_get_IC () 1177rxvt_term::IM_get_IC (const char *modifiers)
1171{ 1178{
1172 int i, j, found; 1179 int i, j, found;
1173 XIM xim; 1180 XIM xim;
1174 XPoint spot; 1181 XPoint spot;
1175 XRectangle rect, status_rect, needed_rect; 1182 XRectangle rect, status_rect, needed_rect;
1176 unsigned long fg, bg; 1183 unsigned long fg, bg;
1177 const char *p; 1184 const char *p;
1178 char **s; 1185 char **s;
1179 XIMStyles *xim_styles; 1186 XIMStyles *xim_styles;
1180 XVaNestedList preedit_attr, status_attr; 1187 XVaNestedList preedit_attr, status_attr;
1181 XIMCallback ximcallback; 1188
1189 if (!((p = XSetLocaleModifiers (modifiers)) && *p))
1190 return false;
1182 1191
1183 D_MAIN((stderr, "rxvt_IM_get_IC()")); 1192 D_MAIN((stderr, "rxvt_IM_get_IC()"));
1184 xim = XOpenIM (display->display, NULL, NULL, NULL); 1193 input_method = display->get_xim (locale, modifiers);
1185 if (xim == NULL) 1194 if (input_method == NULL)
1186 return False; 1195 return false;
1196
1197 xim = input_method->xim;
1187 1198
1188 xim_styles = NULL; 1199 xim_styles = NULL;
1189 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1200 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1190 || !xim_styles || !xim_styles->count_styles) 1201 || !xim_styles || !xim_styles->count_styles)
1191 { 1202 {
1192 XCloseIM(xim); 1203 display->put_xim (input_method);
1193 return False; 1204 return false;
1194 } 1205 }
1195 1206
1196 p = rs[Rs_preeditType] ? rs[Rs_preeditType] 1207 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root";
1197 : "OverTheSpot,OffTheSpot,Root";
1198 s = rxvt_splitcommastring(p); 1208 s = rxvt_splitcommastring(p);
1199 for (i = found = 0; !found && s[i]; i++) 1209 for (i = found = 0; !found && s[i]; i++)
1200 { 1210 {
1201 if (!STRCMP(s[i], "OverTheSpot")) 1211 if (!STRCMP(s[i], "OverTheSpot"))
1202 input_style = (XIMPreeditPosition | XIMStatusNothing); 1212 input_style = (XIMPreeditPosition | XIMStatusNothing);
1210 { 1220 {
1211 found = 1; 1221 found = 1;
1212 break; 1222 break;
1213 } 1223 }
1214 } 1224 }
1225
1215 for (i = 0; s[i]; i++) 1226 for (i = 0; s[i]; i++)
1216 free(s[i]); 1227 free (s[i]);
1228
1217 free(s); 1229 free (s);
1218 XFree(xim_styles); 1230 XFree (xim_styles);
1219 1231
1220 if (!found) 1232 if (!found)
1221 { 1233 {
1222 XCloseIM(xim); 1234 display->put_xim (input_method);
1223 return False; 1235 return false;
1224 } 1236 }
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 1237
1231 preedit_attr = status_attr = NULL; 1238 preedit_attr = status_attr = NULL;
1232 1239
1233 if (input_style & XIMPreeditPosition) 1240 if (input_style & XIMPreeditPosition)
1234 { 1241 {
1235 set_size (&rect); 1242 im_set_size (&rect);
1236 set_position (&spot); 1243 im_set_position (&spot);
1237 set_color (&fg, &bg); 1244 im_set_color (&fg, &bg);
1238 1245
1239 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1246 preedit_attr = XVaCreateNestedList(0, XNArea, &rect,
1240 XNSpotLocation, &spot, 1247 XNSpotLocation, &spot,
1241 XNForeground, fg, XNBackground, bg, 1248 XNForeground, fg, XNBackground, bg,
1242 //XNFontSet, TermWin.fontset, 1249 //XNFontSet, TermWin.fontset,
1243 NULL); 1250 NULL);
1244 } 1251 }
1245 else if (input_style & XIMPreeditArea) 1252 else if (input_style & XIMPreeditArea)
1246 { 1253 {
1247 set_color (&fg, &bg); 1254 im_set_color (&fg, &bg);
1248 1255
1249 /* 1256 /*
1250 * The necessary width of preedit area is unknown 1257 * The necessary width of preedit area is unknown
1251 * until create input context. 1258 * until create input context.
1252 */ 1259 */
1253 needed_rect.width = 0; 1260 needed_rect.width = 0;
1254 1261
1255 set_preedit_area(&rect, &status_rect, &needed_rect); 1262 im_set_preedit_area (&rect, &status_rect, &needed_rect);
1256 1263
1257 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1264 preedit_attr = XVaCreateNestedList(0, XNArea, &rect,
1258 XNForeground, fg, XNBackground, bg, 1265 XNForeground, fg, XNBackground, bg,
1259 //XNFontSet, TermWin.fontset, 1266 //XNFontSet, TermWin.fontset,
1260 NULL); 1267 NULL);
1261 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, 1268 status_attr = XVaCreateNestedList(0, XNArea, &status_rect,
1262 XNForeground, fg, XNBackground, bg, 1269 XNForeground, fg, XNBackground, bg,
1263 //XNFontSet, TermWin.fontset, 1270 //XNFontSet, TermWin.fontset,
1264 NULL); 1271 NULL);
1265 } 1272 }
1273
1266 Input_Context = XCreateIC(xim, XNInputStyle, input_style, 1274 Input_Context = XCreateIC(xim, XNInputStyle, input_style,
1267 XNClientWindow, TermWin.parent[0], 1275 XNClientWindow, TermWin.parent[0],
1268 XNFocusWindow, TermWin.parent[0], 1276 XNFocusWindow, TermWin.parent[0],
1269 XNDestroyCallback, &ximcallback,
1270 preedit_attr ? XNPreeditAttributes : NULL, 1277 preedit_attr ? XNPreeditAttributes : NULL,
1271 preedit_attr, 1278 preedit_attr,
1272 status_attr ? XNStatusAttributes : NULL, 1279 status_attr ? XNStatusAttributes : NULL,
1273 status_attr, NULL); 1280 status_attr, NULL);
1274 if (preedit_attr) 1281 if (preedit_attr) XFree(preedit_attr);
1275 XFree(preedit_attr); 1282 if (status_attr) XFree(status_attr);
1276 if (status_attr) 1283
1277 XFree(status_attr);
1278 if (Input_Context == NULL) 1284 if (Input_Context == NULL)
1279 { 1285 {
1280 rxvt_print_error("failed to create input context"); 1286 rxvt_print_error("failed to create input context");
1281 XCloseIM(xim); 1287 display->put_xim (input_method);
1282 return False; 1288 return false;
1283 } 1289 }
1290
1284 if (input_style & XIMPreeditArea) 1291 if (input_style & XIMPreeditArea)
1285 IMSetStatusPosition (); 1292 IMSetStatusPosition ();
1293
1286 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); 1294 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection"));
1287 return True; 1295 return true;
1288} 1296}
1289 1297
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 1298void
1299rxvt_IMInstantiateCallback(Display * unused 1299rxvt_term::im_cb ()
1300 __attribute__ ((unused)), XPointer client_data
1301 __attribute__ ((unused)), XPointer call_data
1302 __attribute__ ((unused)))
1303{ 1300{
1304 int i, found, had_im; 1301 int i, found, had_im;
1305 const char *p; 1302 const char *p;
1306 char **s; 1303 char **s;
1307 char buf[IMBUFSIZ]; 1304 char buf[IMBUFSIZ];
1308 1305
1306 im_destroy ();
1307
1309 D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); 1308 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1310 if (GET_R->Input_Context) 1309 if (Input_Context)
1311 return; 1310 return;
1312 1311
1313#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1312#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1314 if (GET_R->rs[Rs_imLocale]) 1313 if (rs[Rs_imLocale])
1315 setlocale (LC_CTYPE, GET_R->rs[Rs_imLocale]); 1314 setlocale (LC_CTYPE, rs[Rs_imLocale]);
1316#endif 1315#endif
1317 1316
1318 p = GET_R->rs[Rs_inputMethod]; 1317 p = rs[Rs_inputMethod];
1319 if (p && *p) 1318 if (p && *p)
1320 { 1319 {
1321 bool found = false; 1320 bool found = false;
1322 1321
1323 s = rxvt_splitcommastring (p); 1322 s = rxvt_splitcommastring (p);
1325 { 1324 {
1326 if (*s[i]) 1325 if (*s[i])
1327 { 1326 {
1328 STRCPY (buf, "@im="); 1327 STRCPY (buf, "@im=");
1329 STRNCAT (buf, s[i], IMBUFSIZ - 5); 1328 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1330 if ((p = XSetLocaleModifiers (buf)) && *p && GET_R->IM_get_IC ()) 1329 if (IM_get_IC (buf))
1331 { 1330 {
1332 found = true; 1331 found = true;
1333 break; 1332 break;
1334 } 1333 }
1335 } 1334 }
1341 if (found) 1340 if (found)
1342 goto done; 1341 goto done;
1343 } 1342 }
1344 1343
1345 /* try with XMODIFIERS env. var. */ 1344 /* try with XMODIFIERS env. var. */
1346 if ((p = XSetLocaleModifiers ("")) && *p 1345 if (IM_get_IC (""))
1347 && GET_R->IM_get_IC ())
1348 goto done; 1346 goto done;
1349 1347
1350 /* try with no modifiers base IF the user didn't specify an IM */ 1348 /* try with no modifiers base IF the user didn't specify an IM */
1351 if ((p = XSetLocaleModifiers ("@im=none")) && *p 1349 if (IM_get_IC ("@im=none"))
1352 && GET_R->IM_get_IC () == True)
1353 goto done; 1350 goto done;
1354 1351
1355done: 1352done:
1356#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1353#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1357 if (GET_R->rs[Rs_imLocale]) 1354 if (rs[Rs_imLocale])
1358 setlocale (LC_CTYPE, GET_R->locale); 1355 setlocale (LC_CTYPE, locale);
1359#endif 1356#endif
1360} 1357}
1361 1358
1362void 1359void
1363rxvt_term::IMSetStatusPosition () 1360rxvt_term::IMSetStatusPosition ()
1373 /* Getting the necessary width of preedit area */ 1370 /* Getting the necessary width of preedit area */
1374 status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); 1371 status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL);
1375 XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL); 1372 XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL);
1376 XFree(status_attr); 1373 XFree(status_attr);
1377 1374
1378 set_preedit_area(&preedit_rect, &status_rect, needed_rect); 1375 im_set_preedit_area (&preedit_rect, &status_rect, needed_rect);
1379 1376
1380 preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); 1377 preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL);
1381 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); 1378 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL);
1382 1379
1383 XSetICValues(Input_Context, 1380 XSetICValues(Input_Context,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines