Commit 7ac3562c authored by Felipe Borges's avatar Felipe Borges 👣

frdp-session, display: Handle key press events

FreeRDP should be able to give us proper scancodes given a keycode
which will match the current locale, display server, and whatnot.
parent 369b1704
......@@ -34,6 +34,31 @@ enum
PROP_PASSWORD
};
static gboolean
frdp_display_key_press_event (GtkWidget *widget,
GdkEventKey *key)
{
FrdpDisplay *self = FRDP_DISPLAY (widget);
guint16 keycode = key->hardware_keycode;
FrdpKeyEvent event;
switch (key->type) {
case GDK_KEY_PRESS:
event = FRDP_KEY_EVENT_PRESS;
break;
case GDK_KEY_RELEASE:
event = FRDP_KEY_EVENT_RELEASE;
break;
default:
g_warn_if_reached ();
break;
}
frdp_session_send_key (self->priv->session, event, keycode);
return TRUE;
}
static gboolean
frdp_display_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
......@@ -182,6 +207,8 @@ frdp_display_class_init (FrdpDisplayClass *klass)
gobject_class->get_property = frdp_display_get_property;
gobject_class->set_property = frdp_display_set_property;
widget_class->key_press_event = frdp_display_key_press_event;
widget_class->key_release_event = frdp_display_key_press_event;
widget_class->motion_notify_event = frdp_display_motion_notify_event;
widget_class->button_press_event = frdp_display_button_press_event;
widget_class->button_release_event = frdp_display_button_press_event;
......@@ -219,7 +246,10 @@ frdp_display_init (FrdpDisplay *self)
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_SCROLL_MASK |
GDK_SMOOTH_SCROLL_MASK);
GDK_SMOOTH_SCROLL_MASK |
GDK_KEY_PRESS_MASK);
gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
}
void
......
......@@ -530,3 +530,42 @@ frdp_session_mouse_event (FrdpSession *self,
input->MouseEvent (input, flags, x, y);
}
}
static unsigned char keycode_scancodes[] = {
0, 0, 0, 0, 0, 0, 0, 28,
29, 53, 55, 56, 0, 71, 72, 73,
75, 77, 79, 80, 81, 82, 83, 0,
0, 0, 0, 0, 0, 0, 69, 0,
0, 0, 0, 0, 91, 92, 93,
};
static guint16
frdp_session_get_scancode_by_keycode (guint16 keycode)
{
if (keycode < 8)
return 0;
else if (keycode < 97)
return keycode - 8;
else if (keycode < 97 + sizeof (keycode_scancodes))
return keycode_scancodes[keycode - 97];
else
return 0;
}
void
frdp_session_send_key (FrdpSession *self,
FrdpKeyEvent event,
guint16 keycode)
{
rdpInput *input = self->priv->freerdp_session->input;
guint16 flags = 0;
guint16 scancode =
frdp_session_get_scancode_by_keycode (keycode);
if (event == FRDP_KEY_EVENT_PRESS)
flags |= KBD_FLAGS_DOWN;
else
flags |= KBD_FLAGS_RELEASE;
input->KeyboardEvent (input, flags, scancode);
}
......@@ -49,6 +49,12 @@ typedef enum
FRDP_MOUSE_EVENT_BUTTON3 = 1 << 6,
} FrdpMouseEvent;
typedef enum
{
FRDP_KEY_EVENT_PRESS = 1 << 0,
FRDP_KEY_EVENT_RELEASE = 1 << 1,
} FrdpKeyEvent;
FrdpSession *frdp_session_new (FrdpDisplay *display);
void frdp_session_connect (FrdpSession *self,
......@@ -67,4 +73,8 @@ void frdp_session_mouse_event (FrdpSession *self,
guint16 x,
guint16 y);
void frdp_session_send_key (FrdpSession *self,
FrdpKeyEvent event,
guint16 keycode);
G_END_DECLS
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