[retro-gtk/wip/aplazas/controller] Rename RetroInputDevice to RetroController



commit c5532e03fa8404f2da6111c54d3387264e046588
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed Oct 11 13:23:50 2017 +0200

    Rename RetroInputDevice to RetroController
    
    This name better reflects this type, as it doesn't represent all the
    input types (e.g. microphones are not represented) and it doesn't
    represent only inputs (e.g. rumble is an output).
    
    Also rename RetroCoreViewInputDevice into RetroCoreViewController and
    RetroDeviceType into RetroControllerType to keep the names uniform.

 demos/retro-demo.c                       |   12 ++-
 retro-gtk/Makefile.am                    |   12 ++--
 retro-gtk/retro-controller-iterator.c    |    6 +-
 retro-gtk/retro-controller-iterator.h    |    4 +-
 retro-gtk/retro-controller-type.c        |   30 +++++++
 retro-gtk/retro-controller-type.h        |   45 ++++++++++
 retro-gtk/retro-controller.c             |  130 +++++++++++++++++++++++++++++
 retro-gtk/retro-controller.h             |   46 ++++++++++
 retro-gtk/retro-core-private.h           |    6 +-
 retro-gtk/retro-core-view-controller.c   |  134 ++++++++++++++++++++++++++++++
 retro-gtk/retro-core-view-controller.h   |   26 ++++++
 retro-gtk/retro-core-view-input-device.c |  133 -----------------------------
 retro-gtk/retro-core-view-input-device.h |   25 ------
 retro-gtk/retro-core-view.c              |   71 ++++++++--------
 retro-gtk/retro-core-view.h              |   24 +++---
 retro-gtk/retro-core.c                   |   70 ++++++++--------
 retro-gtk/retro-core.h                   |   22 ++---
 retro-gtk/retro-device-type.c            |   30 -------
 retro-gtk/retro-device-type.h            |   45 ----------
 retro-gtk/retro-environment.c            |    6 +-
 retro-gtk/retro-gtk.h                    |    4 +-
 retro-gtk/retro-input-descriptor.c       |    2 +-
 retro-gtk/retro-input-descriptor.h       |    4 +-
 retro-gtk/retro-input-device.c           |  130 -----------------------------
 retro-gtk/retro-input-device.h           |   46 ----------
 retro-gtk/retro-module.h                 |    4 +-
 26 files changed, 533 insertions(+), 534 deletions(-)
---
diff --git a/demos/retro-demo.c b/demos/retro-demo.c
index 19e9bea..eca4ea5 100644
--- a/demos/retro-demo.c
+++ b/demos/retro-demo.c
@@ -82,7 +82,7 @@ retro_demo_activate (GApplication *application)
 {
   RetroDemoApplication *self;
   GtkWidget *window;
-  RetroInputDevice *input_device;
+  RetroController *controller;
 
   self = RETRO_DEMO_APPLICATION (application);
 
@@ -92,16 +92,18 @@ retro_demo_activate (GApplication *application)
   retro_core_view_set_core (self->view, self->core);
 
   retro_core_set_keyboard (self->core, GTK_WIDGET (self->view));
-  input_device = retro_core_view_as_input_device (self->view, RETRO_DEVICE_TYPE_POINTER);
-  retro_core_set_controller (self->core, 0, input_device);
-  g_object_unref (input_device);
+  controller = retro_core_view_as_controller (self->view,
+                                              RETRO_CONTROLLER_TYPE_POINTER);
+  retro_core_set_controller (self->core, 0, controller);
+  g_object_unref (controller);
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
   gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (self->view));
 
   gtk_widget_show_all (GTK_WIDGET (window));
-  gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (window));
+  gtk_application_add_window (GTK_APPLICATION (application),
+                              GTK_WINDOW (window));
 
   self->loop = retro_main_loop_new (self->core);
   retro_main_loop_start (self->loop);
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 75bc92a..5a8116b 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -30,13 +30,13 @@ dist_vapi_DATA = retro-gtk-0.12.deps
 retro_gtk_public_h_sources = \
        retro-analog-id.h \
        retro-analog-index.h \
+       retro-controller.h \
        retro-controller-iterator.h \
+       retro-controller-type.h \
        retro-core-descriptor.h \
        retro-core.h \
        retro-core-view.h \
-       retro-device-type.h \
        retro-gtk.h \
-       retro-input-device.h \
        retro-joypad-id.h \
        retro-lightgun-id.h \
        retro-log.h \
@@ -56,7 +56,7 @@ retro_gtk_private_h_sources = \
        retro-cairo-display.h \
        retro-controller-iterator-private.h \
        retro-core-private.h \
-       retro-core-view-input-device.h \
+       retro-core-view-controller.h \
        retro-disk-control-callback.h \
        retro-game-info.h \
        retro-input-descriptor.h \
@@ -75,14 +75,14 @@ libretro_gtk_la_SOURCES = \
        retro-analog-id.c \
        retro-analog-index.c \
        retro-cairo-display.c \
+       retro-controller.c \
        retro-controller-iterator.c \
+       retro-controller-type.c \
        retro-core-descriptor.c \
        retro-core-view.c \
-       retro-core-view-input-device.c \
-       retro-device-type.c \
+       retro-core-view-controller.c \
        retro-game-info.c \
        retro-input-descriptor.c \
-       retro-input-device.c \
        retro-joypad-id.c \
        retro-keyboard-key.c \
        retro-lightgun-id.c \
diff --git a/retro-gtk/retro-controller-iterator.c b/retro-gtk/retro-controller-iterator.c
index 69e9413..89b9156 100644
--- a/retro-gtk/retro-controller-iterator.c
+++ b/retro-gtk/retro-controller-iterator.c
@@ -39,14 +39,14 @@ retro_controller_iterator_init (RetroControllerIterator *self)
  * @port: (out) (optional): return location for the port
  * @controller: (out) (optional) (nullable): return location for the controller
  *
- * Fetch the next #RetroInputDevice and the port number it is plugged into.
+ * Fetch the next #RetroController and the port number it is plugged into.
  *
  * Returns: %FALSE if it reached the end, %TRUE otherwise
  */
 gboolean
 retro_controller_iterator_next (RetroControllerIterator  *self,
                                 guint                   **port,
-                                RetroInputDevice        **controller)
+                                RetroController         **controller)
 {
   g_return_val_if_fail (RETRO_IS_CONTROLLER_ITERATOR (self), FALSE);
   g_return_val_if_fail (port != NULL, FALSE);
@@ -57,7 +57,7 @@ retro_controller_iterator_next (RetroControllerIterator  *self,
 
 /**
  * retro_controller_iterator_new:
- * @controllers: (element-type guint RetroInputDevice): A #GHashTable
+ * @controllers: (element-type guint RetroController): A #GHashTable
  *
  * Creates a new #RetroControllerIterator.
  *
diff --git a/retro-gtk/retro-controller-iterator.h b/retro-gtk/retro-controller-iterator.h
index aad2505..4452420 100644
--- a/retro-gtk/retro-controller-iterator.h
+++ b/retro-gtk/retro-controller-iterator.h
@@ -8,7 +8,7 @@
 #endif
 
 #include <glib-object.h>
-#include "retro-input-device.h"
+#include "retro-controller.h"
 
 G_BEGIN_DECLS
 
@@ -18,7 +18,7 @@ G_DECLARE_FINAL_TYPE (RetroControllerIterator, retro_controller_iterator, RETRO,
 
 gboolean retro_controller_iterator_next (RetroControllerIterator  *self,
                                          guint                   **port,
-                                         RetroInputDevice        **controller);
+                                         RetroController         **controller);
 
 G_END_DECLS
 
diff --git a/retro-gtk/retro-controller-type.c b/retro-gtk/retro-controller-type.c
new file mode 100644
index 0000000..63d8ef5
--- /dev/null
+++ b/retro-gtk/retro-controller-type.c
@@ -0,0 +1,30 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-controller-type.h"
+
+GType
+retro_controller_type_get_type (void)
+{
+  static volatile gsize retro_controller_type_type = 0;
+
+  if (g_once_init_enter (&retro_controller_type_type)) {
+    static const GEnumValue values[] = {
+      { RETRO_CONTROLLER_TYPE_NONE, "RETRO_CONTROLLER_TYPE_NONE", "none" },
+      { RETRO_CONTROLLER_TYPE_JOYPAD, "RETRO_CONTROLLER_TYPE_JOYPAD", "joypad" },
+      { RETRO_CONTROLLER_TYPE_MOUSE, "RETRO_CONTROLLER_TYPE_MOUSE", "mouse" },
+      { RETRO_CONTROLLER_TYPE_KEYBOARD, "RETRO_CONTROLLER_TYPE_KEYBOARD", "keyboard" },
+      { RETRO_CONTROLLER_TYPE_LIGHTGUN, "RETRO_CONTROLLER_TYPE_LIGHTGUN", "lightgun" },
+      { RETRO_CONTROLLER_TYPE_ANALOG, "RETRO_CONTROLLER_TYPE_ANALOG", "analog" },
+      { RETRO_CONTROLLER_TYPE_POINTER, "RETRO_CONTROLLER_TYPE_POINTER", "pointer" },
+      { RETRO_CONTROLLER_TYPE_TYPE_MASK, "RETRO_CONTROLLER_TYPE_TYPE_MASK", "type-mask" },
+      { 0, NULL, NULL },
+    };
+    GType type;
+
+    type = g_enum_register_static ("RetroControllerType", values);
+
+    g_once_init_leave (&retro_controller_type_type, type);
+  }
+
+  return retro_controller_type_type;
+}
diff --git a/retro-gtk/retro-controller-type.h b/retro-gtk/retro-controller-type.h
new file mode 100644
index 0000000..0b3dd0f
--- /dev/null
+++ b/retro-gtk/retro-controller-type.h
@@ -0,0 +1,45 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_CONTROLLER_TYPE_H
+#define RETRO_CONTROLLER_TYPE_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define RETRO_TYPE_CONTROLLER_TYPE (retro_controller_type_get_type ())
+
+GType retro_controller_type_get_type (void) G_GNUC_CONST;
+
+/**
+ * RetroControllerType:
+ * @RETRO_CONTROLLER_TYPE_NONE: no controller
+ * @RETRO_CONTROLLER_TYPE_JOYPAD: a classic gamepad
+ * @RETRO_CONTROLLER_TYPE_MOUSE: a simple mouse
+ * @RETRO_CONTROLLER_TYPE_KEYBOARD: a keyboard
+ * @RETRO_CONTROLLER_TYPE_LIGHTGUN: a lightgun
+ * @RETRO_CONTROLLER_TYPE_ANALOG: a gamepad with analog sticks
+ * @RETRO_CONTROLLER_TYPE_POINTER: a screen pointer
+ * @RETRO_CONTROLLER_TYPE_TYPE_MASK: a mask to get the super type of a derived one
+ *
+ * Represents the base types for Libretro controllers.
+ */
+typedef enum
+{
+  RETRO_CONTROLLER_TYPE_NONE,
+  RETRO_CONTROLLER_TYPE_JOYPAD,
+  RETRO_CONTROLLER_TYPE_MOUSE,
+  RETRO_CONTROLLER_TYPE_KEYBOARD,
+  RETRO_CONTROLLER_TYPE_LIGHTGUN,
+  RETRO_CONTROLLER_TYPE_ANALOG,
+  RETRO_CONTROLLER_TYPE_POINTER,
+  RETRO_CONTROLLER_TYPE_TYPE_MASK = 0xff,
+} RetroControllerType;
+
+G_END_DECLS
+
+#endif /* RETRO_CONTROLLER_TYPE_H */
diff --git a/retro-gtk/retro-controller.c b/retro-gtk/retro-controller.c
new file mode 100644
index 0000000..177bdc1
--- /dev/null
+++ b/retro-gtk/retro-controller.c
@@ -0,0 +1,130 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-controller.h"
+
+G_DEFINE_INTERFACE (RetroController, retro_controller, G_TYPE_OBJECT);
+
+static void
+retro_controller_default_init (RetroControllerInterface *iface)
+{
+}
+
+/**
+ * retro_controller_poll:
+ * @self: a #RetroController
+ *
+ * Polls the pending input events for @self.
+ */
+void
+retro_controller_poll (RetroController *self)
+{
+  RetroControllerInterface *iface;
+
+  g_return_if_fail (RETRO_IS_CONTROLLER (self));
+
+  iface = RETRO_CONTROLLER_GET_IFACE (self);
+
+  g_return_if_fail (iface->poll != NULL);
+
+  iface->poll (self);
+}
+
+/**
+ * retro_controller_get_input_state:
+ * @self: a #RetroController
+ * @controller_type: a #RetroControllerType to query @self
+ * @index: an input index to interpret depending on @controller_type
+ * @id: an input id to interpret depending on @controller_type
+ *
+ * Gets the state of an input of @self.
+ *
+ * Returns: the input's state
+ */
+gint16
+retro_controller_get_input_state (RetroController     *self,
+                                  RetroControllerType  controller_type,
+                                  guint                index,
+                                  guint                id)
+{
+  RetroControllerInterface *iface;
+
+  g_return_val_if_fail (RETRO_IS_CONTROLLER (self), 0);
+
+  iface = RETRO_CONTROLLER_GET_IFACE (self);
+
+  g_return_val_if_fail (iface->get_input_state != NULL, 0);
+
+  return iface->get_input_state (self, controller_type, index, id);
+}
+
+/**
+ * retro_controller_get_controller_type:
+ * @self: a #RetroController
+ *
+ * Gets the main type of the controller.
+ *
+ * Returns: the controller type of @self
+ */
+RetroControllerType
+retro_controller_get_controller_type (RetroController *self)
+{
+
+  RetroControllerInterface *iface;
+
+  g_return_val_if_fail (RETRO_IS_CONTROLLER (self), RETRO_CONTROLLER_TYPE_NONE);
+
+  iface = RETRO_CONTROLLER_GET_IFACE (self);
+
+  g_return_val_if_fail (iface->get_controller_type != NULL, RETRO_CONTROLLER_TYPE_NONE);
+
+  return iface->get_controller_type (self);
+}
+
+/**
+ * retro_controller_get_capabilities:
+ * @self: a #RetroController
+ *
+ * Gets a flag representing the capabilities of @self. Each bit index matches
+ * the #RetroControllerType of same number.
+ *
+ * For example, if @self is an analog gamepad, the value would be: (1 <<
+ * RETRO_CONTROLLER_TYPE_JOYPAD) | (1 << RETRO_CONTROLLER_TYPE_ANALOG).
+ *
+ * Returns: the capabilities flag of @self
+ */
+guint64
+retro_controller_get_capabilities (RetroController *self)
+{
+
+  RetroControllerInterface *iface;
+
+  g_return_val_if_fail (RETRO_IS_CONTROLLER (self), 0);
+
+  iface = RETRO_CONTROLLER_GET_IFACE (self);
+
+  g_return_val_if_fail (iface->get_capabilities != NULL, 0);
+
+  return iface->get_capabilities (self);
+}
+
+/**
+ * retro_controller_set_rumble_state:
+ * @self: a #RetroController
+ * @effect: the rumble effect
+ * @strength: the rumble effect strength
+ *
+ * Sets the rumble state of @self.
+ *
+ * Returns: whether the rumble state has been successfully set.
+ */
+gboolean
+retro_controller_set_rumble_state (RetroController   *self,
+                                   RetroRumbleEffect  effect,
+                                   guint16            strength)
+{
+  g_return_val_if_fail (RETRO_IS_CONTROLLER (self), FALSE);
+
+  // TODO
+
+  return FALSE;
+}
diff --git a/retro-gtk/retro-controller.h b/retro-gtk/retro-controller.h
new file mode 100644
index 0000000..32aa2bf
--- /dev/null
+++ b/retro-gtk/retro-controller.h
@@ -0,0 +1,46 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_CONTROLLER_H
+#define RETRO_CONTROLLER_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+#include "retro-controller-type.h"
+#include "retro-rumble-effect.h"
+
+G_BEGIN_DECLS
+
+#define RETRO_TYPE_CONTROLLER (retro_controller_get_type())
+
+G_DECLARE_INTERFACE (RetroController, retro_controller, RETRO, CONTROLLER, GObject)
+
+struct _RetroControllerInterface
+{
+  GTypeInterface parent_iface;
+
+  void (*poll) (RetroController *self);
+  gint16 (*get_input_state) (RetroController     *self,
+                             RetroControllerType  controller_type,
+                             guint                index,
+                             guint                id);
+  RetroControllerType (*get_controller_type) (RetroController *self);
+  guint64 (*get_capabilities) (RetroController *self);
+};
+
+void retro_controller_poll (RetroController *self);
+gint16 retro_controller_get_input_state (RetroController     *self,
+                                         RetroControllerType  controller_type,
+                                         guint                index,
+                                         guint                id);
+RetroControllerType retro_controller_get_controller_type (RetroController *self);
+guint64 retro_controller_get_capabilities (RetroController *self);
+gboolean retro_controller_set_rumble_state (RetroController   *self,
+                                            RetroRumbleEffect  effect,
+                                            guint16            strength);
+
+G_END_DECLS
+
+#endif /* RETRO_CONTROLLER_H */
diff --git a/retro-gtk/retro-core-private.h b/retro-gtk/retro-core-private.h
index 1d604f8..3c4d49f 100644
--- a/retro-gtk/retro-core-private.h
+++ b/retro-gtk/retro-core-private.h
@@ -60,9 +60,9 @@ void retro_core_set_support_no_game (RetroCore *self,
 gchar *retro_core_get_name (RetroCore *self);
 void retro_core_set_system_av_info (RetroCore         *self,
                                     RetroSystemAvInfo *system_av_info);
-void retro_core_set_controller_port_device (RetroCore       *self,
-                                            guint            port,
-                                            RetroDeviceType  device);
+void retro_core_set_controller_port_device (RetroCore           *self,
+                                            guint                port,
+                                            RetroControllerType  controller_type);
 void retro_core_set_controller_descriptors (RetroCore            *self,
                                             RetroInputDescriptor *input_descriptors,
                                             gsize                 length);
diff --git a/retro-gtk/retro-core-view-controller.c b/retro-gtk/retro-core-view-controller.c
new file mode 100644
index 0000000..82329e7
--- /dev/null
+++ b/retro-gtk/retro-core-view-controller.c
@@ -0,0 +1,134 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-core-view-controller.h"
+
+#include "retro-controller.h"
+
+struct _RetroCoreViewController
+{
+  GObject parent_instance;
+  GWeakRef view;
+  RetroControllerType controller_type;
+};
+
+static void retro_controller_interface_init (RetroControllerInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (RetroCoreViewController, retro_core_view_controller, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (RETRO_TYPE_CONTROLLER,
+                                                retro_controller_interface_init))
+
+/* Private */
+
+static void
+retro_core_view_controller_poll (RetroController *base)
+{
+}
+
+static gint16
+retro_core_view_controller_get_input_state (RetroController     *base,
+                                            RetroControllerType  controller_type,
+                                            guint                index,
+                                            guint                id)
+{
+  RetroCoreViewController *self = RETRO_CORE_VIEW_CONTROLLER (base);
+  gpointer view;
+  gint16 result;
+
+  g_return_val_if_fail (self != NULL, 0);
+
+  if (controller_type != self->controller_type)
+    return 0;
+
+  view = g_weak_ref_get (&self->view);
+
+  if (view == NULL)
+    return 0;
+
+  result = retro_core_view_get_input_state (RETRO_CORE_VIEW (view),
+                                            self->controller_type,
+                                            index, id);
+
+  g_object_unref (G_OBJECT (view));
+
+  return result;
+}
+
+static RetroControllerType
+retro_core_view_controller_get_controller_type (RetroController *base)
+{
+  RetroCoreViewController *self = RETRO_CORE_VIEW_CONTROLLER (base);
+
+  g_return_val_if_fail (self != NULL, 0);
+
+  return self->controller_type;
+}
+
+static guint64
+retro_core_view_controller_get_capabilities (RetroController *base)
+{
+  RetroCoreViewController *self = RETRO_CORE_VIEW_CONTROLLER (base);
+  gpointer view;
+  guint64 result;
+
+  g_return_val_if_fail (self != NULL, 0);
+
+  view = g_weak_ref_get (&self->view);
+
+  if (view == NULL)
+    return 0;
+
+  result = retro_core_view_get_controller_capabilities (RETRO_CORE_VIEW (view));
+
+  g_object_unref (G_OBJECT (view));
+
+  return result;
+}
+
+static void
+retro_core_view_controller_finalize (GObject *object)
+{
+  RetroCoreViewController *self = RETRO_CORE_VIEW_CONTROLLER (object);
+
+  g_weak_ref_clear (&self->view);
+
+  G_OBJECT_CLASS (retro_core_view_controller_parent_class)->finalize (object);
+}
+
+static void
+retro_core_view_controller_class_init (RetroCoreViewControllerClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = retro_core_view_controller_finalize;
+}
+
+static void
+retro_core_view_controller_init (RetroCoreViewController *self)
+{
+}
+
+static void
+retro_controller_interface_init (RetroControllerInterface *iface)
+{
+  iface->poll = retro_core_view_controller_poll;
+  iface->get_input_state =  retro_core_view_controller_get_input_state;
+  iface->get_controller_type = retro_core_view_controller_get_controller_type;
+  iface->get_capabilities = retro_core_view_controller_get_capabilities;
+}
+
+/* Public */
+
+RetroCoreViewController *
+retro_core_view_controller_new (RetroCoreView       *view,
+                                RetroControllerType  controller_type)
+{
+  RetroCoreViewController *self = NULL;
+
+  g_return_val_if_fail (view != NULL, NULL);
+
+  self = g_object_new (RETRO_TYPE_CORE_VIEW_CONTROLLER, NULL);
+  g_weak_ref_init (&self->view, view);
+  self->controller_type = controller_type;
+
+  return self;
+}
diff --git a/retro-gtk/retro-core-view-controller.h b/retro-gtk/retro-core-view-controller.h
new file mode 100644
index 0000000..6cf5e24
--- /dev/null
+++ b/retro-gtk/retro-core-view-controller.h
@@ -0,0 +1,26 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_CORE_VIEW_CONTROLLER_H
+#define RETRO_CORE_VIEW_CONTROLLER_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+#include "retro-controller-type.h"
+#include "retro-core-view.h"
+
+G_BEGIN_DECLS
+
+#define RETRO_TYPE_CORE_VIEW_CONTROLLER (retro_core_view_controller_get_type())
+
+G_DECLARE_FINAL_TYPE (RetroCoreViewController, retro_core_view_controller, RETRO, CORE_VIEW_CONTROLLER, 
GObject)
+
+RetroCoreViewController *retro_core_view_controller_new (RetroCoreView       *view,
+                                                         RetroControllerType  controller_type);
+
+G_END_DECLS
+
+#endif /* RETRO_CORE_VIEW_CONTROLLER_H */
+
diff --git a/retro-gtk/retro-core-view.c b/retro-gtk/retro-core-view.c
index d2e3515..0ad91fb 100644
--- a/retro-gtk/retro-core-view.c
+++ b/retro-gtk/retro-core-view.c
@@ -1,9 +1,10 @@
 // This file is part of retro-gtk. License: GPL-3.0+.
 
+#include "retro-core-view.h"
+
 #include <linux/input-event-codes.h>
 #include "retro-cairo-display.h"
-#include "retro-core-view.h"
-#include "retro-core-view-input-device.h"
+#include "retro-core-view-controller.h"
 #include "retro-joypad-id.h"
 #include "retro-mouse-id.h"
 #include "retro-pa-player.h"
@@ -628,29 +629,29 @@ retro_core_view_hide_video (RetroCoreView *self)
 }
 
 /**
- * retro_core_view_as_input_device:
+ * retro_core_view_as_controller:
  * @self: a #RetroCoreView
- * @device_type: the controller type to expose @self as
+ * @controller_type: the controller type to expose @self as
  *
- * Creates a new #RetroInputDevice exposing @self as the specified controller
- * type. The valid controller types are RETRO_DEVICE_TYPE_JOYPAD,
- * RETRO_DEVICE_TYPE_MOUSE and RETRO_DEVICE_TYPE_POINTER.
+ * Creates a new #RetroController exposing @self as the specified controller
+ * type. The valid controller types are RETRO_CONTROLLER_TYPE_JOYPAD,
+ * RETRO_CONTROLLER_TYPE_MOUSE and RETRO_CONTROLLER_TYPE_POINTER.
  *
- * Returns: (transfer full): a new #RetroInputDevice
+ * Returns: (transfer full): a new #RetroController
  */
-RetroInputDevice *
-retro_core_view_as_input_device (RetroCoreView   *self,
-                                 RetroDeviceType  device_type)
+RetroController *
+retro_core_view_as_controller (RetroCoreView       *self,
+                               RetroControllerType  controller_type)
 {
   g_return_val_if_fail (RETRO_IS_CORE_VIEW (self), NULL);
 
-  return RETRO_INPUT_DEVICE (retro_core_view_input_device_new (self, device_type));
+  return RETRO_CONTROLLER (retro_core_view_controller_new (self, controller_type));
 }
 
 /**
  * retro_core_view_get_input_state:
  * @self: a #RetroCoreView
- * @device: an #RetroDeviceType to query @self
+ * @controller_type: a #RetroControllerType to query @self
  * @index: an input index to interpret depending on @device
  * @id: an input id to interpret depending on @device
  *
@@ -659,22 +660,22 @@ retro_core_view_as_input_device (RetroCoreView   *self,
  * Returns: the input's state
  */
 gint16
-retro_core_view_get_input_state (RetroCoreView   *self,
-                                 RetroDeviceType  device,
-                                 guint            index,
-                                 guint            id)
+retro_core_view_get_input_state (RetroCoreView       *self,
+                                 RetroControllerType  controller_type,
+                                 guint                index,
+                                 guint                id)
 {
   gint16 result;
 
   g_return_val_if_fail (RETRO_IS_CORE_VIEW (self), 0);
 
-  switch (device) {
-  case RETRO_DEVICE_TYPE_JOYPAD:
+  switch (controller_type) {
+  case RETRO_CONTROLLER_TYPE_JOYPAD:
     if (id >= RETRO_JOYPAD_ID_COUNT)
       return 0;
 
     return retro_core_view_get_joypad_button_state (self, id) ? G_MAXINT16 : 0;
-  case RETRO_DEVICE_TYPE_MOUSE:
+  case RETRO_CONTROLLER_TYPE_MOUSE:
     switch (id) {
     case RETRO_MOUSE_ID_X:
       result = (gint16) self->mouse_x_delta;
@@ -693,7 +694,7 @@ retro_core_view_get_input_state (RetroCoreView   *self,
     default:
       return 0;
     }
-  case RETRO_DEVICE_TYPE_POINTER:
+  case RETRO_CONTROLLER_TYPE_POINTER:
     switch (id) {
     case RETRO_POINTER_ID_X:
       return axis_to_retro_axis (self->pointer_x);
@@ -714,26 +715,26 @@ retro_core_view_get_input_state (RetroCoreView   *self,
 }
 
 /**
- * retro_core_view_get_device_capabilities:
+ * retro_core_view_get_controller_capabilities:
  * @self: a #RetroCoreView
  *
  * Gets a flag representing the capabilities of @self when exposed as a
- * controller. See retro_input_device_get_device_capabilities() for more
- * information on the flag.
+ * controller. See retro_controller_get_capabilities() for more information on
+ * the flag.
  *
- * See retro_core_view_as_input_device() to know the capabilities of
+ * See retro_core_view_as_controller() to know the capabilities of
  * #RetroCoreView when exposed as a controller.
  *
  * Returns: the capabilities flag of @self when exposed as a controller
  */
 guint64
-retro_core_view_get_device_capabilities (RetroCoreView *self)
+retro_core_view_get_controller_capabilities (RetroCoreView *self)
 {
   g_return_val_if_fail (RETRO_IS_CORE_VIEW (self), 0);
 
-  return 1 << RETRO_DEVICE_TYPE_JOYPAD |
-         1 << RETRO_DEVICE_TYPE_MOUSE |
-         1 << RETRO_DEVICE_TYPE_POINTER;
+  return 1 << RETRO_CONTROLLER_TYPE_JOYPAD |
+         1 << RETRO_CONTROLLER_TYPE_MOUSE |
+         1 << RETRO_CONTROLLER_TYPE_POINTER;
 }
 
 /**
@@ -741,8 +742,8 @@ retro_core_view_get_device_capabilities (RetroCoreView *self)
  * @self: a #RetroCoreView
  *
  * Gets whether the pointer should be grabbed when clicking on the view. This
- * allows @self to work as a RETRO_DEVICE_TYPE_MOUSE instead of a
- * RETRO_DEVICE_TYPE_POINTER.
+ * allows @self to work as a RETRO_CONTROLLER_TYPE_MOUSE instead of a
+ * RETRO_CONTROLLER_TYPE_POINTER.
  *
  * Returns: whether the pointer should snap to the borders
  */
@@ -761,8 +762,8 @@ retro_core_view_get_can_grab_pointer (RetroCoreView *self)
  * the view
  *
  * Sets whether the pointer should be grabbed when clicking on the view. This
- * allows @self to work as a RETRO_DEVICE_TYPE_MOUSE instead of a
- * RETRO_DEVICE_TYPE_POINTER.
+ * allows @self to work as a RETRO_CONTROLLER_TYPE_MOUSE instead of a
+ * RETRO_CONTROLLER_TYPE_POINTER.
  */
 void
 retro_core_view_set_can_grab_pointer (RetroCoreView *self,
@@ -788,7 +789,7 @@ retro_core_view_set_can_grab_pointer (RetroCoreView *self,
  *
  * Gets whether the pointer should be considered to be at the border of the
  * video display when it is outside of it. This is used when @self is exposed as
- * a RETRO_DEVICE_TYPE_POINTER.
+ * a RETRO_CONTROLLER_TYPE_POINTER.
  *
  * Returns: whether the pointer should snap to the borders
  */
@@ -807,7 +808,7 @@ retro_core_view_get_snap_pointer_to_borders (RetroCoreView *self)
  *
  * Sets whether the pointer should be considered to be at the border of the
  * video display when it is outside of it. This is used when @self is exposed as
- * a RETRO_DEVICE_TYPE_POINTER.
+ * a RETRO_CONTROLLER_TYPE_POINTER.
  */
 void
 retro_core_view_set_snap_pointer_to_borders (RetroCoreView *self,
diff --git a/retro-gtk/retro-core-view.h b/retro-gtk/retro-core-view.h
index 4b9551e..ed7892d 100644
--- a/retro-gtk/retro-core-view.h
+++ b/retro-gtk/retro-core-view.h
@@ -7,8 +7,8 @@
 
 #include <gtk/gtk.h>
 #include "retro-core.h"
-#include "retro-device-type.h"
-#include "retro-input-device.h"
+#include "retro-controller.h"
+#include "retro-controller-type.h"
 #include "retro-video-filter.h"
 
 G_BEGIN_DECLS
@@ -20,7 +20,7 @@ G_DECLARE_FINAL_TYPE (RetroCoreView, retro_core_view, RETRO, CORE_VIEW, GtkEvent
 RetroCoreView *retro_core_view_new (void);
 
 void retro_core_view_set_core (RetroCoreView *self,
-                               RetroCore *core);
+                               RetroCore     *core);
 void retro_core_view_set_pixbuf (RetroCoreView *self,
                                  GdkPixbuf     *pixbuf);
 GdkPixbuf *retro_core_view_get_pixbuf (RetroCoreView *self);
@@ -28,19 +28,19 @@ void retro_core_view_set_filter (RetroCoreView    *self,
                                  RetroVideoFilter  filter);
 void retro_core_view_show_video (RetroCoreView *self);
 void retro_core_view_hide_video (RetroCoreView *self);
-RetroInputDevice *retro_core_view_as_input_device (RetroCoreView *self,
-                                                   RetroDeviceType device_type);
-gint16 retro_core_view_get_input_state (RetroCoreView   *self,
-                                        RetroDeviceType  device,
-                                        guint            index,
-                                        guint            id);
-guint64 retro_core_view_get_device_capabilities (RetroCoreView *self);
+RetroController *retro_core_view_as_controller (RetroCoreView       *self,
+                                                RetroControllerType  controller_type);
+gint16 retro_core_view_get_input_state (RetroCoreView       *self,
+                                        RetroControllerType  controller_type,
+                                        guint                index,
+                                        guint                id);
+guint64 retro_core_view_get_controller_capabilities (RetroCoreView *self);
 gboolean retro_core_view_get_can_grab_pointer (RetroCoreView *self);
 void retro_core_view_set_can_grab_pointer (RetroCoreView *self,
-                                           gboolean can_grab_pointer);
+                                           gboolean       can_grab_pointer);
 gboolean retro_core_view_get_snap_pointer_to_borders (RetroCoreView *self);
 void retro_core_view_set_snap_pointer_to_borders (RetroCoreView *self,
-                                                  gboolean snap_pointer_to_borders);
+                                                  gboolean       snap_pointer_to_borders);
 
 G_END_DECLS
 
diff --git a/retro-gtk/retro-core.c b/retro-gtk/retro-core.c
index ddb03b6..a209738 100644
--- a/retro-gtk/retro-core.c
+++ b/retro-gtk/retro-core.c
@@ -631,20 +631,20 @@ retro_core_get_name (RetroCore *self)
 }
 
 static void
-retro_core_controller_connected (RetroCore        *self,
-                                 guint             port,
-                                 RetroInputDevice *device)
+retro_core_controller_connected (RetroCore       *self,
+                                 guint            port,
+                                 RetroController *controller)
 {
-  RetroDeviceType device_type;
+  RetroControllerType controller_type;
 
   g_return_if_fail (RETRO_IS_CORE (self));
-  g_return_if_fail (device != NULL);
+  g_return_if_fail (controller != NULL);
 
   if (!retro_core_get_is_initiated (self))
     return;
 
-  device_type = retro_input_device_get_device_type (device);
-  retro_core_set_controller_port_device (self, port, device_type);
+  controller_type = retro_controller_get_controller_type (controller);
+  retro_core_set_controller_port_device (self, port, controller_type);
 }
 
 static void
@@ -656,7 +656,7 @@ retro_core_controller_disconnected (RetroCore *self,
   if (!retro_core_get_is_initiated (self))
     return;
 
-  retro_core_set_controller_port_device (self, port, RETRO_DEVICE_TYPE_NONE);
+  retro_core_set_controller_port_device (self, port, RETRO_CONTROLLER_TYPE_NONE);
 }
 
 static void
@@ -1337,8 +1337,8 @@ retro_core_boot (RetroCore  *self,
   RetroInit init;
   RetroControllerIterator *controller_iterator;
   guint *port;
-  RetroInputDevice *controller;
-  RetroDeviceType device_type;
+  RetroController *controller;
+  RetroControllerType controller_type;
   GError *tmp_error = NULL;
 
   g_return_if_fail (RETRO_IS_CORE (self));
@@ -1354,8 +1354,8 @@ retro_core_boot (RetroCore  *self,
   while (retro_controller_iterator_next (controller_iterator,
                                          &port,
                                          &controller)) {
-    device_type = retro_input_device_get_device_type (controller);
-    retro_core_set_controller_port_device (self, *port, device_type);
+    controller_type = retro_controller_get_controller_type (controller);
+    retro_core_set_controller_port_device (self, *port, controller_type);
   }
   g_object_unref (controller_iterator);
 
@@ -1443,9 +1443,9 @@ retro_core_set_current_media (RetroCore  *self,
 
 // FIXME Merge this into retro_core_set_controller().
 void
-retro_core_set_controller_port_device (RetroCore       *self,
-                                       guint            port,
-                                       RetroDeviceType  device)
+retro_core_set_controller_port_device (RetroCore           *self,
+                                       guint                port,
+                                       RetroControllerType  controller_type)
 {
   RetroSetControllerPortDevice set_controller_port_device;
 
@@ -1453,7 +1453,7 @@ retro_core_set_controller_port_device (RetroCore       *self,
 
   retro_core_push_cb_data (self);
   set_controller_port_device = retro_module_get_set_controller_port_device (self->module);
-  set_controller_port_device (port, device);
+  set_controller_port_device (port, controller_type);
   retro_core_pop_cb_data ();
 }
 
@@ -1766,14 +1766,14 @@ retro_core_poll_controllers (RetroCore *self)
 {
   RetroControllerIterator *iterator;
   guint *port;
-  RetroInputDevice *controller;
+  RetroController *controller;
 
   g_return_if_fail (RETRO_IS_CORE (self));
 
   iterator = retro_core_iterate_controllers (self);
   while (retro_controller_iterator_next (iterator, &port, &controller))
     if (controller != NULL)
-      retro_input_device_poll (controller);
+      retro_controller_poll (controller);
   g_object_unref (iterator);
 }
 
@@ -1781,7 +1781,7 @@ retro_core_poll_controllers (RetroCore *self)
  * retro_core_get_controller_input_state:
  * @self: a #RetroCore
  * @port: the port number
- * @controller_type: a #RetroDeviceType to query @self
+ * @controller_type: a #RetroControllerType to query @self
  * @index: an input index to interpret depending on @controller_type
  * @id: an input id to interpret depending on @controller_type
  *
@@ -1791,13 +1791,13 @@ retro_core_poll_controllers (RetroCore *self)
  * Returns: the input's state
  */
 gint16
-retro_core_get_controller_input_state (RetroCore       *self,
-                                       guint            port,
-                                       RetroDeviceType  controller_type,
-                                       guint            index,
-                                       guint            id)
+retro_core_get_controller_input_state (RetroCore           *self,
+                                       guint                port,
+                                       RetroControllerType  controller_type,
+                                       guint                index,
+                                       guint                id)
 {
-  RetroInputDevice *controller;
+  RetroController *controller;
 
   g_return_val_if_fail (RETRO_IS_CORE (self), 0);
 
@@ -1809,13 +1809,13 @@ retro_core_get_controller_input_state (RetroCore       *self,
   if (controller == NULL)
     return 0;
 
-  if ((retro_input_device_get_device_capabilities (controller) & (1 << controller_type)) == 0)
+  if ((retro_controller_get_capabilities (controller) & (1 << controller_type)) == 0)
     return 0;
 
-  return retro_input_device_get_input_state (controller,
-                                             controller_type,
-                                             index,
-                                             id);
+  return retro_controller_get_input_state (controller,
+                                           controller_type,
+                                           index,
+                                           id);
 }
 
 // FIXME documentation
@@ -1844,19 +1844,19 @@ retro_core_get_controller_capabilities (RetroCore *self)
  * retro_core_set_controller:
  * @self: a #RetroCore
  * @port: the port number
- * @controller: (nullable): a #RetroInputDevice
+ * @controller: (nullable): a #RetroController
  *
  * Plugs @controller into the specified port number of @self.
  */
 void
-retro_core_set_controller (RetroCore        *self,
-                           guint             port,
-                           RetroInputDevice *controller)
+retro_core_set_controller (RetroCore       *self,
+                           guint            port,
+                           RetroController *controller)
 {
   guint *port_copy;
 
   g_return_if_fail (RETRO_IS_CORE (self));
-  g_return_if_fail (RETRO_IS_INPUT_DEVICE (controller));
+  g_return_if_fail (RETRO_IS_CONTROLLER (controller));
 
   port_copy = g_new (guint, 1);
   *port_copy = port;
diff --git a/retro-gtk/retro-core.h b/retro-gtk/retro-core.h
index 4898478..d784b17 100644
--- a/retro-gtk/retro-core.h
+++ b/retro-gtk/retro-core.h
@@ -9,8 +9,7 @@
 
 #include <gtk/gtk.h>
 #include "retro-controller-iterator.h"
-#include "retro-device-type.h"
-#include "retro-input-device.h"
+#include "retro-controller-type.h"
 #include "retro-memory-type.h"
 
 G_BEGIN_DECLS
@@ -45,9 +44,6 @@ void retro_core_set_medias (RetroCore    *self,
 void retro_core_set_current_media (RetroCore  *self,
                                    guint       media_index,
                                    GError    **error);
-void retro_core_set_controller_port_device (RetroCore       *self,
-                                            guint            port,
-                                            RetroDeviceType  controller);
 void retro_core_reset (RetroCore *self);
 void retro_core_run (RetroCore *self);
 gboolean retro_core_supports_serialization (RetroCore *self);
@@ -68,15 +64,15 @@ void retro_core_set_memory (RetroCore       *self,
                             guint8          *data,
                             gsize            length);
 void retro_core_poll_controllers (RetroCore *self);
-gint16 retro_core_get_controller_input_state (RetroCore       *self,
-                                              uint             port,
-                                              RetroDeviceType  controller_type,
-                                              guint            index,
-                                              guint            id);
+gint16 retro_core_get_controller_input_state (RetroCore           *self,
+                                              uint                 port,
+                                              RetroControllerType  controller_type,
+                                              guint                index,
+                                              guint                id);
 guint64 retro_core_get_controller_capabilities (RetroCore *self);
-void retro_core_set_controller (RetroCore        *self,
-                                guint             port,
-                                RetroInputDevice *controller);
+void retro_core_set_controller (RetroCore       *self,
+                                guint            port,
+                                RetroController *controller);
 void retro_core_set_keyboard (RetroCore *self,
                               GtkWidget *widget);
 void retro_core_remove_controller (RetroCore *self,
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index 2421e3d..fd809a1 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -32,7 +32,7 @@ rumble_callback_set_rumble_state (guint             port,
                                   guint16           strength)
 {
   RetroCore *self;
-  RetroInputDevice *controller;
+  RetroController *controller;
 
   self = retro_core_get_cb_data ();
 
@@ -46,9 +46,7 @@ rumble_callback_set_rumble_state (guint             port,
   if (controller == NULL)
     return FALSE;
 
-  return retro_input_device_set_rumble_state (controller,
-                                              effect,
-                                              strength);
+  return retro_controller_set_rumble_state (controller, effect, strength);
 }
 
 static void
diff --git a/retro-gtk/retro-gtk.h b/retro-gtk/retro-gtk.h
index aee5c8b..700e217 100644
--- a/retro-gtk/retro-gtk.h
+++ b/retro-gtk/retro-gtk.h
@@ -11,11 +11,11 @@
 
 #include "retro-analog-id.h"
 #include "retro-analog-index.h"
+#include "retro-controller.h"
+#include "retro-controller-type.h"
 #include "retro-core.h"
 #include "retro-core-descriptor.h"
 #include "retro-core-view.h"
-#include "retro-device-type.h"
-#include "retro-input-device.h"
 #include "retro-joypad-id.h"
 #include "retro-lightgun-id.h"
 #include "retro-log.h"
diff --git a/retro-gtk/retro-input-descriptor.c b/retro-gtk/retro-input-descriptor.c
index f881fb8..c1a960c 100644
--- a/retro-gtk/retro-input-descriptor.c
+++ b/retro-gtk/retro-input-descriptor.c
@@ -40,7 +40,7 @@ retro_input_descriptor_copy (RetroInputDescriptor *self)
 
   copy = retro_input_descriptor_new ();
   copy->port = self->port;
-  copy->device = self->device;
+  copy->controller_type = self->controller_type;
   copy->index = self->index;
   copy->id = self->id;
   copy->description = g_strdup (self->description);
diff --git a/retro-gtk/retro-input-descriptor.h b/retro-gtk/retro-input-descriptor.h
index 66ee8c5..752db73 100644
--- a/retro-gtk/retro-input-descriptor.h
+++ b/retro-gtk/retro-input-descriptor.h
@@ -8,7 +8,7 @@
 #endif
 
 #include <glib-object.h>
-#include "retro-device-type.h"
+#include "retro-controller-type.h"
 
 G_BEGIN_DECLS
 
@@ -19,7 +19,7 @@ typedef struct _RetroInputDescriptor RetroInputDescriptor;
 struct _RetroInputDescriptor
 {
   guint port;
-  RetroDeviceType device;
+  RetroControllerType controller_type;
   guint index;
   guint id;
   gchar *description;
diff --git a/retro-gtk/retro-module.h b/retro-gtk/retro-module.h
index 8c9ba26..ac0bde6 100644
--- a/retro-gtk/retro-module.h
+++ b/retro-gtk/retro-module.h
@@ -8,7 +8,7 @@
 #endif
 
 #include <glib-object.h>
-#include "retro-device-type.h"
+#include "retro-controller-type.h"
 #include "retro-game-info.h"
 #include "retro-memory-type.h"
 #include "retro-system-av-info.h"
@@ -30,7 +30,7 @@ typedef void (*RetroGetSystemInfo) (RetroSystemInfo *info);
 typedef void (*RetroInit) ();
 typedef void (*RetroReset) ();
 typedef void (*RetroRun) ();
-typedef void (*RetroSetControllerPortDevice) (guint port, RetroDeviceType device);
+typedef void (*RetroSetControllerPortDevice) (guint port, RetroControllerType controller_type);
 typedef void (*RetroUnloadGame) ();
 
 #define RETRO_TYPE_MODULE (retro_module_get_type())



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