1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-27 17:42:17 +00:00

command: disable autorepeat for some commands (actually properties)

Disable autorepeat for the "add"/"cycle" commands when changing
properties that are choices (such as fullscreen, pause, and more).
In these cases, autorepeat is not very useful, and can rather harmful
effects (like triggering too many repeated commands if command
execution is slow).

(Actually, the commands are just dropped _after_ being repeated, since
input.c itself does not know enough about the commands to decide whether
or not they should be repeated.)
This commit is contained in:
wm4 2013-10-28 00:33:52 +01:00
parent f2d438a1fd
commit 5e9c226229
3 changed files with 29 additions and 5 deletions

View File

@ -2347,6 +2347,20 @@ static void overlay_uninit(struct MPContext *mpctx){}
#endif
// Whether this property should react to key events generated by auto-repeat.
static bool check_property_autorepeat(char *property, struct MPContext *mpctx)
{
struct m_option prop = {0};
if (mp_property_do(property, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0)
return true;
// This is a heuristic at best.
if (prop.type == &m_option_type_flag || prop.type == &m_option_type_choice)
return false;
return true;
}
void run_command(MPContext *mpctx, mp_cmd_t *cmd)
{
struct MPOpts *opts = mpctx->opts;
@ -2417,16 +2431,23 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
};
if (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);
char *property = cmd->args[0].v.s;
if (cmd->repeated && !check_property_autorepeat(property, mpctx)) {
mp_msg(MSGT_CPLAYER, MSGL_V,
"Dropping command '%.*s' from auto-repeated key.\n",
BSTR_P(cmd->original));
break;
}
int r = mp_property_do(property, M_PROPERTY_SWITCH, &s, mpctx);
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, property, cmd->on_osd);
} else if (r == M_PROPERTY_UNKNOWN) {
set_osd_msg(mpctx, OSD_MSG_TEXT, osdl, osd_duration,
"Unknown property: '%s'", cmd->args[0].v.s);
"Unknown property: '%s'", property);
} else if (r <= 0) {
set_osd_msg(mpctx, OSD_MSG_TEXT, osdl, osd_duration,
"Failed to increment property '%s' by %g",
cmd->args[0].v.s, s.inc);
property, s.inc);
}
break;
}

View File

@ -1877,9 +1877,11 @@ mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int peek_only)
struct cmd_queue *queue = &ictx->cmd_queue;
if (!queue->first) {
struct mp_cmd *repeated = check_autorepeat(ictx);
if (repeated)
if (repeated) {
repeated->repeated = true;
queue_add_tail(queue, repeated);
}
}
struct mp_cmd *ret = queue_peek(queue);
if (ret && !peek_only) {
queue_remove(queue, ret);

View File

@ -154,6 +154,7 @@ typedef struct mp_cmd {
bstr original;
char *input_section;
bool key_up_follows;
bool repeated;
bool mouse_move;
int mouse_x, mouse_y;
struct mp_cmd *queue_next;