--- rxvt-unicode/src/main.C 2003/12/02 21:49:46 1.9 +++ rxvt-unicode/src/main.C 2003/12/18 07:31:19 1.16 @@ -1,7 +1,7 @@ /*--------------------------------*-C-*---------------------------------* * File: main.c *----------------------------------------------------------------------* - * $Id: main.C,v 1.9 2003/12/02 21:49:46 pcg Exp $ + * $Id: main.C,v 1.16 2003/12/18 07:31:19 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1992 John Bovey, University of Kent at Canterbury @@ -44,6 +44,20 @@ # include #endif +#include + +static char curlocale[128]; + +void +rxvt_set_locale (const char *locale) +{ + if (locale && STRNCMP (locale, curlocale, 128)) + { + STRNCPY (curlocale, locale, 128); + setlocale (LC_CTYPE, curlocale); + } +} + void * rxvt_term::operator new (size_t s) { @@ -69,14 +83,18 @@ #endif x_ev (this, &rxvt_term::x_cb), destroy_ev (this, &rxvt_term::destroy_cb), - check_ev (this, &rxvt_term::check_cb) + check_ev (this, &rxvt_term::check_cb), + incr_ev (this, &rxvt_term::incr_cb) { cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; } rxvt_term::~rxvt_term () { - rxvt_scr_release (this); + scr_release (); + + free (locale); + free (codeset); #ifndef NO_SETOWNER_TTYDEV rxvt_privileged_ttydev (this, RESTORE); @@ -176,8 +194,6 @@ bool rxvt_term::init (int argc, const char *const *argv) { - dR;//TODO (scrollbar, setidle) - /* * Save and then give up any super-user privileges * If we need privileges in any area then we must specifically request it. @@ -188,23 +204,25 @@ rxvt_privileges (this, SAVE); rxvt_privileges (this, IGNORE); - rxvt_init_secondary (this); + init_secondary (); + + const char **cmd_argv = init_resources (argc, argv); - const char **cmd_argv = rxvt_init_resources (this, argc, argv); + set_locale (""); #if (MENUBAR_MAX) rxvt_menubar_read (this, rs[Rs_menu]); #endif #ifdef HAVE_SCROLLBARS if (Options & Opt_scrollBar) - scrollbar_setIdle (); /* set existence for size calculations */ + scrollBar.setIdle (); /* set existence for size calculations */ #endif rxvt_Create_Windows (this, argc, argv); - rxvt_init_xlocale (this); + init_xlocale (); - rxvt_scr_reset (this); /* initialize screen */ + scr_reset (); /* initialize screen */ #ifdef RXVT_GRAPHICS rxvt_Gr_reset (this); /* reset graphics */ #endif @@ -233,14 +251,16 @@ XMapWindow (Xdisplay, TermWin.vt); XMapWindow (Xdisplay, TermWin.parent[0]); - rxvt_init_env (this); - rxvt_init_command (this, cmd_argv); + init_env (); + init_command (cmd_argv); x_ev.start (Xfd, EVENT_READ); pty_ev.start (cmd_fd, EVENT_READ); check_ev.start (); + process_x_events (); + return true; } @@ -757,27 +777,26 @@ /* handle Color_BD, scrollbar background, etc. */ - rxvt_set_colorfgbg(aR); - rxvt_recolour_cursor(aR); + rxvt_set_colorfgbg (aR); + R->recolour_cursor (); /* the only reasonable way to enforce a clean update */ - rxvt_scr_poweron(aR); + rxvt_scr_poweron (aR); } #else # define rxvt_set_window_color(aR_ idx,color) ((void)0) #endif /* XTERM_COLOR_CHANGE */ -/* EXTPROTO */ void -rxvt_recolour_cursor(pR) +rxvt_term::recolour_cursor () { - rxvt_color xcol[2]; - #if TODO - xcol[0] = R->PixColors[Color_pointer]; - xcol[1] = R->PixColors[Color_bg]; - XQueryColors(R->Xdisplay, XCMAP, xcol, 2); - XRecolorCursor(R->Xdisplay, R->TermWin_cursor, &(xcol[0]), &(xcol[1])); + rxvt_color xcol[2]; + + xcol[0] = PixColors[Color_pointer]; + xcol[1] = PixColors[Color_bg]; + XQueryColors (Xdisplay, XCMAP, xcol, 2); + XRecolorCursor (Xdisplay, TermWin_cursor, &(xcol[0]), &(xcol[1])); #endif } @@ -939,7 +958,9 @@ /* scr_reset only works on the primary screen */ if (R->old_height) /* this is not the first time through */ curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); - rxvt_scr_reset(aR); + + R->scr_reset(); + if (curr_screen >= 0) { /* this is not the first time through */ rxvt_scr_change_screen(aR_ curr_screen); rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); @@ -1049,18 +1070,6 @@ XFree(preedit_attr); } -/* EXTPROTO */ -void -rxvt_setTermFontSet(pR_ int idx) -{ - char *string; - long length; - int success = 0; - - if (idx < 0 || idx >= MAX_NFONTS) - return; -} - /* INTPROTO */ void rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect, @@ -1105,71 +1114,11 @@ } /* - * X manual pages and include files don't match on some systems: - * some think this is an XIDProc and others an XIMProc so we can't - * use the first argument - need to update this to be nice for - * both types via some sort of configure detection - */ -/* ARGSUSED */ -/* EXTPROTO */ -void -rxvt_IMInstantiateCallback(Display * unused - __attribute__ ((unused)), XPointer client_data - __attribute__ ((unused)), XPointer call_data - __attribute__ ((unused))) -{ - dR; - int i, found, had_im; - const char *p; - char **s; - char buf[IMBUFSIZ]; - - D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); - if (R->Input_Context) - return; - - found = had_im = 0; - p = R->rs[Rs_inputMethod]; - if (p && *p) { - had_im = 1; - s = rxvt_splitcommastring(p); - for (i = 0; s[i]; i++) { - if (*s[i]) { - STRCPY(buf, "@im="); - STRNCAT(buf, s[i], IMBUFSIZ - 5); - if ((p = XSetLocaleModifiers(buf)) != NULL && *p - && (rxvt_IM_get_IC(aR) == True)) { - found = 1; - break; - } - } - } - for (i = 0; s[i]; i++) - free(s[i]); - free(s); - } - if (found) - return; - -/* try with XMODIFIERS env. var. */ - if ((p = XSetLocaleModifiers("")) != NULL && *p) { - rxvt_IM_get_IC(aR); - return; - } - -/* try with no modifiers base IF the user didn't specify an IM */ - if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p - && rxvt_IM_get_IC(aR) == True) - return; -} - -/* * Try to open a XIM with the current modifiers, then see if we can * open a suitable preedit type */ -/* INTPROTO */ -Bool -rxvt_IM_get_IC(pR) +static Bool +rxvt_IM_get_IC (pR) { int i, j, found; XIM xim; @@ -1183,12 +1132,12 @@ XIMCallback ximcallback; D_MAIN((stderr, "rxvt_IM_get_IC()")); - xim = XOpenIM(R->Xdisplay, NULL, NULL, NULL); + xim = XOpenIM (R->Xdisplay, NULL, NULL, NULL); if (xim == NULL) return False; xim_styles = NULL; - if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) + if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) || !xim_styles || !xim_styles->count_styles) { XCloseIM(xim); return False; @@ -1223,7 +1172,7 @@ ximcallback.callback = rxvt_IMDestroyCallback; -/* XXX: not sure why we need this (as well as IC one below) */ + /* XXX: not sure why we need this (as well as IC one below) */ XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL); preedit_attr = status_attr = NULL; @@ -1281,6 +1230,80 @@ return True; } +/* + * X manual pages and include files don't match on some systems: + * some think this is an XIDProc and others an XIMProc so we can't + * use the first argument - need to update this to be nice for + * both types via some sort of configure detection + */ +/* ARGSUSED */ +/* EXTPROTO */ +void +rxvt_IMInstantiateCallback(Display * unused + __attribute__ ((unused)), XPointer client_data + __attribute__ ((unused)), XPointer call_data + __attribute__ ((unused))) +{ + dR; + int i, found, had_im; + const char *p; + char **s; + char buf[IMBUFSIZ]; + + D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); + if (R->Input_Context) + return; + +#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) + if (R->rs[Rs_imLocale]) + setlocale (LC_CTYPE, R->rs[Rs_imLocale]); +#endif + + p = R->rs[Rs_inputMethod]; + if (p && *p) + { + bool found = false; + + s = rxvt_splitcommastring (p); + for (i = 0; s[i]; i++) + { + if (*s[i]) + { + STRCPY (buf, "@im="); + STRNCAT (buf, s[i], IMBUFSIZ - 5); + if ((p = XSetLocaleModifiers (buf)) && *p + && rxvt_IM_get_IC (aR)) + { + found = true; + break; + } + } + } + for (i = 0; s[i]; i++) + free(s[i]); + free(s); + + if (found) + goto done; + } + +/* try with XMODIFIERS env. var. */ + if ((p = XSetLocaleModifiers ("")) && *p + && rxvt_IM_get_IC (aR)) + goto done; + +/* try with no modifiers base IF the user didn't specify an IM */ + if ((p = XSetLocaleModifiers ("@im=none")) && *p + && rxvt_IM_get_IC (aR) == True) + goto done; + +done: +#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) + if (R->rs[Rs_imLocale]) + setlocale (LC_CTYPE, R->locale); +#endif +} + /* EXTPROTO */ void rxvt_IMSetStatusPosition(pR)