1 #include "input/mouse.h"
6 static int keyb_fifo_put
=-1;
7 static int keyb_fifo_get
=-1;
9 static void set_nonblock_flag(int fd
) {
12 oldflags
= fcntl(fd
, F_GETFL
, 0);
14 if (fcntl(keyb_fifo_put
, F_SETFL
, oldflags
| O_NONBLOCK
) != -1) {
18 mp_msg(MSGT_INPUT
,MSGL_ERR
,"Cannot set nonblocking mode for fd %d!\n", fd
);
21 static void make_pipe(int* pr
,int* pw
){
23 if(pipe(temp
)!=0) mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_CannotMakePipe
);
26 set_nonblock_flag(temp
[1]);
29 static void mplayer_put_key_internal(int code
){
31 if( write(keyb_fifo_put
,&code
,4) != 4 ){
32 mp_msg(MSGT_INPUT
,MSGL_ERR
,"*** key event dropped (FIFO is full) ***\n");
38 int key_fifo_size
= 7;
39 static int *key_fifo_data
= NULL
;
40 static int key_fifo_read
=0;
41 static int key_fifo_write
=0;
43 static void mplayer_put_key_internal(int code
){
44 int fifo_free
= key_fifo_read
- key_fifo_write
- 1;
45 if (fifo_free
< 0) fifo_free
+= key_fifo_size
;
46 // printf("mplayer_put_key(%d)\n",code);
47 if (key_fifo_data
== NULL
)
48 key_fifo_data
= malloc(key_fifo_size
* sizeof(int));
49 if(!fifo_free
) return; // FIFO FULL!!
50 // reserve some space for key release events to avoid stuck keys
51 if((code
& MP_KEY_DOWN
) && fifo_free
< (key_fifo_size
>> 1))
53 key_fifo_data
[key_fifo_write
]=code
;
54 key_fifo_write
=(key_fifo_write
+1)%key_fifo_size
;
57 int mplayer_get_key(int fd
){
59 // printf("mplayer_get_key(%d)\n",fd);
60 if (key_fifo_data
== NULL
)
61 return MP_INPUT_NOTHING
;
62 if(key_fifo_write
==key_fifo_read
) return MP_INPUT_NOTHING
;
63 key
=key_fifo_data
[key_fifo_read
];
64 key_fifo_read
=(key_fifo_read
+1)%key_fifo_size
;
65 // printf("mplayer_get_key => %d\n",key);
71 static unsigned doubleclick_time
= 300;
73 static void put_double(int code
) {
74 if (code
>= MOUSE_BTN0
&& code
<= MOUSE_BTN9
)
75 mplayer_put_key_internal(code
- MOUSE_BTN0
+ MOUSE_BTN0_DBL
);
78 void mplayer_put_key(int code
) {
79 static unsigned last_key_time
[2];
80 static int last_key
[2];
81 unsigned now
= GetTimerMS();
82 // ignore system-doubleclick if we generate these events ourselves
83 if (doubleclick_time
&&
84 (code
& ~MP_KEY_DOWN
) >= MOUSE_BTN0_DBL
&&
85 (code
& ~MP_KEY_DOWN
) <= MOUSE_BTN9_DBL
)
87 mplayer_put_key_internal(code
);
88 if (code
& MP_KEY_DOWN
) {
90 last_key
[1] = last_key
[0];
92 last_key_time
[1] = last_key_time
[0];
93 last_key_time
[0] = now
;
94 if (last_key
[1] == code
&&
95 now
- last_key_time
[1] < doubleclick_time
)
99 if (last_key
[0] == code
&& last_key
[1] == code
&&
100 now
- last_key_time
[1] < doubleclick_time
)