smater way to set latin1 locales in x11

master
Eduardo Bart 14 years ago
parent f58ce52be8
commit 77d1ebc8c5

@ -193,6 +193,13 @@ void Platform::init()
x11.keyMap[XK_Super_R] = KC_RWIN; x11.keyMap[XK_Super_R] = KC_RWIN;
x11.keyMap[XK_Menu] = KC_APPS; x11.keyMap[XK_Menu] = KC_APPS;
// try to set a latin1 locales otherwise fallback to standard C locale
static char locales[][32] = { "en_US.iso88591", "iso88591", "en_US", "C" };
for(int i=0;i<4;++i) {
if(setlocale(LC_ALL, locales[i]))
break;
}
// open display // open display
x11.display = XOpenDisplay(0); x11.display = XOpenDisplay(0);
if(!x11.display) if(!x11.display)
@ -287,6 +294,7 @@ void Platform::poll()
keysym != XK_Delete && keysym != XK_Delete &&
keysym != XK_Escape keysym != XK_Escape
) { ) {
//debug("char: %c code: %d", buf[0], (unsigned char)buf[0]);
inputEvent.type = EV_TEXT_ENTER; inputEvent.type = EV_TEXT_ENTER;
inputEvent.key.keychar = buf[0]; inputEvent.key.keychar = buf[0];
inputEvent.key.keycode = KC_UNKNOWN; inputEvent.key.keycode = KC_UNKNOWN;
@ -472,26 +480,21 @@ bool Platform::createWindow(int width, int height, int minWidth, int minHeight)
if(!x11.window) if(!x11.window)
fatal("Unable to create X window"); fatal("Unable to create X window");
// setup locale to en_US.ISO-8859-1 characters // create input context (to have better key input handling)
// and create input context (to get special characters from input) if(XSupportsLocale()) {
if(setlocale(LC_ALL, "en_US.ISO-8859-1")) { XSetLocaleModifiers("");
if(XSupportsLocale()) { x11.xim = XOpenIM(x11.display, NULL, NULL, NULL);
XSetLocaleModifiers(""); if(x11.xim) {
x11.xim = XOpenIM(x11.display, NULL, NULL, NULL); x11.xic = XCreateIC(x11.xim,
if(x11.xim) { XNInputStyle,
x11.xic = XCreateIC(x11.xim, XIMPreeditNothing | XIMStatusNothing,
XNInputStyle, XNClientWindow, x11.window, NULL);
XIMPreeditNothing | XIMStatusNothing, if(!x11.xic)
XNClientWindow, x11.window, NULL); error("Unable to create the input context");
if(!x11.xic)
error("Unable to create the input context");
} else
error("Failed to open an input method");
} else } else
error("X11 does not support the current locale"); error("Failed to open an input method");
} } else
else error("X11 does not support the current locale");
error("Failed setting locale to latin1");
if(!x11.xic) if(!x11.xic)
warning("Input of special keys maybe messed up because we couldn't create an input context"); warning("Input of special keys maybe messed up because we couldn't create an input context");

Loading…
Cancel
Save