author | ssadetsky |
Fri, 29 Apr 2016 09:45:46 -0700 | |
changeset 37715 | 2feccf1e9f89 |
parent 37711 | 972001566d66 |
child 39852 | 7da63510ba70 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
37699
diff
changeset
|
2 |
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
#ifdef HEADLESS |
|
27 |
#error This file should not be included in headless library |
|
28 |
#endif |
|
29 |
||
30 |
#include "awt_p.h" |
|
31 |
#include "awt_GraphicsEnv.h" |
|
32 |
#define XK_MISCELLANY |
|
33 |
#include <X11/keysymdef.h> |
|
34 |
#include <X11/Xutil.h> |
|
35 |
#include <X11/Xmd.h> |
|
36 |
#include <X11/extensions/xtestext1.h> |
|
37 |
#include <X11/extensions/XTest.h> |
|
38 |
#include <X11/extensions/XInput.h> |
|
39 |
#include <X11/extensions/XI.h> |
|
40 |
#include <jni.h> |
|
18232 | 41 |
#include <sizecalc.h> |
2 | 42 |
#include "robot_common.h" |
43 |
#include "canvas.h" |
|
44 |
#include "wsutils.h" |
|
45 |
#include "list.h" |
|
46 |
#include "multiVis.h" |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
37699
diff
changeset
|
47 |
#include "gtk_interface.h" |
32282 | 48 |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11093
diff
changeset
|
49 |
#if defined(__linux__) || defined(MACOSX) |
2 | 50 |
#include <sys/socket.h> |
51 |
#endif |
|
52 |
||
53 |
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs; |
|
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 | 57 |
|
58 |
static int32_t isXTestAvailable() { |
|
59 |
int32_t major_opcode, first_event, first_error; |
|
60 |
int32_t event_basep, error_basep, majorp, minorp; |
|
61 |
int32_t isXTestAvailable; |
|
62 |
||
63 |
/* check if XTest is available */ |
|
64 |
isXTestAvailable = XQueryExtension(awt_display, XTestExtensionName, &major_opcode, &first_event, &first_error); |
|
65 |
DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XTEST) returns major_opcode = %d, first_event = %d, first_error = %d", |
|
66 |
major_opcode, first_event, first_error); |
|
67 |
if (isXTestAvailable) { |
|
68 |
/* check if XTest version is OK */ |
|
69 |
XTestQueryExtension(awt_display, &event_basep, &error_basep, &majorp, &minorp); |
|
70 |
DTRACE_PRINTLN4("RobotPeer: XTestQueryExtension returns event_basep = %d, error_basep = %d, majorp = %d, minorp = %d", |
|
71 |
event_basep, error_basep, majorp, minorp); |
|
72 |
if (majorp < 2 || (majorp == 2 && minorp < 2)) { |
|
73 |
/* bad version*/ |
|
74 |
DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp); |
|
75 |
if (majorp == 2 && minorp == 1) { |
|
76 |
DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n"); |
|
77 |
} else { |
|
78 |
isXTestAvailable = False; |
|
79 |
} |
|
80 |
} else { |
|
81 |
/* allow XTest calls even if someone else has the grab; e.g. during |
|
82 |
* a window resize operation. Works only with XTEST2.2*/ |
|
83 |
XTestGrabControl(awt_display, True); |
|
84 |
} |
|
85 |
} else { |
|
86 |
DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable"); |
|
87 |
} |
|
88 |
||
89 |
return isXTestAvailable; |
|
90 |
} |
|
91 |
||
92 |
||
93 |
static XImage *getWindowImage(Display * display, Window window, |
|
94 |
int32_t x, int32_t y, |
|
95 |
int32_t w, int32_t h) { |
|
96 |
XImage *image; |
|
97 |
int32_t transparentOverlays; |
|
98 |
int32_t numVisuals; |
|
99 |
XVisualInfo *pVisuals; |
|
100 |
int32_t numOverlayVisuals; |
|
101 |
OverlayInfo *pOverlayVisuals; |
|
102 |
int32_t numImageVisuals; |
|
103 |
XVisualInfo **pImageVisuals; |
|
104 |
list_ptr vis_regions; /* list of regions to read from */ |
|
105 |
list_ptr vis_image_regions ; |
|
106 |
int32_t allImage = 0 ; |
|
107 |
int32_t format = ZPixmap; |
|
108 |
||
109 |
/* prevent user from moving stuff around during the capture */ |
|
110 |
XGrabServer(display); |
|
111 |
||
112 |
/* |
|
113 |
* The following two functions live in multiVis.c-- they are pretty |
|
114 |
* much verbatim taken from the source to the xwd utility from the |
|
115 |
* X11 source. This version of the xwd source was somewhat better written |
|
116 |
* for reuse compared to Sun's version. |
|
117 |
* |
|
118 |
* ftp.x.org/pub/R6.3/xc/programs/xwd |
|
119 |
* |
|
120 |
* We use these functions since they do the very tough job of capturing |
|
121 |
* the screen correctly when it contains multiple visuals. They take into |
|
122 |
* account the depth/colormap of each visual and produce a capture as a |
|
123 |
* 24-bit RGB image so we don't have to fool around with colormaps etc. |
|
124 |
*/ |
|
125 |
||
126 |
GetMultiVisualRegions( |
|
127 |
display, |
|
128 |
window, |
|
129 |
x, y, w, h, |
|
130 |
&transparentOverlays, |
|
131 |
&numVisuals, |
|
132 |
&pVisuals, |
|
133 |
&numOverlayVisuals, |
|
134 |
&pOverlayVisuals, |
|
135 |
&numImageVisuals, |
|
136 |
&pImageVisuals, |
|
137 |
&vis_regions, |
|
138 |
&vis_image_regions, |
|
139 |
&allImage ); |
|
140 |
||
141 |
image = ReadAreaToImage( |
|
142 |
display, |
|
143 |
window, |
|
144 |
x, y, w, h, |
|
145 |
numVisuals, |
|
146 |
pVisuals, |
|
147 |
numOverlayVisuals, |
|
148 |
pOverlayVisuals, |
|
149 |
numImageVisuals, |
|
150 |
pImageVisuals, |
|
151 |
vis_regions, |
|
152 |
vis_image_regions, |
|
153 |
format, |
|
154 |
allImage ); |
|
155 |
||
156 |
/* allow user to do stuff again */ |
|
157 |
XUngrabServer(display); |
|
158 |
||
159 |
/* make sure the grab/ungrab is flushed */ |
|
160 |
XSync(display, False); |
|
161 |
||
162 |
return image; |
|
163 |
} |
|
164 |
||
165 |
/*********************************************************************************************/ |
|
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 | 168 |
JNIEXPORT void JNICALL |
6825 | 169 |
Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls, jint numberOfButtons, jintArray buttonDownMasks) |
170 |
{ |
|
2 | 171 |
int32_t xtestAvailable; |
6825 | 172 |
jint *tmp; |
173 |
int i; |
|
2 | 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 | 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 | 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 | 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 | 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 | 193 |
AWT_LOCK(); |
194 |
xtestAvailable = isXTestAvailable(); |
|
195 |
DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable); |
|
196 |
if (!xtestAvailable) { |
|
197 |
JNU_ThrowByName(env, "java/awt/AWTException", "java.awt.Robot requires your X server support the XTEST extension version 2.2"); |
|
198 |
} |
|
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 | 202 |
|
203 |
||
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 | 206 |
jclass cls, |
207 |
jobject xgc, |
|
32282 | 208 |
jint jx, |
209 |
jint jy, |
|
210 |
jint jwidth, |
|
211 |
jint jheight, |
|
34395 | 212 |
jint scale, |
32282 | 213 |
jintArray pixelArray, |
214 |
jboolean isGtkSupported) { |
|
2 | 215 |
XImage *image; |
216 |
jint *ary; /* Array of jints for sending pixel values back |
|
217 |
* to parent process. |
|
218 |
*/ |
|
9660
73dd0c7a8658
7043455: Taking a screenshot may fail on X11 after 6903034
anthony
parents:
8949
diff
changeset
|
219 |
Window rootWindow; |
32282 | 220 |
XWindowAttributes attr; |
2 | 221 |
AwtGraphicsConfigDataPtr adata; |
222 |
||
32282 | 223 |
DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, jx, jy, jwidth, jheight, pixelArray); |
2 | 224 |
|
32282 | 225 |
if (jwidth <= 0 || jheight <= 0) { |
2 | 226 |
return; |
227 |
} |
|
228 |
||
229 |
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); |
|
230 |
DASSERT(adata != NULL); |
|
231 |
||
32282 | 232 |
AWT_LOCK(); |
233 |
||
34395 | 234 |
jint sx = jx * scale; |
235 |
jint sy = jy * scale; |
|
236 |
jint swidth = jwidth * scale; |
|
237 |
jint sheight = jheight * scale; |
|
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 | 240 |
|
32282 | 241 |
if (!XGetWindowAttributes(awt_display, rootWindow, &attr) |
34395 | 242 |
|| sx + swidth <= attr.x |
243 |
|| attr.x + attr.width <= sx |
|
244 |
|| sy + sheight <= attr.y |
|
245 |
|| attr.y + attr.height <= sy) { |
|
32282 | 246 |
|
2 | 247 |
AWT_UNLOCK(); |
32282 | 248 |
return; // Does not intersect with root window |
2 | 249 |
} |
32282 | 250 |
|
251 |
gboolean gtk_failed = TRUE; |
|
252 |
jint _x, _y; |
|
253 |
||
34395 | 254 |
jint x = MAX(sx, attr.x); |
255 |
jint y = MAX(sy, attr.y); |
|
256 |
jint width = MIN(sx + swidth, attr.x + attr.width) - x; |
|
257 |
jint height = MIN(sy + sheight, attr.y + attr.height) - y; |
|
32282 | 258 |
|
259 |
||
34395 | 260 |
int dx = attr.x > sx ? attr.x - sx : 0; |
261 |
int dy = attr.y > sy ? attr.y - sy : 0; |
|
32282 | 262 |
|
263 |
int index; |
|
264 |
||
265 |
if (isGtkSupported) { |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
37699
diff
changeset
|
266 |
gtk->gdk_threads_enter(); |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
37699
diff
changeset
|
267 |
gtk_failed = gtk->get_drawable_data(env, pixelArray, x, y, width, |
37715
2feccf1e9f89
8155606: [PIT] Robot's createScreenCapture() broken on Linux
ssadetsky
parents:
37711
diff
changeset
|
268 |
height, jwidth, dx, dy, scale); |
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
37699
diff
changeset
|
269 |
gtk->gdk_threads_leave(); |
2 | 270 |
} |
32282 | 271 |
|
272 |
if (gtk_failed) { |
|
34395 | 273 |
image = getWindowImage(awt_display, rootWindow, sx, sy, swidth, sheight); |
32282 | 274 |
|
275 |
ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); |
|
276 |
||
277 |
if (!ary) { |
|
278 |
XDestroyImage(image); |
|
279 |
AWT_UNLOCK(); |
|
280 |
return; |
|
281 |
} |
|
2 | 282 |
|
34395 | 283 |
dx /= scale; |
284 |
dy /= scale; |
|
285 |
width /= scale; |
|
286 |
height /= scale; |
|
287 |
||
32282 | 288 |
/* convert to Java ARGB pixels */ |
289 |
for (_y = 0; _y < height; _y++) { |
|
290 |
for (_x = 0; _x < width; _x++) { |
|
34395 | 291 |
jint pixel = (jint) XGetPixel(image, _x * scale, _y * scale); |
292 |
/* Note ignore upper |
|
32282 | 293 |
* 32-bits on 64-bit |
294 |
* OSes. |
|
295 |
*/ |
|
296 |
pixel |= 0xff000000; /* alpha - full opacity */ |
|
2 | 297 |
|
32282 | 298 |
index = (_y + dy) * jwidth + (_x + dx); |
299 |
ary[index] = pixel; |
|
300 |
} |
|
301 |
} |
|
302 |
||
303 |
XDestroyImage(image); |
|
304 |
(*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0); |
|
305 |
} |
|
2 | 306 |
AWT_UNLOCK(); |
307 |
} |
|
308 |
||
309 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
310 |
Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env, |
2 | 311 |
jclass cls, |
312 |
jint keycode) { |
|
313 |
||
314 |
AWT_LOCK(); |
|
315 |
||
316 |
DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode); |
|
317 |
||
318 |
XTestFakeKeyEvent(awt_display, |
|
319 |
XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), |
|
320 |
True, |
|
321 |
CurrentTime); |
|
322 |
||
323 |
XSync(awt_display, False); |
|
324 |
||
325 |
AWT_UNLOCK(); |
|
326 |
||
327 |
} |
|
328 |
||
329 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
330 |
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env, |
2 | 331 |
jclass cls, |
332 |
jint keycode) { |
|
333 |
AWT_LOCK(); |
|
334 |
||
335 |
DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode); |
|
336 |
||
337 |
XTestFakeKeyEvent(awt_display, |
|
338 |
XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), |
|
339 |
False, |
|
340 |
CurrentTime); |
|
341 |
||
342 |
XSync(awt_display, False); |
|
343 |
||
344 |
AWT_UNLOCK(); |
|
345 |
} |
|
346 |
||
347 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
348 |
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env, |
2 | 349 |
jclass cls, |
350 |
jobject xgc, |
|
351 |
jint root_x, |
|
352 |
jint root_y) { |
|
353 |
||
354 |
AwtGraphicsConfigDataPtr adata; |
|
355 |
||
356 |
AWT_LOCK(); |
|
357 |
||
358 |
DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y); |
|
359 |
||
360 |
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); |
|
361 |
DASSERT(adata != NULL); |
|
362 |
||
363 |
XWarpPointer(awt_display, None, XRootWindow(awt_display, adata->awt_visInfo.screen), 0, 0, 0, 0, root_x, root_y); |
|
364 |
XSync(awt_display, False); |
|
365 |
||
366 |
AWT_UNLOCK(); |
|
367 |
} |
|
368 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
369 |
/* |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
370 |
* 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
|
371 |
*/ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
372 |
void mouseAction(JNIEnv *env, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
373 |
jclass cls, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
374 |
jint buttonMask, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
375 |
Bool isMousePress) |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
376 |
{ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
377 |
AWT_LOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
378 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
379 |
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
|
380 |
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
|
381 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
382 |
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
|
383 |
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
|
384 |
{ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
385 |
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
|
386 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
387 |
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
|
388 |
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
|
389 |
(num_buttons >= 2)) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
390 |
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
|
391 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
392 |
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
|
393 |
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
|
394 |
(num_buttons >= 3)) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
395 |
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
|
396 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
397 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
398 |
if (num_buttons > 3){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
399 |
int32_t i; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
400 |
int32_t button = 0; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
401 |
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
|
402 |
if ((buttonMask & masks[i])) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
403 |
// 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
|
404 |
// 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
|
405 |
// 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
|
406 |
button = i + 3; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
407 |
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
|
408 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
409 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
410 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
411 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
412 |
XSync(awt_display, False); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
413 |
AWT_UNLOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
414 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
415 |
|
1965
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
416 |
JNIEXPORT void JNICALL |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
417 |
Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
418 |
jclass cls, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
419 |
jint buttonMask) { |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
420 |
mouseAction(env, cls, buttonMask, True); |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
421 |
} |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
422 |
|
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
423 |
JNIEXPORT void JNICALL |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
424 |
Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
425 |
jclass cls, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
426 |
jint buttonMask) { |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
427 |
mouseAction(env, cls, buttonMask, False); |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
428 |
} |
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
429 |
|
2 | 430 |
JNIEXPORT void JNICALL |
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
431 |
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env, |
2 | 432 |
jclass cls, |
433 |
jint wheelAmt) { |
|
434 |
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */ |
|
435 |
/* probably could have been hacked into robot_mouseButtonEvent, but it's */ |
|
436 |
/* cleaner to give it its own command type, in case the implementation */ |
|
437 |
/* needs to be changed later. -bchristi, 6/20/01 */ |
|
438 |
||
439 |
int32_t repeat = abs(wheelAmt); |
|
440 |
int32_t button = wheelAmt < 0 ? 4 : 5; /* wheel up: button 4 */ |
|
441 |
/* wheel down: button 5 */ |
|
442 |
int32_t loopIdx; |
|
443 |
||
444 |
AWT_LOCK(); |
|
445 |
||
446 |
DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt); |
|
447 |
||
448 |
for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for */ |
|
449 |
/* wheelAmt == 0 */ |
|
450 |
XTestFakeButtonEvent(awt_display, button, True, CurrentTime); |
|
451 |
XTestFakeButtonEvent(awt_display, button, False, CurrentTime); |
|
452 |
} |
|
453 |
XSync(awt_display, False); |
|
454 |
||
455 |
AWT_UNLOCK(); |
|
456 |
} |