author | dav |
Tue, 16 Sep 2008 12:17:02 +0400 | |
changeset 1962 | 6c293d33645b |
parent 1175 | 026b52c440fe |
child 1965 | 726a2bc97146 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
2 |
* Copyright 1999-2008 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
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_Component.h" |
|
32 |
#include "awt_GraphicsEnv.h" |
|
33 |
#define XK_MISCELLANY |
|
34 |
#include <X11/keysymdef.h> |
|
35 |
#include <X11/Intrinsic.h> |
|
36 |
#include <X11/Xutil.h> |
|
37 |
#include <X11/Xmd.h> |
|
38 |
#include <X11/extensions/xtestext1.h> |
|
39 |
#include <X11/extensions/XTest.h> |
|
40 |
#include <X11/extensions/XInput.h> |
|
41 |
#include <X11/extensions/XI.h> |
|
42 |
#include <jni.h> |
|
43 |
#include "robot_common.h" |
|
44 |
#include "canvas.h" |
|
45 |
#include "wsutils.h" |
|
46 |
#include "list.h" |
|
47 |
#include "multiVis.h" |
|
48 |
#ifdef __linux__ |
|
49 |
#include <sys/socket.h> |
|
50 |
#endif |
|
51 |
||
52 |
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs; |
|
53 |
||
54 |
// 2 would be more correct, however that's how Robot originally worked |
|
55 |
// and tests start to fail if this value is changed |
|
56 |
static int32_t num_buttons = 3; |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
57 |
static jint * masks; |
2 | 58 |
|
59 |
static int32_t isXTestAvailable() { |
|
60 |
int32_t major_opcode, first_event, first_error; |
|
61 |
int32_t event_basep, error_basep, majorp, minorp; |
|
62 |
int32_t isXTestAvailable; |
|
63 |
||
64 |
/* check if XTest is available */ |
|
65 |
isXTestAvailable = XQueryExtension(awt_display, XTestExtensionName, &major_opcode, &first_event, &first_error); |
|
66 |
DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XTEST) returns major_opcode = %d, first_event = %d, first_error = %d", |
|
67 |
major_opcode, first_event, first_error); |
|
68 |
if (isXTestAvailable) { |
|
69 |
/* check if XTest version is OK */ |
|
70 |
XTestQueryExtension(awt_display, &event_basep, &error_basep, &majorp, &minorp); |
|
71 |
DTRACE_PRINTLN4("RobotPeer: XTestQueryExtension returns event_basep = %d, error_basep = %d, majorp = %d, minorp = %d", |
|
72 |
event_basep, error_basep, majorp, minorp); |
|
73 |
if (majorp < 2 || (majorp == 2 && minorp < 2)) { |
|
74 |
/* bad version*/ |
|
75 |
DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp); |
|
76 |
if (majorp == 2 && minorp == 1) { |
|
77 |
DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n"); |
|
78 |
} else { |
|
79 |
isXTestAvailable = False; |
|
80 |
} |
|
81 |
} else { |
|
82 |
/* allow XTest calls even if someone else has the grab; e.g. during |
|
83 |
* a window resize operation. Works only with XTEST2.2*/ |
|
84 |
XTestGrabControl(awt_display, True); |
|
85 |
} |
|
86 |
} else { |
|
87 |
DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable"); |
|
88 |
} |
|
89 |
||
90 |
return isXTestAvailable; |
|
91 |
} |
|
92 |
||
93 |
static void getNumButtons() { |
|
94 |
int32_t major_opcode, first_event, first_error; |
|
95 |
int32_t xinputAvailable; |
|
96 |
int32_t numDevices, devIdx, clsIdx; |
|
97 |
XDeviceInfo* devices; |
|
98 |
XDeviceInfo* aDevice; |
|
99 |
XButtonInfo* bInfo; |
|
100 |
||
101 |
/* 4700242: |
|
102 |
* If XTest is asked to press a non-existant mouse button |
|
103 |
* (i.e. press Button3 on a system configured with a 2-button mouse), |
|
104 |
* then a crash may happen. To avoid this, we use the XInput |
|
105 |
* extension to query for the number of buttons on the XPointer, and check |
|
106 |
* before calling XTestFakeButtonEvent(). |
|
107 |
*/ |
|
108 |
xinputAvailable = XQueryExtension(awt_display, INAME, &major_opcode, &first_event, &first_error); |
|
109 |
DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d", |
|
110 |
major_opcode, first_event, first_error); |
|
111 |
if (xinputAvailable) { |
|
112 |
devices = XListInputDevices(awt_display, &numDevices); |
|
113 |
for (devIdx = 0; devIdx < numDevices; devIdx++) { |
|
114 |
aDevice = &(devices[devIdx]); |
|
115 |
if (aDevice->use == IsXPointer) { |
|
116 |
for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) { |
|
117 |
if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) { |
|
118 |
bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx])); |
|
119 |
num_buttons = bInfo->num_buttons; |
|
120 |
DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons); |
|
121 |
break; |
|
122 |
} |
|
123 |
} |
|
124 |
break; |
|
125 |
} |
|
126 |
} |
|
127 |
XFreeDeviceList(devices); |
|
128 |
} |
|
129 |
else { |
|
130 |
DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons); |
|
131 |
} |
|
132 |
} |
|
133 |
||
134 |
static XImage *getWindowImage(Display * display, Window window, |
|
135 |
int32_t x, int32_t y, |
|
136 |
int32_t w, int32_t h) { |
|
137 |
XImage *image; |
|
138 |
int32_t transparentOverlays; |
|
139 |
int32_t numVisuals; |
|
140 |
XVisualInfo *pVisuals; |
|
141 |
int32_t numOverlayVisuals; |
|
142 |
OverlayInfo *pOverlayVisuals; |
|
143 |
int32_t numImageVisuals; |
|
144 |
XVisualInfo **pImageVisuals; |
|
145 |
list_ptr vis_regions; /* list of regions to read from */ |
|
146 |
list_ptr vis_image_regions ; |
|
147 |
int32_t allImage = 0 ; |
|
148 |
int32_t format = ZPixmap; |
|
149 |
||
150 |
/* prevent user from moving stuff around during the capture */ |
|
151 |
XGrabServer(display); |
|
152 |
||
153 |
/* |
|
154 |
* The following two functions live in multiVis.c-- they are pretty |
|
155 |
* much verbatim taken from the source to the xwd utility from the |
|
156 |
* X11 source. This version of the xwd source was somewhat better written |
|
157 |
* for reuse compared to Sun's version. |
|
158 |
* |
|
159 |
* ftp.x.org/pub/R6.3/xc/programs/xwd |
|
160 |
* |
|
161 |
* We use these functions since they do the very tough job of capturing |
|
162 |
* the screen correctly when it contains multiple visuals. They take into |
|
163 |
* account the depth/colormap of each visual and produce a capture as a |
|
164 |
* 24-bit RGB image so we don't have to fool around with colormaps etc. |
|
165 |
*/ |
|
166 |
||
167 |
GetMultiVisualRegions( |
|
168 |
display, |
|
169 |
window, |
|
170 |
x, y, w, h, |
|
171 |
&transparentOverlays, |
|
172 |
&numVisuals, |
|
173 |
&pVisuals, |
|
174 |
&numOverlayVisuals, |
|
175 |
&pOverlayVisuals, |
|
176 |
&numImageVisuals, |
|
177 |
&pImageVisuals, |
|
178 |
&vis_regions, |
|
179 |
&vis_image_regions, |
|
180 |
&allImage ); |
|
181 |
||
182 |
image = ReadAreaToImage( |
|
183 |
display, |
|
184 |
window, |
|
185 |
x, y, w, h, |
|
186 |
numVisuals, |
|
187 |
pVisuals, |
|
188 |
numOverlayVisuals, |
|
189 |
pOverlayVisuals, |
|
190 |
numImageVisuals, |
|
191 |
pImageVisuals, |
|
192 |
vis_regions, |
|
193 |
vis_image_regions, |
|
194 |
format, |
|
195 |
allImage ); |
|
196 |
||
197 |
/* allow user to do stuff again */ |
|
198 |
XUngrabServer(display); |
|
199 |
||
200 |
/* make sure the grab/ungrab is flushed */ |
|
201 |
XSync(display, False); |
|
202 |
||
203 |
return image; |
|
204 |
} |
|
205 |
||
206 |
/*********************************************************************************************/ |
|
207 |
||
208 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
209 |
Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls) { |
2 | 210 |
int32_t xtestAvailable; |
211 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
212 |
// this should be called from XRobotPeer constructor |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
213 |
jclass inputEventClazz = (*env)->FindClass(env, "java/awt/event/InputEvent"); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
214 |
jmethodID getButtonDownMasksID = (*env)->GetStaticMethodID(env, inputEventClazz, "getButtonDownMasks", "()[I"); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
215 |
jintArray obj = (jintArray)(*env)->CallStaticObjectMethod(env, inputEventClazz, getButtonDownMasksID); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
216 |
jsize len = (*env)->GetArrayLength(env, obj); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
217 |
jint * tmp = (*env)->GetIntArrayElements(env, obj, JNI_FALSE); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
218 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
219 |
masks = (jint *)malloc(sizeof(jint)*len); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
220 |
if (masks == (jint *) NULL) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
221 |
JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
222 |
goto finally; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
223 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
224 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
225 |
int i; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
226 |
for (i = 0; i < len; i++) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
227 |
masks[i] = tmp[i]; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
228 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
229 |
(*env)->ReleaseIntArrayElements(env, obj, tmp, 0); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
230 |
(*env)->DeleteLocalRef(env, obj); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
231 |
|
2 | 232 |
DTRACE_PRINTLN("RobotPeer: setup()"); |
233 |
||
234 |
AWT_LOCK(); |
|
235 |
||
236 |
xtestAvailable = isXTestAvailable(); |
|
237 |
DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable); |
|
238 |
if (!xtestAvailable) { |
|
239 |
JNU_ThrowByName(env, "java/awt/AWTException", "java.awt.Robot requires your X server support the XTEST extension version 2.2"); |
|
240 |
AWT_UNLOCK(); |
|
241 |
return; |
|
242 |
} |
|
243 |
||
244 |
getNumButtons(); |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
245 |
finally: |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
246 |
AWT_UNLOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
247 |
} |
2 | 248 |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
249 |
JNIEXPORT void JNICALL |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
250 |
Java_sun_awt_X11_XRobotPeer_getNumberOfButtonsImpl(JNIEnv *env, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
251 |
jclass cls) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
252 |
// At the moment this routine being called we already should have an initialized num_buttons variable. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
253 |
return num_buttons; |
2 | 254 |
} |
255 |
||
256 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
257 |
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env, |
2 | 258 |
jclass cls, |
259 |
jobject xgc, |
|
260 |
jint x, |
|
261 |
jint y, |
|
262 |
jint width, |
|
263 |
jint height, |
|
264 |
jintArray pixelArray) { |
|
265 |
||
266 |
XImage *image; |
|
267 |
jint *ary; /* Array of jints for sending pixel values back |
|
268 |
* to parent process. |
|
269 |
*/ |
|
270 |
Window rootWindow; |
|
271 |
AwtGraphicsConfigDataPtr adata; |
|
272 |
||
273 |
DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, x, y, width, height, pixelArray); |
|
274 |
||
275 |
AWT_LOCK(); |
|
276 |
||
277 |
/* avoid a lot of work for empty rectangles */ |
|
278 |
if ((width * height) == 0) { |
|
279 |
AWT_UNLOCK(); |
|
280 |
return; |
|
281 |
} |
|
282 |
DASSERT(width * height > 0); /* only allow positive size */ |
|
283 |
||
284 |
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); |
|
285 |
DASSERT(adata != NULL); |
|
286 |
||
287 |
rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen); |
|
288 |
image = getWindowImage(awt_display, rootWindow, x, y, width, height); |
|
289 |
||
290 |
/* Array to use to crunch around the pixel values */ |
|
291 |
ary = (jint *) malloc(width * height * sizeof (jint)); |
|
292 |
if (ary == NULL) { |
|
293 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
294 |
XDestroyImage(image); |
|
295 |
AWT_UNLOCK(); |
|
296 |
return; |
|
297 |
} |
|
298 |
/* convert to Java ARGB pixels */ |
|
299 |
for (y = 0; y < height; y++) { |
|
300 |
for (x = 0; x < width; x++) { |
|
301 |
jint pixel = (jint) XGetPixel(image, x, y); /* Note ignore upper |
|
302 |
* 32-bits on 64-bit |
|
303 |
* OSes. |
|
304 |
*/ |
|
305 |
||
306 |
pixel |= 0xff000000; /* alpha - full opacity */ |
|
307 |
||
308 |
ary[(y * width) + x] = pixel; |
|
309 |
} |
|
310 |
} |
|
311 |
(*env)->SetIntArrayRegion(env, pixelArray, 0, height * width, ary); |
|
312 |
free(ary); |
|
313 |
||
314 |
XDestroyImage(image); |
|
315 |
||
316 |
AWT_UNLOCK(); |
|
317 |
} |
|
318 |
||
319 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
320 |
Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env, |
2 | 321 |
jclass cls, |
322 |
jint keycode) { |
|
323 |
||
324 |
AWT_LOCK(); |
|
325 |
||
326 |
DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode); |
|
327 |
||
328 |
XTestFakeKeyEvent(awt_display, |
|
329 |
XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), |
|
330 |
True, |
|
331 |
CurrentTime); |
|
332 |
||
333 |
XSync(awt_display, False); |
|
334 |
||
335 |
AWT_UNLOCK(); |
|
336 |
||
337 |
} |
|
338 |
||
339 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
340 |
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env, |
2 | 341 |
jclass cls, |
342 |
jint keycode) { |
|
343 |
AWT_LOCK(); |
|
344 |
||
345 |
DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode); |
|
346 |
||
347 |
XTestFakeKeyEvent(awt_display, |
|
348 |
XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), |
|
349 |
False, |
|
350 |
CurrentTime); |
|
351 |
||
352 |
XSync(awt_display, False); |
|
353 |
||
354 |
AWT_UNLOCK(); |
|
355 |
} |
|
356 |
||
357 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
358 |
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env, |
2 | 359 |
jclass cls, |
360 |
jobject xgc, |
|
361 |
jint root_x, |
|
362 |
jint root_y) { |
|
363 |
||
364 |
AwtGraphicsConfigDataPtr adata; |
|
365 |
||
366 |
AWT_LOCK(); |
|
367 |
||
368 |
DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y); |
|
369 |
||
370 |
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); |
|
371 |
DASSERT(adata != NULL); |
|
372 |
||
373 |
XWarpPointer(awt_display, None, XRootWindow(awt_display, adata->awt_visInfo.screen), 0, 0, 0, 0, root_x, root_y); |
|
374 |
XSync(awt_display, False); |
|
375 |
||
376 |
AWT_UNLOCK(); |
|
377 |
} |
|
378 |
||
379 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
380 |
Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env, |
2 | 381 |
jclass cls, |
382 |
jint buttonMask) { |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
383 |
mouseAction(env, cls, buttonMask, True); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
384 |
/* |
2 | 385 |
AWT_LOCK(); |
386 |
||
387 |
DTRACE_PRINTLN1("RobotPeer: mousePressImpl(%i)", buttonMask); |
|
388 |
||
389 |
if (buttonMask & java_awt_event_InputEvent_BUTTON1_MASK) { |
|
390 |
XTestFakeButtonEvent(awt_display, 1, True, CurrentTime); |
|
391 |
} |
|
392 |
if ((buttonMask & java_awt_event_InputEvent_BUTTON2_MASK) && |
|
393 |
(num_buttons >= 2)) { |
|
394 |
XTestFakeButtonEvent(awt_display, 2, True, CurrentTime); |
|
395 |
} |
|
396 |
if ((buttonMask & java_awt_event_InputEvent_BUTTON3_MASK) && |
|
397 |
(num_buttons >= 3)) { |
|
398 |
XTestFakeButtonEvent(awt_display, 3, True, CurrentTime); |
|
399 |
} |
|
400 |
XSync(awt_display, False); |
|
401 |
||
402 |
AWT_UNLOCK(); |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
403 |
*/ |
2 | 404 |
} |
405 |
||
406 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
407 |
Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env, |
2 | 408 |
jclass cls, |
409 |
jint buttonMask) { |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
410 |
mouseAction(env, cls, buttonMask, False); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
411 |
/* |
2 | 412 |
AWT_LOCK(); |
413 |
||
414 |
DTRACE_PRINTLN1("RobotPeer: mouseReleaseImpl(%i)", buttonMask); |
|
415 |
||
416 |
if (buttonMask & java_awt_event_InputEvent_BUTTON1_MASK) { |
|
417 |
XTestFakeButtonEvent(awt_display, 1, False, CurrentTime); |
|
418 |
} |
|
419 |
if ((buttonMask & java_awt_event_InputEvent_BUTTON2_MASK) && |
|
420 |
(num_buttons >= 2)) { |
|
421 |
XTestFakeButtonEvent(awt_display, 2, False, CurrentTime); |
|
422 |
} |
|
423 |
if ((buttonMask & java_awt_event_InputEvent_BUTTON3_MASK) && |
|
424 |
(num_buttons >= 3)) { |
|
425 |
XTestFakeButtonEvent(awt_display, 3, False, CurrentTime); |
|
426 |
} |
|
427 |
XSync(awt_display, False); |
|
428 |
||
429 |
AWT_UNLOCK(); |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
430 |
*/ |
2 | 431 |
} |
432 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
433 |
/* |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
434 |
* 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
|
435 |
*/ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
436 |
void mouseAction(JNIEnv *env, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
437 |
jclass cls, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
438 |
jint buttonMask, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
439 |
Bool isMousePress) |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
440 |
{ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
441 |
AWT_LOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
442 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
443 |
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
|
444 |
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
|
445 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
446 |
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
|
447 |
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
|
448 |
{ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
449 |
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
|
450 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
451 |
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
|
452 |
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
|
453 |
(num_buttons >= 2)) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
454 |
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
|
455 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
456 |
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
|
457 |
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
|
458 |
(num_buttons >= 3)) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
459 |
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
|
460 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
461 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
462 |
if (num_buttons > 3){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
463 |
int32_t i; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
464 |
int32_t button = 0; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
465 |
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
|
466 |
if ((buttonMask & masks[i])) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
467 |
// 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
|
468 |
// 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
|
469 |
// 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
|
470 |
button = i + 3; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
471 |
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
|
472 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
473 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
474 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
475 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
476 |
XSync(awt_display, False); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
477 |
AWT_UNLOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
478 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
479 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
480 |
|
2 | 481 |
JNIEXPORT void JNICALL |
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
482 |
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env, |
2 | 483 |
jclass cls, |
484 |
jint wheelAmt) { |
|
485 |
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */ |
|
486 |
/* probably could have been hacked into robot_mouseButtonEvent, but it's */ |
|
487 |
/* cleaner to give it its own command type, in case the implementation */ |
|
488 |
/* needs to be changed later. -bchristi, 6/20/01 */ |
|
489 |
||
490 |
int32_t repeat = abs(wheelAmt); |
|
491 |
int32_t button = wheelAmt < 0 ? 4 : 5; /* wheel up: button 4 */ |
|
492 |
/* wheel down: button 5 */ |
|
493 |
int32_t loopIdx; |
|
494 |
||
495 |
AWT_LOCK(); |
|
496 |
||
497 |
DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt); |
|
498 |
||
499 |
for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for */ |
|
500 |
/* wheelAmt == 0 */ |
|
501 |
XTestFakeButtonEvent(awt_display, button, True, CurrentTime); |
|
502 |
XTestFakeButtonEvent(awt_display, button, False, CurrentTime); |
|
503 |
} |
|
504 |
XSync(awt_display, False); |
|
505 |
||
506 |
AWT_UNLOCK(); |
|
507 |
} |