mirror of https://github.com/mpv-player/mpv
input: add support for precise scroll axes
Support horizontal and vertical axes of input devices. If the input device support precise scrolling with an input value then it should first be scaled to a standard multiplier, where 1.0 is the default. The multiplier will then applied to the following commands if possible: * MP_CMD_SEEK * MP_CMD_SPEED_MULT * MP_CMD_ADD All other commands will triggered on every axis event, without change the values specified in the config file.
This commit is contained in:
parent
406241005e
commit
023e5ccd02
|
@ -35,6 +35,12 @@ MOUSE_BTN4 seek -10
|
||||||
MOUSE_BTN5 add volume 1
|
MOUSE_BTN5 add volume 1
|
||||||
MOUSE_BTN6 add volume -1
|
MOUSE_BTN6 add volume -1
|
||||||
|
|
||||||
|
# Mouse wheels, touchpad or other input devices that have axes
|
||||||
|
AXIS_UP seek 10
|
||||||
|
AXIS_DOWN seek -10
|
||||||
|
AXIS_LEFT speed_mult 0.5
|
||||||
|
AXIS_RIGHT speed_mult 1.5
|
||||||
|
|
||||||
# Seek units are in seconds, but note that these are limited by keyframes
|
# Seek units are in seconds, but note that these are limited by keyframes
|
||||||
RIGHT seek 10
|
RIGHT seek 10
|
||||||
LEFT seek -10
|
LEFT seek -10
|
||||||
|
|
|
@ -2142,7 +2142,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||||
|
|
||||||
switch (cmd->id) {
|
switch (cmd->id) {
|
||||||
case MP_CMD_SEEK: {
|
case MP_CMD_SEEK: {
|
||||||
double v = cmd->args[0].v.d;
|
double v = cmd->args[0].v.d * cmd->scale;
|
||||||
int abs = cmd->args[1].v.i;
|
int abs = cmd->args[1].v.i;
|
||||||
int exact = cmd->args[2].v.i;
|
int exact = cmd->args[2].v.i;
|
||||||
if (abs == 2) { // Absolute seek to a timestamp in seconds
|
if (abs == 2) { // Absolute seek to a timestamp in seconds
|
||||||
|
@ -2187,7 +2187,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||||
.wrap = cmd->id == MP_CMD_CYCLE,
|
.wrap = cmd->id == MP_CMD_CYCLE,
|
||||||
};
|
};
|
||||||
if (cmd->args[1].v.d)
|
if (cmd->args[1].v.d)
|
||||||
s.inc = cmd->args[1].v.d;
|
s.inc = cmd->args[1].v.d * cmd->scale;
|
||||||
int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_SWITCH, &s, mpctx);
|
int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_SWITCH, &s, mpctx);
|
||||||
if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) {
|
if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) {
|
||||||
show_property_osd(mpctx, cmd->args[0].v.s, cmd->on_osd);
|
show_property_osd(mpctx, cmd->args[0].v.s, cmd->on_osd);
|
||||||
|
@ -2221,7 +2221,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
case MP_CMD_SPEED_MULT: {
|
case MP_CMD_SPEED_MULT: {
|
||||||
double v = cmd->args[0].v.d;
|
double v = cmd->args[0].v.d * cmd->scale;
|
||||||
v *= mpctx->opts->playback_speed;
|
v *= mpctx->opts->playback_speed;
|
||||||
mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
|
mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
|
||||||
show_property_osd(mpctx, "speed", cmd->on_osd);
|
show_property_osd(mpctx, "speed", cmd->on_osd);
|
||||||
|
|
|
@ -424,6 +424,11 @@ static const struct key_name key_names[] = {
|
||||||
{ MP_MK_PREV, "MK_PREV" },
|
{ MP_MK_PREV, "MK_PREV" },
|
||||||
{ MP_MK_NEXT, "MK_NEXT" },
|
{ MP_MK_NEXT, "MK_NEXT" },
|
||||||
|
|
||||||
|
{ MP_AXIS_UP, "AXIS_UP" },
|
||||||
|
{ MP_AXIS_DOWN, "AXIS_DOWN" },
|
||||||
|
{ MP_AXIS_LEFT, "AXIS_LEFT" },
|
||||||
|
{ MP_AXIS_RIGHT, "AXIS_RIGHT" },
|
||||||
|
|
||||||
{ MP_KEY_POWER, "POWER" },
|
{ MP_KEY_POWER, "POWER" },
|
||||||
{ MP_KEY_MENU, "MENU" },
|
{ MP_KEY_MENU, "MENU" },
|
||||||
{ MP_KEY_PLAY, "PLAY" },
|
{ MP_KEY_PLAY, "PLAY" },
|
||||||
|
@ -910,6 +915,7 @@ static int parse_cmd(struct mp_cmd **dest, bstr str, const char *loc)
|
||||||
|
|
||||||
cmd = talloc_ptrtype(NULL, cmd);
|
cmd = talloc_ptrtype(NULL, cmd);
|
||||||
*cmd = mp_cmds[cmd_idx];
|
*cmd = mp_cmds[cmd_idx];
|
||||||
|
cmd->scale = 1;
|
||||||
cmd->pausing = pausing;
|
cmd->pausing = pausing;
|
||||||
cmd->on_osd = on_osd;
|
cmd->on_osd = on_osd;
|
||||||
cmd->raw_args = raw_args;
|
cmd->raw_args = raw_args;
|
||||||
|
@ -1517,6 +1523,18 @@ void mp_input_put_key_utf8(struct input_ctx *ictx, int mods, struct bstr t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mp_input_put_axis(struct input_ctx *ictx, int direction, double value)
|
||||||
|
{
|
||||||
|
struct mp_cmd *cmd = interpret_key(ictx, direction);
|
||||||
|
if (!cmd)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cmd->scale = value;
|
||||||
|
|
||||||
|
ictx->got_new_events = true;
|
||||||
|
add_key_cmd(ictx, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
static void trigger_mouse_leave(struct input_ctx *ictx, char *new_section)
|
static void trigger_mouse_leave(struct input_ctx *ictx, char *new_section)
|
||||||
{
|
{
|
||||||
if (!new_section)
|
if (!new_section)
|
||||||
|
|
|
@ -146,6 +146,7 @@ typedef struct mp_cmd {
|
||||||
bool mouse_move;
|
bool mouse_move;
|
||||||
int mouse_x, mouse_y;
|
int mouse_x, mouse_y;
|
||||||
struct mp_cmd *queue_next;
|
struct mp_cmd *queue_next;
|
||||||
|
double scale; // for scaling numeric arguments
|
||||||
} mp_cmd_t;
|
} mp_cmd_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,6 +182,10 @@ void mp_input_put_key(struct input_ctx *ictx, int code);
|
||||||
// string as key events.
|
// string as key events.
|
||||||
void mp_input_put_key_utf8(struct input_ctx *ictx, int mods, struct bstr t);
|
void mp_input_put_key_utf8(struct input_ctx *ictx, int mods, struct bstr t);
|
||||||
|
|
||||||
|
// Process scrolling input. Support for precise scrolling. Scales the given
|
||||||
|
// scroll amount add multiplies it with the command (seeking, sub-delay, etc)
|
||||||
|
void mp_input_put_axis(struct input_ctx *ictx, int direction, double value);
|
||||||
|
|
||||||
// Update mouse position (in window coordinates).
|
// Update mouse position (in window coordinates).
|
||||||
void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y);
|
void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y);
|
||||||
|
|
||||||
|
|
|
@ -201,6 +201,13 @@
|
||||||
#define MP_MK_PREV (MP_MK_BASE + 1)
|
#define MP_MK_PREV (MP_MK_BASE + 1)
|
||||||
#define MP_MK_NEXT (MP_MK_BASE + 2)
|
#define MP_MK_NEXT (MP_MK_BASE + 2)
|
||||||
|
|
||||||
|
// Mouse wheels or touchpad input
|
||||||
|
#define MP_AXIS_BASE (MP_KEY_BASE+0x100)
|
||||||
|
#define MP_AXIS_UP (MP_AXIS_BASE+0)
|
||||||
|
#define MP_AXIS_DOWN (MP_AXIS_BASE+1)
|
||||||
|
#define MP_AXIS_LEFT (MP_AXIS_BASE+2)
|
||||||
|
#define MP_AXIS_RIGHT (MP_AXIS_BASE+3)
|
||||||
|
|
||||||
/* Special keys */
|
/* Special keys */
|
||||||
#define MP_KEY_INTERN (MP_KEY_BASE+0x1000)
|
#define MP_KEY_INTERN (MP_KEY_BASE+0x1000)
|
||||||
#define MP_KEY_CLOSE_WIN (MP_KEY_INTERN+0)
|
#define MP_KEY_CLOSE_WIN (MP_KEY_INTERN+0)
|
||||||
|
|
Loading…
Reference in New Issue