jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_Robot.c
author azvegint
Fri, 21 Aug 2015 10:43:47 -0700
changeset 32297 1f709146c4cb
parent 32282 9c9ff2c42e0d
child 34395 2ac7e99f7f4a
permissions -rw-r--r--
8134028: [PIT] XToolkit, strange behavior of robot.createScreenCapture(): looks like a native crash in X11/GTK Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
     2
 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3337
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3337
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3337
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3337
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3337
diff changeset
    23
 * questions.
2
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_GraphicsEnv.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#define XK_MISCELLANY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <X11/keysymdef.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <X11/Intrinsic.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <X11/Xutil.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <X11/Xmd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <X11/extensions/xtestext1.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <X11/extensions/XTest.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <X11/extensions/XInput.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <X11/extensions/XI.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <jni.h>
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 12047
diff changeset
    42
#include <sizecalc.h>
2
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"
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
    48
#include "gtk2_interface.h"
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
    49
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
    50
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
90ce3da70b43 Initial load
duke
parents:
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;
3337
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
    57
static jint num_buttons;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
static XImage *getWindowImage(Display * display, Window window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                              int32_t x, int32_t y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                              int32_t w, int32_t h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    XImage         *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    int32_t        transparentOverlays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    int32_t        numVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    XVisualInfo    *pVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    int32_t        numOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    OverlayInfo    *pOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    int32_t        numImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    XVisualInfo    **pImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    list_ptr       vis_regions;    /* list of regions to read from */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    list_ptr       vis_image_regions ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    int32_t        allImage = 0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    int32_t        format = ZPixmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /* prevent user from moving stuff around during the capture */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    XGrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * The following two functions live in multiVis.c-- they are pretty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * much verbatim taken from the source to the xwd utility from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * X11 source. This version of the xwd source was somewhat better written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * for reuse compared to Sun's version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *        ftp.x.org/pub/R6.3/xc/programs/xwd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * We use these functions since they do the very tough job of capturing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * the screen correctly when it contains multiple visuals. They take into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * account the depth/colormap of each visual and produce a capture as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * 24-bit RGB image so we don't have to fool around with colormaps etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    GetMultiVisualRegions(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        &transparentOverlays,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        &numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        &pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        &numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        &pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        &numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        &pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        &vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        &vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        &allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    image = ReadAreaToImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /* allow user to do stuff again */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    XUngrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /* make sure the grab/ungrab is flushed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    XSync(display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    return image;
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
3337
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   168
// this should be called from XRobotPeer constructor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
JNIEXPORT void JNICALL
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   170
Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls, jint numberOfButtons, jintArray buttonDownMasks)
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   171
{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    int32_t xtestAvailable;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   173
    jint *tmp;
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   174
    int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
3337
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   176
    DTRACE_PRINTLN("RobotPeer: setup()");
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   177
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   178
    num_buttons = numberOfButtons;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   179
    tmp = (*env)->GetIntArrayElements(env, buttonDownMasks, JNI_FALSE);
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
   180
    CHECK_NULL(tmp);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
   181
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 12047
diff changeset
   182
    masks = (jint *)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(jint), num_buttons);
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   183
    if (masks == (jint *) NULL) {
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
   184
        (*env)->ExceptionClear(env);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
   185
        (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0);
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   186
        JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL);
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   187
        return;
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   188
    }
3337
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   189
    for (i = 0; i < num_buttons; i++) {
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   190
        masks[i] = tmp[i];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   191
    }
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   192
    (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0);
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   193
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    AWT_LOCK();
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   201
    AWT_UNLOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   202
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   206
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                             jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                             jobject xgc,
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   209
                             jint jx,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   210
                             jint jy,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   211
                             jint jwidth,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   212
                             jint jheight,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   213
                             jintArray pixelArray,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   214
                             jboolean isGtkSupported) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    XImage *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    jint *ary;               /* Array of jints for sending pixel values back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                              * to parent process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                              */
9660
73dd0c7a8658 7043455: Taking a screenshot may fail on X11 after 6903034
anthony
parents: 8949
diff changeset
   219
    Window rootWindow;
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   220
    XWindowAttributes attr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   223
    DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, jx, jy, jwidth, jheight, pixelArray);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   225
    if (jwidth <= 0 || jheight <= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    DASSERT(adata != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   232
    AWT_LOCK();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   233
9660
73dd0c7a8658 7043455: Taking a screenshot may fail on X11 after 6903034
anthony
parents: 8949
diff changeset
   234
    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   236
    if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   237
            || jx + jwidth <= attr.x
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   238
            || attr.x + attr.width <= jx
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   239
            || jy + jheight <= attr.y
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   240
            || attr.y + attr.height <= jy) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   241
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        AWT_UNLOCK();
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   243
        return; // Does not intersect with root window
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   245
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   246
    gboolean gtk_failed = TRUE;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   247
    jint _x, _y;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   248
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   249
    jint x = MAX(jx, attr.x);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   250
    jint y = MAX(jy, attr.y);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   251
    jint width = MIN(jx + jwidth, attr.x + attr.width) - x;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   252
    jint height = MIN(jy + jheight, attr.y + attr.height) - y;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   253
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   254
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   255
    int dx = attr.x > jx ? attr.x - jx : 0;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   256
    int dy = attr.y > jy ? attr.y - jy : 0;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   257
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   258
    int index;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   259
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   260
    if (isGtkSupported) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   261
        GdkPixbuf *pixbuf;
32297
1f709146c4cb 8134028: [PIT] XToolkit, strange behavior of robot.createScreenCapture(): looks like a native crash in X11/GTK
azvegint
parents: 32282
diff changeset
   262
        (*fp_gdk_threads_enter)();
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   263
        GdkWindow *root = (*fp_gdk_get_default_root_window)();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   264
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   265
        pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(NULL, root, NULL,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   266
                                                    x, y, 0, 0, width, height);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   267
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   268
        if (pixbuf) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   269
            int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   270
            int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   272
            if ((*fp_gdk_pixbuf_get_width)(pixbuf) == width
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   273
                    && (*fp_gdk_pixbuf_get_height)(pixbuf) == height
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   274
                    && (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   275
                    && (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   276
                    && nchan >= 3
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   277
                    ) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   278
                guchar *p, *pix = (*fp_gdk_pixbuf_get_pixels)(pixbuf);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   279
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   280
                ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   281
                if (!ary) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   282
                    (*fp_g_object_unref)(pixbuf);
32297
1f709146c4cb 8134028: [PIT] XToolkit, strange behavior of robot.createScreenCapture(): looks like a native crash in X11/GTK
azvegint
parents: 32282
diff changeset
   283
                    (*fp_gdk_threads_leave)();
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   284
                    AWT_UNLOCK();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   285
                    return;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   286
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   288
                for (_y = 0; _y < height; _y++) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   289
                    for (_x = 0; _x < width; _x++) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   290
                        p = pix + _y * stride + _x * nchan;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   291
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   292
                        index = (_y + dy) * jwidth + (_x + dx);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   293
                        ary[index] = 0xff000000
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   294
                                        | (p[0] << 16)
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   295
                                        | (p[1] << 8)
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   296
                                        | (p[2]);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   297
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   298
                    }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   299
                }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   300
                (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   301
                if ((*env)->ExceptionCheck(env)) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   302
                    (*fp_g_object_unref)(pixbuf);
32297
1f709146c4cb 8134028: [PIT] XToolkit, strange behavior of robot.createScreenCapture(): looks like a native crash in X11/GTK
azvegint
parents: 32282
diff changeset
   303
                    (*fp_gdk_threads_leave)();
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   304
                    AWT_UNLOCK();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   305
                    return;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   306
                }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   307
                gtk_failed = FALSE;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   308
            }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   309
            (*fp_g_object_unref)(pixbuf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
32297
1f709146c4cb 8134028: [PIT] XToolkit, strange behavior of robot.createScreenCapture(): looks like a native crash in X11/GTK
azvegint
parents: 32282
diff changeset
   311
        (*fp_gdk_threads_leave)();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   313
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   314
    if (gtk_failed) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   315
        image = getWindowImage(awt_display, rootWindow, x, y, width, height);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   316
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   317
        ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   318
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   319
        if (!ary) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   320
            XDestroyImage(image);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   321
            AWT_UNLOCK();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   322
            return;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   323
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   325
        /* convert to Java ARGB pixels */
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   326
        for (_y = 0; _y < height; _y++) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   327
            for (_x = 0; _x < width; _x++) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   328
                jint pixel = (jint) XGetPixel(image, _x, _y); /* Note ignore upper
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   329
                                                               * 32-bits on 64-bit
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   330
                                                               * OSes.
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   331
                                                               */
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   332
                pixel |= 0xff000000; /* alpha - full opacity */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   334
                index = (_y + dy) * jwidth + (_x + dx);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   335
                ary[index] = pixel;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   336
            }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   337
        }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   338
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   339
        XDestroyImage(image);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   340
        (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   341
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   346
Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                         jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                         jint keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                      True,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   366
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                           jint keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                      False,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   384
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                          jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                          jobject xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                          jint root_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                          jint root_y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    DASSERT(adata != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    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
   400
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   405
/*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   406
  * 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
   407
  */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   408
void mouseAction(JNIEnv *env,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   409
                 jclass cls,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   410
                 jint buttonMask,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   411
                 Bool isMousePress)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   412
{
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   413
    AWT_LOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   414
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   415
    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
   416
    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
   417
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   418
    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
   419
        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
   420
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   421
        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
   422
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   423
    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
   424
         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
   425
        (num_buttons >= 2)) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   426
        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
   427
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   428
    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
   429
         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
   430
        (num_buttons >= 3)) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   431
        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
   432
    }
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
    if (num_buttons > 3){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   435
        int32_t i;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   436
        int32_t button = 0;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   437
        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
   438
            if ((buttonMask & masks[i])) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   439
                // 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
   440
                // 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
   441
                // 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
   442
                button = i + 3;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   443
                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
   444
            }
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
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   447
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   448
    XSync(awt_display, False);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   449
    AWT_UNLOCK();
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
1965
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   452
JNIEXPORT void JNICALL
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   453
Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   454
                           jclass cls,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   455
                           jint buttonMask) {
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   456
    mouseAction(env, cls, buttonMask, True);
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   457
}
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   458
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   459
JNIEXPORT void JNICALL
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   460
Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   461
                             jclass cls,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   462
                             jint buttonMask) {
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   463
    mouseAction(env, cls, buttonMask, False);
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   464
}
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   465
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   467
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                           jint wheelAmt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
/* probably could have been hacked into robot_mouseButtonEvent, but it's */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
/* cleaner to give it its own command type, in case the implementation   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
/* needs to be changed later.  -bchristi, 6/20/01                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    int32_t repeat = abs(wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    int32_t button = wheelAmt < 0 ? 4 : 5;  /* wheel up:   button 4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                                 /* wheel down: button 5 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    int32_t loopIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                                     /* wheelAmt == 0    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        XTestFakeButtonEvent(awt_display, button, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        XTestFakeButtonEvent(awt_display, button, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
}