[retro-gtk] input: Add retro_input_get_keyboard()



commit a1859e157cefa15cc47137a5eaf2613e3a897413
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Wed Nov 14 19:14:12 2018 +0500

    input: Add retro_input_get_keyboard()
    
    This will be used in the next commit to implement keyboard support in
    RetroCoreView.

 retro-gtk/retro-input-private.h | 11 +++++++++++
 retro-gtk/retro-input.c         | 27 +++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
---
diff --git a/retro-gtk/retro-input-private.h b/retro-gtk/retro-input-private.h
index ce3497c..5b817e8 100644
--- a/retro-gtk/retro-input-private.h
+++ b/retro-gtk/retro-input-private.h
@@ -8,12 +8,14 @@
 #endif
 
 #include "retro-input.h"
+#include "retro-keyboard-key.h"
 
 G_BEGIN_DECLS
 
 typedef struct _RetroInputAny RetroInputAny;
 typedef struct _RetroInputJoypad RetroInputJoypad;
 typedef struct _RetroInputMouse RetroInputMouse;
+typedef struct _RetroInputKeyboard RetroInputKeyboard;
 typedef struct _RetroInputLightgun RetroInputLightgun;
 typedef struct _RetroInputAnalog RetroInputAnalog;
 typedef struct _RetroInputPointer RetroInputPointer;
@@ -34,6 +36,11 @@ struct _RetroInputMouse {
   RetroMouseId id;
 };
 
+struct _RetroInputKeyboard {
+  RetroControllerType type;
+  RetroKeyboardKey key;
+};
+
 struct _RetroInputLightgun {
   RetroControllerType type;
   RetroLightgunId id;
@@ -54,6 +61,7 @@ union _RetroInput {
   RetroInputAny any;
   RetroInputJoypad joypad;
   RetroInputMouse mouse;
+  RetroInputKeyboard keyboard;
   RetroInputLightgun lightgun;
   RetroInputAnalog analog;
   RetroInputPointer pointer;
@@ -64,6 +72,9 @@ void retro_input_init (RetroInput          *self,
                        guint                id,
                        guint                index);
 
+gboolean retro_input_get_keyboard (RetroInput       *self,
+                                   RetroKeyboardKey *key);
+
 G_END_DECLS
 
 #endif /* RETRO_INPUT_PRIVATE_H */
diff --git a/retro-gtk/retro-input.c b/retro-gtk/retro-input.c
index cfd99e4..ab29a23 100644
--- a/retro-gtk/retro-input.c
+++ b/retro-gtk/retro-input.c
@@ -156,6 +156,33 @@ retro_input_get_mouse (RetroInput   *self,
   return TRUE;
 }
 
+/**
+ * retro_input_get_keyboard:
+ * @self: a #RetroInput
+ * @key: (out): return location for the key
+ *
+ * Gets the keyboard key of %self, if any.
+ *
+ * Returns: whether the key was retrieved
+ */
+gboolean
+retro_input_get_keyboard (RetroInput       *self,
+                          RetroKeyboardKey *key)
+{
+  g_return_val_if_fail (self != NULL, FALSE);
+  g_return_val_if_fail (key != NULL, FALSE);
+
+  if (self->any.type != RETRO_CONTROLLER_TYPE_KEYBOARD)
+    return FALSE;
+
+  if (self->keyboard.key >= RETRO_KEYBOARD_KEY_LAST)
+    return FALSE;
+
+  *key = self->keyboard.key;
+
+  return TRUE;
+}
+
 /**
  * retro_input_get_lightgun:
  * @self: a #RetroInput


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]