[gtk+] Share code to fill GdkEventKey.string
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Share code to fill GdkEventKey.string
- Date: Sat, 5 Feb 2011 02:11:47 +0000 (UTC)
commit 2c352f51a0e5578d300d34211ef20ead6dd793e7
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 4 20:58:41 2011 -0500
Share code to fill GdkEventKey.string
This code was duplicated between the core and XI2 device manager
implementations.
gdk/x11/gdkdevicemanager-core-x11.c | 126 ++++++++++++++++++-----------------
gdk/x11/gdkdevicemanager-xi2.c | 66 +------------------
gdk/x11/gdkprivate-x11.h | 2 +
3 files changed, 69 insertions(+), 125 deletions(-)
---
diff --git a/gdk/x11/gdkdevicemanager-core-x11.c b/gdk/x11/gdkdevicemanager-core-x11.c
index 1533d40..1fcb67d 100644
--- a/gdk/x11/gdkdevicemanager-core-x11.c
+++ b/gdk/x11/gdkdevicemanager-core-x11.c
@@ -145,8 +145,6 @@ translate_key_event (GdkDisplay *display,
{
GdkKeymap *keymap = gdk_keymap_get_for_display (display);
GdkModifierType consumed, state;
- gunichar c = 0;
- gchar buf[7];
event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
event->key.time = xevent->xkey.time;
@@ -171,64 +169,8 @@ translate_key_event (GdkDisplay *display,
event->key.is_modifier = _gdk_x11_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
- /* Fill in event->string crudely, since various programs
- * depend on it.
- */
- event->key.string = NULL;
-
- if (event->key.keyval != GDK_KEY_VoidSymbol)
- c = gdk_keyval_to_unicode (event->key.keyval);
-
- if (c)
- {
- gsize bytes_written;
- gint len;
-
- /* Apply the control key - Taken from Xlib
- */
- if (event->key.state & GDK_CONTROL_MASK)
- {
- if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
- else if (c == '2')
- {
- event->key.string = g_memdup ("\0\0", 2);
- event->key.length = 1;
- buf[0] = '\0';
- goto out;
- }
- else if (c >= '3' && c <= '7') c -= ('3' - '\033');
- else if (c == '8') c = '\177';
- else if (c == '/') c = '_' & 0x1F;
- }
-
- len = g_unichar_to_utf8 (c, buf);
- buf[len] = '\0';
+ _gdk_x11_event_translate_keyboard_string (&event->key);
- event->key.string = g_locale_from_utf8 (buf, len,
- NULL, &bytes_written,
- NULL);
- if (event->key.string)
- event->key.length = bytes_written;
- }
- else if (event->key.keyval == GDK_KEY_Escape)
- {
- event->key.length = 1;
- event->key.string = g_strdup ("\033");
- }
- else if (event->key.keyval == GDK_KEY_Return ||
- event->key.keyval == GDK_KEY_KP_Enter)
- {
- event->key.length = 1;
- event->key.string = g_strdup ("\r");
- }
-
- if (!event->key.string)
- {
- event->key.length = 0;
- event->key.string = g_strdup ("");
- }
-
- out:
#ifdef G_ENABLE_DEBUG
if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
{
@@ -240,7 +182,7 @@ translate_key_event (GdkDisplay *display,
if (event->key.length > 0)
g_message ("\t\tlength: %4d string: \"%s\"",
- event->key.length, buf);
+ event->key.length, event->key.string);
}
#endif /* G_ENABLE_DEBUG */
return;
@@ -906,3 +848,67 @@ gdk_x11_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager
device_manager_core = (GdkX11DeviceManagerCore *) device_manager;
return device_manager_core->core_pointer;
}
+
+void
+_gdk_x11_event_translate_keyboard_string (GdkEventKey *event)
+{
+ gunichar c = 0;
+ gchar buf[7];
+
+ /* Fill in event->string crudely, since various programs
+ * depend on it.
+ */
+ event->string = NULL;
+
+ if (event->keyval != GDK_KEY_VoidSymbol)
+ c = gdk_keyval_to_unicode (event->keyval);
+
+ if (c)
+ {
+ gsize bytes_written;
+ gint len;
+
+ /* Apply the control key - Taken from Xlib
+ */
+ if (event->state & GDK_CONTROL_MASK)
+ {
+ if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
+ else if (c == '2')
+ {
+ event->string = g_memdup ("\0\0", 2);
+ event->length = 1;
+ buf[0] = '\0';
+ return;
+ }
+ else if (c >= '3' && c <= '7') c -= ('3' - '\033');
+ else if (c == '8') c = '\177';
+ else if (c == '/') c = '_' & 0x1F;
+ }
+
+ len = g_unichar_to_utf8 (c, buf);
+ buf[len] = '\0';
+
+ event->string = g_locale_from_utf8 (buf, len,
+ NULL, &bytes_written,
+ NULL);
+ if (event->string)
+ event->length = bytes_written;
+ }
+ else if (event->keyval == GDK_KEY_Escape)
+ {
+ event->length = 1;
+ event->string = g_strdup ("\033");
+ }
+ else if (event->keyval == GDK_KEY_Return ||
+ event->keyval == GDK_KEY_KP_Enter)
+ {
+ event->length = 1;
+ event->string = g_strdup ("\r");
+ }
+
+ if (!event->string)
+ {
+ event->length = 0;
+ event->string = g_strdup ("");
+ }
+}
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 48bb947..33cd1ae 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -709,70 +709,6 @@ set_user_time (GdkEvent *event)
}
static void
-translate_keyboard_string (GdkEventKey *event)
-{
- gunichar c = 0;
- gchar buf[7];
-
- /* Fill in event->string crudely, since various programs
- * depend on it.
- */
- event->string = NULL;
-
- if (event->keyval != GDK_KEY_VoidSymbol)
- c = gdk_keyval_to_unicode (event->keyval);
-
- if (c)
- {
- gsize bytes_written;
- gint len;
-
- /* Apply the control key - Taken from Xlib
- */
- if (event->state & GDK_CONTROL_MASK)
- {
- if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
- else if (c == '2')
- {
- event->string = g_memdup ("\0\0", 2);
- event->length = 1;
- buf[0] = '\0';
- return;
- }
- else if (c >= '3' && c <= '7') c -= ('3' - '\033');
- else if (c == '8') c = '\177';
- else if (c == '/') c = '_' & 0x1F;
- }
-
- len = g_unichar_to_utf8 (c, buf);
- buf[len] = '\0';
-
- event->string = g_locale_from_utf8 (buf, len,
- NULL, &bytes_written,
- NULL);
- if (event->string)
- event->length = bytes_written;
- }
- else if (event->keyval == GDK_KEY_Escape)
- {
- event->length = 1;
- event->string = g_strdup ("\033");
- }
- else if (event->keyval == GDK_KEY_Return ||
- event->keyval == GDK_KEY_KP_Enter)
- {
- event->length = 1;
- event->string = g_strdup ("\r");
- }
-
- if (!event->string)
- {
- event->length = 0;
- event->string = g_strdup ("");
- }
-}
-
-static void
generate_focus_event (GdkWindow *window,
GdkDevice *device,
GdkDevice *source_device,
@@ -1108,7 +1044,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
_gdk_x11_keymap_add_virt_mods (keymap, &state);
event->key.state |= state;
- translate_keyboard_string ((GdkEventKey *) event);
+ _gdk_x11_event_translate_keyboard_string (&event->key);
if (ev->evtype == XI_KeyPress)
set_user_time (event);
diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h
index 322d586..f3b8a8c 100644
--- a/gdk/x11/gdkprivate-x11.h
+++ b/gdk/x11/gdkprivate-x11.h
@@ -243,6 +243,8 @@ guchar * _gdk_x11_device_xi2_translate_event_mask (GdkEventMask event_mask,
guint _gdk_x11_device_xi2_translate_state (XIModifierState *mods_state,
XIButtonState *buttons_state);
+void _gdk_x11_event_translate_keyboard_string (GdkEventKey *event);
+
void _gdk_x11_display_manager_add_display (GdkDisplayManager *manager,
GdkDisplay *display);
void _gdk_x11_display_manager_remove_display (GdkDisplayManager *manager,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]