client.c 36.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* 
 * Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
 * Copyright (C) 2010-2011 Red Hat, Inc.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Daiki Ueno's avatar
Daiki Ueno committed
18
19
20
21
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif  /* HAVE_CONFIG_H */

22
#include <libxklavier/xklavier.h>
Daiki Ueno's avatar
Daiki Ueno committed
23

Daiki Ueno's avatar
Daiki Ueno committed
24
25
26
27
#ifdef HAVE_ATSPI
#include <dbus/dbus.h>
#include <atspi/atspi.h>
#endif  /* HAVE_ATSPI */
Daiki Ueno's avatar
Daiki Ueno committed
28

29
30
#include <gdk/gdkx.h>

31
32
#ifdef HAVE_XTEST
#include <X11/extensions/XTest.h>
33
#include <X11/XKBlib.h>
34
#endif  /* HAVE_XTEST */
35

Daiki Ueno's avatar
Daiki Ueno committed
36
37
38
39
#ifdef HAVE_IBUS
#include <ibus.h>
#endif  /* HAVE_IBUS */

40
41
#include "eek/eek.h"
#include "eek/eek-xkl.h"
Daiki Ueno's avatar
Daiki Ueno committed
42
43
#include "eekboard/eekboard-client.h"
#include "eekboard/eekboard-xklutil.h"
44
#include "client.h"
45

46
47
#include <string.h>

48
49
50
51
52
53
#define CSW 640
#define CSH 480

enum {
    PROP_0,
    PROP_CONNECTION,
Daiki Ueno's avatar
Daiki Ueno committed
54
    PROP_EEKBOARD,
55
    PROP_CONTEXT,
56
    PROP_KEYBOARDS,
57
58
59
    PROP_LAST
};

Daiki Ueno's avatar
Daiki Ueno committed
60
typedef struct _ClientClass ClientClass;
61

Daiki Ueno's avatar
Daiki Ueno committed
62
struct _Client {
63
64
    GObject parent;

Daiki Ueno's avatar
Daiki Ueno committed
65
    EekboardClient *eekboard;
66
    EekboardContext *context;
67

Daiki Ueno's avatar
Daiki Ueno committed
68
    GSList *keyboards;
69
70
    GSList *keyboards_head;

71
72
73
    XklEngine *xkl_engine;
    XklConfigRegistry *xkl_config_registry;

74
75
    gulong xkl_config_changed_handler;
    gulong xkl_state_changed_handler;
76

77
    gulong key_activated_handler;
78

Daiki Ueno's avatar
Daiki Ueno committed
79
    gboolean follows_focus;
Daiki Ueno's avatar
Daiki Ueno committed
80
    guint hide_keyboard_timeout_id;
Daiki Ueno's avatar
Daiki Ueno committed
81

Daiki Ueno's avatar
Daiki Ueno committed
82
83
84
85
#ifdef HAVE_ATSPI
    AtspiAccessible *acc;
    AtspiDeviceListener *keystroke_listener;
#endif  /* HAVE_ATSPI */
Daiki Ueno's avatar
Daiki Ueno committed
86

Daiki Ueno's avatar
Daiki Ueno committed
87
88
89
90
91
#ifdef HAVE_IBUS
    IBusBus *ibus_bus;
    guint ibus_focus_message_filter;
#endif  /* HAVE_IBUS */

92
#ifdef HAVE_XTEST
Daiki Ueno's avatar
Daiki Ueno committed
93
    guint modifier_keycodes[8]; 
94
    XkbDescRec *xkb;
Daiki Ueno's avatar
Daiki Ueno committed
95
96
    GSList *replaced_keycodes;
    gulong reset_replaced_keycodes_timeout_handler;
97
#endif  /* HAVE_XTEST */
98
99

    GSettings *settings;
100
101
};

Daiki Ueno's avatar
Daiki Ueno committed
102
struct _ClientClass {
103
104
105
    GObjectClass parent_class;
};

Daiki Ueno's avatar
Daiki Ueno committed
106
G_DEFINE_TYPE (Client, client, G_TYPE_OBJECT);
107

108
109
110
111
112
113
#if ENABLE_FOCUS_LISTENER
#define IS_KEYBOARD_VISIBLE(client) (!client->follows_focus)
#else  /* ENABLE_FOCUS_LISTENER */
#define IS_KEYBOARD_VISIBLE(client) TRUE
#endif  /* !ENABLE_FOCUS_LISTENER */

Daiki Ueno's avatar
Daiki Ueno committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
static GdkFilterReturn filter_xkl_event     (GdkXEvent              *xev,
                                             GdkEvent               *event,
                                             gpointer                user_data);
static void            on_xkl_config_changed (XklEngine              *xklengine,
                                              gpointer                user_data);

static void            on_xkl_state_changed (XklEngine              *xklengine,
                                             XklEngineStateChange    type,
                                             gint                    value,
                                             gboolean                restore,
                                             gpointer                user_data);

#ifdef HAVE_ATSPI
static void            focus_listener_cb    (const AtspiEvent       *event,
                                             void                   *user_data);

static gboolean        keystroke_listener_cb (const AtspiDeviceEvent *stroke,
                                              void                   *user_data);
#endif  /* HAVE_ATSPI */
133
static gboolean        set_keyboards        (Client                 *client,
Daiki Ueno's avatar
Daiki Ueno committed
134
                                             const gchar * const    *keyboard);
135
136
static gboolean        set_keyboards_from_xkl
                                            (Client                 *client);
137
138
#ifdef HAVE_XTEST
static void            update_modifier_keycodes
139
                                            (Client                 *client);
140
#endif  /* HAVE_XTEST */
141
142

static void
Daiki Ueno's avatar
Daiki Ueno committed
143
144
145
146
client_set_property (GObject      *object,
                     guint         prop_id,
                     const GValue *value,
                     GParamSpec   *pspec)
147
{
Daiki Ueno's avatar
Daiki Ueno committed
148
    Client *client = CLIENT(object);
149
150
151
152
153
    GDBusConnection *connection;

    switch (prop_id) {
    case PROP_CONNECTION:
        connection = g_value_get_object (value);
154

Daiki Ueno's avatar
Daiki Ueno committed
155
        client->eekboard = eekboard_client_new (connection, NULL);
Daiki Ueno's avatar
Daiki Ueno committed
156
157
        if (client->eekboard != NULL) {
            client->context =
Daiki Ueno's avatar
Daiki Ueno committed
158
159
160
                eekboard_client_create_context (client->eekboard,
                                                "eekboard",
                                                NULL);
Daiki Ueno's avatar
Daiki Ueno committed
161
162
163
            if (client->context == NULL) {
                g_object_unref (client->eekboard);
                client->eekboard = NULL;
164
            } else {
Daiki Ueno's avatar
Daiki Ueno committed
165
166
167
                eekboard_client_push_context (client->eekboard,
                                              client->context,
                                              NULL);
168
169
170
171
                g_settings_bind (client->settings, "keyboards",
                                 client, "keyboards",
                                 G_SETTINGS_BIND_GET);
            }
Daiki Ueno's avatar
Daiki Ueno committed
172
        }
173
        break;
174
175
176
    case PROP_KEYBOARDS:
        client_set_keyboards (client, g_value_get_boxed (value));
        break;
177
    default:
178
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
179
180
181
182
        break;
    }
}

183
static void
Daiki Ueno's avatar
Daiki Ueno committed
184
185
186
187
client_get_property (GObject    *object,
                     guint       prop_id,
                     GValue     *value,
                     GParamSpec *pspec)
188
{
Daiki Ueno's avatar
Daiki Ueno committed
189
    Client *client = CLIENT(object);
190
191

    switch (prop_id) {
Daiki Ueno's avatar
Daiki Ueno committed
192
193
194
    case PROP_EEKBOARD:
        g_value_set_object (value, client->eekboard);
        break;
195
196
197
198
    case PROP_CONTEXT:
        g_value_set_object (value, client->context);
        break;
    default:
199
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
200
201
202
203
        break;
    }
}

204
static void
Daiki Ueno's avatar
Daiki Ueno committed
205
client_dispose (GObject *object)
206
{
Daiki Ueno's avatar
Daiki Ueno committed
207
    Client *client = CLIENT(object);
208

Daiki Ueno's avatar
Daiki Ueno committed
209
    client_disable_xkl (client);
Daiki Ueno's avatar
Daiki Ueno committed
210

Daiki Ueno's avatar
Daiki Ueno committed
211
#ifdef HAVE_ATSPI
Daiki Ueno's avatar
Daiki Ueno committed
212
213
    client_disable_atspi_focus (client);
    client_disable_atspi_keystroke (client);
Daiki Ueno's avatar
Daiki Ueno committed
214
#endif  /* HAVE_ATSPI */
Daiki Ueno's avatar
Daiki Ueno committed
215

Daiki Ueno's avatar
Daiki Ueno committed
216
#ifdef HAVE_IBUS
Daiki Ueno's avatar
Daiki Ueno committed
217
    client_disable_ibus_focus (client);
Daiki Ueno's avatar
Daiki Ueno committed
218
219
220
221
222
223
    if (client->ibus_bus) {
        g_object_unref (client->ibus_bus);
        client->ibus_bus = NULL;
    }
#endif  /* HAVE_IBUS */

224
#ifdef HAVE_XTEST
Daiki Ueno's avatar
Daiki Ueno committed
225
    client_disable_xtest (client);
226
#endif  /* HAVE_XTEST */
227

228
229
230
231
232
    if (client->context) {
        g_object_unref (client->context);
        client->context = NULL;
    }

233
234
235
    if (client->eekboard) {
        g_object_unref (client->eekboard);
        client->eekboard = NULL;
236
237
    }

238
239
240
241
242
    if (client->settings) {
        g_object_unref (client->settings);
        client->settings = NULL;
    }

Daiki Ueno's avatar
Daiki Ueno committed
243
    G_OBJECT_CLASS (client_parent_class)->dispose (object);
244
245
}

Daiki Ueno's avatar
Daiki Ueno committed
246
247
248
249
250
static void
client_finalize (GObject *object)
{
    Client *client = CLIENT(object);

Daiki Ueno's avatar
Daiki Ueno committed
251
    g_slist_free (client->keyboards);
Daiki Ueno's avatar
Daiki Ueno committed
252
253
254
    G_OBJECT_CLASS (client_parent_class)->finalize (object);
}

255
static void
Daiki Ueno's avatar
Daiki Ueno committed
256
client_class_init (ClientClass *klass)
257
258
259
260
{
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
    GParamSpec *pspec;

Daiki Ueno's avatar
Daiki Ueno committed
261
262
263
    gobject_class->set_property = client_set_property;
    gobject_class->get_property = client_get_property;
    gobject_class->dispose = client_dispose;
Daiki Ueno's avatar
Daiki Ueno committed
264
    gobject_class->finalize = client_finalize;
265
266
267
268
269
270
271
272
273

    pspec = g_param_spec_object ("connection",
                                 "Connection",
                                 "Connection",
                                 G_TYPE_DBUS_CONNECTION,
                                 G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
    g_object_class_install_property (gobject_class,
                                     PROP_CONNECTION,
                                     pspec);
274

Daiki Ueno's avatar
Daiki Ueno committed
275
276
277
    pspec = g_param_spec_object ("eekboard",
                                 "Eekboard",
                                 "Eekboard",
Daiki Ueno's avatar
Daiki Ueno committed
278
                                 EEKBOARD_TYPE_CLIENT,
Daiki Ueno's avatar
Daiki Ueno committed
279
280
281
282
283
                                 G_PARAM_READABLE);
    g_object_class_install_property (gobject_class,
                                     PROP_EEKBOARD,
                                     pspec);

284
285
286
287
288
289
290
291
    pspec = g_param_spec_object ("context",
                                 "Context",
                                 "Context",
                                 EEKBOARD_TYPE_CONTEXT,
                                 G_PARAM_READABLE);
    g_object_class_install_property (gobject_class,
                                     PROP_CONTEXT,
                                     pspec);
292
293
294
295
296
297
298
299
300

    pspec = g_param_spec_boxed ("keyboards",
                                "Keyboards",
                                "Keyboards",
                                G_TYPE_STRV,
                                G_PARAM_WRITABLE);
    g_object_class_install_property (gobject_class,
                                     PROP_KEYBOARDS,
                                     pspec);
301
302
303
}

static void
Daiki Ueno's avatar
Daiki Ueno committed
304
client_init (Client *client)
305
{
306
    client->settings = g_settings_new ("org.fedorahosted.eekboard");
307
308
}

309
gboolean
Daiki Ueno's avatar
Daiki Ueno committed
310
311
client_set_keyboards (Client              *client,
                      const gchar * const *keyboards)
312
313
{
    gboolean retval;
314
    retval = set_keyboards (client, keyboards);
315
    if (retval && IS_KEYBOARD_VISIBLE (client))
316
317
        eekboard_context_show_keyboard (client->context, NULL);
    return retval;
318
319
}

320
gboolean
Daiki Ueno's avatar
Daiki Ueno committed
321
client_enable_xkl (Client *client)
322
{
Daiki Ueno's avatar
Daiki Ueno committed
323
    GdkDisplay *display = gdk_display_get_default ();
324
325
    gboolean retval;

Daiki Ueno's avatar
Daiki Ueno committed
326
    g_assert (display);
327

328
329
    if (!client->xkl_engine) {
        client->xkl_engine =
Daiki Ueno's avatar
Daiki Ueno committed
330
            xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY (display));
331
    }
332
    g_assert (client->xkl_engine);
333
334
335
336
337
338
339

    if (!client->xkl_config_registry) {
        client->xkl_config_registry =
            xkl_config_registry_get_instance (client->xkl_engine);
        xkl_config_registry_load (client->xkl_config_registry, FALSE);
    }

340
    client->xkl_config_changed_handler =
341
342
        g_signal_connect (client->xkl_engine, "X-config-changed",
                          G_CALLBACK(on_xkl_config_changed), client);
343
    client->xkl_state_changed_handler =
344
345
346
347
348
349
350
351
352
353
354
355
        g_signal_connect (client->xkl_engine, "X-state-changed",
                          G_CALLBACK(on_xkl_state_changed), client);

    gdk_window_add_filter (NULL,
                           (GdkFilterFunc) filter_xkl_event,
                           client);
    gdk_window_add_filter (gdk_get_default_root_window (),
                           (GdkFilterFunc) filter_xkl_event,
                           client);

    xkl_engine_start_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);

356
    retval = set_keyboards_from_xkl (client);
357
358
359
360
    if (IS_KEYBOARD_VISIBLE (client))
        eekboard_context_show_keyboard (client->context, NULL);

    return retval;
361
362
363
}

void
Daiki Ueno's avatar
Daiki Ueno committed
364
client_disable_xkl (Client *client)
365
{
366
    if (client->xkl_engine) {
367
        xkl_engine_stop_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
368
369
370
371
372
373
374
375
376
377
378

        if (g_signal_handler_is_connected (client->xkl_engine,
                                           client->xkl_config_changed_handler))
            g_signal_handler_disconnect (client->xkl_engine,
                                         client->xkl_config_changed_handler);
        if (g_signal_handler_is_connected (client->xkl_engine,
                                           client->xkl_state_changed_handler))
            g_signal_handler_disconnect (client->xkl_engine,
                                         client->xkl_state_changed_handler);
        client->xkl_engine = NULL;
    }
379
380
}

Daiki Ueno's avatar
Daiki Ueno committed
381
#ifdef HAVE_ATSPI
382
gboolean
Daiki Ueno's avatar
Daiki Ueno committed
383
client_enable_atspi_focus (Client *client)
384
{
Daiki Ueno's avatar
Daiki Ueno committed
385
    GError *error;
386

Daiki Ueno's avatar
Daiki Ueno committed
387
388
389
390
391
392
    error = NULL;
    if (!atspi_event_listener_register_from_callback
        ((AtspiEventListenerCB)focus_listener_cb,
         client,
         NULL,
         "object:state-changed:focused",
Daiki Ueno's avatar
Daiki Ueno committed
393
394
395
396
         &error)) {
        g_warning ("can't register object:state-changed:focused handler: %s",
                   error->message);
        g_error_free (error);
397
        return FALSE;
Daiki Ueno's avatar
Daiki Ueno committed
398
    }
399

Daiki Ueno's avatar
Daiki Ueno committed
400
401
402
403
404
405
    error = NULL;
    if (!atspi_event_listener_register_from_callback
        ((AtspiEventListenerCB)focus_listener_cb,
         client,
         NULL,
         "focus:",
Daiki Ueno's avatar
Daiki Ueno committed
406
407
408
409
         &error)) {
        g_warning ("can't register focus: handler: %s",
                   error->message);
        g_error_free (error);
410
        return FALSE;
Daiki Ueno's avatar
Daiki Ueno committed
411
    }
412

Daiki Ueno's avatar
Daiki Ueno committed
413
    client->follows_focus = TRUE;
414
415
416
417
    return TRUE;
}

void
Daiki Ueno's avatar
Daiki Ueno committed
418
client_disable_atspi_focus (Client *client)
419
{
Daiki Ueno's avatar
Daiki Ueno committed
420
421
422
423
424
    GError *error;

    client->follows_focus = FALSE;

    error = NULL;
Daiki Ueno's avatar
Daiki Ueno committed
425
    if (!atspi_event_listener_deregister_from_callback
Daiki Ueno's avatar
Daiki Ueno committed
426
427
428
        ((AtspiEventListenerCB)focus_listener_cb,
         client,
         "object:state-changed:focused",
Daiki Ueno's avatar
Daiki Ueno committed
429
430
431
432
433
         &error)) {
        g_warning ("can't deregister object:state-changed:focused handler: %s",
                   error->message);
        g_error_free (error);
    }
Daiki Ueno's avatar
Daiki Ueno committed
434
435

    error = NULL;
Daiki Ueno's avatar
Daiki Ueno committed
436
    if (!atspi_event_listener_deregister_from_callback
Daiki Ueno's avatar
Daiki Ueno committed
437
438
439
        ((AtspiEventListenerCB)focus_listener_cb,
         client,
         "focus:",
Daiki Ueno's avatar
Daiki Ueno committed
440
441
442
443
444
         &error)) {
        g_warning ("can't deregister focus: handler: %s",
                   error->message);
        g_error_free (error);
    }
445
446
447
}

gboolean
Daiki Ueno's avatar
Daiki Ueno committed
448
client_enable_atspi_keystroke (Client *client)
449
{
Daiki Ueno's avatar
Daiki Ueno committed
450
451
    GError *error;

452
    client->keystroke_listener =
Daiki Ueno's avatar
Daiki Ueno committed
453
        atspi_device_listener_new ((AtspiDeviceListenerCB)keystroke_listener_cb,
Daiki Ueno's avatar
Daiki Ueno committed
454
455
                                   client,
                                   NULL);
456

Daiki Ueno's avatar
Daiki Ueno committed
457
458
459
460
461
462
463
    error = NULL;
    if (!atspi_register_keystroke_listener
        (client->keystroke_listener,
         NULL,
         0,
         ATSPI_KEY_PRESSED,
         ATSPI_KEYLISTENER_NOSYNC,
Daiki Ueno's avatar
Daiki Ueno committed
464
465
466
467
         &error)) {
        g_warning ("can't register keystroke listener for key press: %s",
                   error->message);
        g_error_free (error);
Daiki Ueno's avatar
Daiki Ueno committed
468
        return FALSE;
Daiki Ueno's avatar
Daiki Ueno committed
469
    }
Daiki Ueno's avatar
Daiki Ueno committed
470
471
472

    error = NULL;
    if (!atspi_register_keystroke_listener
473
        (client->keystroke_listener,
Daiki Ueno's avatar
Daiki Ueno committed
474
         NULL,
475
         0,
Daiki Ueno's avatar
Daiki Ueno committed
476
477
         ATSPI_KEY_RELEASED,
         ATSPI_KEYLISTENER_NOSYNC,
Daiki Ueno's avatar
Daiki Ueno committed
478
479
480
481
         &error)) {
        g_warning ("can't register keystroke listener for key release: %s",
                   error->message);
        g_error_free (error);
482
        return FALSE;
Daiki Ueno's avatar
Daiki Ueno committed
483
    }
484
485
486
487
    return TRUE;
}

void
Daiki Ueno's avatar
Daiki Ueno committed
488
client_disable_atspi_keystroke (Client *client)
489
490
{
    if (client->keystroke_listener) {
Daiki Ueno's avatar
Daiki Ueno committed
491
492
493
        GError *error;

        error = NULL;
Daiki Ueno's avatar
Daiki Ueno committed
494
495
496
497
498
499
500
501
502
503
        if (!atspi_deregister_keystroke_listener
            (client->keystroke_listener,
             NULL,
             0,
             ATSPI_KEY_PRESSED,
             &error)) {
            g_warning ("can't deregister keystroke listener for key press: %s",
                       error->message);
            g_error_free (error);
        }
Daiki Ueno's avatar
Daiki Ueno committed
504
505

        error = NULL;
Daiki Ueno's avatar
Daiki Ueno committed
506
507
508
509
510
511
512
513
514
        if (!atspi_deregister_keystroke_listener (client->keystroke_listener,
                                                  NULL,
                                                  0,
                                                  ATSPI_KEY_RELEASED,
                                                  &error)) {
            g_warning ("can't deregister keystroke listener for key release: %s",
                       error->message);
            g_error_free (error);
        }
Daiki Ueno's avatar
Daiki Ueno committed
515
516

        g_object_unref (client->keystroke_listener);
517
518
519
520
        client->keystroke_listener = NULL;
    }
}

Daiki Ueno's avatar
Daiki Ueno committed
521
522
523
static void
focus_listener_cb (const AtspiEvent *event,
                   void             *user_data)
524
{
Daiki Ueno's avatar
Daiki Ueno committed
525
    Client *client = user_data;
Daiki Ueno's avatar
Daiki Ueno committed
526
527
528
529
530
531
532
    AtspiAccessible *accessible = event->source;
    AtspiStateSet *state_set = atspi_accessible_get_state_set (accessible);
    AtspiRole role;
    GError *error;

    error = NULL;
    role = atspi_accessible_get_role (accessible, &error);
Daiki Ueno's avatar
Daiki Ueno committed
533
    if (role == ATSPI_ROLE_INVALID) {
Daiki Ueno's avatar
Daiki Ueno committed
534
535
536
        g_warning ("can't get accessible role: %s",
                   error->message);
        g_error_free (error);
Daiki Ueno's avatar
Daiki Ueno committed
537
        return;
Daiki Ueno's avatar
Daiki Ueno committed
538
    }
539

Daiki Ueno's avatar
Daiki Ueno committed
540
541
    if (atspi_state_set_contains (state_set, ATSPI_STATE_EDITABLE) ||
        role == ATSPI_ROLE_TERMINAL) {
542
        switch (role) {
Daiki Ueno's avatar
Daiki Ueno committed
543
544
545
546
        case ATSPI_ROLE_TEXT:
        case ATSPI_ROLE_PARAGRAPH:
        case ATSPI_ROLE_PASSWORD_TEXT:
        case ATSPI_ROLE_TERMINAL:
Daiki Ueno's avatar
Daiki Ueno committed
547
548
549
            if (strncmp (event->type, "focus", 5) == 0 || event->detail1 == 1) {
                client->acc = accessible;
                eekboard_context_show_keyboard (client->context, NULL);
550
551
            } else if (g_settings_get_boolean (client->settings, "auto-hide") &&
                       event->detail1 == 0 && accessible == client->acc) {
Daiki Ueno's avatar
Daiki Ueno committed
552
553
554
555
                client->acc = NULL;
                eekboard_context_hide_keyboard (client->context, NULL);
            }
            break;
Daiki Ueno's avatar
Daiki Ueno committed
556
        case ATSPI_ROLE_ENTRY:
Daiki Ueno's avatar
Daiki Ueno committed
557
558
            if (strncmp (event->type, "focus", 5) == 0 || event->detail1 == 1) {
                client->acc = accessible;
559
                eekboard_context_show_keyboard (client->context, NULL);
560
561
            } else if (g_settings_get_boolean (client->settings, "auto-hide") &&
                       event->detail1 == 0) {
Daiki Ueno's avatar
Daiki Ueno committed
562
563
                client->acc = NULL;
                eekboard_context_hide_keyboard (client->context, NULL);
564
            }
Daiki Ueno's avatar
Daiki Ueno committed
565
566
            break;
            
567
568
569
        default:
            ;
        }
570
571
572
    } else {
        eekboard_context_hide_keyboard (client->context, NULL);
    }
573
574
}

Daiki Ueno's avatar
Daiki Ueno committed
575
576
577
static gboolean
keystroke_listener_cb (const AtspiDeviceEvent *stroke,
                       void                   *user_data)
578
{
Daiki Ueno's avatar
Daiki Ueno committed
579
    Client *client = user_data;
580

581
582
    switch (stroke->type) {
    case ATSPI_KEY_PRESSED:
Daiki Ueno's avatar
Daiki Ueno committed
583
        eekboard_context_press_keycode (client->context, stroke->hw_code, NULL);
584
585
        break;
    case ATSPI_KEY_RELEASED:
Daiki Ueno's avatar
Daiki Ueno committed
586
        eekboard_context_release_keycode (client->context, stroke->hw_code, NULL);
587
588
589
        break;
    default:
        g_return_val_if_reached (FALSE);
590
    }
591
592
    return TRUE;
}
Daiki Ueno's avatar
Daiki Ueno committed
593
#endif  /* HAVE_ATSPI */
Daiki Ueno's avatar
Daiki Ueno committed
594

Daiki Ueno's avatar
Daiki Ueno committed
595
596
597
598
599
#ifdef HAVE_IBUS
static void
add_match_rule (GDBusConnection *connection,
                const gchar     *match_rule)
{
Daiki Ueno's avatar
Daiki Ueno committed
600
601
    GError *error;
    GDBusMessage *message;
Daiki Ueno's avatar
Daiki Ueno committed
602

Daiki Ueno's avatar
Daiki Ueno committed
603
604
605
606
607
608
    message = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
                                              "/org/freedesktop/DBus", /* path */
                                              "org.freedesktop.DBus", /* interface */
                                              "AddMatch");
    g_dbus_message_set_body (message, g_variant_new ("(s)", match_rule));
    error = NULL;
Daiki Ueno's avatar
Daiki Ueno committed
609
610
611
612
613
614
615
616
617
    if (!g_dbus_connection_send_message (connection,
                                         message,
                                         G_DBUS_SEND_MESSAGE_FLAGS_NONE,
                                         NULL,
                                         &error)) {
        g_warning ("can't register match rule %s: %s",
                   match_rule, error->message);
        g_error_free (error);
    }
Daiki Ueno's avatar
Daiki Ueno committed
618
    g_object_unref (message);
Daiki Ueno's avatar
Daiki Ueno committed
619
620
}

Daiki Ueno's avatar
Daiki Ueno committed
621
static gboolean
Daiki Ueno's avatar
Daiki Ueno committed
622
on_hide_keyboard_timeout (Client *client)
Daiki Ueno's avatar
Daiki Ueno committed
623
624
625
626
627
628
{
    eekboard_context_hide_keyboard (client->context, NULL);
    client->hide_keyboard_timeout_id = 0;
    return FALSE;
}

Daiki Ueno's avatar
Daiki Ueno committed
629
630
631
632
633
634
static GDBusMessage *
focus_message_filter (GDBusConnection *connection,
                      GDBusMessage    *message,
                      gboolean         incoming,
                      gpointer         user_data)
{
Daiki Ueno's avatar
Daiki Ueno committed
635
    Client *client = user_data;
Daiki Ueno's avatar
Daiki Ueno committed
636
637
638

    if (incoming &&
        g_strcmp0 (g_dbus_message_get_interface (message),
639
                   IBUS_INTERFACE_PANEL) == 0) {
Daiki Ueno's avatar
Daiki Ueno committed
640
641
642
        const gchar *member = g_dbus_message_get_member (message);

        if (g_strcmp0 (member, "FocusIn") == 0) {
Daiki Ueno's avatar
Daiki Ueno committed
643
644
645
646
            if (client->hide_keyboard_timeout_id > 0) {
                g_source_remove (client->hide_keyboard_timeout_id);
                client->hide_keyboard_timeout_id = 0;
            }
Daiki Ueno's avatar
Daiki Ueno committed
647
            eekboard_context_show_keyboard (client->context, NULL);
648
649
        } else if (g_settings_get_boolean (client->settings, "auto-hide") &&
                   g_strcmp0 (member, "FocusOut") == 0) {
650
651
            guint delay;
            g_settings_get (client->settings, "auto-hide-delay", "u", &delay);
Daiki Ueno's avatar
Daiki Ueno committed
652
            client->hide_keyboard_timeout_id =
653
                g_timeout_add (delay,
Daiki Ueno's avatar
Daiki Ueno committed
654
655
                               (GSourceFunc)on_hide_keyboard_timeout,
                               client);
Daiki Ueno's avatar
Daiki Ueno committed
656
657
658
659
660
661
        }
    }

    return message;
}

662
663
static void
_ibus_connect_focus_handlers (IBusBus *bus, gpointer user_data)
Daiki Ueno's avatar
Daiki Ueno committed
664
{
Daiki Ueno's avatar
Daiki Ueno committed
665
    Client *client = user_data;
Daiki Ueno's avatar
Daiki Ueno committed
666
667
    GDBusConnection *connection;

668
    connection = ibus_bus_get_connection (bus);
Daiki Ueno's avatar
Daiki Ueno committed
669
670
    add_match_rule (connection,
                    "type='method_call',"
671
                    "interface='" IBUS_INTERFACE_PANEL "',"
Daiki Ueno's avatar
Daiki Ueno committed
672
                    "member='FocusIn'");
673
674
    add_match_rule (connection,
                    "type='method_call',"
675
                    "interface='" IBUS_INTERFACE_PANEL "',"
676
                    "member='FocusOut'");
Daiki Ueno's avatar
Daiki Ueno committed
677
678
679
680
681
    client->ibus_focus_message_filter =
        g_dbus_connection_add_filter (connection,
                                      focus_message_filter,
                                      client,
                                      NULL);
682
683
684
}

gboolean
Daiki Ueno's avatar
Daiki Ueno committed
685
client_enable_ibus_focus (Client *client)
686
687
688
689
690
691
692
693
694
695
696
697
{
    if (!client->ibus_bus) {
        client->ibus_bus = ibus_bus_new ();
        g_object_ref (client->ibus_bus);
        g_signal_connect (client->ibus_bus, "connected",
                          G_CALLBACK(_ibus_connect_focus_handlers),
                          client);
    }

    if (ibus_bus_is_connected (client->ibus_bus))
        _ibus_connect_focus_handlers (client->ibus_bus, client);

Daiki Ueno's avatar
Daiki Ueno committed
698
699
700
701
702
    client->follows_focus = TRUE;
    return TRUE;
}

void
Daiki Ueno's avatar
Daiki Ueno committed
703
client_disable_ibus_focus (Client *client)
Daiki Ueno's avatar
Daiki Ueno committed
704
705
706
707
708
{
    GDBusConnection *connection;

    client->follows_focus = FALSE;

709
710
711
712
713
714
715
716
717
    if (client->ibus_bus) {
        if (client->ibus_focus_message_filter != 0) {
            connection = ibus_bus_get_connection (client->ibus_bus);
            g_dbus_connection_remove_filter (connection,
                                             client->ibus_focus_message_filter);
        }
        g_object_unref (client->ibus_bus);
        client->ibus_bus = NULL;
    }
Daiki Ueno's avatar
Daiki Ueno committed
718
719
720
}
#endif  /* HAVE_ATSPI */

Daiki Ueno's avatar
Daiki Ueno committed
721
722
Client *
client_new (GDBusConnection *connection)
Daiki Ueno's avatar
Daiki Ueno committed
723
{
Daiki Ueno's avatar
Daiki Ueno committed
724
725
726
    Client *client = g_object_new (TYPE_CLIENT,
                                   "connection", connection,
                                   NULL);
Daiki Ueno's avatar
Daiki Ueno committed
727
728
729
    if (client->context)
        return client;
    return NULL;
Daiki Ueno's avatar
Daiki Ueno committed
730
}
731
732
733
734
735
736

static GdkFilterReturn
filter_xkl_event (GdkXEvent *xev,
                  GdkEvent  *event,
                  gpointer   user_data)
{
Daiki Ueno's avatar
Daiki Ueno committed
737
    Client *client = user_data;
738
739
740
741
742
743
744
745
746
747
    XEvent *xevent = (XEvent *)xev;

    xkl_engine_filter_events (client->xkl_engine, xevent);
    return GDK_FILTER_CONTINUE;
}

static void
on_xkl_config_changed (XklEngine *xklengine,
                       gpointer   user_data)
{
Daiki Ueno's avatar
Daiki Ueno committed
748
    Client *client = user_data;
749
    gboolean retval;
750

751
    retval = set_keyboards_from_xkl (client);
752
    g_return_if_fail (retval);
753

754
#ifdef HAVE_XTEST
755
    update_modifier_keycodes (client);
756
#endif  /* HAVE_XTEST */
757
758
}

759
static gboolean
Daiki Ueno's avatar
Daiki Ueno committed
760
761
set_keyboards (Client              *client,
               const gchar * const *keyboards)
762
{
763
    guint keyboard_id;
Daiki Ueno's avatar
Daiki Ueno committed
764
    const gchar * const *p;
765
766
767
768
    GSList *head;

    g_return_val_if_fail (keyboards != NULL, FALSE);
    g_return_val_if_fail (client->context, FALSE);
Daiki Ueno's avatar
Daiki Ueno committed
769

770
771
772
773
774
775
    if (client->keyboards) {
        for (head = client->keyboards; head; head = head->next) {
            eekboard_context_remove_keyboard (client->context,
                                              GPOINTER_TO_UINT(head->data),
                                              NULL);
        }
Daiki Ueno's avatar
Daiki Ueno committed
776
        g_slist_free (client->keyboards);
777
778
        client->keyboards = NULL;
    }
779

780
781
782
783
    for (p = keyboards; *p != NULL; p++) {
        keyboard_id = eekboard_context_add_keyboard (client->context, *p, NULL);
        if (keyboard_id == 0) {
            g_slist_free (head);
Daiki Ueno's avatar
Daiki Ueno committed
784
            return FALSE;
785
        }
786
787
        client->keyboards = g_slist_prepend (client->keyboards,
                                             GUINT_TO_POINTER(keyboard_id));
Daiki Ueno's avatar
Daiki Ueno committed
788
789
    }

790
791
    client->keyboards = g_slist_reverse (client->keyboards);
    client->keyboards_head = client->keyboards;
Daiki Ueno's avatar
Daiki Ueno committed
792
793
794

    /* select the first keyboard */
    eekboard_context_set_keyboard (client->context,
795
                                   GPOINTER_TO_UINT(client->keyboards_head->data),
Daiki Ueno's avatar
Daiki Ueno committed
796
                                   NULL);
Daiki Ueno's avatar
Daiki Ueno committed
797
798
799
    return TRUE;
}

800
static gboolean
801
set_keyboards_from_xkl (Client *client)
802
803
804
{
    XklConfigRec *rec;
    gchar *layout, *keyboard;
Daiki Ueno's avatar
Daiki Ueno committed
805
    guint keyboard_id;
806
807
808
809
810
811
812
813

    rec = xkl_config_rec_new ();
    xkl_config_rec_get_from_server (rec, client->xkl_engine);
    layout = eekboard_xkl_config_rec_to_string (rec);
    g_object_unref (rec);

    keyboard = g_strdup_printf ("xkb:%s", layout);
    g_free (layout);
Daiki Ueno's avatar
Daiki Ueno committed
814
815
816
817

    keyboard_id = eekboard_context_add_keyboard (client->context,
                                                 keyboard,
                                                 NULL);
818
    g_free (keyboard);
Daiki Ueno's avatar
Daiki Ueno committed
819
820
821
    if (keyboard_id == 0)
        return FALSE;
    eekboard_context_set_keyboard (client->context, keyboard_id, NULL);
822

Daiki Ueno's avatar
Daiki Ueno committed
823
    return TRUE;
824
825
}

826
827
828
829
830
831
832
static void
on_xkl_state_changed (XklEngine           *xklengine,
                      XklEngineStateChange type,
                      gint                 value,
                      gboolean             restore,
                      gpointer             user_data)
{
Daiki Ueno's avatar
Daiki Ueno committed
833
    Client *client = user_data;
834

835
836
    if (type == GROUP_CHANGED)
        eekboard_context_set_group (client->context, value, NULL);
837
838
}

839
#ifdef HAVE_XTEST
Daiki Ueno's avatar
Daiki Ueno committed
840
841
842
843
844
845
846
847
848
849
850
851
852
struct _KeycodeReplacement {
    guint keycode;
    guint new_keysym;
    guint old_keysym;
};
typedef struct _KeycodeReplacement KeycodeReplacement;

static void
keycode_replacement_free (KeycodeReplacement *replacement)
{
    g_slice_free (KeycodeReplacement, replacement);
}

853
854
855
856
857
858
859
860
/* The following functions for keyboard mapping change are direct
   translation of the code in Caribou (in libcaribou/xadapter.vala):

   - get_replaced_keycode (Caribou: get_reserved_keycode)
   - replace_keycode
   - get_keycode_from_gdk_keymap (Caribou: best_keycode_keyval_match)
*/
static guint
Daiki Ueno's avatar
Daiki Ueno committed
861
get_replaced_keycode (Client *client)
862
{
Daiki Ueno's avatar
Daiki Ueno committed
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
    guint keycode;

    for (keycode = client->xkb->max_key_code;
         keycode >= client->xkb->min_key_code;
         --keycode) {
        guint offset = client->xkb->map->key_sym_map[keycode].offset;
        if (client->xkb->map->key_sym_map[keycode].kt_index[0] == XkbOneLevelIndex &&
            client->xkb->map->syms[offset] != NoSymbol) {
            GSList *head;
            for (head = client->replaced_keycodes; head; head = head->next) {
                KeycodeReplacement *replacement = head->data;
                if (replacement->keycode == keycode)
                    break;
            }
            if (head == NULL)
                return keycode;
        }
    }
881

Daiki Ueno's avatar
Daiki Ueno committed
882
    return 0;
883
884
885
886
887
888
889
890
891
892
}

/* Replace keysym assigned to KEYCODE to KEYSYM.  Both args are used
   as in-out.  If KEYCODE points to 0, this function picks a keycode
   from the current map and replace the associated keysym to KEYSYM.
   In that case, the replaced keycode is stored in KEYCODE and the old
   keysym is stored in KEYSYM.  If otherwise (KEYCODE points to
   non-zero keycode), it simply changes the current map with the
   specified KEYCODE and KEYSYM. */
static gboolean
Daiki Ueno's avatar
Daiki Ueno committed
893
replace_keycode (Client *client,
Daiki Ueno's avatar
Daiki Ueno committed
894
895
                 guint   keycode,
                 guint  *keysym)
896
{
Daiki Ueno's avatar
Daiki Ueno committed
897
898
    GdkDisplay *display = gdk_display_get_default ();
    Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
899
900
    guint offset;
    XkbMapChangesRec changes;
Daiki Ueno's avatar
Daiki Ueno committed
901
    guint old_keysym;
902

Daiki Ueno's avatar
Daiki Ueno committed
903
904
905
906
    g_return_val_if_fail (client->xkb->min_key_code <= keycode &&
                          client->xkb->max_key_code,
                          FALSE);
    g_return_val_if_fail (keysym != NULL, FALSE);
907

Daiki Ueno's avatar
Daiki Ueno committed
908
909
    offset = client->xkb->map->key_sym_map[keycode].offset;
    old_keysym = client->xkb->map->syms[offset];
910
911
912
    client->xkb->map->syms[offset] = *keysym;

    changes.changed = XkbKeySymsMask;
Daiki Ueno's avatar
Daiki Ueno committed
913
    changes.first_key_sym = keycode;
914
915
    changes.num_key_syms = 1;

Daiki Ueno's avatar
Daiki Ueno committed
916
    XkbChangeMap (xdisplay, client->xkb, &changes);
Daiki Ueno's avatar
Daiki Ueno committed
917
    XSync (xdisplay, False);
918

Daiki Ueno's avatar
Daiki Ueno committed
919
    *keysym = old_keysym;
920
921
922
923
924

    return TRUE;
}

static gboolean
Daiki Ueno's avatar
Daiki Ueno committed
925
get_keycode_from_gdk_keymap (Client *client,
926
927
928
929
930
                             guint           keysym,
                             guint          *keycode,
                             guint          *modifiers)
{
    GdkKeymap *keymap = gdk_keymap_get_default ();
Daiki Ueno's avatar
Daiki Ueno committed
931
    GdkKeymapKey *keys, *best_match = NULL;
932
933
934
935
936
937
    gint n_keys, i;

    if (!gdk_keymap_get_entries_for_keyval (keymap, keysym, &keys, &n_keys))
        return FALSE;

    for (i = 0; i < n_keys; i++)
938
        if (keys[i].group == eekboard_context_get_group (client->context, NULL))
939
940
            best_match = &keys[i];

Daiki Ueno's avatar
Daiki Ueno committed
941
942
943
944
945
    if (!best_match) {
        g_free (keys);
        return FALSE;
    }

946
947
948
949
950
951
952
    *keycode = best_match->keycode;
    *modifiers = best_match->level == 1 ? EEK_SHIFT_MASK : 0;

    g_free (keys);
    return TRUE;
}

953
static void
Daiki Ueno's avatar
Daiki Ueno committed
954
send_fake_modifier_key_event (Client         *client,
955
956
                              EekModifierType modifiers,
                              gboolean        is_pressed)
Daiki Ueno's avatar
Daiki Ueno committed
957
{
Daiki Ueno's avatar
Daiki Ueno committed
958
    GdkDisplay *display = gdk_display_get_default ();
959
    gint i;
Daiki Ueno's avatar
Daiki Ueno committed
960

961
962
963
    for (i = 0; i < G_N_ELEMENTS(client->modifier_keycodes); i++) {
        if (modifiers & (1 << i)) {
            guint keycode = client->modifier_keycodes[i];
Daiki Ueno's avatar
Daiki Ueno committed
964

965
966
            g_return_if_fail (keycode > 0);

Daiki Ueno's avatar
Daiki Ueno committed
967
            XTestFakeKeyEvent (GDK_DISPLAY_XDISPLAY (display),
968
969
970
971
972
973
974
                               keycode,
                               is_pressed,
                               CurrentTime);
        }
    }
}

Daiki Ueno's avatar
Daiki Ueno committed
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
static gboolean
reset_replaced_keycodes (gpointer data)
{
    Client *client = data;
    GSList *head;

    for (head = client->replaced_keycodes; head; head = head->next) {
        KeycodeReplacement *replacement = head->data;
        guint keysym = replacement->old_keysym;
        replace_keycode (client, replacement->keycode, &keysym);
    }
    g_slist_free_full (client->replaced_keycodes,
                       (GDestroyNotify) keycode_replacement_free);
    client->replaced_keycodes = NULL;
    client->reset_replaced_keycodes_timeout_handler = 0;
    return FALSE;
}

993
static void
Daiki Ueno's avatar
Daiki Ueno committed
994
995
996
997
send_fake_key_event (Client  *client,
                     guint    xkeysym,
                     guint    keyboard_modifiers,
                     gboolean is_pressed)
998
{
Daiki Ueno's avatar
Daiki Ueno committed
999
    GdkDisplay *display = gdk_display_get_default ();
Daiki Ueno's avatar
Daiki Ueno committed
1000
    Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1001
    EekModifierType modifiers;
Daiki Ueno's avatar
Daiki Ueno committed
1002
1003
1004
    guint keycode;
    guint old_keysym = 0;
    GSList *head;
1005
1006
1007

    g_return_if_fail (xkeysym > 0);

Daiki Ueno's avatar
Daiki Ueno committed
1008
1009
1010
1011
1012
1013
1014
1015
1016
    keycode = 0;
    for (head = client->replaced_keycodes; head; head = head->next) {
        KeycodeReplacement *replacement = head->data;
        if (replacement->new_keysym == xkeysym) {
            keycode = replacement->keycode;
            break;
        }
    }

1017
    modifiers = 0;
Daiki Ueno's avatar
Daiki Ueno committed
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
    if (keycode == 0) {
        if (!get_keycode_from_gdk_keymap (client, xkeysym, &keycode, &modifiers)) {
            KeycodeReplacement *replacement;

            keycode = get_replaced_keycode (client);
            if (keycode == 0) {
                g_warning ("no available keycode to replace");
                return;
            }

            old_keysym = xkeysym;
            if (!replace_keycode (client, keycode, &old_keysym)) {
                g_warning ("failed to lookup X keysym %X", xkeysym);
                return;
            }

            replacement = g_slice_new0 (KeycodeReplacement);
            replacement->keycode = keycode;
            replacement->new_keysym = xkeysym;
            replacement->old_keysym = old_keysym;
            client->replaced_keycodes =
                g_slist_prepend (client->replaced_keycodes, replacement);
1040
        }
1041
    }
Daiki Ueno's avatar
Daiki Ueno committed
1042

1043
1044
1045
    /* Clear level shift modifiers */
    keyboard_modifiers &= ~EEK_SHIFT_MASK;
    keyboard_modifiers &= ~EEK_LOCK_MASK;
Daiki Ueno's avatar
Daiki Ueno committed
1046
    /* FIXME: may need to remap ISO_Level3_Shift and NumLock */
Daiki Ueno's avatar
Daiki Ueno committed
1047
1048
1049
1050
1051
#if 0
    keyboard_modifiers &= ~EEK_MOD5_MASK;
    keyboard_modifiers &= ~client->alt_gr_mask;
    keyboard_modifiers &= ~client->num_lock_mask;
#endif
1052
1053

    modifiers |= keyboard_modifiers;
1054
1055

    send_fake_modifier_key_event (client, modifiers, is_pressed);
Daiki Ueno's avatar
Daiki Ueno committed
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
    XTestFakeKeyEvent (xdisplay, keycode, is_pressed, CurrentTime);

    if (client->reset_replaced_keycodes_timeout_handler == 0 &&
        old_keysym != 0) {
        /* Queue a timer to restore the old keycode.  Ugly, but
         * required due to races / asynchronous X delivery.  Long-term
         * fix is to extend the X keymap here instead of replace
         * entries. */
        client->reset_replaced_keycodes_timeout_handler =
            g_timeout_add (500, reset_replaced_keycodes, client);
    }
Daiki Ueno's avatar
Daiki Ueno committed
1067
1068
}

Daiki Ueno's avatar
Daiki Ueno committed
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
static void
send_fake_key_events (Client    *client,
                      EekSymbol *symbol,
                      guint      keyboard_modifiers)
{
    /* Ignore modifier keys */
    if (eek_symbol_is_modifier (symbol))
        return;

    /* If symbol is a text, convert chars in it to keysym */
    if (EEK_IS_TEXT(symbol)) {
Daiki Ueno's avatar
Daiki Ueno committed
1080
        const gchar *utf8 = eek_text_get_text (EEK_TEXT(symbol));
Daiki Ueno's avatar
Daiki Ueno committed
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
        glong items_written;
        gunichar *ucs4 = g_utf8_to_ucs4_fast (utf8, -1, &items_written);
        gint i;

        for (i = 0; i < items_written; i++) {
            guint xkeysym;
            EekKeysym *keysym;
            gchar *name;

            name = g_strdup_printf ("U%04X", ucs4[i]);
            xkeysym = XStringToKeysym (name);
            g_free (name);

            keysym = eek_keysym_new (xkeysym);
            send_fake_key_events (client,
                                  EEK_SYMBOL(keysym),
                                  keyboard_modifiers);
        }
        g_free (ucs4);
        return;
    }

Daiki Ueno's avatar
Daiki Ueno committed
1103
1104
1105
1106
1107
    if (EEK_IS_KEYSYM(symbol)) {
        guint xkeysym = eek_keysym_get_xkeysym (EEK_KEYSYM(symbol));
        send_fake_key_event (client, xkeysym, keyboard_modifiers, TRUE);
        send_fake_key_event (client, xkeysym, keyboard_modifiers, FALSE);
    }
Daiki Ueno's avatar
Daiki Ueno committed
1108
1109
}

1110
static void
1111
1112
1113
1114
1115
on_key_activated (EekboardContext *context,
                  guint            keycode,
                  EekSymbol       *symbol,
                  guint            modifiers,
                  gpointer         user_data)
1116
{
Daiki Ueno's avatar
Daiki Ueno committed
1117
    Client *client = user_data;
Daiki Ueno's avatar
Daiki Ueno committed
1118
1119

    if (g_strcmp0 (eek_symbol_get_name (symbol), "cycle-keyboard") == 0) {