[retro-gtk] core: Forward keyboard events to the core
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] core: Forward keyboard events to the core
- Date: Wed, 5 Jul 2017 14:20:24 +0000 (UTC)
commit 1fd4da5eaa26df824537232986d7834c7dcbc9f2
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Jul 4 16:40:06 2017 +0200
core: Forward keyboard events to the core
Store the keyboard callback sent by the core and, if there is one,
forward the keyboard events to the core via the callback.
retro-gtk/core.vala | 6 +++++-
retro-gtk/retro-core.c | 19 +++++++++++++++++++
retro-gtk/retro-core.h | 6 +++++-
retro-gtk/retro-environment.c | 13 ++++++++++++-
4 files changed, 41 insertions(+), 3 deletions(-)
---
diff --git a/retro-gtk/core.vala b/retro-gtk/core.vala
index 16d5d17..c707bc4 100644
--- a/retro-gtk/core.vala
+++ b/retro-gtk/core.vala
@@ -422,9 +422,13 @@ public class Core : Object {
if (!is_initiated)
return;
- // TODO Handle the key event.
+ push_cb_data ();
+ send_input_key_event (down, keycode, character, key_modifiers);
+ pop_cb_data ();
}
+ private extern void send_input_key_event (bool down, KeyboardKey keycode, uint32 character,
KeyboardModifierKey key_modifiers);
+
private extern void set_system_av_info (SystemAvInfo system_av_info);
private extern void environment_internal_setup ();
diff --git a/retro-gtk/retro-core.c b/retro-gtk/retro-core.c
index 0f6d4bf..c25cb01 100644
--- a/retro-gtk/retro-core.c
+++ b/retro-gtk/retro-core.c
@@ -180,6 +180,25 @@ retro_core_set_memory (RetroCore *self,
}
void
+retro_core_send_input_key_event (RetroCore *self,
+ gboolean down,
+ RetroKeyboardKey keycode,
+ guint32 character,
+ RetroKeyboardModifierKey key_modifiers)
+{
+ RetroCoreEnvironmentInternal *environment_internal;
+
+ g_return_if_fail (self != NULL);
+
+ environment_internal = RETRO_CORE_ENVIRONMENT_INTERNAL (self);
+
+ if (environment_internal->keyboard_callback.callback == NULL)
+ return;
+
+ environment_internal->keyboard_callback.callback (down, keycode, character, key_modifiers);
+}
+
+void
retro_core_environment_internal_setup (RetroCore *self)
{
self->environment_internal = g_new0 (RetroCoreEnvironmentInternal, 1);
diff --git a/retro-gtk/retro-core.h b/retro-gtk/retro-core.h
index bd2581b..f1819e9 100644
--- a/retro-gtk/retro-core.h
+++ b/retro-gtk/retro-core.h
@@ -7,12 +7,16 @@
G_BEGIN_DECLS
+typedef struct {
+ void (*callback) (guchar down, guint keycode, guint32 character, guint16 key_modifiers);
+} RetroKeyboardCallback;
+
#define RETRO_CORE_ENVIRONMENT_INTERNAL(core) ((RetroCoreEnvironmentInternal *)
((core)->environment_internal))
typedef struct _RetroCoreEnvironmentInternal RetroCoreEnvironmentInternal;
struct _RetroCoreEnvironmentInternal {
- gpointer dummy;
+ RetroKeyboardCallback keyboard_callback;
};
G_END_DECLS
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index 3958986..6cc26fc 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -243,6 +243,15 @@ set_input_descriptors (RetroCore *self,
}
static gboolean
+set_keyboard_callback (RetroCore *self,
+ RetroKeyboardCallback *callback)
+{
+ RETRO_CORE_ENVIRONMENT_INTERNAL (self)->keyboard_callback = *callback;
+
+ return TRUE;
+}
+
+static gboolean
set_message (RetroCore *self,
const RetroMessage *message)
{
@@ -360,6 +369,9 @@ environment_core_command (RetroCore *self,
case RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS:
return set_input_descriptors (self, (RetroInputDescriptor *) data);
+ case RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK:
+ return set_keyboard_callback (self, (RetroKeyboardCallback *) data);
+
case RETRO_ENVIRONMENT_SET_MESSAGE:
return set_message (self, (RetroMessage *) data);
@@ -392,7 +404,6 @@ environment_core_command (RetroCore *self,
case RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK:
case RETRO_ENVIRONMENT_SET_GEOMETRY:
case RETRO_ENVIRONMENT_SET_HW_RENDER:
- case RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK:
case RETRO_ENVIRONMENT_SET_MEMORY_MAPS:
case RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL:
case RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]