changeset 33019:03ed899a72bc

Allow mouse wheel to work with a key fifo size of 2.
author reimar
date Thu, 24 Mar 2011 22:34:23 +0000
parents d88b8a9e989e
children 733cca07c9a4
files input/input.c mp_fifo.c
diffstat 2 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/input/input.c	Thu Mar 24 22:28:17 2011 +0000
+++ b/input/input.c	Thu Mar 24 22:34:23 2011 +0000
@@ -1100,11 +1100,13 @@
   unsigned int j;
   mp_cmd_t* ret;
 
-  if (code == MP_KEY_RELEASE_ALL) {
+  if (code & MP_KEY_RELEASE_ALL) {
+      code &= ~MP_KEY_RELEASE_ALL;
       memset(key_down, 0, sizeof(key_down));
       num_key_down = 0;
       last_key_down = 0;
-      return NULL;
+      if (!code)
+          return NULL;
   }
 
   if(mp_input_key_cb) {
--- a/mp_fifo.c	Thu Mar 24 22:28:17 2011 +0000
+++ b/mp_fifo.c	Thu Mar 24 22:34:23 2011 +0000
@@ -26,6 +26,7 @@
 static int *key_fifo_data;
 static unsigned key_fifo_read;
 static unsigned key_fifo_write;
+static int previous_down_key;
 
 static void mplayer_put_key_internal(int code){
   int fifo_free = key_fifo_read + key_fifo_size - key_fifo_write;
@@ -37,10 +38,21 @@
   if((code & MP_KEY_DOWN) && fifo_free <= (key_fifo_size >> 1))
     return;
   // in the worst case, just reset key state
-  if (fifo_free == 1)
-    code = MP_KEY_RELEASE_ALL;
+  if (fifo_free == 1) {
+    // HACK: this ensures that a fifo size of 2 does
+    // not queue any key presses while still allowing
+    // the mouse wheel to work (which sends down and up
+    // at nearly the same time
+    if (code != previous_down_key)
+      code = 0;
+    code |= MP_KEY_RELEASE_ALL;
+  }
   key_fifo_data[key_fifo_write % key_fifo_size]=code;
   key_fifo_write++;
+  if (code & MP_KEY_DOWN)
+    previous_down_key = code & ~MP_KEY_DOWN;
+  else
+    previous_down_key = 0;
 }
 
 int mplayer_get_key(int fd){