Browse Source

smater way to set latin1 locales in x11

Eduardo Bart 10 years ago
parent
commit
77d1ebc8c5
1 changed files with 22 additions and 19 deletions
  1. 22
    19
      src/x11platform.cpp

+ 22
- 19
src/x11platform.cpp View File

@@ -193,6 +193,13 @@ void Platform::init()
193 193
     x11.keyMap[XK_Super_R] = KC_RWIN;
194 194
     x11.keyMap[XK_Menu] = KC_APPS;
195 195
 
196
+    // try to set a latin1 locales otherwise fallback to standard C locale
197
+    static char locales[][32] = { "en_US.iso88591", "iso88591", "en_US", "C" };
198
+    for(int i=0;i<4;++i) {
199
+        if(setlocale(LC_ALL, locales[i]))
200
+            break;
201
+    }
202
+
196 203
     // open display
197 204
     x11.display = XOpenDisplay(0);
198 205
     if(!x11.display)
@@ -287,6 +294,7 @@ void Platform::poll()
287 294
                        keysym != XK_Delete &&
288 295
                        keysym != XK_Escape
289 296
                     ) {
297
+                        //debug("char: %c code: %d", buf[0], (unsigned char)buf[0]);
290 298
                         inputEvent.type = EV_TEXT_ENTER;
291 299
                         inputEvent.key.keychar = buf[0];
292 300
                         inputEvent.key.keycode = KC_UNKNOWN;
@@ -472,26 +480,21 @@ bool Platform::createWindow(int width, int height, int minWidth, int minHeight)
472 480
     if(!x11.window)
473 481
         fatal("Unable to create X window");
474 482
 
475
-    // setup locale to en_US.ISO-8859-1 characters
476
-    // and create input context (to get special characters from input)
477
-    if(setlocale(LC_ALL, "en_US.ISO-8859-1")) {
478
-        if(XSupportsLocale()) {
479
-            XSetLocaleModifiers("");
480
-            x11.xim = XOpenIM(x11.display, NULL, NULL, NULL);
481
-            if(x11.xim) {
482
-                x11.xic = XCreateIC(x11.xim,
483
-                                        XNInputStyle,
484
-                                        XIMPreeditNothing | XIMStatusNothing,
485
-                                        XNClientWindow, x11.window, NULL);
486
-                if(!x11.xic)
487
-                    error("Unable to create the input context");
488
-            } else
489
-                error("Failed to open an input method");
483
+    //  create input context (to have better key input handling)
484
+    if(XSupportsLocale()) {
485
+        XSetLocaleModifiers("");
486
+        x11.xim = XOpenIM(x11.display, NULL, NULL, NULL);
487
+        if(x11.xim) {
488
+            x11.xic = XCreateIC(x11.xim,
489
+                                    XNInputStyle,
490
+                                    XIMPreeditNothing | XIMStatusNothing,
491
+                                    XNClientWindow, x11.window, NULL);
492
+            if(!x11.xic)
493
+                error("Unable to create the input context");
490 494
         } else
491
-            error("X11 does not support the current locale");
492
-    }
493
-    else
494
-        error("Failed setting locale to latin1");
495
+            error("Failed to open an input method");
496
+    } else
497
+        error("X11 does not support the current locale");
495 498
 
496 499
     if(!x11.xic)
497 500
         warning("Input of special keys maybe messed up because we couldn't create an input context");

Loading…
Cancel
Save