jdk/src/solaris/native/sun/awt/awt_Robot.c
author yan
Thu, 19 Jun 2008 11:26:54 +0400
changeset 1175 026b52c440fe
parent 2 90ce3da70b43
child 1962 6c293d33645b
permissions -rw-r--r--
6706121: makefile: unnecessary Motif classes compilation in JDK7 Summary: removed 80 obsolete .c and .java files, temporary modified some more Reviewed-by: denis
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
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;
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
static void getNumButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    int32_t major_opcode, first_event, first_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    int32_t xinputAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    int32_t numDevices, devIdx, clsIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    XDeviceInfo* devices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    XDeviceInfo* aDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    XButtonInfo* bInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /* 4700242:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * If XTest is asked to press a non-existant mouse button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * (i.e. press Button3 on a system configured with a 2-button mouse),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * then a crash may happen.  To avoid this, we use the XInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * extension to query for the number of buttons on the XPointer, and check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * before calling XTestFakeButtonEvent().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    xinputAvailable = XQueryExtension(awt_display, INAME, &major_opcode, &first_event, &first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    major_opcode, first_event, first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    if (xinputAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        devices = XListInputDevices(awt_display, &numDevices);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        for (devIdx = 0; devIdx < numDevices; devIdx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            aDevice = &(devices[devIdx]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            if (aDevice->use == IsXPointer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                        bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                        num_buttons = bInfo->num_buttons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        XFreeDeviceList(devices);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
static XImage *getWindowImage(Display * display, Window window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                              int32_t x, int32_t y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                              int32_t w, int32_t h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    XImage         *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    int32_t        transparentOverlays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    int32_t        numVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    XVisualInfo    *pVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    int32_t        numOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    OverlayInfo    *pOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    int32_t        numImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    XVisualInfo    **pImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    list_ptr       vis_regions;    /* list of regions to read from */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    list_ptr       vis_image_regions ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    int32_t        allImage = 0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    int32_t        format = ZPixmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /* prevent user from moving stuff around during the capture */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    XGrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * The following two functions live in multiVis.c-- they are pretty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * much verbatim taken from the source to the xwd utility from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * X11 source. This version of the xwd source was somewhat better written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * for reuse compared to Sun's version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *        ftp.x.org/pub/R6.3/xc/programs/xwd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * We use these functions since they do the very tough job of capturing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * the screen correctly when it contains multiple visuals. They take into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * account the depth/colormap of each visual and produce a capture as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * 24-bit RGB image so we don't have to fool around with colormaps etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    GetMultiVisualRegions(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        &transparentOverlays,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        &numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        &pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        &numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        &pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        &numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        &pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        &vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        &vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        &allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    image = ReadAreaToImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /* allow user to do stuff again */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    XUngrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /* make sure the grab/ungrab is flushed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    XSync(display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
}
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
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   208
Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    int32_t xtestAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    DTRACE_PRINTLN("RobotPeer: setup()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    xtestAvailable = isXTestAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    if (!xtestAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        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
   219
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    getNumButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   229
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                             jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                             jobject xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                             jint x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                             jint y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                             jint width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                             jint height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                             jintArray pixelArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    XImage *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    jint *ary;               /* Array of jints for sending pixel values back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                              * to parent process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                              */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    Window rootWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, x, y, width, height, pixelArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /* avoid a lot of work for empty rectangles */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    if ((width * height) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    DASSERT(width * height > 0); /* only allow positive size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    DASSERT(adata != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    image = getWindowImage(awt_display, rootWindow, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /* Array to use to crunch around the pixel values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    ary = (jint *) malloc(width * height * sizeof (jint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    if (ary == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        XDestroyImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /* convert to Java ARGB pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    for (y = 0; y < height; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        for (x = 0; x < width; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            jint pixel = (jint) XGetPixel(image, x, y); /* Note ignore upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                                         * 32-bits on 64-bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                                         * OSes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            pixel |= 0xff000000; /* alpha - full opacity */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            ary[(y * width) + x] = pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    (*env)->SetIntArrayRegion(env, pixelArray, 0, height * width, ary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    free(ary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    XDestroyImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    AWT_UNLOCK();
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_keyPressImpl (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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                      True,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   312
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                           jint keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                      False,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   330
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                          jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                          jobject xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                          jint root_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                          jint root_y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    DASSERT(adata != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    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
   346
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   352
Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                           jint buttonMask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    DTRACE_PRINTLN1("RobotPeer: mousePressImpl(%i)", buttonMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    if (buttonMask & java_awt_event_InputEvent_BUTTON1_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        XTestFakeButtonEvent(awt_display, 1, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    if ((buttonMask & java_awt_event_InputEvent_BUTTON2_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        (num_buttons >= 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        XTestFakeButtonEvent(awt_display, 2, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    if ((buttonMask & java_awt_event_InputEvent_BUTTON3_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        (num_buttons >= 3)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        XTestFakeButtonEvent(awt_display, 3, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   376
Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                             jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                             jint buttonMask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    DTRACE_PRINTLN1("RobotPeer: mouseReleaseImpl(%i)", buttonMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    if (buttonMask & java_awt_event_InputEvent_BUTTON1_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        XTestFakeButtonEvent(awt_display, 1, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    if ((buttonMask & java_awt_event_InputEvent_BUTTON2_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        (num_buttons >= 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        XTestFakeButtonEvent(awt_display, 2, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    if ((buttonMask & java_awt_event_InputEvent_BUTTON3_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        (num_buttons >= 3)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        XTestFakeButtonEvent(awt_display, 3, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   400
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                           jint wheelAmt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
/* probably could have been hacked into robot_mouseButtonEvent, but it's */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
/* cleaner to give it its own command type, in case the implementation   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
/* needs to be changed later.  -bchristi, 6/20/01                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    int32_t repeat = abs(wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    int32_t button = wheelAmt < 0 ? 4 : 5;  /* wheel up:   button 4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                                                 /* wheel down: button 5 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    int32_t loopIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                                                     /* wheelAmt == 0    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        XTestFakeButtonEvent(awt_display, button, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        XTestFakeButtonEvent(awt_display, button, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
}