[gnome-games/wip/abhinavsingh/gamepad-config: 5/25] gamepad: Add 'unplugged' signal to GamepadMonitor



commit 71bb520600fd8fa1e68c30e7d37690d38a3b07c4
Author: theawless <theawless gmail com>
Date:   Wed May 24 09:26:29 2017 +0530

    gamepad: Add 'unplugged' signal to GamepadMonitor
    
    The motivation is that without this signal, the users of GamepadMonitor
    were forced to maintain an array for the plugged-in gamepads.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780754

 src/gamepad/gamepad-monitor.c    |   19 +++++++++++++++++--
 src/gamepad/gamepad-monitor.vapi |    1 +
 2 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/src/gamepad/gamepad-monitor.c b/src/gamepad/gamepad-monitor.c
index dfb3700..e4af861 100644
--- a/src/gamepad/gamepad-monitor.c
+++ b/src/gamepad/gamepad-monitor.c
@@ -19,6 +19,7 @@ G_DEFINE_TYPE (GamesGamepadMonitor, games_gamepad_monitor, G_TYPE_OBJECT)
 
 enum {
   SIGNAL_GAMEPAD_PLUGGED,
+  SIGNAL_GAMEPAD_UNPLUGGED,
   LAST_SIGNAL,
 };
 
@@ -45,6 +46,7 @@ on_gamepad_unplugged (GamesGamepad *sender,
   g_return_if_fail (sender != NULL);
 
   g_hash_table_remove (self->gamepads, sender);
+  g_signal_emit (self, signals[SIGNAL_GAMEPAD_UNPLUGGED], 0);
 }
 
 static GamesGamepad *
@@ -191,9 +193,9 @@ static void games_gamepad_monitor_class_init (GamesGamepadMonitorClass *klass) {
   G_OBJECT_CLASS (klass)->finalize = finalize;
 
   /**
-   * GamesGamepad::unplugged:
+   * GamesGamepad::plugged:
    *
-   * Emitted when the gamepad is unplugged.
+   * Emitted when the gamepad is plugged.
    */
   signals[SIGNAL_GAMEPAD_PLUGGED] =
     g_signal_new ("gamepad_plugged",
@@ -203,6 +205,19 @@ static void games_gamepad_monitor_class_init (GamesGamepadMonitorClass *klass) {
                   g_cclosure_marshal_VOID__OBJECT,
                   G_TYPE_NONE, 1,
                   GAMES_TYPE_GAMEPAD);
+
+  /**
+   * GamesGamepad::unplugged:
+   *
+   * Emitted when the gamepad is unplugged.
+   */
+  signals[SIGNAL_GAMEPAD_UNPLUGGED] =
+    g_signal_new ("gamepad_unplugged",
+                  GAMES_TYPE_GAMEPAD_MONITOR,
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
 }
 
 static void
diff --git a/src/gamepad/gamepad-monitor.vapi b/src/gamepad/gamepad-monitor.vapi
index ec61c08..8a67ec1 100644
--- a/src/gamepad/gamepad-monitor.vapi
+++ b/src/gamepad/gamepad-monitor.vapi
@@ -3,6 +3,7 @@
 [CCode (cheader_filename = "gamepad-monitor.h")]
 private class Games.GamepadMonitor : GLib.Object {
        public signal void gamepad_plugged (Gamepad gamepad);
+       public signal void gamepad_unplugged ();
        public static GamepadMonitor get_instance ();
        public void foreach_gamepad (GamepadCallback callback);
 }


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