1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-07 06:37:46 +00:00

input: minor cleanup

Add MP_KEY_MOUSE_ENTER to the ignored input if the user has disabled
mouse input. Remove one instance of code duplication, and add a
MP_KEY_IS_MOUSE_MOVE macro to summarize events that are caused by moving
the mouse.
This commit is contained in:
wm4 2015-02-18 21:09:35 +01:00
parent aa98049877
commit 69e6e7b17c
2 changed files with 11 additions and 12 deletions

View File

@ -463,11 +463,8 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, char *force_section,
if (code == MP_KEY_CLOSE_WIN)
return mp_input_parse_cmd_strv(ictx->log, (const char*[]){"quit", 0});
int msgl = MSGL_WARN;
if (code == MP_KEY_MOUSE_MOVE || code == MP_KEY_MOUSE_LEAVE ||
code == MP_KEY_MOUSE_ENTER)
{
if (MP_KEY_IS_MOUSE_MOVE(code))
msgl = MSGL_DEBUG;
}
char *key_buf = mp_input_get_key_combo_name(&code, 1);
MP_MSG(ictx, msgl, "No bind found for key '%s'.\n", key_buf);
talloc_free(key_buf);
@ -634,11 +631,7 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale)
}
if (!opts->enable_mouse_movements && MP_KEY_IS_MOUSE(unmod))
return;
if (unmod == MP_KEY_MOUSE_LEAVE) {
update_mouse_section(ictx);
mp_input_queue_cmd(ictx, get_cmd_from_keys(ictx, NULL, code));
return;
} else if (unmod == MP_KEY_MOUSE_ENTER) {
if (unmod == MP_KEY_MOUSE_LEAVE || unmod == MP_KEY_MOUSE_ENTER) {
update_mouse_section(ictx);
mp_input_queue_cmd(ictx, get_cmd_from_keys(ictx, NULL, code));
return;

View File

@ -224,13 +224,19 @@
#define MP_KEY_MOUSE_LEAVE ((MP_KEY_INTERN+2)|MP_NO_REPEAT_KEY)
#define MP_KEY_MOUSE_ENTER ((MP_KEY_INTERN+3)|MP_NO_REPEAT_KEY)
#define MP_KEY_IS_MOUSE_CLICK(code) \
(MP_KEY_IS_MOUSE_BTN_SINGLE(code) || MP_KEY_IS_MOUSE_BTN_DBL(code))
#define MP_KEY_IS_MOUSE_MOVE(code) \
((code) == MP_KEY_MOUSE_MOVE || (code) == MP_KEY_MOUSE_ENTER || \
(code) == MP_KEY_MOUSE_LEAVE)
// Whether to dispatch the key binding by current mouse position.
#define MP_KEY_DEPENDS_ON_MOUSE_POS(code) \
(MP_KEY_IS_MOUSE_BTN_SINGLE(code) || MP_KEY_IS_MOUSE_BTN_DBL(code) || \
(code) == MP_KEY_MOUSE_MOVE)
(MP_KEY_IS_MOUSE_CLICK(code) || (code) == MP_KEY_MOUSE_MOVE)
#define MP_KEY_IS_MOUSE(code) \
(MP_KEY_DEPENDS_ON_MOUSE_POS(code) || (code) == MP_KEY_MOUSE_LEAVE)
(MP_KEY_IS_MOUSE_CLICK(code) || MP_KEY_IS_MOUSE_MOVE(code))
// Emit a command even on key-up (normally key-up is ignored). This means by
// default they binding will be triggered on key-up instead of key-down.