jdk/src/solaris/native/sun/awt/awt_Robot.c
author dav
Fri, 22 May 2009 16:09:45 +0400
changeset 2810 fa49c6a06baf
parent 1965 726a2bc97146
child 3337 45c02b7c01b6
permissions -rw-r--r--
6799099: All automatic regression tests that create Robot fail on X11 Reviewed-by: art, ant
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
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1965
diff changeset
    54
extern int32_t getNumButtons();
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1965
diff changeset
    55
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
    56
static jint * masks;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
static int32_t isXTestAvailable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    int32_t major_opcode, first_event, first_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int32_t  event_basep, error_basep, majorp, minorp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    int32_t isXTestAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /* check if XTest is available */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    isXTestAvailable = XQueryExtension(awt_display, XTestExtensionName, &major_opcode, &first_event, &first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XTEST) returns major_opcode = %d, first_event = %d, first_error = %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    major_opcode, first_event, first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    if (isXTestAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        /* check if XTest version is OK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        XTestQueryExtension(awt_display, &event_basep, &error_basep, &majorp, &minorp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        DTRACE_PRINTLN4("RobotPeer: XTestQueryExtension returns event_basep = %d, error_basep = %d, majorp = %d, minorp = %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                        event_basep, error_basep, majorp, minorp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        if (majorp < 2 || (majorp == 2 && minorp < 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            /* bad version*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            if (majorp == 2 && minorp == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                isXTestAvailable = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            /* allow XTest calls even if someone else has the grab; e.g. during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
             * a window resize operation. Works only with XTEST2.2*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            XTestGrabControl(awt_display, True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    return isXTestAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
}
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 XImage *getWindowImage(Display * display, Window window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                              int32_t x, int32_t y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                              int32_t w, int32_t h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    XImage         *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    int32_t        transparentOverlays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    int32_t        numVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    XVisualInfo    *pVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    int32_t        numOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    OverlayInfo    *pOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    int32_t        numImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    XVisualInfo    **pImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    list_ptr       vis_regions;    /* list of regions to read from */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    list_ptr       vis_image_regions ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    int32_t        allImage = 0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    int32_t        format = ZPixmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /* prevent user from moving stuff around during the capture */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    XGrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * The following two functions live in multiVis.c-- they are pretty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * much verbatim taken from the source to the xwd utility from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * X11 source. This version of the xwd source was somewhat better written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * for reuse compared to Sun's version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *        ftp.x.org/pub/R6.3/xc/programs/xwd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * We use these functions since they do the very tough job of capturing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * the screen correctly when it contains multiple visuals. They take into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * account the depth/colormap of each visual and produce a capture as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * 24-bit RGB image so we don't have to fool around with colormaps etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    GetMultiVisualRegions(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        &transparentOverlays,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        &numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        &pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        &numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        &pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        &numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        &pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        &vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        &vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        &allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    image = ReadAreaToImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /* allow user to do stuff again */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    XUngrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /* make sure the grab/ungrab is flushed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    XSync(display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
/*********************************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   168
Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    int32_t xtestAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   171
// 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
   172
    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
   173
    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
   174
    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
   175
    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
   176
    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
   177
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   178
    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
   179
    if (masks == (jint *) NULL) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   180
        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
   181
        goto finally;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   182
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   183
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   184
    int i;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   185
    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
   186
        masks[i] = tmp[i];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   187
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   188
    (*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
   189
    (*env)->DeleteLocalRef(env, obj);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   190
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    DTRACE_PRINTLN("RobotPeer: setup()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    xtestAvailable = isXTestAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    if (!xtestAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        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
   199
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   203
    finally:
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   204
    AWT_UNLOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   205
}
2
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_getRGBPixelsImpl( JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                             jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                             jobject xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                             jint x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                             jint y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                             jint width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                             jint height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                             jintArray pixelArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    XImage *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    jint *ary;               /* Array of jints for sending pixel values back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                              * to parent process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                              */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    Window rootWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, x, y, width, height, pixelArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /* avoid a lot of work for empty rectangles */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    if ((width * height) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    DASSERT(width * height > 0); /* only allow positive size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    DASSERT(adata != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    image = getWindowImage(awt_display, rootWindow, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /* Array to use to crunch around the pixel values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    ary = (jint *) malloc(width * height * sizeof (jint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    if (ary == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        XDestroyImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /* convert to Java ARGB pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    for (y = 0; y < height; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        for (x = 0; x < width; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            jint pixel = (jint) XGetPixel(image, x, y); /* Note ignore upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                                         * 32-bits on 64-bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                                         * OSes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            pixel |= 0xff000000; /* alpha - full opacity */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            ary[(y * width) + x] = pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    (*env)->SetIntArrayRegion(env, pixelArray, 0, height * width, ary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    free(ary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    XDestroyImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   272
Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                         jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                         jint keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                      True,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   292
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                           jint keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                      False,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   310
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                          jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                          jobject xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                          jint root_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                          jint root_y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    DASSERT(adata != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    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
   326
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   331
/*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   332
  * 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
   333
  */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   334
void mouseAction(JNIEnv *env,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   335
                 jclass cls,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   336
                 jint buttonMask,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   337
                 Bool isMousePress)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   338
{
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   339
    AWT_LOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   340
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1965
diff changeset
   341
    int32_t num_buttons = getNumButtons(); //from XToolkit.c
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1965
diff changeset
   342
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   343
    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
   344
    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
   345
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   346
    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
   347
        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
   348
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   349
        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
   350
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   351
    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
   352
         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
   353
        (num_buttons >= 2)) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   354
        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
   355
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   356
    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
   357
         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
   358
        (num_buttons >= 3)) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   359
        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
   360
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   361
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   362
    if (num_buttons > 3){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   363
        int32_t i;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   364
        int32_t button = 0;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   365
        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
   366
            if ((buttonMask & masks[i])) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   367
                // 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
   368
                // 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
   369
                // 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
   370
                button = i + 3;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   371
                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
   372
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   373
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   374
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   375
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   376
    XSync(awt_display, False);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   377
    AWT_UNLOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   378
}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   379
1965
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   380
JNIEXPORT void JNICALL
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   381
Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   382
                           jclass cls,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   383
                           jint buttonMask) {
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   384
    mouseAction(env, cls, buttonMask, True);
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   385
}
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   386
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   387
JNIEXPORT void JNICALL
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   388
Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   389
                             jclass cls,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   390
                             jint buttonMask) {
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   391
    mouseAction(env, cls, buttonMask, False);
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   392
}
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   393
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   395
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                           jint wheelAmt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
/* probably could have been hacked into robot_mouseButtonEvent, but it's */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
/* cleaner to give it its own command type, in case the implementation   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
/* needs to be changed later.  -bchristi, 6/20/01                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    int32_t repeat = abs(wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    int32_t button = wheelAmt < 0 ? 4 : 5;  /* wheel up:   button 4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                                 /* wheel down: button 5 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    int32_t loopIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                                     /* wheelAmt == 0    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        XTestFakeButtonEvent(awt_display, button, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        XTestFakeButtonEvent(awt_display, button, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
}