Commit 29b4baea authored by Carlos Garnacho's avatar Carlos Garnacho

Translate KeyPress/KeyRelease in gtkplug-x11

This makes XEmbed work properly again. Only event->
and is_modifier are left blank at the moment. Exposing the
necessary XKB bits should be considered, but it's not urgent
for the current usecases.
parent 4ed78177
......@@ -353,64 +353,52 @@ _gtk_plug_windowing_filter_func (GdkXEvent *gdk_xevent,
#if 0
/* FIXME: this needs some X11 backend api to do things
* in a saner way
case KeyPress:
case KeyRelease:
static GdkDeviceManager *core_device_manager = NULL;
GdkModifierType state, consumed;
GdkDeviceManager *device_manager;
GdkEvent *translated_event;
GList *devices, *d;
GdkDevice *keyboard = NULL;
device_manager = gdk_display_get_device_manager (display);
/* bail out if the device manager already
* interprets core keyboard events.
if (!GDK_IS_DEVICE_MANAGER_XI2 (device_manager))
/* Find out the first keyboard device, the
* generated event will be assigned to it.
devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
for (d = devices; d; d = d->next)
GdkDevice *device = d->data;
GdkDevice *pointer, *keyboard;
GdkKeymap *keymap;
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
keyboard = device;
if (xevent->type == KeyPress)
event->key.type = GDK_KEY_PRESS;
event->key.type = GDK_KEY_RELEASE;
g_list_free (devices);
event->key.window = gdk_x11_window_lookup_for_display (display, xevent->xany.window);
event->key.send_event = TRUE;
event->key.time = xevent->xkey.time;
event->key.state = (GdkModifierType) xevent->xkey.state;
event->key.hardware_keycode = xevent->xkey.keycode;
event->key.keyval = GDK_KEY_VoidSymbol;
if (!keyboard)
/* This is a crude hack so key events
* are interpreted as if there was a
* GdkDeviceManagerCore available.
if (G_UNLIKELY (!core_device_manager))
core_device_manager = g_object_new (GDK_TYPE_DEVICE_MANAGER_CORE,
"display", display,
translated_event = gdk_event_translator_translate (GDK_EVENT_TRANSLATOR (core_device_manager), display, xevent);
gdk_event_set_device (translated_event, keyboard);
gtk_main_do_event (translated_event);
gdk_event_free (translated_event);
return_val = GDK_FILTER_REMOVE;
device_manager = gdk_display_get_device_manager (display);
pointer = gdk_device_manager_get_client_pointer (device_manager);
keyboard = gdk_device_get_associated_device (pointer);
gdk_event_set_device (event, keyboard);
keymap = gdk_keymap_get_for_display (display);
gdk_keymap_translate_keyboard_state (keymap,
NULL, NULL, &consumed);
state = event->key.state & ~consumed;
gdk_keymap_add_virtual_modifiers (keymap, &state);
event->key.state |= state;
event->key.length = 0;
event->key.string = g_strdup ("");
/* FIXME: These should be filled in properly */
event-> = 0;
event->key.is_modifier = FALSE;
return return_val;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment