jdk/src/solaris/native/sun/awt/awt_Robot.c
author dav
Tue, 16 Sep 2008 12:17:02 +0400
changeset 1962 6c293d33645b
parent 1175 026b52c440fe
child 1965 726a2bc97146
permissions -rw-r--r--
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons Summary: implementation of the more mouse buttons support Reviewed-by: art, dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
    #error This file should not be included in headless library
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "awt_GraphicsEnv.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#define XK_MISCELLANY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <X11/keysymdef.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <X11/Intrinsic.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <X11/Xutil.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <X11/Xmd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <X11/extensions/xtestext1.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <X11/extensions/XTest.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <X11/extensions/XInput.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <X11/extensions/XI.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "robot_common.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "canvas.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "wsutils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "list.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include "multiVis.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
// 2 would be more correct, however that's how Robot originally worked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
// and tests start to fail if this value is changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
static int32_t num_buttons = 3;
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
    57
static jint * masks;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
static int32_t isXTestAvailable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int32_t major_opcode, first_event, first_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    int32_t  event_basep, error_basep, majorp, minorp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    int32_t isXTestAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /* check if XTest is available */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    isXTestAvailable = XQueryExtension(awt_display, XTestExtensionName, &major_opcode, &first_event, &first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XTEST) returns major_opcode = %d, first_event = %d, first_error = %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    major_opcode, first_event, first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    if (isXTestAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        /* check if XTest version is OK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        XTestQueryExtension(awt_display, &event_basep, &error_basep, &majorp, &minorp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        DTRACE_PRINTLN4("RobotPeer: XTestQueryExtension returns event_basep = %d, error_basep = %d, majorp = %d, minorp = %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                        event_basep, error_basep, majorp, minorp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (majorp < 2 || (majorp == 2 && minorp < 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            /* bad version*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            if (majorp == 2 && minorp == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                isXTestAvailable = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            /* allow XTest calls even if someone else has the grab; e.g. during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
             * a window resize operation. Works only with XTEST2.2*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            XTestGrabControl(awt_display, True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    return isXTestAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
static void getNumButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    int32_t major_opcode, first_event, first_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    int32_t xinputAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    int32_t numDevices, devIdx, clsIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    XDeviceInfo* devices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    XDeviceInfo* aDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    XButtonInfo* bInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /* 4700242:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * If XTest is asked to press a non-existant mouse button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * (i.e. press Button3 on a system configured with a 2-button mouse),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * then a crash may happen.  To avoid this, we use the XInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * extension to query for the number of buttons on the XPointer, and check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * before calling XTestFakeButtonEvent().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    xinputAvailable = XQueryExtension(awt_display, INAME, &major_opcode, &first_event, &first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    major_opcode, first_event, first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    if (xinputAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        devices = XListInputDevices(awt_display, &numDevices);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        for (devIdx = 0; devIdx < numDevices; devIdx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            aDevice = &(devices[devIdx]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            if (aDevice->use == IsXPointer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                        bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        num_buttons = bInfo->num_buttons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                        DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        XFreeDeviceList(devices);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
static XImage *getWindowImage(Display * display, Window window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                              int32_t x, int32_t y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                              int32_t w, int32_t h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    XImage         *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    int32_t        transparentOverlays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    int32_t        numVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    XVisualInfo    *pVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    int32_t        numOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    OverlayInfo    *pOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    int32_t        numImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    XVisualInfo    **pImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    list_ptr       vis_regions;    /* list of regions to read from */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    list_ptr       vis_image_regions ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    int32_t        allImage = 0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    int32_t        format = ZPixmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /* prevent user from moving stuff around during the capture */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    XGrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * The following two functions live in multiVis.c-- they are pretty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * much verbatim taken from the source to the xwd utility from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * X11 source. This version of the xwd source was somewhat better written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * for reuse compared to Sun's version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *        ftp.x.org/pub/R6.3/xc/programs/xwd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * We use these functions since they do the very tough job of capturing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * the screen correctly when it contains multiple visuals. They take into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * account the depth/colormap of each visual and produce a capture as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * 24-bit RGB image so we don't have to fool around with colormaps etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    GetMultiVisualRegions(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        &transparentOverlays,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        &numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        &pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        &numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        &pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        &numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        &pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        &vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        &vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        &allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    image = ReadAreaToImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /* allow user to do stuff again */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    XUngrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /* make sure the grab/ungrab is flushed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    XSync(display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
/*********************************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   209
Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    int32_t xtestAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   212
// this should be called from XRobotPeer constructor
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   213
    jclass inputEventClazz = (*env)->FindClass(env, "java/awt/event/InputEvent");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   214
    jmethodID getButtonDownMasksID = (*env)->GetStaticMethodID(env, inputEventClazz, "getButtonDownMasks", "()[I");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   215
    jintArray obj = (jintArray)(*env)->CallStaticObjectMethod(env, inputEventClazz, getButtonDownMasksID);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   216
    jsize len = (*env)->GetArrayLength(env, obj);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   217
    jint * tmp = (*env)->GetIntArrayElements(env, obj, JNI_FALSE);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   218
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   219
    masks  = (jint *)malloc(sizeof(jint)*len);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   220
    if (masks == (jint *) NULL) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   221
        JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   222
        goto finally;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   223
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   224
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   225
    int i;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   226
    for (i = 0; i < len; i++) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   227
        masks[i] = tmp[i];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   228
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   229
    (*env)->ReleaseIntArrayElements(env, obj, tmp, 0);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   230
    (*env)->DeleteLocalRef(env, obj);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   231
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    DTRACE_PRINTLN("RobotPeer: setup()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    xtestAvailable = isXTestAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    if (!xtestAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        JNU_ThrowByName(env, "java/awt/AWTException", "java.awt.Robot requires your X server support the XTEST extension version 2.2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    getNumButtons();
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   245
    finally:
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   246
    AWT_UNLOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   247
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   249
JNIEXPORT void JNICALL
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   250
Java_sun_awt_X11_XRobotPeer_getNumberOfButtonsImpl(JNIEnv *env,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   251
                                                   jclass cls) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   252
    // At the moment this routine being called we already should have an initialized num_buttons variable.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   253
    return num_buttons;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   257
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                             jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                             jobject xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                             jint x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                             jint y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                             jint width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                             jint height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                             jintArray pixelArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    XImage *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    jint *ary;               /* Array of jints for sending pixel values back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                              * to parent process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                              */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    Window rootWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, x, y, width, height, pixelArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /* avoid a lot of work for empty rectangles */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    if ((width * height) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    DASSERT(width * height > 0); /* only allow positive size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    DASSERT(adata != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    image = getWindowImage(awt_display, rootWindow, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /* Array to use to crunch around the pixel values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    ary = (jint *) malloc(width * height * sizeof (jint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    if (ary == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        XDestroyImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /* convert to Java ARGB pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    for (y = 0; y < height; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        for (x = 0; x < width; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            jint pixel = (jint) XGetPixel(image, x, y); /* Note ignore upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                                         * 32-bits on 64-bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                                         * OSes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            pixel |= 0xff000000; /* alpha - full opacity */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            ary[(y * width) + x] = pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    (*env)->SetIntArrayRegion(env, pixelArray, 0, height * width, ary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    free(ary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    XDestroyImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   320
Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                         jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                         jint keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                      True,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   340
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                           jint keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                      False,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   358
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                          jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                          jobject xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                          jint root_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                          jint root_y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    DASSERT(adata != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    XWarpPointer(awt_display, None, XRootWindow(awt_display, adata->awt_visInfo.screen), 0, 0, 0, 0, root_x, root_y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   380
Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                           jint buttonMask) {
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   383
    mouseAction(env, cls, buttonMask, True);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   384
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    DTRACE_PRINTLN1("RobotPeer: mousePressImpl(%i)", buttonMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    if (buttonMask & java_awt_event_InputEvent_BUTTON1_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        XTestFakeButtonEvent(awt_display, 1, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    if ((buttonMask & java_awt_event_InputEvent_BUTTON2_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        (num_buttons >= 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        XTestFakeButtonEvent(awt_display, 2, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    if ((buttonMask & java_awt_event_InputEvent_BUTTON3_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        (num_buttons >= 3)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        XTestFakeButtonEvent(awt_display, 3, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    AWT_UNLOCK();
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   403
*/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   407
Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                             jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                             jint buttonMask) {
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   410
    mouseAction(env, cls, buttonMask, False);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   411
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    DTRACE_PRINTLN1("RobotPeer: mouseReleaseImpl(%i)", buttonMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    if (buttonMask & java_awt_event_InputEvent_BUTTON1_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        XTestFakeButtonEvent(awt_display, 1, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    if ((buttonMask & java_awt_event_InputEvent_BUTTON2_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        (num_buttons >= 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        XTestFakeButtonEvent(awt_display, 2, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    if ((buttonMask & java_awt_event_InputEvent_BUTTON3_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        (num_buttons >= 3)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        XTestFakeButtonEvent(awt_display, 3, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    AWT_UNLOCK();
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   430
*/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   433
/*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   434
  * Function joining the code of mousePressImpl and mouseReleaseImpl
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   435
  */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   436
void mouseAction(JNIEnv *env,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   437
                 jclass cls,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   438
                 jint buttonMask,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   439
                 Bool isMousePress)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   440
{
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   441
    AWT_LOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   442
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   443
    DTRACE_PRINTLN1("RobotPeer: mouseAction(%i)", buttonMask);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   444
    DTRACE_PRINTLN1("RobotPeer: mouseAction, press = %d", isMousePress);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   445
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   446
    if (buttonMask & java_awt_event_InputEvent_BUTTON1_MASK ||
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   447
        buttonMask & java_awt_event_InputEvent_BUTTON1_DOWN_MASK )
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   448
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   449
        XTestFakeButtonEvent(awt_display, 1, isMousePress, CurrentTime);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   450
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   451
    if ((buttonMask & java_awt_event_InputEvent_BUTTON2_MASK ||
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   452
         buttonMask & java_awt_event_InputEvent_BUTTON2_DOWN_MASK) &&
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   453
        (num_buttons >= 2)) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   454
        XTestFakeButtonEvent(awt_display, 2, isMousePress, CurrentTime);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   455
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   456
    if ((buttonMask & java_awt_event_InputEvent_BUTTON3_MASK ||
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   457
         buttonMask & java_awt_event_InputEvent_BUTTON3_DOWN_MASK) &&
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   458
        (num_buttons >= 3)) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   459
        XTestFakeButtonEvent(awt_display, 3, isMousePress, CurrentTime);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   460
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   461
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   462
    if (num_buttons > 3){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   463
        int32_t i;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   464
        int32_t button = 0;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   465
        for (i = 3; i<num_buttons; i++){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   466
            if ((buttonMask & masks[i])) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   467
                // arrays starts from zero index => +1
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   468
                // users wants to affect 4 or 5 button but they are assigned
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   469
                // to the wheel so => we have to shift it to the right by 2.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   470
                button = i + 3;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   471
                XTestFakeButtonEvent(awt_display, button, isMousePress, CurrentTime);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   472
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   473
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   474
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   475
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   476
    XSync(awt_display, False);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   477
    AWT_UNLOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   478
}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   479
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   480
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   482
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                           jint wheelAmt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
/* probably could have been hacked into robot_mouseButtonEvent, but it's */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
/* cleaner to give it its own command type, in case the implementation   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
/* needs to be changed later.  -bchristi, 6/20/01                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    int32_t repeat = abs(wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    int32_t button = wheelAmt < 0 ? 4 : 5;  /* wheel up:   button 4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                                 /* wheel down: button 5 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    int32_t loopIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                                     /* wheelAmt == 0    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        XTestFakeButtonEvent(awt_display, button, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        XTestFakeButtonEvent(awt_display, button, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
}