changeset 22131:934010b90043

Reserve half of fifo for key release events to help avoiding stop buttons and remove thus useless hack for mouse wheel.
author reimar
date Mon, 05 Feb 2007 17:51:26 +0000
parents bca522054afe
children 2de97f5f0662
files fifo.c
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/fifo.c	Mon Feb 05 17:47:43 2007 +0000
+++ b/fifo.c	Mon Feb 05 17:51:26 2007 +0000
@@ -35,16 +35,21 @@
 
 #else
 
-int key_fifo_size = 10;
+int key_fifo_size = 7;
 static int *key_fifo_data = NULL;
 static int key_fifo_read=0;
 static int key_fifo_write=0;
 
 static void mplayer_put_key_internal(int code){
+  int fifo_free = key_fifo_read - key_fifo_write - 1;
+  if (fifo_free < 0) fifo_free += key_fifo_size;
 //  printf("mplayer_put_key(%d)\n",code);
   if (key_fifo_data == NULL)
     key_fifo_data = malloc(key_fifo_size * sizeof(int));
-  if(((key_fifo_write+1)%key_fifo_size)==key_fifo_read) return; // FIFO FULL!!
+  if(!fifo_free) return; // FIFO FULL!!
+  // reserve some space for key release events to avoid stuck keys
+  if((code & MP_KEY_DOWN) && fifo_free < (key_fifo_size >> 1))
+    return;
   key_fifo_data[key_fifo_write]=code;
   key_fifo_write=(key_fifo_write+1)%key_fifo_size;
 }
@@ -79,8 +84,6 @@
       (code & ~MP_KEY_DOWN) >= MOUSE_BTN0_DBL &&
       (code & ~MP_KEY_DOWN) <= MOUSE_BTN9_DBL)
     return;
-  // ignore mouse wheel down events since they can easily get stuck
-  if (code < (MOUSE_BTN3 | MP_KEY_DOWN) || code > (MOUSE_BTN4 | MP_KEY_DOWN))
   mplayer_put_key_internal(code);
   if (code & MP_KEY_DOWN) {
     code &= ~MP_KEY_DOWN;