< prev index next >
src/java.desktop/unix/native/libawt_xawt/awt/awt_Robot.c
Print this page
@@ -36,18 +36,18 @@
#include <X11/Xmd.h>
#include <X11/extensions/xtestext1.h>
#include <X11/extensions/XTest.h>
#include <X11/extensions/XInput.h>
#include <X11/extensions/XI.h>
+#include <X11/extensions/Xcomposite.h>
#include <jni.h>
#include <sizecalc.h>
#include "robot_common.h"
#include "canvas.h"
#include "wsutils.h"
#include "list.h"
#include "multiVis.h"
-#include "gtk2_interface.h"
#if defined(__linux__) || defined(MACOSX)
#include <sys/socket.h>
#endif
@@ -88,10 +88,36 @@
}
return isXTestAvailable;
}
+static Bool hasXCompositeOverlayExtension(Display *display) {
+ int xoverlay = False;
+ int eventBase, errorBase;
+ if (XCompositeQueryExtension(display, &eventBase, &errorBase)) {
+ int major = 0;
+ int minor = 0;
+
+ XCompositeQueryVersion(display, &major, &minor);
+ if (major > 0 || minor >= 3) {
+ xoverlay = True;
+ }
+ }
+
+ return xoverlay;
+}
+
+static jboolean isXCompositeDisplay(Display *display, int screenNumber) {
+
+ char NET_WM_CM_Sn[25];
+ snprintf(NET_WM_CM_Sn, sizeof(NET_WM_CM_Sn), "_NET_WM_CM_S%d\0", screenNumber);
+
+ Atom managerSelection = XInternAtom(display, NET_WM_CM_Sn, 0);
+ Window owner = XGetSelectionOwner(display, managerSelection);
+
+ return owner != 0;
+}
static XImage *getWindowImage(Display * display, Window window,
int32_t x, int32_t y,
int32_t w, int32_t h) {
XImage *image;
@@ -209,12 +235,11 @@
jint jx,
jint jy,
jint jwidth,
jint jheight,
jint scale,
- jintArray pixelArray,
- jboolean isGtkSupported) {
+ jintArray pixelArray) {
XImage *image;
jint *ary; /* Array of jints for sending pixel values back
* to parent process.
*/
Window rootWindow;
@@ -236,10 +261,15 @@
jint sy = jy * scale;
jint swidth = jwidth * scale;
jint sheight = jheight * scale;
rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
+ if (isXCompositeDisplay(awt_display, adata->awt_visInfo.screen) &&
+ hasXCompositeOverlayExtension(awt_display))
+ {
+ rootWindow = XCompositeGetOverlayWindow(awt_display, rootWindow);
+ }
if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
|| sx + swidth <= attr.x
|| attr.x + attr.width <= sx
|| sy + sheight <= attr.y
@@ -247,11 +277,10 @@
AWT_UNLOCK();
return; // Does not intersect with root window
}
- gboolean gtk_failed = TRUE;
jint _x, _y;
jint x = MAX(sx, attr.x);
jint y = MAX(sy, attr.y);
jint width = MIN(sx + swidth, attr.x + attr.width) - x;
@@ -261,78 +290,10 @@
int dx = attr.x > sx ? attr.x - sx : 0;
int dy = attr.y > sy ? attr.y - sy : 0;
int index;
- if (isGtkSupported) {
- GdkPixbuf *pixbuf;
- (*fp_gdk_threads_enter)();
- GdkWindow *root = (*fp_gdk_get_default_root_window)();
-
- pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(NULL, root, NULL,
- x, y, 0, 0, width, height);
- if (pixbuf && scale != 1) {
- GdkPixbuf *scaledPixbuf;
- x /= scale;
- y /= scale;
- width /= scale;
- height /= scale;
- dx /= scale;
- dy /= scale;
- scaledPixbuf = (*fp_gdk_pixbuf_scale_simple)(pixbuf, width, height,
- GDK_INTERP_BILINEAR);
- (*fp_g_object_unref)(pixbuf);
- pixbuf = scaledPixbuf;
- }
-
- if (pixbuf) {
- int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
- int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
-
- if ((*fp_gdk_pixbuf_get_width)(pixbuf) == width
- && (*fp_gdk_pixbuf_get_height)(pixbuf) == height
- && (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8
- && (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB
- && nchan >= 3
- ) {
- guchar *p, *pix = (*fp_gdk_pixbuf_get_pixels)(pixbuf);
-
- ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);
- if (!ary) {
- (*fp_g_object_unref)(pixbuf);
- (*fp_gdk_threads_leave)();
- AWT_UNLOCK();
- return;
- }
-
- for (_y = 0; _y < height; _y++) {
- for (_x = 0; _x < width; _x++) {
- p = pix + _y * stride + _x * nchan;
-
- index = (_y + dy) * jwidth + (_x + dx);
- ary[index] = 0xff000000
- | (p[0] << 16)
- | (p[1] << 8)
- | (p[2]);
-
- }
- }
- (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
- if ((*env)->ExceptionCheck(env)) {
- (*fp_g_object_unref)(pixbuf);
- (*fp_gdk_threads_leave)();
- AWT_UNLOCK();
- return;
- }
- gtk_failed = FALSE;
- }
- (*fp_g_object_unref)(pixbuf);
- }
- (*fp_gdk_threads_leave)();
- }
-
- if (gtk_failed) {
image = getWindowImage(awt_display, rootWindow, sx, sy, swidth, sheight);
ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);
if (!ary) {
@@ -361,11 +322,11 @@
}
}
XDestroyImage(image);
(*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
- }
+
AWT_UNLOCK();
}
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env,
< prev index next >