[gtk+] XInput allows up to 255 buttons



commit 2635fb75c688b9c44a7db4840afaadba4c6d31b3
Author: Thomas Jaeger <ThJaeger gmail com>
Date:   Tue Sep 29 01:51:44 2009 -0400

    XInput allows up to 255 buttons
    
    Signed-off-by: Thomas Jaeger <ThJaeger gmail com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=588649

 gdk/x11/gdkinput-x11.c    |   16 +++++++++++++---
 gdk/x11/gdkinput-xfree.c  |    5 +++--
 gdk/x11/gdkinputprivate.h |    3 ++-
 3 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/gdk/x11/gdkinput-x11.c b/gdk/x11/gdkinput-x11.c
index a423c91..73ce4cc 100644
--- a/gdk/x11/gdkinput-x11.c
+++ b/gdk/x11/gdkinput-x11.c
@@ -135,7 +135,8 @@ gdk_input_device_new (GdkDisplay  *display,
   gdkdev->info.has_cursor = 0;
   gdkdev->needs_update = FALSE;
   gdkdev->claimed = FALSE;
-  gdkdev->button_state = 0;
+  memset(gdkdev->button_state, 0, sizeof (gdkdev->button_state));
+  gdkdev->button_count = 0;
 
   class = device->inputclassinfo;
   for (i=0;i<device->num_classes;i++)
@@ -556,15 +557,24 @@ _gdk_input_common_other_event (GdkEvent         *event,
     {
       XDeviceButtonEvent *xdbe = (XDeviceButtonEvent *)(xevent);
 
+      g_return_val_if_fail (xdbe->button < 256, FALSE);
       if (xdbe->type == gdkdev->buttonpress_type)
 	{
 	  event->button.type = GDK_BUTTON_PRESS;
-	  gdkdev->button_state |= 1 << xdbe->button;
+	  if (!(gdkdev->button_state[xdbe->button/8] & 1 << (xdbe->button%8)))
+	    {
+	      gdkdev->button_state[xdbe->button/8] |= 1 << (xdbe->button%8);
+	      gdkdev->button_count++;
+	    }
 	}
       else
 	{
 	  event->button.type = GDK_BUTTON_RELEASE;
-	  gdkdev->button_state &= ~(1 << xdbe->button);
+	  if (gdkdev->button_state[xdbe->button/8] & 1 << (xdbe->button%8))
+	    {
+	      gdkdev->button_state[xdbe->button/8] &= ~(1 << (xdbe->button%8));
+	      gdkdev->button_count--;
+	    }
 	}
       event->button.device = &gdkdev->info;
       event->button.window = window;
diff --git a/gdk/x11/gdkinput-xfree.c b/gdk/x11/gdkinput-xfree.c
index e52ef2a..695175f 100644
--- a/gdk/x11/gdkinput-xfree.c
+++ b/gdk/x11/gdkinput-xfree.c
@@ -369,10 +369,11 @@ _gdk_input_grab_pointer (GdkWindow      *window,
 	{
 	  gdkdev = (GdkDevicePrivate *)tmp_list->data;
 	  if (!GDK_IS_CORE (gdkdev) && gdkdev->xdevice &&
-	      ((gdkdev->button_state != 0) || need_ungrab))
+	      ((gdkdev->button_count != 0) || need_ungrab))
 	    {
 	      XUngrabDevice (display_impl->xdisplay, gdkdev->xdevice, time);
-	      gdkdev->button_state = 0;
+	      memset(gdkdev->button_state, 0, sizeof (gdkdev->button_state));
+	      gdkdev->button_count = 0;
 	    }
 
 	  tmp_list = tmp_list->next;
diff --git a/gdk/x11/gdkinputprivate.h b/gdk/x11/gdkinputprivate.h
index 217e28c..aeb440e 100644
--- a/gdk/x11/gdkinputprivate.h
+++ b/gdk/x11/gdkinputprivate.h
@@ -89,7 +89,8 @@ struct _GdkDevicePrivate
   gint needs_update;
 
   /* Mask of buttons (used for button grabs) */
-  gint button_state;
+  char button_state[32];
+  gint button_count;
 
   /* true if we've claimed the device as active. (used only for XINPUT_GXI) */
   gint claimed;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]