diff options
Diffstat (limited to 'input')
-rw-r--r-- | input/cmd.h | 2 | ||||
-rw-r--r-- | input/event.c | 15 | ||||
-rw-r--r-- | input/event.h | 5 | ||||
-rw-r--r-- | input/input.c | 73 | ||||
-rw-r--r-- | input/input.h | 7 | ||||
-rw-r--r-- | input/keycodes.c | 3 | ||||
-rw-r--r-- | input/keycodes.h | 9 | ||||
-rw-r--r-- | input/sdl_gamepad.c | 2 |
8 files changed, 77 insertions, 39 deletions
diff --git a/input/cmd.h b/input/cmd.h index 1c9fb3e..3d4b15f 100644 --- a/input/cmd.h +++ b/input/cmd.h @@ -23,7 +23,7 @@ #include "misc/bstr.h" #include "options/m_option.h" -#define MP_CMD_DEF_MAX_ARGS 9 +#define MP_CMD_DEF_MAX_ARGS 11 #define MP_CMD_OPT_ARG M_OPT_OPTIONAL_PARAM struct mp_log; diff --git a/input/event.c b/input/event.c index 266e029..6c1e004 100644 --- a/input/event.c +++ b/input/event.c @@ -37,6 +37,21 @@ void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files, }; mp_input_run_cmd(ictx, cmd); } + } else if (action == DND_INSERT_NEXT) { + /* To insert the entries in the correct order, we iterate over them + backwards */ + for (int i = num_files - 1; i >= 0; i--) { + const char *cmd[] = { + "osd-auto", + "loadfile", + files[i], + /* Since we're inserting in reverse, wait til the final item + is added to start playing */ + (i > 0) ? "insert-next" : "insert-next-play", + NULL + }; + mp_input_run_cmd(ictx, cmd); + } } else { for (int i = 0; i < num_files; i++) { const char *cmd[] = { diff --git a/input/event.h b/input/event.h index 1e2149b..5f48bee 100644 --- a/input/event.h +++ b/input/event.h @@ -24,16 +24,17 @@ struct input_ctx; enum mp_dnd_action { DND_REPLACE, DND_APPEND, + DND_INSERT_NEXT, }; // Enqueue files for playback after drag and drop void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files, - enum mp_dnd_action append); + enum mp_dnd_action action); // Drop data in a specific format (identified by the mimetype). // Returns <0 on error, ==0 if data was ok but empty, >0 on success. int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type, - bstr data, enum mp_dnd_action append); + bstr data, enum mp_dnd_action action); // Many drag & drop APIs support multiple mime types, and this function returns // whether a type is preferred (higher integer score), or supported (scores diff --git a/input/input.c b/input/input.c index b8d12aa..9fd2a16 100644 --- a/input/input.c +++ b/input/input.c @@ -50,13 +50,13 @@ #include "common/common.h" #if HAVE_COCOA -#include "osdep/macosx_events.h" +#include "osdep/mac/app_bridge.h" #endif #define input_lock(ictx) mp_mutex_lock(&ictx->mutex) #define input_unlock(ictx) mp_mutex_unlock(&ictx->mutex) -#define MP_MAX_KEY_DOWN 4 +#define MP_MAX_KEY_DOWN 16 struct cmd_bind { int keys[MP_MAX_KEY_DOWN]; @@ -79,8 +79,6 @@ struct cmd_bind_section { #define MP_MAX_SOURCES 10 -#define MAX_ACTIVE_SECTIONS 50 - struct active_section { char *name; int flags; @@ -142,7 +140,7 @@ struct input_ctx { int num_sections; // List currently active command sections - struct active_section active_sections[MAX_ACTIVE_SECTIONS]; + struct active_section *active_sections; int num_active_sections; unsigned int mouse_event_counter; @@ -179,6 +177,7 @@ struct input_opts { bool vo_key_input; bool test; bool allow_win_drag; + bool preprocess_wheel; }; const struct m_sub_options input_config = { @@ -198,6 +197,7 @@ const struct m_sub_options input_config = { {"input-cursor", OPT_BOOL(enable_mouse_movements)}, {"input-vo-keyboard", OPT_BOOL(vo_key_input)}, {"input-media-keys", OPT_BOOL(use_media_keys)}, + {"input-preprocess-wheel", OPT_BOOL(preprocess_wheel)}, #if HAVE_SDL2_GAMEPAD {"input-gamepad", OPT_BOOL(use_gamepad)}, #endif @@ -217,6 +217,7 @@ const struct m_sub_options input_config = { .builtin_bindings = true, .vo_key_input = true, .allow_win_drag = true, + .preprocess_wheel = true, }, .change_flags = UPDATE_INPUT, }; @@ -731,18 +732,23 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale, if (!force_mouse && opts->doubleclick_time && MP_KEY_IS_MOUSE_BTN_DBL(unmod)) return; int units = 1; - if (MP_KEY_IS_WHEEL(unmod) && !process_wheel(ictx, unmod, &scale, &units)) + if (MP_KEY_IS_WHEEL(unmod) && opts->preprocess_wheel && !process_wheel(ictx, unmod, &scale, &units)) return; interpret_key(ictx, code, scale, units); if (code & MP_KEY_STATE_DOWN) { code &= ~MP_KEY_STATE_DOWN; if (ictx->last_doubleclick_key_down == code && - now - ictx->last_doubleclick_time < opts->doubleclick_time / 1000.0) + now - ictx->last_doubleclick_time < opts->doubleclick_time / 1000.0 && + code >= MP_MBTN_LEFT && code <= MP_MBTN_RIGHT) { - if (code >= MP_MBTN_LEFT && code <= MP_MBTN_RIGHT) { - interpret_key(ictx, code - MP_MBTN_BASE + MP_MBTN_DBL_BASE, - 1, 1); - } + now = 0; + interpret_key(ictx, code - MP_MBTN_BASE + MP_MBTN_DBL_BASE, + 1, 1); + } else if (code == MP_MBTN_LEFT) { + // This is a mouse left botton down event which isn't part of a doubleclick. + // Initialize vo dragging in this case. + mp_cmd_t *cmd = mp_input_parse_cmd(ictx, bstr0("begin-vo-dragging"), "<internal>"); + mp_input_queue_cmd(ictx, cmd); } ictx->last_doubleclick_key_down = code; ictx->last_doubleclick_time = now; @@ -756,10 +762,12 @@ void mp_input_put_key(struct input_ctx *ictx, int code) input_unlock(ictx); } -void mp_input_put_key_artificial(struct input_ctx *ictx, int code) +void mp_input_put_key_artificial(struct input_ctx *ictx, int code, double value) { + if (value == 0.0) + return; input_lock(ictx); - mp_input_feed_key(ictx, code, 1, true); + mp_input_feed_key(ictx, code, value, true); input_unlock(ictx); } @@ -1007,20 +1015,16 @@ void mp_input_enable_section(struct input_ctx *ictx, char *name, int flags) MP_TRACE(ictx, "enable section '%s'\n", name); - if (ictx->num_active_sections < MAX_ACTIVE_SECTIONS) { - int top = ictx->num_active_sections; - if (!(flags & MP_INPUT_ON_TOP)) { - // insert before the first top entry - for (top = 0; top < ictx->num_active_sections; top++) { - if (ictx->active_sections[top].flags & MP_INPUT_ON_TOP) - break; - } - for (int n = ictx->num_active_sections; n > top; n--) - ictx->active_sections[n] = ictx->active_sections[n - 1]; + int top = ictx->num_active_sections; + if (!(flags & MP_INPUT_ON_TOP)) { + // insert before the first top entry + for (top = 0; top < ictx->num_active_sections; top++) { + if (ictx->active_sections[top].flags & MP_INPUT_ON_TOP) + break; } - ictx->active_sections[top] = (struct active_section){name, flags}; - ictx->num_active_sections++; } + MP_TARRAY_INSERT_AT(ictx, ictx->active_sections, ictx->num_active_sections, + top, (struct active_section){name, flags}); MP_TRACE(ictx, "active section stack:\n"); for (int n = 0; n < ictx->num_active_sections; n++) { @@ -1273,9 +1277,9 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data, return n_binds; } -static int parse_config_file(struct input_ctx *ictx, char *file, bool warn) +static bool parse_config_file(struct input_ctx *ictx, char *file) { - int r = 0; + bool r = false; void *tmp = talloc_new(NULL); stream_t *s = NULL; @@ -1292,7 +1296,7 @@ static int parse_config_file(struct input_ctx *ictx, char *file, bool warn) MP_VERBOSE(ictx, "Parsing input config file %s\n", file); int num = parse_config(ictx, false, data, file, NULL); MP_VERBOSE(ictx, "Input config file %s parsed: %d binds\n", file, num); - r = 1; + r = true; } else { MP_ERR(ictx, "Error reading input config file %s\n", file); } @@ -1317,6 +1321,7 @@ struct input_ctx *mp_input_init(struct mpv_global *global, .opts_cache = m_config_cache_alloc(ictx, global, &input_config), .wakeup_cb = wakeup_cb, .wakeup_ctx = wakeup_ctx, + .active_sections = talloc_array(ictx, struct active_section, 0), }; ictx->opts = ictx->opts_cache->opts; @@ -1373,13 +1378,13 @@ void mp_input_load_config(struct input_ctx *ictx) bool config_ok = false; if (ictx->opts->config_file && ictx->opts->config_file[0]) - config_ok = parse_config_file(ictx, ictx->opts->config_file, true); + config_ok = parse_config_file(ictx, ictx->opts->config_file); if (!config_ok) { // Try global conf dir void *tmp = talloc_new(NULL); char **files = mp_find_all_config_files(tmp, ictx->global, "input.conf"); for (int n = 0; files && files[n]; n++) - parse_config_file(ictx, files[n], false); + parse_config_file(ictx, files[n]); talloc_free(tmp); } @@ -1392,6 +1397,14 @@ void mp_input_load_config(struct input_ctx *ictx) input_unlock(ictx); } +bool mp_input_load_config_file(struct input_ctx *ictx, char *file) +{ + input_lock(ictx); + bool result = parse_config_file(ictx, file); + input_unlock(ictx); + return result; +} + static void clear_queue(struct cmd_queue *queue) { while (queue->first) { diff --git a/input/input.h b/input/input.h index 5b5e7a9..7f6707e 100644 --- a/input/input.h +++ b/input/input.h @@ -83,7 +83,8 @@ void mp_input_src_feed_cmd_text(struct mp_input_src *src, char *buf, size_t len) void mp_input_put_key(struct input_ctx *ictx, int code); // Like mp_input_put_key(), but ignore mouse disable option for mouse buttons. -void mp_input_put_key_artificial(struct input_ctx *ictx, int code); +// value can be used like with mp_input_put_wheel(), use 1 if not applicable. +void mp_input_put_key_artificial(struct input_ctx *ictx, int code, double value); // Like mp_input_put_key(), but process all UTF-8 characters in the given // string as key events. @@ -177,8 +178,12 @@ struct input_ctx *mp_input_init(struct mpv_global *global, void (*wakeup_cb)(void *ctx), void *wakeup_ctx); +// Load the configured input.conf files. void mp_input_load_config(struct input_ctx *ictx); +// Load a specific input.conf file. +bool mp_input_load_config_file(struct input_ctx *ictx, char *file); + void mp_input_update_opts(struct input_ctx *ictx); void mp_input_uninit(struct input_ctx *ictx); diff --git a/input/keycodes.c b/input/keycodes.c index bca9e17..c412191 100644 --- a/input/keycodes.c +++ b/input/keycodes.c @@ -173,7 +173,8 @@ static const struct key_name key_names[] = { { MP_KEY_CHANNEL_DOWN,"CHANNEL_DOWN" }, { MP_KEY_PLAYONLY, "PLAYONLY" }, { MP_KEY_PAUSEONLY, "PAUSEONLY" }, - { MP_KEY_BACK, "BACK" }, + { MP_KEY_GO_BACK, "GO_BACK" }, + { MP_KEY_GO_FORWARD, "GO_FORWARD" }, { MP_KEY_TOOLS, "TOOLS" }, { MP_KEY_ZOOMIN, "ZOOMIN" }, { MP_KEY_ZOOMOUT, "ZOOMOUT" }, diff --git a/input/keycodes.h b/input/keycodes.h index a5a746a..1a21a3c 100644 --- a/input/keycodes.h +++ b/input/keycodes.h @@ -82,10 +82,11 @@ #define MP_KEY_CHANNEL_DOWN (MP_KEY_MM_BASE+22) #define MP_KEY_PLAYONLY (MP_KEY_MM_BASE+23) #define MP_KEY_PAUSEONLY (MP_KEY_MM_BASE+24) -#define MP_KEY_BACK (MP_KEY_MM_BASE+25) -#define MP_KEY_TOOLS (MP_KEY_MM_BASE+26) -#define MP_KEY_ZOOMIN (MP_KEY_MM_BASE+27) -#define MP_KEY_ZOOMOUT (MP_KEY_MM_BASE+28) +#define MP_KEY_GO_BACK (MP_KEY_MM_BASE+25) +#define MP_KEY_GO_FORWARD (MP_KEY_MM_BASE+26) +#define MP_KEY_TOOLS (MP_KEY_MM_BASE+27) +#define MP_KEY_ZOOMIN (MP_KEY_MM_BASE+28) +#define MP_KEY_ZOOMOUT (MP_KEY_MM_BASE+29) /* Function keys */ #define MP_KEY_F (MP_KEY_BASE+0x40) diff --git a/input/sdl_gamepad.c b/input/sdl_gamepad.c index 790c945..b61f7c9 100644 --- a/input/sdl_gamepad.c +++ b/input/sdl_gamepad.c @@ -200,7 +200,9 @@ static void remove_gamepad(struct mp_input_src *src, int id) static void read_gamepad_thread(struct mp_input_src *src, void *param) { +#if SDL_VERSION_ATLEAST(2, 0, 14) SDL_SetHint(SDL_HINT_JOYSTICK_THREAD, "1"); +#endif if (SDL_WasInit(SDL_INIT_EVENTS)) { MP_ERR(src, "Another component is using SDL already.\n"); |