[gnome-games/wip/abhinavsingh/gamepad-reassignment] Temp patch for input set
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-reassignment] Temp patch for input set
- Date: Sat, 8 Jul 2017 05:44:31 +0000 (UTC)
commit a9248a52c11767440ff97ac50d8d279a2262c1c7
Author: theawless <theawless gmail com>
Date: Sat Jul 8 11:13:25 2017 +0530
Temp patch for input set
src/Makefile.am | 1 +
src/core/input-set.vala | 10 ++++++
src/gamepad/gamepad.vapi | 2 +-
src/gamepad/raw-gamepad.vapi | 2 +-
src/retro/retro-input-manager.vala | 56 ++++++++++++++++++-----------------
src/retro/retro-runner.vala | 4 ++
6 files changed, 46 insertions(+), 29 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a49476d..68a6b6a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,6 +47,7 @@ gnome_games_SOURCES = \
core/game-collection.vala \
core/game-uri-adapter.vala \
core/icon.vala \
+ core/input-set.vala \
core/input-capabilities.vala \
core/media.vala \
core/media-info.vala \
diff --git a/src/core/input-set.vala b/src/core/input-set.vala
new file mode 100644
index 0000000..d9ea8dd
--- /dev/null
+++ b/src/core/input-set.vala
@@ -0,0 +1,10 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.InputSet : Object {
+ public HashTable<uint, Gamepad?> gamepads { set; get; }
+ public uint keyboard_port { set; get; }
+
+ construct {
+ gamepads = new HashTable<uint, Gamepad?> (GLib.direct_hash, GLib.direct_equal);
+ }
+}
diff --git a/src/gamepad/gamepad.vapi b/src/gamepad/gamepad.vapi
index e52b030..c200916 100644
--- a/src/gamepad/gamepad.vapi
+++ b/src/gamepad/gamepad.vapi
@@ -1,7 +1,7 @@
// This file is part of GNOME Games. License: GPL-3.0+.
[CCode (cheader_filename = "gamepad.h")]
-private class Games.Gamepad : GLib.Object {
+public class Games.Gamepad : GLib.Object {
public signal void event (Event event);
public signal void button_press_event (Event event);
public signal void button_release_event (Event event);
diff --git a/src/gamepad/raw-gamepad.vapi b/src/gamepad/raw-gamepad.vapi
index 7c4099d..8ece824 100644
--- a/src/gamepad/raw-gamepad.vapi
+++ b/src/gamepad/raw-gamepad.vapi
@@ -1,7 +1,7 @@
// This file is part of GNOME Games. License: GPL-3.0+.
[CCode (cheader_filename = "raw-gamepad.h")]
-private interface Games.RawGamepad : GLib.Object {
+public interface Games.RawGamepad : GLib.Object {
public abstract signal void event (Event event);
public abstract signal void unplugged ();
public abstract string guid { get; }
diff --git a/src/retro/retro-input-manager.vala b/src/retro/retro-input-manager.vala
index 9e0ab5c..0919738 100644
--- a/src/retro/retro-input-manager.vala
+++ b/src/retro/retro-input-manager.vala
@@ -3,10 +3,14 @@
private class Games.RetroInputManager : Retro.InputDeviceManager, Retro.Rumble {
private Retro.VirtualGamepad keyboard;
private GamepadMonitor gamepad_monitor;
- private Retro.InputDevice?[] input_devices;
- private int keyboard_port;
private bool present_analog_sticks;
+ public InputSet input_set { private set; get; }
+
+ construct {
+ input_set = new InputSet ();
+ }
+
public RetroInputManager (Gtk.Widget widget, bool present_analog_sticks) {
this.present_analog_sticks = present_analog_sticks;
@@ -15,66 +19,64 @@ private class Games.RetroInputManager : Retro.InputDeviceManager, Retro.Rumble {
gamepad_monitor = GamepadMonitor.get_instance ();
gamepad_monitor.foreach_gamepad ((gamepad) => {
- var port = input_devices.length;
+ var port = input_set.gamepads.size ();
+ input_set.gamepads[port] = gamepad;
var retro_gamepad = new RetroGamepad (gamepad, present_analog_sticks);
- input_devices += retro_gamepad;
set_controller_device (port, retro_gamepad);
gamepad.unplugged.connect (() => handle_gamepad_unplugged (port));
});
- keyboard_port = input_devices.length;
- input_devices += keyboard;
- set_controller_device (keyboard_port, keyboard);
+ input_set.keyboard_port = input_set.gamepads.size ();
+ set_controller_device (input_set.keyboard_port, keyboard);
gamepad_monitor.gamepad_plugged.connect (handle_gamepad_plugged);
}
private void handle_gamepad_plugged (Gamepad gamepad) {
// Plug this gamepad to the port where the keyboard was plugged as a last resort
- var port = keyboard_port;
+ var port = input_set.keyboard_port;
+ input_set.gamepads[port] = gamepad;
var retro_gamepad = new RetroGamepad (gamepad, present_analog_sticks);
- input_devices[port] = retro_gamepad;
set_controller_device (port, retro_gamepad);
gamepad.unplugged.connect (() => handle_gamepad_unplugged (port));
// Assign keyboard to another unplugged port if exists and return
- for (var i = keyboard_port; i < input_devices.length; i++) {
- if (input_devices[i] == null) {
+ for (var i = input_set.keyboard_port; i < input_set.gamepads.size (); i++) {
+ if (input_set.gamepads[i] == null) {
// Found an unplugged port and so assigning keyboard to it
- keyboard_port = i;
- input_devices[keyboard_port] = keyboard;
- set_controller_device (keyboard_port, keyboard);
+ input_set.keyboard_port = i;
+ input_set.gamepads[input_set.keyboard_port] = null;
+ set_controller_device (input_set.keyboard_port, keyboard);
return;
}
}
// Now it means that there is no unplugged port so append keyboard to ports
- keyboard_port = input_devices.length;
- input_devices += keyboard;
- set_controller_device (keyboard_port, keyboard);
+ input_set.keyboard_port = input_set.gamepads.size ();
+ input_set.gamepads[input_set.keyboard_port] = null;
+ set_controller_device (input_set.keyboard_port, keyboard);
}
- private void handle_gamepad_unplugged (int port) {
- if (keyboard_port > port) {
+ private void handle_gamepad_unplugged (uint port) {
+ if (input_set.keyboard_port > port) {
// Remove the controller and shift keyboard to "lesser" port
- input_devices[keyboard_port] = null;
- remove_controller_device (keyboard_port);
- keyboard_port = port;
- input_devices[keyboard_port] = keyboard;
- set_controller_device (keyboard_port, keyboard);
+ input_set.gamepads[input_set.keyboard_port] = null;
+ remove_controller_device (input_set.keyboard_port);
+ input_set.keyboard_port = port;
+ set_controller_device (input_set.keyboard_port, keyboard);
}
else {
// Just remove the controller as no need to shift keyboard
- input_devices[port] = null;
+ input_set.gamepads[port] = null;
remove_controller_device (port);
}
}
private bool set_rumble_state (uint port, Retro.RumbleEffect effect, uint16 strength) {
- if (port > input_devices.length)
+ if (port > input_set.gamepads.size ())
return false;
- if (input_devices[port] == null || input_devices[port] == keyboard)
+ if (input_set.gamepads[port] == null)
return false;
// TODO Transmit the rumble signal to the gamepad.
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 8d7d5f8..1594b32 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -34,6 +34,10 @@ public class Games.RetroRunner : Object, Runner {
get { return _media_set; }
}
+ public InputSet? input_set {
+ get { return input_manager.input_set; }
+ }
+
private Retro.Core core;
private Retro.CairoDisplay video;
private Retro.PaPlayer audio;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]