author | serb |
Sat, 12 Nov 2011 04:13:38 +0400 | |
changeset 11093 | e753252dc8a9 |
parent 9660 | 73dd0c7a8658 |
child 12047 | 320a714614e9 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 1999, 2010, 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/Intrinsic.h> |
|
35 |
#include <X11/Xutil.h> |
|
36 |
#include <X11/Xmd.h> |
|
37 |
#include <X11/extensions/xtestext1.h> |
|
38 |
#include <X11/extensions/XTest.h> |
|
39 |
#include <X11/extensions/XInput.h> |
|
40 |
#include <X11/extensions/XI.h> |
|
41 |
#include <jni.h> |
|
42 |
#include "robot_common.h" |
|
43 |
#include "canvas.h" |
|
44 |
#include "wsutils.h" |
|
45 |
#include "list.h" |
|
46 |
#include "multiVis.h" |
|
47 |
#ifdef __linux__ |
|
48 |
#include <sys/socket.h> |
|
49 |
#endif |
|
50 |
||
51 |
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs; |
|
52 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
53 |
static jint * masks; |
3337
45c02b7c01b6
6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents:
2810
diff
changeset
|
54 |
static jint num_buttons; |
2 | 55 |
|
56 |
static int32_t isXTestAvailable() { |
|
57 |
int32_t major_opcode, first_event, first_error; |
|
58 |
int32_t event_basep, error_basep, majorp, minorp; |
|
59 |
int32_t isXTestAvailable; |
|
60 |
||
61 |
/* check if XTest is available */ |
|
62 |
isXTestAvailable = XQueryExtension(awt_display, XTestExtensionName, &major_opcode, &first_event, &first_error); |
|
63 |
DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XTEST) returns major_opcode = %d, first_event = %d, first_error = %d", |
|
64 |
major_opcode, first_event, first_error); |
|
65 |
if (isXTestAvailable) { |
|
66 |
/* check if XTest version is OK */ |
|
67 |
XTestQueryExtension(awt_display, &event_basep, &error_basep, &majorp, &minorp); |
|
68 |
DTRACE_PRINTLN4("RobotPeer: XTestQueryExtension returns event_basep = %d, error_basep = %d, majorp = %d, minorp = %d", |
|
69 |
event_basep, error_basep, majorp, minorp); |
|
70 |
if (majorp < 2 || (majorp == 2 && minorp < 2)) { |
|
71 |
/* bad version*/ |
|
72 |
DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp); |
|
73 |
if (majorp == 2 && minorp == 1) { |
|
74 |
DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n"); |
|
75 |
} else { |
|
76 |
isXTestAvailable = False; |
|
77 |
} |
|
78 |
} else { |
|
79 |
/* allow XTest calls even if someone else has the grab; e.g. during |
|
80 |
* a window resize operation. Works only with XTEST2.2*/ |
|
81 |
XTestGrabControl(awt_display, True); |
|
82 |
} |
|
83 |
} else { |
|
84 |
DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable"); |
|
85 |
} |
|
86 |
||
87 |
return isXTestAvailable; |
|
88 |
} |
|
89 |
||
90 |
||
91 |
static XImage *getWindowImage(Display * display, Window window, |
|
92 |
int32_t x, int32_t y, |
|
93 |
int32_t w, int32_t h) { |
|
94 |
XImage *image; |
|
95 |
int32_t transparentOverlays; |
|
96 |
int32_t numVisuals; |
|
97 |
XVisualInfo *pVisuals; |
|
98 |
int32_t numOverlayVisuals; |
|
99 |
OverlayInfo *pOverlayVisuals; |
|
100 |
int32_t numImageVisuals; |
|
101 |
XVisualInfo **pImageVisuals; |
|
102 |
list_ptr vis_regions; /* list of regions to read from */ |
|
103 |
list_ptr vis_image_regions ; |
|
104 |
int32_t allImage = 0 ; |
|
105 |
int32_t format = ZPixmap; |
|
106 |
||
107 |
/* prevent user from moving stuff around during the capture */ |
|
108 |
XGrabServer(display); |
|
109 |
||
110 |
/* |
|
111 |
* The following two functions live in multiVis.c-- they are pretty |
|
112 |
* much verbatim taken from the source to the xwd utility from the |
|
113 |
* X11 source. This version of the xwd source was somewhat better written |
|
114 |
* for reuse compared to Sun's version. |
|
115 |
* |
|
116 |
* ftp.x.org/pub/R6.3/xc/programs/xwd |
|
117 |
* |
|
118 |
* We use these functions since they do the very tough job of capturing |
|
119 |
* the screen correctly when it contains multiple visuals. They take into |
|
120 |
* account the depth/colormap of each visual and produce a capture as a |
|
121 |
* 24-bit RGB image so we don't have to fool around with colormaps etc. |
|
122 |
*/ |
|
123 |
||
124 |
GetMultiVisualRegions( |
|
125 |
display, |
|
126 |
window, |
|
127 |
x, y, w, h, |
|
128 |
&transparentOverlays, |
|
129 |
&numVisuals, |
|
130 |
&pVisuals, |
|
131 |
&numOverlayVisuals, |
|
132 |
&pOverlayVisuals, |
|
133 |
&numImageVisuals, |
|
134 |
&pImageVisuals, |
|
135 |
&vis_regions, |
|
136 |
&vis_image_regions, |
|
137 |
&allImage ); |
|
138 |
||
139 |
image = ReadAreaToImage( |
|
140 |
display, |
|
141 |
window, |
|
142 |
x, y, w, h, |
|
143 |
numVisuals, |
|
144 |
pVisuals, |
|
145 |
numOverlayVisuals, |
|
146 |
pOverlayVisuals, |
|
147 |
numImageVisuals, |
|
148 |
pImageVisuals, |
|
149 |
vis_regions, |
|
150 |
vis_image_regions, |
|
151 |
format, |
|
152 |
allImage ); |
|
153 |
||
154 |
/* allow user to do stuff again */ |
|
155 |
XUngrabServer(display); |
|
156 |
||
157 |
/* make sure the grab/ungrab is flushed */ |
|
158 |
XSync(display, False); |
|
159 |
||
160 |
return image; |
|
161 |
} |
|
162 |
||
163 |
/*********************************************************************************************/ |
|
164 |
||
3337
45c02b7c01b6
6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents:
2810
diff
changeset
|
165 |
// this should be called from XRobotPeer constructor |
2 | 166 |
JNIEXPORT void JNICALL |
6825 | 167 |
Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls, jint numberOfButtons, jintArray buttonDownMasks) |
168 |
{ |
|
2 | 169 |
int32_t xtestAvailable; |
6825 | 170 |
jint *tmp; |
171 |
int i; |
|
2 | 172 |
|
3337
45c02b7c01b6
6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents:
2810
diff
changeset
|
173 |
DTRACE_PRINTLN("RobotPeer: setup()"); |
45c02b7c01b6
6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents:
2810
diff
changeset
|
174 |
|
45c02b7c01b6
6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents:
2810
diff
changeset
|
175 |
num_buttons = numberOfButtons; |
6825 | 176 |
tmp = (*env)->GetIntArrayElements(env, buttonDownMasks, JNI_FALSE); |
177 |
masks = (jint *)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
|
178 |
if (masks == (jint *) NULL) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
179 |
JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL); |
6825 | 180 |
(*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0); |
181 |
return; |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
182 |
} |
3337
45c02b7c01b6
6856929: Frame is not getting resized using Robot in OpenSolaris and Ubuntu
dcherepanov
parents:
2810
diff
changeset
|
183 |
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
|
184 |
masks[i] = tmp[i]; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
185 |
} |
6825 | 186 |
(*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
|
187 |
|
2 | 188 |
AWT_LOCK(); |
189 |
xtestAvailable = isXTestAvailable(); |
|
190 |
DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable); |
|
191 |
if (!xtestAvailable) { |
|
192 |
JNU_ThrowByName(env, "java/awt/AWTException", "java.awt.Robot requires your X server support the XTEST extension version 2.2"); |
|
193 |
} |
|
194 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
195 |
AWT_UNLOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
196 |
} |
2 | 197 |
|
198 |
||
199 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
200 |
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env, |
2 | 201 |
jclass cls, |
202 |
jobject xgc, |
|
203 |
jint x, |
|
204 |
jint y, |
|
205 |
jint width, |
|
206 |
jint height, |
|
207 |
jintArray pixelArray) { |
|
208 |
||
209 |
XImage *image; |
|
210 |
jint *ary; /* Array of jints for sending pixel values back |
|
211 |
* to parent process. |
|
212 |
*/ |
|
9660
73dd0c7a8658
7043455: Taking a screenshot may fail on X11 after 6903034
anthony
parents:
8949
diff
changeset
|
213 |
Window rootWindow; |
2 | 214 |
AwtGraphicsConfigDataPtr adata; |
215 |
||
216 |
DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, x, y, width, height, pixelArray); |
|
217 |
||
218 |
AWT_LOCK(); |
|
219 |
||
220 |
/* avoid a lot of work for empty rectangles */ |
|
221 |
if ((width * height) == 0) { |
|
222 |
AWT_UNLOCK(); |
|
223 |
return; |
|
224 |
} |
|
225 |
DASSERT(width * height > 0); /* only allow positive size */ |
|
226 |
||
227 |
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); |
|
228 |
DASSERT(adata != NULL); |
|
229 |
||
9660
73dd0c7a8658
7043455: Taking a screenshot may fail on X11 after 6903034
anthony
parents:
8949
diff
changeset
|
230 |
rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen); |
73dd0c7a8658
7043455: Taking a screenshot may fail on X11 after 6903034
anthony
parents:
8949
diff
changeset
|
231 |
image = getWindowImage(awt_display, rootWindow, x, y, width, height); |
2 | 232 |
|
233 |
/* Array to use to crunch around the pixel values */ |
|
234 |
ary = (jint *) malloc(width * height * sizeof (jint)); |
|
235 |
if (ary == NULL) { |
|
236 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
237 |
XDestroyImage(image); |
|
238 |
AWT_UNLOCK(); |
|
239 |
return; |
|
240 |
} |
|
241 |
/* convert to Java ARGB pixels */ |
|
242 |
for (y = 0; y < height; y++) { |
|
243 |
for (x = 0; x < width; x++) { |
|
244 |
jint pixel = (jint) XGetPixel(image, x, y); /* Note ignore upper |
|
245 |
* 32-bits on 64-bit |
|
246 |
* OSes. |
|
247 |
*/ |
|
248 |
||
249 |
pixel |= 0xff000000; /* alpha - full opacity */ |
|
250 |
||
251 |
ary[(y * width) + x] = pixel; |
|
252 |
} |
|
253 |
} |
|
254 |
(*env)->SetIntArrayRegion(env, pixelArray, 0, height * width, ary); |
|
255 |
free(ary); |
|
256 |
||
257 |
XDestroyImage(image); |
|
258 |
||
259 |
AWT_UNLOCK(); |
|
260 |
} |
|
261 |
||
262 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
263 |
Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env, |
2 | 264 |
jclass cls, |
265 |
jint keycode) { |
|
266 |
||
267 |
AWT_LOCK(); |
|
268 |
||
269 |
DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode); |
|
270 |
||
271 |
XTestFakeKeyEvent(awt_display, |
|
272 |
XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), |
|
273 |
True, |
|
274 |
CurrentTime); |
|
275 |
||
276 |
XSync(awt_display, False); |
|
277 |
||
278 |
AWT_UNLOCK(); |
|
279 |
||
280 |
} |
|
281 |
||
282 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
283 |
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env, |
2 | 284 |
jclass cls, |
285 |
jint keycode) { |
|
286 |
AWT_LOCK(); |
|
287 |
||
288 |
DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode); |
|
289 |
||
290 |
XTestFakeKeyEvent(awt_display, |
|
291 |
XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), |
|
292 |
False, |
|
293 |
CurrentTime); |
|
294 |
||
295 |
XSync(awt_display, False); |
|
296 |
||
297 |
AWT_UNLOCK(); |
|
298 |
} |
|
299 |
||
300 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
301 |
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env, |
2 | 302 |
jclass cls, |
303 |
jobject xgc, |
|
304 |
jint root_x, |
|
305 |
jint root_y) { |
|
306 |
||
307 |
AwtGraphicsConfigDataPtr adata; |
|
308 |
||
309 |
AWT_LOCK(); |
|
310 |
||
311 |
DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y); |
|
312 |
||
313 |
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); |
|
314 |
DASSERT(adata != NULL); |
|
315 |
||
316 |
XWarpPointer(awt_display, None, XRootWindow(awt_display, adata->awt_visInfo.screen), 0, 0, 0, 0, root_x, root_y); |
|
317 |
XSync(awt_display, False); |
|
318 |
||
319 |
AWT_UNLOCK(); |
|
320 |
} |
|
321 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
322 |
/* |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
323 |
* 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
|
324 |
*/ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
325 |
void mouseAction(JNIEnv *env, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
326 |
jclass cls, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
327 |
jint buttonMask, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
328 |
Bool isMousePress) |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
329 |
{ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
330 |
AWT_LOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
331 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
332 |
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
|
333 |
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
|
334 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
335 |
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
|
336 |
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
|
337 |
{ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
338 |
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
|
339 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
340 |
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
|
341 |
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
|
342 |
(num_buttons >= 2)) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
343 |
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
|
344 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
345 |
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
|
346 |
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
|
347 |
(num_buttons >= 3)) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
348 |
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
|
349 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
350 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
351 |
if (num_buttons > 3){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
352 |
int32_t i; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
353 |
int32_t button = 0; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
354 |
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
|
355 |
if ((buttonMask & masks[i])) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
356 |
// 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
|
357 |
// 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
|
358 |
// 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
|
359 |
button = i + 3; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
360 |
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
|
361 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
362 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
363 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
364 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
365 |
XSync(awt_display, False); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
366 |
AWT_UNLOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
367 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
368 |
|
1965
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
369 |
JNIEXPORT void JNICALL |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
370 |
Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
371 |
jclass cls, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
372 |
jint buttonMask) { |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
373 |
mouseAction(env, cls, buttonMask, True); |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
374 |
} |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
375 |
|
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
376 |
JNIEXPORT void JNICALL |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
377 |
Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
378 |
jclass cls, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
379 |
jint buttonMask) { |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
380 |
mouseAction(env, cls, buttonMask, False); |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
381 |
} |
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
382 |
|
2 | 383 |
JNIEXPORT void JNICALL |
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
384 |
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env, |
2 | 385 |
jclass cls, |
386 |
jint wheelAmt) { |
|
387 |
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */ |
|
388 |
/* probably could have been hacked into robot_mouseButtonEvent, but it's */ |
|
389 |
/* cleaner to give it its own command type, in case the implementation */ |
|
390 |
/* needs to be changed later. -bchristi, 6/20/01 */ |
|
391 |
||
392 |
int32_t repeat = abs(wheelAmt); |
|
393 |
int32_t button = wheelAmt < 0 ? 4 : 5; /* wheel up: button 4 */ |
|
394 |
/* wheel down: button 5 */ |
|
395 |
int32_t loopIdx; |
|
396 |
||
397 |
AWT_LOCK(); |
|
398 |
||
399 |
DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt); |
|
400 |
||
401 |
for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for */ |
|
402 |
/* wheelAmt == 0 */ |
|
403 |
XTestFakeButtonEvent(awt_display, button, True, CurrentTime); |
|
404 |
XTestFakeButtonEvent(awt_display, button, False, CurrentTime); |
|
405 |
} |
|
406 |
XSync(awt_display, False); |
|
407 |
||
408 |
AWT_UNLOCK(); |
|
409 |
} |