[gnome-games/wip/exalm/ds-popover: 29/30] Add shortcut



commit 8852c644618d5eaa1f1496b51b75e98a7f4cc01d
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Fri Jan 18 23:58:50 2019 +0500

    Add shortcut

 plugins/nintendo-ds/src/nintendo-ds-runner.vala | 33 ++++++++++++++-----------
 src/command/command-runner.vala                 |  8 ++----
 src/core/runner.vala                            |  5 ++--
 src/dummy/dummy-runner.vala                     |  8 ++----
 src/meson.build                                 |  1 -
 src/retro/retro-runner.vala                     |  8 ++----
 src/ui/application-window.vala                  | 17 ++++---------
 src/ui/display-box.vala                         | 18 +++++---------
 8 files changed, 38 insertions(+), 60 deletions(-)
---
diff --git a/plugins/nintendo-ds/src/nintendo-ds-runner.vala b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
index 0623de11..194b849c 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-runner.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
@@ -60,7 +60,6 @@ private class Games.NintendoDsRunner : Object, Runner {
                        option_value = bottom ? "bottom only" : "top only";
                }
 
-
                try {
                        option.set_value (option_value);
                }
@@ -125,13 +124,27 @@ private class Games.NintendoDsRunner : Object, Runner {
                return runner.get_available_input_modes ();
        }
 
-       public bool gamepad_button_press_event (Manette.Event event) {
-               uint16 button;
+       public bool key_press_event (Gdk.EventKey event) {
+               var default_modifiers = Gtk.accelerator_get_default_mod_mask ();
 
-               if (!event.get_button (out button))
-                       return false;
+               if ((event.keyval == Gdk.Key.s || event.keyval == Gdk.Key.S) &&
+                   (event.state & default_modifiers) == Gdk.ModifierType.CONTROL_MASK)
+                       return swap_screens ();
+
+               return false;
+       }
+
+       public bool gamepad_button_press_event (uint16 button) {
+               if (button == EventCode.BTN_THUMBR)
+                       return swap_screens ();
+
+               return false;
+       }
+
+       private bool swap_screens () {
+               var layout = settings.get_string ("screen-layout");
 
-               if (button != EventCode.BTN_THUMBR)
+               if (layout != "quick switch")
                        return false;
 
                var view_bottom = settings.get_boolean ("view-bottom-screen");
@@ -139,12 +152,4 @@ private class Games.NintendoDsRunner : Object, Runner {
 
                return true;
        }
-
-       public bool gamepad_button_release_event (Manette.Event event) {
-               return false;
-       }
-
-       public bool gamepad_absolute_axis_event (Manette.Event event) {
-               return false;
-       }
 }
diff --git a/src/command/command-runner.vala b/src/command/command-runner.vala
index ca83c080..8db2a5e0 100644
--- a/src/command/command-runner.vala
+++ b/src/command/command-runner.vala
@@ -86,15 +86,11 @@ public class Games.CommandRunner : Object, Runner {
                return { };
        }
 
-       public bool gamepad_button_press_event (Manette.Event event) {
+       public bool key_press_event (Gdk.EventKey event) {
                return false;
        }
 
-       public bool gamepad_button_release_event (Manette.Event event) {
-               return false;
-       }
-
-       public bool gamepad_absolute_axis_event (Manette.Event event) {
+       public bool gamepad_button_press_event (uint16 button) {
                return false;
        }
 }
diff --git a/src/core/runner.vala b/src/core/runner.vala
index 84799644..e5374866 100644
--- a/src/core/runner.vala
+++ b/src/core/runner.vala
@@ -18,7 +18,6 @@ public interface Games.Runner : Object {
        public abstract void stop ();
        public abstract InputMode[] get_available_input_modes ();
 
-       public abstract bool gamepad_button_press_event (Manette.Event event);
-       public abstract bool gamepad_button_release_event (Manette.Event event);
-       public abstract bool gamepad_absolute_axis_event (Manette.Event event);
+       public abstract bool key_press_event (Gdk.EventKey event);
+       public abstract bool gamepad_button_press_event (uint16 button);
 }
diff --git a/src/dummy/dummy-runner.vala b/src/dummy/dummy-runner.vala
index d5abe7da..d82572e0 100644
--- a/src/dummy/dummy-runner.vala
+++ b/src/dummy/dummy-runner.vala
@@ -52,15 +52,11 @@ private class Games.DummyRunner : Object, Runner {
                return { };
        }
 
-       public bool gamepad_button_press_event (Manette.Event event) {
+       public bool key_press_event (Gdk.EventKey event) {
                return false;
        }
 
-       public bool gamepad_button_release_event (Manette.Event event) {
-               return false;
-       }
-
-       public bool gamepad_absolute_axis_event (Manette.Event event) {
+       public bool gamepad_button_press_event (uint16 button) {
                return false;
        }
 }
diff --git a/src/meson.build b/src/meson.build
index cfacbe6c..054e720d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -237,7 +237,6 @@ plugin_dependencies = [
   gio_dep,
   glib_dep,
   gtk_dep,
-  manette_dep,
   retro_gtk_dep,
   soup_dep,
   tracker_sparql_dep,
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index b14d2ae0..12f72c5e 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -309,15 +309,11 @@ public class Games.RetroRunner : Object, Runner {
                        return { InputMode.GAMEPAD };
        }
 
-       public bool gamepad_button_press_event (Manette.Event event) {
+       public bool key_press_event (Gdk.EventKey event) {
                return false;
        }
 
-       public bool gamepad_button_release_event (Manette.Event event) {
-               return false;
-       }
-
-       public bool gamepad_absolute_axis_event (Manette.Event event) {
+       public bool gamepad_button_press_event (uint16 button) {
                return false;
        }
 
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index a59f21c4..94ccabd0 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -308,28 +308,18 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        public bool gamepad_button_release_event (Manette.Event event) {
-               if (!is_active)
-                       return false;
-
                switch (ui_state) {
                case UiState.COLLECTION:
-                       return collection_box.gamepad_button_release_event (event);
-               case UiState.DISPLAY:
-                       return display_box.gamepad_button_release_event (event);
+                       return is_active && collection_box.gamepad_button_release_event (event);
                default:
                        return false;
                }
        }
 
        public bool gamepad_absolute_axis_event (Manette.Event event) {
-               if (!is_active)
-                       return false;
-
                switch (ui_state) {
                case UiState.COLLECTION:
-                       return collection_box.gamepad_absolute_axis_event (event);
-               case UiState.DISPLAY:
-                       return display_box.gamepad_absolute_axis_event (event);
+                       return is_active && collection_box.gamepad_absolute_axis_event (event);
                default:
                        return false;
                }
@@ -632,6 +622,9 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                if (ui_state != UiState.DISPLAY)
                        return false;
 
+               if (display_box.on_key_press_event (event))
+                       return true;
+
                var default_modifiers = Gtk.accelerator_get_default_mod_mask ();
 
                if ((event.keyval == Gdk.Key.f || event.keyval == Gdk.Key.F) &&
diff --git a/src/ui/display-box.vala b/src/ui/display-box.vala
index 1ea8c63f..1162066c 100644
--- a/src/ui/display-box.vala
+++ b/src/ui/display-box.vala
@@ -71,33 +71,27 @@ private class Games.DisplayBox : Gtk.Bin {
                        display_bin.remove (child);
        }
 
-       public bool gamepad_button_press_event (Manette.Event event) {
+       public bool on_key_press_event (Gdk.EventKey event) {
                if (!get_mapped ())
                        return false;
 
                if (runner == null)
                        return false;
 
-               return runner.gamepad_button_press_event (event);
+               return runner.key_press_event (event);
        }
 
-       public bool gamepad_button_release_event (Manette.Event event) {
+       public bool gamepad_button_press_event (Manette.Event event) {
                if (!get_mapped ())
                        return false;
 
                if (runner == null)
                        return false;
 
-               return runner.gamepad_button_release_event (event);
-       }
-
-       public bool gamepad_absolute_axis_event (Manette.Event event) {
-               if (!get_mapped ())
-                       return false;
-
-               if (runner == null)
+               uint16 button;
+               if (!event.get_button (out button))
                        return false;
 
-               return runner.gamepad_absolute_axis_event (event);
+               return runner.gamepad_button_press_event (button);
        }
 }


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