J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. 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 | #include "sun_awt_X11_XlibWrapper.h" |
| 27 | #include <X11/Xlib.h> |
| 28 | #include <X11/keysym.h> |
| 29 | #include <X11/Xutil.h> |
| 30 | #include <X11/Xos.h> |
| 31 | #include <X11/Xatom.h> |
| 32 | #include <X11/extensions/Xdbe.h> |
| 33 | #include <X11/extensions/shape.h> |
| 34 | #include <string.h> |
| 35 | #include <stdlib.h> |
| 36 | |
| 37 | #include <jni.h> |
| 38 | #include <jni_util.h> |
| 39 | #include <jlong.h> |
| 40 | |
| 41 | #include <awt.h> |
| 42 | #include <jvm.h> |
| 43 | |
| 44 | #include <Region.h> |
| 45 | |
| 46 | #if defined(DEBUG) || defined(INTERNAL_BUILD) |
| 47 | static jmethodID lockIsHeldMID = NULL; |
| 48 | |
| 49 | static void |
| 50 | CheckHaveAWTLock(JNIEnv *env) |
| 51 | { |
| 52 | if (lockIsHeldMID == NULL) { |
| 53 | if (tkClass == NULL) return; |
| 54 | lockIsHeldMID = |
| 55 | (*env)->GetStaticMethodID(env, tkClass, |
| 56 | "isAWTLockHeldByCurrentThread", "()Z"); |
| 57 | } |
| 58 | if (!(*env)->CallStaticBooleanMethod(env, tkClass, lockIsHeldMID)) { |
| 59 | JNU_ThrowInternalError(env, "Current thread does not hold AWT_LOCK!"); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | #define AWT_CHECK_HAVE_LOCK() CheckHaveAWTLock(env) |
| 64 | #else |
| 65 | #define AWT_CHECK_HAVE_LOCK() |
| 66 | #endif |
| 67 | |
| 68 | |
| 69 | /* |
| 70 | * Class: XlibWrapper |
| 71 | * Method: XOpenDisplay |
| 72 | * Signature: (J)J |
| 73 | */ |
| 74 | |
| 75 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XOpenDisplay |
| 76 | (JNIEnv *env, jclass clazz, jlong display_name) |
| 77 | { |
| 78 | Display *dp; |
| 79 | AWT_CHECK_HAVE_LOCK(); |
| 80 | dp = XOpenDisplay((char *) jlong_to_ptr(display_name)); |
| 81 | |
| 82 | return ptr_to_jlong(dp); |
| 83 | } |
| 84 | |
| 85 | JNIEXPORT void JNICALL |
| 86 | Java_sun_awt_X11_XlibWrapper_XCloseDisplay(JNIEnv *env, jclass clazz, |
| 87 | jlong display) { |
| 88 | AWT_CHECK_HAVE_LOCK(); |
| 89 | XCloseDisplay((Display*) jlong_to_ptr(display)); |
| 90 | } |
| 91 | |
| 92 | JNIEXPORT jlong JNICALL |
| 93 | Java_sun_awt_X11_XlibWrapper_XDisplayString(JNIEnv *env, jclass clazz, |
| 94 | jlong display) { |
| 95 | AWT_CHECK_HAVE_LOCK(); |
| 96 | return ptr_to_jlong(XDisplayString((Display*) jlong_to_ptr(display))); |
| 97 | } |
| 98 | |
| 99 | JNIEXPORT void JNICALL |
| 100 | Java_sun_awt_X11_XlibWrapper_XSetCloseDownMode(JNIEnv *env, jclass clazz, |
| 101 | jlong display, jint mode) { |
| 102 | AWT_CHECK_HAVE_LOCK(); |
| 103 | XSetCloseDownMode((Display*) jlong_to_ptr(display), (int)mode); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Class: sun_awt_X11_XlibWrapper |
| 108 | * Method: DefaultScreen |
| 109 | * Signature: (J)J |
| 110 | */ |
| 111 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DefaultScreen (JNIEnv *env, jclass clazz, jlong display) { |
| 112 | |
| 113 | AWT_CHECK_HAVE_LOCK(); |
| 114 | return (jlong) DefaultScreen((Display *) jlong_to_ptr(display)); |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Class: sun_awt_X11_XlibWrapper |
| 119 | * Method: ScreenOfDisplay |
| 120 | * Signature: (JJ)J |
| 121 | */ |
| 122 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_ScreenOfDisplay(JNIEnv *env, jclass clazz, jlong display, jlong screen_number) { |
| 123 | AWT_CHECK_HAVE_LOCK(); |
| 124 | return ptr_to_jlong(ScreenOfDisplay((Display *) jlong_to_ptr(display), |
| 125 | screen_number)); |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * Class: sun_awt_X11_XlibWrapper |
| 130 | * Method: DoesBackingStore |
| 131 | * Signature: (J)I |
| 132 | */ |
| 133 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_DoesBackingStore(JNIEnv *env, jclass clazz, jlong screen) { |
| 134 | AWT_CHECK_HAVE_LOCK(); |
| 135 | return (jint) DoesBackingStore((Screen*) jlong_to_ptr(screen)); |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Class: sun_awt_X11_XlibWrapper |
| 140 | * Method: DisplayWidth |
| 141 | * Signature: (JJ)J |
| 142 | */ |
| 143 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayWidth |
| 144 | (JNIEnv *env, jclass clazz, jlong display, jlong screen) { |
| 145 | |
| 146 | AWT_CHECK_HAVE_LOCK(); |
| 147 | return (jlong) DisplayWidth((Display *) jlong_to_ptr(display),screen); |
| 148 | |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Class: sun_awt_X11_XlibWrapper |
| 153 | * Method: DisplayWidthMM |
| 154 | * Signature: (JJ)J |
| 155 | */ |
| 156 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayWidthMM |
| 157 | (JNIEnv *env, jclass clazz, jlong display, jlong screen) { |
| 158 | AWT_CHECK_HAVE_LOCK(); |
| 159 | return (jlong) DisplayWidthMM((Display *) jlong_to_ptr(display),screen); |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Class: sun_awt_X11_XlibWrapper |
| 164 | * Method: DisplayHeight |
| 165 | * Signature: (JJ)J |
| 166 | */ |
| 167 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayHeight |
| 168 | (JNIEnv *env, jclass clazz, jlong display, jlong screen) { |
| 169 | |
| 170 | AWT_CHECK_HAVE_LOCK(); |
| 171 | return (jlong) DisplayHeight((Display *) jlong_to_ptr(display),screen); |
| 172 | } |
| 173 | /* |
| 174 | * Class: sun_awt_X11_XlibWrapper |
| 175 | * Method: DisplayHeightMM |
| 176 | * Signature: (JJ)J |
| 177 | */ |
| 178 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayHeightMM |
| 179 | (JNIEnv *env, jclass clazz, jlong display, jlong screen) { |
| 180 | AWT_CHECK_HAVE_LOCK(); |
| 181 | return (jlong) DisplayHeightMM((Display *) jlong_to_ptr(display),screen); |
| 182 | } |
| 183 | |
| 184 | /* |
| 185 | * Class: sun_awt_X11_XlibWrapper |
| 186 | * Method: RootWindow |
| 187 | * Signature: (JJ)J |
| 188 | */ |
| 189 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_RootWindow |
| 190 | (JNIEnv *env , jclass clazz, jlong display, jlong screen_number) { |
| 191 | AWT_CHECK_HAVE_LOCK(); |
| 192 | return (jlong) RootWindow((Display *) jlong_to_ptr(display), screen_number); |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * Class: sun_awt_X11_XlibWrapper |
| 197 | * Method: ScreenCount |
| 198 | */ |
| 199 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_ScreenCount |
| 200 | (JNIEnv *env , jclass clazz, jlong display) { |
| 201 | AWT_CHECK_HAVE_LOCK(); |
| 202 | return ScreenCount((Display *) jlong_to_ptr(display)); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | /* |
| 207 | * Class: XlibWrapper |
| 208 | * Method: XCreateWindow |
| 209 | * Signature: (JJIIIIIIJJJJ)J |
| 210 | */ |
| 211 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreateWindow |
| 212 | (JNIEnv *env, jclass clazz, jlong display, jlong window, |
| 213 | jint x, jint y, jint w, jint h , jint border_width, jint depth, |
| 214 | jlong wclass, jlong visual, jlong valuemask, jlong attributes) |
| 215 | { |
| 216 | AWT_CHECK_HAVE_LOCK(); |
| 217 | return XCreateWindow((Display *) jlong_to_ptr(display),(Window) window, x, y, w, h, |
| 218 | border_width, depth, wclass, (Visual *) jlong_to_ptr(visual), |
| 219 | valuemask, (XSetWindowAttributes *) jlong_to_ptr(attributes)); |
| 220 | |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Class: XlibWrapper |
| 225 | * Method: XConvertCase |
| 226 | * Signature: (JJJ)V |
| 227 | */ |
| 228 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XConvertCase |
| 229 | (JNIEnv *env, jclass clazz, jlong keysym, |
| 230 | jlong keysym_lowercase, jlong keysym_uppercase) |
| 231 | { |
| 232 | AWT_CHECK_HAVE_LOCK(); |
| 233 | XConvertCase(keysym, (jlong_to_ptr(keysym_lowercase)), |
| 234 | (jlong_to_ptr(keysym_uppercase))); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /* |
| 239 | * Class: XlibWrapper |
| 240 | * Method: XMapWindow |
| 241 | * Signature: (JJ)V |
| 242 | */ |
| 243 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMapWindow |
| 244 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 245 | { |
| 246 | AWT_CHECK_HAVE_LOCK(); |
| 247 | XMapWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 248 | |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Class: XlibWrapper |
| 253 | * Method: XMapRaised |
| 254 | * Signature: (JJ)V |
| 255 | */ |
| 256 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMapRaised |
| 257 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 258 | { |
| 259 | AWT_CHECK_HAVE_LOCK(); |
| 260 | XMapRaised( (Display *)jlong_to_ptr(display),(Window) window); |
| 261 | |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * Class: XlibWrapper |
| 266 | * Method: XRaiseWindow |
| 267 | * Signature: (JJ)V |
| 268 | */ |
| 269 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRaiseWindow |
| 270 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 271 | { |
| 272 | |
| 273 | AWT_CHECK_HAVE_LOCK(); |
| 274 | XRaiseWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 275 | |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * Class: XlibWrapper |
| 280 | * Method: XLowerWindow |
| 281 | * Signature: (JJ)V |
| 282 | */ |
| 283 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XLowerWindow |
| 284 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 285 | { |
| 286 | |
| 287 | AWT_CHECK_HAVE_LOCK(); |
| 288 | XLowerWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 289 | |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Class: XlibWrapper |
| 294 | * Method: XRestackWindows |
| 295 | * Signature: (JJI)V |
| 296 | */ |
| 297 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRestackWindows |
| 298 | (JNIEnv *env, jclass clazz, jlong display, jlong windows, jint length) |
| 299 | { |
| 300 | |
| 301 | AWT_CHECK_HAVE_LOCK(); |
| 302 | XRestackWindows( (Display *) jlong_to_ptr(display), (Window *) jlong_to_ptr(windows), length); |
| 303 | |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * Class: XlibWrapper |
| 308 | * Method: XSetInputFocus |
| 309 | * Signature: (JJ)V |
| 310 | */ |
| 311 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetInputFocus |
| 312 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 313 | { |
| 314 | |
| 315 | AWT_CHECK_HAVE_LOCK(); |
| 316 | XSetInputFocus( (Display *)jlong_to_ptr(display),(Window) window, RevertToPointerRoot, CurrentTime); |
| 317 | |
| 318 | } |
| 319 | /* |
| 320 | * Class: XlibWrapper |
| 321 | * Method: XSetInputFocus2 |
| 322 | * Signature: (JJJ)V |
| 323 | */ |
| 324 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetInputFocus2 |
| 325 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong time) |
| 326 | { |
| 327 | |
| 328 | AWT_CHECK_HAVE_LOCK(); |
| 329 | XSetInputFocus( (Display *)jlong_to_ptr(display),(Window) window, RevertToPointerRoot, time); |
| 330 | |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Class: XlibWrapper |
| 335 | * Method: XGetInputFocus |
| 336 | * Signature: (JJ)V |
| 337 | */ |
| 338 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XGetInputFocus |
| 339 | (JNIEnv *env, jclass clazz, jlong display) |
| 340 | { |
| 341 | |
| 342 | Window focusOwner; |
| 343 | int revert_to; |
| 344 | AWT_CHECK_HAVE_LOCK(); |
| 345 | XGetInputFocus( (Display *)jlong_to_ptr(display), &focusOwner, &revert_to); |
| 346 | return focusOwner; |
| 347 | } |
| 348 | |
| 349 | |
| 350 | /* |
| 351 | * Class: XlibWrapper |
| 352 | * Method: XDestroyWindow |
| 353 | * Signature: (JJ)V |
| 354 | */ |
| 355 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XDestroyWindow |
| 356 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 357 | { |
| 358 | AWT_CHECK_HAVE_LOCK(); |
| 359 | XDestroyWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 360 | } |
| 361 | |
| 362 | JNIEXPORT int JNICALL Java_sun_awt_X11_XlibWrapper_XGrabPointer |
| 363 | (JNIEnv *env, jclass clazz, jlong display, jlong window, |
| 364 | jint owner_events, jint event_mask, jint pointer_mode, |
| 365 | jint keyboard_mode, jlong confine_to, jlong cursor, jlong time) |
| 366 | { |
| 367 | AWT_CHECK_HAVE_LOCK(); |
| 368 | return XGrabPointer( (Display *)jlong_to_ptr(display), (Window) window, |
| 369 | (Bool) owner_events, (unsigned int) event_mask, (int) pointer_mode, |
| 370 | (int) keyboard_mode, (Window) confine_to, (Cursor) cursor, (Time) time); |
| 371 | } |
| 372 | |
| 373 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUngrabPointer |
| 374 | (JNIEnv *env, jclass clazz, jlong display, jlong time) |
| 375 | { |
| 376 | AWT_CHECK_HAVE_LOCK(); |
| 377 | XUngrabPointer( (Display *)jlong_to_ptr(display), (Time) time); |
| 378 | } |
| 379 | |
| 380 | JNIEXPORT int JNICALL Java_sun_awt_X11_XlibWrapper_XGrabKeyboard |
| 381 | (JNIEnv *env, jclass clazz, jlong display, jlong window, |
| 382 | jint owner_events, jint pointer_mode, |
| 383 | jint keyboard_mode, jlong time) |
| 384 | { |
| 385 | AWT_CHECK_HAVE_LOCK(); |
| 386 | return XGrabKeyboard( (Display *)jlong_to_ptr(display), (Window) window, |
| 387 | (Bool) owner_events, (int) pointer_mode, |
| 388 | (int) keyboard_mode, (Time) time); |
| 389 | } |
| 390 | |
| 391 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUngrabKeyboard |
| 392 | (JNIEnv *env, jclass clazz, jlong display, jlong time) |
| 393 | { |
| 394 | AWT_CHECK_HAVE_LOCK(); |
| 395 | XUngrabKeyboard( (Display *)jlong_to_ptr(display), (Time) time); |
| 396 | } |
| 397 | |
| 398 | JNIEXPORT void JNICALL |
| 399 | Java_sun_awt_X11_XlibWrapper_XGrabServer(JNIEnv *env, jclass clazz, |
| 400 | jlong display) { |
| 401 | AWT_CHECK_HAVE_LOCK(); |
| 402 | XGrabServer((Display*)jlong_to_ptr(display)); |
| 403 | } |
| 404 | |
| 405 | JNIEXPORT void JNICALL |
| 406 | Java_sun_awt_X11_XlibWrapper_XUngrabServer(JNIEnv *env, jclass clazz, |
| 407 | jlong display) { |
| 408 | AWT_CHECK_HAVE_LOCK(); |
| 409 | XUngrabServer((Display*)jlong_to_ptr(display)); |
| 410 | /* Workaround for bug 5039226 */ |
| 411 | XSync((Display*)jlong_to_ptr(display), False); |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * Class: XlibWrapper |
| 416 | * Method: XUnmapWindow |
| 417 | * Signature: (JJ)V |
| 418 | */ |
| 419 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUnmapWindow |
| 420 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 421 | { |
| 422 | |
| 423 | AWT_CHECK_HAVE_LOCK(); |
| 424 | XUnmapWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 425 | |
| 426 | } |
| 427 | |
| 428 | |
| 429 | |
| 430 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSelectInput |
| 431 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong mask) |
| 432 | { |
| 433 | AWT_CHECK_HAVE_LOCK(); |
| 434 | XSelectInput((Display *) jlong_to_ptr(display), (Window) window, mask); |
| 435 | } |
| 436 | |
| 437 | /* |
| 438 | * Class: sun_awt_X11_XlibWrapper |
| 439 | * Method: XNextEvent |
| 440 | * Signature: (JJ)V |
| 441 | */ |
| 442 | |
| 443 | |
| 444 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XNextEvent |
| 445 | (JNIEnv *env, jclass clazz, jlong display, jlong ptr) |
| 446 | { |
| 447 | AWT_CHECK_HAVE_LOCK(); |
| 448 | XNextEvent( (Display *) jlong_to_ptr(display), jlong_to_ptr(ptr)); |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | * Class: sun_awt_X11_XlibWrapper |
| 453 | * Method: XMaskEvent |
| 454 | * Signature: (JJJ)V |
| 455 | */ |
| 456 | |
| 457 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMaskEvent |
| 458 | (JNIEnv *env, jclass clazz, jlong display, jlong event_mask, jlong event_return) |
| 459 | { |
| 460 | AWT_CHECK_HAVE_LOCK(); |
| 461 | XMaskEvent( (Display *) jlong_to_ptr(display), event_mask, (XEvent *) jlong_to_ptr(event_return)); |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * Class: sun_awt_X11_XlibWrapper |
| 466 | * Method: XWindowEvent |
| 467 | * Signature: (JJJJ)V |
| 468 | */ |
| 469 | |
| 470 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XWindowEvent |
| 471 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong event_mask, jlong event_return) |
| 472 | { |
| 473 | AWT_CHECK_HAVE_LOCK(); |
| 474 | XWindowEvent( (Display *) jlong_to_ptr(display), (Window)window, event_mask, (XEvent *) jlong_to_ptr(event_return)); |
| 475 | } |
| 476 | |
| 477 | /* |
| 478 | * Class: sun_awt_X11_XlibWrapper |
| 479 | * Method: XFilterEvent |
| 480 | * Signature: (JJ)Z |
| 481 | */ |
| 482 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XFilterEvent |
| 483 | (JNIEnv *env, jclass clazz, jlong ptr, jlong window) |
| 484 | { |
| 485 | AWT_CHECK_HAVE_LOCK(); |
| 486 | return (jboolean) XFilterEvent((XEvent *) jlong_to_ptr(ptr), (Window) window); |
| 487 | } |
| 488 | |
| 489 | /* |
| 490 | * Class: sun_awt_X11_XlibWrapper |
| 491 | * Method: XSupportsLocale |
| 492 | * Signature: ()Z |
| 493 | */ |
| 494 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XSupportsLocale |
| 495 | (JNIEnv *env, jclass clazz) |
| 496 | { |
| 497 | AWT_CHECK_HAVE_LOCK(); |
| 498 | return (jboolean)XSupportsLocale(); |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | * Class: sun_awt_X11_XlibWrapper |
| 503 | * Method: XSetLocaleModifiers |
| 504 | * Signature: (Ljava/lang/String;)Ljava/lang/String; |
| 505 | */ |
| 506 | JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_XSetLocaleModifiers |
| 507 | (JNIEnv *env, jclass clazz, jstring jstr) |
| 508 | { |
| 509 | char * modifier_list = NULL; |
| 510 | char * ret = NULL; |
| 511 | |
| 512 | if (!JNU_IsNull(env, jstr)) { |
| 513 | modifier_list = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); |
| 514 | } |
| 515 | |
| 516 | AWT_CHECK_HAVE_LOCK(); |
| 517 | if (modifier_list) { |
| 518 | ret = XSetLocaleModifiers(modifier_list); |
| 519 | JNU_ReleaseStringPlatformChars(env, jstr, (const char *) modifier_list); |
| 520 | } else { |
| 521 | ret = XSetLocaleModifiers(""); |
| 522 | } |
| 523 | |
| 524 | return (ret != NULL ? JNU_NewStringPlatform(env, ret): NULL); |
| 525 | } |
| 526 | |
| 527 | |
| 528 | /* |
| 529 | * Class: sun_awt_X11_wrappers_XlibWrapper |
| 530 | * Method: XPeekEvent |
| 531 | * Signature: (JJ)V |
| 532 | */ |
| 533 | |
| 534 | |
| 535 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XPeekEvent |
| 536 | (JNIEnv *env, jclass clazz, jlong display, jlong ptr) |
| 537 | { |
| 538 | AWT_CHECK_HAVE_LOCK(); |
| 539 | XPeekEvent((Display *) jlong_to_ptr(display),jlong_to_ptr(ptr)); |
| 540 | } |
| 541 | |
| 542 | |
| 543 | /* |
| 544 | * Class: sun_awt_X11_XlibWrapper |
| 545 | * Method: XMoveResizeWindow |
| 546 | * Signature: (JJIIII)V |
| 547 | */ |
| 548 | |
| 549 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMoveResizeWindow |
| 550 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint x , jint y , jint width, jint height) { |
| 551 | |
| 552 | AWT_CHECK_HAVE_LOCK(); |
| 553 | XMoveResizeWindow( (Display *) jlong_to_ptr(display), (Window) window, x, y, width, height); |
| 554 | |
| 555 | } |
| 556 | |
| 557 | /* |
| 558 | * Class: sun_awt_X11_XlibWrapper |
| 559 | * Method: XResizeWindow |
| 560 | * Signature: (JJII)V |
| 561 | */ |
| 562 | |
| 563 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XResizeWindow |
| 564 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint width, jint height) |
| 565 | { |
| 566 | AWT_CHECK_HAVE_LOCK(); |
| 567 | XResizeWindow( (Display *) jlong_to_ptr(display),(Window) window,width,height); |
| 568 | } |
| 569 | |
| 570 | /* |
| 571 | * Class: sun_awt_X11_XlibWrapper |
| 572 | * Method: XMoveWindow |
| 573 | * Signature: (JJII)V |
| 574 | */ |
| 575 | |
| 576 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMoveWindow |
| 577 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint width, jint height) |
| 578 | { |
| 579 | AWT_CHECK_HAVE_LOCK(); |
| 580 | XMoveWindow( (Display *) jlong_to_ptr(display),(Window) window,width,height); |
| 581 | } |
| 582 | |
| 583 | |
| 584 | /* |
| 585 | * Class: sun_awt_X11_XlibWrapper |
| 586 | * Method: XSetWindowBackground |
| 587 | * Signature: (JJJ)V |
| 588 | */ |
| 589 | |
| 590 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWindowBackground |
| 591 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong background_pixel) { |
| 592 | |
| 593 | AWT_CHECK_HAVE_LOCK(); |
| 594 | XSetWindowBackground((Display *) jlong_to_ptr(display),window,background_pixel); |
| 595 | |
| 596 | } |
| 597 | |
| 598 | |
| 599 | /* |
| 600 | * Class: sun_awt_X11_XlibWrapper |
| 601 | * Method: XFlush |
| 602 | * Signature: (J)V |
| 603 | */ |
| 604 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFlush |
| 605 | (JNIEnv *env, jclass clazz, jlong display) { |
| 606 | |
| 607 | AWT_CHECK_HAVE_LOCK(); |
| 608 | XFlush((Display *)jlong_to_ptr(display)); |
| 609 | } |
| 610 | |
| 611 | /* |
| 612 | * Class: sun_awt_X11_XlibWrapper |
| 613 | * Method: XSync |
| 614 | * Signature: (JI)V |
| 615 | */ |
| 616 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSync |
| 617 | (JNIEnv *env, jclass clazz, jlong display, jint discard) { |
| 618 | |
| 619 | AWT_CHECK_HAVE_LOCK(); |
| 620 | XSync((Display *) jlong_to_ptr(display), discard); |
| 621 | |
| 622 | } |
| 623 | |
| 624 | JNIEXPORT int JNICALL Java_sun_awt_X11_XlibWrapper_XTranslateCoordinates |
| 625 | (JNIEnv *env, jclass clazz, jlong display, jlong src_w, jlong dest_w, |
| 626 | jlong src_x, jlong src_y, jlong dest_x_return, jlong dest_y_return, |
| 627 | jlong child_return) |
| 628 | { |
| 629 | AWT_CHECK_HAVE_LOCK(); |
| 630 | return XTranslateCoordinates( (Display *) jlong_to_ptr(display), src_w, dest_w, |
| 631 | src_x, src_y, |
| 632 | (int *) jlong_to_ptr(dest_x_return), |
| 633 | (int *) jlong_to_ptr(dest_y_return), |
| 634 | (Window *) jlong_to_ptr(child_return)); |
| 635 | } |
| 636 | |
| 637 | JNIEXPORT int JNICALL Java_sun_awt_X11_XlibWrapper_XEventsQueued |
| 638 | (JNIEnv *env, jclass clazz, jlong display, jint mode) { |
| 639 | |
| 640 | AWT_CHECK_HAVE_LOCK(); |
| 641 | return XEventsQueued((Display *) jlong_to_ptr(display), mode); |
| 642 | |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | * Class: sun_awt_X11_XlibWrapper |
| 647 | * Method: SetProperty |
| 648 | * Signature: (JJJLjava/lang/String;)V |
| 649 | */ |
| 650 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_SetProperty |
| 651 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom, jstring jstr) { |
| 652 | char *cname; |
| 653 | XTextProperty tp; |
| 654 | int32_t status; |
| 655 | |
| 656 | /* |
| 657 | In case there are direct support of UTF-8 declared, use UTF-8 strings. |
| 658 | */ |
| 659 | if (!JNU_IsNull(env, jstr)) { |
| 660 | #ifdef X_HAVE_UTF8_STRING |
| 661 | cname = (char *) (*env)->GetStringUTFChars(env, jstr, JNI_FALSE); |
| 662 | #else |
| 663 | cname = (char *) JNU_GetStringPlatformChars(env, jstr, NULL); |
| 664 | #endif |
| 665 | } else { |
| 666 | cname = ""; |
| 667 | } |
| 668 | |
| 669 | |
| 670 | AWT_CHECK_HAVE_LOCK(); |
| 671 | |
| 672 | #ifdef X_HAVE_UTF8_STRING |
| 673 | status = Xutf8TextListToTextProperty((Display *)jlong_to_ptr(display), &cname, 1, |
| 674 | XStdICCTextStyle, &tp); |
| 675 | #else |
| 676 | status = XmbTextListToTextProperty((Display *)jlong_to_ptr(display), &cname, 1, |
| 677 | XStdICCTextStyle, &tp); |
| 678 | #endif |
| 679 | |
| 680 | |
| 681 | if (status == Success || status > 0) { |
| 682 | XChangeProperty((Display *)jlong_to_ptr(display), window, atom, tp.encoding, tp.format, PropModeReplace, tp.value, tp.nitems); |
| 683 | if (tp.value != NULL) { |
| 684 | XFree(tp.value); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | if (!JNU_IsNull(env, jstr)) { |
| 689 | #ifdef X_HAVE_UTF8_STRING |
| 690 | (*env)->ReleaseStringUTFChars(env, jstr, (const char *) cname); |
| 691 | #else |
| 692 | JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); |
| 693 | #endif |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | /* |
| 698 | * Class: sun_awt_X11_XlibWrapper |
| 699 | * Method: XChangeProperty |
| 700 | * Signature: (JJJJJJJJJJJ)V |
| 701 | */ |
| 702 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangePropertyImpl( |
| 703 | JNIEnv *env, jclass clazz, jlong display, jlong window, jlong property, |
| 704 | jlong type, jint format, jint mode, jlong data, jint nelements) |
| 705 | { |
| 706 | AWT_CHECK_HAVE_LOCK(); |
| 707 | XChangeProperty((Display*) jlong_to_ptr(display), (Window) window, (Atom) property, |
| 708 | (Atom) type, format, mode, (unsigned char*) jlong_to_ptr(data), |
| 709 | nelements); |
| 710 | } |
| 711 | /* |
| 712 | * Class: sun_awt_X11_XlibWrapper |
| 713 | * Method: XChangePropertyS |
| 714 | * Signature: (JJJJJJJJJLjava/lang/String;)V |
| 715 | */ |
| 716 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangePropertyS( |
| 717 | JNIEnv *env, jclass clazz, jlong display, jlong window, jlong property, |
| 718 | jlong type, jint format, jint mode, jstring value) |
| 719 | { |
| 720 | jboolean iscopy; |
| 721 | const char * chars = JNU_GetStringPlatformChars(env, value, &iscopy); |
| 722 | AWT_CHECK_HAVE_LOCK(); |
| 723 | XChangeProperty((Display*)jlong_to_ptr(display), window, (Atom)property, |
| 724 | (Atom)type, format, mode, (unsigned char*)chars, strlen(chars)); |
| 725 | if (iscopy) { |
| 726 | JNU_ReleaseStringPlatformChars(env, value, chars); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | /* |
| 731 | * Class: sun_awt_X11_XlibWrapper |
| 732 | * Method: XGetWindowProperty |
| 733 | * Signature: (JJJJJJJJJJJ)J; |
| 734 | */ |
| 735 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWindowProperty |
| 736 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong property, jlong long_offset, |
| 737 | jlong long_length, jlong delete, jlong req_type, jlong actual_type, |
| 738 | jlong actual_format, jlong nitems_ptr, jlong bytes_after, jlong data_ptr) |
| 739 | { |
| 740 | AWT_CHECK_HAVE_LOCK(); |
| 741 | return XGetWindowProperty((Display*) jlong_to_ptr(display), window, property, long_offset, long_length, |
| 742 | delete, (Atom) req_type, (Atom*) jlong_to_ptr(actual_type), |
| 743 | (int *) jlong_to_ptr(actual_format), (unsigned long *) jlong_to_ptr(nitems_ptr), |
| 744 | (unsigned long*) jlong_to_ptr(bytes_after), (unsigned char**) jlong_to_ptr(data_ptr)); |
| 745 | } |
| 746 | |
| 747 | /* |
| 748 | * Class: sun_awt_X11_XlibWrapper |
| 749 | * Method: GetProperty |
| 750 | * Signature: (JJJ)Ljava/lang/String; |
| 751 | */ |
| 752 | JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_GetProperty |
| 753 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom) |
| 754 | { |
| 755 | /* Request status */ |
| 756 | int status; |
| 757 | |
| 758 | /* Returns of XGetWindowProperty */ |
| 759 | Atom actual_type; |
| 760 | int actual_format; |
| 761 | unsigned long nitems; |
| 762 | unsigned long bytes_after; |
| 763 | unsigned char * string; |
| 764 | jstring res; |
| 765 | AWT_CHECK_HAVE_LOCK(); |
| 766 | status = XGetWindowProperty((Display*)jlong_to_ptr(display), window, |
| 767 | atom, 0, 0xFFFF, False, XA_STRING, |
| 768 | &actual_type, &actual_format, &nitems, &bytes_after, |
| 769 | &string); |
| 770 | if (status != Success || string == NULL) { |
| 771 | return NULL; |
| 772 | } |
| 773 | |
| 774 | if (actual_type != XA_STRING || actual_format != 8) { |
| 775 | XFree(string); |
| 776 | return NULL; |
| 777 | } |
| 778 | |
| 779 | // Memory leak??? |
| 780 | return JNU_NewStringPlatform(env,(char*) string); |
| 781 | } |
| 782 | |
| 783 | /* |
| 784 | * Class: sun_awt_X11_XlibWrapper |
| 785 | * Method: InternAtom |
| 786 | * Signature: (JLjava/lang/String;I)J |
| 787 | */ |
| 788 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_InternAtom |
| 789 | (JNIEnv *env, jclass clazz, jlong display, jstring jstr, jint ife) { |
| 790 | |
| 791 | char *cname; |
| 792 | unsigned long atom; |
| 793 | |
| 794 | if (!JNU_IsNull(env, jstr)) { |
| 795 | cname = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); |
| 796 | } else { |
| 797 | cname = ""; |
| 798 | } |
| 799 | |
| 800 | AWT_CHECK_HAVE_LOCK(); |
| 801 | atom = XInternAtom((Display *) jlong_to_ptr(display), cname, ife); |
| 802 | |
| 803 | if (!JNU_IsNull(env, jstr)) { |
| 804 | JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); |
| 805 | } |
| 806 | |
| 807 | return (jlong) atom; |
| 808 | |
| 809 | } |
| 810 | |
| 811 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XCreateFontCursor |
| 812 | (JNIEnv *env, jclass clazz, jlong display, jint shape) { |
| 813 | AWT_CHECK_HAVE_LOCK(); |
| 814 | return XCreateFontCursor((Display *) jlong_to_ptr(display), (int) shape); |
| 815 | } |
| 816 | |
| 817 | |
| 818 | /* |
| 819 | * Class: sun_awt_X11_XlibWrapper |
| 820 | * Method: XCreatePixmapCursor |
| 821 | * Signature: (JJJJJII)J |
| 822 | */ |
| 823 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreatePixmapCursor |
| 824 | (JNIEnv *env , jclass clazz, jlong display, jlong source, jlong mask, jlong fore, jlong back, jint x , jint y) { |
| 825 | |
| 826 | AWT_CHECK_HAVE_LOCK(); |
| 827 | return (jlong) XCreatePixmapCursor((Display *) jlong_to_ptr(display), (Pixmap) source, (Pixmap) mask, |
| 828 | (XColor *) jlong_to_ptr(fore), (XColor *) jlong_to_ptr(back), x, y); |
| 829 | } |
| 830 | |
| 831 | |
| 832 | /* |
| 833 | * Class: sun_awt_X11_XlibWrapper |
| 834 | * Method: XQueryBestCursor |
| 835 | * Signature: (JJIIJJ)Z |
| 836 | */ |
| 837 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryBestCursor |
| 838 | (JNIEnv *env, jclass clazz, jlong display, jlong drawable, jint width, jint height, jlong width_return, jlong height_return) { |
| 839 | |
| 840 | Status status; |
| 841 | |
| 842 | AWT_CHECK_HAVE_LOCK(); |
| 843 | status = XQueryBestCursor((Display *) jlong_to_ptr(display), (Drawable) drawable, width,height, |
| 844 | (unsigned int *) jlong_to_ptr(width_return), (unsigned int *) jlong_to_ptr(height_return)); |
| 845 | |
| 846 | if (status == 0) return JNI_FALSE; |
| 847 | else return JNI_TRUE; |
| 848 | } |
| 849 | |
| 850 | |
| 851 | /* |
| 852 | * Class: sun_awt_X11_XlibWrapper |
| 853 | * Method: XFreeCursor |
| 854 | * Signature: (JJ)V |
| 855 | */ |
| 856 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFreeCursor |
| 857 | (JNIEnv *env, jclass clazz, jlong display, jlong cursor) { |
| 858 | |
| 859 | AWT_CHECK_HAVE_LOCK(); |
| 860 | XFreeCursor( (Display *) jlong_to_ptr(display), (Cursor) cursor); |
| 861 | } |
| 862 | |
| 863 | /* |
| 864 | * Class: sun_awt_X11_XlibWrapper |
| 865 | * Method: XQueryPointer |
| 866 | * Signature: (JJJJJJJJJ)Z |
| 867 | */ |
| 868 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryPointer |
| 869 | (JNIEnv *env, jclass clazz, jlong display, jlong w, jlong root_return, jlong child_return, jlong root_x_return , jlong root_y_return, jlong win_x_return, jlong win_y_return, jlong mask_return) { |
| 870 | |
| 871 | Bool b; |
| 872 | |
| 873 | AWT_CHECK_HAVE_LOCK(); |
| 874 | b = XQueryPointer((Display *) jlong_to_ptr(display), |
| 875 | (Window) w, (Window *) jlong_to_ptr(root_return), (Window *) jlong_to_ptr(child_return), |
| 876 | (int *) jlong_to_ptr(root_x_return), (int *) jlong_to_ptr(root_y_return), |
| 877 | (int *) jlong_to_ptr(win_x_return), (int *) jlong_to_ptr(win_y_return), |
| 878 | (unsigned int *) jlong_to_ptr(mask_return)); |
| 879 | if (b == True) return JNI_TRUE; |
| 880 | else return JNI_FALSE; |
| 881 | |
| 882 | } |
| 883 | |
| 884 | /* |
| 885 | * Class: sun_awt_X11_XlibWrapper |
| 886 | * Method: XChangeWindowAttributes |
| 887 | * Signature: (JJJJ)V |
| 888 | */ |
| 889 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangeWindowAttributes |
| 890 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong valuemask, jlong attributes) { |
| 891 | |
| 892 | AWT_CHECK_HAVE_LOCK(); |
| 893 | XChangeWindowAttributes((Display *) jlong_to_ptr(display), (Window) window, (unsigned long) valuemask, |
| 894 | (XSetWindowAttributes *) jlong_to_ptr(attributes)); |
| 895 | } |
| 896 | |
| 897 | |
| 898 | /* |
| 899 | * Class: sun_awt_X11_XlibWrapper |
| 900 | * Method: XSetTransientFor |
| 901 | * Signature: (JJJ)V |
| 902 | */ |
| 903 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetTransientFor |
| 904 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong transient_for_window) |
| 905 | { |
| 906 | AWT_CHECK_HAVE_LOCK(); |
| 907 | XSetTransientForHint((Display *) jlong_to_ptr(display), window, transient_for_window); |
| 908 | } |
| 909 | |
| 910 | /* |
| 911 | * Class: sun_awt_X11_XlibWrapper |
| 912 | * Method: XSetWMHints |
| 913 | * Signature: (JJJ)V |
| 914 | */ |
| 915 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWMHints |
| 916 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints) |
| 917 | { |
| 918 | AWT_CHECK_HAVE_LOCK(); |
| 919 | XSetWMHints((Display *) jlong_to_ptr(display), window, (XWMHints *) jlong_to_ptr(hints)); |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | * Class: sun_awt_X11_XlibWrapper |
| 924 | * Method: XGetWMHints |
| 925 | * Signature: (JJJ)V |
| 926 | */ |
| 927 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XGetWMHints |
| 928 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints) |
| 929 | { |
| 930 | XWMHints * get_hints; |
| 931 | AWT_CHECK_HAVE_LOCK(); |
| 932 | get_hints = XGetWMHints((Display*)jlong_to_ptr(display), window); |
| 933 | if (get_hints != NULL) { |
| 934 | memcpy(jlong_to_ptr(hints), get_hints, sizeof(XWMHints)); |
| 935 | XFree(get_hints); |
| 936 | } else { |
| 937 | memset(jlong_to_ptr(hints), 0, sizeof(XWMHints)); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | /* |
| 942 | * Class: sun_awt_X11_XlibWrapper |
| 943 | * Method: XGetPointerMapping |
| 944 | * Signature: (JJI)I |
| 945 | */ |
| 946 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetPointerMapping |
| 947 | (JNIEnv *env, jclass clazz, jlong display, jlong map, jint buttonNumber) |
| 948 | { |
| 949 | AWT_CHECK_HAVE_LOCK(); |
| 950 | return XGetPointerMapping((Display*)jlong_to_ptr(display), (unsigned char*) jlong_to_ptr(map), buttonNumber); |
| 951 | } |
| 952 | |
| 953 | /* |
| 954 | * Class: sun_awt_X11_XlibWrapper |
| 955 | * Method: XGetDefault |
| 956 | * Signature: (JJI)I |
| 957 | */ |
| 958 | JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_XGetDefault |
| 959 | (JNIEnv *env, jclass clazz, jlong display, jstring program, jstring option) |
| 960 | { |
| 961 | char * c_program = NULL; |
| 962 | char * c_option = NULL; |
| 963 | char * c_res = NULL; |
| 964 | |
| 965 | if (!JNU_IsNull(env, program)) { |
| 966 | c_program = (char *)JNU_GetStringPlatformChars(env, program, NULL); |
| 967 | } |
| 968 | if (!JNU_IsNull(env, option)) { |
| 969 | c_option = (char *)JNU_GetStringPlatformChars(env, option, NULL); |
| 970 | } |
| 971 | |
| 972 | if (c_program == NULL || c_option == NULL) { |
| 973 | if (!JNU_IsNull(env, program)) { |
| 974 | JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program); |
| 975 | } |
| 976 | if (!JNU_IsNull(env, option)) { |
| 977 | JNU_ReleaseStringPlatformChars(env, option, (const char *) c_option); |
| 978 | } |
| 979 | return NULL; |
| 980 | } |
| 981 | AWT_CHECK_HAVE_LOCK(); |
| 982 | c_res = XGetDefault((Display*)jlong_to_ptr(display), c_program, c_option); |
| 983 | |
| 984 | if (!JNU_IsNull(env, program)) { |
| 985 | JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program); |
| 986 | } |
| 987 | if (!JNU_IsNull(env, option)) { |
| 988 | JNU_ReleaseStringPlatformChars(env, option, (const char *) c_option); |
| 989 | } |
| 990 | |
| 991 | if (c_res != NULL) { |
| 992 | // Memory leak??? |
| 993 | return JNU_NewStringPlatform(env, c_res); |
| 994 | } else { |
| 995 | return NULL; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | /* |
| 1001 | * Class: sun_awt_X11_XlibWrapper |
| 1002 | * Method: getScreenOfWindow |
| 1003 | * Signature: (JJ)J |
| 1004 | */ |
| 1005 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_getScreenOfWindow |
| 1006 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 1007 | { |
| 1008 | XWindowAttributes attrs; |
| 1009 | memset(&attrs, 0, sizeof(attrs)); |
| 1010 | AWT_CHECK_HAVE_LOCK(); |
| 1011 | XGetWindowAttributes((Display *) jlong_to_ptr(display), window, &attrs); |
| 1012 | return ptr_to_jlong(attrs.screen); |
| 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * Class: sun_awt_X11_XlibWrapper |
| 1017 | * Method: XScreenNumberOfScreen |
| 1018 | * Signature: (J)J |
| 1019 | */ |
| 1020 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XScreenNumberOfScreen |
| 1021 | (JNIEnv *env, jclass clazz, jlong screen) |
| 1022 | { |
| 1023 | AWT_CHECK_HAVE_LOCK(); |
| 1024 | if(jlong_to_ptr(screen) == NULL) { |
| 1025 | return -1; |
| 1026 | } |
| 1027 | return XScreenNumberOfScreen((Screen*) jlong_to_ptr(screen)); |
| 1028 | } |
| 1029 | |
| 1030 | /* |
| 1031 | * Class: sun_awt_X11_XlibWrapper |
| 1032 | * Method: XIconifyWindow |
| 1033 | * Signature: (JJJ)V |
| 1034 | */ |
| 1035 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XIconifyWindow |
| 1036 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong screenNumber) |
| 1037 | { |
| 1038 | AWT_CHECK_HAVE_LOCK(); |
| 1039 | return XIconifyWindow((Display*) jlong_to_ptr(display), window, screenNumber); |
| 1040 | } |
| 1041 | |
| 1042 | /* |
| 1043 | * Class: sun_awt_X11_XlibWrapper |
| 1044 | * Method: XFree |
| 1045 | * Signature: (J)V |
| 1046 | */ |
| 1047 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFree |
| 1048 | (JNIEnv *env, jclass clazz, jlong ptr) |
| 1049 | { |
| 1050 | AWT_CHECK_HAVE_LOCK(); |
| 1051 | XFree(jlong_to_ptr(ptr)); |
| 1052 | } |
| 1053 | |
| 1054 | /* |
| 1055 | * Class: sun_awt_X11_XlibWrapper |
| 1056 | * Method: XFree |
| 1057 | * Signature: (J)V |
| 1058 | */ |
| 1059 | JNIEXPORT jbyteArray JNICALL Java_sun_awt_X11_XlibWrapper_getStringBytes |
| 1060 | (JNIEnv *env, jclass clazz, jlong str_ptr) |
| 1061 | { |
| 1062 | unsigned char * str = (unsigned char*) jlong_to_ptr(str_ptr); |
| 1063 | long length = strlen((char*)str); |
| 1064 | jbyteArray res = (*env)->NewByteArray(env, length); |
| 1065 | void * storage = malloc(length+1); |
| 1066 | memcpy(storage, str, length+1); |
| 1067 | (*env)->SetByteArrayRegion(env, res, 0, length, |
| 1068 | (const signed char*) storage); |
| 1069 | return res; |
| 1070 | } |
| 1071 | |
| 1072 | |
| 1073 | /* |
| 1074 | * Class: sun_awt_X11_XlibWrapper |
| 1075 | * Method: ServerVendor |
| 1076 | * Signature: (J)Ljava/lang/String; |
| 1077 | */ |
| 1078 | JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_ServerVendor |
| 1079 | (JNIEnv *env, jclass clazz, jlong display) |
| 1080 | { |
| 1081 | AWT_CHECK_HAVE_LOCK(); |
| 1082 | return JNU_NewStringPlatform(env, ServerVendor((Display*)jlong_to_ptr(display))); |
| 1083 | } |
| 1084 | /* |
| 1085 | * Class: sun_awt_X11_XlibWrapper |
| 1086 | * Method: VendorRelease |
| 1087 | * Signature: (J)I; |
| 1088 | */ |
| 1089 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_VendorRelease |
| 1090 | (JNIEnv *env, jclass clazz, jlong display) |
| 1091 | { |
| 1092 | AWT_CHECK_HAVE_LOCK(); |
| 1093 | return VendorRelease((Display*)jlong_to_ptr(display)); |
| 1094 | } |
| 1095 | |
| 1096 | JavaVM* jvm = NULL; |
| 1097 | static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) { |
| 1098 | if (jvm != NULL) { |
| 1099 | JNIEnv * env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
| 1100 | return JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit", "GlobalErrorHandler", "(JJ)I", |
| 1101 | ptr_to_jlong(dpy), ptr_to_jlong(event)).i; |
| 1102 | } else { |
| 1103 | return 0; |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | /* |
| 1108 | * Class: sun_awt_X11_XlibWrapper |
| 1109 | * Method: SetToolkitErrorHandler |
| 1110 | * Signature: ()J |
| 1111 | */ |
| 1112 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_SetToolkitErrorHandler |
| 1113 | (JNIEnv *env, jclass clazz) |
| 1114 | { |
| 1115 | (*env)->GetJavaVM(env, &jvm); |
| 1116 | AWT_CHECK_HAVE_LOCK(); |
| 1117 | return ptr_to_jlong(XSetErrorHandler(ToolkitErrorHandler)); |
| 1118 | } |
| 1119 | |
| 1120 | /* |
| 1121 | * Class: sun_awt_X11_XlibWrapper |
| 1122 | * Method: XSetErrorHandler |
| 1123 | * Signature: (J)V |
| 1124 | */ |
| 1125 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetErrorHandler |
| 1126 | (JNIEnv *env, jclass clazz, jlong handler) |
| 1127 | { |
| 1128 | AWT_CHECK_HAVE_LOCK(); |
| 1129 | XSetErrorHandler((XErrorHandler) jlong_to_ptr(handler)); |
| 1130 | } |
| 1131 | |
| 1132 | /* |
| 1133 | * Class: sun_awt_X11_XlibWrapper |
| 1134 | * Method: CallErrorHandler |
| 1135 | * Signature: (JJJ)I |
| 1136 | */ |
| 1137 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_CallErrorHandler |
| 1138 | (JNIEnv *env, jclass clazz, jlong handler, jlong display, jlong event_ptr) |
| 1139 | { |
| 1140 | return (*(XErrorHandler)jlong_to_ptr(handler))((Display*) jlong_to_ptr(display), (XErrorEvent*) jlong_to_ptr(event_ptr)); |
| 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | |
| 1145 | /* |
| 1146 | * Class: sun_awt_X11_XlibWrapper |
| 1147 | * Method: XInternAtoms |
| 1148 | * Signature: (J[Ljava/lang/String;ZJ)I |
| 1149 | */ |
| 1150 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XInternAtoms |
| 1151 | (JNIEnv *env, jclass clazz, jlong display, jobjectArray names_arr, jboolean only_if_exists, jlong atoms) |
| 1152 | { |
| 1153 | |
| 1154 | int length = (*env)->GetArrayLength(env, names_arr); |
| 1155 | char ** names = (char**)malloc(length*sizeof(char*)); |
| 1156 | jboolean copy; |
| 1157 | int index, name_index = 0; |
| 1158 | int status; |
| 1159 | for (index = 0; index < length; index++) { |
| 1160 | jstring str = (*env)->GetObjectArrayElement(env, names_arr, index); |
| 1161 | if (!JNU_IsNull(env, str)) { |
| 1162 | const char * str_char = JNU_GetStringPlatformChars(env, str, NULL); |
| 1163 | names[name_index++] = strdup(str_char); |
| 1164 | JNU_ReleaseStringPlatformChars(env, str, str_char); |
| 1165 | (*env)->DeleteLocalRef(env, str); |
| 1166 | } |
| 1167 | } |
| 1168 | AWT_CHECK_HAVE_LOCK(); |
| 1169 | status = XInternAtoms((Display*)jlong_to_ptr(display), names, name_index, only_if_exists, (Atom*) jlong_to_ptr(atoms)); |
| 1170 | for (index = 0; index < length; index++) { |
| 1171 | free(names[index]); |
| 1172 | } |
| 1173 | free(names); |
| 1174 | return status; |
| 1175 | } |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | /* |
| 1180 | * Class: sun_awt_X11_XlibWrapper |
| 1181 | * Method: XGetWindowAttributes |
| 1182 | * Signature: (JJJ)I |
| 1183 | */ |
| 1184 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWindowAttributes |
| 1185 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong attr_ptr) |
| 1186 | { |
| 1187 | jint status; |
| 1188 | AWT_CHECK_HAVE_LOCK(); |
| 1189 | memset((XWindowAttributes*) jlong_to_ptr(attr_ptr), 0, sizeof(XWindowAttributes)); |
| 1190 | status = XGetWindowAttributes((Display*)jlong_to_ptr(display), window, (XWindowAttributes*) jlong_to_ptr(attr_ptr)); |
| 1191 | return status; |
| 1192 | } |
| 1193 | |
| 1194 | |
| 1195 | /* |
| 1196 | * Class: sun_awt_X11_XlibWrapper |
| 1197 | * Method: XGetGeometry |
| 1198 | * Signature: (JJJJJJJJJ)I |
| 1199 | */ |
| 1200 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetGeometry |
| 1201 | (JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong root_return, |
| 1202 | jlong x_return, jlong y_return, jlong width_return, jlong height_return, |
| 1203 | jlong border_width_return, jlong depth_return) |
| 1204 | { |
| 1205 | jint status; |
| 1206 | AWT_CHECK_HAVE_LOCK(); |
| 1207 | status = XGetGeometry((Display *)jlong_to_ptr(display), |
| 1208 | (Drawable)drawable, (Window *)jlong_to_ptr(root_return), |
| 1209 | (int *)jlong_to_ptr(x_return), (int *)jlong_to_ptr(y_return), |
| 1210 | (unsigned int *)jlong_to_ptr(width_return), (unsigned int *)jlong_to_ptr(height_return), |
| 1211 | (unsigned int *)jlong_to_ptr(border_width_return), |
| 1212 | (unsigned int *)jlong_to_ptr(depth_return)); |
| 1213 | return status; |
| 1214 | } |
| 1215 | |
| 1216 | |
| 1217 | /* |
| 1218 | * Class: sun_awt_X11_XlibWrapper |
| 1219 | * Method: XGetWMNormalHints |
| 1220 | * Signature: (JJJJ)I |
| 1221 | */ |
| 1222 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWMNormalHints |
| 1223 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints, jlong supplied_return) |
| 1224 | { |
| 1225 | AWT_CHECK_HAVE_LOCK(); |
| 1226 | return XGetWMNormalHints((Display*) jlong_to_ptr(display), |
| 1227 | window, |
| 1228 | (XSizeHints*) jlong_to_ptr(hints), |
| 1229 | (long*) jlong_to_ptr(supplied_return)); |
| 1230 | } |
| 1231 | |
| 1232 | /* |
| 1233 | * Class: sun_awt_X11_XlibWrapper |
| 1234 | * Method: XSetWMNormalHints |
| 1235 | * Signature: (JJJ)V |
| 1236 | */ |
| 1237 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWMNormalHints |
| 1238 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints) |
| 1239 | { |
| 1240 | AWT_CHECK_HAVE_LOCK(); |
| 1241 | XSetWMNormalHints((Display*) jlong_to_ptr(display), window, (XSizeHints*) jlong_to_ptr(hints)); |
| 1242 | } |
| 1243 | |
| 1244 | /* |
| 1245 | * Class: sun_awt_X11_XlibWrapper |
| 1246 | * Method: XDeleteProperty |
| 1247 | * Signature: (JJJ)V |
| 1248 | */ |
| 1249 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XDeleteProperty |
| 1250 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom) |
| 1251 | { |
| 1252 | AWT_CHECK_HAVE_LOCK(); |
| 1253 | XDeleteProperty((Display*) jlong_to_ptr(display), window, (Atom)atom); |
| 1254 | } |
| 1255 | |
| 1256 | /* |
| 1257 | * Class: sun_awt_X11_XlibWrapper |
| 1258 | * Method: XSendEvent |
| 1259 | * Signature: (JJZJJ)V |
| 1260 | */ |
| 1261 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XSendEvent |
| 1262 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jboolean propagate, jlong event_mask, jlong event) |
| 1263 | { |
| 1264 | AWT_CHECK_HAVE_LOCK(); |
| 1265 | return XSendEvent((Display*) jlong_to_ptr(display), |
| 1266 | window, |
| 1267 | propagate==JNI_TRUE?True:False, |
| 1268 | (long) event_mask, |
| 1269 | (XEvent*) jlong_to_ptr(event)); |
| 1270 | } |
| 1271 | |
| 1272 | |
| 1273 | /* |
| 1274 | * Class: sun_awt_X11_XlibWrapper |
| 1275 | * Method: XQueryTree |
| 1276 | * Signature: (JJJJJJ)I |
| 1277 | */ |
| 1278 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XQueryTree |
| 1279 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong root_return, jlong parent_return, jlong children_return, jlong nchildren_return) |
| 1280 | { |
| 1281 | AWT_CHECK_HAVE_LOCK(); |
| 1282 | return XQueryTree((Display*) jlong_to_ptr(display), |
| 1283 | window, |
| 1284 | (Window *) jlong_to_ptr(root_return), |
| 1285 | (Window*) jlong_to_ptr(parent_return), |
| 1286 | (Window**) jlong_to_ptr(children_return), |
| 1287 | (unsigned int*) jlong_to_ptr(nchildren_return)); |
| 1288 | } |
| 1289 | |
| 1290 | |
| 1291 | /* |
| 1292 | * Class: sun_awt_X11_XlibWrapper |
| 1293 | * Method: memcpy |
| 1294 | * Signature: (JJJ)V |
| 1295 | */ |
| 1296 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_memcpy |
| 1297 | (JNIEnv *env, jclass clazz, jlong dest_ptr, jlong src_ptr, jlong length) |
| 1298 | { |
| 1299 | memcpy(jlong_to_ptr(dest_ptr), jlong_to_ptr(src_ptr), length); |
| 1300 | } |
| 1301 | |
| 1302 | |
| 1303 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetMinMaxHints |
| 1304 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint x, jint y, jint width, jint height, jlong flags) { |
| 1305 | XSizeHints * hints; |
| 1306 | AWT_CHECK_HAVE_LOCK(); |
| 1307 | hints = XAllocSizeHints(); |
| 1308 | hints->flags = flags; |
| 1309 | hints->width = width; |
| 1310 | hints->min_width = width; |
| 1311 | hints->max_width = width; |
| 1312 | hints->height = height; |
| 1313 | hints->min_height = height; |
| 1314 | hints->max_height = height; |
| 1315 | hints->x = x; |
| 1316 | hints->y = y; |
| 1317 | XSetWMNormalHints((Display*) jlong_to_ptr(display), window, hints); |
| 1318 | XFree(hints); |
| 1319 | } |
| 1320 | |
| 1321 | |
| 1322 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XGetVisualInfo |
| 1323 | (JNIEnv *env, jclass clazz, jlong display, jlong vinfo_mask, jlong vinfo_template, |
| 1324 | jlong nitems_return) |
| 1325 | { |
| 1326 | AWT_CHECK_HAVE_LOCK(); |
| 1327 | return ptr_to_jlong(XGetVisualInfo((Display*) jlong_to_ptr(display), |
| 1328 | (long) vinfo_mask, |
| 1329 | (XVisualInfo*) jlong_to_ptr(vinfo_template), |
| 1330 | (int*) jlong_to_ptr(nitems_return))); |
| 1331 | } |
| 1332 | |
| 1333 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XAllocSizeHints |
| 1334 | (JNIEnv *env, jclass clazz) |
| 1335 | { |
| 1336 | AWT_CHECK_HAVE_LOCK(); |
| 1337 | return ptr_to_jlong(XAllocSizeHints()); |
| 1338 | } |
| 1339 | |
| 1340 | /* |
| 1341 | * Class: sun_awt_X11_XlibWrapper |
| 1342 | * Method: XIconifyWindow |
| 1343 | * Signature: (JJJ)V |
| 1344 | */ |
| 1345 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XBell |
| 1346 | (JNIEnv *env, jclass clazz, jlong display, jint percent) |
| 1347 | { |
| 1348 | AWT_CHECK_HAVE_LOCK(); |
| 1349 | XBell((Display*)jlong_to_ptr(display), percent); |
| 1350 | } |
| 1351 | |
| 1352 | |
| 1353 | /* |
| 1354 | * Class: sun_awt_X11_XlibWrapper |
| 1355 | * Method: XAllocColor |
| 1356 | * Signature: (JJJ)Z |
| 1357 | */ |
| 1358 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XAllocColor |
| 1359 | (JNIEnv *env, jclass clazz, jlong display , jlong colormap, jlong xcolor) { |
| 1360 | |
| 1361 | Status status; |
| 1362 | AWT_CHECK_HAVE_LOCK(); |
| 1363 | status = XAllocColor((Display *) jlong_to_ptr(display), (Colormap) colormap, (XColor *) jlong_to_ptr(xcolor)); |
| 1364 | |
| 1365 | if (status == 0) return JNI_FALSE; |
| 1366 | else return JNI_TRUE; |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | /* |
| 1371 | * Class: sun_awt_X11_XlibWrapper |
| 1372 | * Method: XCreateBitmapFromData |
| 1373 | * Signature: (JJJII)J |
| 1374 | */ |
| 1375 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreateBitmapFromData |
| 1376 | (JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong data, jint width, jint height) { |
| 1377 | AWT_CHECK_HAVE_LOCK(); |
| 1378 | |
| 1379 | return (jlong) XCreateBitmapFromData((Display *) jlong_to_ptr(display), (Drawable) drawable, |
| 1380 | (char *) jlong_to_ptr(data), width, height); |
| 1381 | } |
| 1382 | |
| 1383 | |
| 1384 | /* |
| 1385 | * Class: sun_awt_X11_XlibWrapper |
| 1386 | * Method: XFreePixmap |
| 1387 | * Signature: (JJ)V |
| 1388 | */ |
| 1389 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFreePixmap |
| 1390 | (JNIEnv *env, jclass clazz, jlong display, jlong pixmap) { |
| 1391 | AWT_CHECK_HAVE_LOCK(); |
| 1392 | XFreePixmap((Display *)jlong_to_ptr(display), (Pixmap) pixmap); |
| 1393 | } |
| 1394 | |
| 1395 | /* |
| 1396 | * Class: sun_awt_X11_XlibWrapper |
| 1397 | * Method: XReparentWindow |
| 1398 | * Signature: (JJJII)V |
| 1399 | */ |
| 1400 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XReparentWindow |
| 1401 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong parent, jint x, jint y) { |
| 1402 | AWT_CHECK_HAVE_LOCK(); |
| 1403 | XReparentWindow((Display*)jlong_to_ptr(display), window, parent, x, y); |
| 1404 | } |
| 1405 | |
| 1406 | /* |
| 1407 | * Class: sun_awt_X11_XlibWrapper |
| 1408 | * Method: XConvertSelection |
| 1409 | * Signature: (JJJJJJ)V |
| 1410 | */ |
| 1411 | JNIEXPORT void JNICALL |
| 1412 | Java_sun_awt_X11_XlibWrapper_XConvertSelection(JNIEnv *env, jclass clazz, |
| 1413 | jlong display, jlong selection, |
| 1414 | jlong target, jlong property, |
| 1415 | jlong requestor, jlong time) { |
| 1416 | AWT_CHECK_HAVE_LOCK(); |
| 1417 | XConvertSelection((Display*)jlong_to_ptr(display), selection, target, property, requestor, |
| 1418 | time); |
| 1419 | } |
| 1420 | |
| 1421 | /* |
| 1422 | * Class: sun_awt_X11_XlibWrapper |
| 1423 | * Method: XSetSelectionOwner |
| 1424 | * Signature: (JJJJ)V |
| 1425 | */ |
| 1426 | JNIEXPORT void JNICALL |
| 1427 | Java_sun_awt_X11_XlibWrapper_XSetSelectionOwner(JNIEnv *env, jclass clazz, |
| 1428 | jlong display, jlong selection, |
| 1429 | jlong owner, jlong time) { |
| 1430 | AWT_CHECK_HAVE_LOCK(); |
| 1431 | XSetSelectionOwner((Display*)jlong_to_ptr(display), selection, owner, time); |
| 1432 | } |
| 1433 | |
| 1434 | /* |
| 1435 | * Class: sun_awt_X11_XlibWrapper |
| 1436 | * Method: XGetSelectionOwner |
| 1437 | * Signature: (JJ)J |
| 1438 | */ |
| 1439 | JNIEXPORT jlong JNICALL |
| 1440 | Java_sun_awt_X11_XlibWrapper_XGetSelectionOwner(JNIEnv *env, jclass clazz, |
| 1441 | jlong display, jlong selection) { |
| 1442 | AWT_CHECK_HAVE_LOCK(); |
| 1443 | return (jlong)XGetSelectionOwner((Display*)jlong_to_ptr(display), selection); |
| 1444 | } |
| 1445 | |
| 1446 | /* |
| 1447 | * Class: sun_awt_X11_XlibWrapper |
| 1448 | * Method: XGetAtomName |
| 1449 | * Signature: (JJ)Ljava/lang/String; |
| 1450 | */ |
| 1451 | JNIEXPORT jstring JNICALL |
| 1452 | Java_sun_awt_X11_XlibWrapper_XGetAtomName(JNIEnv *env, jclass clazz, |
| 1453 | jlong display, jlong atom) |
| 1454 | { |
| 1455 | jstring string = NULL; |
| 1456 | char* name; |
| 1457 | AWT_CHECK_HAVE_LOCK(); |
| 1458 | name = (char*) XGetAtomName((Display*)jlong_to_ptr(display), atom); |
| 1459 | |
| 1460 | if (name == NULL) { |
| 1461 | fprintf(stderr, "Atom was %d\n", (int)atom); |
| 1462 | JNU_ThrowNullPointerException(env, "Failed to retrieve atom name."); |
| 1463 | return NULL; |
| 1464 | } |
| 1465 | |
| 1466 | string = (*env)->NewStringUTF(env, (const char *)name); |
| 1467 | |
| 1468 | XFree(name); |
| 1469 | |
| 1470 | return string; |
| 1471 | } |
| 1472 | |
| 1473 | /* |
| 1474 | * Class: sun_awt_X11_XlibWrapper |
| 1475 | * Method: XMaxRequestSize |
| 1476 | * Signature: (J)J |
| 1477 | */ |
| 1478 | JNIEXPORT jlong JNICALL |
| 1479 | Java_sun_awt_X11_XlibWrapper_XMaxRequestSize(JNIEnv *env, jclass clazz, |
| 1480 | jlong display) { |
| 1481 | AWT_CHECK_HAVE_LOCK(); |
| 1482 | return XMaxRequestSize((Display*) jlong_to_ptr(display)); |
| 1483 | } |
| 1484 | |
| 1485 | JNIEXPORT jlong JNICALL |
| 1486 | Java_sun_awt_X11_XlibWrapper_XAllocWMHints(JNIEnv *env, jclass clazz) |
| 1487 | { |
| 1488 | AWT_CHECK_HAVE_LOCK(); |
| 1489 | return ptr_to_jlong(XAllocWMHints()); |
| 1490 | } |
| 1491 | |
| 1492 | JNIEXPORT jlong JNICALL |
| 1493 | Java_sun_awt_X11_XlibWrapper_XCreatePixmap(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jint width, jint height, jint depth) |
| 1494 | { |
| 1495 | AWT_CHECK_HAVE_LOCK(); |
| 1496 | return XCreatePixmap((Display*)jlong_to_ptr(display), (Drawable)drawable, width, height, depth); |
| 1497 | } |
| 1498 | JNIEXPORT jlong JNICALL |
| 1499 | Java_sun_awt_X11_XlibWrapper_XCreateImage |
| 1500 | (JNIEnv *env, jclass clazz, jlong display, jlong visual_ptr, |
| 1501 | jint depth, jint format, jint offset, jlong data, jint width, |
| 1502 | jint height, jint bitmap_pad, jint bytes_per_line) |
| 1503 | { |
| 1504 | AWT_CHECK_HAVE_LOCK(); |
| 1505 | return ptr_to_jlong(XCreateImage((Display*) jlong_to_ptr(display), (Visual*) jlong_to_ptr(visual_ptr), |
| 1506 | depth, format, offset, (char*) jlong_to_ptr(data), |
| 1507 | width, height, bitmap_pad, bytes_per_line)); |
| 1508 | } |
| 1509 | JNIEXPORT jlong JNICALL |
| 1510 | Java_sun_awt_X11_XlibWrapper_XCreateGC |
| 1511 | (JNIEnv *env, jclass clazz, jlong display, jlong drawable, |
| 1512 | jlong valuemask, jlong values) |
| 1513 | { |
| 1514 | AWT_CHECK_HAVE_LOCK(); |
| 1515 | return ptr_to_jlong(XCreateGC((Display*) jlong_to_ptr(display), (Drawable)drawable, valuemask, (XGCValues*) jlong_to_ptr(values))); |
| 1516 | } |
| 1517 | |
| 1518 | JNIEXPORT void JNICALL |
| 1519 | Java_sun_awt_X11_XlibWrapper_XDestroyImage(JNIEnv *env, jclass clazz, jlong image) |
| 1520 | { |
| 1521 | XImage *img = (XImage*) jlong_to_ptr(image); |
| 1522 | AWT_CHECK_HAVE_LOCK(); |
| 1523 | |
| 1524 | // Fix for bug 4903671 : |
| 1525 | // We should be careful to not double free the memory pointed to data |
| 1526 | // Since we use unsafe to allocate it, we should use unsafe to free it. |
| 1527 | // So we should NULL the data pointer before calling XDestroyImage so |
| 1528 | // that X does not free the pointer for us. |
| 1529 | img->data = NULL; |
| 1530 | XDestroyImage(img); |
| 1531 | } |
| 1532 | JNIEXPORT void JNICALL |
| 1533 | Java_sun_awt_X11_XlibWrapper_XPutImage(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong gc, jlong image, jint src_x, jint src_y, jint dest_x, jint dest_y, jint width, jint height) |
| 1534 | { |
| 1535 | AWT_CHECK_HAVE_LOCK(); |
| 1536 | XPutImage((Display*)jlong_to_ptr(display), (Drawable)drawable, (GC) jlong_to_ptr(gc), (XImage*) jlong_to_ptr(image), src_x, src_y, |
| 1537 | dest_x, dest_y, width, height); |
| 1538 | } |
| 1539 | JNIEXPORT void JNICALL |
| 1540 | Java_sun_awt_X11_XlibWrapper_XFreeGC(JNIEnv *env, jclass clazz, jlong display, jlong gc) |
| 1541 | { |
| 1542 | AWT_CHECK_HAVE_LOCK(); |
| 1543 | XFreeGC((Display*) jlong_to_ptr(display), (GC) jlong_to_ptr(gc)); |
| 1544 | } |
| 1545 | JNIEXPORT void JNICALL |
| 1546 | Java_sun_awt_X11_XlibWrapper_XSetWindowBackgroundPixmap(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong pixmap) |
| 1547 | { |
| 1548 | AWT_CHECK_HAVE_LOCK(); |
| 1549 | XSetWindowBackgroundPixmap((Display*) jlong_to_ptr(display), (Window)window, (Pixmap)pixmap); |
| 1550 | } |
| 1551 | JNIEXPORT void JNICALL |
| 1552 | Java_sun_awt_X11_XlibWrapper_XClearWindow(JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 1553 | { |
| 1554 | AWT_CHECK_HAVE_LOCK(); |
| 1555 | XClearWindow((Display*) jlong_to_ptr(display), (Window)window); |
| 1556 | } |
| 1557 | |
| 1558 | JNIEXPORT jint JNICALL |
| 1559 | Java_sun_awt_X11_XlibWrapper_XGetIconSizes(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong ret_sizes, jlong ret_count) |
| 1560 | { |
| 1561 | XIconSize** psize = (XIconSize**) jlong_to_ptr(ret_sizes); |
| 1562 | int * pcount = (int *) jlong_to_ptr(ret_count); |
| 1563 | Status res; |
| 1564 | AWT_CHECK_HAVE_LOCK(); |
| 1565 | res = XGetIconSizes((Display*) jlong_to_ptr(display), (Window)window, psize, pcount); |
| 1566 | return res; |
| 1567 | } |
| 1568 | |
| 1569 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeQueryExtension |
| 1570 | (JNIEnv *env, jclass clazz, jlong display, jlong major_version_return, |
| 1571 | jlong minor_version_return) |
| 1572 | { |
| 1573 | AWT_CHECK_HAVE_LOCK(); |
| 1574 | return XdbeQueryExtension((Display*) jlong_to_ptr(display), (int *) jlong_to_ptr(major_version_return), |
| 1575 | (int *) jlong_to_ptr(minor_version_return)); |
| 1576 | } |
| 1577 | |
| 1578 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryExtension |
| 1579 | (JNIEnv *env, jclass clazz, jlong display, jstring jstr, jlong mop_return, |
| 1580 | jlong feve_return, jlong err_return) |
| 1581 | { |
| 1582 | char *cname; |
| 1583 | Boolean bu; |
| 1584 | if (!JNU_IsNull(env, jstr)) { |
| 1585 | cname = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); |
| 1586 | } else { |
| 1587 | cname = ""; |
| 1588 | } |
| 1589 | |
| 1590 | AWT_CHECK_HAVE_LOCK(); |
| 1591 | bu = XQueryExtension((Display*) jlong_to_ptr(display), cname, (int *) jlong_to_ptr(mop_return), |
| 1592 | (int *) jlong_to_ptr(feve_return), (int *) jlong_to_ptr(err_return)); |
| 1593 | if (!JNU_IsNull(env, jstr)) { |
| 1594 | JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); |
| 1595 | } |
| 1596 | return bu ? JNI_TRUE : JNI_FALSE; |
| 1597 | } |
| 1598 | |
| 1599 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKeypadKey |
| 1600 | (JNIEnv *env, jclass clazz, jlong keysym) |
| 1601 | { |
| 1602 | AWT_CHECK_HAVE_LOCK(); |
| 1603 | if(IsKeypadKey(keysym)) { |
| 1604 | return JNI_TRUE; |
| 1605 | } |
| 1606 | return JNI_FALSE; |
| 1607 | } |
| 1608 | |
| 1609 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XdbeAllocateBackBufferName |
| 1610 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint swap_action) |
| 1611 | { |
| 1612 | AWT_CHECK_HAVE_LOCK(); |
| 1613 | return XdbeAllocateBackBufferName((Display*) jlong_to_ptr(display), (Window) window, |
| 1614 | (XdbeSwapAction) swap_action); |
| 1615 | } |
| 1616 | |
| 1617 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeDeallocateBackBufferName |
| 1618 | (JNIEnv *env, jclass clazz, jlong display, jlong buffer) |
| 1619 | { |
| 1620 | AWT_CHECK_HAVE_LOCK(); |
| 1621 | return XdbeDeallocateBackBufferName((Display*) jlong_to_ptr(display), (XdbeBackBuffer) buffer); |
| 1622 | } |
| 1623 | |
| 1624 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeBeginIdiom |
| 1625 | (JNIEnv *env, jclass clazz, jlong display) |
| 1626 | { |
| 1627 | AWT_CHECK_HAVE_LOCK(); |
| 1628 | return XdbeBeginIdiom((Display*) jlong_to_ptr(display)); |
| 1629 | } |
| 1630 | |
| 1631 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeEndIdiom |
| 1632 | (JNIEnv *env, jclass clazz, jlong display) |
| 1633 | { |
| 1634 | AWT_CHECK_HAVE_LOCK(); |
| 1635 | return XdbeEndIdiom((Display*) jlong_to_ptr(display)); |
| 1636 | } |
| 1637 | |
| 1638 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeSwapBuffers |
| 1639 | (JNIEnv *env, jclass clazz, jlong display, jlong swap_info, jint num_windows) |
| 1640 | { |
| 1641 | AWT_CHECK_HAVE_LOCK(); |
| 1642 | return XdbeSwapBuffers((Display*) jlong_to_ptr(display), (XdbeSwapInfo *) jlong_to_ptr(swap_info), num_windows); |
| 1643 | } |
| 1644 | |
| 1645 | JNIEXPORT jlong JNICALL |
| 1646 | Java_sun_awt_X11_XlibWrapper_XKeycodeToKeysym(JNIEnv *env, jclass clazz, |
| 1647 | jlong display, jint keycode, |
| 1648 | jint index) { |
| 1649 | AWT_CHECK_HAVE_LOCK(); |
| 1650 | return XKeycodeToKeysym((Display*) jlong_to_ptr(display), (unsigned int)keycode, (int)index); |
| 1651 | } |
| 1652 | |
| 1653 | JNIEXPORT jint JNICALL |
| 1654 | Java_sun_awt_X11_XlibWrapper_XKeysymToKeycode(JNIEnv *env, jclass clazz, |
| 1655 | jlong display, jlong keysym) { |
| 1656 | AWT_CHECK_HAVE_LOCK(); |
| 1657 | return XKeysymToKeycode((Display*) jlong_to_ptr(display), (KeySym)keysym); |
| 1658 | } |
| 1659 | |
| 1660 | JNIEXPORT jlong JNICALL |
| 1661 | Java_sun_awt_X11_XlibWrapper_XGetModifierMapping(JNIEnv *env, jclass clazz, |
| 1662 | jlong display) { |
| 1663 | AWT_CHECK_HAVE_LOCK(); |
| 1664 | return ptr_to_jlong(XGetModifierMapping((Display*) jlong_to_ptr(display))); |
| 1665 | } |
| 1666 | |
| 1667 | JNIEXPORT void JNICALL |
| 1668 | Java_sun_awt_X11_XlibWrapper_XFreeModifiermap(JNIEnv *env, jclass clazz, |
| 1669 | jlong keymap) { |
| 1670 | AWT_CHECK_HAVE_LOCK(); |
| 1671 | XFreeModifiermap((XModifierKeymap*) jlong_to_ptr(keymap)); |
| 1672 | } |
| 1673 | |
| 1674 | JNIEXPORT void JNICALL |
| 1675 | Java_sun_awt_X11_XlibWrapper_XChangeActivePointerGrab(JNIEnv *env, jclass clazz, |
| 1676 | jlong display, jint mask, |
| 1677 | jlong cursor, jlong time) { |
| 1678 | AWT_CHECK_HAVE_LOCK(); |
| 1679 | XChangeActivePointerGrab((Display*)jlong_to_ptr(display), (unsigned int)mask, |
| 1680 | (Cursor)cursor, (Time)time); |
| 1681 | } |
| 1682 | |
| 1683 | /******************* Secondary loop support ************************************/ |
| 1684 | #define AWT_SECONDARY_LOOP_TIMEOUT 250 |
| 1685 | |
| 1686 | static Bool exitSecondaryLoop = True; |
| 1687 | |
| 1688 | /* |
| 1689 | * This predicate procedure allows the Toolkit thread to process specific events |
| 1690 | * while it is blocked waiting for the event dispatch thread to process |
| 1691 | * a SunDropTargetEvent. We need this to prevent deadlock when the client code |
| 1692 | * processing SunDropTargetEvent sets or gets the contents of the system |
| 1693 | * clipboard/selection. In this case the event dispatch thread waits for the |
| 1694 | * Toolkit thread to process PropertyNotify or SelectionNotify events. |
| 1695 | */ |
| 1696 | static Bool |
| 1697 | secondary_loop_event(Display* dpy, XEvent* event, char* arg) { |
| 1698 | return (event->type == SelectionNotify || |
| 1699 | event->type == SelectionClear || |
| 1700 | event->type == PropertyNotify) ? True : False; |
| 1701 | } |
| 1702 | |
| 1703 | |
| 1704 | JNIEXPORT jboolean JNICALL |
| 1705 | Java_sun_awt_X11_XlibWrapper_XNextSecondaryLoopEvent(JNIEnv *env, jclass clazz, |
| 1706 | jlong display, jlong ptr) { |
| 1707 | AWT_CHECK_HAVE_LOCK(); |
| 1708 | exitSecondaryLoop = False; |
| 1709 | while (!exitSecondaryLoop) { |
| 1710 | if (XCheckIfEvent((Display*) jlong_to_ptr(display), (XEvent*) jlong_to_ptr(ptr), secondary_loop_event, NULL)) { |
| 1711 | return JNI_TRUE; |
| 1712 | } |
| 1713 | AWT_WAIT(AWT_SECONDARY_LOOP_TIMEOUT); |
| 1714 | } |
| 1715 | return JNI_FALSE; |
| 1716 | } |
| 1717 | |
| 1718 | JNIEXPORT void JNICALL |
| 1719 | Java_sun_awt_X11_XlibWrapper_ExitSecondaryLoop(JNIEnv *env, jclass clazz) { |
| 1720 | DASSERT(!exitSecondaryLoop); |
| 1721 | AWT_CHECK_HAVE_LOCK(); |
| 1722 | exitSecondaryLoop = True; |
| 1723 | AWT_NOTIFY_ALL(); |
| 1724 | } |
| 1725 | /*******************************************************************************/ |
| 1726 | |
| 1727 | JNIEXPORT jobjectArray JNICALL |
| 1728 | Java_sun_awt_X11_XlibWrapper_XTextPropertyToStringList(JNIEnv *env, |
| 1729 | jclass clazz, |
| 1730 | jbyteArray bytes, |
| 1731 | jlong encodingAtom) { |
| 1732 | XTextProperty tp; |
| 1733 | jbyte *value; |
| 1734 | |
| 1735 | char** strings = (char **)NULL; |
| 1736 | int32_t nstrings = 0; |
| 1737 | jobjectArray ret = NULL; |
| 1738 | int32_t i; |
| 1739 | jsize len; |
| 1740 | jboolean isCopy = JNI_FALSE; |
| 1741 | static jclass stringClass = NULL; |
| 1742 | jclass stringClassLocal = NULL; |
| 1743 | |
| 1744 | AWT_CHECK_HAVE_LOCK(); |
| 1745 | |
| 1746 | if (JNU_IsNull(env, stringClass)) { |
| 1747 | stringClassLocal = (*env)->FindClass(env, "java/lang/String"); |
| 1748 | |
| 1749 | if ((*env)->ExceptionCheck(env)) { |
| 1750 | (*env)->ExceptionDescribe(env); |
| 1751 | (*env)->ExceptionClear(env); |
| 1752 | DASSERT(False); |
| 1753 | } |
| 1754 | |
| 1755 | if (JNU_IsNull(env, stringClassLocal)) { |
| 1756 | return NULL; |
| 1757 | } |
| 1758 | |
| 1759 | stringClass = (*env)->NewGlobalRef(env, stringClassLocal); /* never freed! */ |
| 1760 | (*env)->DeleteLocalRef(env, stringClassLocal); |
| 1761 | |
| 1762 | if (JNU_IsNull(env, stringClass)) { |
| 1763 | JNU_ThrowOutOfMemoryError(env, ""); |
| 1764 | return NULL; |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | /* |
| 1769 | * If the length of the byte array is 0 just return a null |
| 1770 | */ |
| 1771 | len = (*env)->GetArrayLength(env, bytes); |
| 1772 | if (len == 0) { |
| 1773 | return (*env)->NewObjectArray(env, 0, stringClass, NULL); |
| 1774 | } |
| 1775 | |
| 1776 | value = (*env)->GetByteArrayElements(env, bytes, &isCopy); |
| 1777 | if (JNU_IsNull(env, value)) { |
| 1778 | return NULL; |
| 1779 | } |
| 1780 | |
| 1781 | tp.encoding = encodingAtom; |
| 1782 | tp.value = (unsigned char *)value; |
| 1783 | tp.nitems = len; |
| 1784 | tp.format = 8; |
| 1785 | |
| 1786 | /* |
| 1787 | * Convert the byte stream into a list of X11 strings |
| 1788 | */ |
| 1789 | if (XTextPropertyToStringList(&tp, &strings, &nstrings) == 0) { |
| 1790 | (*env)->ReleaseByteArrayElements(env, bytes, value, JNI_ABORT); |
| 1791 | return NULL; |
| 1792 | } |
| 1793 | |
| 1794 | (*env)->ReleaseByteArrayElements(env, bytes, value, JNI_ABORT); |
| 1795 | |
| 1796 | if (nstrings == 0) { |
| 1797 | return (*env)->NewObjectArray(env, 0, stringClass, NULL); |
| 1798 | } |
| 1799 | |
| 1800 | ret = (*env)->NewObjectArray(env, nstrings, stringClass, NULL); |
| 1801 | |
| 1802 | if ((*env)->ExceptionCheck(env)) { |
| 1803 | (*env)->ExceptionDescribe(env); |
| 1804 | (*env)->ExceptionClear(env); |
| 1805 | goto wayout; |
| 1806 | } |
| 1807 | |
| 1808 | if (JNU_IsNull(env, ret)) { |
| 1809 | goto wayout; |
| 1810 | } |
| 1811 | |
| 1812 | for (i = 0; i < nstrings; i++) { |
| 1813 | jstring string = (*env)->NewStringUTF(env, |
| 1814 | (const char *)strings[i]); |
| 1815 | if ((*env)->ExceptionCheck(env)) { |
| 1816 | (*env)->ExceptionDescribe(env); |
| 1817 | (*env)->ExceptionClear(env); |
| 1818 | goto wayout; |
| 1819 | } |
| 1820 | |
| 1821 | if (JNU_IsNull(env, string)) { |
| 1822 | goto wayout; |
| 1823 | } |
| 1824 | |
| 1825 | (*env)->SetObjectArrayElement(env, ret, i, string); |
| 1826 | |
| 1827 | if ((*env)->ExceptionCheck(env)) { |
| 1828 | (*env)->ExceptionDescribe(env); |
| 1829 | (*env)->ExceptionClear(env); |
| 1830 | goto wayout; |
| 1831 | } |
| 1832 | |
| 1833 | (*env)->DeleteLocalRef(env, string); |
| 1834 | } |
| 1835 | |
| 1836 | wayout: |
| 1837 | /* |
| 1838 | * Clean up and return |
| 1839 | */ |
| 1840 | XFreeStringList(strings); |
| 1841 | return ret; |
| 1842 | } |
| 1843 | |
| 1844 | |
| 1845 | JNIEXPORT void JNICALL |
| 1846 | Java_sun_awt_X11_XlibWrapper_XPutBackEvent(JNIEnv *env, |
| 1847 | jclass clazz, |
| 1848 | jlong display, |
| 1849 | jlong event) { |
| 1850 | XPutBackEvent((Display*)jlong_to_ptr(display), (XEvent*) jlong_to_ptr(event)); |
| 1851 | } |
| 1852 | |
| 1853 | JNIEXPORT jlong JNICALL |
| 1854 | Java_sun_awt_X11_XlibWrapper_getAddress(JNIEnv *env, |
| 1855 | jclass clazz, |
| 1856 | jobject o) { |
| 1857 | return ptr_to_jlong(o); |
| 1858 | } |
| 1859 | |
| 1860 | JNIEXPORT void JNICALL |
| 1861 | Java_sun_awt_X11_XlibWrapper_copyIntArray(JNIEnv *env, |
| 1862 | jclass clazz, |
| 1863 | jlong dest, jobject array, jint size) { |
| 1864 | jboolean isCopy = JNI_FALSE; |
| 1865 | jint * ints = (*env)->GetIntArrayElements(env, array, &isCopy); |
| 1866 | memcpy(jlong_to_ptr(dest), ints, size); |
| 1867 | if (isCopy) { |
| 1868 | (*env)->ReleaseIntArrayElements(env, array, ints, JNI_ABORT); |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | JNIEXPORT void JNICALL |
| 1873 | Java_sun_awt_X11_XlibWrapper_copyLongArray(JNIEnv *env, |
| 1874 | jclass clazz, |
| 1875 | jlong dest, jobject array, jint size) { |
| 1876 | jboolean isCopy = JNI_FALSE; |
| 1877 | jlong * longs = (*env)->GetLongArrayElements(env, array, &isCopy); |
| 1878 | memcpy(jlong_to_ptr(dest), longs, size); |
| 1879 | if (isCopy) { |
| 1880 | (*env)->ReleaseLongArrayElements(env, array, longs, JNI_ABORT); |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | JNIEXPORT jint JNICALL |
| 1885 | Java_sun_awt_X11_XlibWrapper_XSynchronize(JNIEnv *env, jclass clazz, jlong display, jboolean onoff) |
| 1886 | { |
| 1887 | return (jint) XSynchronize((Display*)jlong_to_ptr(display), (onoff == JNI_TRUE ? True : False)); |
| 1888 | } |
| 1889 | |
| 1890 | JNIEXPORT jboolean JNICALL |
| 1891 | Java_sun_awt_X11_XlibWrapper_XShapeQueryExtension |
| 1892 | (JNIEnv *env, jclass clazz, jlong display, jlong event_base_return, jlong error_base_return) |
| 1893 | { |
| 1894 | jboolean status; |
| 1895 | |
| 1896 | AWT_CHECK_HAVE_LOCK(); |
| 1897 | |
| 1898 | status = XShapeQueryExtension((Display *)jlong_to_ptr(display), |
| 1899 | (int *)jlong_to_ptr(event_base_return), (int *)jlong_to_ptr(error_base_return)); |
| 1900 | return status; |
| 1901 | } |
| 1902 | |
| 1903 | /* |
| 1904 | * Class: XlibWrapper |
| 1905 | * Method: SetRectangularShape |
| 1906 | */ |
| 1907 | |
| 1908 | JNIEXPORT void JNICALL |
| 1909 | Java_sun_awt_X11_XlibWrapper_SetRectangularShape |
| 1910 | (JNIEnv *env, jclass clazz, jlong display, jlong window, |
| 1911 | jint x1, jint y1, jint x2, jint y2, |
| 1912 | jobject region) |
| 1913 | { |
| 1914 | XRectangle rects[256]; |
| 1915 | XRectangle *pRect = rects; |
| 1916 | int numrects; |
| 1917 | |
| 1918 | AWT_CHECK_HAVE_LOCK(); |
| 1919 | |
| 1920 | numrects = RegionToYXBandedRectangles(env, x1, y1, x2, y2, region, |
| 1921 | &pRect, 256); |
| 1922 | |
| 1923 | XShapeCombineRectangles((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), |
| 1924 | ShapeBounding, 0, 0, pRect, numrects, ShapeSet, YXBanded); |
| 1925 | |
| 1926 | if (pRect != rects) { |
| 1927 | free(pRect); |
| 1928 | } |
| 1929 | } |