< prev index next >

modules/graphics/src/main/native-glass/gtk/GlassRobot.cpp

Print this page


   1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 #include <X11/Xlib.h>
  26 #include <X11/Xutil.h>
  27 #include <X11/extensions/XTest.h>
  28 #include <assert.h>
  29 #include <stdlib.h>
  30 #include <gdk/gdk.h>
  31 #include <gdk/gdkx.h>
  32 
  33 #include <com_sun_glass_ui_gtk_GtkRobot.h>
  34 #include <com_sun_glass_events_MouseEvent.h>
  35 #include "glass_general.h"
  36 #include "glass_gtkcompat.h"
  37 #include "glass_key.h"
  38 
  39 
  40 static void checkXTest(JNIEnv* env) {
  41     int32_t major_opcode, first_event, first_error;
  42     int32_t  event_basep, error_basep, majorp, minorp;
  43     static int32_t isXTestAvailable;
  44     static gboolean checkDone = FALSE;
  45     if (!checkDone) {
  46         /* check if XTest is available */
  47         isXTestAvailable = XQueryExtension(gdk_x11_get_default_xdisplay(), XTestExtensionName, &major_opcode, &first_event, &first_error);
  48         if (isXTestAvailable) {
  49             /* check if XTest version is OK */
  50             XTestQueryExtension(gdk_x11_get_default_xdisplay(), &event_basep, &error_basep, &majorp, &minorp);
  51             if (majorp < 2 || (majorp == 2 && minorp < 2)) {
  52                     isXTestAvailable = False;
  53             } else {
  54                 XTestGrabControl(gdk_x11_get_default_xdisplay(), True);
  55             }
  56         }


 230     (void)obj;
 231 
 232     jint y;
 233     glass_gdk_display_get_pointer(gdk_display_get_default(), NULL, &y);
 234     return y;
 235 }
 236 
 237 /*
 238  * Class:     com_sun_glass_ui_gtk_GtkRobot
 239  * Method:    _getScreenCapture
 240  * Signature: (IIII[I)V
 241  */
 242 JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkRobot__1getScreenCapture
 243   (JNIEnv * env, jobject obj, jint x, jint y, jint width, jint height, jintArray data)
 244 {
 245     (void)obj;
 246 
 247     GdkPixbuf *screenshot, *tmp;
 248     GdkWindow *root_window = gdk_get_default_root_window();
 249 
 250     tmp = gdk_pixbuf_get_from_drawable (NULL, root_window, NULL,
 251                                            x, y, 0, 0, width, height);
 252     screenshot = gdk_pixbuf_add_alpha(tmp, FALSE, 0, 0, 0);
 253     g_object_unref(tmp);
 254 
 255     jint *pixels = (jint *)convert_BGRA_to_RGBA((int*)gdk_pixbuf_get_pixels(screenshot), width * 4, height);
 256     env->SetIntArrayRegion(data, 0, height * width, pixels);
 257     g_free(pixels);
 258 
 259     g_object_unref(screenshot);
 260 }
 261 
 262 } // extern "C"
   1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 #include <X11/Xlib.h>
  26 #include <X11/Xutil.h>
  27 #include <X11/extensions/XTest.h>
  28 #include <assert.h>
  29 #include <stdlib.h>
  30 #include <gdk/gdk.h>
  31 #include <gdk/gdkx.h>
  32 
  33 #include <com_sun_glass_ui_gtk_GtkRobot.h>
  34 #include <com_sun_glass_events_MouseEvent.h>
  35 #include "glass_general.h"

  36 #include "glass_key.h"
  37 
  38 
  39 static void checkXTest(JNIEnv* env) {
  40     int32_t major_opcode, first_event, first_error;
  41     int32_t  event_basep, error_basep, majorp, minorp;
  42     static int32_t isXTestAvailable;
  43     static gboolean checkDone = FALSE;
  44     if (!checkDone) {
  45         /* check if XTest is available */
  46         isXTestAvailable = XQueryExtension(gdk_x11_get_default_xdisplay(), XTestExtensionName, &major_opcode, &first_event, &first_error);
  47         if (isXTestAvailable) {
  48             /* check if XTest version is OK */
  49             XTestQueryExtension(gdk_x11_get_default_xdisplay(), &event_basep, &error_basep, &majorp, &minorp);
  50             if (majorp < 2 || (majorp == 2 && minorp < 2)) {
  51                     isXTestAvailable = False;
  52             } else {
  53                 XTestGrabControl(gdk_x11_get_default_xdisplay(), True);
  54             }
  55         }


 229     (void)obj;
 230 
 231     jint y;
 232     glass_gdk_display_get_pointer(gdk_display_get_default(), NULL, &y);
 233     return y;
 234 }
 235 
 236 /*
 237  * Class:     com_sun_glass_ui_gtk_GtkRobot
 238  * Method:    _getScreenCapture
 239  * Signature: (IIII[I)V
 240  */
 241 JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkRobot__1getScreenCapture
 242   (JNIEnv * env, jobject obj, jint x, jint y, jint width, jint height, jintArray data)
 243 {
 244     (void)obj;
 245 
 246     GdkPixbuf *screenshot, *tmp;
 247     GdkWindow *root_window = gdk_get_default_root_window();
 248 
 249     tmp = glass_pixbuf_from_window(root_window, x, y, width, height);

 250     screenshot = gdk_pixbuf_add_alpha(tmp, FALSE, 0, 0, 0);
 251     g_object_unref(tmp);
 252 
 253     jint *pixels = (jint *)convert_BGRA_to_RGBA((int*)gdk_pixbuf_get_pixels(screenshot), width * 4, height);
 254     env->SetIntArrayRegion(data, 0, height * width, pixels);
 255     g_free(pixels);
 256 
 257     g_object_unref(screenshot);
 258 }
 259 
 260 } // extern "C"
< prev index next >