Mercurial > mplayer.hg
annotate fifo.c @ 22003:6fd6bf6269f3
fastmemcpy.h always has to include inttypes.h on systems that need it.
patch by Carl Eugen Hoyos, cehoyos ag.or at
author | diego |
---|---|
date | Fri, 26 Jan 2007 18:43:17 +0000 |
parents | d8ffeda84296 |
children | 934010b90043 |
rev | line source |
---|---|
21941
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
1 #include "input/mouse.h" |
9831 | 2 |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
3 #if 0 |
113 | 4 |
5 // keyboard: | |
6 static int keyb_fifo_put=-1; | |
7 static int keyb_fifo_get=-1; | |
8 | |
13872
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
9 static void set_nonblock_flag(int fd) { |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
10 int oldflags; |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
11 |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
12 oldflags = fcntl(fd, F_GETFL, 0); |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
13 if (oldflags != -1) { |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
14 if (fcntl(keyb_fifo_put, F_SETFL, oldflags | O_NONBLOCK) != -1) { |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
15 return; |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
16 } |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
17 } |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
18 mp_msg(MSGT_INPUT,MSGL_ERR,"Cannot set nonblocking mode for fd %d!\n", fd); |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
19 } |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
20 |
113 | 21 static void make_pipe(int* pr,int* pw){ |
22 int temp[2]; | |
13699
11b249ef87b0
printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents:
9831
diff
changeset
|
23 if(pipe(temp)!=0) mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_CannotMakePipe); |
113 | 24 *pr=temp[0]; |
25 *pw=temp[1]; | |
13872
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
26 set_nonblock_flag(temp[1]); |
113 | 27 } |
28 | |
21941
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
29 static void mplayer_put_key_internal(int code){ |
113 | 30 |
13872
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
31 if( write(keyb_fifo_put,&code,4) != 4 ){ |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
32 mp_msg(MSGT_INPUT,MSGL_ERR,"*** key event dropped (FIFO is full) ***\n"); |
8b810ed6e543
fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents:
13699
diff
changeset
|
33 } |
113 | 34 } |
9831 | 35 |
36 #else | |
37 | |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
38 int key_fifo_size = 10; |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
39 static int *key_fifo_data = NULL; |
9831 | 40 static int key_fifo_read=0; |
41 static int key_fifo_write=0; | |
42 | |
21941
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
43 static void mplayer_put_key_internal(int code){ |
9831 | 44 // printf("mplayer_put_key(%d)\n",code); |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
45 if (key_fifo_data == NULL) |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
46 key_fifo_data = malloc(key_fifo_size * sizeof(int)); |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
47 if(((key_fifo_write+1)%key_fifo_size)==key_fifo_read) return; // FIFO FULL!! |
9831 | 48 key_fifo_data[key_fifo_write]=code; |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
49 key_fifo_write=(key_fifo_write+1)%key_fifo_size; |
9831 | 50 } |
51 | |
52 int mplayer_get_key(int fd){ | |
53 int key; | |
54 // printf("mplayer_get_key(%d)\n",fd); | |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
55 if (key_fifo_data == NULL) |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
56 return MP_INPUT_NOTHING; |
9831 | 57 if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING; |
58 key=key_fifo_data[key_fifo_read]; | |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
59 key_fifo_read=(key_fifo_read+1)%key_fifo_size; |
9831 | 60 // printf("mplayer_get_key => %d\n",key); |
61 return key; | |
62 } | |
63 | |
64 #endif | |
65 | |
21941
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
66 static unsigned doubleclick_time = 300; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
67 |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
68 static void put_double(int code) { |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
69 if (code >= MOUSE_BTN0 && code <= MOUSE_BTN9) |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
70 mplayer_put_key_internal(code - MOUSE_BTN0 + MOUSE_BTN0_DBL); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
71 } |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
72 |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
73 void mplayer_put_key(int code) { |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
74 static unsigned last_key_time[2]; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
75 static int last_key[2]; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
76 unsigned now = GetTimerMS(); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
77 // ignore system-doubleclick if we generate these events ourselves |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
78 if (doubleclick_time && |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
79 (code & ~MP_KEY_DOWN) >= MOUSE_BTN0_DBL && |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
80 (code & ~MP_KEY_DOWN) <= MOUSE_BTN9_DBL) |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
81 return; |
21964
d8ffeda84296
Move code to ignore mouse wheel "down" events to fifo.c (needed because
reimar
parents:
21941
diff
changeset
|
82 // ignore mouse wheel down events since they can easily get stuck |
d8ffeda84296
Move code to ignore mouse wheel "down" events to fifo.c (needed because
reimar
parents:
21941
diff
changeset
|
83 if (code < (MOUSE_BTN3 | MP_KEY_DOWN) || code > (MOUSE_BTN4 | MP_KEY_DOWN)) |
21941
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
84 mplayer_put_key_internal(code); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
85 if (code & MP_KEY_DOWN) { |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
86 code &= ~MP_KEY_DOWN; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
87 last_key[1] = last_key[0]; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
88 last_key[0] = code; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
89 last_key_time[1] = last_key_time[0]; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
90 last_key_time[0] = now; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
91 if (last_key[1] == code && |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
92 now - last_key_time[1] < doubleclick_time) |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
93 put_double(code); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
94 return; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
95 } |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
96 if (last_key[0] == code && last_key[1] == code && |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
97 now - last_key_time[1] < doubleclick_time) |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
98 put_double(code); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
99 } |