[gnome-games] retro: Make RetroInputManager a RetroGtk.InputDeviceManager
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] retro: Make RetroInputManager a RetroGtk.InputDeviceManager
- Date: Sun, 21 Aug 2016 11:49:54 +0000 (UTC)
commit aaea9ccdba57be6724d884f5014cbec3a60a875e
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sat Aug 20 06:56:31 2016 +0200
retro: Make RetroInputManager a RetroGtk.InputDeviceManager
Make RetroInputManager implement RetroGtk.InputDeviceManager rather than
containing one.
https://bugzilla.gnome.org/show_bug.cgi?id=769318
src/retro/retro-input-manager.vala | 31 ++++++++++++++++++-------------
src/retro/retro-runner.vala | 2 +-
2 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/src/retro/retro-input-manager.vala b/src/retro/retro-input-manager.vala
index 79b8bae..e00540c 100644
--- a/src/retro/retro-input-manager.vala
+++ b/src/retro/retro-input-manager.vala
@@ -1,30 +1,30 @@
// This file is part of GNOME Games. License: GPLv3
-private class Games.RetroInputManager : Object {
- public RetroGtk.InputDeviceManager input { get; private set; }
-
+private class Games.RetroInputManager : RetroGtk.InputDeviceManager {
private RetroGtk.VirtualGamepad keyboard;
private GamepadMonitor gamepad_monitor;
private bool[] is_port_plugged;
+ private Gamepad?[] gamepads;
private int keyboard_port;
public RetroInputManager (Gtk.Widget widget) {
- input = new RetroGtk.InputDeviceManager ();
keyboard = new RetroGtk.VirtualGamepad (widget);
gamepad_monitor = GamepadMonitor.get_instance ();
- input.set_keyboard (new RetroGtk.Keyboard (widget));
+ set_keyboard (new RetroGtk.Keyboard (widget));
gamepad_monitor.foreach_gamepad ((gamepad) => {
var port = is_port_plugged.length;
is_port_plugged += true;
- input.set_controller_device (port, new RetroGamepad (gamepad));
+ gamepads += gamepad;
+ set_controller_device (port, new RetroGamepad (gamepad));
gamepad.unplugged.connect (() => handle_gamepad_unplugged (port));
});
keyboard_port = is_port_plugged.length;
is_port_plugged += true;
- input.set_controller_device (keyboard_port, keyboard);
+ gamepads += null;
+ set_controller_device (keyboard_port, keyboard);
gamepad_monitor.gamepad_plugged.connect (handle_gamepad_plugged);
}
@@ -32,7 +32,8 @@ private class Games.RetroInputManager : Object {
// Plug this gamepad to the port where the keyboard was plugged as a last resort
var port = keyboard_port;
gamepad.unplugged.connect (() => handle_gamepad_unplugged (port));
- input.set_controller_device (keyboard_port, new RetroGamepad (gamepad));
+ set_controller_device (keyboard_port, new RetroGamepad (gamepad));
+ gamepads[port] = gamepad;
// Assign keyboard to another unplugged port if exists and return
for (var i = keyboard_port; i < is_port_plugged.length; i++) {
@@ -40,7 +41,8 @@ private class Games.RetroInputManager : Object {
// Found an unplugged port and so assigning keyboard to it
keyboard_port = i;
is_port_plugged[keyboard_port] = true;
- input.set_controller_device (keyboard_port, keyboard);
+ gamepads[keyboard_port] = null;
+ set_controller_device (keyboard_port, keyboard);
return;
}
@@ -49,21 +51,24 @@ private class Games.RetroInputManager : Object {
// Now it means that there is no unplugged port so append keyboard to ports
keyboard_port = is_port_plugged.length;
is_port_plugged += true;
- input.set_controller_device (keyboard_port, keyboard);
+ set_controller_device (keyboard_port, keyboard);
}
private void handle_gamepad_unplugged (int port) {
if (keyboard_port > port) {
// Remove the controller and shift keyboard to "lesser" port
is_port_plugged[keyboard_port] = false;
- input.remove_controller_device (keyboard_port);
+ gamepads[keyboard_port] = null;
+ remove_controller_device (keyboard_port);
keyboard_port = port;
- input.set_controller_device (keyboard_port, keyboard);
+ gamepads[keyboard_port] = null;
+ set_controller_device (keyboard_port, keyboard);
}
else {
// Just remove the controller as no need to shift keyboard
is_port_plugged[port] = false;
- input.remove_controller_device (port);
+ gamepads[port] = null;
+ remove_controller_device (port);
}
}
}
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index cbe8765..bf4764e 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -228,7 +228,7 @@ public class Games.RetroRunner : Object, Runner {
core.video_interface = video;
core.audio_interface = audio;
- core.input_interface = input_manager.input;
+ core.input_interface = input_manager;
core.init ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]