Commit cf14fea5 authored by Frediano Ziglio's avatar Frediano Ziglio Committed by Matthias Clasen

Save scancode inside GdkEventPrivate

Windows save in hardware_keycode an information which is not so low
level and some application require the hardware scancode.
As Windows provides this information save it in GdkEventPrivate
and provide a function to get this information.
For no Windows system the function return the hardware_keycode instead.
Signed-off-by: Frediano Ziglio's avatarFrediano Ziglio <fziglio@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=765259
parent c081ca2d
......@@ -295,6 +295,7 @@ _gdk_broadway_events_got_input (BroadwayInputMsg *message)
event->key.keyval = message->key.key;
event->key.state = message->key.state;
event->key.hardware_keycode = message->key.key;
_gdk_event_set_scancode (event, message->key.key);
event->key.length = 0;
gdk_event_set_device (event, device_manager->core_keyboard);
gdk_event_set_seat (event, gdk_device_get_seat (device_manager->core_keyboard));
......
......@@ -2464,3 +2464,37 @@ gdk_event_set_device_tool (GdkEvent *event,
private = (GdkEventPrivate *) event;
private->tool = tool;
}
void
_gdk_event_set_scancode (GdkEvent *event,
guint16 scancode)
{
GdkEventPrivate *private = (GdkEventPrivate *) event;
private->key_scancode = scancode;
}
/**
* gdk_event_get_scancode:
* @event: a #GdkEvent
*
* Gets the keyboard low-level scancode.
* This is usually hardware_keycode.
* On Windows this is the high word of WM_KEY{DOWN,UP} lParam
* which contains the scancode and some extended flags.
*
* Returns: The associated keyboard scancode or 0
*
* Since: 3.22
**/
int
gdk_event_get_scancode (GdkEvent *event)
{
GdkEventPrivate *private;
if (!gdk_event_is_allocated (event))
return 0;
private = (GdkEventPrivate *) event;
return private->key_scancode;
}
......@@ -1451,6 +1451,9 @@ GDK_AVAILABLE_IN_3_22
void gdk_event_set_device_tool (GdkEvent *event,
GdkDeviceTool *tool);
GDK_AVAILABLE_IN_3_22
int gdk_event_get_scancode (GdkEvent *event);
G_END_DECLS
#endif /* __GDK_EVENTS_H__ */
......@@ -190,6 +190,7 @@ struct _GdkEventPrivate
GdkDevice *source_device;
GdkSeat *seat;
GdkDeviceTool *tool;
guint16 key_scancode;
};
typedef struct _GdkWindowPaint GdkWindowPaint;
......@@ -396,6 +397,9 @@ void _gdk_event_set_pointer_emulated (GdkEvent *event,
gboolean emulated);
gboolean _gdk_event_get_pointer_emulated (GdkEvent *event);
void _gdk_event_set_scancode (GdkEvent *event,
guint16 scancode);
void gdk_event_set_seat (GdkEvent *event,
GdkSeat *seat);
......
......@@ -133,6 +133,7 @@ generate_key_event (GdkWindow *window, GdkEventType type, guint state, guint key
event->key.state = state;
event->key.keyval = keyval;
event->key.hardware_keycode = keycode + 8;
_gdk_event_set_scancode (event, keycode + 8);
event->key.is_modifier = is_modifier;
event->key.time = event_time;
set_key_event_string (&event->key);
......
......@@ -1134,6 +1134,7 @@ fill_key_event (GdkWindow *window,
event->key.time = get_time_from_ns_event (nsevent);
event->key.state = get_keyboard_modifiers_from_ns_event (nsevent);
event->key.hardware_keycode = [nsevent keyCode];
_gdk_event_set_scancode (event, [nsevent keyCode]);
event->key.group = ([nsevent modifierFlags] & NSAlternateKeyMask) ? 1 : 0;
event->key.keyval = GDK_KEY_VoidSymbol;
......
......@@ -1836,6 +1836,7 @@ deliver_key_event (GdkWaylandSeat *seat,
event->key.state = device_get_modifiers (seat->master_pointer);
event->key.group = 0;
event->key.hardware_keycode = key;
_gdk_event_set_scancode (event, key);
event->key.keyval = sym;
event->key.is_modifier = _gdk_wayland_keymap_key_is_modifier (keymap, key);
......
......@@ -2339,6 +2339,8 @@ gdk_event_translate (MSG *msg,
event->key.string = NULL;
event->key.length = 0;
event->key.hardware_keycode = msg->wParam;
/* save original scancode */
_gdk_event_set_scancode (event, msg->lParam >> 16);
gdk_event_set_device (event, device_manager_win32->core_keyboard);
gdk_event_set_source_device (event, device_manager_win32->system_keyboard);
gdk_event_set_seat (event, gdk_device_get_seat (device_manager_win32->core_keyboard));
......
......@@ -160,6 +160,7 @@ translate_key_event (GdkDisplay *display,
event->key.state = (GdkModifierType) xevent->xkey.state;
event->key.group = gdk_x11_keymap_get_group_for_state (keymap, xevent->xkey.state);
event->key.hardware_keycode = xevent->xkey.keycode;
_gdk_event_set_scancode (event, xevent->xkey.keycode);
event->key.keyval = GDK_KEY_VoidSymbol;
......
......@@ -1469,6 +1469,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
event->key.group = xev->group.effective;
event->key.hardware_keycode = xev->detail;
_gdk_event_set_scancode (event, xev->detail);
event->key.is_modifier = gdk_x11_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
device = g_hash_table_lookup (device_manager->id_table,
......
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