--- old/src/solaris/classes/sun/awt/X11/XBaseWindow.java 2012-12-10 20:46:44.152064901 +0100 +++ new/src/solaris/classes/sun/awt/X11/XBaseWindow.java 2012-12-10 20:46:43.927065576 +0100 @@ -994,10 +994,7 @@ return; } int buttonState = 0; - final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons(); - for (int i = 0; i buttonsNumber) { return buttonState == 0; } else { - return buttonState == XConstants.buttonsMask[button - 1]; + return buttonState == XlibUtil.getButtonMask(button); } } --- old/src/solaris/classes/sun/awt/X11/XConstants.java 2012-12-10 20:46:44.742065370 +0100 +++ new/src/solaris/classes/sun/awt/X11/XConstants.java 2012-12-10 20:46:44.529065454 +0100 @@ -130,6 +130,9 @@ public static final long ColormapChangeMask = (1L<<23) ; public static final long OwnerGrabButtonMask = (1L<<24) ; + public static final int MAX_BUTTON_MASK = 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 */ --- old/src/solaris/classes/sun/awt/X11/XToolkit.java 2012-12-10 20:46:45.237047214 +0100 +++ new/src/solaris/classes/sun/awt/X11/XToolkit.java 2012-12-10 20:46:45.024065583 +0100 @@ -1543,6 +1543,10 @@ } } + static int getNumberOfButtonsForMask() { + return Math.min(XConstants.MAX_BUTTON_MASK, ((SunToolkit) (Toolkit.getDefaultToolkit())).getNumberOfButtons()); + } + private final static String prefix = "DnD.Cursor."; private final static String postfix = ".32x32"; private static final String dndPrefix = "DnD."; --- old/src/solaris/classes/sun/awt/X11/XWindow.java 2012-12-10 20:46:45.739064659 +0100 +++ new/src/solaris/classes/sun/awt/X11/XWindow.java 2012-12-10 20:46:45.542002810 +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)); } } --- old/src/solaris/classes/sun/awt/X11/XWindowPeer.java 2012-12-10 20:46:46.118002226 +0100 +++ new/src/solaris/classes/sun/awt/X11/XWindowPeer.java 2012-12-10 20:46:45.980127319 +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 --- old/src/solaris/classes/sun/awt/X11/XlibUtil.java 2012-12-10 20:46:46.476064800 +0100 +++ new/src/solaris/classes/sun/awt/X11/XlibUtil.java 2012-12-10 20:46:46.343064789 +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_BUTTON_MASK) { + return 0; + } else { + return 1 << (7 + button); + } + } }