[gnome-games/wip/abhinavsingh/gamepad-reassign: 7/12] core: Add ControllerSet
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-reassign: 7/12] core: Add ControllerSet
- Date: Sat, 26 Aug 2017 10:40:53 +0000 (UTC)
commit bc62f9968b06ede765b1f87eb7c06fb42a2c9a8a
Author: theawless <theawless gmail com>
Date: Sat Aug 12 00:05:25 2017 +0530
core: Add ControllerSet
This will be used to move controller information from retro to ui
similar to media set.
src/Makefile.am | 1 +
src/core/controller-set.vala | 53 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 645eb45..e9cd162 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,6 +64,7 @@ gnome_games_SOURCES = \
core/game-collection.vala \
core/game-uri-adapter.vala \
core/icon.vala \
+ core/controller-set.vala \
core/input-capabilities.vala \
core/media.vala \
core/media-info.vala \
diff --git a/src/core/controller-set.vala b/src/core/controller-set.vala
new file mode 100644
index 0000000..eee90ca
--- /dev/null
+++ b/src/core/controller-set.vala
@@ -0,0 +1,53 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.ControllerSet : Object {
+ public signal void changed ();
+ public signal void reset ();
+
+ public bool has_multiple_inputs {
+ get {
+ return has_keyboard && gamepads.length > 0
+ || gamepads.length > 1;
+ }
+ }
+
+ public bool has_keyboard {
+ get { return keyboard_port != uint.MAX; }
+ }
+
+ public bool has_gamepads {
+ get { return gamepads.length > 0; }
+ }
+
+ public uint first_unplugged_port {
+ get {
+ uint i = 0;
+ while (gamepads.contains (i) || i == keyboard_port) {
+ i++;
+ }
+ return i;
+ }
+ }
+
+ public uint keyboard_port { set; get; }
+ public HashTable<uint, Gamepad?> gamepads { set; get; }
+
+ construct {
+ keyboard_port = uint.MAX;
+ gamepads = new HashTable<uint, Gamepad?> (GLib.direct_hash, GLib.direct_equal);
+ notify["gamepads"].connect (() => changed ());
+ notify["keyboard-port"].connect (() => changed ());
+ }
+
+ public void add_gamepad (uint port, Gamepad gamepad) {
+ gamepads.insert (port, gamepad);
+
+ changed ();
+ }
+
+ public void remove_gamepad (uint port) {
+ gamepads.remove (port);
+
+ changed ();
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]