src/video/x11/SDL_x11video.c
changeset 10562 b48d8a98e261
parent 10518 fe8023cff95a
child 10737 3406a0f8b041
equal deleted inserted replaced
10561:35fee69e84df 10562:b48d8a98e261
    35 #include "SDL_x11touch.h"
    35 #include "SDL_x11touch.h"
    36 #include "SDL_x11xinput2.h"
    36 #include "SDL_x11xinput2.h"
    37 
    37 
    38 #if SDL_VIDEO_OPENGL_EGL
    38 #if SDL_VIDEO_OPENGL_EGL
    39 #include "SDL_x11opengles.h"
    39 #include "SDL_x11opengles.h"
    40 #endif
       
    41 
       
    42 #ifdef X_HAVE_UTF8_STRING
       
    43 #include <locale.h>
       
    44 #endif
    40 #endif
    45 
    41 
    46 /* Initialization/Query functions */
    42 /* Initialization/Query functions */
    47 static int X11_VideoInit(_THIS);
    43 static int X11_VideoInit(_THIS);
    48 static void X11_VideoQuit(_THIS);
    44 static void X11_VideoQuit(_THIS);
   385     /* Get the process PID to be associated to the window */
   381     /* Get the process PID to be associated to the window */
   386     data->pid = getpid();
   382     data->pid = getpid();
   387 
   383 
   388     /* I have no idea how random this actually is, or has to be. */
   384     /* I have no idea how random this actually is, or has to be. */
   389     data->window_group = (XID) (((size_t) data->pid) ^ ((size_t) _this));
   385     data->window_group = (XID) (((size_t) data->pid) ^ ((size_t) _this));
   390 
       
   391     /* Open a connection to the X input manager */
       
   392 #ifdef X_HAVE_UTF8_STRING
       
   393     if (SDL_X11_HAVE_UTF8) {
       
   394         /* Set the locale, and call XSetLocaleModifiers before XOpenIM so that 
       
   395            Compose keys will work correctly. */
       
   396         char *prev_locale = setlocale(LC_ALL, NULL);
       
   397         char *prev_xmods  = X11_XSetLocaleModifiers(NULL);
       
   398         const char *new_xmods = "";
       
   399 #if defined(HAVE_IBUS_IBUS_H) || defined(HAVE_FCITX_FRONTEND_H)
       
   400         const char *env_xmods = SDL_getenv("XMODIFIERS");
       
   401 #endif
       
   402         SDL_bool has_dbus_ime_support = SDL_FALSE;
       
   403 
       
   404         if (prev_locale) {
       
   405             prev_locale = SDL_strdup(prev_locale);
       
   406         }
       
   407 
       
   408         if (prev_xmods) {
       
   409             prev_xmods = SDL_strdup(prev_xmods);
       
   410         }
       
   411 
       
   412         /* IBus resends some key events that were filtered by XFilterEvents
       
   413            when it is used via XIM which causes issues. Prevent this by forcing
       
   414            @im=none if XMODIFIERS contains @im=ibus. IBus can still be used via 
       
   415            the DBus implementation, which also has support for pre-editing. */
       
   416 #ifdef HAVE_IBUS_IBUS_H
       
   417         if (env_xmods && SDL_strstr(env_xmods, "@im=ibus") != NULL) {
       
   418             has_dbus_ime_support = SDL_TRUE;
       
   419         }
       
   420 #endif
       
   421 #ifdef HAVE_FCITX_FRONTEND_H
       
   422         if (env_xmods && SDL_strstr(env_xmods, "@im=fcitx") != NULL) {
       
   423             has_dbus_ime_support = SDL_TRUE;
       
   424         }
       
   425 #endif
       
   426         if (has_dbus_ime_support) {
       
   427             new_xmods = "@im=none";
       
   428         }
       
   429 
       
   430         setlocale(LC_ALL, "");
       
   431         X11_XSetLocaleModifiers(new_xmods);
       
   432 
       
   433         data->im = X11_XOpenIM(data->display, NULL, data->classname, data->classname);
       
   434 
       
   435         /* Reset the locale + X locale modifiers back to how they were,
       
   436            locale first because the X locale modifiers depend on it. */
       
   437         setlocale(LC_ALL, prev_locale);
       
   438         X11_XSetLocaleModifiers(prev_xmods);
       
   439 
       
   440         if (prev_locale) {
       
   441             SDL_free(prev_locale);
       
   442         }
       
   443 
       
   444         if (prev_xmods) {
       
   445             SDL_free(prev_xmods);
       
   446         }
       
   447     }
       
   448 #endif
       
   449 
   386 
   450     /* Look up some useful Atoms */
   387     /* Look up some useful Atoms */
   451 #define GET_ATOM(X) data->X = X11_XInternAtom(data->display, #X, False)
   388 #define GET_ATOM(X) data->X = X11_XInternAtom(data->display, #X, False)
   452     GET_ATOM(WM_PROTOCOLS);
   389     GET_ATOM(WM_PROTOCOLS);
   453     GET_ATOM(WM_DELETE_WINDOW);
   390     GET_ATOM(WM_DELETE_WINDOW);