summaryrefslogtreecommitdiff
path: root/ism/modules/panelagent/wayland/isf_wsc_control_ui.cpp
blob: 221922ef07f24db2b3b95f22b7e22086154404ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * ISF(Input Service Framework)
 *
 * ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable.
 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
 *
 * Contact: Jihoon Kim <jihoon48.kim@samsung.com>, Haifeng Deng <haifeng.deng@samsung.com>
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */

#define Uses_SCIM_TRANSACTION
#define Uses_SCIM_CONFIG_PATH

/* IM control UI part */
#include "scim_private.h"

#include <Ecore_Wayland.h>
#include <Ecore_IMF.h>
#ifdef HAVE_VCONF
#include <vconf.h>
#endif

#include "scim.h"
#include "isf_wsc_control_ui.h"
#include "isf_wsc_context.h"
#include "isf_wsc_control.h"
#include "ise_context.h"
#include "isf_debug.h"

#ifdef LOG_TAG
# undef LOG_TAG
#endif
#define LOG_TAG                                         "ISF_WSC_EFL"

using namespace scim;

/* IM control related variables */
static TOOLBAR_MODE_T     kbd_mode = TOOLBAR_HELPER_MODE;
WSCContextISF            *input_panel_ctx = NULL;
static bool               _support_hw_keyboard_mode = false;

static int _get_context_id (WSCContextISF *ctx)
{
    WSCContextISF *context_scim = ctx;

    if (!context_scim) return -1;

    return context_scim->id;
}

#ifdef HAVE_VCONF
static void keyboard_mode_changed_cb (keynode_t *key, void* data)
{
    int val;
    if (vconf_get_bool (VCONFKEY_ISF_HW_KEYBOARD_INPUT_DETECTED, &val) != 0) {
        LOGW ("Failed to get input detect\n");
        return;
    }

    kbd_mode = (TOOLBAR_MODE_T)!val;
}
#endif

TOOLBAR_MODE_T get_keyboard_mode ()
{
    return kbd_mode;
}

void isf_wsc_input_panel_init (void)
{
    _support_hw_keyboard_mode = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_SUPPORT_HW_KEYBOARD_MODE), _support_hw_keyboard_mode);

#ifdef HAVE_VCONF
    vconf_notify_key_changed (VCONFKEY_ISF_HW_KEYBOARD_INPUT_DETECTED, keyboard_mode_changed_cb, NULL);
#endif
}

void isf_wsc_input_panel_shutdown (void)
{
#ifdef HAVE_VCONF
    vconf_ignore_key_changed (VCONFKEY_ISF_HW_KEYBOARD_INPUT_DETECTED, keyboard_mode_changed_cb);
#endif
}

void isf_wsc_context_input_panel_show (WSCContextISF* wsc_ctx)
{
    int length = -1;
    void *packet = NULL;
    char imdata[1024] = {0};
    bool input_panel_show = false;
    input_panel_ctx = wsc_ctx;
    Ise_Context iseContext;

    if (!wsc_ctx || !wsc_ctx->ctx)
        return;

    /* set password mode */
    iseContext.password_mode = wsc_context_input_panel_password_mode_get (wsc_ctx);

    /* set language */
    iseContext.language = wsc_context_input_panel_language_get (wsc_ctx);

    /* set layout in ise context info */
    iseContext.layout = wsc_context_input_panel_layout_get (wsc_ctx);

    /* set layout variation in ise context info */
    iseContext.layout_variation = wsc_context_input_panel_layout_variation_get (wsc_ctx);

    /* set prediction allow */
    iseContext.prediction_allow = wsc_context_prediction_allow_get (wsc_ctx);

    if (iseContext.layout == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD)
        iseContext.password_mode = EINA_TRUE;

    if (iseContext.password_mode)
        iseContext.prediction_allow = EINA_FALSE;

    if (iseContext.layout == ECORE_IMF_INPUT_PANEL_LAYOUT_TERMINAL)
        iseContext.prediction_allow = EINA_FALSE;

    /* set return key type */
    iseContext.return_key_type = (Ecore_IMF_Input_Panel_Return_Key_Type)wsc_ctx->return_key_type;

    /* set return key disabled */
    iseContext.return_key_disabled = wsc_ctx->return_key_disabled;

    /* set caps mode */
    iseContext.caps_mode = wsc_ctx->caps_mode;

    /* set client window */
    iseContext.client_window = 0;

    /* set the size of imdata */
    context_scim_imdata_get (wsc_ctx, (void *)imdata, &iseContext.imdata_size);

    /* set the cursor position of the editable widget */
    wsc_context_surrounding_get (wsc_ctx, NULL, &iseContext.cursor_pos);

    iseContext.autocapital_type = wsc_context_autocapital_type_get (wsc_ctx);

    iseContext.input_hint = wsc_context_input_hint_get (wsc_ctx);

    iseContext.bidi_direction = wsc_context_bidi_direction_get (wsc_ctx);

    LOGD ("ctx : %p, layout : %d, layout variation : %d\n", wsc_ctx, iseContext.layout, iseContext.layout_variation);
    LOGD ("language : %d, cursor position : %d, caps mode : %d\n", iseContext.language, iseContext.cursor_pos, iseContext.caps_mode);
    LOGD ("return_key_type : %d, return_key_disabled : %d, autocapital type : %d\n", iseContext.return_key_type, iseContext.return_key_disabled, iseContext.autocapital_type);
    LOGD ("password mode : %d, prediction_allow : %d\n", iseContext.password_mode, iseContext.prediction_allow);
    LOGD ("input hint : %#x\n", iseContext.input_hint);
    LOGD ("bidi direction : %d\n", iseContext.bidi_direction);

    /* calculate packet size */
    length = sizeof (iseContext);
    length += iseContext.imdata_size;

    /* create packet */
    packet = calloc (1, length);
    if (!packet)
        return;

    memcpy (packet, (void *)&iseContext, sizeof (iseContext));
    memcpy ((void *)((char *)packet + sizeof (iseContext)), (void *)imdata, iseContext.imdata_size);

    int context_id = _get_context_id (wsc_ctx);

    _isf_wsc_context_input_panel_show (get_panel_client_id (), context_id, packet, length, input_panel_show);

    free (packet);

#ifdef HAVE_VCONF
    vconf_set_int (VCONFKEY_ISF_INPUT_PANEL_STATE, VCONFKEY_ISF_INPUT_PANEL_STATE_SHOW);
#endif
}

void isf_wsc_context_input_panel_hide (WSCContextISF *ctx)
{
    int context_id = _get_context_id (ctx);
    _isf_wsc_context_input_panel_hide (get_panel_client_id (), context_id);

#ifdef HAVE_VCONF
    vconf_set_int (VCONFKEY_ISF_INPUT_PANEL_STATE, VCONFKEY_ISF_INPUT_PANEL_STATE_HIDE);
#endif
}

void isf_wsc_context_set_keyboard_mode (WSCContextISF *ctx, TOOLBAR_MODE_T mode)
{
    _support_hw_keyboard_mode = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_SUPPORT_HW_KEYBOARD_MODE), _support_hw_keyboard_mode);

    if (_support_hw_keyboard_mode) {
        kbd_mode = mode;
        SECURE_LOGD ("keyboard mode : %d\n", kbd_mode);
        _isf_wsc_context_set_keyboard_mode (_get_context_id (ctx), mode);
    }
}

void
isf_wsc_context_input_panel_layout_set (WSCContextISF *ctx, Ecore_IMF_Input_Panel_Layout layout)
{
    WSCContextISF *context_scim = ctx;

    if (context_scim == get_focused_ic ()) {
        LOGD ("layout type : %d\n", layout);
        _isf_wsc_context_input_panel_layout_set (_get_context_id (ctx), layout);
    }
}

Ecore_IMF_Input_Panel_Layout isf_wsc_context_input_panel_layout_get (WSCContextISF *ctx)
{
    Ecore_IMF_Input_Panel_Layout layout;
    _isf_wsc_context_input_panel_layout_get (_get_context_id (ctx), &layout);

    return layout;
}

void isf_wsc_context_input_panel_caps_mode_set (WSCContextISF *ctx, unsigned int mode)
{
    LOGD ("ctx : %p, mode : %d\n", ctx, mode);
    _isf_wsc_context_input_panel_caps_mode_set (_get_context_id (ctx), mode);
}

void isf_wsc_context_input_panel_caps_lock_mode_set (WSCContextISF *ctx, Eina_Bool mode)
{
    //FIXME: missing
}

void isf_wsc_context_input_panel_language_set (WSCContextISF *ctx, Ecore_IMF_Input_Panel_Lang language)
{
    WSCContextISF *context_scim = ctx;

    if (context_scim == get_focused_ic ()) {
        LOGD ("language mode : %d\n", language);
        _isf_wsc_context_input_panel_language_set (_get_context_id (ctx), language);
    }
}

void isf_wsc_context_input_panel_return_key_type_set (WSCContextISF *ctx, Ecore_IMF_Input_Panel_Return_Key_Type return_key_type)
{
    LOGD ("ctx : %p, return key type : %d\n", ctx, return_key_type);
    _isf_wsc_context_input_panel_return_key_type_set (_get_context_id (ctx), return_key_type);
}

void isf_wsc_context_input_panel_return_key_disabled_set (WSCContextISF *ctx, Eina_Bool disabled)
{
    LOGD ("ctx : %p, disabled : %d\n", ctx, disabled);
    _isf_wsc_context_input_panel_return_key_disabled_set (_get_context_id (ctx), disabled);
}

void isf_wsc_context_input_panel_imdata_set (WSCContextISF *ctx, const void *imdata, int len)
{
    _isf_wsc_context_input_panel_imdata_set (_get_context_id (ctx), imdata, len);
}

void isf_wsc_context_input_panel_imdata_get (WSCContextISF *ctx, void **imdata, int* len)
{
    _isf_wsc_context_input_panel_imdata_get (_get_context_id (ctx), imdata, len);
}

void isf_wsc_context_process_input_device_event (WSCContextISF *ctx, uint32_t type, const char *data, uint32_t len)
{
    _isf_wsc_context_process_input_device_event (_get_context_id(ctx), type, data, len);
}