0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

input: modify interpretation of doubleclick events

The code combining button presses into multibutton commands prevented
single click commands from triggering if a doubleclick event had been
generated from the same button press. As a result using the mouse
wheel to seek worked very badly. Special-case doubleclick events in
the event interpretation code to avoid this issue. This changes the
sequence of generated "keys" for press-release-press-release from
MOUSE_BTN0   MOUSE_BTN0-MOUSE_BTN0_DBL   MOUSE_BTN0_DBL   to
MOUSE_BTN0   MOUSE_BTN0_DBL              MOUSE_BTN0.
"Keys" like MOUSE_BTN0-MOUSE_BTN0_DBL will never be generated now; any
existing configuration files using those need to be changed.
This commit is contained in:
Uoti Urpala 2011-04-25 14:12:04 +03:00
parent 325926f9f8
commit b9eaafe1ed
3 changed files with 19 additions and 16 deletions

View File

@ -780,10 +780,6 @@ Time in milliseconds to recognize two consecutive button presses as
a double-click (default: 300). a double-click (default: 300).
Set to 0 to let your windowing system decide what a double-click is Set to 0 to let your windowing system decide what a double-click is
(\-vo directx only). (\-vo directx only).
.br
.I NOTE:
You will get slightly different behaviour depending on whether you bind
MOUSE_BTN0_DBL or MOUSE_BTN0\-MOUSE_BTN0_DBL.
. .
.TP .TP
.B \-edlout <filename> .B \-edlout <filename>

View File

@ -1184,6 +1184,15 @@ static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code)
if (ictx->key_down[j] == code) if (ictx->key_down[j] == code)
break; break;
} }
bool doubleclick = code >= MOUSE_BTN0_DBL && code < MOUSE_BTN_DBL_END;
if (doubleclick) {
int btn = code - MOUSE_BTN0_DBL + MOUSE_BTN0;
if (!ictx->num_key_down
|| ictx->key_down[ictx->num_key_down - 1] != btn)
return NULL;
j = ictx->num_key_down - 1;
ictx->key_down[j] = code;
}
if (j == ictx->num_key_down) { // was not already down; add temporarily if (j == ictx->num_key_down) { // was not already down; add temporarily
if (ictx->num_key_down > MP_MAX_KEY_DOWN) { if (ictx->num_key_down > MP_MAX_KEY_DOWN) {
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Too many key down events " mp_tmsg(MSGT_INPUT, MSGL_ERR, "Too many key down events "
@ -1198,6 +1207,10 @@ static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code)
ret = ictx->last_key_down ? ret = ictx->last_key_down ?
get_cmd_from_keys(ictx, ictx->num_key_down, ictx->key_down) get_cmd_from_keys(ictx, ictx->num_key_down, ictx->key_down)
: NULL; : NULL;
if (doubleclick) {
ictx->key_down[j] = code - MOUSE_BTN0_DBL + MOUSE_BTN0;
return ret;
}
// Remove the key // Remove the key
if (j + 1 < ictx->num_key_down) if (j + 1 < ictx->num_key_down)
memmove(&ictx->key_down[j], &ictx->key_down[j + 1], memmove(&ictx->key_down[j], &ictx->key_down[j + 1],

View File

@ -31,8 +31,8 @@ struct mp_fifo {
int readpos; int readpos;
int writepos; int writepos;
int size; int size;
unsigned last_key_time[2]; int last_key_down;
int last_key[2]; unsigned last_down_time;
}; };
struct mp_fifo *mp_fifo_create(struct MPOpts *opts) struct mp_fifo *mp_fifo_create(struct MPOpts *opts)
@ -86,16 +86,10 @@ void mplayer_put_key(struct mp_fifo *fifo, int code)
mplayer_put_key_internal(fifo, code); mplayer_put_key_internal(fifo, code);
if (code & MP_KEY_DOWN) { if (code & MP_KEY_DOWN) {
code &= ~MP_KEY_DOWN; code &= ~MP_KEY_DOWN;
fifo->last_key[1] = fifo->last_key[0]; if (fifo->last_key_down == code
fifo->last_key[0] = code; && now - fifo->last_down_time < doubleclick_time)
fifo->last_key_time[1] = fifo->last_key_time[0];
fifo->last_key_time[0] = now;
if (fifo->last_key[1] == code
&& now - fifo->last_key_time[1] < doubleclick_time)
put_double(fifo, code); put_double(fifo, code);
return; fifo->last_key_down = code;
fifo->last_down_time = now;
} }
if (fifo->last_key[0] == code && fifo->last_key[1] == code
&& now - fifo->last_key_time[1] < doubleclick_time)
put_double(fifo, code);
} }