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.27 by pcg, Mon Feb 9 07:11:49 2004 UTC vs.
Revision 1.30 by pcg, Thu Feb 12 01:53:25 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines