1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 /* ibus
3 * Copyright (C) 2008-2015 Peng Huang <shawn.p.huang@gmail.com>
4 * Copyright (C) 2008-2015 Red Hat, Inc.
5 *
6 * gdk-private.c: Copied some code from gtk2
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 * USA
22 */
23
24 #include "config.h"
25
26 #include <gtk/gtk.h>
27 #include <gdk/gdkx.h>
28 #include <gdk/gdkkeysyms.h>
29
30 #ifdef HAVE_X11_XKBLIB_H
31 # define HAVE_XKB
32 # include <X11/XKBlib.h>
33 #endif
34
35 void
translate_key_event(GdkDisplay * display,GdkEvent * event,XEvent * xevent)36 translate_key_event (GdkDisplay *display,
37 GdkEvent *event,
38 XEvent *xevent)
39 {
40 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
41
42 event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
43 event->key.time = xevent->xkey.time;
44
45 event->key.state = (GdkModifierType) xevent->xkey.state;
46
47 #ifdef HAVE_XKB
48 event->key.group = XkbGroupForCoreState (xevent->xkey.state);
49 #else
50 event->key.group = 0;
51 #endif
52
53 event->key.hardware_keycode = xevent->xkey.keycode;
54
55 #if GTK_CHECK_VERSION(3, 0, 0)
56 event->key.keyval = GDK_KEY_VoidSymbol;
57 #else
58 event->key.keyval = GDK_VoidSymbol;
59 #endif
60
61 gdk_keymap_translate_keyboard_state (keymap,
62 event->key.hardware_keycode,
63 event->key.state,
64 event->key.group,
65 &event->key.keyval,
66 NULL, NULL, NULL);
67 event->key.is_modifier = 0;
68
69 /* Fill in event->string crudely, since various programs
70 * depend on it.
71 */
72 event->key.string = NULL;
73 event->key.length = 0;
74
75 return;
76 }
77
78