| 1 | /* |
| 2 | * Copyright (c) 2002, 2018, Oracle and/or its affiliates. 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. Oracle designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | * or visit www.oracle.com if you need additional information or have any |
| 23 | * questions. |
| 24 | */ |
| 25 | |
| 26 | #include "awt.h" |
| 27 | #include "awt_util.h" |
| 28 | #include "jni.h" |
| 29 | #include "jlong.h" |
| 30 | #include "Region.h" |
| 31 | #include "sizecalc.h" |
| 32 | #include "utility/rect.h" |
| 33 | |
| 34 | #include "sun_awt_X11_XlibWrapper.h" |
| 35 | |
| 36 | #include <stdlib.h> |
| 37 | #include <string.h> |
| 38 | #include <X11/extensions/Xdbe.h> |
| 39 | #include <X11/extensions/shape.h> |
| 40 | #include <X11/keysym.h> |
| 41 | #include <X11/Sunkeysym.h> |
| 42 | #include <X11/Xlib.h> |
| 43 | #include <X11/Xatom.h> |
| 44 | #include <X11/XKBlib.h> |
| 45 | #include <X11/Xos.h> |
| 46 | #include <X11/Xutil.h> |
| 47 | |
| 48 | #if defined(AIX) |
| 49 | #undef X_HAVE_UTF8_STRING |
| 50 | extern Bool statusWindowEventHandler(XEvent event); |
| 51 | #endif |
| 52 | |
| 53 | // From XWindow.c |
| 54 | extern KeySym keycodeToKeysym(Display *display, KeyCode keycode, int index); |
| 55 | |
| 56 | #if defined(DEBUG) |
| 57 | static jmethodID lockIsHeldMID = NULL; |
| 58 | |
| 59 | static void |
| 60 | CheckHaveAWTLock(JNIEnv *env) |
| 61 | { |
| 62 | if (lockIsHeldMID == NULL) { |
| 63 | if (tkClass == NULL) return; |
| 64 | lockIsHeldMID = |
| 65 | (*env)->GetStaticMethodID(env, tkClass, |
| 66 | "isAWTLockHeldByCurrentThread" , "()Z" ); |
| 67 | if (lockIsHeldMID == NULL) return; |
| 68 | } |
| 69 | if (!(*env)->CallStaticBooleanMethod(env, tkClass, lockIsHeldMID)) { |
| 70 | JNU_ThrowInternalError(env, "Current thread does not hold AWT_LOCK!" ); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | #define AWT_CHECK_HAVE_LOCK() \ |
| 75 | do { \ |
| 76 | CheckHaveAWTLock(env); \ |
| 77 | if ((*env)->ExceptionCheck(env)) { \ |
| 78 | return; \ |
| 79 | } \ |
| 80 | } while (0); \ |
| 81 | |
| 82 | #define AWT_CHECK_HAVE_LOCK_RETURN(ret) \ |
| 83 | do { \ |
| 84 | CheckHaveAWTLock(env); \ |
| 85 | if ((*env)->ExceptionCheck(env)) { \ |
| 86 | return (ret); \ |
| 87 | } \ |
| 88 | } while (0); \ |
| 89 | |
| 90 | #else |
| 91 | #define AWT_CHECK_HAVE_LOCK() |
| 92 | #define AWT_CHECK_HAVE_LOCK_RETURN(ret) |
| 93 | #endif |
| 94 | |
| 95 | void freeNativeStringArray(char **array, jsize length) { |
| 96 | int i; |
| 97 | if (array == NULL) { |
| 98 | return; |
| 99 | } |
| 100 | for (i = 0; i < length; i++) { |
| 101 | free(array[i]); |
| 102 | } |
| 103 | free(array); |
| 104 | } |
| 105 | |
| 106 | char** stringArrayToNative(JNIEnv *env, jobjectArray array, jsize * ret_length) { |
| 107 | Bool err = FALSE; |
| 108 | char ** strings; |
| 109 | int index, str_index = 0; |
| 110 | jsize length = (*env)->GetArrayLength(env, array); |
| 111 | |
| 112 | if (length == 0) { |
| 113 | return NULL; |
| 114 | } |
| 115 | |
| 116 | strings = (char**) calloc(length, sizeof (char*)); |
| 117 | |
| 118 | if (strings == NULL) { |
| 119 | JNU_ThrowOutOfMemoryError(env, "" ); |
| 120 | return NULL; |
| 121 | } |
| 122 | |
| 123 | for (index = 0; index < length; index++) { |
| 124 | jstring str = (*env)->GetObjectArrayElement(env, array, index); |
| 125 | if (str != NULL) { |
| 126 | const char * str_char = JNU_GetStringPlatformChars(env, str, NULL); |
| 127 | if (str_char != NULL) { |
| 128 | char * dup_str = strdup(str_char); |
| 129 | if (dup_str != NULL) { |
| 130 | strings[str_index++] = dup_str; |
| 131 | } else { |
| 132 | JNU_ThrowOutOfMemoryError(env, "" ); |
| 133 | err = TRUE; |
| 134 | } |
| 135 | JNU_ReleaseStringPlatformChars(env, str, str_char); |
| 136 | } else { |
| 137 | err = TRUE; |
| 138 | } |
| 139 | (*env)->DeleteLocalRef(env, str); |
| 140 | if (err) { |
| 141 | break; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (err) { |
| 147 | freeNativeStringArray(strings, str_index); |
| 148 | strings = NULL; |
| 149 | str_index = -1; |
| 150 | } |
| 151 | *ret_length = str_index; |
| 152 | |
| 153 | return strings; |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Class: XlibWrapper |
| 158 | * Method: XOpenDisplay |
| 159 | * Signature: (J)J |
| 160 | */ |
| 161 | |
| 162 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XOpenDisplay |
| 163 | (JNIEnv *env, jclass clazz, jlong display_name) |
| 164 | { |
| 165 | Display *dp; |
| 166 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 167 | dp = XOpenDisplay((char *) jlong_to_ptr(display_name)); |
| 168 | |
| 169 | return ptr_to_jlong(dp); |
| 170 | } |
| 171 | |
| 172 | JNIEXPORT void JNICALL |
| 173 | Java_sun_awt_X11_XlibWrapper_XCloseDisplay(JNIEnv *env, jclass clazz, |
| 174 | jlong display) { |
| 175 | AWT_CHECK_HAVE_LOCK(); |
| 176 | XCloseDisplay((Display*) jlong_to_ptr(display)); |
| 177 | } |
| 178 | |
| 179 | JNIEXPORT jlong JNICALL |
| 180 | Java_sun_awt_X11_XlibWrapper_XDisplayString(JNIEnv *env, jclass clazz, |
| 181 | jlong display) { |
| 182 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 183 | return ptr_to_jlong(XDisplayString((Display*) jlong_to_ptr(display))); |
| 184 | } |
| 185 | |
| 186 | JNIEXPORT void JNICALL |
| 187 | Java_sun_awt_X11_XlibWrapper_XSetCloseDownMode(JNIEnv *env, jclass clazz, |
| 188 | jlong display, jint mode) { |
| 189 | AWT_CHECK_HAVE_LOCK(); |
| 190 | XSetCloseDownMode((Display*) jlong_to_ptr(display), (int)mode); |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * Class: sun_awt_X11_XlibWrapper |
| 195 | * Method: DefaultScreen |
| 196 | * Signature: (J)J |
| 197 | */ |
| 198 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DefaultScreen (JNIEnv *env, jclass clazz, jlong display) { |
| 199 | |
| 200 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 201 | return (jlong) DefaultScreen((Display *) jlong_to_ptr(display)); |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Class: sun_awt_X11_XlibWrapper |
| 206 | * Method: ScreenOfDisplay |
| 207 | * Signature: (JJ)J |
| 208 | */ |
| 209 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_ScreenOfDisplay(JNIEnv *env, jclass clazz, jlong display, jlong screen_number) { |
| 210 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 211 | return ptr_to_jlong(ScreenOfDisplay((Display *) jlong_to_ptr(display), |
| 212 | screen_number)); |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | * Class: sun_awt_X11_XlibWrapper |
| 217 | * Method: DoesBackingStore |
| 218 | * Signature: (J)I |
| 219 | */ |
| 220 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_DoesBackingStore(JNIEnv *env, jclass clazz, jlong screen) { |
| 221 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 222 | return (jint) DoesBackingStore((Screen*) jlong_to_ptr(screen)); |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Class: sun_awt_X11_XlibWrapper |
| 227 | * Method: DisplayWidth |
| 228 | * Signature: (JJ)J |
| 229 | */ |
| 230 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayWidth |
| 231 | (JNIEnv *env, jclass clazz, jlong display, jlong screen) { |
| 232 | |
| 233 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 234 | return (jlong) DisplayWidth((Display *) jlong_to_ptr(display),screen); |
| 235 | |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | * Class: sun_awt_X11_XlibWrapper |
| 240 | * Method: DisplayWidthMM |
| 241 | * Signature: (JJ)J |
| 242 | */ |
| 243 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayWidthMM |
| 244 | (JNIEnv *env, jclass clazz, jlong display, jlong screen) { |
| 245 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 246 | return (jlong) DisplayWidthMM((Display *) jlong_to_ptr(display),screen); |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * Class: sun_awt_X11_XlibWrapper |
| 251 | * Method: DisplayHeight |
| 252 | * Signature: (JJ)J |
| 253 | */ |
| 254 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayHeight |
| 255 | (JNIEnv *env, jclass clazz, jlong display, jlong screen) { |
| 256 | |
| 257 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 258 | return (jlong) DisplayHeight((Display *) jlong_to_ptr(display),screen); |
| 259 | } |
| 260 | /* |
| 261 | * Class: sun_awt_X11_XlibWrapper |
| 262 | * Method: DisplayHeightMM |
| 263 | * Signature: (JJ)J |
| 264 | */ |
| 265 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayHeightMM |
| 266 | (JNIEnv *env, jclass clazz, jlong display, jlong screen) { |
| 267 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 268 | return (jlong) DisplayHeightMM((Display *) jlong_to_ptr(display),screen); |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * Class: sun_awt_X11_XlibWrapper |
| 273 | * Method: RootWindow |
| 274 | * Signature: (JJ)J |
| 275 | */ |
| 276 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_RootWindow |
| 277 | (JNIEnv *env , jclass clazz, jlong display, jlong screen_number) { |
| 278 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 279 | return (jlong) RootWindow((Display *) jlong_to_ptr(display), screen_number); |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | * Class: sun_awt_X11_XlibWrapper |
| 284 | * Method: ScreenCount |
| 285 | */ |
| 286 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_ScreenCount |
| 287 | (JNIEnv *env , jclass clazz, jlong display) { |
| 288 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 289 | return ScreenCount((Display *) jlong_to_ptr(display)); |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Class: XlibWrapper |
| 294 | * Method: XCreateWindow |
| 295 | * Signature: (JJIIIIIIJJJJ)J |
| 296 | */ |
| 297 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreateWindow |
| 298 | (JNIEnv *env, jclass clazz, jlong display, jlong window, |
| 299 | jint x, jint y, jint w, jint h , jint border_width, jint depth, |
| 300 | jlong wclass, jlong visual, jlong valuemask, jlong attributes) |
| 301 | { |
| 302 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 303 | return XCreateWindow((Display *) jlong_to_ptr(display),(Window) window, x, y, w, h, |
| 304 | border_width, depth, wclass, (Visual *) jlong_to_ptr(visual), |
| 305 | valuemask, (XSetWindowAttributes *) jlong_to_ptr(attributes)); |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * Class: XlibWrapper |
| 310 | * Method: XConvertCase |
| 311 | * Signature: (JJJ)V |
| 312 | */ |
| 313 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XConvertCase |
| 314 | (JNIEnv *env, jclass clazz, jlong keysym, |
| 315 | jlong keysym_lowercase, jlong keysym_uppercase) |
| 316 | { |
| 317 | AWT_CHECK_HAVE_LOCK(); |
| 318 | XConvertCase(keysym, (jlong_to_ptr(keysym_lowercase)), |
| 319 | (jlong_to_ptr(keysym_uppercase))); |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Class: XlibWrapper |
| 324 | * Method: XMapWindow |
| 325 | * Signature: (JJ)V |
| 326 | */ |
| 327 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMapWindow |
| 328 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 329 | { |
| 330 | AWT_CHECK_HAVE_LOCK(); |
| 331 | XMapWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * Class: XlibWrapper |
| 336 | * Method: XMapRaised |
| 337 | * Signature: (JJ)V |
| 338 | */ |
| 339 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMapRaised |
| 340 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 341 | { |
| 342 | AWT_CHECK_HAVE_LOCK(); |
| 343 | XMapRaised( (Display *)jlong_to_ptr(display),(Window) window); |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Class: XlibWrapper |
| 348 | * Method: XRaiseWindow |
| 349 | * Signature: (JJ)V |
| 350 | */ |
| 351 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRaiseWindow |
| 352 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 353 | { |
| 354 | AWT_CHECK_HAVE_LOCK(); |
| 355 | XRaiseWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * Class: XlibWrapper |
| 360 | * Method: XLowerWindow |
| 361 | * Signature: (JJ)V |
| 362 | */ |
| 363 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XLowerWindow |
| 364 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 365 | { |
| 366 | AWT_CHECK_HAVE_LOCK(); |
| 367 | XLowerWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | * Class: XlibWrapper |
| 372 | * Method: XRestackWindows |
| 373 | * Signature: (JJI)V |
| 374 | */ |
| 375 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRestackWindows |
| 376 | (JNIEnv *env, jclass clazz, jlong display, jlong windows, jint length) |
| 377 | { |
| 378 | AWT_CHECK_HAVE_LOCK(); |
| 379 | XRestackWindows( (Display *) jlong_to_ptr(display), (Window *) jlong_to_ptr(windows), length); |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Class: XlibWrapper |
| 384 | * Method: XConfigureWindow |
| 385 | * Signature: (JJJJ)V |
| 386 | */ |
| 387 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XConfigureWindow |
| 388 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong value_mask, |
| 389 | jlong values) |
| 390 | { |
| 391 | AWT_CHECK_HAVE_LOCK(); |
| 392 | XConfigureWindow((Display*)jlong_to_ptr(display), (Window)window, |
| 393 | (unsigned int)value_mask, (XWindowChanges*)jlong_to_ptr(values)); |
| 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Class: XlibWrapper |
| 398 | * Method: XSetInputFocus |
| 399 | * Signature: (JJ)V |
| 400 | */ |
| 401 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetInputFocus |
| 402 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 403 | { |
| 404 | AWT_CHECK_HAVE_LOCK(); |
| 405 | XSetInputFocus( (Display *)jlong_to_ptr(display),(Window) window, RevertToPointerRoot, CurrentTime); |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * Class: XlibWrapper |
| 410 | * Method: XSetInputFocus2 |
| 411 | * Signature: (JJJ)V |
| 412 | */ |
| 413 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetInputFocus2 |
| 414 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong time) |
| 415 | { |
| 416 | AWT_CHECK_HAVE_LOCK(); |
| 417 | XSetInputFocus( (Display *)jlong_to_ptr(display),(Window) window, RevertToPointerRoot, time); |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * Class: XlibWrapper |
| 422 | * Method: XGetInputFocus |
| 423 | * Signature: (JJ)V |
| 424 | */ |
| 425 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XGetInputFocus |
| 426 | (JNIEnv *env, jclass clazz, jlong display) |
| 427 | { |
| 428 | Window focusOwner; |
| 429 | int revert_to; |
| 430 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 431 | XGetInputFocus( (Display *)jlong_to_ptr(display), &focusOwner, &revert_to); |
| 432 | return focusOwner; |
| 433 | } |
| 434 | |
| 435 | /* |
| 436 | * Class: XlibWrapper |
| 437 | * Method: XDestroyWindow |
| 438 | * Signature: (JJ)V |
| 439 | */ |
| 440 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XDestroyWindow |
| 441 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 442 | { |
| 443 | AWT_CHECK_HAVE_LOCK(); |
| 444 | XDestroyWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 445 | } |
| 446 | |
| 447 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGrabPointer |
| 448 | (JNIEnv *env, jclass clazz, jlong display, jlong window, |
| 449 | jint owner_events, jint event_mask, jint pointer_mode, |
| 450 | jint keyboard_mode, jlong confine_to, jlong cursor, jlong time) |
| 451 | { |
| 452 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 453 | return XGrabPointer( (Display *)jlong_to_ptr(display), (Window) window, |
| 454 | (Bool) owner_events, (unsigned int) event_mask, (int) pointer_mode, |
| 455 | (int) keyboard_mode, (Window) confine_to, (Cursor) cursor, (Time) time); |
| 456 | } |
| 457 | |
| 458 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUngrabPointer |
| 459 | (JNIEnv *env, jclass clazz, jlong display, jlong time) |
| 460 | { |
| 461 | AWT_CHECK_HAVE_LOCK(); |
| 462 | XUngrabPointer( (Display *)jlong_to_ptr(display), (Time) time); |
| 463 | } |
| 464 | |
| 465 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGrabKeyboard |
| 466 | (JNIEnv *env, jclass clazz, jlong display, jlong window, |
| 467 | jint owner_events, jint pointer_mode, |
| 468 | jint keyboard_mode, jlong time) |
| 469 | { |
| 470 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 471 | return XGrabKeyboard( (Display *)jlong_to_ptr(display), (Window) window, |
| 472 | (Bool) owner_events, (int) pointer_mode, |
| 473 | (int) keyboard_mode, (Time) time); |
| 474 | } |
| 475 | |
| 476 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUngrabKeyboard |
| 477 | (JNIEnv *env, jclass clazz, jlong display, jlong time) |
| 478 | { |
| 479 | AWT_CHECK_HAVE_LOCK(); |
| 480 | XUngrabKeyboard( (Display *)jlong_to_ptr(display), (Time) time); |
| 481 | } |
| 482 | |
| 483 | JNIEXPORT void JNICALL |
| 484 | Java_sun_awt_X11_XlibWrapper_XGrabServer(JNIEnv *env, jclass clazz, |
| 485 | jlong display) { |
| 486 | AWT_CHECK_HAVE_LOCK(); |
| 487 | XGrabServer((Display*)jlong_to_ptr(display)); |
| 488 | } |
| 489 | |
| 490 | JNIEXPORT void JNICALL |
| 491 | Java_sun_awt_X11_XlibWrapper_XUngrabServer(JNIEnv *env, jclass clazz, |
| 492 | jlong display) { |
| 493 | AWT_CHECK_HAVE_LOCK(); |
| 494 | XUngrabServer((Display*)jlong_to_ptr(display)); |
| 495 | /* Workaround for bug 5039226 */ |
| 496 | XSync((Display*)jlong_to_ptr(display), False); |
| 497 | } |
| 498 | |
| 499 | /* |
| 500 | * Class: XlibWrapper |
| 501 | * Method: XUnmapWindow |
| 502 | * Signature: (JJ)V |
| 503 | */ |
| 504 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUnmapWindow |
| 505 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 506 | { |
| 507 | |
| 508 | AWT_CHECK_HAVE_LOCK(); |
| 509 | XUnmapWindow( (Display *)jlong_to_ptr(display),(Window) window); |
| 510 | |
| 511 | } |
| 512 | |
| 513 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSelectInput |
| 514 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong mask) |
| 515 | { |
| 516 | AWT_CHECK_HAVE_LOCK(); |
| 517 | XSelectInput((Display *) jlong_to_ptr(display), (Window) window, mask); |
| 518 | } |
| 519 | |
| 520 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbSelectEvents |
| 521 | (JNIEnv *env, jclass clazz, jlong display, jlong device, jlong bits_to_change, |
| 522 | jlong values_for_bits) |
| 523 | { |
| 524 | AWT_CHECK_HAVE_LOCK(); |
| 525 | XkbSelectEvents((Display *) jlong_to_ptr(display), (unsigned int)device, |
| 526 | (unsigned long)bits_to_change, |
| 527 | (unsigned long)values_for_bits); |
| 528 | } |
| 529 | |
| 530 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbSelectEventDetails |
| 531 | (JNIEnv *env, jclass clazz, jlong display, jlong device, jlong event_type, |
| 532 | jlong bits_to_change, jlong values_for_bits) |
| 533 | { |
| 534 | AWT_CHECK_HAVE_LOCK(); |
| 535 | XkbSelectEventDetails((Display *) jlong_to_ptr(display), (unsigned int)device, |
| 536 | (unsigned int) event_type, |
| 537 | (unsigned long)bits_to_change, |
| 538 | (unsigned long)values_for_bits); |
| 539 | } |
| 540 | |
| 541 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbQueryExtension |
| 542 | (JNIEnv *env, jclass clazz, jlong display, jlong opcode_rtrn, jlong event_rtrn, |
| 543 | jlong error_rtrn, jlong major_in_out, jlong minor_in_out) |
| 544 | { |
| 545 | Bool status; |
| 546 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 547 | status = XkbQueryExtension((Display *) jlong_to_ptr(display), |
| 548 | (int *) jlong_to_ptr(opcode_rtrn), |
| 549 | (int *) jlong_to_ptr(event_rtrn), |
| 550 | (int *) jlong_to_ptr(error_rtrn), |
| 551 | (int *) jlong_to_ptr(major_in_out), |
| 552 | (int *) jlong_to_ptr(minor_in_out)); |
| 553 | return status ? JNI_TRUE : JNI_FALSE; |
| 554 | } |
| 555 | |
| 556 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbLibraryVersion |
| 557 | (JNIEnv *env, jclass clazz, jlong lib_major_in_out, jlong lib_minor_in_out) |
| 558 | { |
| 559 | Bool status; |
| 560 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 561 | *((int *)jlong_to_ptr(lib_major_in_out)) = XkbMajorVersion; |
| 562 | *((int *)jlong_to_ptr(lib_minor_in_out)) = XkbMinorVersion; |
| 563 | status = XkbLibraryVersion((int *)jlong_to_ptr(lib_major_in_out), |
| 564 | (int *)jlong_to_ptr(lib_minor_in_out)); |
| 565 | return status ? JNI_TRUE : JNI_FALSE; |
| 566 | } |
| 567 | |
| 568 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XkbGetMap |
| 569 | (JNIEnv *env, jclass clazz, jlong display, jlong which, jlong device_spec) |
| 570 | { |
| 571 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 572 | return (jlong) XkbGetMap( (Display *) jlong_to_ptr(display), |
| 573 | (unsigned int) which, |
| 574 | (unsigned int) device_spec); |
| 575 | } |
| 576 | |
| 577 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XkbGetUpdatedMap |
| 578 | (JNIEnv *env, jclass clazz, jlong display, jlong which, jlong xkb) |
| 579 | { |
| 580 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 581 | return (jlong) XkbGetUpdatedMap( (Display *) jlong_to_ptr(display), |
| 582 | (unsigned int) which, |
| 583 | (XkbDescPtr) jlong_to_ptr(xkb)); |
| 584 | } |
| 585 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbFreeKeyboard |
| 586 | (JNIEnv *env, jclass clazz, jlong xkb, jlong which, jboolean free_all) |
| 587 | { |
| 588 | AWT_CHECK_HAVE_LOCK(); |
| 589 | XkbFreeKeyboard(jlong_to_ptr(xkb), (unsigned int)which, free_all); |
| 590 | } |
| 591 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbTranslateKeyCode |
| 592 | (JNIEnv *env, jclass clazz, jlong xkb, jint keycode, jlong mods, jlong mods_rtrn, jlong keysym_rtrn) |
| 593 | { |
| 594 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 595 | Bool b; |
| 596 | b = XkbTranslateKeyCode((XkbDescPtr)xkb, (unsigned int)keycode, (unsigned int)mods, |
| 597 | (unsigned int *)jlong_to_ptr(mods_rtrn), |
| 598 | (KeySym *)jlong_to_ptr(keysym_rtrn)); |
| 599 | //printf("native, input: keycode:0x%0X; mods:0x%0X\n", keycode, mods); |
| 600 | //printf("native, output: keysym:0x%0X; mods:0x%0X\n", |
| 601 | // *(unsigned int *)jlong_to_ptr(keysym_rtrn), |
| 602 | // *(unsigned int *)jlong_to_ptr(mods_rtrn)); |
| 603 | return b ? JNI_TRUE : JNI_FALSE; |
| 604 | } |
| 605 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbSetDetectableAutoRepeat |
| 606 | (JNIEnv *env, jclass clazz, jlong display, jboolean detectable) |
| 607 | { |
| 608 | AWT_CHECK_HAVE_LOCK(); |
| 609 | XkbSetDetectableAutoRepeat((Display *) jlong_to_ptr(display), detectable, NULL); |
| 610 | } |
| 611 | /* |
| 612 | * Class: sun_awt_X11_XlibWrapper |
| 613 | * Method: XNextEvent |
| 614 | * Signature: (JJ)V |
| 615 | */ |
| 616 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XNextEvent |
| 617 | (JNIEnv *env, jclass clazz, jlong display, jlong ptr) |
| 618 | { |
| 619 | AWT_CHECK_HAVE_LOCK(); |
| 620 | XNextEvent( (Display *) jlong_to_ptr(display), jlong_to_ptr(ptr)); |
| 621 | } |
| 622 | |
| 623 | /* |
| 624 | * Class: sun_awt_X11_XlibWrapper |
| 625 | * Method: XMaskEvent |
| 626 | * Signature: (JJJ)V |
| 627 | */ |
| 628 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMaskEvent |
| 629 | (JNIEnv *env, jclass clazz, jlong display, jlong event_mask, jlong event_return) |
| 630 | { |
| 631 | AWT_CHECK_HAVE_LOCK(); |
| 632 | XMaskEvent( (Display *) jlong_to_ptr(display), event_mask, (XEvent *) jlong_to_ptr(event_return)); |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * Class: sun_awt_X11_XlibWrapper |
| 637 | * Method: XWindowEvent |
| 638 | * Signature: (JJJJ)V |
| 639 | */ |
| 640 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XWindowEvent |
| 641 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong event_mask, jlong event_return) |
| 642 | { |
| 643 | AWT_CHECK_HAVE_LOCK(); |
| 644 | XWindowEvent( (Display *) jlong_to_ptr(display), (Window)window, event_mask, (XEvent *) jlong_to_ptr(event_return)); |
| 645 | } |
| 646 | |
| 647 | /* |
| 648 | * Class: sun_awt_X11_XlibWrapper |
| 649 | * Method: XFilterEvent |
| 650 | * Signature: (JJ)Z |
| 651 | */ |
| 652 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XFilterEvent |
| 653 | (JNIEnv *env, jclass clazz, jlong ptr, jlong window) |
| 654 | { |
| 655 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 656 | #if defined(AIX) |
| 657 | if (True == statusWindowEventHandler(*((XEvent *)(uintptr_t)ptr))) { |
| 658 | return (jboolean)True; |
| 659 | } |
| 660 | #endif |
| 661 | return (jboolean) XFilterEvent((XEvent *) jlong_to_ptr(ptr), (Window) window); |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | * Class: sun_awt_X11_XlibWrapper |
| 666 | * Method: XSupportsLocale |
| 667 | * Signature: ()Z |
| 668 | */ |
| 669 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XSupportsLocale |
| 670 | (JNIEnv *env, jclass clazz) |
| 671 | { |
| 672 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 673 | return (jboolean)XSupportsLocale(); |
| 674 | } |
| 675 | |
| 676 | /* |
| 677 | * Class: sun_awt_X11_XlibWrapper |
| 678 | * Method: XSetLocaleModifiers |
| 679 | * Signature: (Ljava/lang/String;)Ljava/lang/String; |
| 680 | */ |
| 681 | JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_XSetLocaleModifiers |
| 682 | (JNIEnv *env, jclass clazz, jstring jstr) |
| 683 | { |
| 684 | char * modifier_list = NULL; |
| 685 | char * ret = NULL; |
| 686 | |
| 687 | if (!JNU_IsNull(env, jstr)) { |
| 688 | modifier_list = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); |
| 689 | CHECK_NULL_RETURN(modifier_list, NULL); |
| 690 | } |
| 691 | |
| 692 | AWT_CHECK_HAVE_LOCK_RETURN(NULL); |
| 693 | if (modifier_list) { |
| 694 | ret = XSetLocaleModifiers(modifier_list); |
| 695 | JNU_ReleaseStringPlatformChars(env, jstr, (const char *) modifier_list); |
| 696 | } else { |
| 697 | ret = XSetLocaleModifiers("" ); |
| 698 | } |
| 699 | |
| 700 | return (ret != NULL ? JNU_NewStringPlatform(env, ret): NULL); |
| 701 | } |
| 702 | |
| 703 | |
| 704 | /* |
| 705 | * Class: sun_awt_X11_wrappers_XlibWrapper |
| 706 | * Method: XPeekEvent |
| 707 | * Signature: (JJ)V |
| 708 | */ |
| 709 | |
| 710 | |
| 711 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XPeekEvent |
| 712 | (JNIEnv *env, jclass clazz, jlong display, jlong ptr) |
| 713 | { |
| 714 | AWT_CHECK_HAVE_LOCK(); |
| 715 | XPeekEvent((Display *) jlong_to_ptr(display),jlong_to_ptr(ptr)); |
| 716 | } |
| 717 | |
| 718 | /* |
| 719 | * Class: sun_awt_X11_XlibWrapper |
| 720 | * Method: XMoveResizeWindow |
| 721 | * Signature: (JJIIII)V |
| 722 | */ |
| 723 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMoveResizeWindow |
| 724 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint x , jint y , jint width, jint height) { |
| 725 | AWT_CHECK_HAVE_LOCK(); |
| 726 | XMoveResizeWindow( (Display *) jlong_to_ptr(display), (Window) window, x, y, width, height); |
| 727 | } |
| 728 | |
| 729 | /* |
| 730 | * Class: sun_awt_X11_XlibWrapper |
| 731 | * Method: XResizeWindow |
| 732 | * Signature: (JJII)V |
| 733 | */ |
| 734 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XResizeWindow |
| 735 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint width, jint height) { |
| 736 | AWT_CHECK_HAVE_LOCK(); |
| 737 | XResizeWindow( (Display *) jlong_to_ptr(display),(Window) window,width,height); |
| 738 | } |
| 739 | |
| 740 | /* |
| 741 | * Class: sun_awt_X11_XlibWrapper |
| 742 | * Method: XMoveWindow |
| 743 | * Signature: (JJII)V |
| 744 | */ |
| 745 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMoveWindow |
| 746 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint width, jint height) { |
| 747 | AWT_CHECK_HAVE_LOCK(); |
| 748 | XMoveWindow( (Display *) jlong_to_ptr(display),(Window) window,width,height); |
| 749 | } |
| 750 | |
| 751 | |
| 752 | /* |
| 753 | * Class: sun_awt_X11_XlibWrapper |
| 754 | * Method: XSetWindowBackground |
| 755 | * Signature: (JJJ)V |
| 756 | */ |
| 757 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWindowBackground |
| 758 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong background_pixel) { |
| 759 | AWT_CHECK_HAVE_LOCK(); |
| 760 | XSetWindowBackground((Display *) jlong_to_ptr(display),window,background_pixel); |
| 761 | } |
| 762 | |
| 763 | |
| 764 | /* |
| 765 | * Class: sun_awt_X11_XlibWrapper |
| 766 | * Method: XFlush |
| 767 | * Signature: (J)V |
| 768 | */ |
| 769 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFlush |
| 770 | (JNIEnv *env, jclass clazz, jlong display) { |
| 771 | |
| 772 | AWT_CHECK_HAVE_LOCK(); |
| 773 | XFlush((Display *)jlong_to_ptr(display)); |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Class: sun_awt_X11_XlibWrapper |
| 778 | * Method: XSync |
| 779 | * Signature: (JI)V |
| 780 | */ |
| 781 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSync |
| 782 | (JNIEnv *env, jclass clazz, jlong display, jint discard) { |
| 783 | AWT_CHECK_HAVE_LOCK(); |
| 784 | XSync((Display *) jlong_to_ptr(display), discard); |
| 785 | } |
| 786 | |
| 787 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XTranslateCoordinates |
| 788 | (JNIEnv *env, jclass clazz, jlong display, jlong src_w, jlong dest_w, |
| 789 | jlong src_x, jlong src_y, jlong dest_x_return, jlong dest_y_return, |
| 790 | jlong child_return) |
| 791 | { |
| 792 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 793 | return XTranslateCoordinates( (Display *) jlong_to_ptr(display), src_w, dest_w, |
| 794 | src_x, src_y, |
| 795 | (int *) jlong_to_ptr(dest_x_return), |
| 796 | (int *) jlong_to_ptr(dest_y_return), |
| 797 | (Window *) jlong_to_ptr(child_return)); |
| 798 | } |
| 799 | |
| 800 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XEventsQueued |
| 801 | (JNIEnv *env, jclass clazz, jlong display, jint mode) { |
| 802 | |
| 803 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 804 | return XEventsQueued((Display *) jlong_to_ptr(display), mode); |
| 805 | |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * Class: sun_awt_X11_XlibWrapper |
| 810 | * Method: SetProperty |
| 811 | * Signature: (JJJLjava/lang/String;)V |
| 812 | */ |
| 813 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_SetProperty |
| 814 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom, jstring jstr) { |
| 815 | char *cname; |
| 816 | XTextProperty tp; |
| 817 | int32_t status; |
| 818 | |
| 819 | /* |
| 820 | In case there are direct support of UTF-8 declared, use UTF-8 strings. |
| 821 | */ |
| 822 | if (!JNU_IsNull(env, jstr)) { |
| 823 | #ifdef X_HAVE_UTF8_STRING |
| 824 | cname = (char *) (*env)->GetStringUTFChars(env, jstr, JNI_FALSE); |
| 825 | #else |
| 826 | cname = (char *) JNU_GetStringPlatformChars(env, jstr, NULL); |
| 827 | #endif |
| 828 | CHECK_NULL(cname); |
| 829 | } else { |
| 830 | cname = "" ; |
| 831 | } |
| 832 | |
| 833 | AWT_CHECK_HAVE_LOCK(); |
| 834 | |
| 835 | #ifdef X_HAVE_UTF8_STRING |
| 836 | status = Xutf8TextListToTextProperty((Display *)jlong_to_ptr(display), &cname, 1, |
| 837 | XStdICCTextStyle, &tp); |
| 838 | #else |
| 839 | status = XmbTextListToTextProperty((Display *)jlong_to_ptr(display), &cname, 1, |
| 840 | XStdICCTextStyle, &tp); |
| 841 | #endif |
| 842 | |
| 843 | if (status == Success || status > 0) { |
| 844 | XChangeProperty((Display *)jlong_to_ptr(display), window, atom, tp.encoding, tp.format, PropModeReplace, tp.value, tp.nitems); |
| 845 | if (tp.value != NULL) { |
| 846 | XFree(tp.value); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | if (!JNU_IsNull(env, jstr)) { |
| 851 | #ifdef X_HAVE_UTF8_STRING |
| 852 | (*env)->ReleaseStringUTFChars(env, jstr, (const char *) cname); |
| 853 | #else |
| 854 | JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); |
| 855 | #endif |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /* |
| 860 | * Class: sun_awt_X11_XlibWrapper |
| 861 | * Method: XChangeProperty |
| 862 | * Signature: (JJJJJJJJJJJ)V |
| 863 | */ |
| 864 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangePropertyImpl( |
| 865 | JNIEnv *env, jclass clazz, jlong display, jlong window, jlong property, |
| 866 | jlong type, jint format, jint mode, jlong data, jint nelements) |
| 867 | { |
| 868 | AWT_CHECK_HAVE_LOCK(); |
| 869 | XChangeProperty((Display*) jlong_to_ptr(display), (Window) window, (Atom) property, |
| 870 | (Atom) type, format, mode, (unsigned char*) jlong_to_ptr(data), |
| 871 | nelements); |
| 872 | } |
| 873 | /* |
| 874 | * Class: sun_awt_X11_XlibWrapper |
| 875 | * Method: XChangePropertyS |
| 876 | * Signature: (JJJJJJJJJLjava/lang/String;)V |
| 877 | */ |
| 878 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangePropertyS( |
| 879 | JNIEnv *env, jclass clazz, jlong display, jlong window, jlong property, |
| 880 | jlong type, jint format, jint mode, jstring value) |
| 881 | { |
| 882 | jboolean iscopy; |
| 883 | AWT_CHECK_HAVE_LOCK(); |
| 884 | const char * chars = JNU_GetStringPlatformChars(env, value, &iscopy); |
| 885 | CHECK_NULL(chars); |
| 886 | XChangeProperty((Display*)jlong_to_ptr(display), window, (Atom)property, |
| 887 | (Atom)type, format, mode, (unsigned char*)chars, strlen(chars)); |
| 888 | if (iscopy) { |
| 889 | JNU_ReleaseStringPlatformChars(env, value, chars); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | /* |
| 894 | * Class: sun_awt_X11_XlibWrapper |
| 895 | * Method: XGetWindowProperty |
| 896 | * Signature: (JJJJJJJJJJJ)J; |
| 897 | */ |
| 898 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWindowProperty |
| 899 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong property, jlong long_offset, |
| 900 | jlong long_length, jlong delete, jlong req_type, jlong actual_type, |
| 901 | jlong actual_format, jlong nitems_ptr, jlong bytes_after, jlong data_ptr) |
| 902 | { |
| 903 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 904 | return XGetWindowProperty((Display*) jlong_to_ptr(display), window, property, long_offset, long_length, |
| 905 | delete, (Atom) req_type, (Atom*) jlong_to_ptr(actual_type), |
| 906 | (int *) jlong_to_ptr(actual_format), (unsigned long *) jlong_to_ptr(nitems_ptr), |
| 907 | (unsigned long*) jlong_to_ptr(bytes_after), (unsigned char**) jlong_to_ptr(data_ptr)); |
| 908 | } |
| 909 | |
| 910 | /* |
| 911 | * Class: sun_awt_X11_XlibWrapper |
| 912 | * Method: GetProperty |
| 913 | * Signature: (JJJ)Ljava/lang/String; |
| 914 | */ |
| 915 | JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_GetProperty |
| 916 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom) |
| 917 | { |
| 918 | /* Request status */ |
| 919 | int status; |
| 920 | |
| 921 | /* Returns of XGetWindowProperty */ |
| 922 | Atom actual_type; |
| 923 | int actual_format; |
| 924 | unsigned long nitems; |
| 925 | unsigned long bytes_after; |
| 926 | unsigned char * string; |
| 927 | jstring res = NULL; |
| 928 | AWT_CHECK_HAVE_LOCK_RETURN(NULL); |
| 929 | status = XGetWindowProperty((Display*)jlong_to_ptr(display), window, |
| 930 | atom, 0, 0xFFFF, False, XA_STRING, |
| 931 | &actual_type, &actual_format, &nitems, &bytes_after, |
| 932 | &string); |
| 933 | |
| 934 | if (status != Success || string == NULL) { |
| 935 | return NULL; |
| 936 | } |
| 937 | |
| 938 | if (actual_type == XA_STRING && actual_format == 8) { |
| 939 | res = JNU_NewStringPlatform(env,(char*) string); |
| 940 | } |
| 941 | XFree(string); |
| 942 | return res; |
| 943 | } |
| 944 | |
| 945 | /* |
| 946 | * Class: sun_awt_X11_XlibWrapper |
| 947 | * Method: InternAtom |
| 948 | * Signature: (JLjava/lang/String;I)J |
| 949 | */ |
| 950 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_InternAtom |
| 951 | (JNIEnv *env, jclass clazz, jlong display, jstring jstr, jint ife) { |
| 952 | |
| 953 | char *cname; |
| 954 | unsigned long atom; |
| 955 | |
| 956 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 957 | |
| 958 | if (!JNU_IsNull(env, jstr)) { |
| 959 | cname = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); |
| 960 | CHECK_NULL_RETURN(cname, 0); |
| 961 | } else { |
| 962 | cname = "" ; |
| 963 | } |
| 964 | |
| 965 | atom = XInternAtom((Display *) jlong_to_ptr(display), cname, ife); |
| 966 | |
| 967 | if (!JNU_IsNull(env, jstr)) { |
| 968 | JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); |
| 969 | } |
| 970 | |
| 971 | return (jlong) atom; |
| 972 | |
| 973 | } |
| 974 | |
| 975 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XCreateFontCursor |
| 976 | (JNIEnv *env, jclass clazz, jlong display, jint shape) { |
| 977 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 978 | return XCreateFontCursor((Display *) jlong_to_ptr(display), (int) shape); |
| 979 | } |
| 980 | |
| 981 | /* |
| 982 | * Class: sun_awt_X11_XlibWrapper |
| 983 | * Method: XCreatePixmapCursor |
| 984 | * Signature: (JJJJJII)J |
| 985 | */ |
| 986 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreatePixmapCursor |
| 987 | (JNIEnv *env , jclass clazz, jlong display, jlong source, jlong mask, jlong fore, jlong back, jint x , jint y) { |
| 988 | |
| 989 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 990 | return (jlong) XCreatePixmapCursor((Display *) jlong_to_ptr(display), (Pixmap) source, (Pixmap) mask, |
| 991 | (XColor *) jlong_to_ptr(fore), (XColor *) jlong_to_ptr(back), x, y); |
| 992 | } |
| 993 | |
| 994 | /* |
| 995 | * Class: sun_awt_X11_XlibWrapper |
| 996 | * Method: XQueryBestCursor |
| 997 | * Signature: (JJIIJJ)Z |
| 998 | */ |
| 999 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryBestCursor |
| 1000 | (JNIEnv *env, jclass clazz, jlong display, jlong drawable, jint width, jint height, jlong width_return, jlong height_return) { |
| 1001 | |
| 1002 | Status status; |
| 1003 | |
| 1004 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 1005 | status = XQueryBestCursor((Display *) jlong_to_ptr(display), (Drawable) drawable, width,height, |
| 1006 | (unsigned int *) jlong_to_ptr(width_return), (unsigned int *) jlong_to_ptr(height_return)); |
| 1007 | |
| 1008 | if (status == 0) return JNI_FALSE; |
| 1009 | else return JNI_TRUE; |
| 1010 | } |
| 1011 | |
| 1012 | /* |
| 1013 | * Class: sun_awt_X11_XlibWrapper |
| 1014 | * Method: XFreeCursor |
| 1015 | * Signature: (JJ)V |
| 1016 | */ |
| 1017 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFreeCursor |
| 1018 | (JNIEnv *env, jclass clazz, jlong display, jlong cursor) { |
| 1019 | |
| 1020 | AWT_CHECK_HAVE_LOCK(); |
| 1021 | XFreeCursor( (Display *) jlong_to_ptr(display), (Cursor) cursor); |
| 1022 | } |
| 1023 | |
| 1024 | /* |
| 1025 | * Class: sun_awt_X11_XlibWrapper |
| 1026 | * Method: XQueryPointer |
| 1027 | * Signature: (JJJJJJJJJ)Z |
| 1028 | */ |
| 1029 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryPointer |
| 1030 | (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) { |
| 1031 | |
| 1032 | Bool b; |
| 1033 | |
| 1034 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 1035 | b = XQueryPointer((Display *) jlong_to_ptr(display), |
| 1036 | (Window) w, (Window *) jlong_to_ptr(root_return), (Window *) jlong_to_ptr(child_return), |
| 1037 | (int *) jlong_to_ptr(root_x_return), (int *) jlong_to_ptr(root_y_return), |
| 1038 | (int *) jlong_to_ptr(win_x_return), (int *) jlong_to_ptr(win_y_return), |
| 1039 | (unsigned int *) jlong_to_ptr(mask_return)); |
| 1040 | |
| 1041 | return b ? JNI_TRUE : JNI_FALSE; |
| 1042 | } |
| 1043 | |
| 1044 | /* |
| 1045 | * Class: sun_awt_X11_XlibWrapper |
| 1046 | * Method: XChangeWindowAttributes |
| 1047 | * Signature: (JJJJ)V |
| 1048 | */ |
| 1049 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangeWindowAttributes |
| 1050 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong valuemask, jlong attributes) { |
| 1051 | |
| 1052 | AWT_CHECK_HAVE_LOCK(); |
| 1053 | XChangeWindowAttributes((Display *) jlong_to_ptr(display), (Window) window, (unsigned long) valuemask, |
| 1054 | (XSetWindowAttributes *) jlong_to_ptr(attributes)); |
| 1055 | } |
| 1056 | |
| 1057 | /* |
| 1058 | * Class: sun_awt_X11_XlibWrapper |
| 1059 | * Method: XSetTransientFor |
| 1060 | * Signature: (JJJ)V |
| 1061 | */ |
| 1062 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetTransientFor |
| 1063 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong transient_for_window) |
| 1064 | { |
| 1065 | AWT_CHECK_HAVE_LOCK(); |
| 1066 | XSetTransientForHint((Display *) jlong_to_ptr(display), window, transient_for_window); |
| 1067 | } |
| 1068 | |
| 1069 | /* |
| 1070 | * Class: sun_awt_X11_XlibWrapper |
| 1071 | * Method: XSetWMHints |
| 1072 | * Signature: (JJJ)V |
| 1073 | */ |
| 1074 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWMHints |
| 1075 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints) |
| 1076 | { |
| 1077 | AWT_CHECK_HAVE_LOCK(); |
| 1078 | XSetWMHints((Display *) jlong_to_ptr(display), window, (XWMHints *) jlong_to_ptr(hints)); |
| 1079 | } |
| 1080 | |
| 1081 | /* |
| 1082 | * Class: sun_awt_X11_XlibWrapper |
| 1083 | * Method: XGetWMHints |
| 1084 | * Signature: (JJJ)V |
| 1085 | */ |
| 1086 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XGetWMHints |
| 1087 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints) |
| 1088 | { |
| 1089 | XWMHints * get_hints; |
| 1090 | AWT_CHECK_HAVE_LOCK(); |
| 1091 | get_hints = XGetWMHints((Display*)jlong_to_ptr(display), window); |
| 1092 | if (get_hints != NULL) { |
| 1093 | memcpy(jlong_to_ptr(hints), get_hints, sizeof(XWMHints)); |
| 1094 | XFree(get_hints); |
| 1095 | } else { |
| 1096 | memset(jlong_to_ptr(hints), 0, sizeof(XWMHints)); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | /* |
| 1101 | * Class: sun_awt_X11_XlibWrapper |
| 1102 | * Method: XGetPointerMapping |
| 1103 | * Signature: (JJI)I |
| 1104 | */ |
| 1105 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetPointerMapping |
| 1106 | (JNIEnv *env, jclass clazz, jlong display, jlong map, jint buttonNumber) |
| 1107 | { |
| 1108 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1109 | return XGetPointerMapping((Display*)jlong_to_ptr(display), (unsigned char*) jlong_to_ptr(map), buttonNumber); |
| 1110 | } |
| 1111 | |
| 1112 | /* |
| 1113 | * Class: sun_awt_X11_XlibWrapper |
| 1114 | * Method: XGetDefault |
| 1115 | * Signature: (JJI)I |
| 1116 | */ |
| 1117 | JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_XGetDefault |
| 1118 | (JNIEnv *env, jclass clazz, jlong display, jstring program, jstring option) |
| 1119 | { |
| 1120 | char * c_program = NULL; |
| 1121 | char * c_option = NULL; |
| 1122 | char * c_res = NULL; |
| 1123 | |
| 1124 | if (!JNU_IsNull(env, program)) { |
| 1125 | c_program = (char *)JNU_GetStringPlatformChars(env, program, NULL); |
| 1126 | } |
| 1127 | CHECK_NULL_RETURN(c_program, NULL); |
| 1128 | |
| 1129 | if (!JNU_IsNull(env, option)) { |
| 1130 | c_option = (char *)JNU_GetStringPlatformChars(env, option, NULL); |
| 1131 | } |
| 1132 | |
| 1133 | if (c_option == NULL) { |
| 1134 | JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program); |
| 1135 | return NULL; |
| 1136 | } |
| 1137 | |
| 1138 | AWT_CHECK_HAVE_LOCK_RETURN(NULL); |
| 1139 | c_res = XGetDefault((Display*)jlong_to_ptr(display), c_program, c_option); |
| 1140 | // The strings returned by XGetDefault() are owned by Xlib and |
| 1141 | // should not be modified or freed by the client. |
| 1142 | |
| 1143 | JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program); |
| 1144 | JNU_ReleaseStringPlatformChars(env, option, (const char *) c_option); |
| 1145 | |
| 1146 | if (c_res != NULL) { |
| 1147 | return JNU_NewStringPlatform(env, c_res); |
| 1148 | } else { |
| 1149 | return NULL; |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | /* |
| 1154 | * Class: sun_awt_X11_XlibWrapper |
| 1155 | * Method: getScreenOfWindow |
| 1156 | * Signature: (JJ)J |
| 1157 | */ |
| 1158 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_getScreenOfWindow |
| 1159 | (JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 1160 | { |
| 1161 | XWindowAttributes attrs; |
| 1162 | memset(&attrs, 0, sizeof(attrs)); |
| 1163 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1164 | XGetWindowAttributes((Display *) jlong_to_ptr(display), window, &attrs); |
| 1165 | return ptr_to_jlong(attrs.screen); |
| 1166 | } |
| 1167 | |
| 1168 | /* |
| 1169 | * Class: sun_awt_X11_XlibWrapper |
| 1170 | * Method: XScreenNumberOfScreen |
| 1171 | * Signature: (J)J |
| 1172 | */ |
| 1173 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XScreenNumberOfScreen |
| 1174 | (JNIEnv *env, jclass clazz, jlong screen) |
| 1175 | { |
| 1176 | AWT_CHECK_HAVE_LOCK_RETURN(-1); |
| 1177 | if(jlong_to_ptr(screen) == NULL) { |
| 1178 | return -1; |
| 1179 | } |
| 1180 | return XScreenNumberOfScreen((Screen*) jlong_to_ptr(screen)); |
| 1181 | } |
| 1182 | |
| 1183 | /* |
| 1184 | * Class: sun_awt_X11_XlibWrapper |
| 1185 | * Method: XIconifyWindow |
| 1186 | * Signature: (JJJ)V |
| 1187 | */ |
| 1188 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XIconifyWindow |
| 1189 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong screenNumber) |
| 1190 | { |
| 1191 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1192 | return XIconifyWindow((Display*) jlong_to_ptr(display), window, screenNumber); |
| 1193 | } |
| 1194 | |
| 1195 | /* |
| 1196 | * Class: sun_awt_X11_XlibWrapper |
| 1197 | * Method: XFree |
| 1198 | * Signature: (J)V |
| 1199 | */ |
| 1200 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFree |
| 1201 | (JNIEnv *env, jclass clazz, jlong ptr) |
| 1202 | { |
| 1203 | AWT_CHECK_HAVE_LOCK(); |
| 1204 | XFree(jlong_to_ptr(ptr)); |
| 1205 | } |
| 1206 | |
| 1207 | /* |
| 1208 | * Class: sun_awt_X11_XlibWrapper |
| 1209 | * Method: XFree |
| 1210 | * Signature: (J)V |
| 1211 | */ |
| 1212 | JNIEXPORT jbyteArray JNICALL Java_sun_awt_X11_XlibWrapper_getStringBytes |
| 1213 | (JNIEnv *env, jclass clazz, jlong str_ptr) |
| 1214 | { |
| 1215 | unsigned char * str = (unsigned char*) jlong_to_ptr(str_ptr); |
| 1216 | long length = strlen((char*)str); |
| 1217 | jbyteArray res = (*env)->NewByteArray(env, length); |
| 1218 | CHECK_NULL_RETURN(res, NULL); |
| 1219 | (*env)->SetByteArrayRegion(env, res, 0, length, |
| 1220 | (const signed char*) str); |
| 1221 | return res; |
| 1222 | } |
| 1223 | |
| 1224 | /* |
| 1225 | * Class: sun_awt_X11_XlibWrapper |
| 1226 | * Method: ServerVendor |
| 1227 | * Signature: (J)Ljava/lang/String; |
| 1228 | */ |
| 1229 | JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_ServerVendor |
| 1230 | (JNIEnv *env, jclass clazz, jlong display) |
| 1231 | { |
| 1232 | AWT_CHECK_HAVE_LOCK_RETURN(NULL); |
| 1233 | return JNU_NewStringPlatform(env, ServerVendor((Display*)jlong_to_ptr(display))); |
| 1234 | } |
| 1235 | |
| 1236 | /* |
| 1237 | * Class: sun_awt_X11_XlibWrapper |
| 1238 | * Method: VendorRelease |
| 1239 | * Signature: (J)I; |
| 1240 | */ |
| 1241 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_VendorRelease |
| 1242 | (JNIEnv *env, jclass clazz, jlong display) |
| 1243 | { |
| 1244 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1245 | return VendorRelease((Display*)jlong_to_ptr(display)); |
| 1246 | } |
| 1247 | |
| 1248 | /* |
| 1249 | * Class: sun_awt_X11_XlibWrapper |
| 1250 | * Method: IsXsunKPBehavior |
| 1251 | * Signature: (J)Z; |
| 1252 | */ |
| 1253 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsXsunKPBehavior |
| 1254 | (JNIEnv *env, jclass clazz, jlong display) |
| 1255 | { |
| 1256 | // Xsun without XKB uses keysymarray[2] keysym to determine if it is KP event. |
| 1257 | // Otherwise, it is [1] or sometimes [0]. |
| 1258 | // This sniffer first tries to determine what is a keycode for XK_KP_7 |
| 1259 | // using XKeysymToKeycode; |
| 1260 | // second, in which place in the keysymarray is XK_KP_7 |
| 1261 | // using XKeycodeToKeysym. |
| 1262 | int kc7; |
| 1263 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 1264 | kc7 = XKeysymToKeycode((Display*)jlong_to_ptr(display), XK_KP_7); |
| 1265 | if( !kc7 ) { |
| 1266 | // keycode is not defined. Why, it's a reduced keyboard perhaps: |
| 1267 | // report arbitrarily false. |
| 1268 | return JNI_FALSE; |
| 1269 | } else { |
| 1270 | long ks2 = keycodeToKeysym((Display*)jlong_to_ptr(display), kc7, 2); |
| 1271 | if( ks2 == XK_KP_7 ) { |
| 1272 | //XXX If some Xorg server would put XK_KP_7 in keysymarray[2] as well, |
| 1273 | //XXX for yet unknown to me reason, the sniffer would lie. |
| 1274 | return JNI_TRUE; |
| 1275 | }else{ |
| 1276 | return JNI_FALSE; |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsSunKeyboard |
| 1282 | (JNIEnv *env, jclass clazz, jlong display) |
| 1283 | { |
| 1284 | int xx; |
| 1285 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 1286 | xx = XKeysymToKeycode((Display*)jlong_to_ptr(display), SunXK_F37); |
| 1287 | return (!xx) ? JNI_FALSE : JNI_TRUE; |
| 1288 | } |
| 1289 | |
| 1290 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKanaKeyboard |
| 1291 | (JNIEnv *env, jclass clazz, jlong display) |
| 1292 | { |
| 1293 | int xx; |
| 1294 | static jboolean result = JNI_FALSE; |
| 1295 | |
| 1296 | int32_t minKeyCode, maxKeyCode, keySymsPerKeyCode; |
| 1297 | KeySym *keySyms, *keySymsStart, keySym; |
| 1298 | int32_t i; |
| 1299 | int32_t kanaCount = 0; |
| 1300 | |
| 1301 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 1302 | |
| 1303 | // There's no direct way to determine whether the keyboard has |
| 1304 | // a kana lock key. From available keyboard mapping tables, it looks |
| 1305 | // like only keyboards with the kana lock key can produce keysyms |
| 1306 | // for kana characters. So, as an indirect test, we check for those. |
| 1307 | XDisplayKeycodes((Display*)jlong_to_ptr(display), &minKeyCode, &maxKeyCode); |
| 1308 | keySyms = XGetKeyboardMapping((Display*)jlong_to_ptr(display), minKeyCode, maxKeyCode - minKeyCode + 1, &keySymsPerKeyCode); |
| 1309 | keySymsStart = keySyms; |
| 1310 | for (i = 0; i < (maxKeyCode - minKeyCode + 1) * keySymsPerKeyCode; i++) { |
| 1311 | keySym = *keySyms++; |
| 1312 | if ((keySym & 0xff00) == 0x0400) { |
| 1313 | kanaCount++; |
| 1314 | } |
| 1315 | } |
| 1316 | XFree(keySymsStart); |
| 1317 | |
| 1318 | // use a (somewhat arbitrary) minimum so we don't get confused by a stray function key |
| 1319 | result = kanaCount > 10; |
| 1320 | return result ? JNI_TRUE : JNI_FALSE; |
| 1321 | } |
| 1322 | |
| 1323 | JavaVM* jvm = NULL; |
| 1324 | static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) { |
| 1325 | JNIEnv * env; |
| 1326 | // First call the native synthetic error handler declared in "awt_util.h" file. |
| 1327 | if (current_native_xerror_handler != NULL) { |
| 1328 | current_native_xerror_handler(dpy, event); |
| 1329 | } |
| 1330 | if (jvm != NULL) { |
| 1331 | env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
| 1332 | if (env) { |
| 1333 | return JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil" , |
| 1334 | "globalErrorHandler" , "(JJ)I" , ptr_to_jlong(dpy), ptr_to_jlong(event)).i; |
| 1335 | } |
| 1336 | } |
| 1337 | return 0; |
| 1338 | } |
| 1339 | |
| 1340 | /* |
| 1341 | * Class: sun_awt_X11_XlibWrapper |
| 1342 | * Method: SetToolkitErrorHandler |
| 1343 | * Signature: ()J |
| 1344 | */ |
| 1345 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_SetToolkitErrorHandler |
| 1346 | (JNIEnv *env, jclass clazz) |
| 1347 | { |
| 1348 | if ((*env)->GetJavaVM(env, &jvm) < 0) { |
| 1349 | return 0; |
| 1350 | } |
| 1351 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1352 | return ptr_to_jlong(XSetErrorHandler(ToolkitErrorHandler)); |
| 1353 | } |
| 1354 | |
| 1355 | /* |
| 1356 | * Class: sun_awt_X11_XlibWrapper |
| 1357 | * Method: XSetErrorHandler |
| 1358 | * Signature: (J)V |
| 1359 | */ |
| 1360 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetErrorHandler |
| 1361 | (JNIEnv *env, jclass clazz, jlong handler) |
| 1362 | { |
| 1363 | AWT_CHECK_HAVE_LOCK(); |
| 1364 | XSetErrorHandler((XErrorHandler) jlong_to_ptr(handler)); |
| 1365 | } |
| 1366 | |
| 1367 | /* |
| 1368 | * Class: sun_awt_X11_XlibWrapper |
| 1369 | * Method: CallErrorHandler |
| 1370 | * Signature: (JJJ)I |
| 1371 | */ |
| 1372 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_CallErrorHandler |
| 1373 | (JNIEnv *env, jclass clazz, jlong handler, jlong display, jlong event_ptr) |
| 1374 | { |
| 1375 | return (*(XErrorHandler)jlong_to_ptr(handler))((Display*) jlong_to_ptr(display), (XErrorEvent*) jlong_to_ptr(event_ptr)); |
| 1376 | } |
| 1377 | |
| 1378 | /* |
| 1379 | * Class: sun_awt_X11_XlibWrapper |
| 1380 | * Method: PrintXErrorEvent |
| 1381 | * Signature: (JJ)V |
| 1382 | */ |
| 1383 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_PrintXErrorEvent |
| 1384 | (JNIEnv *env, jclass clazz, jlong display, jlong event_ptr) |
| 1385 | { |
| 1386 | char msg[128]; |
| 1387 | char buf[128]; |
| 1388 | |
| 1389 | XErrorEvent* err = (XErrorEvent *)jlong_to_ptr(event_ptr); |
| 1390 | |
| 1391 | XGetErrorText((Display *)jlong_to_ptr(display), err->error_code, msg, sizeof(msg)); |
| 1392 | jio_fprintf(stderr, "Xerror %s, XID %x, ser# %d\n" , msg, err->resourceid, err->serial); |
| 1393 | jio_snprintf(buf, sizeof(buf), "%d" , err->request_code); |
| 1394 | XGetErrorDatabaseText((Display *)jlong_to_ptr(display), "XRequest" , buf, "Unknown" , msg, sizeof(msg)); |
| 1395 | jio_fprintf(stderr, "Major opcode %d (%s)\n" , err->request_code, msg); |
| 1396 | if (err->request_code > 128) { |
| 1397 | jio_fprintf(stderr, "Minor opcode %d\n" , err->minor_code); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | /* |
| 1402 | * Class: sun_awt_X11_XlibWrapper |
| 1403 | * Method: XInternAtoms |
| 1404 | * Signature: (J[Ljava/lang/String;ZJ)I |
| 1405 | */ |
| 1406 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XInternAtoms |
| 1407 | (JNIEnv *env, jclass clazz, jlong display, jobjectArray names_arr, jboolean only_if_exists, jlong atoms) |
| 1408 | { |
| 1409 | int status = 0; |
| 1410 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1411 | jsize length; |
| 1412 | char** names = stringArrayToNative(env, names_arr, &length); |
| 1413 | if (names) { |
| 1414 | status = XInternAtoms((Display*)jlong_to_ptr(display), names, length, only_if_exists, (Atom*) jlong_to_ptr(atoms)); |
| 1415 | freeNativeStringArray(names, length); |
| 1416 | } |
| 1417 | return status; |
| 1418 | } |
| 1419 | |
| 1420 | /* |
| 1421 | * Class: sun_awt_X11_XlibWrapper |
| 1422 | * Method: XGetWindowAttributes |
| 1423 | * Signature: (JJJ)I |
| 1424 | */ |
| 1425 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWindowAttributes |
| 1426 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong attr_ptr) |
| 1427 | { |
| 1428 | jint status; |
| 1429 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1430 | memset((XWindowAttributes*) jlong_to_ptr(attr_ptr), 0, sizeof(XWindowAttributes)); |
| 1431 | status = XGetWindowAttributes((Display*)jlong_to_ptr(display), window, (XWindowAttributes*) jlong_to_ptr(attr_ptr)); |
| 1432 | return status; |
| 1433 | } |
| 1434 | |
| 1435 | /* |
| 1436 | * Class: sun_awt_X11_XlibWrapper |
| 1437 | * Method: XGetGeometry |
| 1438 | * Signature: (JJJJJJJJJ)I |
| 1439 | */ |
| 1440 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetGeometry |
| 1441 | (JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong root_return, |
| 1442 | jlong x_return, jlong y_return, jlong width_return, jlong height_return, |
| 1443 | jlong border_width_return, jlong depth_return) |
| 1444 | { |
| 1445 | jint status; |
| 1446 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1447 | status = XGetGeometry((Display *)jlong_to_ptr(display), |
| 1448 | (Drawable)drawable, (Window *)jlong_to_ptr(root_return), |
| 1449 | (int *)jlong_to_ptr(x_return), (int *)jlong_to_ptr(y_return), |
| 1450 | (unsigned int *)jlong_to_ptr(width_return), (unsigned int *)jlong_to_ptr(height_return), |
| 1451 | (unsigned int *)jlong_to_ptr(border_width_return), |
| 1452 | (unsigned int *)jlong_to_ptr(depth_return)); |
| 1453 | return status; |
| 1454 | } |
| 1455 | |
| 1456 | /* |
| 1457 | * Class: sun_awt_X11_XlibWrapper |
| 1458 | * Method: XGetWMNormalHints |
| 1459 | * Signature: (JJJJ)I |
| 1460 | */ |
| 1461 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWMNormalHints |
| 1462 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints, jlong supplied_return) |
| 1463 | { |
| 1464 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1465 | return XGetWMNormalHints((Display*) jlong_to_ptr(display), |
| 1466 | window, |
| 1467 | (XSizeHints*) jlong_to_ptr(hints), |
| 1468 | (long*) jlong_to_ptr(supplied_return)); |
| 1469 | } |
| 1470 | |
| 1471 | /* |
| 1472 | * Class: sun_awt_X11_XlibWrapper |
| 1473 | * Method: XSetWMNormalHints |
| 1474 | * Signature: (JJJ)V |
| 1475 | */ |
| 1476 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWMNormalHints |
| 1477 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints) |
| 1478 | { |
| 1479 | AWT_CHECK_HAVE_LOCK(); |
| 1480 | XSetWMNormalHints((Display*) jlong_to_ptr(display), window, (XSizeHints*) jlong_to_ptr(hints)); |
| 1481 | } |
| 1482 | |
| 1483 | /* |
| 1484 | * Class: sun_awt_X11_XlibWrapper |
| 1485 | * Method: XDeleteProperty |
| 1486 | * Signature: (JJJ)V |
| 1487 | */ |
| 1488 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XDeleteProperty |
| 1489 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom) |
| 1490 | { |
| 1491 | AWT_CHECK_HAVE_LOCK(); |
| 1492 | XDeleteProperty((Display*) jlong_to_ptr(display), window, (Atom)atom); |
| 1493 | } |
| 1494 | |
| 1495 | /* |
| 1496 | * Class: sun_awt_X11_XlibWrapper |
| 1497 | * Method: XSendEvent |
| 1498 | * Signature: (JJZJJ)V |
| 1499 | */ |
| 1500 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XSendEvent |
| 1501 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jboolean propagate, jlong event_mask, jlong event) |
| 1502 | { |
| 1503 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1504 | return XSendEvent((Display*) jlong_to_ptr(display), |
| 1505 | window, |
| 1506 | propagate==JNI_TRUE?True:False, |
| 1507 | (long) event_mask, |
| 1508 | (XEvent*) jlong_to_ptr(event)); |
| 1509 | } |
| 1510 | |
| 1511 | /* |
| 1512 | * Class: sun_awt_X11_XlibWrapper |
| 1513 | * Method: XQueryTree |
| 1514 | * Signature: (JJJJJJ)I |
| 1515 | */ |
| 1516 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XQueryTree |
| 1517 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong root_return, jlong parent_return, jlong children_return, jlong nchildren_return) |
| 1518 | { |
| 1519 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1520 | return XQueryTree((Display*) jlong_to_ptr(display), |
| 1521 | window, |
| 1522 | (Window *) jlong_to_ptr(root_return), |
| 1523 | (Window*) jlong_to_ptr(parent_return), |
| 1524 | (Window**) jlong_to_ptr(children_return), |
| 1525 | (unsigned int*) jlong_to_ptr(nchildren_return)); |
| 1526 | } |
| 1527 | |
| 1528 | /* |
| 1529 | * Class: sun_awt_X11_XlibWrapper |
| 1530 | * Method: memcpy |
| 1531 | * Signature: (JJJ)V |
| 1532 | */ |
| 1533 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_memcpy |
| 1534 | (JNIEnv *env, jclass clazz, jlong dest_ptr, jlong src_ptr, jlong length) |
| 1535 | { |
| 1536 | memcpy(jlong_to_ptr(dest_ptr), jlong_to_ptr(src_ptr), length); |
| 1537 | } |
| 1538 | |
| 1539 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetMinMaxHints |
| 1540 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint x, jint y, jint width, jint height, jlong flags) { |
| 1541 | XSizeHints * hints; |
| 1542 | AWT_CHECK_HAVE_LOCK(); |
| 1543 | hints = XAllocSizeHints(); |
| 1544 | hints->flags = flags; |
| 1545 | hints->width = width; |
| 1546 | hints->min_width = width; |
| 1547 | hints->max_width = width; |
| 1548 | hints->height = height; |
| 1549 | hints->min_height = height; |
| 1550 | hints->max_height = height; |
| 1551 | hints->x = x; |
| 1552 | hints->y = y; |
| 1553 | XSetWMNormalHints((Display*) jlong_to_ptr(display), window, hints); |
| 1554 | XFree(hints); |
| 1555 | } |
| 1556 | |
| 1557 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XGetVisualInfo |
| 1558 | (JNIEnv *env, jclass clazz, jlong display, jlong vinfo_mask, jlong vinfo_template, |
| 1559 | jlong nitems_return) |
| 1560 | { |
| 1561 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1562 | return ptr_to_jlong(XGetVisualInfo((Display*) jlong_to_ptr(display), |
| 1563 | (long) vinfo_mask, |
| 1564 | (XVisualInfo*) jlong_to_ptr(vinfo_template), |
| 1565 | (int*) jlong_to_ptr(nitems_return))); |
| 1566 | } |
| 1567 | |
| 1568 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XAllocSizeHints |
| 1569 | (JNIEnv *env, jclass clazz) |
| 1570 | { |
| 1571 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1572 | return ptr_to_jlong(XAllocSizeHints()); |
| 1573 | } |
| 1574 | |
| 1575 | /* |
| 1576 | * Class: sun_awt_X11_XlibWrapper |
| 1577 | * Method: XIconifyWindow |
| 1578 | * Signature: (JJJ)V |
| 1579 | */ |
| 1580 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XBell |
| 1581 | (JNIEnv *env, jclass clazz, jlong display, jint percent) |
| 1582 | { |
| 1583 | AWT_CHECK_HAVE_LOCK(); |
| 1584 | XBell((Display*)jlong_to_ptr(display), percent); |
| 1585 | } |
| 1586 | |
| 1587 | /* |
| 1588 | * Class: sun_awt_X11_XlibWrapper |
| 1589 | * Method: XAllocColor |
| 1590 | * Signature: (JJJ)Z |
| 1591 | */ |
| 1592 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XAllocColor |
| 1593 | (JNIEnv *env, jclass clazz, jlong display , jlong colormap, jlong xcolor) { |
| 1594 | |
| 1595 | Status status; |
| 1596 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 1597 | status = XAllocColor((Display *) jlong_to_ptr(display), (Colormap) colormap, (XColor *) jlong_to_ptr(xcolor)); |
| 1598 | |
| 1599 | if (status == 0) return JNI_FALSE; |
| 1600 | else return JNI_TRUE; |
| 1601 | } |
| 1602 | |
| 1603 | /* |
| 1604 | * Class: sun_awt_X11_XlibWrapper |
| 1605 | * Method: XCreateBitmapFromData |
| 1606 | * Signature: (JJJII)J |
| 1607 | */ |
| 1608 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreateBitmapFromData |
| 1609 | (JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong data, jint width, jint height) { |
| 1610 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1611 | |
| 1612 | return (jlong) XCreateBitmapFromData((Display *) jlong_to_ptr(display), (Drawable) drawable, |
| 1613 | (char *) jlong_to_ptr(data), width, height); |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * Class: sun_awt_X11_XlibWrapper |
| 1618 | * Method: XFreePixmap |
| 1619 | * Signature: (JJ)V |
| 1620 | */ |
| 1621 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFreePixmap |
| 1622 | (JNIEnv *env, jclass clazz, jlong display, jlong pixmap) { |
| 1623 | AWT_CHECK_HAVE_LOCK(); |
| 1624 | XFreePixmap((Display *)jlong_to_ptr(display), (Pixmap) pixmap); |
| 1625 | } |
| 1626 | |
| 1627 | /* |
| 1628 | * Class: sun_awt_X11_XlibWrapper |
| 1629 | * Method: XReparentWindow |
| 1630 | * Signature: (JJJII)V |
| 1631 | */ |
| 1632 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XReparentWindow |
| 1633 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong parent, jint x, jint y) { |
| 1634 | AWT_CHECK_HAVE_LOCK(); |
| 1635 | XReparentWindow((Display*)jlong_to_ptr(display), window, parent, x, y); |
| 1636 | } |
| 1637 | |
| 1638 | /* |
| 1639 | * Class: sun_awt_X11_XlibWrapper |
| 1640 | * Method: XConvertSelection |
| 1641 | * Signature: (JJJJJJ)V |
| 1642 | */ |
| 1643 | JNIEXPORT void JNICALL |
| 1644 | Java_sun_awt_X11_XlibWrapper_XConvertSelection(JNIEnv *env, jclass clazz, |
| 1645 | jlong display, jlong selection, |
| 1646 | jlong target, jlong property, |
| 1647 | jlong requestor, jlong time) { |
| 1648 | AWT_CHECK_HAVE_LOCK(); |
| 1649 | XConvertSelection((Display*)jlong_to_ptr(display), selection, target, property, requestor, |
| 1650 | time); |
| 1651 | } |
| 1652 | |
| 1653 | /* |
| 1654 | * Class: sun_awt_X11_XlibWrapper |
| 1655 | * Method: XSetSelectionOwner |
| 1656 | * Signature: (JJJJ)V |
| 1657 | */ |
| 1658 | JNIEXPORT void JNICALL |
| 1659 | Java_sun_awt_X11_XlibWrapper_XSetSelectionOwner(JNIEnv *env, jclass clazz, |
| 1660 | jlong display, jlong selection, |
| 1661 | jlong owner, jlong time) { |
| 1662 | AWT_CHECK_HAVE_LOCK(); |
| 1663 | XSetSelectionOwner((Display*)jlong_to_ptr(display), selection, owner, time); |
| 1664 | } |
| 1665 | |
| 1666 | /* |
| 1667 | * Class: sun_awt_X11_XlibWrapper |
| 1668 | * Method: XGetSelectionOwner |
| 1669 | * Signature: (JJ)J |
| 1670 | */ |
| 1671 | JNIEXPORT jlong JNICALL |
| 1672 | Java_sun_awt_X11_XlibWrapper_XGetSelectionOwner(JNIEnv *env, jclass clazz, |
| 1673 | jlong display, jlong selection) { |
| 1674 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1675 | return (jlong)XGetSelectionOwner((Display*)jlong_to_ptr(display), selection); |
| 1676 | } |
| 1677 | |
| 1678 | /* |
| 1679 | * Class: sun_awt_X11_XlibWrapper |
| 1680 | * Method: XGetAtomName |
| 1681 | * Signature: (JJ)Ljava/lang/String; |
| 1682 | */ |
| 1683 | JNIEXPORT jstring JNICALL |
| 1684 | Java_sun_awt_X11_XlibWrapper_XGetAtomName(JNIEnv *env, jclass clazz, |
| 1685 | jlong display, jlong atom) |
| 1686 | { |
| 1687 | jstring string = NULL; |
| 1688 | char* name; |
| 1689 | AWT_CHECK_HAVE_LOCK_RETURN(NULL); |
| 1690 | name = (char*) XGetAtomName((Display*)jlong_to_ptr(display), atom); |
| 1691 | |
| 1692 | if (name == NULL) { |
| 1693 | fprintf(stderr, "Atom was %d\n" , (int)atom); |
| 1694 | JNU_ThrowNullPointerException(env, "Failed to retrieve atom name." ); |
| 1695 | return NULL; |
| 1696 | } |
| 1697 | |
| 1698 | string = (*env)->NewStringUTF(env, (const char *)name); |
| 1699 | |
| 1700 | XFree(name); |
| 1701 | |
| 1702 | return string; |
| 1703 | } |
| 1704 | |
| 1705 | /* |
| 1706 | * Class: sun_awt_X11_XlibWrapper |
| 1707 | * Method: XMaxRequestSize |
| 1708 | * Signature: (J)J |
| 1709 | */ |
| 1710 | JNIEXPORT jlong JNICALL |
| 1711 | Java_sun_awt_X11_XlibWrapper_XMaxRequestSize(JNIEnv *env, jclass clazz, |
| 1712 | jlong display) { |
| 1713 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1714 | return XMaxRequestSize((Display*) jlong_to_ptr(display)); |
| 1715 | } |
| 1716 | |
| 1717 | JNIEXPORT jlong JNICALL |
| 1718 | Java_sun_awt_X11_XlibWrapper_XAllocWMHints(JNIEnv *env, jclass clazz) |
| 1719 | { |
| 1720 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1721 | return ptr_to_jlong(XAllocWMHints()); |
| 1722 | } |
| 1723 | |
| 1724 | JNIEXPORT jlong JNICALL |
| 1725 | Java_sun_awt_X11_XlibWrapper_XCreatePixmap(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jint width, jint height, jint depth) |
| 1726 | { |
| 1727 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1728 | return XCreatePixmap((Display*)jlong_to_ptr(display), (Drawable)drawable, width, height, depth); |
| 1729 | } |
| 1730 | |
| 1731 | JNIEXPORT jlong JNICALL |
| 1732 | Java_sun_awt_X11_XlibWrapper_XCreateImage |
| 1733 | (JNIEnv *env, jclass clazz, jlong display, jlong visual_ptr, |
| 1734 | jint depth, jint format, jint offset, jlong data, jint width, |
| 1735 | jint height, jint bitmap_pad, jint bytes_per_line) |
| 1736 | { |
| 1737 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1738 | return ptr_to_jlong(XCreateImage((Display*) jlong_to_ptr(display), (Visual*) jlong_to_ptr(visual_ptr), |
| 1739 | depth, format, offset, (char*) jlong_to_ptr(data), |
| 1740 | width, height, bitmap_pad, bytes_per_line)); |
| 1741 | } |
| 1742 | |
| 1743 | JNIEXPORT jlong JNICALL |
| 1744 | Java_sun_awt_X11_XlibWrapper_XCreateGC |
| 1745 | (JNIEnv *env, jclass clazz, jlong display, jlong drawable, |
| 1746 | jlong valuemask, jlong values) |
| 1747 | { |
| 1748 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1749 | return ptr_to_jlong(XCreateGC((Display*) jlong_to_ptr(display), (Drawable)drawable, valuemask, (XGCValues*) jlong_to_ptr(values))); |
| 1750 | } |
| 1751 | |
| 1752 | JNIEXPORT void JNICALL |
| 1753 | Java_sun_awt_X11_XlibWrapper_XDestroyImage(JNIEnv *env, jclass clazz, jlong image) |
| 1754 | { |
| 1755 | XImage *img = (XImage*) jlong_to_ptr(image); |
| 1756 | AWT_CHECK_HAVE_LOCK(); |
| 1757 | |
| 1758 | // Fix for bug 4903671 : |
| 1759 | // We should be careful to not double free the memory pointed to data |
| 1760 | // Since we use unsafe to allocate it, we should use unsafe to free it. |
| 1761 | // So we should NULL the data pointer before calling XDestroyImage so |
| 1762 | // that X does not free the pointer for us. |
| 1763 | img->data = NULL; |
| 1764 | XDestroyImage(img); |
| 1765 | } |
| 1766 | |
| 1767 | JNIEXPORT void JNICALL |
| 1768 | 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) |
| 1769 | { |
| 1770 | AWT_CHECK_HAVE_LOCK(); |
| 1771 | XPutImage((Display*)jlong_to_ptr(display), (Drawable)drawable, (GC) jlong_to_ptr(gc), (XImage*) jlong_to_ptr(image), src_x, src_y, |
| 1772 | dest_x, dest_y, width, height); |
| 1773 | } |
| 1774 | |
| 1775 | JNIEXPORT void JNICALL |
| 1776 | Java_sun_awt_X11_XlibWrapper_XFreeGC(JNIEnv *env, jclass clazz, jlong display, jlong gc) |
| 1777 | { |
| 1778 | AWT_CHECK_HAVE_LOCK(); |
| 1779 | XFreeGC((Display*) jlong_to_ptr(display), (GC) jlong_to_ptr(gc)); |
| 1780 | } |
| 1781 | |
| 1782 | JNIEXPORT void JNICALL |
| 1783 | Java_sun_awt_X11_XlibWrapper_XSetWindowBackgroundPixmap(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong pixmap) |
| 1784 | { |
| 1785 | AWT_CHECK_HAVE_LOCK(); |
| 1786 | XSetWindowBackgroundPixmap((Display*) jlong_to_ptr(display), (Window)window, (Pixmap)pixmap); |
| 1787 | } |
| 1788 | |
| 1789 | JNIEXPORT void JNICALL |
| 1790 | Java_sun_awt_X11_XlibWrapper_XClearWindow(JNIEnv *env, jclass clazz, jlong display, jlong window) |
| 1791 | { |
| 1792 | AWT_CHECK_HAVE_LOCK(); |
| 1793 | XClearWindow((Display*) jlong_to_ptr(display), (Window)window); |
| 1794 | } |
| 1795 | |
| 1796 | JNIEXPORT jint JNICALL |
| 1797 | Java_sun_awt_X11_XlibWrapper_XGetIconSizes(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong ret_sizes, jlong ret_count) |
| 1798 | { |
| 1799 | XIconSize** psize = (XIconSize**) jlong_to_ptr(ret_sizes); |
| 1800 | int * pcount = (int *) jlong_to_ptr(ret_count); |
| 1801 | Status res; |
| 1802 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1803 | res = XGetIconSizes((Display*) jlong_to_ptr(display), (Window)window, psize, pcount); |
| 1804 | return res; |
| 1805 | } |
| 1806 | |
| 1807 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeQueryExtension |
| 1808 | (JNIEnv *env, jclass clazz, jlong display, jlong major_version_return, |
| 1809 | jlong minor_version_return) |
| 1810 | { |
| 1811 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1812 | return XdbeQueryExtension((Display*) jlong_to_ptr(display), (int *) jlong_to_ptr(major_version_return), |
| 1813 | (int *) jlong_to_ptr(minor_version_return)); |
| 1814 | } |
| 1815 | |
| 1816 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryExtension |
| 1817 | (JNIEnv *env, jclass clazz, jlong display, jstring jstr, jlong mop_return, |
| 1818 | jlong feve_return, jlong err_return) |
| 1819 | { |
| 1820 | char *cname; |
| 1821 | Boolean bu; |
| 1822 | if (!JNU_IsNull(env, jstr)) { |
| 1823 | cname = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); |
| 1824 | CHECK_NULL_RETURN(cname, JNI_FALSE); |
| 1825 | } else { |
| 1826 | cname = "" ; |
| 1827 | } |
| 1828 | |
| 1829 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 1830 | bu = XQueryExtension((Display*) jlong_to_ptr(display), cname, (int *) jlong_to_ptr(mop_return), |
| 1831 | (int *) jlong_to_ptr(feve_return), (int *) jlong_to_ptr(err_return)); |
| 1832 | if (!JNU_IsNull(env, jstr)) { |
| 1833 | JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); |
| 1834 | } |
| 1835 | return bu ? JNI_TRUE : JNI_FALSE; |
| 1836 | } |
| 1837 | |
| 1838 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKeypadKey |
| 1839 | (JNIEnv *env, jclass clazz, jlong keysym) |
| 1840 | { |
| 1841 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 1842 | if(IsKeypadKey(keysym)) { |
| 1843 | return JNI_TRUE; |
| 1844 | } |
| 1845 | return JNI_FALSE; |
| 1846 | } |
| 1847 | |
| 1848 | JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XdbeAllocateBackBufferName |
| 1849 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jint swap_action) |
| 1850 | { |
| 1851 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1852 | return XdbeAllocateBackBufferName((Display*) jlong_to_ptr(display), (Window) window, |
| 1853 | (XdbeSwapAction) swap_action); |
| 1854 | } |
| 1855 | |
| 1856 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeDeallocateBackBufferName |
| 1857 | (JNIEnv *env, jclass clazz, jlong display, jlong buffer) |
| 1858 | { |
| 1859 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1860 | return XdbeDeallocateBackBufferName((Display*) jlong_to_ptr(display), (XdbeBackBuffer) buffer); |
| 1861 | } |
| 1862 | |
| 1863 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeBeginIdiom |
| 1864 | (JNIEnv *env, jclass clazz, jlong display) |
| 1865 | { |
| 1866 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1867 | return XdbeBeginIdiom((Display*) jlong_to_ptr(display)); |
| 1868 | } |
| 1869 | |
| 1870 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeEndIdiom |
| 1871 | (JNIEnv *env, jclass clazz, jlong display) |
| 1872 | { |
| 1873 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1874 | return XdbeEndIdiom((Display*) jlong_to_ptr(display)); |
| 1875 | } |
| 1876 | |
| 1877 | JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeSwapBuffers |
| 1878 | (JNIEnv *env, jclass clazz, jlong display, jlong swap_info, jint num_windows) |
| 1879 | { |
| 1880 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1881 | return XdbeSwapBuffers((Display*) jlong_to_ptr(display), (XdbeSwapInfo *) jlong_to_ptr(swap_info), num_windows); |
| 1882 | } |
| 1883 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XQueryKeymap |
| 1884 | (JNIEnv *env, jclass clazz, jlong display, jlong vector) |
| 1885 | { |
| 1886 | AWT_CHECK_HAVE_LOCK(); |
| 1887 | XQueryKeymap( (Display *) jlong_to_ptr(display), (char *) jlong_to_ptr(vector)); |
| 1888 | } |
| 1889 | |
| 1890 | // XKeycodeToKeysym is deprecated but for compatibility we keep the API. |
| 1891 | JNIEXPORT jlong JNICALL |
| 1892 | Java_sun_awt_X11_XlibWrapper_XKeycodeToKeysym(JNIEnv *env, jclass clazz, |
| 1893 | jlong display, jint keycode, |
| 1894 | jint index) { |
| 1895 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1896 | return keycodeToKeysym((Display*)jlong_to_ptr(display), (unsigned int)keycode, (int)index); |
| 1897 | } |
| 1898 | |
| 1899 | JNIEXPORT jint JNICALL |
| 1900 | Java_sun_awt_X11_XlibWrapper_XkbGetEffectiveGroup(JNIEnv *env, jclass clazz, |
| 1901 | jlong display) { |
| 1902 | XkbStateRec sr; |
| 1903 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1904 | memset(&sr, 0, sizeof(XkbStateRec)); |
| 1905 | XkbGetState((Display*) jlong_to_ptr(display), XkbUseCoreKbd, &sr); |
| 1906 | // printf("-------------------------------------VVVV\n"); |
| 1907 | // printf(" group:0x%0X\n",sr.group); |
| 1908 | // printf(" base_group:0x%0X\n",sr.base_group); |
| 1909 | // printf(" latched_group:0x%0X\n",sr.latched_group); |
| 1910 | // printf(" locked_group:0x%0X\n",sr.locked_group); |
| 1911 | // printf(" mods:0x%0X\n",sr.mods); |
| 1912 | // printf(" base_mods:0x%0X\n",sr.base_mods); |
| 1913 | // printf(" latched_mods:0x%0X\n",sr.latched_mods); |
| 1914 | // printf(" locked_mods:0x%0X\n",sr.locked_mods); |
| 1915 | // printf(" compat_state:0x%0X\n",sr.compat_state); |
| 1916 | // printf(" grab_mods:0x%0X\n",sr.grab_mods); |
| 1917 | // printf(" compat_grab_mods:0x%0X\n",sr.compat_grab_mods); |
| 1918 | // printf(" lookup_mods:0x%0X\n",sr.lookup_mods); |
| 1919 | // printf(" compat_lookup_mods:0x%0X\n",sr.compat_lookup_mods); |
| 1920 | // printf(" ptr_buttons:0x%0X\n",sr.ptr_buttons); |
| 1921 | // printf("-------------------------------------^^^^\n"); |
| 1922 | return (jint)(sr.group); |
| 1923 | } |
| 1924 | |
| 1925 | JNIEXPORT jlong JNICALL |
| 1926 | Java_sun_awt_X11_XlibWrapper_XkbKeycodeToKeysym(JNIEnv *env, jclass clazz, |
| 1927 | jlong display, jint keycode, |
| 1928 | jint group, jint level) { |
| 1929 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1930 | return XkbKeycodeToKeysym((Display*) jlong_to_ptr(display), (unsigned int)keycode, (unsigned int)group, (unsigned int)level); |
| 1931 | } |
| 1932 | |
| 1933 | JNIEXPORT jint JNICALL |
| 1934 | Java_sun_awt_X11_XlibWrapper_XKeysymToKeycode(JNIEnv *env, jclass clazz, |
| 1935 | jlong display, jlong keysym) { |
| 1936 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1937 | return XKeysymToKeycode((Display*) jlong_to_ptr(display), (KeySym)keysym); |
| 1938 | } |
| 1939 | |
| 1940 | JNIEXPORT jlong JNICALL |
| 1941 | Java_sun_awt_X11_XlibWrapper_XGetModifierMapping(JNIEnv *env, jclass clazz, |
| 1942 | jlong display) { |
| 1943 | AWT_CHECK_HAVE_LOCK_RETURN(0); |
| 1944 | return ptr_to_jlong(XGetModifierMapping((Display*) jlong_to_ptr(display))); |
| 1945 | } |
| 1946 | |
| 1947 | JNIEXPORT void JNICALL |
| 1948 | Java_sun_awt_X11_XlibWrapper_XFreeModifiermap(JNIEnv *env, jclass clazz, |
| 1949 | jlong keymap) { |
| 1950 | AWT_CHECK_HAVE_LOCK(); |
| 1951 | XFreeModifiermap((XModifierKeymap*) jlong_to_ptr(keymap)); |
| 1952 | } |
| 1953 | |
| 1954 | /* |
| 1955 | * Class: sun_awt_X11_XlibWrapper |
| 1956 | * Method: XRefreshKeyboardMapping |
| 1957 | * Signature: (J)V |
| 1958 | */ |
| 1959 | JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRefreshKeyboardMapping |
| 1960 | (JNIEnv *env, jclass clazz, jlong event_ptr) |
| 1961 | { |
| 1962 | AWT_CHECK_HAVE_LOCK(); |
| 1963 | XRefreshKeyboardMapping((XMappingEvent*) jlong_to_ptr(event_ptr)); |
| 1964 | } |
| 1965 | |
| 1966 | JNIEXPORT void JNICALL |
| 1967 | Java_sun_awt_X11_XlibWrapper_XChangeActivePointerGrab(JNIEnv *env, jclass clazz, |
| 1968 | jlong display, jint mask, |
| 1969 | jlong cursor, jlong time) { |
| 1970 | AWT_CHECK_HAVE_LOCK(); |
| 1971 | XChangeActivePointerGrab((Display*)jlong_to_ptr(display), (unsigned int)mask, |
| 1972 | (Cursor)cursor, (Time)time); |
| 1973 | } |
| 1974 | |
| 1975 | /******************* Secondary loop support ************************************/ |
| 1976 | #define AWT_SECONDARY_LOOP_TIMEOUT 250 |
| 1977 | |
| 1978 | static Bool exitSecondaryLoop = True; |
| 1979 | |
| 1980 | /* |
| 1981 | * This predicate procedure allows the Toolkit thread to process specific events |
| 1982 | * while it is blocked waiting for the event dispatch thread to process |
| 1983 | * a SunDropTargetEvent. We need this to prevent deadlock when the client code |
| 1984 | * processing SunDropTargetEvent sets or gets the contents of the system |
| 1985 | * clipboard/selection. In this case the event dispatch thread waits for the |
| 1986 | * Toolkit thread to process PropertyNotify or SelectionNotify events. |
| 1987 | */ |
| 1988 | static Bool |
| 1989 | secondary_loop_event(Display* dpy, XEvent* event, XPointer xawt_root_window) { |
| 1990 | return ( |
| 1991 | event->type == SelectionNotify || |
| 1992 | event->type == SelectionClear || |
| 1993 | event->type == PropertyNotify || |
| 1994 | (event->type == ConfigureNotify |
| 1995 | && event->xany.window == *(Window*) xawt_root_window) |
| 1996 | ) ? True : False; |
| 1997 | } |
| 1998 | |
| 1999 | JNIEXPORT jboolean JNICALL |
| 2000 | Java_sun_awt_X11_XlibWrapper_XNextSecondaryLoopEvent(JNIEnv *env, jclass clazz, |
| 2001 | jlong display, jlong ptr) { |
| 2002 | uint32_t timeout = 1; |
| 2003 | |
| 2004 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 2005 | exitSecondaryLoop = False; |
| 2006 | Window xawt_root_window = get_xawt_root_shell(env); |
| 2007 | |
| 2008 | while (!exitSecondaryLoop) { |
| 2009 | if (XCheckIfEvent((Display*) jlong_to_ptr(display), |
| 2010 | (XEvent*) jlong_to_ptr(ptr), secondary_loop_event, (XPointer) &xawt_root_window)) { |
| 2011 | return JNI_TRUE; |
| 2012 | } |
| 2013 | timeout = (timeout < AWT_SECONDARY_LOOP_TIMEOUT) ? (timeout << 1) : AWT_SECONDARY_LOOP_TIMEOUT; |
| 2014 | AWT_WAIT(timeout); |
| 2015 | } |
| 2016 | return JNI_FALSE; |
| 2017 | } |
| 2018 | |
| 2019 | JNIEXPORT void JNICALL |
| 2020 | Java_sun_awt_X11_XlibWrapper_ExitSecondaryLoop(JNIEnv *env, jclass clazz) { |
| 2021 | DASSERT(!exitSecondaryLoop); |
| 2022 | AWT_CHECK_HAVE_LOCK(); |
| 2023 | exitSecondaryLoop = True; |
| 2024 | AWT_NOTIFY_ALL(); |
| 2025 | } |
| 2026 | |
| 2027 | JNIEXPORT jobjectArray JNICALL |
| 2028 | Java_sun_awt_X11_XlibWrapper_XTextPropertyToStringList(JNIEnv *env, |
| 2029 | jclass clazz, |
| 2030 | jbyteArray bytes, |
| 2031 | jlong encodingAtom) { |
| 2032 | XTextProperty tp; |
| 2033 | jbyte *value; |
| 2034 | |
| 2035 | char** strings = (char **)NULL; |
| 2036 | int32_t nstrings = 0; |
| 2037 | jobjectArray ret = NULL; |
| 2038 | int32_t i; |
| 2039 | jsize len; |
| 2040 | jboolean isCopy = JNI_FALSE; |
| 2041 | static jclass stringClass = NULL; |
| 2042 | jclass stringClassLocal = NULL; |
| 2043 | |
| 2044 | AWT_CHECK_HAVE_LOCK_RETURN(NULL); |
| 2045 | |
| 2046 | if (JNU_IsNull(env, stringClass)) { |
| 2047 | stringClassLocal = (*env)->FindClass(env, "java/lang/String" ); |
| 2048 | |
| 2049 | if ((*env)->ExceptionCheck(env)) { |
| 2050 | (*env)->ExceptionDescribe(env); |
| 2051 | (*env)->ExceptionClear(env); |
| 2052 | DASSERT(False); |
| 2053 | } |
| 2054 | |
| 2055 | if (JNU_IsNull(env, stringClassLocal)) { |
| 2056 | return NULL; |
| 2057 | } |
| 2058 | |
| 2059 | stringClass = (*env)->NewGlobalRef(env, stringClassLocal); /* never freed! */ |
| 2060 | (*env)->DeleteLocalRef(env, stringClassLocal); |
| 2061 | |
| 2062 | if (JNU_IsNull(env, stringClass)) { |
| 2063 | JNU_ThrowOutOfMemoryError(env, "" ); |
| 2064 | return NULL; |
| 2065 | } |
| 2066 | } |
| 2067 | |
| 2068 | /* |
| 2069 | * If the length of the byte array is 0 just return a null |
| 2070 | */ |
| 2071 | len = (*env)->GetArrayLength(env, bytes); |
| 2072 | if (len == 0) { |
| 2073 | return (*env)->NewObjectArray(env, 0, stringClass, NULL); |
| 2074 | } |
| 2075 | |
| 2076 | value = (*env)->GetByteArrayElements(env, bytes, &isCopy); |
| 2077 | if (JNU_IsNull(env, value)) { |
| 2078 | return NULL; |
| 2079 | } |
| 2080 | |
| 2081 | tp.encoding = encodingAtom; |
| 2082 | tp.value = (unsigned char *)value; |
| 2083 | tp.nitems = len; |
| 2084 | tp.format = 8; |
| 2085 | |
| 2086 | /* |
| 2087 | * Convert the byte stream into a list of X11 strings |
| 2088 | */ |
| 2089 | if (XTextPropertyToStringList(&tp, &strings, &nstrings) == 0) { |
| 2090 | (*env)->ReleaseByteArrayElements(env, bytes, value, JNI_ABORT); |
| 2091 | return NULL; |
| 2092 | } |
| 2093 | |
| 2094 | (*env)->ReleaseByteArrayElements(env, bytes, value, JNI_ABORT); |
| 2095 | |
| 2096 | if (nstrings == 0) { |
| 2097 | return (*env)->NewObjectArray(env, 0, stringClass, NULL); |
| 2098 | } |
| 2099 | |
| 2100 | ret = (*env)->NewObjectArray(env, nstrings, stringClass, NULL); |
| 2101 | |
| 2102 | if ((*env)->ExceptionCheck(env)) { |
| 2103 | (*env)->ExceptionDescribe(env); |
| 2104 | (*env)->ExceptionClear(env); |
| 2105 | goto wayout; |
| 2106 | } |
| 2107 | |
| 2108 | if (JNU_IsNull(env, ret)) { |
| 2109 | goto wayout; |
| 2110 | } |
| 2111 | |
| 2112 | for (i = 0; i < nstrings; i++) { |
| 2113 | jstring string = (*env)->NewStringUTF(env, |
| 2114 | (const char *)strings[i]); |
| 2115 | if ((*env)->ExceptionCheck(env)) { |
| 2116 | (*env)->ExceptionDescribe(env); |
| 2117 | (*env)->ExceptionClear(env); |
| 2118 | goto wayout; |
| 2119 | } |
| 2120 | |
| 2121 | if (JNU_IsNull(env, string)) { |
| 2122 | goto wayout; |
| 2123 | } |
| 2124 | |
| 2125 | (*env)->SetObjectArrayElement(env, ret, i, string); |
| 2126 | |
| 2127 | if ((*env)->ExceptionCheck(env)) { |
| 2128 | (*env)->ExceptionDescribe(env); |
| 2129 | (*env)->ExceptionClear(env); |
| 2130 | goto wayout; |
| 2131 | } |
| 2132 | |
| 2133 | (*env)->DeleteLocalRef(env, string); |
| 2134 | } |
| 2135 | |
| 2136 | wayout: |
| 2137 | /* |
| 2138 | * Clean up and return |
| 2139 | */ |
| 2140 | XFreeStringList(strings); |
| 2141 | return ret; |
| 2142 | } |
| 2143 | |
| 2144 | JNIEXPORT void JNICALL |
| 2145 | Java_sun_awt_X11_XlibWrapper_XPutBackEvent(JNIEnv *env, |
| 2146 | jclass clazz, |
| 2147 | jlong display, |
| 2148 | jlong event) { |
| 2149 | XPutBackEvent((Display*)jlong_to_ptr(display), (XEvent*) jlong_to_ptr(event)); |
| 2150 | } |
| 2151 | |
| 2152 | JNIEXPORT jlong JNICALL |
| 2153 | Java_sun_awt_X11_XlibWrapper_getAddress(JNIEnv *env, |
| 2154 | jclass clazz, |
| 2155 | jobject o) { |
| 2156 | return ptr_to_jlong(o); |
| 2157 | } |
| 2158 | |
| 2159 | JNIEXPORT void JNICALL |
| 2160 | Java_sun_awt_X11_XlibWrapper_copyIntArray(JNIEnv *env, |
| 2161 | jclass clazz, |
| 2162 | jlong dest, jobject array, jint size) { |
| 2163 | jboolean isCopy = JNI_FALSE; |
| 2164 | jint * ints = (*env)->GetIntArrayElements(env, array, &isCopy); |
| 2165 | memcpy(jlong_to_ptr(dest), ints, size); |
| 2166 | if (isCopy) { |
| 2167 | (*env)->ReleaseIntArrayElements(env, array, ints, JNI_ABORT); |
| 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | JNIEXPORT void JNICALL |
| 2172 | Java_sun_awt_X11_XlibWrapper_copyLongArray(JNIEnv *env, |
| 2173 | jclass clazz, |
| 2174 | jlong dest, jobject array, jint size) { |
| 2175 | jboolean isCopy = JNI_FALSE; |
| 2176 | jlong * longs = (*env)->GetLongArrayElements(env, array, &isCopy); |
| 2177 | memcpy(jlong_to_ptr(dest), longs, size); |
| 2178 | if (isCopy) { |
| 2179 | (*env)->ReleaseLongArrayElements(env, array, longs, JNI_ABORT); |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | JNIEXPORT jint JNICALL |
| 2184 | Java_sun_awt_X11_XlibWrapper_XSynchronize(JNIEnv *env, jclass clazz, jlong display, jboolean onoff) |
| 2185 | { |
| 2186 | return (jint) XSynchronize((Display*)jlong_to_ptr(display), (onoff == JNI_TRUE ? True : False)); |
| 2187 | } |
| 2188 | |
| 2189 | JNIEXPORT jboolean JNICALL |
| 2190 | Java_sun_awt_X11_XlibWrapper_XShapeQueryExtension |
| 2191 | (JNIEnv *env, jclass clazz, jlong display, jlong event_base_return, jlong error_base_return) |
| 2192 | { |
| 2193 | Bool status; |
| 2194 | |
| 2195 | AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); |
| 2196 | |
| 2197 | status = XShapeQueryExtension((Display *)jlong_to_ptr(display), |
| 2198 | (int *)jlong_to_ptr(event_base_return), (int *)jlong_to_ptr(error_base_return)); |
| 2199 | return status ? JNI_TRUE : JNI_FALSE; |
| 2200 | } |
| 2201 | |
| 2202 | /* |
| 2203 | * Class: XlibWrapper |
| 2204 | * Method: SetRectangularShape |
| 2205 | */ |
| 2206 | |
| 2207 | JNIEXPORT void JNICALL |
| 2208 | Java_sun_awt_X11_XlibWrapper_SetRectangularShape |
| 2209 | (JNIEnv *env, jclass clazz, jlong display, jlong window, |
| 2210 | jint x1, jint y1, jint x2, jint y2, |
| 2211 | jobject region) |
| 2212 | { |
| 2213 | AWT_CHECK_HAVE_LOCK(); |
| 2214 | |
| 2215 | // If all the params are zeros, the shape must be simply reset. |
| 2216 | // Otherwise, the shape may be not rectangular. |
| 2217 | if (region || x1 || x2 || y1 || y2) { |
| 2218 | XRectangle rects[256]; |
| 2219 | XRectangle *pRect = rects; |
| 2220 | |
| 2221 | int numrects = RegionToYXBandedRectangles(env, x1, y1, x2, y2, region, |
| 2222 | &pRect, 256); |
| 2223 | |
| 2224 | XShapeCombineRectangles((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), |
| 2225 | ShapeClip, 0, 0, pRect, numrects, ShapeSet, YXBanded); |
| 2226 | XShapeCombineRectangles((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), |
| 2227 | ShapeBounding, 0, 0, pRect, numrects, ShapeSet, YXBanded); |
| 2228 | |
| 2229 | if (pRect != rects) { |
| 2230 | free(pRect); |
| 2231 | } |
| 2232 | } else { |
| 2233 | // Reset the shape to a rectangular form. |
| 2234 | XShapeCombineMask((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), |
| 2235 | ShapeClip, 0, 0, None, ShapeSet); |
| 2236 | XShapeCombineMask((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), |
| 2237 | ShapeBounding, 0, 0, None, ShapeSet); |
| 2238 | } |
| 2239 | } |
| 2240 | |
| 2241 | /* |
| 2242 | * Class: XlibWrapper |
| 2243 | * Method: SetZOrder |
| 2244 | */ |
| 2245 | |
| 2246 | JNIEXPORT void JNICALL |
| 2247 | Java_sun_awt_X11_XlibWrapper_SetZOrder |
| 2248 | (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong above) |
| 2249 | { |
| 2250 | unsigned int value_mask = CWStackMode; |
| 2251 | |
| 2252 | XWindowChanges wc; |
| 2253 | wc.sibling = (Window)jlong_to_ptr(above); |
| 2254 | |
| 2255 | AWT_CHECK_HAVE_LOCK(); |
| 2256 | |
| 2257 | if (above == 0) { |
| 2258 | wc.stack_mode = Above; |
| 2259 | } else { |
| 2260 | wc.stack_mode = Below; |
| 2261 | value_mask |= CWSibling; |
| 2262 | } |
| 2263 | |
| 2264 | XConfigureWindow((Display *)jlong_to_ptr(display), |
| 2265 | (Window)jlong_to_ptr(window), |
| 2266 | value_mask, &wc ); |
| 2267 | } |
| 2268 | |
| 2269 | /* |
| 2270 | * Class: XlibWrapper |
| 2271 | * Method: SetBitmapShape |
| 2272 | */ |
| 2273 | JNIEXPORT void JNICALL |
| 2274 | Java_sun_awt_X11_XlibWrapper_SetBitmapShape |
| 2275 | (JNIEnv *env, jclass clazz, jlong display, jlong window, |
| 2276 | jint width, jint height, jintArray bitmap) |
| 2277 | { |
| 2278 | jsize len; |
| 2279 | jint *values; |
| 2280 | jboolean isCopy = JNI_FALSE; |
| 2281 | size_t worstBufferSize = (size_t)((width / 2 + 1) * height); |
| 2282 | RECT_T * pRect; |
| 2283 | int numrects; |
| 2284 | |
| 2285 | if (!IS_SAFE_SIZE_MUL(width / 2 + 1, height)) { |
| 2286 | return; |
| 2287 | } |
| 2288 | |
| 2289 | AWT_CHECK_HAVE_LOCK(); |
| 2290 | |
| 2291 | len = (*env)->GetArrayLength(env, bitmap); |
| 2292 | if (len == 0 || len < width * height) { |
| 2293 | return; |
| 2294 | } |
| 2295 | |
| 2296 | values = (*env)->GetIntArrayElements(env, bitmap, &isCopy); |
| 2297 | if (JNU_IsNull(env, values)) { |
| 2298 | return; |
| 2299 | } |
| 2300 | |
| 2301 | pRect = (RECT_T *)SAFE_SIZE_ARRAY_ALLOC(malloc, worstBufferSize, sizeof(RECT_T)); |
| 2302 | if (!pRect) { |
| 2303 | return; |
| 2304 | } |
| 2305 | |
| 2306 | /* Note: the values[0] and values[1] are supposed to contain the width |
| 2307 | * and height (see XIconInfo.getIntData() for details). So, we do +2. |
| 2308 | */ |
| 2309 | numrects = BitmapToYXBandedRectangles(32, (int)width, (int)height, |
| 2310 | (unsigned char *)(values + 2), pRect); |
| 2311 | |
| 2312 | XShapeCombineRectangles((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), |
| 2313 | ShapeClip, 0, 0, pRect, numrects, ShapeSet, YXBanded); |
| 2314 | XShapeCombineRectangles((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), |
| 2315 | ShapeBounding, 0, 0, pRect, numrects, ShapeSet, YXBanded); |
| 2316 | |
| 2317 | free(pRect); |
| 2318 | |
| 2319 | (*env)->ReleaseIntArrayElements(env, bitmap, values, JNI_ABORT); |
| 2320 | } |
| 2321 | |