changeset 875:ce224a356eb8

6750288: Regression after 6315717. ArrayIndexOutOfBoundsException. Reviewed-by: dcherepanov, denis
author dav
date Tue, 07 Oct 2008 16:34:27 +0400
parents 485e803c2d5a
children 724eb9cbd3bb
files src/solaris/classes/sun/awt/X11/XToolkit.java
diffstat 1 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/classes/sun/awt/X11/XToolkit.java	Fri Oct 03 10:33:11 2008 +0400
+++ b/src/solaris/classes/sun/awt/X11/XToolkit.java	Tue Oct 07 16:34:27 2008 +0400
@@ -79,6 +79,21 @@
     private static boolean areExtraMouseButtonsEnabled = true;
 
     /**
+     * Number of buttons.
+     * By default it's taken from the system. If system value does not
+     * fit into int type range, use our own MAX_BUTTONS_SUPPORT value.
+     */
+    private static int numberOfButtons = 0;
+
+    /* XFree standard mention 24 buttons as maximum:
+     * http://www.xfree86.org/current/mouse.4.html
+     * We workaround systems supporting more than 24 buttons.
+     * Otherwise, we have to use long type values as masks
+     * which leads to API change.
+     */
+    private static int MAX_BUTTONS_SUPPORT = 24;
+
+    /**
      * True when the x settings have been loaded.
      */
     private boolean loadedXSettings;
@@ -1393,7 +1408,12 @@
     public static int getNumMouseButtons() {
         awtLock();
         try {
-            return XlibWrapper.XGetPointerMapping(XToolkit.getDisplay(), 0, 0);
+            if (numberOfButtons == 0) {
+                numberOfButtons = Math.min(
+                    XlibWrapper.XGetPointerMapping(XToolkit.getDisplay(), 0, 0),
+                    MAX_BUTTONS_SUPPORT);
+            }
+            return numberOfButtons;
         } finally {
             awtUnlock();
         }