jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_Robot.c
author prr
Fri, 15 Apr 2016 10:25:11 -0700
changeset 37699 c3d9835483f9
parent 34395 2ac7e99f7f4a
child 37711 972001566d66
permissions -rw-r--r--
8154269: Remove unused or unnecessary Xm/Xt files and header includes Reviewed-by: serb, ssadetsky
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/Xutil.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <X11/Xmd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <X11/extensions/xtestext1.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <X11/extensions/XTest.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <X11/extensions/XInput.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <X11/extensions/XI.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <jni.h>
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 12047
diff changeset
    41
#include <sizecalc.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "robot_common.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "canvas.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "wsutils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "list.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "multiVis.h"
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
    47
#include "gtk2_interface.h"
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
    48
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
    49
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
    55
static jint * masks;
3337
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
    56
static jint num_buttons;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
static int32_t isXTestAvailable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    int32_t major_opcode, first_event, first_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int32_t  event_basep, error_basep, majorp, minorp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    int32_t isXTestAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /* check if XTest is available */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    isXTestAvailable = XQueryExtension(awt_display, XTestExtensionName, &major_opcode, &first_event, &first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XTEST) returns major_opcode = %d, first_event = %d, first_error = %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    major_opcode, first_event, first_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    if (isXTestAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        /* check if XTest version is OK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        XTestQueryExtension(awt_display, &event_basep, &error_basep, &majorp, &minorp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        DTRACE_PRINTLN4("RobotPeer: XTestQueryExtension returns event_basep = %d, error_basep = %d, majorp = %d, minorp = %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                        event_basep, error_basep, majorp, minorp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        if (majorp < 2 || (majorp == 2 && minorp < 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            /* bad version*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            if (majorp == 2 && minorp == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                isXTestAvailable = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            /* allow XTest calls even if someone else has the grab; e.g. during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
             * a window resize operation. Works only with XTEST2.2*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            XTestGrabControl(awt_display, True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    return isXTestAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
static XImage *getWindowImage(Display * display, Window window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                              int32_t x, int32_t y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                              int32_t w, int32_t h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    XImage         *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    int32_t        transparentOverlays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    int32_t        numVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    XVisualInfo    *pVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    int32_t        numOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    OverlayInfo    *pOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    int32_t        numImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    XVisualInfo    **pImageVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    list_ptr       vis_regions;    /* list of regions to read from */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    list_ptr       vis_image_regions ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    int32_t        allImage = 0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    int32_t        format = ZPixmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /* prevent user from moving stuff around during the capture */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    XGrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * The following two functions live in multiVis.c-- they are pretty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * much verbatim taken from the source to the xwd utility from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * X11 source. This version of the xwd source was somewhat better written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * for reuse compared to Sun's version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *        ftp.x.org/pub/R6.3/xc/programs/xwd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * We use these functions since they do the very tough job of capturing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * the screen correctly when it contains multiple visuals. They take into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * account the depth/colormap of each visual and produce a capture as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * 24-bit RGB image so we don't have to fool around with colormaps etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    GetMultiVisualRegions(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        &transparentOverlays,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        &numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        &pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        &numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        &pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        &numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        &pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        &vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        &vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        &allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    image = ReadAreaToImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        numVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        numOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        pImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        vis_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        vis_image_regions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        allImage );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /* allow user to do stuff again */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    XUngrabServer(display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /* make sure the grab/ungrab is flushed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    XSync(display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
/*********************************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
3337
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   167
// this should be called from XRobotPeer constructor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
JNIEXPORT void JNICALL
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   169
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
   170
{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    int32_t xtestAvailable;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   172
    jint *tmp;
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   173
    int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
3337
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   175
    DTRACE_PRINTLN("RobotPeer: setup()");
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   176
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   177
    num_buttons = numberOfButtons;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   178
    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
   179
    CHECK_NULL(tmp);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
   180
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 12047
diff changeset
   181
    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
   182
    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
   183
        (*env)->ExceptionClear(env);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
   184
        (*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
   185
        JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL);
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   186
        return;
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   187
    }
3337
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
   188
    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
   189
        masks[i] = tmp[i];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   190
    }
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   191
    (*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
   192
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    xtestAvailable = isXTestAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    if (!xtestAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        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
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   200
    AWT_UNLOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   201
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   205
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                             jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                             jobject xgc,
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   208
                             jint jx,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   209
                             jint jy,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   210
                             jint jwidth,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   211
                             jint jheight,
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   212
                             jint scale,
32282
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
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   234
    jint sx = jx * scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   235
    jint sy = jy * scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   236
    jint swidth = jwidth * scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   237
    jint sheight = jheight * scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   238
9660
73dd0c7a8658 7043455: Taking a screenshot may fail on X11 after 6903034
anthony
parents: 8949
diff changeset
   239
    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   241
    if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   242
            || sx + swidth <= attr.x
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   243
            || attr.x + attr.width <= sx
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   244
            || sy + sheight <= attr.y
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   245
            || attr.y + attr.height <= sy) {
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   246
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        AWT_UNLOCK();
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   248
        return; // Does not intersect with root window
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   250
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   251
    gboolean gtk_failed = TRUE;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   252
    jint _x, _y;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   253
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   254
    jint x = MAX(sx, attr.x);
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   255
    jint y = MAX(sy, attr.y);
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   256
    jint width = MIN(sx + swidth, attr.x + attr.width) - x;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   257
    jint height = MIN(sy + sheight, attr.y + attr.height) - y;
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   258
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   259
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   260
    int dx = attr.x > sx ? attr.x - sx : 0;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   261
    int dy = attr.y > sy ? attr.y - sy : 0;
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   262
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   263
    int index;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   264
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   265
    if (isGtkSupported) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   266
        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
   267
        (*fp_gdk_threads_enter)();
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   268
        GdkWindow *root = (*fp_gdk_get_default_root_window)();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   269
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   270
        pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(NULL, root, NULL,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   271
                                                    x, y, 0, 0, width, height);
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   272
        if (pixbuf && scale != 1) {
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   273
            GdkPixbuf *scaledPixbuf;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   274
            x /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   275
            y /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   276
            width /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   277
            height /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   278
            dx /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   279
            dy /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   280
            scaledPixbuf = (*fp_gdk_pixbuf_scale_simple)(pixbuf, width, height,
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   281
                                                         GDK_INTERP_BILINEAR);
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   282
            (*fp_g_object_unref)(pixbuf);
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   283
            pixbuf = scaledPixbuf;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   284
        }
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   285
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   286
        if (pixbuf) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   287
            int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   288
            int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   290
            if ((*fp_gdk_pixbuf_get_width)(pixbuf) == width
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   291
                    && (*fp_gdk_pixbuf_get_height)(pixbuf) == height
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   292
                    && (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   293
                    && (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   294
                    && nchan >= 3
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   295
                    ) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   296
                guchar *p, *pix = (*fp_gdk_pixbuf_get_pixels)(pixbuf);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   297
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   298
                ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   299
                if (!ary) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   300
                    (*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
   301
                    (*fp_gdk_threads_leave)();
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   302
                    AWT_UNLOCK();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   303
                    return;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   304
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   306
                for (_y = 0; _y < height; _y++) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   307
                    for (_x = 0; _x < width; _x++) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   308
                        p = pix + _y * stride + _x * nchan;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   309
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   310
                        index = (_y + dy) * jwidth + (_x + dx);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   311
                        ary[index] = 0xff000000
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   312
                                        | (p[0] << 16)
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   313
                                        | (p[1] << 8)
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   314
                                        | (p[2]);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   315
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   316
                    }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   317
                }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   318
                (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   319
                if ((*env)->ExceptionCheck(env)) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   320
                    (*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
   321
                    (*fp_gdk_threads_leave)();
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   322
                    AWT_UNLOCK();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   323
                    return;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   324
                }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   325
                gtk_failed = FALSE;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   326
            }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   327
            (*fp_g_object_unref)(pixbuf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
32297
1f709146c4cb 8134028: [PIT] XToolkit, strange behavior of robot.createScreenCapture(): looks like a native crash in X11/GTK
azvegint
parents: 32282
diff changeset
   329
        (*fp_gdk_threads_leave)();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   331
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   332
    if (gtk_failed) {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   333
        image = getWindowImage(awt_display, rootWindow, sx, sy, swidth, sheight);
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   334
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   335
        ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   336
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   337
        if (!ary) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   338
            XDestroyImage(image);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   339
            AWT_UNLOCK();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   340
            return;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   341
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   343
        dx /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   344
        dy /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   345
        width /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   346
        height /= scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   347
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   348
        /* convert to Java ARGB pixels */
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   349
        for (_y = 0; _y < height; _y++) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   350
            for (_x = 0; _x < width; _x++) {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   351
                jint pixel = (jint) XGetPixel(image, _x * scale, _y * scale);
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32297
diff changeset
   352
                                                              /* Note ignore upper
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   353
                                                               * 32-bits on 64-bit
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   354
                                                               * OSes.
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   355
                                                               */
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   356
                pixel |= 0xff000000; /* alpha - full opacity */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   358
                index = (_y + dy) * jwidth + (_x + dx);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   359
                ary[index] = pixel;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   360
            }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   361
        }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   362
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   363
        XDestroyImage(image);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   364
        (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 26751
diff changeset
   365
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   370
Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                         jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                         jint keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                      True,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   390
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                           jint keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    XTestFakeKeyEvent(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                      False,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                      CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   408
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                          jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                          jobject xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                          jint root_x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                          jint root_y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    DASSERT(adata != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    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
   424
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   429
/*
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   430
  * 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
   431
  */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   432
void mouseAction(JNIEnv *env,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   433
                 jclass cls,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   434
                 jint buttonMask,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   435
                 Bool isMousePress)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   436
{
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   437
    AWT_LOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   438
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   439
    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
   440
    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
   441
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   442
    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
   443
        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
   444
    {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   445
        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
   446
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   447
    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
   448
         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
   449
        (num_buttons >= 2)) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   450
        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
   451
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   452
    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
   453
         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
   454
        (num_buttons >= 3)) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   455
        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
   456
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   457
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   458
    if (num_buttons > 3){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   459
        int32_t i;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   460
        int32_t button = 0;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   461
        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
   462
            if ((buttonMask & masks[i])) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   463
                // 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
   464
                // 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
   465
                // 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
   466
                button = i + 3;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   467
                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
   468
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   469
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   470
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   471
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   472
    XSync(awt_display, False);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   473
    AWT_UNLOCK();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   474
}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   475
1965
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   476
JNIEXPORT void JNICALL
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   477
Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   478
                           jclass cls,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   479
                           jint buttonMask) {
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   480
    mouseAction(env, cls, buttonMask, True);
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   481
}
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   482
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   483
JNIEXPORT void JNICALL
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   484
Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   485
                             jclass cls,
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   486
                             jint buttonMask) {
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   487
    mouseAction(env, cls, buttonMask, False);
726a2bc97146 6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents: 1962
diff changeset
   488
}
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1175
diff changeset
   489
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
JNIEXPORT void JNICALL
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
   491
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                           jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                           jint wheelAmt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
/* probably could have been hacked into robot_mouseButtonEvent, but it's */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
/* cleaner to give it its own command type, in case the implementation   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
/* needs to be changed later.  -bchristi, 6/20/01                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    int32_t repeat = abs(wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    int32_t button = wheelAmt < 0 ? 4 : 5;  /* wheel up:   button 4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                                 /* wheel down: button 5 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    int32_t loopIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                                     /* wheelAmt == 0    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        XTestFakeButtonEvent(awt_display, button, True, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        XTestFakeButtonEvent(awt_display, button, False, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
}