jdk/src/solaris/native/sun/awt/awt_Robot.c
changeset 2810 fa49c6a06baf
parent 1965 726a2bc97146
child 3337 45c02b7c01b6
--- a/jdk/src/solaris/native/sun/awt/awt_Robot.c	Thu May 21 15:04:23 2009 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_Robot.c	Fri May 22 16:09:45 2009 +0400
@@ -51,9 +51,8 @@
 
 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
 
-// 2 would be more correct, however that's how Robot originally worked
-// and tests start to fail if this value is changed
-static int32_t num_buttons = 3;
+extern int32_t getNumButtons();
+
 static jint * masks;
 
 static int32_t isXTestAvailable() {
@@ -90,46 +89,6 @@
     return isXTestAvailable;
 }
 
-static void getNumButtons() {
-    int32_t major_opcode, first_event, first_error;
-    int32_t xinputAvailable;
-    int32_t numDevices, devIdx, clsIdx;
-    XDeviceInfo* devices;
-    XDeviceInfo* aDevice;
-    XButtonInfo* bInfo;
-
-    /* 4700242:
-     * If XTest is asked to press a non-existant mouse button
-     * (i.e. press Button3 on a system configured with a 2-button mouse),
-     * then a crash may happen.  To avoid this, we use the XInput
-     * extension to query for the number of buttons on the XPointer, and check
-     * before calling XTestFakeButtonEvent().
-     */
-    xinputAvailable = XQueryExtension(awt_display, INAME, &major_opcode, &first_event, &first_error);
-    DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d",
-                    major_opcode, first_event, first_error);
-    if (xinputAvailable) {
-        devices = XListInputDevices(awt_display, &numDevices);
-        for (devIdx = 0; devIdx < numDevices; devIdx++) {
-            aDevice = &(devices[devIdx]);
-            if (aDevice->use == IsXPointer) {
-                for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) {
-                    if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
-                        bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
-                        num_buttons = bInfo->num_buttons;
-                        DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons);
-                        break;
-                    }
-                }
-                break;
-            }
-        }
-        XFreeDeviceList(devices);
-    }
-    else {
-        DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons);
-    }
-}
 
 static XImage *getWindowImage(Display * display, Window window,
                               int32_t x, int32_t y,
@@ -241,17 +200,10 @@
         return;
     }
 
-    getNumButtons();
     finally:
     AWT_UNLOCK();
 }
 
-JNIEXPORT jint JNICALL
-Java_sun_awt_X11_XRobotPeer_getNumberOfButtonsImpl(JNIEnv *env,
-                                                   jclass cls) {
-    // At the moment this routine being called we already should have an initialized num_buttons variable.
-    return num_buttons;
-}
 
 JNIEXPORT void JNICALL
 Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
@@ -386,6 +338,8 @@
 {
     AWT_LOCK();
 
+    int32_t num_buttons = getNumButtons(); //from XToolkit.c
+
     DTRACE_PRINTLN1("RobotPeer: mouseAction(%i)", buttonMask);
     DTRACE_PRINTLN1("RobotPeer: mouseAction, press = %d", isMousePress);