forked from AuroraMiddleware/gtk
Share code to fill GdkEventKey.string
This code was duplicated between the core and XI2 device manager implementations.
This commit is contained in:
parent
4960a81082
commit
2c352f51a0
@ -145,8 +145,6 @@ translate_key_event (GdkDisplay *display,
|
|||||||
{
|
{
|
||||||
GdkKeymap *keymap = gdk_keymap_get_for_display (display);
|
GdkKeymap *keymap = gdk_keymap_get_for_display (display);
|
||||||
GdkModifierType consumed, state;
|
GdkModifierType consumed, state;
|
||||||
gunichar c = 0;
|
|
||||||
gchar buf[7];
|
|
||||||
|
|
||||||
event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
|
event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
|
||||||
event->key.time = xevent->xkey.time;
|
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);
|
event->key.is_modifier = _gdk_x11_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
|
||||||
|
|
||||||
/* Fill in event->string crudely, since various programs
|
_gdk_x11_event_translate_keyboard_string (&event->key);
|
||||||
* 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';
|
|
||||||
|
|
||||||
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
|
#ifdef G_ENABLE_DEBUG
|
||||||
if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
|
if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
|
||||||
{
|
{
|
||||||
@ -240,7 +182,7 @@ translate_key_event (GdkDisplay *display,
|
|||||||
|
|
||||||
if (event->key.length > 0)
|
if (event->key.length > 0)
|
||||||
g_message ("\t\tlength: %4d string: \"%s\"",
|
g_message ("\t\tlength: %4d string: \"%s\"",
|
||||||
event->key.length, buf);
|
event->key.length, event->key.string);
|
||||||
}
|
}
|
||||||
#endif /* G_ENABLE_DEBUG */
|
#endif /* G_ENABLE_DEBUG */
|
||||||
return;
|
return;
|
||||||
@ -906,3 +848,67 @@ gdk_x11_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager
|
|||||||
device_manager_core = (GdkX11DeviceManagerCore *) device_manager;
|
device_manager_core = (GdkX11DeviceManagerCore *) device_manager;
|
||||||
return device_manager_core->core_pointer;
|
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 ("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -708,70 +708,6 @@ set_user_time (GdkEvent *event)
|
|||||||
gdk_x11_window_set_user_time (window, time);
|
gdk_x11_window_set_user_time (window, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
static void
|
||||||
generate_focus_event (GdkWindow *window,
|
generate_focus_event (GdkWindow *window,
|
||||||
GdkDevice *device,
|
GdkDevice *device,
|
||||||
@ -1108,7 +1044,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
|
|||||||
_gdk_x11_keymap_add_virt_mods (keymap, &state);
|
_gdk_x11_keymap_add_virt_mods (keymap, &state);
|
||||||
event->key.state |= state;
|
event->key.state |= state;
|
||||||
|
|
||||||
translate_keyboard_string ((GdkEventKey *) event);
|
_gdk_x11_event_translate_keyboard_string (&event->key);
|
||||||
|
|
||||||
if (ev->evtype == XI_KeyPress)
|
if (ev->evtype == XI_KeyPress)
|
||||||
set_user_time (event);
|
set_user_time (event);
|
||||||
|
@ -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,
|
guint _gdk_x11_device_xi2_translate_state (XIModifierState *mods_state,
|
||||||
XIButtonState *buttons_state);
|
XIButtonState *buttons_state);
|
||||||
|
|
||||||
|
void _gdk_x11_event_translate_keyboard_string (GdkEventKey *event);
|
||||||
|
|
||||||
void _gdk_x11_display_manager_add_display (GdkDisplayManager *manager,
|
void _gdk_x11_display_manager_add_display (GdkDisplayManager *manager,
|
||||||
GdkDisplay *display);
|
GdkDisplay *display);
|
||||||
void _gdk_x11_display_manager_remove_display (GdkDisplayManager *manager,
|
void _gdk_x11_display_manager_remove_display (GdkDisplayManager *manager,
|
||||||
|
Loading…
Reference in New Issue
Block a user