src/core/linux/SDL_ime.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 18 Aug 2017 20:00:29 -0400
changeset 11323 46861f3fc187
parent 11053 dc895d39212c
child 11811 5d94cb6b24d3
permissions -rw-r--r--
cmake: added a FIXME for later.

Have to figure out what cmake version fixed this and bump the minimum to that.
slouken@10496
     1
/*
slouken@10496
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@10496
     4
slouken@10496
     5
  This software is provided 'as-is', without any express or implied
slouken@10496
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@10496
     7
  arising from the use of this software.
slouken@10496
     8
slouken@10496
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@10496
    10
  including commercial applications, and to alter it and redistribute it
slouken@10496
    11
  freely, subject to the following restrictions:
slouken@10496
    12
slouken@10496
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@10496
    14
     claim that you wrote the original software. If you use this software
slouken@10496
    15
     in a product, an acknowledgment in the product documentation would be
slouken@10496
    16
     appreciated but is not required.
slouken@10496
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@10496
    18
     misrepresented as being the original software.
slouken@10496
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@10496
    20
*/
slouken@10496
    21
slouken@10496
    22
#include "SDL_ime.h"
slouken@10496
    23
#include "SDL_ibus.h"
slouken@10496
    24
#include "SDL_fcitx.h"
slouken@10496
    25
slouken@10496
    26
typedef SDL_bool (*_SDL_IME_Init)();
slouken@10496
    27
typedef void (*_SDL_IME_Quit)();
slouken@10496
    28
typedef void (*_SDL_IME_SetFocus)(SDL_bool);
slouken@10496
    29
typedef void (*_SDL_IME_Reset)();
slouken@10496
    30
typedef SDL_bool (*_SDL_IME_ProcessKeyEvent)(Uint32, Uint32);
slouken@10496
    31
typedef void (*_SDL_IME_UpdateTextRect)(SDL_Rect *);
slouken@10496
    32
typedef void (*_SDL_IME_PumpEvents)();
slouken@10496
    33
slouken@10496
    34
static _SDL_IME_Init SDL_IME_Init_Real = NULL;
slouken@10496
    35
static _SDL_IME_Quit SDL_IME_Quit_Real = NULL;
slouken@10496
    36
static _SDL_IME_SetFocus SDL_IME_SetFocus_Real = NULL;
slouken@10496
    37
static _SDL_IME_Reset SDL_IME_Reset_Real = NULL;
slouken@10496
    38
static _SDL_IME_ProcessKeyEvent SDL_IME_ProcessKeyEvent_Real = NULL;
slouken@10496
    39
static _SDL_IME_UpdateTextRect SDL_IME_UpdateTextRect_Real = NULL;
slouken@10496
    40
static _SDL_IME_PumpEvents SDL_IME_PumpEvents_Real = NULL;
slouken@10496
    41
slouken@10496
    42
static void
slouken@10496
    43
InitIME()
slouken@10496
    44
{
slouken@10496
    45
    static SDL_bool inited = SDL_FALSE;
philipp@10544
    46
#ifdef HAVE_FCITX_FRONTEND_H
philipp@10544
    47
    const char *im_module = SDL_getenv("SDL_IM_MODULE");
philipp@10544
    48
    const char *xmodifiers = SDL_getenv("XMODIFIERS");
philipp@10544
    49
#endif
slouken@10496
    50
slouken@10496
    51
    if (inited == SDL_TRUE)
slouken@10500
    52
        return;
slouken@10496
    53
slouken@10496
    54
    inited = SDL_TRUE;
slouken@10496
    55
slouken@10500
    56
    /* See if fcitx IME support is being requested */
slouken@10496
    57
#ifdef HAVE_FCITX_FRONTEND_H
slouken@10500
    58
    if (!SDL_IME_Init_Real &&
slouken@10500
    59
        ((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
slouken@10500
    60
         (!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
slouken@10500
    61
        SDL_IME_Init_Real = SDL_Fcitx_Init;
slouken@10500
    62
        SDL_IME_Quit_Real = SDL_Fcitx_Quit;
slouken@10500
    63
        SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
slouken@10500
    64
        SDL_IME_Reset_Real = SDL_Fcitx_Reset;
slouken@10500
    65
        SDL_IME_ProcessKeyEvent_Real = SDL_Fcitx_ProcessKeyEvent;
slouken@10500
    66
        SDL_IME_UpdateTextRect_Real = SDL_Fcitx_UpdateTextRect;
slouken@10500
    67
        SDL_IME_PumpEvents_Real = SDL_Fcitx_PumpEvents;
slouken@10496
    68
    }
slouken@10500
    69
#endif /* HAVE_FCITX_FRONTEND_H */
slouken@10500
    70
slouken@10500
    71
    /* default to IBus */
slouken@10500
    72
#ifdef HAVE_IBUS_IBUS_H
slouken@10500
    73
    if (!SDL_IME_Init_Real) {
slouken@10500
    74
        SDL_IME_Init_Real = SDL_IBus_Init;
slouken@10500
    75
        SDL_IME_Quit_Real = SDL_IBus_Quit;
slouken@10500
    76
        SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
slouken@10500
    77
        SDL_IME_Reset_Real = SDL_IBus_Reset;
slouken@10500
    78
        SDL_IME_ProcessKeyEvent_Real = SDL_IBus_ProcessKeyEvent;
slouken@10500
    79
        SDL_IME_UpdateTextRect_Real = SDL_IBus_UpdateTextRect;
slouken@10500
    80
        SDL_IME_PumpEvents_Real = SDL_IBus_PumpEvents;
slouken@10500
    81
    }
slouken@10500
    82
#endif /* HAVE_IBUS_IBUS_H */
slouken@10496
    83
}
slouken@10496
    84
slouken@10496
    85
SDL_bool
slouken@10496
    86
SDL_IME_Init(void)
slouken@10496
    87
{
slouken@10496
    88
    InitIME();
slouken@10496
    89
icculus@11053
    90
    if (SDL_IME_Init_Real) {
icculus@11053
    91
        if (SDL_IME_Init_Real()) {
icculus@11053
    92
            return SDL_TRUE;
icculus@11053
    93
        }
icculus@11053
    94
icculus@11053
    95
        /* uhoh, the IME implementation's init failed! Disable IME support. */
icculus@11053
    96
        SDL_IME_Init_Real = NULL;
icculus@11053
    97
        SDL_IME_Quit_Real = NULL;
icculus@11053
    98
        SDL_IME_SetFocus_Real = NULL;
icculus@11053
    99
        SDL_IME_Reset_Real = NULL;
icculus@11053
   100
        SDL_IME_ProcessKeyEvent_Real = NULL;
icculus@11053
   101
        SDL_IME_UpdateTextRect_Real = NULL;
icculus@11053
   102
        SDL_IME_PumpEvents_Real = NULL;
icculus@11053
   103
    }
slouken@10496
   104
slouken@10496
   105
    return SDL_FALSE;
slouken@10496
   106
}
slouken@10496
   107
slouken@10496
   108
void
slouken@10496
   109
SDL_IME_Quit(void)
slouken@10496
   110
{
slouken@10496
   111
    if (SDL_IME_Quit_Real)
slouken@10496
   112
        SDL_IME_Quit_Real();
slouken@10496
   113
}
slouken@10496
   114
slouken@10496
   115
void
slouken@10496
   116
SDL_IME_SetFocus(SDL_bool focused)
slouken@10496
   117
{
slouken@10496
   118
    if (SDL_IME_SetFocus_Real)
slouken@10496
   119
        SDL_IME_SetFocus_Real(focused);
slouken@10496
   120
}
slouken@10496
   121
slouken@10496
   122
void
slouken@10496
   123
SDL_IME_Reset(void)
slouken@10496
   124
{
slouken@10496
   125
    if (SDL_IME_Reset_Real)
slouken@10496
   126
        SDL_IME_Reset_Real();
slouken@10496
   127
}
slouken@10496
   128
slouken@10496
   129
SDL_bool
slouken@10496
   130
SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
slouken@10496
   131
{
slouken@10496
   132
    if (SDL_IME_ProcessKeyEvent_Real)
slouken@10496
   133
        return SDL_IME_ProcessKeyEvent_Real(keysym, keycode);
slouken@10496
   134
slouken@10496
   135
    return SDL_FALSE;
slouken@10496
   136
}
slouken@10496
   137
slouken@10496
   138
void
slouken@10496
   139
SDL_IME_UpdateTextRect(SDL_Rect *rect)
slouken@10496
   140
{
slouken@10496
   141
    if (SDL_IME_UpdateTextRect_Real)
slouken@10496
   142
        SDL_IME_UpdateTextRect_Real(rect);
slouken@10496
   143
}
slouken@10496
   144
slouken@10496
   145
void
slouken@10496
   146
SDL_IME_PumpEvents()
slouken@10496
   147
{
slouken@10496
   148
    if (SDL_IME_PumpEvents_Real)
slouken@10496
   149
        SDL_IME_PumpEvents_Real();
slouken@10496
   150
}
slouken@10660
   151
slouken@10660
   152
/* vi: set ts=4 sw=4 expandtab: */