[retro-gtk] Move retro-gtk/input to retro-gobject/input



commit dc492f4497116dd1bbb7b735d13dcebfc5469816
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Mon Feb 13 11:43:43 2017 +0100

    Move retro-gtk/input to retro-gobject/input
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777489

 Makefile.am                                        |    2 +-
 configure.ac                                       |    2 +-
 retro-gobject/Makefile.am                          |    5 +
 .../input/gamepad-button-type.vala                 |    7 +-
 .../input/gamepad-configuration.vala               |    7 +-
 retro-gobject/input/input-device-manager.vala      |    9 +
 .../input/keyboard-state.vala                      |    7 +-
 retro-gobject/input/keyboard.vala                  |  168 +++++++++++++++++++-
 {retro-gtk => retro-gobject}/input/mouse.vala      |   29 ++--
 .../input/virtual-gamepad.vala                     |   17 +--
 retro-gtk/Makefile.am                              |    1 -
 retro-gtk/input/input-device-manager.vala          |   18 --
 retro-gtk/input/keyboard.vala                      |  171 --------------------
 13 files changed, 201 insertions(+), 242 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index fabb128..e763ce4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@
 
 NULL =
 
-SUBDIRS = retro-gobject retro-gtk po
+SUBDIRS = retro-gobject po
 
 dist_doc_DATA = \
        README \
diff --git a/configure.ac b/configure.ac
index e7bf4a3..6b22334 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,7 +46,7 @@ AC_SUBST(retro_gobject_pkg_modules)
 # retro-gtk
 ###########
 
-retro_gtk_pkg_modules="gobject-2.0 glib-2.0 gtk+-3.0"
+retro_gtk_pkg_modules="gobject-2.0 glib-2.0"
 PKG_CHECK_MODULES(RETRO_GTK, $retro_gtk_pkg_modules)
 retro_gtk_pkg_modules="$retro_gtk_pkg_modules retro-gobject-0.8"
 AC_SUBST(retro_gtk_pkg_modules)
diff --git a/retro-gobject/Makefile.am b/retro-gobject/Makefile.am
index e03cda5..7a61922 100644
--- a/retro-gobject/Makefile.am
+++ b/retro-gobject/Makefile.am
@@ -31,10 +31,15 @@ libretro_gobject_la_SOURCES = \
        \
        input/controller.vala \
        input/device.vala \
+       input/gamepad-button-type.vala \
+       input/gamepad-configuration.vala \
        input/input.vala \
        input/input-device.vala \
        input/input-device-manager.vala \
        input/keyboard.vala \
+       input/keyboard-state.vala \
+       input/mouse.vala \
+       input/virtual-gamepad.vala \
        \
        log/file-stream-log.vala \
        log/log.vala \
diff --git a/retro-gtk/input/gamepad-button-type.vala b/retro-gobject/input/gamepad-button-type.vala
similarity index 85%
rename from retro-gtk/input/gamepad-button-type.vala
rename to retro-gobject/input/gamepad-button-type.vala
index 17bfad8..5f41386 100644
--- a/retro-gtk/input/gamepad-button-type.vala
+++ b/retro-gobject/input/gamepad-button-type.vala
@@ -1,8 +1,6 @@
 // This file is part of RetroGtk. License: GPLv3
 
-namespace RetroGtk {
-
-public enum GamepadButtonType {
+public enum Retro.GamepadButtonType {
        ACTION_DOWN,
        ACTION_LEFT,
        SELECT,
@@ -25,6 +23,3 @@ public enum GamepadButtonType {
                return 1 + (size_t) GamepadButtonType.HOME;
        }
 }
-
-}
-
diff --git a/retro-gtk/input/gamepad-configuration.vala b/retro-gobject/input/gamepad-configuration.vala
similarity index 95%
rename from retro-gtk/input/gamepad-configuration.vala
rename to retro-gobject/input/gamepad-configuration.vala
index 9baeac0..5d83480 100644
--- a/retro-gtk/input/gamepad-configuration.vala
+++ b/retro-gobject/input/gamepad-configuration.vala
@@ -1,8 +1,6 @@
 // This file is part of RetroGtk. License: GPLv3
 
-namespace RetroGtk {
-
-public class GamepadConfiguration : Object {
+public class Retro.GamepadConfiguration : Object {
        private uint16[] gamepad_keys;
 
        construct {
@@ -37,6 +35,3 @@ public class GamepadConfiguration : Object {
                return gamepad_keys[button];
        }
 }
-
-}
-
diff --git a/retro-gobject/input/input-device-manager.vala b/retro-gobject/input/input-device-manager.vala
index 0443f51..4aaba36 100644
--- a/retro-gobject/input/input-device-manager.vala
+++ b/retro-gobject/input/input-device-manager.vala
@@ -4,6 +4,7 @@ namespace Retro {
 
 public class InputDeviceManager : Object, Input {
        private HashTable<uint?, InputDevice> controller_devices;
+       private Keyboard keyboard;
 
        construct {
                controller_devices = new HashTable<int?, InputDevice> (int_hash, int_equal);
@@ -45,6 +46,14 @@ public class InputDeviceManager : Object, Input {
                controller_connected (port, device);
        }
 
+       public void set_keyboard (Keyboard keyboard) {
+               this.keyboard = keyboard;
+
+               keyboard.key_event.connect ((p, k, c, m) => {
+                       key_event (p, k, c, m);
+               });
+       }
+
        public void remove_controller_device (uint port) {
                if (!controller_devices.contains (port))
                        return;
diff --git a/retro-gtk/input/keyboard-state.vala b/retro-gobject/input/keyboard-state.vala
similarity index 96%
rename from retro-gtk/input/keyboard-state.vala
rename to retro-gobject/input/keyboard-state.vala
index ac671ba..989e688 100644
--- a/retro-gtk/input/keyboard-state.vala
+++ b/retro-gobject/input/keyboard-state.vala
@@ -1,8 +1,6 @@
 // This file is part of RetroGtk. License: GPLv3
 
-namespace RetroGtk {
-
-public class KeyboardState : Object {
+public class Retro.KeyboardState : Object {
        public Gtk.Widget widget { get; construct; }
 
        private HashTable<uint?, bool?> key_state;
@@ -78,6 +76,3 @@ public class KeyboardState : Object {
                return false;
        }
 }
-
-}
-
diff --git a/retro-gobject/input/keyboard.vala b/retro-gobject/input/keyboard.vala
index b7a1221..12daac7 100644
--- a/retro-gobject/input/keyboard.vala
+++ b/retro-gobject/input/keyboard.vala
@@ -1,11 +1,9 @@
 // This file is part of Retro. License: GPLv3
 
-namespace Retro {
-
 /**
  * Key types to feed to a {@link Core} via {@link Input.key_event}.
  */
-public enum KeyboardKey {
+public enum Retro.KeyboardKey {
        UNKNOWN        = 0,
        FIRST          = 0,
        BACKSPACE      = 8,
@@ -156,7 +154,7 @@ public enum KeyboardKey {
  * Modifier key types to feed to a {@link Core} via {@link Input.key_event}.
  */
 [Flags]
-public enum KeyboardModifierKey {
+public enum Retro.KeyboardModifierKey {
        NONE       = 0x0000,
 
        SHIFT      = 0x01,
@@ -169,4 +167,166 @@ public enum KeyboardModifierKey {
        SCROLLOCK  = 0x40
 }
 
+public class Retro.Keyboard : Object {
+       public Gtk.Widget widget { get; construct; }
+
+       public signal void key_event (bool down, KeyboardKey keycode, uint32 character, KeyboardModifierKey 
key_modifiers);
+
+       public Keyboard (Gtk.Widget widget) {
+               Object (widget: widget);
+       }
+
+       construct {
+               widget.key_press_event.connect ((w, e) => on_key_event (e, true));
+               widget.key_release_event.connect ((w, e) => on_key_event (e, false));
+       }
+
+       private KeyboardModifierKey modifier_key_converter (uint keyval, Gdk.ModifierType modifiers) {
+               var retro_modifiers = KeyboardModifierKey.NONE;
+               if ((bool) (modifiers & Gdk.ModifierType.SHIFT_MASK))
+                       retro_modifiers |= KeyboardModifierKey.SHIFT;
+               if ((bool) (modifiers & Gdk.ModifierType.CONTROL_MASK))
+                       retro_modifiers |= KeyboardModifierKey.CTRL;
+               if ((bool) (modifiers & Gdk.ModifierType.MOD1_MASK))
+                       retro_modifiers |= KeyboardModifierKey.ALT;
+               if ((bool) (modifiers & Gdk.ModifierType.META_MASK))
+                       retro_modifiers |= KeyboardModifierKey.META;
+               if (keyval == Gdk.Key.Num_Lock)
+                       retro_modifiers |= KeyboardModifierKey.NUMLOCK;
+               if ((bool) (modifiers & Gdk.ModifierType.LOCK_MASK))
+                       retro_modifiers |= KeyboardModifierKey.CAPSLOCK;
+               if (keyval == Gdk.Key.Scroll_Lock)
+                       retro_modifiers |= KeyboardModifierKey.SCROLLOCK;
+               return retro_modifiers;
+       }
+
+       private KeyboardKey key_converter (uint keyval) {
+               // Common keys (0x0020 to 0x00fe)
+               if (keyval < 0x80) {
+                       var key = (0x7f & keyval);
+
+                       // If the key is uppercase, turn it lower case
+                       if (key >= 'A' && key <= 'Z')
+                               return (KeyboardKey) (key + 0x20);
+
+                       return (KeyboardKey) key;
+               }
+
+               // Function keys
+               var fx = keyval - Gdk.Key.F1;
+               if (fx < 15) return (KeyboardKey) ((uint) KeyboardKey.F1 + fx);
+
+               // Keypad digits
+               var kp = keyval - Gdk.Key.KP_0;
+               if (kp < 10) return (KeyboardKey) ((uint) KeyboardKey.KP0 + kp);
+
+               // Various keys
+               // Missing keys: MODE, COMPOSE, POWER
+               switch (keyval) {
+                       case Gdk.Key.BackSpace:
+                               return KeyboardKey.BACKSPACE;
+                       case Gdk.Key.Tab:
+                               return KeyboardKey.TAB;
+                       case Gdk.Key.Clear:
+                               return KeyboardKey.CLEAR;
+                       case Gdk.Key.Return:
+                               return KeyboardKey.RETURN;
+                       case Gdk.Key.Pause:
+                               return KeyboardKey.PAUSE;
+                       case Gdk.Key.Escape:
+                               return KeyboardKey.ESCAPE;
+                       case Gdk.Key.Delete:
+                               return KeyboardKey.DELETE;
+
+                       case Gdk.Key.Up:
+                               return KeyboardKey.UP;
+                       case Gdk.Key.Down:
+                               return KeyboardKey.DOWN;
+                       case Gdk.Key.Left:
+                               return KeyboardKey.LEFT;
+                       case Gdk.Key.Right:
+                               return KeyboardKey.RIGHT;
+                       case Gdk.Key.Insert:
+                               return KeyboardKey.INSERT;
+                       case Gdk.Key.Home:
+                               return KeyboardKey.HOME;
+                       case Gdk.Key.End:
+                               return KeyboardKey.END;
+                       case Gdk.Key.Page_Up:
+                               return KeyboardKey.PAGEUP;
+                       case Gdk.Key.Page_Down:
+                               return KeyboardKey.PAGEDOWN;
+
+                       case Gdk.Key.KP_Decimal:
+                               return KeyboardKey.KP_PERIOD;
+                       case Gdk.Key.KP_Divide:
+                               return KeyboardKey.KP_DIVIDE;
+                       case Gdk.Key.KP_Multiply:
+                               return KeyboardKey.KP_MULTIPLY;
+                       case Gdk.Key.KP_Subtract:
+                               return KeyboardKey.KP_MINUS;
+                       case Gdk.Key.KP_Add:
+                               return KeyboardKey.KP_PLUS;
+                       case Gdk.Key.KP_Enter:
+                               return KeyboardKey.KP_ENTER;
+                       case Gdk.Key.KP_Equal:
+                               return KeyboardKey.KP_EQUALS;
+
+                       case Gdk.Key.Num_Lock:
+                               return KeyboardKey.NUMLOCK;
+                       case Gdk.Key.Caps_Lock:
+                               return KeyboardKey.CAPSLOCK;
+                       case Gdk.Key.Scroll_Lock:
+                               return KeyboardKey.SCROLLOCK;
+                       case Gdk.Key.Shift_R:
+                               return KeyboardKey.RSHIFT;
+                       case Gdk.Key.Shift_L:
+                               return KeyboardKey.LSHIFT;
+                       case Gdk.Key.Control_R:
+                               return KeyboardKey.RCTRL;
+                       case Gdk.Key.Control_L:
+                               return KeyboardKey.LCTRL;
+                       case Gdk.Key.Alt_R:
+                               return KeyboardKey.RALT;
+                       case Gdk.Key.Alt_L:
+                               return KeyboardKey.LALT;
+                       case Gdk.Key.Meta_R:
+                               return KeyboardKey.RMETA;
+                       case Gdk.Key.Meta_L:
+                               return KeyboardKey.LMETA;
+                       case Gdk.Key.Super_R:
+                               return KeyboardKey.RSUPER;
+                       case Gdk.Key.Super_L:
+                               return KeyboardKey.LSUPER;
+
+                       case Gdk.Key.Help:
+                               return KeyboardKey.HELP;
+                       case Gdk.Key.Print:
+                               return KeyboardKey.PRINT;
+                       case Gdk.Key.Sys_Req:
+                               return KeyboardKey.SYSREQ;
+                       case Gdk.Key.Break:
+                               return KeyboardKey.BREAK;
+                       case Gdk.Key.Menu:
+                               return KeyboardKey.MENU;
+                       case Gdk.Key.EuroSign:
+                               return KeyboardKey.EURO;
+                       case Gdk.Key.Undo:
+                               return KeyboardKey.UNDO;
+
+                       default:
+                               return KeyboardKey.UNKNOWN;
+               }
+       }
+
+       private bool on_key_event (Gdk.EventKey event, bool pressed) {
+               key_event (
+                       pressed,
+                       key_converter (event.keyval),
+                       event.str.to_utf8 ()[0],
+                       modifier_key_converter (event.keyval, event.state)
+               );
+
+               return false;
+       }
 }
diff --git a/retro-gtk/input/mouse.vala b/retro-gobject/input/mouse.vala
similarity index 89%
rename from retro-gtk/input/mouse.vala
rename to retro-gobject/input/mouse.vala
index 06545c9..2620eaf 100644
--- a/retro-gtk/input/mouse.vala
+++ b/retro-gobject/input/mouse.vala
@@ -1,8 +1,6 @@
 // This file is part of RetroGtk. License: GPLv3
 
-namespace RetroGtk {
-
-private class MotionParser : Object {
+private class Retro.MotionParser : Object {
        private Gdk.Screen screen;
 
        private bool _grab_pointer;
@@ -67,7 +65,7 @@ private class MotionParser : Object {
        }
 }
 
-public class Mouse : Object, Retro.InputDevice {
+public class Retro.Mouse : Object, InputDevice {
        public Gtk.Widget widget { get; construct; }
 
        public bool parse {
@@ -114,33 +112,33 @@ public class Mouse : Object, Retro.InputDevice {
 
        public void poll () {}
 
-       public int16 get_input_state (Retro.DeviceType device, uint index, uint id) {
-               if (device != Retro.DeviceType.MOUSE) return 0;
+       public int16 get_input_state (DeviceType device, uint index, uint id) {
+               if (device != DeviceType.MOUSE) return 0;
 
-               switch ((Retro.MouseId) id) {
-                       case Retro.MouseId.X:
+               switch ((MouseId) id) {
+                       case MouseId.X:
                                int16 result = x_delta;
                                x_delta = 0;
                                return result;
-                       case Retro.MouseId.Y:
+                       case MouseId.Y:
                                int16 result = y_delta;
                                y_delta = 0;
                                return result;
-                       case Retro.MouseId.LEFT:
+                       case MouseId.LEFT:
                                return get_button_state (1) ? int16.MAX : 0;
-                       case Retro.MouseId.RIGHT:
+                       case MouseId.RIGHT:
                                return get_button_state (3) ? int16.MAX : 0;
                        default:
                                return 0;
                }
        }
 
-       public Retro.DeviceType get_device_type () {
-               return Retro.DeviceType.MOUSE;
+       public DeviceType get_device_type () {
+               return DeviceType.MOUSE;
        }
 
        public uint64 get_device_capabilities () {
-               return 1 << Retro.DeviceType.MOUSE;
+               return 1 << DeviceType.MOUSE;
        }
 
        private bool on_button_press_event (Gtk.Widget source, Gdk.EventButton event) {
@@ -222,6 +220,3 @@ public class Mouse : Object, Retro.InputDevice {
                });
        }
 }
-
-}
-
diff --git a/retro-gtk/input/virtual-gamepad.vala b/retro-gobject/input/virtual-gamepad.vala
similarity index 71%
rename from retro-gtk/input/virtual-gamepad.vala
rename to retro-gobject/input/virtual-gamepad.vala
index 9973c18..62c0fb9 100644
--- a/retro-gtk/input/virtual-gamepad.vala
+++ b/retro-gobject/input/virtual-gamepad.vala
@@ -1,8 +1,6 @@
 // This file is part of RetroGtk. License: GPLv3
 
-namespace RetroGtk {
-
-public class VirtualGamepad : Object, Retro.InputDevice {
+public class Retro.VirtualGamepad : Object, InputDevice {
        public Gtk.Widget widget { get; construct; }
        public GamepadConfiguration configuration { get; construct set; }
 
@@ -27,24 +25,21 @@ public class VirtualGamepad : Object, Retro.InputDevice {
 
        public void poll () {}
 
-       public int16 get_input_state (Retro.DeviceType device, uint index, uint id) {
-               if ((Retro.DeviceType) device != Retro.DeviceType.JOYPAD) return 0;
+       public int16 get_input_state (DeviceType device, uint index, uint id) {
+               if ((DeviceType) device != DeviceType.JOYPAD) return 0;
 
                return get_button_pressed ((GamepadButtonType) id) ? int16.MAX : 0;
        }
 
-       public Retro.DeviceType get_device_type () {
-               return Retro.DeviceType.JOYPAD;
+       public DeviceType get_device_type () {
+               return DeviceType.JOYPAD;
        }
 
        public uint64 get_device_capabilities () {
-               return 1 << Retro.DeviceType.JOYPAD;
+               return 1 << DeviceType.JOYPAD;
        }
 
        public bool get_button_pressed (GamepadButtonType button) {
                return keyboard.get_key_state (configuration.get_button_key (button));
        }
 }
-
-}
-
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 16cc38b..3c3c45e 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -39,7 +39,6 @@ libretro_gtk_la_VALAFLAGS = \
        --vapidir $(top_builddir)/retro-gobject \
        --pkg glib-2.0 \
        --pkg gobject-2.0 \
-       --pkg gtk+-3.0 \
        --pkg retro-gobject-0.8 \
        --thread \
        --target-glib 2.32 \


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