[retro-gtk] retro-controller: Add get_supports_rumble()



commit a54bfc093fd9caf1586c0650e1a9b9470dbd5611
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Jan 6 18:55:01 2020 +0500

    retro-controller: Add get_supports_rumble()
    
    Stop returning value from set_rumble_state() and have a separate function
    for checking whether a controller supports rumble.
    
    This is required for moving the core out of process, as setting rumble
    effect will be done async, and still immediately have a return value.

 retro-gtk/retro-controller.c           | 32 ++++++++++++++++++++++++++------
 retro-gtk/retro-controller.h           | 14 ++++++++------
 retro-gtk/retro-core-view-controller.c |  8 +++++++-
 retro-gtk/retro-environment.c          |  7 ++++++-
 tests/retro-test-controller.c          |  9 +++++++--
 5 files changed, 54 insertions(+), 16 deletions(-)
---
diff --git a/retro-gtk/retro-controller.c b/retro-gtk/retro-controller.c
index e966586..26364a1 100644
--- a/retro-gtk/retro-controller.c
+++ b/retro-gtk/retro-controller.c
@@ -126,6 +126,28 @@ retro_controller_has_capability (RetroController     *self,
   return (capabilities & (1 << masked_controller_type)) != 0;
 }
 
+/**
+ * retro_controller_get_supports_rumble:
+ * @self: a #RetroController
+ *
+ * Gets whether @self supports rumble effects.
+ *
+ * Returns: whether @self supports rumble effects.
+ */
+gboolean
+retro_controller_get_supports_rumble (RetroController *self)
+{
+  RetroControllerInterface *iface;
+
+  g_return_val_if_fail (RETRO_IS_CONTROLLER (self), FALSE);
+
+  iface = RETRO_CONTROLLER_GET_IFACE (self);
+
+  g_return_val_if_fail (iface->get_supports_rumble != NULL, FALSE);
+
+  return iface->get_supports_rumble (self);
+}
+
 /**
  * retro_controller_set_rumble_state:
  * @self: a #RetroController
@@ -133,21 +155,19 @@ retro_controller_has_capability (RetroController     *self,
  * @strength: the rumble effect strength
  *
  * Sets the rumble state of @self.
- *
- * Returns: whether the rumble state has been successfully set.
  */
-gboolean
+void
 retro_controller_set_rumble_state (RetroController   *self,
                                    RetroRumbleEffect  effect,
                                    guint16            strength)
 {
   RetroControllerInterface *iface;
 
-  g_return_val_if_fail (RETRO_IS_CONTROLLER (self), FALSE);
+  g_return_if_fail (RETRO_IS_CONTROLLER (self));
 
   iface = RETRO_CONTROLLER_GET_IFACE (self);
 
-  g_return_val_if_fail (iface->set_rumble_state != NULL, FALSE);
+  g_return_if_fail (iface->set_rumble_state != NULL);
 
-  return iface->set_rumble_state (self, effect, strength);
+  iface->set_rumble_state (self, effect, strength);
 }
diff --git a/retro-gtk/retro-controller.h b/retro-gtk/retro-controller.h
index ee28dd5..eae1a5a 100644
--- a/retro-gtk/retro-controller.h
+++ b/retro-gtk/retro-controller.h
@@ -25,9 +25,10 @@ struct _RetroControllerInterface
                              RetroInput      *input);
   RetroControllerType (*get_controller_type) (RetroController *self);
   guint64 (*get_capabilities) (RetroController *self);
-  gboolean (*set_rumble_state) (RetroController   *self,
-                                RetroRumbleEffect  effect,
-                                guint16            strength);
+  gboolean (*get_supports_rumble) (RetroController *self);
+  void (*set_rumble_state) (RetroController   *self,
+                            RetroRumbleEffect  effect,
+                            guint16            strength);
 };
 
 void retro_controller_poll (RetroController *self);
@@ -37,8 +38,9 @@ RetroControllerType retro_controller_get_controller_type (RetroController *self)
 guint64 retro_controller_get_capabilities (RetroController *self);
 gboolean retro_controller_has_capability (RetroController     *self,
                                           RetroControllerType  controller_type);
-gboolean retro_controller_set_rumble_state (RetroController   *self,
-                                            RetroRumbleEffect  effect,
-                                            guint16            strength);
+gboolean retro_controller_get_supports_rumble (RetroController *self);
+void retro_controller_set_rumble_state (RetroController   *self,
+                                        RetroRumbleEffect  effect,
+                                        guint16            strength);
 
 G_END_DECLS
diff --git a/retro-gtk/retro-core-view-controller.c b/retro-gtk/retro-core-view-controller.c
index 39e6309..8a5886f 100644
--- a/retro-gtk/retro-core-view-controller.c
+++ b/retro-gtk/retro-core-view-controller.c
@@ -81,11 +81,16 @@ retro_core_view_controller_get_capabilities (RetroController *base)
 }
 
 static gboolean
+retro_core_view_controller_get_supports_rumble (RetroController *self)
+{
+  return FALSE;
+}
+
+static void
 retro_core_view_controller_set_rumble_state (RetroController   *self,
                                              RetroRumbleEffect  effect,
                                              guint16            strength)
 {
-  return FALSE;
 }
 
 static void
@@ -118,6 +123,7 @@ retro_controller_interface_init (RetroControllerInterface *iface)
   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;
+  iface->get_supports_rumble = retro_core_view_controller_get_supports_rumble;
   iface->set_rumble_state = retro_core_view_controller_set_rumble_state;
 }
 
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index a8b3ddd..af83b16 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -114,7 +114,12 @@ rumble_callback_set_rumble_state (guint             port,
   if (controller == NULL)
     return FALSE;
 
-  return retro_controller_set_rumble_state (controller, effect, strength);
+  if (!retro_controller_get_supports_rumble (controller))
+    return FALSE;
+
+  retro_controller_set_rumble_state (controller, effect, strength);
+
+  return TRUE;
 }
 
 static void
diff --git a/tests/retro-test-controller.c b/tests/retro-test-controller.c
index 074f086..085f433 100644
--- a/tests/retro-test-controller.c
+++ b/tests/retro-test-controller.c
@@ -115,6 +115,12 @@ retro_test_controller_get_capabilities (RetroController *base)
 }
 
 static gboolean
+retro_test_controller_get_supports_rumble (RetroController *base)
+{
+  return FALSE;
+}
+
+static void
 retro_test_controller_set_rumble_state (RetroController   *base,
                                         RetroRumbleEffect  effect,
                                         guint16            strength)
@@ -122,8 +128,6 @@ retro_test_controller_set_rumble_state (RetroController   *base,
   RetroTestController *self = RETRO_TEST_CONTROLLER (base);
 
   self->rumble[effect] = strength;
-
-  return FALSE;
 }
 
 static void
@@ -166,6 +170,7 @@ retro_controller_interface_init (RetroControllerInterface *iface)
   iface->get_input_state =  retro_test_controller_get_input_state;
   iface->get_controller_type = retro_test_controller_get_controller_type;
   iface->get_capabilities = retro_test_controller_get_capabilities;
+  iface->get_supports_rumble = retro_test_controller_get_supports_rumble;
   iface->set_rumble_state = retro_test_controller_set_rumble_state;
 }
 


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