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
|
/*
* Copyright (C) 2010, Intel Corporation.
*
* Author: Raymond Liu <raymond.liu@intel.com>
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* 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 St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "debug.h"
#include <QEvent>
#include <QKeyEvent>
#include "qt-keysym-map.h"
#include "qt-translate.h"
enum {
ShiftModifier = 1 << 0,
ControlModifier = 1 << 2,
AltModifier = 1 << 3
};
#define SHIFT_MASK 1 << 0)
void meego_im_key_event_decode(MeegoImKeyEvent *e, int type, int key, int modifiers, char *text)
{
g_warn_if_fail(type == QEvent::KeyPress || type == QEvent::KeyRelease);
e->release = type == QEvent::KeyRelease;
e->state = 0;
if (modifiers & Qt::ShiftModifier)
e->state |= ShiftModifier;
if (modifiers & Qt::ControlModifier)
e->state |= ControlModifier;
if (modifiers & Qt::AltModifier)
e->state |= AltModifier;
e->keysym = QtKeyToXKeySym(key);
if (text && strlen(text) > 0) {
e->text = text;
}
}
void meego_im_key_event_encode(const MeegoImKeyEvent *e, int *type, int *key, int *modifiers, char **text)
{
*type = e->release ? QEvent::KeyRelease : QEvent::KeyPress;
*key = XKeySymToQTKey(e->keysym);
*modifiers = Qt::NoModifier;
if (e->state & ShiftModifier)
*modifiers |= Qt::ShiftModifier;
if (e->state & ControlModifier)
*modifiers |= Qt::ControlModifier;
if (e->state & AltModifier)
*modifiers |= Qt::AltModifier;
*text = e->text && strlen(e->text) > 0 ? e->text : NULL;
}
#if 0
GdkEventKey *
compose_gdk_keyevent(GdkEventType type, guint keyval, guint state, GdkWindow *window)
{
GdkEventKey *event = NULL;
#if GTK_CHECK_VERSION (3, 0, 0)
GdkDisplay *display;
GdkDeviceManager *device_manager;
GdkDevice *client_pointer;
#endif
if ((type != GDK_KEY_PRESS) && (type != GDK_KEY_RELEASE))
return NULL;
event = (GdkEventKey *)(gdk_event_new(type));
event->length = 0;
event->string = 0;
event->is_modifier = 0;
event->time = GDK_CURRENT_TIME;
event->state = state;
#if GTK_CHECK_VERSION (3, 0, 0)
display = gdk_window_get_display (window);
device_manager = gdk_display_get_device_manager (display);
client_pointer = gdk_device_manager_get_client_pointer (device_manager);
gdk_event_set_device ((GdkEvent *)event,
gdk_device_get_associated_device (client_pointer));
#endif
if (type == GDK_KEY_RELEASE)
event->state |= GDK_RELEASE_MASK;
event->keyval = keyval;
event->window = window;
if (event->window) {
GdkKeymap *key_map = gdk_keymap_get_default();
GdkKeymapKey *keys;
gint n;
g_object_ref(event->window); // seems when event is freed, the event->window will be unref
if (gdk_keymap_get_entries_for_keyval(key_map, event->keyval, &keys, &n)) {
event->hardware_keycode = keys[0].keycode;
event->group = keys[0].group;
} else {
event->hardware_keycode = 0;
event->group = 0;
}
}
DBG("event type=0x%x, state=0x%x, keyval=0x%x, keycode=0x%x, group=%d",
event->type, event->state, event->keyval, event->hardware_keycode, event->group);
return event;
}
GdkEventKey *
qt_key_event_to_gdk(int type, int key, int modifiers, char *text, GdkWindow *window)
{
Q_UNUSED(text);
guint state = 0;
guint keyval;
STEP();
if ((type != QEvent::KeyPress) && (type != QEvent::KeyRelease))
return NULL;
if (modifiers & Qt::ShiftModifier)
state |= GDK_SHIFT_MASK;
if (modifiers & Qt::ControlModifier)
state |= GDK_CONTROL_MASK;
if (modifiers & Qt::AltModifier)
state |= GDK_MOD1_MASK;
keyval = QtKeyToXKeySym(key);
if (type == QEvent::KeyPress) {
return compose_gdk_keyevent(GDK_KEY_PRESS, keyval, state, window);
} else {
return compose_gdk_keyevent(GDK_KEY_RELEASE, keyval, state, window);
}
}
gboolean
gdk_key_event_to_qt(GdkEventKey *event, int *type, int *key, int *modifier)
{
switch (event->type) {
case GDK_KEY_PRESS:
*type = QEvent::KeyPress;
break;
case GDK_KEY_RELEASE:
*type = QEvent::KeyRelease;
break;
default:
return FALSE;
}
*key = XKeySymToQTKey(event->keyval);
if (*key == Qt::Key_unknown) {
qWarning("Unkonwn key");
return FALSE;
}
*modifier = Qt::NoModifier;
if (event->state & GDK_SHIFT_MASK)
*modifier |= Qt::ShiftModifier;
if (event->state & GDK_CONTROL_MASK)
*modifier |= Qt::ControlModifier;
if (event->state & GDK_MOD1_MASK)
*modifier |= Qt::AltModifier;
if (event->state & GDK_META_MASK)
*modifier |= Qt::MetaModifier;
DBG("qtkey type =%d, qtkey=0x%x, modifier=0x%x", *type, *key, *modifier);
return TRUE;
}
#endif
|