diff --git a/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java b/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java index ba4ed50b9613bc4bd86b7f214cd202ab1ce568d9..72ca1b7aebe6dc820c935d29d019b5e371d85b5e 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java @@ -994,10 +994,7 @@ public class XBaseWindow { 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 @@ public class XBaseWindow { * 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); } } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XConstants.java b/jdk/src/solaris/classes/sun/awt/X11/XConstants.java index 725bf6afb1a2df044b32341b1d7774727070a57d..d72ff07273bf55c9893d23bce5e8145b9fd7eb20 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XConstants.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XConstants.java @@ -130,6 +130,9 @@ final public class XConstants { 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 @@ final public class XConstants { 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 */ diff --git a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java index 4084ca4b24e33819b48508ab7d8975957b75a38a..7c40e8260efba0a7990b84e2c5d543ba9e0a4b5d 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java @@ -1543,6 +1543,10 @@ public final class XToolkit extends UNIXToolkit implements Runnable { } } + 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."; diff --git a/jdk/src/solaris/classes/sun/awt/X11/XWindow.java b/jdk/src/solaris/classes/sun/awt/X11/XWindow.java index 0eebbd45c9ac123c05dcbfbc32a84a7c72351d59..e4d0ec6a68d6bb0e69b45e6e226b0f5a07d9c1ee 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XWindow.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XWindow.java @@ -596,12 +596,12 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { /* 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 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { 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 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { 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 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { /* 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 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { //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)); } } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java index a6af2e776d2867ebf3277aec818ced5f06671590..4d8671755976d76563c1c4ea12ba024f9245ea83 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java @@ -2070,12 +2070,12 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, } 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 diff --git a/jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java b/jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java index b5cc9739a582a7575eddb19e4dc58c11731c24ed..875ab16f6420a0a2da3be801998a3ecc6f863cb7 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java @@ -396,4 +396,14 @@ public class XlibUtil 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); + } + } }