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