Add global field dominance flag instead of duplicating this "everywhere"
[mplayer/glamo.git] / fifo.c
blobbd9afc54b7488d5aac9cc71ddef2f42339719c5d
1 #include "input/mouse.h"
3 #if 0
5 // keyboard:
6 static int keyb_fifo_put=-1;
7 static int keyb_fifo_get=-1;
9 static void set_nonblock_flag(int fd) {
10 int oldflags;
12 oldflags = fcntl(fd, F_GETFL, 0);
13 if (oldflags != -1) {
14 if (fcntl(keyb_fifo_put, F_SETFL, oldflags | O_NONBLOCK) != -1) {
15 return;
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){
22 int temp[2];
23 if(pipe(temp)!=0) mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_CannotMakePipe);
24 *pr=temp[0];
25 *pw=temp[1];
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");
36 #else
38 int key_fifo_size = 10;
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 // printf("mplayer_put_key(%d)\n",code);
45 if (key_fifo_data == NULL)
46 key_fifo_data = malloc(key_fifo_size * sizeof(int));
47 if(((key_fifo_write+1)%key_fifo_size)==key_fifo_read) return; // FIFO FULL!!
48 key_fifo_data[key_fifo_write]=code;
49 key_fifo_write=(key_fifo_write+1)%key_fifo_size;
52 int mplayer_get_key(int fd){
53 int key;
54 // printf("mplayer_get_key(%d)\n",fd);
55 if (key_fifo_data == NULL)
56 return MP_INPUT_NOTHING;
57 if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING;
58 key=key_fifo_data[key_fifo_read];
59 key_fifo_read=(key_fifo_read+1)%key_fifo_size;
60 // printf("mplayer_get_key => %d\n",key);
61 return key;
64 #endif
66 static unsigned doubleclick_time = 300;
68 static void put_double(int code) {
69 if (code >= MOUSE_BTN0 && code <= MOUSE_BTN9)
70 mplayer_put_key_internal(code - MOUSE_BTN0 + MOUSE_BTN0_DBL);
73 void mplayer_put_key(int code) {
74 static unsigned last_key_time[2];
75 static int last_key[2];
76 unsigned now = GetTimerMS();
77 // ignore system-doubleclick if we generate these events ourselves
78 if (doubleclick_time &&
79 (code & ~MP_KEY_DOWN) >= MOUSE_BTN0_DBL &&
80 (code & ~MP_KEY_DOWN) <= MOUSE_BTN9_DBL)
81 return;
82 // ignore mouse wheel down events since they can easily get stuck
83 if (code < (MOUSE_BTN3 | MP_KEY_DOWN) || code > (MOUSE_BTN4 | MP_KEY_DOWN))
84 mplayer_put_key_internal(code);
85 if (code & MP_KEY_DOWN) {
86 code &= ~MP_KEY_DOWN;
87 last_key[1] = last_key[0];
88 last_key[0] = code;
89 last_key_time[1] = last_key_time[0];
90 last_key_time[0] = now;
91 if (last_key[1] == code &&
92 now - last_key_time[1] < doubleclick_time)
93 put_double(code);
94 return;
96 if (last_key[0] == code && last_key[1] == code &&
97 now - last_key_time[1] < doubleclick_time)
98 put_double(code);