1.1 --- a/make/sun/xawt/mapfile-vers Thu May 21 15:04:23 2009 +0400
1.2 +++ b/make/sun/xawt/mapfile-vers Fri May 22 16:09:45 2009 +0400
1.3 @@ -155,7 +155,7 @@
1.4 Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl;
1.5 Java_sun_awt_X11_XRobotPeer_mouseWheelImpl;
1.6 Java_sun_awt_X11_XRobotPeer_setup;
1.7 - Java_sun_awt_X11_XRobotPeer_getNumberOfButtonsImpl;
1.8 + Java_sun_awt_X11_XToolkit_getNumberOfButtonsImpl;
1.9 Java_java_awt_Component_initIDs;
1.10 Java_java_awt_Container_initIDs;
1.11 Java_java_awt_Button_initIDs;
2.1 --- a/src/share/classes/java/awt/Robot.java Thu May 21 15:04:23 2009 +0400
2.2 +++ b/src/share/classes/java/awt/Robot.java Fri May 22 16:09:45 2009 +0400
2.3 @@ -96,9 +96,13 @@
2.4 init(GraphicsEnvironment.getLocalGraphicsEnvironment()
2.5 .getDefaultScreenDevice());
2.6 int tmpMask = 0;
2.7 +
2.8 if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
2.9 - for (int i = 0; i < peer.getNumberOfButtons(); i++){
2.10 - tmpMask |= InputEvent.getMaskForButton(i+1);
2.11 + if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
2.12 + final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
2.13 + for (int i = 0; i < buttonsNumber; i++){
2.14 + tmpMask |= InputEvent.getMaskForButton(i+1);
2.15 + }
2.16 }
2.17 }
2.18 tmpMask |= InputEvent.BUTTON1_MASK|
3.1 --- a/src/share/classes/java/awt/event/InputEvent.java Thu May 21 15:04:23 2009 +0400
3.2 +++ b/src/share/classes/java/awt/event/InputEvent.java Fri May 22 16:09:45 2009 +0400
3.3 @@ -157,6 +157,8 @@
3.4 /**
3.5 * An array of extended modifiers for additional buttons.
3.6 * @see getButtonDownMasks
3.7 + * There are twenty buttons fit into 4byte space.
3.8 + * one more bit is reserved for FIRST_HIGH_BIT.
3.9 * @since 7.0
3.10 */
3.11 private static final int [] BUTTON_DOWN_MASK = new int [] { BUTTON1_DOWN_MASK,
3.12 @@ -169,7 +171,16 @@
3.13 1<<18,
3.14 1<<19,
3.15 1<<20,
3.16 - 1<<21 };
3.17 + 1<<21,
3.18 + 1<<22,
3.19 + 1<<23,
3.20 + 1<<24,
3.21 + 1<<25,
3.22 + 1<<26,
3.23 + 1<<27,
3.24 + 1<<28,
3.25 + 1<<29,
3.26 + 1<<30};
3.27
3.28 /**
3.29 * A method to access an array of extended modifiers for additional buttons.
3.30 @@ -240,7 +251,7 @@
3.31 // in fact, it is undesirable to add modifier bits
3.32 // to the same field as this may break applications
3.33 // see bug# 5066958
3.34 - static final int FIRST_HIGH_BIT = 1 << 22;
3.35 + static final int FIRST_HIGH_BIT = 1 << 31;
3.36
3.37 static final int JDK_1_3_MODIFIERS = SHIFT_DOWN_MASK - 1;
3.38 static final int HIGH_MODIFIERS = ~( FIRST_HIGH_BIT - 1 );
4.1 --- a/src/share/classes/java/awt/event/MouseEvent.java Thu May 21 15:04:23 2009 +0400
4.2 +++ b/src/share/classes/java/awt/event/MouseEvent.java Fri May 22 16:09:45 2009 +0400
4.3 @@ -33,6 +33,7 @@
4.4 import java.io.ObjectInputStream;
4.5 import java.awt.IllegalComponentStateException;
4.6 import java.awt.MouseInfo;
4.7 +import sun.awt.SunToolkit;
4.8
4.9 /**
4.10 * An event which indicates that a mouse action occurred in a component.
4.11 @@ -379,12 +380,25 @@
4.12 */
4.13 private static final long serialVersionUID = -991214153494842848L;
4.14
4.15 + /**
4.16 + * A number of buttons available on the mouse at the {@code Toolkit} machinery startup.
4.17 + */
4.18 + private static int cachedNumberOfButtons;
4.19 +
4.20 static {
4.21 /* ensure that the necessary native libraries are loaded */
4.22 NativeLibLoader.loadLibraries();
4.23 if (!GraphicsEnvironment.isHeadless()) {
4.24 initIDs();
4.25 }
4.26 + final Toolkit tk = Toolkit.getDefaultToolkit();
4.27 + if (tk instanceof SunToolkit) {
4.28 + cachedNumberOfButtons = ((SunToolkit)tk).getNumberOfButtons();
4.29 + } else {
4.30 + //It's expected that some toolkits (Headless,
4.31 + //whatever besides SunToolkit) could also operate.
4.32 + cachedNumberOfButtons = 3;
4.33 + }
4.34 }
4.35
4.36 /**
4.37 @@ -412,15 +426,6 @@
4.38 }
4.39
4.40 /**
4.41 - * A number of buttons available on the mouse at the {@code Toolkit} machinery startup.
4.42 - */
4.43 - private static int cachedNumberOfButtons;
4.44 -
4.45 - static {
4.46 - cachedNumberOfButtons = MouseInfo.getNumberOfButtons();
4.47 - }
4.48 -
4.49 - /**
4.50 * Returns the absolute horizontal x position of the event.
4.51 * In a virtual device multi-screen environment in which the
4.52 * desktop area could span multiple physical screen devices,
4.53 @@ -735,7 +740,6 @@
4.54 if (button < NOBUTTON){
4.55 throw new IllegalArgumentException("Invalid button value :" + button);
4.56 }
4.57 - //TODO: initialize MouseInfo.cachedNumber on toolkit creation.
4.58 if (button > BUTTON3) {
4.59 if (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
4.60 throw new IllegalArgumentException("Extra mouse events are disabled " + button);
5.1 --- a/src/share/classes/java/awt/peer/RobotPeer.java Thu May 21 15:04:23 2009 +0400
5.2 +++ b/src/share/classes/java/awt/peer/RobotPeer.java Fri May 22 16:09:45 2009 +0400
5.3 @@ -121,11 +121,4 @@
5.4 * Disposes the robot peer when it is not needed anymore.
5.5 */
5.6 void dispose();
5.7 -
5.8 - /**
5.9 - * Returns the number of buttons that the robot simulates.
5.10 - *
5.11 - * @return the number of buttons that the robot simulates
5.12 - */
5.13 - int getNumberOfButtons();
5.14 }
6.1 --- a/src/share/classes/sun/awt/SunToolkit.java Thu May 21 15:04:23 2009 +0400
6.2 +++ b/src/share/classes/sun/awt/SunToolkit.java Fri May 22 16:09:45 2009 +0400
6.3 @@ -89,6 +89,25 @@
6.4 */
6.5 private static final String POST_EVENT_QUEUE_KEY = "PostEventQueue";
6.6
6.7 + /**
6.8 + * Number of buttons.
6.9 + * By default it's taken from the system. If system value does not
6.10 + * fit into int type range, use our own MAX_BUTTONS_SUPPORT value.
6.11 + */
6.12 + protected static int numberOfButtons = 0;
6.13 +
6.14 +
6.15 + /* XFree standard mention 24 buttons as maximum:
6.16 + * http://www.xfree86.org/current/mouse.4.html
6.17 + * We workaround systems supporting more than 24 buttons.
6.18 + * Otherwise, we have to use long type values as masks
6.19 + * which leads to API change.
6.20 + * InputEvent.BUTTON_DOWN_MASK may contain only 21 masks due to
6.21 + * the 4-bytes limit for the int type. (CR 6799099)
6.22 + * One more bit is reserved for FIRST_HIGH_BIT.
6.23 + */
6.24 + public final static int MAX_BUTTONS_SUPPORTED = 20;
6.25 +
6.26 public SunToolkit() {
6.27 /* If awt.threadgroup is set to class name the instance of
6.28 * this class is created (should be subclass of ThreadGroup)
6.29 @@ -2079,6 +2098,12 @@
6.30 return false;
6.31 }
6.32
6.33 + /**
6.34 + * Descendants of the SunToolkit should override and put their own logic here.
6.35 + */
6.36 + public int getNumberOfButtons(){
6.37 + return 3;
6.38 + }
6.39 } // class SunToolkit
6.40
6.41
7.1 --- a/src/solaris/classes/sun/awt/X11/XBaseWindow.java Thu May 21 15:04:23 2009 +0400
7.2 +++ b/src/solaris/classes/sun/awt/X11/XBaseWindow.java Fri May 22 16:09:45 2009 +0400
7.3 @@ -989,8 +989,17 @@
7.4 */
7.5 public void handleButtonPressRelease(XEvent xev) {
7.6 XButtonEvent xbe = xev.get_xbutton();
7.7 + /*
7.8 + * Ignore the buttons above 20 due to the bit limit for
7.9 + * InputEvent.BUTTON_DOWN_MASK.
7.10 + * One more bit is reserved for FIRST_HIGH_BIT.
7.11 + */
7.12 + if (xbe.get_button() > SunToolkit.MAX_BUTTONS_SUPPORTED) {
7.13 + return;
7.14 + }
7.15 int buttonState = 0;
7.16 - for (int i = 0; i<XToolkit.getNumMouseButtons(); i++){
7.17 + final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
7.18 + for (int i = 0; i<buttonsNumber; i++){
7.19 // A bug in WM implementation: extra buttons doesn't have state!=0 as they should on Release message.
7.20 if ((i != 4) && (i != 5)){
7.21 buttonState |= (xbe.get_state() & XConstants.buttonsMask[i]);
7.22 @@ -1026,7 +1035,9 @@
7.23 * Checks ButtonRelease released all Mouse buttons
7.24 */
7.25 static boolean isFullRelease(int buttonState, int button) {
7.26 - if (button < 0 || button > XToolkit.getNumMouseButtons()) {
7.27 + final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
7.28 +
7.29 + if (button < 0 || button > buttonsNumber) {
7.30 return buttonState == 0;
7.31 } else {
7.32 return buttonState == XConstants.buttonsMask[button - 1];
8.1 --- a/src/solaris/classes/sun/awt/X11/XDragSourceContextPeer.java Thu May 21 15:04:23 2009 +0400
8.2 +++ b/src/solaris/classes/sun/awt/X11/XDragSourceContextPeer.java Fri May 22 16:09:45 2009 +0400
8.3 @@ -42,6 +42,7 @@
8.4
8.5 import sun.awt.dnd.SunDragSourceContextPeer;
8.6 import sun.awt.dnd.SunDropTargetContextPeer;
8.7 +import sun.awt.SunToolkit;
8.8
8.9 /**
8.10 * The XDragSourceContextPeer class is the class responsible for handling
8.11 @@ -666,6 +667,15 @@
8.12 case XConstants.ButtonRelease: {
8.13 XButtonEvent xbutton = ev.get_xbutton();
8.14 /*
8.15 + * Ignore the buttons above 20 due to the bit limit for
8.16 + * InputEvent.BUTTON_DOWN_MASK.
8.17 + * One more bit is reserved for FIRST_HIGH_BIT.
8.18 + */
8.19 + if (xbutton.get_button() > SunToolkit.MAX_BUTTONS_SUPPORTED) {
8.20 + return true;
8.21 + }
8.22 +
8.23 + /*
8.24 * On some X servers it could happen that ButtonRelease coordinates
8.25 * differ from the latest MotionNotify coordinates, so we need to
8.26 * process it as a mouse motion.
9.1 --- a/src/solaris/classes/sun/awt/X11/XRobotPeer.java Thu May 21 15:04:23 2009 +0400
9.2 +++ b/src/solaris/classes/sun/awt/X11/XRobotPeer.java Fri May 22 16:09:45 2009 +0400
9.3 @@ -81,16 +81,11 @@
9.4 return pixelArray;
9.5 }
9.6
9.7 - public int getNumberOfButtons(){
9.8 - return getNumberOfButtonsImpl();
9.9 - }
9.10 -
9.11 private static native synchronized void setup();
9.12
9.13 private static native synchronized void mouseMoveImpl(X11GraphicsConfig xgc, int x, int y);
9.14 private static native synchronized void mousePressImpl(int buttons);
9.15 private static native synchronized void mouseReleaseImpl(int buttons);
9.16 - private static native synchronized int getNumberOfButtonsImpl();
9.17 private static native synchronized void mouseWheelImpl(int wheelAmt);
9.18
9.19 private static native synchronized void keyPressImpl(int keycode);
10.1 --- a/src/solaris/classes/sun/awt/X11/XToolkit.java Thu May 21 15:04:23 2009 +0400
10.2 +++ b/src/solaris/classes/sun/awt/X11/XToolkit.java Fri May 22 16:09:45 2009 +0400
10.3 @@ -85,21 +85,6 @@
10.4 private static boolean areExtraMouseButtonsEnabled = true;
10.5
10.6 /**
10.7 - * Number of buttons.
10.8 - * By default it's taken from the system. If system value does not
10.9 - * fit into int type range, use our own MAX_BUTTONS_SUPPORT value.
10.10 - */
10.11 - private static int numberOfButtons = 0;
10.12 -
10.13 - /* XFree standard mention 24 buttons as maximum:
10.14 - * http://www.xfree86.org/current/mouse.4.html
10.15 - * We workaround systems supporting more than 24 buttons.
10.16 - * Otherwise, we have to use long type values as masks
10.17 - * which leads to API change.
10.18 - */
10.19 - private static int MAX_BUTTONS_SUPPORT = 24;
10.20 -
10.21 - /**
10.22 * True when the x settings have been loaded.
10.23 */
10.24 private boolean loadedXSettings;
10.25 @@ -1458,19 +1443,26 @@
10.26 desktopProperties.put("awt.multiClickInterval",
10.27 Integer.valueOf(getMultiClickTime()));
10.28 desktopProperties.put("awt.mouse.numButtons",
10.29 - Integer.valueOf(getNumMouseButtons()));
10.30 + Integer.valueOf(getNumberOfButtons()));
10.31 }
10.32 }
10.33
10.34 - public static int getNumMouseButtons() {
10.35 + /**
10.36 + * This method runs through the XPointer and XExtendedPointer array.
10.37 + * XExtendedPointer has priority because on some systems XPointer
10.38 + * (which is assigned to the virtual pointer) reports the maximum
10.39 + * capabilities of the mouse pointer (i.e. 32 physical buttons).
10.40 + */
10.41 + private native synchronized int getNumberOfButtonsImpl();
10.42 +
10.43 + @Override
10.44 + public int getNumberOfButtons(){
10.45 awtLock();
10.46 try {
10.47 if (numberOfButtons == 0) {
10.48 - numberOfButtons = Math.min(
10.49 - XlibWrapper.XGetPointerMapping(XToolkit.getDisplay(), 0, 0),
10.50 - MAX_BUTTONS_SUPPORT);
10.51 + numberOfButtons = getNumberOfButtonsImpl();
10.52 }
10.53 - return numberOfButtons;
10.54 + return (numberOfButtons > MAX_BUTTONS_SUPPORTED)? MAX_BUTTONS_SUPPORTED : numberOfButtons;
10.55 } finally {
10.56 awtUnlock();
10.57 }
11.1 --- a/src/solaris/classes/sun/awt/X11/XWindow.java Thu May 21 15:04:23 2009 +0400
11.2 +++ b/src/solaris/classes/sun/awt/X11/XWindow.java Fri May 22 16:09:45 2009 +0400
11.3 @@ -677,6 +677,14 @@
11.4 int button=0;
11.5 boolean wheel_mouse = false;
11.6 int lbutton = xbe.get_button();
11.7 + /*
11.8 + * Ignore the buttons above 20 due to the bit limit for
11.9 + * InputEvent.BUTTON_DOWN_MASK.
11.10 + * One more bit is reserved for FIRST_HIGH_BIT.
11.11 + */
11.12 + if (lbutton > SunToolkit.MAX_BUTTONS_SUPPORTED) {
11.13 + return;
11.14 + }
11.15 int type = xev.get_type();
11.16 when = xbe.get_time();
11.17 long jWhen = XToolkit.nowMillisUTC_offset(when);
11.18 @@ -795,8 +803,9 @@
11.19 //this doesn't work for extra buttons because Xsystem is sending state==0 for every extra button event.
11.20 // we can't correct it in MouseEvent class as we done it with modifiers, because exact type (DRAG|MOVE)
11.21 // should be passed from XWindow.
11.22 - //TODO: eliminate it with some other value obtained w/o AWTLock.
11.23 - for (int i = 0; i < XToolkit.getNumMouseButtons(); i++){
11.24 + final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
11.25 +
11.26 + for (int i = 0; i < buttonsNumber; i++){
11.27 // TODO : here is the bug in WM: extra buttons doesn't have state!=0 as they should.
11.28 if ((i != 4) && (i != 5)) {
11.29 mouseKeyState = mouseKeyState | (xme.get_state() & XConstants.buttonsMask[i]);
12.1 --- a/src/solaris/classes/sun/awt/X11/XWindowPeer.java Thu May 21 15:04:23 2009 +0400
12.2 +++ b/src/solaris/classes/sun/awt/X11/XWindowPeer.java Fri May 22 16:09:45 2009 +0400
12.3 @@ -1894,7 +1894,9 @@
12.4 }
12.5 if (isGrabbed()) {
12.6 boolean dragging = false;
12.7 - for (int i = 0; i<XToolkit.getNumMouseButtons(); i++){
12.8 + final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
12.9 +
12.10 + for (int i = 0; i < buttonsNumber; i++){
12.11 // here is the bug in WM: extra buttons doesn't have state!=0 as they should.
12.12 if ((i != 4) && (i != 5)){
12.13 dragging = dragging || ((xme.get_state() & XConstants.buttonsMask[i]) != 0);
12.14 @@ -1940,6 +1942,15 @@
12.15
12.16 public void handleButtonPressRelease(XEvent xev) {
12.17 XButtonEvent xbe = xev.get_xbutton();
12.18 +
12.19 + /*
12.20 + * Ignore the buttons above 20 due to the bit limit for
12.21 + * InputEvent.BUTTON_DOWN_MASK.
12.22 + * One more bit is reserved for FIRST_HIGH_BIT.
12.23 + */
12.24 + if (xbe.get_button() > SunToolkit.MAX_BUTTONS_SUPPORTED) {
12.25 + return;
12.26 + }
12.27 if (grabLog.isLoggable(Level.FINE)) {
12.28 grabLog.log(Level.FINE, "{0}, when grabbed {1}, contains {2} ({3}, {4}, {5}x{6})",
12.29 new Object[] {xbe, isGrabbed(), containsGlobal(xbe.get_x_root(), xbe.get_y_root()), getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight()});
13.1 --- a/src/solaris/classes/sun/awt/motif/MToolkit.java Thu May 21 15:04:23 2009 +0400
13.2 +++ b/src/solaris/classes/sun/awt/motif/MToolkit.java Fri May 22 16:09:45 2009 +0400
13.3 @@ -1,5 +1,5 @@
13.4 /*
13.5 - * Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved.
13.6 + * Copyright 1995-2009 Sun Microsystems, Inc. All Rights Reserved.
13.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13.8 *
13.9 * This code is free software; you can redistribute it and/or modify it
13.10 @@ -624,7 +624,6 @@
13.11 }
13.12
13.13 private native int getMulticlickTime();
13.14 - private native int getNumMouseButtons();
13.15
13.16 protected void initializeDesktopProperties() {
13.17 desktopProperties.put("DnD.Autoscroll.initialDelay", Integer.valueOf(50));
13.18 @@ -643,7 +642,7 @@
13.19 desktopProperties.put("awt.multiClickInterval",
13.20 Integer.valueOf(getMulticlickTime()));
13.21 desktopProperties.put("awt.mouse.numButtons",
13.22 - Integer.valueOf(getNumMouseButtons()));
13.23 + Integer.valueOf(getNumberOfButtons()));
13.24 }
13.25 }
13.26
14.1 --- a/src/solaris/native/sun/awt/awt_MToolkit.c Thu May 21 15:04:23 2009 +0400
14.2 +++ b/src/solaris/native/sun/awt/awt_MToolkit.c Fri May 22 16:09:45 2009 +0400
14.3 @@ -3168,21 +3168,6 @@
14.4
14.5 /*
14.6 * Class: sun_awt_motif_MToolkit
14.7 - * Method: getNumMouseButtons
14.8 - * Signature: ()I
14.9 - */
14.10 -JNIEXPORT jint JNICALL Java_sun_awt_motif_MToolkit_getNumMouseButtons
14.11 - (JNIEnv *env, jobject this)
14.12 -{
14.13 - jint res = 0;
14.14 - AWT_LOCK();
14.15 - res = XGetPointerMapping(awt_display, NULL, 0);
14.16 - AWT_UNLOCK();
14.17 - return res;
14.18 -}
14.19 -
14.20 -/*
14.21 - * Class: sun_awt_motif_MToolkit
14.22 * Method: loadXSettings
14.23 * Signature: ()V
14.24 */
15.1 --- a/src/solaris/native/sun/awt/awt_Robot.c Thu May 21 15:04:23 2009 +0400
15.2 +++ b/src/solaris/native/sun/awt/awt_Robot.c Fri May 22 16:09:45 2009 +0400
15.3 @@ -51,9 +51,8 @@
15.4
15.5 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
15.6
15.7 -// 2 would be more correct, however that's how Robot originally worked
15.8 -// and tests start to fail if this value is changed
15.9 -static int32_t num_buttons = 3;
15.10 +extern int32_t getNumButtons();
15.11 +
15.12 static jint * masks;
15.13
15.14 static int32_t isXTestAvailable() {
15.15 @@ -90,46 +89,6 @@
15.16 return isXTestAvailable;
15.17 }
15.18
15.19 -static void getNumButtons() {
15.20 - int32_t major_opcode, first_event, first_error;
15.21 - int32_t xinputAvailable;
15.22 - int32_t numDevices, devIdx, clsIdx;
15.23 - XDeviceInfo* devices;
15.24 - XDeviceInfo* aDevice;
15.25 - XButtonInfo* bInfo;
15.26 -
15.27 - /* 4700242:
15.28 - * If XTest is asked to press a non-existant mouse button
15.29 - * (i.e. press Button3 on a system configured with a 2-button mouse),
15.30 - * then a crash may happen. To avoid this, we use the XInput
15.31 - * extension to query for the number of buttons on the XPointer, and check
15.32 - * before calling XTestFakeButtonEvent().
15.33 - */
15.34 - xinputAvailable = XQueryExtension(awt_display, INAME, &major_opcode, &first_event, &first_error);
15.35 - DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d",
15.36 - major_opcode, first_event, first_error);
15.37 - if (xinputAvailable) {
15.38 - devices = XListInputDevices(awt_display, &numDevices);
15.39 - for (devIdx = 0; devIdx < numDevices; devIdx++) {
15.40 - aDevice = &(devices[devIdx]);
15.41 - if (aDevice->use == IsXPointer) {
15.42 - for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) {
15.43 - if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
15.44 - bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
15.45 - num_buttons = bInfo->num_buttons;
15.46 - DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons);
15.47 - break;
15.48 - }
15.49 - }
15.50 - break;
15.51 - }
15.52 - }
15.53 - XFreeDeviceList(devices);
15.54 - }
15.55 - else {
15.56 - DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons);
15.57 - }
15.58 -}
15.59
15.60 static XImage *getWindowImage(Display * display, Window window,
15.61 int32_t x, int32_t y,
15.62 @@ -241,17 +200,10 @@
15.63 return;
15.64 }
15.65
15.66 - getNumButtons();
15.67 finally:
15.68 AWT_UNLOCK();
15.69 }
15.70
15.71 -JNIEXPORT jint JNICALL
15.72 -Java_sun_awt_X11_XRobotPeer_getNumberOfButtonsImpl(JNIEnv *env,
15.73 - jclass cls) {
15.74 - // At the moment this routine being called we already should have an initialized num_buttons variable.
15.75 - return num_buttons;
15.76 -}
15.77
15.78 JNIEXPORT void JNICALL
15.79 Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
15.80 @@ -386,6 +338,8 @@
15.81 {
15.82 AWT_LOCK();
15.83
15.84 + int32_t num_buttons = getNumButtons(); //from XToolkit.c
15.85 +
15.86 DTRACE_PRINTLN1("RobotPeer: mouseAction(%i)", buttonMask);
15.87 DTRACE_PRINTLN1("RobotPeer: mouseAction, press = %d", isMousePress);
15.88
16.1 --- a/src/solaris/native/sun/xawt/XToolkit.c Thu May 21 15:04:23 2009 +0400
16.2 +++ b/src/solaris/native/sun/xawt/XToolkit.c Fri May 22 16:09:45 2009 +0400
16.3 @@ -45,10 +45,14 @@
16.4 #include "sun_awt_X11_XToolkit.h"
16.5 #include "java_awt_SystemColor.h"
16.6 #include "java_awt_TrayIcon.h"
16.7 +#include <X11/extensions/XTest.h>
16.8
16.9 uint32_t awt_NumLockMask = 0;
16.10 Boolean awt_ModLockIsShiftLock = False;
16.11
16.12 +static int32_t num_buttons = 0;
16.13 +int32_t getNumButtons();
16.14 +
16.15 extern JavaVM *jvm;
16.16
16.17 // Tracing level
16.18 @@ -908,3 +912,78 @@
16.19 AWT_UNLOCK();
16.20 }
16.21 }
16.22 +
16.23 +
16.24 +/*
16.25 + * Class: sun_awt_X11_XToolkit
16.26 + * Method: getNumberOfButtonsImpl
16.27 + * Signature: ()I
16.28 + */
16.29 +JNIEXPORT jint JNICALL Java_sun_awt_X11_XToolkit_getNumberOfButtonsImpl
16.30 +(JNIEnv * env, jobject cls){
16.31 + if (num_buttons == 0) {
16.32 + num_buttons = getNumButtons();
16.33 + }
16.34 + return num_buttons;
16.35 +}
16.36 +
16.37 +int32_t getNumButtons() {
16.38 + int32_t major_opcode, first_event, first_error;
16.39 + int32_t xinputAvailable;
16.40 + int32_t numDevices, devIdx, clsIdx;
16.41 + XDeviceInfo* devices;
16.42 + XDeviceInfo* aDevice;
16.43 + XButtonInfo* bInfo;
16.44 + int32_t local_num_buttons = 0;
16.45 +
16.46 + /* 4700242:
16.47 + * If XTest is asked to press a non-existant mouse button
16.48 + * (i.e. press Button3 on a system configured with a 2-button mouse),
16.49 + * then a crash may happen. To avoid this, we use the XInput
16.50 + * extension to query for the number of buttons on the XPointer, and check
16.51 + * before calling XTestFakeButtonEvent().
16.52 + */
16.53 + xinputAvailable = XQueryExtension(awt_display, INAME, &major_opcode, &first_event, &first_error);
16.54 + DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d",
16.55 + major_opcode, first_event, first_error);
16.56 + if (xinputAvailable) {
16.57 + devices = XListInputDevices(awt_display, &numDevices);
16.58 + for (devIdx = 0; devIdx < numDevices; devIdx++) {
16.59 + aDevice = &(devices[devIdx]);
16.60 + if (aDevice->use == IsXExtensionPointer) {
16.61 + for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) {
16.62 + if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
16.63 + bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
16.64 + local_num_buttons = bInfo->num_buttons;
16.65 + DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons);
16.66 + break;
16.67 + }
16.68 + }
16.69 + break;
16.70 + }
16.71 + if (local_num_buttons <= 0 ) {
16.72 + if (aDevice->use == IsXPointer) {
16.73 + for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) {
16.74 + if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
16.75 + bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
16.76 + local_num_buttons = bInfo->num_buttons;
16.77 + DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons);
16.78 + break;
16.79 + }
16.80 + }
16.81 + break;
16.82 + }
16.83 + }
16.84 + }
16.85 +
16.86 + XFreeDeviceList(devices);
16.87 + }
16.88 + else {
16.89 + DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons);
16.90 + }
16.91 + if (local_num_buttons == 0 ) {
16.92 + local_num_buttons = 3;
16.93 + }
16.94 +
16.95 + return local_num_buttons;
16.96 +}
17.1 --- a/src/windows/classes/sun/awt/windows/WRobotPeer.java Thu May 21 15:04:23 2009 +0400
17.2 +++ b/src/windows/classes/sun/awt/windows/WRobotPeer.java Fri May 22 16:09:45 2009 +0400
17.3 @@ -60,8 +60,6 @@
17.4 }
17.5 public native int getRGBPixelImpl(int x, int y);
17.6
17.7 - public native int getNumberOfButtons();
17.8 -
17.9 public int [] getRGBPixels(Rectangle bounds) {
17.10 int pixelArray[] = new int[bounds.width*bounds.height];
17.11 getRGBPixels(bounds.x, bounds.y, bounds.width, bounds.height, pixelArray);
18.1 --- a/src/windows/classes/sun/awt/windows/WToolkit.java Thu May 21 15:04:23 2009 +0400
18.2 +++ b/src/windows/classes/sun/awt/windows/WToolkit.java Fri May 22 16:09:45 2009 +0400
18.3 @@ -982,6 +982,16 @@
18.4 return areExtraMouseButtonsEnabled;
18.5 }
18.6
18.7 + private native synchronized int getNumberOfButtonsImpl();
18.8 +
18.9 + @Override
18.10 + public int getNumberOfButtons(){
18.11 + if (numberOfButtons == 0) {
18.12 + numberOfButtons = getNumberOfButtonsImpl();
18.13 + }
18.14 + return (numberOfButtons > MAX_BUTTONS_SUPPORTED)? MAX_BUTTONS_SUPPORTED : numberOfButtons;
18.15 + }
18.16 +
18.17 @Override
18.18 public boolean isWindowOpacitySupported() {
18.19 // supported in Win2K and later
19.1 --- a/src/windows/native/sun/windows/awt_Robot.cpp Thu May 21 15:04:23 2009 +0400
19.2 +++ b/src/windows/native/sun/windows/awt_Robot.cpp Fri May 22 16:09:45 2009 +0400
19.3 @@ -437,9 +437,3 @@
19.4
19.5 CATCH_BAD_ALLOC;
19.6 }
19.7 -
19.8 -JNIEXPORT jint JNICALL Java_sun_awt_windows_WRobotPeer_getNumberOfButtons(
19.9 - JNIEnv *, jobject self)
19.10 -{
19.11 - return GetSystemMetrics(SM_CMOUSEBUTTONS);
19.12 -}
20.1 --- a/src/windows/native/sun/windows/awt_Toolkit.cpp Thu May 21 15:04:23 2009 +0400
20.2 +++ b/src/windows/native/sun/windows/awt_Toolkit.cpp Fri May 22 16:09:45 2009 +0400
20.3 @@ -2259,3 +2259,8 @@
20.4 void AwtToolkit::setExtraMouseButtonsEnabled(BOOL enable) {
20.5 m_areExtraMouseButtonsEnabled = enable;
20.6 }
20.7 +
20.8 +JNIEXPORT jint JNICALL Java_sun_awt_windows_WToolkit_getNumberOfButtonsImpl
20.9 +(JNIEnv *, jobject self) {
20.10 + return GetSystemMetrics(SM_CMOUSEBUTTONS);
20.11 +}