diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2019-10-22 16:41:19 +0200 |
---|---|---|
committer | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2019-10-23 09:40:30 +0200 |
commit | 899e0bd16bcf80b0a1badbafeb83d3f474f24261 (patch) | |
tree | a9adca33672534629d9af5bfcc01834fd5c382dc /input/input.c | |
parent | 79b15f50e31d62b50d1c20160fa7ec489d3b05e5 (diff) | |
download | mpv-899e0bd16bcf80b0a1badbafeb83d3f474f24261.tar.bz2 mpv-899e0bd16bcf80b0a1badbafeb83d3f474f24261.tar.xz |
input: add gamepad support through SDL2
The code is very basic:
- only handles gamepads, could be extended for generic joysticks in the
future.
- only has button mappings for controllers natively supported by SDL2.
I heard more can be added through env vars, there's also ways to load
mappings from text files, but I'd rather not go there yet. Common ones
like Dualshock are supported natively.
- analog buttons (TRIGGER and AXIS) are mapped to discrete buttons using an
activation threshold.
- only supports one gamepad at a time. the feature is intented to use
gamepads as evolved remote controls, not play multiplayer games in mpv :)
Diffstat (limited to 'input/input.c')
-rw-r--r-- | input/input.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/input/input.c b/input/input.c index 8a14d862b3..32ee75b4cf 100644 --- a/input/input.c +++ b/input/input.c @@ -173,6 +173,7 @@ struct input_opts { int ar_rate; int use_alt_gr; int use_appleremote; + int use_gamepad; int use_media_keys; int default_bindings; int enable_mouse_movements; @@ -199,6 +200,9 @@ const struct m_sub_options input_config = { #if HAVE_COCOA OPT_FLAG("input-appleremote", use_appleremote, 0), #endif +#if HAVE_SDL2_GAMEPAD + OPT_FLAG("input-gamepad", use_gamepad, 0), +#endif OPT_FLAG("window-dragging", allow_win_drag, 0), OPT_REPLACED("input-x11-keyboard", "input-vo-keyboard"), {0} @@ -215,6 +219,9 @@ const struct m_sub_options input_config = { #if HAVE_COCOA .use_appleremote = 1, #endif +#if HAVE_SDL2_GAMEPAD + .use_gamepad = 1, +#endif .default_bindings = 1, .vo_key_input = 1, .allow_win_drag = 1, @@ -1377,6 +1384,12 @@ void mp_input_load_config(struct input_ctx *ictx) talloc_free(ifile); #endif +#if HAVE_SDL2_GAMEPAD + if (ictx->opts->use_gamepad) { + mp_input_sdl_gamepad_add(ictx); + } +#endif + input_unlock(ictx); } |