2 #include "osdep/timer.h"
3 #include "input/input.h"
4 #include "input/mouse.h"
16 unsigned last_key_time
[2];
20 struct mp_fifo
*mp_fifo_create(struct MPOpts
*opts
)
22 struct mp_fifo
*fifo
= talloc_zero(NULL
, struct mp_fifo
);
24 fifo
->size
= opts
->key_fifo_size
;
25 fifo
->data
= talloc_array_ptrtype(fifo
, fifo
->data
, fifo
->size
);
29 static void mplayer_put_key_internal(struct mp_fifo
*fifo
, int code
)
31 int fifo_free
= fifo
->readpos
- fifo
->writepos
- 1;
33 fifo_free
+= fifo
->size
;
35 return; // FIFO FULL!!
36 // reserve some space for key release events to avoid stuck keys
37 if((code
& MP_KEY_DOWN
) && fifo_free
< (fifo
->size
>> 1))
39 fifo
->data
[fifo
->writepos
++] = code
;
40 fifo
->writepos
%= fifo
->size
;
43 int mplayer_get_key(void *ctx
, int fd
)
45 struct mp_fifo
*fifo
= ctx
;
46 if (fifo
->writepos
== fifo
->readpos
)
47 return MP_INPUT_NOTHING
;
48 int key
= fifo
->data
[fifo
->readpos
++];
49 fifo
->readpos
%= fifo
->size
;
53 static void put_double(struct mp_fifo
*fifo
, int code
)
55 if (code
>= MOUSE_BTN0
&& code
<= MOUSE_BTN9
)
56 mplayer_put_key_internal(fifo
, code
- MOUSE_BTN0
+ MOUSE_BTN0_DBL
);
59 void mplayer_put_key(struct mp_fifo
*fifo
, int code
)
61 unsigned now
= GetTimerMS();
62 int doubleclick_time
= fifo
->opts
->doubleclick_time
;
63 // ignore system-doubleclick if we generate these events ourselves
65 && (code
& ~MP_KEY_DOWN
) >= MOUSE_BTN0_DBL
66 && (code
& ~MP_KEY_DOWN
) <= MOUSE_BTN9_DBL
)
68 mplayer_put_key_internal(fifo
, code
);
69 if (code
& MP_KEY_DOWN
) {
71 fifo
->last_key
[1] = fifo
->last_key
[0];
72 fifo
->last_key
[0] = code
;
73 fifo
->last_key_time
[1] = fifo
->last_key_time
[0];
74 fifo
->last_key_time
[0] = now
;
75 if (fifo
->last_key
[1] == code
76 && now
- fifo
->last_key_time
[1] < doubleclick_time
)
77 put_double(fifo
, code
);
80 if (fifo
->last_key
[0] == code
&& fifo
->last_key
[1] == code
81 && now
- fifo
->last_key_time
[1] < doubleclick_time
)
82 put_double(fifo
, code
);