[gnome-games/wip/exalm/keyboard: 1/2] retro-input-manager: Re-introduce CoreView joypad



commit fbd00335b2a760d076fab1affeeeb68016710f75
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Nov 29 23:13:17 2018 +0500

    retro-input-manager: Re-introduce CoreView joypad
    
    When a controller is set to null, retro-gtk tells core to change device
    type to Retro.ControllerType.NONE, which breaks input in some specific
    games. So either set it to CoreView joypad controller or to null,
    depending on input mode.
    
    Effectively reverts commit 099eb11c4060bacddb1e66383bb22eeec5b9fa3c.

 src/retro/retro-input-manager.vala | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
---
diff --git a/src/retro/retro-input-manager.vala b/src/retro/retro-input-manager.vala
index 5acd1257..6a690dd5 100644
--- a/src/retro/retro-input-manager.vala
+++ b/src/retro/retro-input-manager.vala
@@ -3,6 +3,7 @@
 private class Games.RetroInputManager : Object {
        private Retro.Core core;
        private Retro.CoreView view;
+       private Retro.Controller core_view_joypad;
        private KeyboardMappingManager keyboard_mapping_manager;
        private Manette.Monitor monitor;
        private InputMode _input_mode;
@@ -12,8 +13,6 @@ private class Games.RetroInputManager : Object {
                        if (value == _input_mode)
                                return;
 
-                       var core_view_joypad = view.as_controller (Retro.ControllerType.JOYPAD);
-
                        _input_mode = value;
                        switch (value) {
                        case InputMode.GAMEPAD:
@@ -32,6 +31,8 @@ private class Games.RetroInputManager : Object {
 
                                break;
                        }
+
+                       update_core_view_gamepad ();
                }
        }
 
@@ -53,7 +54,8 @@ private class Games.RetroInputManager : Object {
                view.set_key_joypad_mapping (keyboard_mapping_manager.mapping);
                keyboard_mapping_manager.changed.connect (on_keyboard_mapping_manager_changed);
                view.set_as_default_controller (core);
-               input_mode = InputMode.GAMEPAD;
+
+               core_view_joypad = view.as_controller (Retro.ControllerType.JOYPAD);
 
                monitor = new Manette.Monitor ();
                var iterator = monitor.iterate ();
@@ -70,8 +72,9 @@ private class Games.RetroInputManager : Object {
                core_view_joypad_port = controllers.length;
                devices += null;
                controllers += null;
-               core.set_controller (core_view_joypad_port, null);
                monitor.device_connected.connect (on_device_connected);
+
+               input_mode = InputMode.GAMEPAD;
        }
 
        ~RetroInputManager () {
@@ -83,6 +86,18 @@ private class Games.RetroInputManager : Object {
                        core.set_controller (port, null);
        }
 
+       private void update_core_view_gamepad () {
+               devices[core_view_joypad_port] = null;
+
+               if (input_mode == InputMode.GAMEPAD) {
+                       controllers[core_view_joypad_port] = core_view_joypad;
+                       core.set_controller (core_view_joypad_port, core_view_joypad);
+               } else {
+                       controllers[core_view_joypad_port] = null;
+                       core.set_controller (core_view_joypad_port, null);
+               }
+       }
+
        private void on_keyboard_mapping_manager_changed () {
                view.set_key_joypad_mapping (keyboard_mapping_manager.mapping);
        }
@@ -103,9 +118,7 @@ private class Games.RetroInputManager : Object {
                        if (controllers[i] == null) {
                                // Found an disconnected port and so assigning core_view_joypad to it
                                core_view_joypad_port = i;
-                               devices[core_view_joypad_port] = null;
-                               controllers[core_view_joypad_port] = null;
-                               core.set_controller (core_view_joypad_port, null);
+                               update_core_view_gamepad ();
 
                                return;
                        }
@@ -116,7 +129,7 @@ private class Games.RetroInputManager : Object {
                core_view_joypad_port = controllers.length;
                devices += null;
                controllers += null;
-               core.set_controller (core_view_joypad_port, null);
+               update_core_view_gamepad ();
        }
 
        private void on_device_disconnected (Manette.Device device) {
@@ -131,10 +144,9 @@ private class Games.RetroInputManager : Object {
                        // "lesser" port.
                        devices[core_view_joypad_port] = null;
                        controllers[core_view_joypad_port] = null;
-                       core_view_joypad_port = port;
-                       devices[core_view_joypad_port] = null;
-                       controllers[core_view_joypad_port] = null;
                        core.set_controller (core_view_joypad_port, null);
+                       core_view_joypad_port = port;
+                       update_core_view_gamepad ();
                }
                else {
                        // Just remove the controller as no need to shift the


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