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



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

    gamepad: Add 'unplugged' signal to GamepadMonitor
    
    This will benefit the users of GamepadMonitor. The motivation is that
    without it, the users were forced to maintain a set for the plugged in
    gamepads.

 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]