author | dav |
Fri, 22 May 2009 16:09:45 +0400 | |
changeset 2810 | fa49c6a06baf |
parent 1965 | 726a2bc97146 |
child 3337 | 45c02b7c01b6 |
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 |
||
2810
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
1965
diff
changeset
|
54 |
extern int32_t getNumButtons(); |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
1965
diff
changeset
|
55 |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
56 |
static jint * masks; |
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 |
||
167 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
168 |
Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls) { |
2 | 169 |
int32_t xtestAvailable; |
170 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
171 |
// 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
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
178 |
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
|
179 |
if (masks == (jint *) NULL) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
180 |
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
|
181 |
goto finally; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
182 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
183 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
184 |
int i; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
185 |
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
|
186 |
masks[i] = tmp[i]; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
187 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
188 |
(*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
|
189 |
(*env)->DeleteLocalRef(env, obj); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
190 |
|
2 | 191 |
DTRACE_PRINTLN("RobotPeer: setup()"); |
192 |
||
193 |
AWT_LOCK(); |
|
194 |
||
195 |
xtestAvailable = isXTestAvailable(); |
|
196 |
DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable); |
|
197 |
if (!xtestAvailable) { |
|
198 |
JNU_ThrowByName(env, "java/awt/AWTException", "java.awt.Robot requires your X server support the XTEST extension version 2.2"); |
|
199 |
AWT_UNLOCK(); |
|
200 |
return; |
|
201 |
} |
|
202 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
203 |
finally: |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
204 |
AWT_UNLOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
205 |
} |
2 | 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_getRGBPixelsImpl( JNIEnv *env, |
2 | 210 |
jclass cls, |
211 |
jobject xgc, |
|
212 |
jint x, |
|
213 |
jint y, |
|
214 |
jint width, |
|
215 |
jint height, |
|
216 |
jintArray pixelArray) { |
|
217 |
||
218 |
XImage *image; |
|
219 |
jint *ary; /* Array of jints for sending pixel values back |
|
220 |
* to parent process. |
|
221 |
*/ |
|
222 |
Window rootWindow; |
|
223 |
AwtGraphicsConfigDataPtr adata; |
|
224 |
||
225 |
DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, x, y, width, height, pixelArray); |
|
226 |
||
227 |
AWT_LOCK(); |
|
228 |
||
229 |
/* avoid a lot of work for empty rectangles */ |
|
230 |
if ((width * height) == 0) { |
|
231 |
AWT_UNLOCK(); |
|
232 |
return; |
|
233 |
} |
|
234 |
DASSERT(width * height > 0); /* only allow positive size */ |
|
235 |
||
236 |
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); |
|
237 |
DASSERT(adata != NULL); |
|
238 |
||
239 |
rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen); |
|
240 |
image = getWindowImage(awt_display, rootWindow, x, y, width, height); |
|
241 |
||
242 |
/* Array to use to crunch around the pixel values */ |
|
243 |
ary = (jint *) malloc(width * height * sizeof (jint)); |
|
244 |
if (ary == NULL) { |
|
245 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
246 |
XDestroyImage(image); |
|
247 |
AWT_UNLOCK(); |
|
248 |
return; |
|
249 |
} |
|
250 |
/* convert to Java ARGB pixels */ |
|
251 |
for (y = 0; y < height; y++) { |
|
252 |
for (x = 0; x < width; x++) { |
|
253 |
jint pixel = (jint) XGetPixel(image, x, y); /* Note ignore upper |
|
254 |
* 32-bits on 64-bit |
|
255 |
* OSes. |
|
256 |
*/ |
|
257 |
||
258 |
pixel |= 0xff000000; /* alpha - full opacity */ |
|
259 |
||
260 |
ary[(y * width) + x] = pixel; |
|
261 |
} |
|
262 |
} |
|
263 |
(*env)->SetIntArrayRegion(env, pixelArray, 0, height * width, ary); |
|
264 |
free(ary); |
|
265 |
||
266 |
XDestroyImage(image); |
|
267 |
||
268 |
AWT_UNLOCK(); |
|
269 |
} |
|
270 |
||
271 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
272 |
Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env, |
2 | 273 |
jclass cls, |
274 |
jint keycode) { |
|
275 |
||
276 |
AWT_LOCK(); |
|
277 |
||
278 |
DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode); |
|
279 |
||
280 |
XTestFakeKeyEvent(awt_display, |
|
281 |
XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), |
|
282 |
True, |
|
283 |
CurrentTime); |
|
284 |
||
285 |
XSync(awt_display, False); |
|
286 |
||
287 |
AWT_UNLOCK(); |
|
288 |
||
289 |
} |
|
290 |
||
291 |
JNIEXPORT void JNICALL |
|
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
292 |
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env, |
2 | 293 |
jclass cls, |
294 |
jint keycode) { |
|
295 |
AWT_LOCK(); |
|
296 |
||
297 |
DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode); |
|
298 |
||
299 |
XTestFakeKeyEvent(awt_display, |
|
300 |
XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), |
|
301 |
False, |
|
302 |
CurrentTime); |
|
303 |
||
304 |
XSync(awt_display, False); |
|
305 |
||
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_mouseMoveImpl (JNIEnv *env, |
2 | 311 |
jclass cls, |
312 |
jobject xgc, |
|
313 |
jint root_x, |
|
314 |
jint root_y) { |
|
315 |
||
316 |
AwtGraphicsConfigDataPtr adata; |
|
317 |
||
318 |
AWT_LOCK(); |
|
319 |
||
320 |
DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y); |
|
321 |
||
322 |
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); |
|
323 |
DASSERT(adata != NULL); |
|
324 |
||
325 |
XWarpPointer(awt_display, None, XRootWindow(awt_display, adata->awt_visInfo.screen), 0, 0, 0, 0, root_x, root_y); |
|
326 |
XSync(awt_display, False); |
|
327 |
||
328 |
AWT_UNLOCK(); |
|
329 |
} |
|
330 |
||
1962
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 |
* 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
|
333 |
*/ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
334 |
void mouseAction(JNIEnv *env, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
335 |
jclass cls, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
336 |
jint buttonMask, |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
337 |
Bool isMousePress) |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
338 |
{ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
339 |
AWT_LOCK(); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
340 |
|
2810
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
1965
diff
changeset
|
341 |
int32_t num_buttons = getNumButtons(); //from XToolkit.c |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
1965
diff
changeset
|
342 |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
343 |
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
|
344 |
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
|
345 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
346 |
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
|
347 |
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
|
348 |
{ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
349 |
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
|
350 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
351 |
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
|
352 |
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
|
353 |
(num_buttons >= 2)) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
354 |
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
|
355 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
356 |
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
|
357 |
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
|
358 |
(num_buttons >= 3)) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
359 |
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
|
360 |
} |
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 |
if (num_buttons > 3){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
363 |
int32_t i; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
364 |
int32_t button = 0; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
365 |
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
|
366 |
if ((buttonMask & masks[i])) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
367 |
// 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
|
368 |
// 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
|
369 |
// 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
|
370 |
button = i + 3; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
371 |
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
|
372 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
373 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
374 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
375 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
376 |
XSync(awt_display, False); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
377 |
AWT_UNLOCK(); |
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 |
|
1965
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
380 |
JNIEXPORT void JNICALL |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
381 |
Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
382 |
jclass cls, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
383 |
jint buttonMask) { |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
384 |
mouseAction(env, cls, buttonMask, True); |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
385 |
} |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
386 |
|
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
387 |
JNIEXPORT void JNICALL |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
388 |
Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
389 |
jclass cls, |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
390 |
jint buttonMask) { |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
391 |
mouseAction(env, cls, buttonMask, False); |
726a2bc97146
6755110: Solaris build has corrupted with extra mouse buttons RFE
dav
parents:
1962
diff
changeset
|
392 |
} |
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1175
diff
changeset
|
393 |
|
2 | 394 |
JNIEXPORT void JNICALL |
1175
026b52c440fe
6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents:
2
diff
changeset
|
395 |
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env, |
2 | 396 |
jclass cls, |
397 |
jint wheelAmt) { |
|
398 |
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */ |
|
399 |
/* probably could have been hacked into robot_mouseButtonEvent, but it's */ |
|
400 |
/* cleaner to give it its own command type, in case the implementation */ |
|
401 |
/* needs to be changed later. -bchristi, 6/20/01 */ |
|
402 |
||
403 |
int32_t repeat = abs(wheelAmt); |
|
404 |
int32_t button = wheelAmt < 0 ? 4 : 5; /* wheel up: button 4 */ |
|
405 |
/* wheel down: button 5 */ |
|
406 |
int32_t loopIdx; |
|
407 |
||
408 |
AWT_LOCK(); |
|
409 |
||
410 |
DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt); |
|
411 |
||
412 |
for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for */ |
|
413 |
/* wheelAmt == 0 */ |
|
414 |
XTestFakeButtonEvent(awt_display, button, True, CurrentTime); |
|
415 |
XTestFakeButtonEvent(awt_display, button, False, CurrentTime); |
|
416 |
} |
|
417 |
XSync(awt_display, False); |
|
418 |
||
419 |
AWT_UNLOCK(); |
|
420 |
} |