[gnome-games/wip/abhinavsingh/gamepad-config: 17/25] ui: Improve error displays in GamepadMapper



commit 49bf8130e02f5ecb2cfcd0213e4ba77a8d7eab7c
Author: theawless <theawless gmail com>
Date:   Sun Jun 18 20:26:02 2017 +0530

    ui: Improve error displays in GamepadMapper
    
    Make the errors hide automatically and add error messages for
    incompatible mappings. This commit also fixes minor style problems.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780754

 src/ui/gamepad-mapper.vala |   46 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/src/ui/gamepad-mapper.vala b/src/ui/gamepad-mapper.vala
index 7675e35..6e8adb8 100644
--- a/src/ui/gamepad-mapper.vala
+++ b/src/ui/gamepad-mapper.vala
@@ -88,6 +88,14 @@ private class Games.GamepadMapper : Gtk.Box {
        private Gamepad gamepad;
        private GamepadMappingBuilder mapping_builder;
        private ulong gamepad_event_handler_id;
+       private uint error_message_hider_id;
+
+       construct {
+               error_message.notify["label"].connect (() => {
+                       if (error_message.label != "")
+                               error_message_hide ();
+               });
+       }
 
        public GamepadMapper (Gamepad gamepad) {
                this.gamepad = gamepad;
@@ -95,6 +103,19 @@ private class Games.GamepadMapper : Gtk.Box {
                state = State.BEGIN;
        }
 
+       private void error_message_hide () {
+               if (error_message_hider_id > 0) {
+                       GLib.Source.remove (error_message_hider_id);
+               }
+               error_message_hider_id = GLib.Timeout.add (2000, () => {
+                       error_message_hider_id = 0;
+                       if (error_message != null)
+                               error_message.label = "";
+
+                       return false;
+               });
+       }
+
        public void start () {
                next_input ();
        }
@@ -141,7 +162,15 @@ private class Games.GamepadMapper : Gtk.Box {
        }
 
        private void on_button_event (EventGamepadButton event) {
-               if (!mapping_builder.set_button_mapping (event.gamepad_button.hardware_index, input)) {
+               if (input.type == EventCode.EV_ABS) {
+                       error_message.label = _("This combination is not valid");
+
+                       return;
+               }
+
+               var success = mapping_builder.set_button_mapping (event.gamepad_button.hardware_index,
+                                                                 input);
+               if (!success) {
                        error_message.label = _("This button is already in use");
 
                        return;
@@ -151,10 +180,17 @@ private class Games.GamepadMapper : Gtk.Box {
        }
 
        private void on_axis_event (EventGamepadAxis event) {
+               if (input.type == EventCode.EV_KEY) {
+                       error_message.label = _("This combination is not valid");
+
+                       return;
+               }
                if (-0.8 < event.gamepad_axis.value && event.gamepad_axis.value < 0.8)
                        return;
 
-               if (!mapping_builder.set_axis_mapping (event.gamepad_axis.hardware_index, input)) {
+               var success = mapping_builder.set_axis_mapping (event.gamepad_axis.hardware_index,
+                                                               input);
+               if (!success) {
                        error_message.label = _("This axis is already in use");
 
                        return;
@@ -167,7 +203,11 @@ private class Games.GamepadMapper : Gtk.Box {
                if (event.gamepad_hat.value == 0)
                        return;
 
-               if (!mapping_builder.set_hat_mapping (event.gamepad_hat.hardware_index, 
event.gamepad_hat.value, event.gamepad_hat.axis, input)) {
+               var success = mapping_builder.set_hat_mapping (event.gamepad_hat.hardware_index,
+                                                              event.gamepad_hat.value,
+                                                              event.gamepad_hat.axis,
+                                                              input);
+               if (!success) {
                        error_message.label = _("This hat is already in use");
 
                        return;


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