8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
authorneugens
Mon, 17 Dec 2012 17:43:21 +0100
changeset 14888 7ad1550e7050
parent 14887 226dd1cda199
child 14889 591d504751ec
8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list Summary: Don't consider extraenous bits when checking button mask, so that grabWindowRef on the window is not confused and released correctly Reviewed-by: art, anthony
jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java
jdk/src/solaris/classes/sun/awt/X11/XConstants.java
jdk/src/solaris/classes/sun/awt/X11/XToolkit.java
jdk/src/solaris/classes/sun/awt/X11/XWindow.java
jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java
jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java
--- a/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java	Mon Dec 17 16:58:56 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java	Mon Dec 17 17:43:21 2012 +0100
@@ -994,10 +994,7 @@
             return;
         }
         int buttonState = 0;
-        final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
-        for (int i = 0; i<buttonsNumber; i++){
-            buttonState |= (xbe.get_state() & XConstants.buttonsMask[i]);
-        }
+        buttonState = xbe.get_state() & XConstants.ALL_BUTTONS_MASK;
         switch (xev.get_type()) {
         case XConstants.ButtonPress:
             if (buttonState == 0) {
@@ -1034,12 +1031,12 @@
      * Checks ButtonRelease released all Mouse buttons
      */
     static boolean isFullRelease(int buttonState, int button) {
-        final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
+        final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
 
         if (button < 0 || button > buttonsNumber) {
             return buttonState == 0;
         } else {
-            return buttonState == XConstants.buttonsMask[button - 1];
+            return buttonState == XlibUtil.getButtonMask(button);
         }
     }
 
--- a/jdk/src/solaris/classes/sun/awt/X11/XConstants.java	Mon Dec 17 16:58:56 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XConstants.java	Mon Dec 17 17:43:21 2012 +0100
@@ -130,6 +130,9 @@
     public static final long ColormapChangeMask = (1L<<23) ;
     public static final long OwnerGrabButtonMask = (1L<<24) ;
 
+    public static final int MAX_BUTTONS = 5;
+    public static final int ALL_BUTTONS_MASK = (int) (Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask);
+
     /* Event names.  Used in "type" field in XEvent structures.  Not to be
     confused with event masks above.  They start from 2 because 0 and 1
     are reserved in the protocol for errors and replies. */
@@ -194,34 +197,6 @@
     public static final int Mod4MapIndex = 6 ;
     public static final int Mod5MapIndex = 7 ;
 
-
-    /* button masks.  Used in same manner as Key masks above. Not to be confused
-       with button names below. */
-    public static final int [] buttonsMask = new int []{ 1<<8,
-                                                         1<<9,
-                                                         1<<10,
-                                                         1<<11,
-                                                         1<<12,
-                                                         1<<13,
-                                                         1<<14,
-                                                         1<<15,
-                                                         1<<16,
-                                                         1<<17,
-                                                         1<<18,
-                                                         1<<19,
-                                                         1<<20,
-                                                         1<<21,
-                                                         1<<22,
-                                                         1<<23,
-                                                         1<<24,
-                                                         1<<25,
-                                                         1<<26,
-                                                         1<<27,
-                                                         1<<28,
-                                                         1<<29,
-                                                         1<<30,
-                                                         1<<31 };
-
     public static final int AnyModifier = (1<<15) ; /* used in GrabButton, GrabKey */
 
 
--- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Mon Dec 17 16:58:56 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Mon Dec 17 17:43:21 2012 +0100
@@ -1543,6 +1543,10 @@
         }
     }
 
+    static int getNumberOfButtonsForMask() {
+        return Math.min(XConstants.MAX_BUTTONS, ((SunToolkit) (Toolkit.getDefaultToolkit())).getNumberOfButtons());
+    }
+
     private final static String prefix  = "DnD.Cursor.";
     private final static String postfix = ".32x32";
     private static final String dndPrefix  = "DnD.";
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindow.java	Mon Dec 17 16:58:56 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindow.java	Mon Dec 17 17:43:21 2012 +0100
@@ -596,12 +596,12 @@
         /* this is an attempt to refactor button IDs in : MouseEvent, InputEvent, XlibWrapper and XWindow.*/
 
         //reflects a button number similar to MouseEvent.BUTTON1, 2, 3 etc.
-        for (int i = 0; i < XConstants.buttonsMask.length; i ++){
+        for (int i = 0; i < XConstants.buttons.length; i ++){
             //modifier should be added if :
             // 1) current button is now still in PRESSED state (means that user just pressed mouse but not released yet) or
             // 2) if Xsystem reports that "state" represents that button was just released. This only happens on RELEASE with 1,2,3 buttons.
             // ONLY one of these conditions should be TRUE to add that modifier.
-            if (((state & XConstants.buttonsMask[i]) != 0) != (button == XConstants.buttons[i])){
+            if (((state & XlibUtil.getButtonMask(i + 1)) != 0) != (button == XConstants.buttons[i])){
                 //exclude wheel buttons from adding their numbers as modifiers
                 if (!wheel_mouse) {
                     modifiers |= InputEvent.getMaskForButton(i+1);
@@ -689,7 +689,7 @@
 
         if (type == XConstants.ButtonPress) {
             //Allow this mouse button to generate CLICK event on next ButtonRelease
-            mouseButtonClickAllowed |= XConstants.buttonsMask[lbutton];
+            mouseButtonClickAllowed |= XlibUtil.getButtonMask(lbutton);
             XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null);
             /*
                multiclick checking
@@ -747,7 +747,7 @@
             postEventToEventQueue(me);
 
             if ((type == XConstants.ButtonRelease) &&
-                ((mouseButtonClickAllowed & XConstants.buttonsMask[lbutton]) != 0) ) // No up-button in the drag-state
+                ((mouseButtonClickAllowed & XlibUtil.getButtonMask(lbutton)) != 0) ) // No up-button in the drag-state
             {
                 postEventToEventQueue(me = new MouseEvent((Component)getEventSource(),
                                                      MouseEvent.MOUSE_CLICKED,
@@ -777,7 +777,7 @@
         /* Update the state variable AFTER the CLICKED event post. */
         if (type == XConstants.ButtonRelease) {
             /* Exclude this mouse button from allowed list.*/
-            mouseButtonClickAllowed &= ~XConstants.buttonsMask[lbutton];
+            mouseButtonClickAllowed &= ~ XlibUtil.getButtonMask(lbutton);
         }
     }
 
@@ -793,12 +793,12 @@
         //this doesn't work for extra buttons because Xsystem is sending state==0 for every extra button event.
         // we can't correct it in MouseEvent class as we done it with modifiers, because exact type (DRAG|MOVE)
         // should be passed from XWindow.
-        final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
+        final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
 
         for (int i = 0; i < buttonsNumber; i++){
             // TODO : here is the bug in WM: extra buttons doesn't have state!=0 as they should.
             if ((i != 4) && (i != 5)) {
-                mouseKeyState = mouseKeyState | (xme.get_state() & XConstants.buttonsMask[i]);
+                mouseKeyState = mouseKeyState | (xme.get_state() & XlibUtil.getButtonMask(i + 1));
             }
         }
 
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java	Mon Dec 17 16:58:56 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java	Mon Dec 17 17:43:21 2012 +0100
@@ -2070,12 +2070,12 @@
         }
         if (isGrabbed()) {
             boolean dragging = false;
-            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
+            final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
 
             for (int i = 0; i < buttonsNumber; i++){
                 // here is the bug in WM: extra buttons doesn't have state!=0 as they should.
                 if ((i != 4) && (i != 5)){
-                    dragging = dragging || ((xme.get_state() & XConstants.buttonsMask[i]) != 0);
+                    dragging = dragging || ((xme.get_state() & XlibUtil.getButtonMask(i + 1)) != 0);
                 }
             }
             // When window is grabbed, all events are dispatched to
--- a/jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java	Mon Dec 17 16:58:56 2012 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java	Mon Dec 17 17:43:21 2012 +0100
@@ -396,4 +396,14 @@
         return isShapingSupported.booleanValue();
     }
 
+    static int getButtonMask(int button) {
+        // Button indices start with 1. The first bit in the button mask is the 8th.
+        // The state mask does not support button indicies > 5, so we need to
+        // cut there.
+        if (button <= 0 || button > XConstants.MAX_BUTTONS) {
+            return 0;
+        } else {
+            return 1 << (7 + button);
+        }
+    }
 }