Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gamepad support #300

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
6089add
Add gamepad support
meghprkh Jul 11, 2016
fa20fe0
Remove gamepads_number from GamepadMonitor
meghprkh Jul 13, 2016
44ba663
Remove debug print statements from retro-input-manager
meghprkh Jul 13, 2016
b4e2c04
Remove get_raw_gamepad from GamepadMonitor
meghprkh Jul 13, 2016
9629ca4
Remove identifier from the frontend code and manage it only in the dr…
meghprkh Jul 13, 2016
b9175cb
Revamp RawGamepad and RawGamepadMonitor
meghprkh Jul 14, 2016
4d7c61a
Revamp gamepad-monitor
meghprkh Jul 14, 2016
404b29c
Prefix linux in front of the linux driver files
meghprkh Jul 14, 2016
a2274fe
Remove identifier from public API of drivers
meghprkh Jul 14, 2016
a0271c3
Remove raw_name from Gamepad
meghprkh Jul 14, 2016
8c2ffc9
Fix helpers to adhere to coding standards
meghprkh Jul 14, 2016
9d25f5d
Fix helpers to adhere to coding standards
meghprkh Jul 14, 2016
91598b0
Convert a big lambda in LinuxRawGamepadMonitor to a function
meghprkh Jul 14, 2016
ffc826e
Merge branch 'dirty/feature/gamepad-pr' of https://github.com/meghprk…
meghprkh Jul 14, 2016
812c7e6
Use a MappedEvent struct to represent mapped events
meghprkh Jul 14, 2016
d04d597
Remove C files commited by mistake
meghprkh Jul 14, 2016
1cd464d
Merge branch 'master' into dirty/feature/gamepad-pr
meghprkh Jul 14, 2016
535f8f6
Rename err to e to follow convention
meghprkh Jul 14, 2016
d247ce3
Fix indentation aligning issue in linux-raw-gamepad-monitor
meghprkh Jul 14, 2016
66e9506
Change some naming
meghprkh Jul 14, 2016
79c68ac
Merge MappingHelpers and Mapping
meghprkh Jul 14, 2016
8d09814
Make LinuxRawGamepadMonitor more readable
meghprkh Jul 14, 2016
f0f7d05
Return MappedEvent instead of having it as an out parameter
meghprkh Jul 14, 2016
31f810c
Fix LinuxRawGamepadMonitor
meghprkh Jul 14, 2016
6e5cd9f
Add new line before return
meghprkh Jul 14, 2016
959c3c9
Fix out in gamepad.vala
meghprkh Jul 14, 2016
eec060d
Remove unplugged signals
meghprkh Jul 14, 2016
943d0c6
Remove mapping-helpers.c left by mistake
meghprkh Jul 14, 2016
f19fc75
Use singleton and fix build error in LinuxRawGamepadMonitor
meghprkh Jul 14, 2016
f056bc7
Update gamepad-monitor to obey the AWESOME style guide
meghprkh Jul 15, 2016
38c36db
Merge LinuxGuidHelpers into LinuxRawGamepad
meghprkh Jul 15, 2016
4bcfb9e
Hide guid in Gamepad
meghprkh Jul 15, 2016
244226b
Remove _name from raw-gamepad
meghprkh Jul 15, 2016
3c2f1f9
Dont initialize _guid and compare with null
meghprkh Jul 15, 2016
bab074b
Add blank line before break/continue/return if it is not the only sta…
meghprkh Jul 15, 2016
c44e5bf
Split one liner ifs, and whiles into two lines
meghprkh Jul 15, 2016
b1b31fb
Make MappingsManager a singleton
meghprkh Jul 15, 2016
157ee1e
Switch to GenericSet instead of SList in gamepad-manager
meghprkh Jul 15, 2016
ecb69c4
Fix genericset
meghprkh Jul 15, 2016
9c9c98d
Cleanup LinuxRawGamepadMonitor
meghprkh Jul 15, 2016
acd9adc
Some cleanup in Mapping
meghprkh Jul 15, 2016
d99b062
Remove mapped from gamepad and change code accordingly and some cleanup
meghprkh Jul 15, 2016
a4c0b92
Minor cleanup in LinuxRawGamepad
meghprkh Jul 15, 2016
3f33a80
Merge Helpers into LinuxRawGamepad
meghprkh Jul 15, 2016
7af68b1
Use brackets in HashTables
meghprkh Jul 15, 2016
64ae04f
Remove emit_event from Gamepad
meghprkh Jul 15, 2016
83a39a3
Fix build
meghprkh Jul 15, 2016
ae0bfee
Cleanup Mapping
meghprkh Jul 15, 2016
a51622e
Fix build
meghprkh Jul 15, 2016
2ad0443
Little cleanup Mapping
meghprkh Jul 15, 2016
dba5011
Remove unmapped_raw_gamepads and similar methods from gamepad-monitors
meghprkh Jul 15, 2016
69a1b5f
Move callbacks to separate file to avoid duplication
meghprkh Jul 15, 2016
a022b77
Make raw_gamepad of Gamepad private
meghprkh Jul 15, 2016
6a0b033
Make mapping of gamepad private
meghprkh Jul 15, 2016
f11f593
Cleanup
meghprkh Jul 15, 2016
c4a6ca0
Add oneline FIXME comment about constant in linux-raw-gamepad
meghprkh Jul 16, 2016
3939534
Revamp RawGamepad and remove properties
meghprkh Jul 16, 2016
4dd6394
Simplify handle_evdev_callback in linux-raw-gamepad
meghprkh Jul 16, 2016
727b99a
Hide name in Gamepad
meghprkh Jul 16, 2016
56dde71
Add trailing comma in mapping-error
meghprkh Jul 16, 2016
6b1e3bd
Move dpad to its own file
meghprkh Jul 16, 2016
0415532
Throw different error message for null and empty string
meghprkh Jul 16, 2016
1013c03
Split constructor of Mapping into some functions
meghprkh Jul 16, 2016
b5341df
Fix mapping build and a little cleanup
meghprkh Jul 18, 2016
b4a633b
Use GTK Widget instead of EventBox in RetroInputManager
meghprkh Jul 18, 2016
9b79570
Shift UNKNOWN in standard gamepad enums to value 0 so that it can be …
meghprkh Jul 18, 2016
0025669
Fix else styling
meghprkh Jul 18, 2016
07cd128
Remove some useless comments
meghprkh Jul 18, 2016
5d29dfa
Remove some more comments
meghprkh Jul 18, 2016
32a7518
Remove some comments
meghprkh Jul 18, 2016
4edce35
Fix catch on new line
meghprkh Jul 18, 2016
c35028e
mappingstr to mapping_string
meghprkh Jul 18, 2016
5a12b7e
Remove the dpad comments since they are obvious
meghprkh Jul 18, 2016
6187d6d
Update controller db
meghprkh Jul 18, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ PKG_CHECK_MODULES(GNOME_GAMES, [
glib-2.0 >= $GLIB_MIN_VERSION
grilo-0.3
gtk+-3.0
gudev-1.0
libevdev
retro-gobject-0.6
retro-gtk-0.6
tracker-sparql-1.0
Expand Down
129 changes: 129 additions & 0 deletions data/gamepads/gamecontrollerdb.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/org.gnome.Games.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/org/gnome/Games">
<file>gtk-style.css</file>
<file>gamepads/gamecontrollerdb.txt</file>
<file preprocess="xml-stripblanks">gtk/menus.ui</file>
<file preprocess="xml-stripblanks">ui/application-window.ui</file>
<file preprocess="xml-stripblanks">ui/collection-icon-view.ui</file>
Expand Down
23 changes: 23 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,28 @@ gnome_games_SOURCES = \
dummy/dummy-icon.vala \
dummy/dummy-runner.vala \
\
gamepad/raw-gamepad-monitor.vala \
gamepad/raw-gamepad.vala \
gamepad/linux/linux-guid-helpers.vala \
gamepad/linux/linux-raw-gamepad-monitor.vala \
gamepad/linux/linux-raw-gamepad.vala \
gamepad/gamepad-monitor.vala \
gamepad/gamepad.vala \
gamepad/helpers.vala \
gamepad/input-type.vala \
gamepad/mapped-event.vala \
gamepad/mapping-error.vala \
gamepad/mapping.vala \
gamepad/mappings-manager.vala \
gamepad/standard-gamepad-axis.vala \
gamepad/standard-gamepad-button.vala \
\
grilo/grilo-cover.vala \
grilo/grilo-media.vala \
\
retro/retro-error.vala \
retro/retro-gamepad.vala \
retro/retro-input-manager.vala \
retro/retro-log.vala \
retro/retro-runner.vala \
\
Expand Down Expand Up @@ -99,13 +117,18 @@ gnome_games_SOURCES = \

gnome_games_VALAFLAGS = \
--target-glib=@GLIB_MIN_VERSION@ \
--vapidir=gamepad/linux/ \
--pkg gio-2.0 \
--pkg glib-2.0 \
--pkg grilo-0.3 \
--pkg gtk+-3.0 \
--pkg tracker-sparql-1.0 \
--pkg retro-gobject-0.6 \
--pkg retro-gtk-0.6 \
--pkg gudev-1.0 \
--pkg libevdev \
--pkg linux \
--pkg posix \
--gresources $(gresource_file) \
--vapi $(vapi_file) \
-H $(header_file) \
Expand Down
59 changes: 59 additions & 0 deletions src/gamepad/gamepad-monitor.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This file is part of GNOME Games. License: GPLv3

/**
* This class provides a way to the client to monitor gamepads
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting comment, we can keep it.

*
* The client interfaces with this class primarily
*/
public class LibGamepad.GamepadMonitor : Object {
/**
* Emitted when a gamepad is plugged in
* @param gamepad The gamepad
*/
public signal void gamepad_plugged (Gamepad gamepad);

public delegate void GamepadCallback (Gamepad gamepad);

private static GamepadMonitor instance;

private SList <Gamepad> gamepads;
Copy link
Owner

@Kekun Kekun Jul 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need order so it's better to use a GenericSet, also we don't put spaces between the generic type and <.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GenericSet needs a hash function, which I dont know how to use. would be helpful if you tell me that

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pass direct_hash and direct_equal as hashing and comparison functions.

private RawGamepadMonitor raw_gamepad_monitor;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you made it a singleton you don't need to store it anymore: the instance will never be destroyed.


private GamepadMonitor () {
if (gamepads == null)
Copy link
Owner

@Kekun Kekun Jul 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check for null: it is guaranteed to be null as it is an instance field and we are in the constructor.

gamepads = new SList <Gamepad> ();

raw_gamepad_monitor = LinuxRawGamepadMonitor.get_instance ();

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line.

raw_gamepad_monitor.gamepad_plugged.connect (on_raw_gamepad_plugged);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

raw_gamepad_monitor.foreach_gamepad ((raw_gamepad) => add_gamepad (raw_gamepad));
}

public static GamepadMonitor get_instance () {
if (instance == null)
instance = new GamepadMonitor ();

return instance;
}

/**
* This function allows to iterate over all gamepads
Copy link
Owner

@Kekun Kekun Jul 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably obvious enough.

From now on I'll only comment the plugins that I think should be removed.

* @param callback The callback
*/
public void foreach_gamepad (GamepadCallback callback) {
gamepads.foreach ((gamepad) => callback (gamepad));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foreach (var gamepad in gamepads)
callback (gamepad);

}

private Gamepad add_gamepad (RawGamepad raw_gamepad) {
var gamepad = new Gamepad (raw_gamepad);
gamepads.append (gamepad);
gamepad.unplugged.connect (() => gamepads.remove (gamepad));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use lambdas as callbacks to signals. Create a remove_gamepad() method instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seriously! making a function for a one liner! Wow! I am amazed by your style guide


return gamepad;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline.

}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add the RawGamepad.unplugged() signal as suggested later, we can instead make the Gamepad progagate the signal and remove it directly.


private void on_raw_gamepad_plugged (RawGamepad raw_gamepad) {
gamepad_plugged (add_gamepad (raw_gamepad));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't chain calls, first add the gamepad then pass it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn looks like this feature doesnot exist in vala. lets code as if it were assembly

}
}
98 changes: 98 additions & 0 deletions src/gamepad/gamepad.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// This file is part of GNOME Games. License: GPLv3

/**
* This class represents a gamepad
*
* The client interfaces with this class primarily
*/
public class LibGamepad.Gamepad : Object {

/**
* Emitted when a button is pressed/released
* @param button The button pressed
* @param value True if pressed, False if released
*/
public signal void button_event (StandardGamepadButton button, bool value);

/**
* Emitted when an axis's value changes
* @param axis The axis number from 0 to axes_number
* @param value The value of the axis ranging from -1 to 1
*/
public signal void axis_event (StandardGamepadAxis axis, double value);

/**
* Emitted when the gamepad is unplugged
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably not hyper useful but it's not that annoying either.

*/
public signal void unplugged ();


/**
* The guid
*/
public string? guid { get; private set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is useless (and a technical detail of raw gamepads we want to hide).


/**
* The name present in our database
*/
public string? name { get; private set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, we don't use it yet, let's keep it aside for now and add it when we will have a UI using it. :)


/**
* The raw gamepad behind this gamepad
*/
public RawGamepad raw_gamepad { get; private set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better to make it a private field, especially as we don't use it outside (which is good) and we shouldn't expose it.


/**
* Whether this gamepad is mapped
*/
public bool mapped { get; private set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in retro-input-manager and only the mapped gamepads are selected. This is particularly useful when we are remapping controls GUI

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the case we want to list all the gamepads but want to know if they are mapped or unmapped

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they are not mapped then they shouldn't be Gamepad object, we already have an object type representing the unmapped gamepads: RawGamepad. And you clearly don't want unmapped gamepads: you are filtering them out in RetroInputManager!

If later we need them we can have the GamepadManager maintaining two lists: one of Gamepad and one of the remaining RawGamepad it wasn't able to map.

Hence, let's remove this useless mapped property. :)


/**
* The mapping object
*/
public Mapping? mapping { get; private set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, it would be better as a private field.


public Gamepad (RawGamepad raw_gamepad) throws FileError {
this.raw_gamepad = raw_gamepad;
guid = raw_gamepad.guid;
name = MappingsManager.get_name (guid) ?? raw_gamepad.name;
try {
mapping = new Mapping.from_sdl_string (MappingsManager.get_mapping (guid));
mapped = true;
raw_gamepad.button_event.connect (on_raw_button_event);
raw_gamepad.axis_event.connect (on_raw_axis_event);
raw_gamepad.dpad_event.connect (on_raw_dpad_event);
} catch (MappingError e) {
debug ("%s - for %s/%s", e.message, guid, name);
mapping = null;
mapped = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not mapped it's not a valid Gamepad object and we don't want invalid objects, let the constructor throw the mapping error instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a valid gamepad object imo

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can't know where the A button is, it's not a Gamepad, it's a RawGamepad in disguise.

}
raw_gamepad.unplugged.connect (() => unplugged ());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible try raw_gamepad.unplugged.connect (unplugged);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah.. doesnt work.

gamepad/gamepad.vala:70.34-70.42: error: Argument 1: Cannot convert from `LibGamepad.Gamepad.unplugged' to `LibGamepad.RawGamepad.unplugged'
        raw_gamepad.unplugged.connect (unplugged);

}

private void on_raw_button_event (int button, bool value) {
var event = mapping.get_button_mapping (button);
emit_event (event, value ? 1 : 0);
}

private void on_raw_axis_event (int axis, double value) {
var event = mapping.get_axis_mapping (axis);
emit_event (event, value);
}

private void on_raw_dpad_event (int dpad_index, int axis, int value) {
var event = mapping.get_dpad_mapping (dpad_index, axis, value);
emit_event (event, value.abs ());
}

private void emit_event (MappedEvent event, double value) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forcing a boolean and an integer into a double may not be the best solution, let's have an emit_bool_event() and an emit_int_event() one so we convert the values only once (in these methods) and not twice (before this method and in it).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually don't create new methods, add this to the body of the on_raw... ones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the purpose is to have this in emit_event to prevent code duplication. Otherwise I need a switch case in every function

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding code duplication is good except that there wouldn't be code duplication as you would handle the values differently and properly in each method.

switch (event.type) {
case InputType.AXIS:
axis_event (event.axis, value);
break;
case InputType.BUTTON:
button_event (event.button, (bool) value);
break;
}
}
}
24 changes: 24 additions & 0 deletions src/gamepad/helpers.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file is part of GNOME Games. License: GPLv3

namespace LibGamepad {
private const int GUID_LENGTH = 8;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this as to LinuxRawGamepad.


private string uint16s_to_hex_string (uint16[] data)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this as a static method to LinuxRawGamepad.

requires (data.length == GUID_LENGTH)
{
const string hex_to_ascii_map = "0123456789abcdef";

var builder = new StringBuilder ();
foreach (uint16 el in data) {
uint8 c = (uint8) el;
builder.append_unichar (hex_to_ascii_map[c >> 4]);
builder.append_unichar (hex_to_ascii_map[c & 0x0F]);

c = (uint8) (el >> 8);
builder.append_unichar (hex_to_ascii_map[c >> 4]);
builder.append_unichar (hex_to_ascii_map[c & 0x0F]);
}

return builder.str;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a newline before.

}
}
11 changes: 11 additions & 0 deletions src/gamepad/input-type.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file is part of GNOME Games. License: GPLv3

public enum LibGamepad.InputType {
AXIS,
BUTTON,
INVALID;

public static uint length () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doesn't seem to be used to me, if it's not we better remove it, otherwise tell me so I don't annoy you with it later.

return InputType.INVALID + 1;
}
}
39 changes: 39 additions & 0 deletions src/gamepad/linux/libevdev.vapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file is part of GNOME Games. License: GPLv3

[CCode (cheader_filename = "libevdev/libevdev.h")]
namespace Libevdev {

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks extra (yes I also annoy you for extra empty lines :p ).

[CCode (cname = "libevdev_read_flag", cprefix = "LIBEVDEV_READ_FLAG_", has_type_id = false)]
[Flags]
public enum ReadFlag {
SYNC,
NORMAL,
FORCE_SYNC,
BLOCKING
}

[CCode (cname = "struct libevdev", cprefix = "libevdev_", free_function = "libevdev_free")]
[Compact]
public class Evdev {
[CCode (cname = "libevdev_new")]
public Evdev ();

public int get_fd ();
public int set_fd (int fd);

public string name { get; set; }

public int id_bustype { get; set; }
public int id_vendor { get; set; }
public int id_product { get; set; }
public int id_version { get; set; }

public unowned Linux.Input.AbsInfo? get_abs_info (uint code);
public bool has_event_code (uint type, uint code);
public int has_event_pending ();
public int next_event (uint flags, out Linux.Input.Event ev);

public static unowned string event_code_get_name(uint type, uint code);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

}
31 changes: 31 additions & 0 deletions src/gamepad/linux/linux-guid-helpers.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This file is part of GNOME Games. License: GPLv3

private class LibGamepad.LinuxGuidHelpers : Object {
public static string from_dev (Libevdev.Evdev device) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go with uint16s_to_hex_string and clearly not in an empty class. I'm not sure what's the good name as it's both related to SDL2 mappings and Evdev... The namespace's name should reflect that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it simple instead, just move it to LinuxRawGamepad.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier this was also being used in raw-gamepad-monitor, so it is here. but moved

uint16 guid[8];
guid[0] = (uint16) device.id_bustype.to_little_endian ();
guid[1] = 0;
guid[2] = (uint16) device.id_vendor.to_little_endian ();
guid[3] = 0;
guid[4] = (uint16) device.id_product.to_little_endian ();
guid[5] = 0;
guid[6] = (uint16) device.id_version.to_little_endian ();
guid[7] = 0;
return uint16s_to_hex_string (guid);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a newline before.

}

public static string from_file (string file_name) throws FileError {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used and should be removed.

var fd = Posix.open (file_name, Posix.O_RDONLY | Posix.O_NONBLOCK);

if (fd < 0)
throw new FileError.FAILED (@"Unable to open file $file_name: $(Posix.strerror (Posix.errno))");

var device = new Libevdev.Evdev ();
if (device.set_fd (fd) < 0)
throw new FileError.FAILED (@"Evdev error on opening file $file_name: $(Posix.strerror (Posix.errno))");

var guid = from_dev (device);
Posix.close (fd);
return guid;
}
}
Loading