jdk/src/java.desktop/unix/classes/sun/awt/X11/XRobotPeer.java
author prr
Sat, 19 Sep 2015 15:45:59 -0700
changeset 32865 f9cb6e427f9e
parent 32282 9c9ff2c42e0d
child 34395 2ac7e99f7f4a
permissions -rw-r--r--
8136783: Run blessed-modifier-order script on java.desktop Reviewed-by: martin, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
     2
 * Copyright (c) 2003, 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
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.peer.*;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    29
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    30
import sun.awt.AWTAccessor;
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    31
import sun.awt.SunToolkit;
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    32
import sun.awt.UNIXToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.awt.X11GraphicsConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
class XRobotPeer implements RobotPeer {
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    36
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    37
    private static volatile boolean isGtkSupported;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private X11GraphicsConfig   xgc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * native implementation uses some static shared data (pipes, processes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * so use a class lock to synchronize native method calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static Object robotLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    XRobotPeer(GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        this.xgc = (X11GraphicsConfig)gc;
3337
45c02b7c01b6 6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents: 2810
diff changeset
    47
        SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    48
        setup(tk.getNumberOfButtons(),
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    49
                AWTAccessor.getInputEventAccessor().getButtonDownMasks());
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    50
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    51
        Toolkit toolkit = Toolkit.getDefaultToolkit();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    52
        if (!isGtkSupported) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    53
            if (toolkit instanceof UNIXToolkit
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    54
                    && ((UNIXToolkit) toolkit).loadGTK()) {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    55
                isGtkSupported = true;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    56
            }
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    57
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    60
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public void dispose() {
9660
73dd0c7a8658 7043455: Taking a screenshot may fail on X11 after 6903034
anthony
parents: 8949
diff changeset
    62
        // does nothing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    65
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public void mouseMove(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        mouseMoveImpl(xgc, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    70
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public void mousePress(int buttons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        mousePressImpl(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    75
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public void mouseRelease(int buttons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        mouseReleaseImpl(buttons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    80
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public void mouseWheel(int wheelAmt) {
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    82
        mouseWheelImpl(wheelAmt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    85
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public void keyPress(int keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        keyPressImpl(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    90
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public void keyRelease(int keycode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        keyReleaseImpl(keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    95
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public int getRGBPixel(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        int pixelArray[] = new int[1];
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
    98
        getRGBPixelsImpl(xgc, x, y, 1, 1, pixelArray, isGtkSupported);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return pixelArray[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
   102
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public int [] getRGBPixels(Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        int pixelArray[] = new int[bounds.width*bounds.height];
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
   105
        getRGBPixelsImpl(xgc, bounds.x, bounds.y, bounds.width, bounds.height,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
   106
                            pixelArray, isGtkSupported);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return pixelArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32282
diff changeset
   110
    private static synchronized native void setup(int numberOfButtons, int[] buttonDownMasks);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32282
diff changeset
   112
    private static synchronized native void mouseMoveImpl(X11GraphicsConfig xgc, int x, int y);
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32282
diff changeset
   113
    private static synchronized native void mousePressImpl(int buttons);
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32282
diff changeset
   114
    private static synchronized native void mouseReleaseImpl(int buttons);
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32282
diff changeset
   115
    private static synchronized native void mouseWheelImpl(int wheelAmt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32282
diff changeset
   117
    private static synchronized native void keyPressImpl(int keycode);
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32282
diff changeset
   118
    private static synchronized native void keyReleaseImpl(int keycode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32282
diff changeset
   120
    private static synchronized native void getRGBPixelsImpl(X11GraphicsConfig xgc,
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 25859
diff changeset
   121
            int x, int y, int width, int height, int pixelArray[], boolean isGtkSupported);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}