< prev index next >

src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c

Print this page
rev 50172 : 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
   1 /*
   2  * Copyright (c) 2002, 2017, 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 "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 #include <X11/Sunkeysym.h>
  37 
  38 #include <jni.h>
  39 #include <jni_util.h>
  40 #include <jlong.h>
  41 #include <sizecalc.h>
  42 
  43 #include <awt.h>
  44 #include <awt_util.h>
  45 #include <jvm.h>
  46 
  47 #include <Region.h>
  48 #include "utility/rect.h"
  49 
  50 #include <X11/XKBlib.h>







  51 
  52 // From XWindow.c
  53 extern KeySym keycodeToKeysym(Display *display, KeyCode keycode, int index);
  54 
  55 #if defined(DEBUG)
  56 static jmethodID lockIsHeldMID = NULL;
  57 
  58 static void
  59 CheckHaveAWTLock(JNIEnv *env)
  60 {
  61     if (lockIsHeldMID == NULL) {
  62         if (tkClass == NULL) return;
  63         lockIsHeldMID =
  64             (*env)->GetStaticMethodID(env, tkClass,
  65                                       "isAWTLockHeldByCurrentThread", "()Z");
  66         if (lockIsHeldMID == NULL) return;
  67     }
  68     if (!(*env)->CallStaticBooleanMethod(env, tkClass, lockIsHeldMID)) {
  69         JNU_ThrowInternalError(env, "Current thread does not hold AWT_LOCK!");
  70     }


 271  * Class:     sun_awt_X11_XlibWrapper
 272  * Method:    RootWindow
 273  * Signature: (JJ)J
 274  */
 275 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_RootWindow
 276 (JNIEnv *env , jclass clazz, jlong display, jlong screen_number) {
 277     AWT_CHECK_HAVE_LOCK_RETURN(0);
 278     return (jlong) RootWindow((Display *) jlong_to_ptr(display), screen_number);
 279 }
 280 
 281 /*
 282  * Class:     sun_awt_X11_XlibWrapper
 283  * Method:    ScreenCount
 284  */
 285 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_ScreenCount
 286 (JNIEnv *env , jclass clazz, jlong display) {
 287     AWT_CHECK_HAVE_LOCK_RETURN(0);
 288     return ScreenCount((Display *) jlong_to_ptr(display));
 289 }
 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 /*
 310  * Class:     XlibWrapper
 311  * Method:    XConvertCase
 312  * Signature: (JJJ)V
 313  */
 314 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XConvertCase
 315   (JNIEnv *env, jclass clazz, jlong keysym,
 316    jlong keysym_lowercase, jlong keysym_uppercase)
 317 {
 318     AWT_CHECK_HAVE_LOCK();
 319     XConvertCase(keysym, (jlong_to_ptr(keysym_lowercase)),
 320                          (jlong_to_ptr(keysym_uppercase)));
 321 }
 322 
 323 
 324 /*
 325  * Class:     XlibWrapper
 326  * Method:    XMapWindow
 327  * Signature: (JJ)V
 328  */
 329 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMapWindow
 330 (JNIEnv *env, jclass clazz, jlong display, jlong window)
 331 {
 332     AWT_CHECK_HAVE_LOCK();
 333     XMapWindow( (Display *)jlong_to_ptr(display),(Window) window);
 334 
 335 }
 336 
 337 /*
 338  * Class:     XlibWrapper
 339  * Method:    XMapRaised
 340  * Signature: (JJ)V
 341  */
 342 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMapRaised
 343 (JNIEnv *env, jclass clazz, jlong display, jlong window)
 344 {
 345     AWT_CHECK_HAVE_LOCK();
 346     XMapRaised( (Display *)jlong_to_ptr(display),(Window) window);
 347 
 348 }
 349 
 350 /*
 351  * Class:     XlibWrapper
 352  * Method:    XRaiseWindow
 353  * Signature: (JJ)V
 354  */
 355 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRaiseWindow
 356 (JNIEnv *env, jclass clazz, jlong display, jlong window)
 357 {
 358 
 359     AWT_CHECK_HAVE_LOCK();
 360     XRaiseWindow( (Display *)jlong_to_ptr(display),(Window) window);
 361 
 362 }
 363 
 364 /*
 365  * Class:     XlibWrapper
 366  * Method:    XLowerWindow
 367  * Signature: (JJ)V
 368  */
 369 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XLowerWindow
 370 (JNIEnv *env, jclass clazz, jlong display, jlong window)
 371 {
 372 
 373     AWT_CHECK_HAVE_LOCK();
 374     XLowerWindow( (Display *)jlong_to_ptr(display),(Window) window);
 375 
 376 }
 377 
 378 /*
 379  * Class:     XlibWrapper
 380  * Method:    XRestackWindows
 381  * Signature: (JJI)V
 382  */
 383 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRestackWindows
 384 (JNIEnv *env, jclass clazz, jlong display, jlong windows, jint length)
 385 {
 386 
 387     AWT_CHECK_HAVE_LOCK();
 388     XRestackWindows( (Display *) jlong_to_ptr(display), (Window *) jlong_to_ptr(windows), length);
 389 
 390 }
 391 
 392 /*
 393  * Class:     XlibWrapper
 394  * Method:    XConfigureWindow
 395  * Signature: (JJJJ)V
 396  */
 397 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XConfigureWindow
 398 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong value_mask,
 399  jlong values)
 400 {
 401     AWT_CHECK_HAVE_LOCK();
 402     XConfigureWindow((Display*)jlong_to_ptr(display), (Window)window,
 403             (unsigned int)value_mask, (XWindowChanges*)jlong_to_ptr(values));
 404 }
 405 
 406 /*
 407  * Class:     XlibWrapper
 408  * Method:    XSetInputFocus
 409  * Signature: (JJ)V
 410  */
 411 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetInputFocus
 412 (JNIEnv *env, jclass clazz, jlong display, jlong window)
 413 {
 414 
 415     AWT_CHECK_HAVE_LOCK();
 416     XSetInputFocus( (Display *)jlong_to_ptr(display),(Window) window, RevertToPointerRoot, CurrentTime);
 417 
 418 }

 419 /*
 420  * Class:     XlibWrapper
 421  * Method:    XSetInputFocus2
 422  * Signature: (JJJ)V
 423  */
 424 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetInputFocus2
 425 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong time)
 426 {
 427 
 428     AWT_CHECK_HAVE_LOCK();
 429     XSetInputFocus( (Display *)jlong_to_ptr(display),(Window) window, RevertToPointerRoot, time);
 430 
 431 }
 432 
 433 /*
 434  * Class:     XlibWrapper
 435  * Method:    XGetInputFocus
 436  * Signature: (JJ)V
 437  */
 438 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XGetInputFocus
 439 (JNIEnv *env, jclass clazz, jlong display)
 440 {
 441 
 442     Window focusOwner;
 443     int revert_to;
 444     AWT_CHECK_HAVE_LOCK_RETURN(0);
 445     XGetInputFocus( (Display *)jlong_to_ptr(display), &focusOwner, &revert_to);
 446     return focusOwner;
 447 }
 448 
 449 
 450 /*
 451  * Class:     XlibWrapper
 452  * Method:    XDestroyWindow
 453  * Signature: (JJ)V
 454  */
 455 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XDestroyWindow
 456 (JNIEnv *env, jclass clazz, jlong display, jlong window)
 457 {
 458     AWT_CHECK_HAVE_LOCK();
 459     XDestroyWindow( (Display *)jlong_to_ptr(display),(Window) window);
 460 }
 461 
 462 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGrabPointer
 463 (JNIEnv *env, jclass clazz, jlong display, jlong window,
 464  jint owner_events, jint event_mask, jint pointer_mode,
 465  jint keyboard_mode, jlong confine_to, jlong cursor, jlong time)
 466 {
 467     AWT_CHECK_HAVE_LOCK_RETURN(0);
 468     return XGrabPointer( (Display *)jlong_to_ptr(display), (Window) window,
 469              (Bool) owner_events, (unsigned int) event_mask, (int) pointer_mode,


 508      AWT_CHECK_HAVE_LOCK();
 509      XUngrabServer((Display*)jlong_to_ptr(display));
 510      /* Workaround for bug 5039226 */
 511      XSync((Display*)jlong_to_ptr(display), False);
 512 }
 513 
 514 /*
 515  * Class:     XlibWrapper
 516  * Method:    XUnmapWindow
 517  * Signature: (JJ)V
 518  */
 519 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUnmapWindow
 520 (JNIEnv *env, jclass clazz, jlong display, jlong window)
 521 {
 522 
 523     AWT_CHECK_HAVE_LOCK();
 524     XUnmapWindow( (Display *)jlong_to_ptr(display),(Window) window);
 525 
 526 }
 527 
 528 
 529 
 530 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSelectInput
 531 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong mask)
 532 {
 533     AWT_CHECK_HAVE_LOCK();
 534     XSelectInput((Display *) jlong_to_ptr(display), (Window) window, mask);
 535 }
 536 
 537 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbSelectEvents
 538 (JNIEnv *env, jclass clazz, jlong display, jlong device, jlong bits_to_change,
 539               jlong values_for_bits)
 540 {
 541     AWT_CHECK_HAVE_LOCK();
 542     XkbSelectEvents((Display *) jlong_to_ptr(display), (unsigned int)device,
 543                    (unsigned long)bits_to_change,
 544                    (unsigned long)values_for_bits);
 545 }

 546 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbSelectEventDetails
 547 (JNIEnv *env, jclass clazz, jlong display, jlong device, jlong event_type,
 548               jlong bits_to_change, jlong values_for_bits)
 549 {
 550     AWT_CHECK_HAVE_LOCK();
 551     XkbSelectEventDetails((Display *) jlong_to_ptr(display), (unsigned int)device,
 552                    (unsigned int) event_type,
 553                    (unsigned long)bits_to_change,
 554                    (unsigned long)values_for_bits);
 555 }

 556 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbQueryExtension
 557 (JNIEnv *env, jclass clazz, jlong display, jlong opcode_rtrn, jlong event_rtrn,
 558               jlong error_rtrn, jlong major_in_out, jlong minor_in_out)
 559 {
 560     Bool status;
 561     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
 562     status = XkbQueryExtension((Display *) jlong_to_ptr(display),
 563                                (int *) jlong_to_ptr(opcode_rtrn),
 564                                (int *) jlong_to_ptr(event_rtrn),
 565                                (int *) jlong_to_ptr(error_rtrn),
 566                                (int *) jlong_to_ptr(major_in_out),
 567                                (int *) jlong_to_ptr(minor_in_out));
 568     return status ? JNI_TRUE : JNI_FALSE;
 569 }

 570 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbLibraryVersion
 571 (JNIEnv *env, jclass clazz, jlong lib_major_in_out, jlong lib_minor_in_out)
 572 {
 573     Bool status;
 574     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
 575     *((int *)jlong_to_ptr(lib_major_in_out)) =  XkbMajorVersion;
 576     *((int *)jlong_to_ptr(lib_minor_in_out)) =  XkbMinorVersion;
 577     status = XkbLibraryVersion((int *)jlong_to_ptr(lib_major_in_out),
 578                                (int *)jlong_to_ptr(lib_minor_in_out));
 579     return status ? JNI_TRUE : JNI_FALSE;
 580 }
 581 
 582 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XkbGetMap
 583 (JNIEnv *env, jclass clazz, jlong display, jlong which, jlong device_spec)
 584 {
 585     AWT_CHECK_HAVE_LOCK_RETURN(0);
 586     return (jlong) XkbGetMap( (Display *) jlong_to_ptr(display),
 587                               (unsigned int) which,
 588                               (unsigned int) device_spec);
 589 }

 590 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XkbGetUpdatedMap
 591 (JNIEnv *env, jclass clazz, jlong display, jlong which, jlong xkb)
 592 {
 593     AWT_CHECK_HAVE_LOCK_RETURN(0);
 594     return (jlong) XkbGetUpdatedMap( (Display *) jlong_to_ptr(display),
 595                               (unsigned int) which,
 596                               (XkbDescPtr) jlong_to_ptr(xkb));
 597 }
 598 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbFreeKeyboard
 599 (JNIEnv *env, jclass clazz, jlong xkb, jlong which, jboolean free_all)
 600 {
 601     AWT_CHECK_HAVE_LOCK();
 602     XkbFreeKeyboard(jlong_to_ptr(xkb), (unsigned int)which, free_all);
 603 }
 604 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbTranslateKeyCode
 605 (JNIEnv *env, jclass clazz, jlong xkb, jint keycode, jlong mods, jlong mods_rtrn, jlong keysym_rtrn)
 606 {
 607     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
 608     Bool b;
 609     b = XkbTranslateKeyCode((XkbDescPtr)xkb, (unsigned int)keycode, (unsigned int)mods,
 610                               (unsigned int *)jlong_to_ptr(mods_rtrn),
 611                                (KeySym *)jlong_to_ptr(keysym_rtrn));
 612     //printf("native,  input: keycode:0x%0X; mods:0x%0X\n", keycode, mods);
 613     //printf("native, output:  keysym:0x%0X; mods:0x%0X\n",
 614     //       *(unsigned int *)jlong_to_ptr(keysym_rtrn),
 615     //       *(unsigned int *)jlong_to_ptr(mods_rtrn));
 616     return b ? JNI_TRUE : JNI_FALSE;
 617 }
 618 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbSetDetectableAutoRepeat
 619 (JNIEnv *env, jclass clazz, jlong display, jboolean detectable)
 620 {
 621     AWT_CHECK_HAVE_LOCK();
 622     XkbSetDetectableAutoRepeat((Display *) jlong_to_ptr(display), detectable, NULL);
 623 }
 624 /*
 625  * Class:     sun_awt_X11_XlibWrapper
 626  * Method:    XNextEvent
 627  * Signature: (JJ)V
 628  */
 629 
 630 
 631 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XNextEvent
 632 (JNIEnv *env, jclass clazz, jlong display, jlong ptr)
 633 {
 634     AWT_CHECK_HAVE_LOCK();
 635     XNextEvent( (Display *) jlong_to_ptr(display), jlong_to_ptr(ptr));
 636 }
 637 
 638 /*
 639  * Class:     sun_awt_X11_XlibWrapper
 640  * Method:    XMaskEvent
 641  * Signature: (JJJ)V
 642  */
 643 
 644 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMaskEvent
 645   (JNIEnv *env, jclass clazz, jlong display, jlong event_mask, jlong event_return)
 646 {
 647     AWT_CHECK_HAVE_LOCK();
 648     XMaskEvent( (Display *) jlong_to_ptr(display), event_mask, (XEvent *) jlong_to_ptr(event_return));
 649 }
 650 
 651 /*
 652  * Class:     sun_awt_X11_XlibWrapper
 653  * Method:    XWindowEvent
 654  * Signature: (JJJJ)V
 655  */
 656 
 657 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XWindowEvent
 658   (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong event_mask, jlong event_return)
 659 {
 660     AWT_CHECK_HAVE_LOCK();
 661     XWindowEvent( (Display *) jlong_to_ptr(display), (Window)window, event_mask, (XEvent *) jlong_to_ptr(event_return));
 662 }
 663 
 664 /*
 665  * Class:     sun_awt_X11_XlibWrapper
 666  * Method:    XFilterEvent
 667  * Signature: (JJ)Z
 668  */
 669 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XFilterEvent
 670 (JNIEnv *env, jclass clazz, jlong ptr, jlong window)
 671 {
 672     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);





 673     return (jboolean) XFilterEvent((XEvent *) jlong_to_ptr(ptr), (Window) window);
 674 }
 675 
 676 /*
 677  * Class:     sun_awt_X11_XlibWrapper
 678  * Method:    XSupportsLocale
 679  * Signature: ()Z
 680  */
 681 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XSupportsLocale
 682 (JNIEnv *env, jclass clazz)
 683 {
 684     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
 685     return (jboolean)XSupportsLocale();
 686 }
 687 
 688 /*
 689  * Class:     sun_awt_X11_XlibWrapper
 690  * Method:    XSetLocaleModifiers
 691  * Signature: (Ljava/lang/String;)Ljava/lang/String;
 692  */


 710     }
 711 
 712     return (ret != NULL ? JNU_NewStringPlatform(env, ret): NULL);
 713 }
 714 
 715 
 716 /*
 717  * Class:     sun_awt_X11_wrappers_XlibWrapper
 718  * Method:    XPeekEvent
 719  * Signature: (JJ)V
 720  */
 721 
 722 
 723 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XPeekEvent
 724 (JNIEnv *env, jclass clazz, jlong display, jlong ptr)
 725 {
 726     AWT_CHECK_HAVE_LOCK();
 727     XPeekEvent((Display *) jlong_to_ptr(display),jlong_to_ptr(ptr));
 728 }
 729 
 730 
 731 /*
 732  * Class:     sun_awt_X11_XlibWrapper
 733  * Method:    XMoveResizeWindow
 734  * Signature: (JJIIII)V
 735  */
 736 
 737 JNIEXPORT void JNICALL  Java_sun_awt_X11_XlibWrapper_XMoveResizeWindow
 738 (JNIEnv *env, jclass clazz, jlong display, jlong window, jint x , jint y , jint width, jint height) {
 739 
 740     AWT_CHECK_HAVE_LOCK();
 741     XMoveResizeWindow( (Display *) jlong_to_ptr(display), (Window) window, x, y, width, height);
 742 
 743 }
 744 
 745 /*
 746  * Class:     sun_awt_X11_XlibWrapper
 747  * Method:    XResizeWindow
 748  * Signature: (JJII)V
 749  */
 750 
 751 JNIEXPORT void JNICALL  Java_sun_awt_X11_XlibWrapper_XResizeWindow
 752 (JNIEnv *env, jclass clazz, jlong display, jlong window, jint width, jint height)
 753 {
 754     AWT_CHECK_HAVE_LOCK();
 755     XResizeWindow( (Display *) jlong_to_ptr(display),(Window) window,width,height);
 756 }
 757 
 758 /*
 759  * Class:     sun_awt_X11_XlibWrapper
 760  * Method:    XMoveWindow
 761  * Signature: (JJII)V
 762  */
 763 
 764 JNIEXPORT void JNICALL  Java_sun_awt_X11_XlibWrapper_XMoveWindow
 765 (JNIEnv *env, jclass clazz, jlong display, jlong window, jint width, jint height)
 766 {
 767     AWT_CHECK_HAVE_LOCK();
 768     XMoveWindow( (Display *) jlong_to_ptr(display),(Window) window,width,height);
 769 }
 770 
 771 
 772 /*
 773  * Class:     sun_awt_X11_XlibWrapper
 774  * Method:    XSetWindowBackground
 775  * Signature: (JJJ)V
 776  */
 777 
 778 JNIEXPORT void JNICALL  Java_sun_awt_X11_XlibWrapper_XSetWindowBackground
 779 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong background_pixel) {
 780 
 781     AWT_CHECK_HAVE_LOCK();
 782     XSetWindowBackground((Display *) jlong_to_ptr(display),window,background_pixel);
 783 
 784 }
 785 
 786 
 787 /*
 788  * Class:     sun_awt_X11_XlibWrapper
 789  * Method:    XFlush
 790  * Signature: (J)V
 791  */
 792 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFlush
 793 (JNIEnv *env, jclass clazz, jlong display) {
 794 
 795     AWT_CHECK_HAVE_LOCK();
 796     XFlush((Display *)jlong_to_ptr(display));
 797 }
 798 
 799 /*
 800  * Class:     sun_awt_X11_XlibWrapper
 801  * Method:    XSync
 802  * Signature: (JI)V
 803  */
 804 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSync
 805 (JNIEnv *env, jclass clazz, jlong display, jint discard) {
 806 
 807     AWT_CHECK_HAVE_LOCK();
 808     XSync((Display *) jlong_to_ptr(display), discard);
 809 
 810 }
 811 
 812 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XTranslateCoordinates
 813 (JNIEnv *env, jclass clazz, jlong display, jlong src_w, jlong dest_w,
 814  jlong src_x, jlong src_y, jlong dest_x_return, jlong dest_y_return,
 815  jlong child_return)
 816 {
 817     AWT_CHECK_HAVE_LOCK_RETURN(0);
 818     return XTranslateCoordinates( (Display *) jlong_to_ptr(display), src_w, dest_w,
 819                   src_x, src_y,
 820                   (int *) jlong_to_ptr(dest_x_return),
 821                   (int *) jlong_to_ptr(dest_y_return),
 822                   (Window *) jlong_to_ptr(child_return));
 823 }
 824 
 825 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XEventsQueued
 826 (JNIEnv *env, jclass clazz, jlong display, jint mode) {
 827 
 828     AWT_CHECK_HAVE_LOCK_RETURN(0);
 829     return XEventsQueued((Display *) jlong_to_ptr(display), mode);


 838 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_SetProperty
 839 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom, jstring jstr) {
 840     char *cname;
 841     XTextProperty tp;
 842     int32_t status;
 843 
 844     /*
 845        In case there are direct support of UTF-8 declared, use UTF-8 strings.
 846     */
 847     if (!JNU_IsNull(env, jstr)) {
 848 #ifdef X_HAVE_UTF8_STRING
 849         cname = (char *) (*env)->GetStringUTFChars(env, jstr, JNI_FALSE);
 850 #else
 851         cname = (char *) JNU_GetStringPlatformChars(env, jstr, NULL);
 852 #endif
 853         CHECK_NULL(cname);
 854     } else {
 855         cname = "";
 856     }
 857 
 858 
 859     AWT_CHECK_HAVE_LOCK();
 860 
 861 #ifdef X_HAVE_UTF8_STRING
 862     status = Xutf8TextListToTextProperty((Display *)jlong_to_ptr(display), &cname, 1,
 863                                        XStdICCTextStyle, &tp);
 864 #else
 865     status = XmbTextListToTextProperty((Display *)jlong_to_ptr(display), &cname, 1,
 866                                        XStdICCTextStyle, &tp);
 867 #endif
 868 
 869 
 870     if (status == Success || status > 0) {
 871         XChangeProperty((Display *)jlong_to_ptr(display), window, atom, tp.encoding, tp.format, PropModeReplace, tp.value, tp.nitems);
 872         if (tp.value != NULL) {
 873             XFree(tp.value);
 874         }
 875     }
 876 
 877     if (!JNU_IsNull(env, jstr)) {
 878 #ifdef X_HAVE_UTF8_STRING
 879         (*env)->ReleaseStringUTFChars(env, jstr, (const char *) cname);
 880 #else
 881         JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname);
 882 #endif
 883     }
 884 }
 885 
 886 /*
 887  * Class:     sun_awt_X11_XlibWrapper
 888  * Method:    XChangeProperty
 889  * Signature: (JJJJJJJJJJJ)V


 988     } else {
 989         cname = "";
 990     }
 991 
 992     atom = XInternAtom((Display *) jlong_to_ptr(display), cname, ife);
 993 
 994     if (!JNU_IsNull(env, jstr)) {
 995         JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname);
 996     }
 997 
 998     return (jlong) atom;
 999 
1000 }
1001 
1002 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XCreateFontCursor
1003 (JNIEnv *env, jclass clazz, jlong display, jint shape) {
1004     AWT_CHECK_HAVE_LOCK_RETURN(0);
1005     return XCreateFontCursor((Display *) jlong_to_ptr(display), (int) shape);
1006 }
1007 
1008 
1009 /*
1010  * Class:     sun_awt_X11_XlibWrapper
1011  * Method:    XCreatePixmapCursor
1012  * Signature: (JJJJJII)J
1013  */
1014 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreatePixmapCursor
1015 (JNIEnv *env , jclass clazz, jlong display, jlong source, jlong mask, jlong fore, jlong back, jint x , jint y) {
1016 
1017     AWT_CHECK_HAVE_LOCK_RETURN(0);
1018     return (jlong) XCreatePixmapCursor((Display *) jlong_to_ptr(display), (Pixmap) source, (Pixmap) mask,
1019                                        (XColor *) jlong_to_ptr(fore), (XColor *) jlong_to_ptr(back), x, y);
1020 }
1021 
1022 
1023 /*
1024  * Class:     sun_awt_X11_XlibWrapper
1025  * Method:    XQueryBestCursor
1026  * Signature: (JJIIJJ)Z
1027  */
1028 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryBestCursor
1029 (JNIEnv *env, jclass clazz, jlong display, jlong drawable, jint width, jint height, jlong width_return, jlong height_return) {
1030 
1031     Status status;
1032 
1033     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
1034     status  =  XQueryBestCursor((Display *) jlong_to_ptr(display), (Drawable) drawable, width,height,
1035                                 (unsigned int *) jlong_to_ptr(width_return), (unsigned int *) jlong_to_ptr(height_return));
1036 
1037     if (status == 0) return JNI_FALSE;
1038     else return JNI_TRUE;
1039 }
1040 
1041 
1042 /*
1043  * Class:     sun_awt_X11_XlibWrapper
1044  * Method:    XFreeCursor
1045  * Signature: (JJ)V
1046  */
1047 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFreeCursor
1048 (JNIEnv *env, jclass clazz, jlong display, jlong cursor) {
1049 
1050     AWT_CHECK_HAVE_LOCK();
1051     XFreeCursor( (Display *) jlong_to_ptr(display), (Cursor) cursor);
1052 }
1053 
1054 /*
1055  * Class:     sun_awt_X11_XlibWrapper
1056  * Method:    XQueryPointer
1057  * Signature: (JJJJJJJJJ)Z
1058  */
1059 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryPointer
1060 (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) {
1061 


1067                       (int *) jlong_to_ptr(root_x_return), (int *) jlong_to_ptr(root_y_return),
1068                       (int *) jlong_to_ptr(win_x_return), (int *) jlong_to_ptr(win_y_return),
1069                       (unsigned int *) jlong_to_ptr(mask_return));
1070 
1071     return b ? JNI_TRUE : JNI_FALSE;
1072 }
1073 
1074 /*
1075  * Class:     sun_awt_X11_XlibWrapper
1076  * Method:    XChangeWindowAttributes
1077  * Signature: (JJJJ)V
1078  */
1079 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangeWindowAttributes
1080 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong valuemask, jlong attributes) {
1081 
1082     AWT_CHECK_HAVE_LOCK();
1083     XChangeWindowAttributes((Display *) jlong_to_ptr(display), (Window) window, (unsigned long) valuemask,
1084                             (XSetWindowAttributes *) jlong_to_ptr(attributes));
1085 }
1086 
1087 
1088 /*
1089  * Class:     sun_awt_X11_XlibWrapper
1090  * Method:    XSetTransientFor
1091  * Signature: (JJJ)V
1092  */
1093 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetTransientFor
1094 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong transient_for_window)
1095 {
1096     AWT_CHECK_HAVE_LOCK();
1097     XSetTransientForHint((Display *) jlong_to_ptr(display), window, transient_for_window);
1098 }
1099 
1100 /*
1101  * Class:     sun_awt_X11_XlibWrapper
1102  * Method:    XSetWMHints
1103  * Signature: (JJJ)V
1104  */
1105 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWMHints
1106 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints)
1107 {


1164     if (c_option == NULL) {
1165         JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program);
1166         return NULL;
1167     }
1168 
1169     AWT_CHECK_HAVE_LOCK_RETURN(NULL);
1170     c_res = XGetDefault((Display*)jlong_to_ptr(display), c_program, c_option);
1171     // The strings returned by XGetDefault() are owned by Xlib and
1172     // should not be modified or freed by the client.
1173 
1174     JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program);
1175     JNU_ReleaseStringPlatformChars(env, option, (const char *) c_option);
1176 
1177     if (c_res != NULL) {
1178         return JNU_NewStringPlatform(env, c_res);
1179     } else {
1180         return NULL;
1181     }
1182 }
1183 
1184 
1185 /*
1186  * Class:     sun_awt_X11_XlibWrapper
1187  * Method:    getScreenOfWindow
1188  * Signature: (JJ)J
1189  */
1190 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_getScreenOfWindow
1191 (JNIEnv *env, jclass clazz, jlong display, jlong window)
1192 {
1193     XWindowAttributes attrs;
1194     memset(&attrs, 0, sizeof(attrs));
1195     AWT_CHECK_HAVE_LOCK_RETURN(0);
1196     XGetWindowAttributes((Display *) jlong_to_ptr(display), window, &attrs);
1197     return ptr_to_jlong(attrs.screen);
1198 }
1199 
1200 /*
1201  * Class:     sun_awt_X11_XlibWrapper
1202  * Method:    XScreenNumberOfScreen
1203  * Signature: (J)J
1204  */


1236     XFree(jlong_to_ptr(ptr));
1237 }
1238 
1239 /*
1240  * Class:     sun_awt_X11_XlibWrapper
1241  * Method:    XFree
1242  * Signature: (J)V
1243  */
1244 JNIEXPORT jbyteArray JNICALL Java_sun_awt_X11_XlibWrapper_getStringBytes
1245 (JNIEnv *env, jclass clazz, jlong str_ptr)
1246 {
1247     unsigned char * str = (unsigned char*) jlong_to_ptr(str_ptr);
1248     long length = strlen((char*)str);
1249     jbyteArray res = (*env)->NewByteArray(env, length);
1250     CHECK_NULL_RETURN(res, NULL);
1251     (*env)->SetByteArrayRegion(env, res, 0, length,
1252                    (const signed char*) str);
1253     return res;
1254 }
1255 
1256 
1257 /*
1258  * Class:     sun_awt_X11_XlibWrapper
1259  * Method:    ServerVendor
1260  * Signature: (J)Ljava/lang/String;
1261  */
1262 JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_ServerVendor
1263 (JNIEnv *env, jclass clazz, jlong display)
1264 {
1265     AWT_CHECK_HAVE_LOCK_RETURN(NULL);
1266     return JNU_NewStringPlatform(env, ServerVendor((Display*)jlong_to_ptr(display)));
1267 }

1268 /*
1269  * Class:     sun_awt_X11_XlibWrapper
1270  * Method:    VendorRelease
1271  * Signature: (J)I;
1272  */
1273 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_VendorRelease
1274 (JNIEnv *env, jclass clazz, jlong display)
1275 {
1276     AWT_CHECK_HAVE_LOCK_RETURN(0);
1277     return VendorRelease((Display*)jlong_to_ptr(display));
1278 }

1279 /*
1280  * Class:     sun_awt_X11_XlibWrapper
1281  * Method:    IsXsunKPBehavior
1282  * Signature: (J)Z;
1283  */
1284 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsXsunKPBehavior
1285 (JNIEnv *env, jclass clazz, jlong display)
1286 {
1287     // Xsun without XKB uses keysymarray[2] keysym to determine if it is KP event.
1288     // Otherwise, it is [1] or sometimes [0].
1289     // This sniffer first tries to determine what is a keycode for XK_KP_7
1290     // using XKeysymToKeycode;
1291     // second, in which place in the keysymarray is XK_KP_7
1292     // using XKeycodeToKeysym.
1293     int kc7;
1294     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
1295     kc7 = XKeysymToKeycode((Display*)jlong_to_ptr(display), XK_KP_7);
1296     if( !kc7 ) {
1297         // keycode is not defined. Why, it's a reduced keyboard perhaps:
1298         // report arbitrarily false.
1299         return JNI_FALSE;
1300     } else {
1301         long ks2 = keycodeToKeysym((Display*)jlong_to_ptr(display), kc7, 2);
1302         if( ks2 == XK_KP_7 ) {
1303             //XXX If some Xorg server would put XK_KP_7 in keysymarray[2] as well,
1304             //XXX for yet unknown to me reason, the sniffer would lie.
1305             return JNI_TRUE;
1306         }else{
1307             return JNI_FALSE;
1308         }
1309     }
1310 }
1311 
1312 
1313 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsSunKeyboard
1314 (JNIEnv *env, jclass clazz, jlong display)
1315 {
1316     int xx;
1317     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
1318     xx = XKeysymToKeycode((Display*)jlong_to_ptr(display), SunXK_F37);
1319     return (!xx) ? JNI_FALSE : JNI_TRUE;
1320 }
1321 
1322 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKanaKeyboard
1323 (JNIEnv *env, jclass clazz, jlong display)
1324 {
1325     int xx;
1326     static jboolean result = JNI_FALSE;
1327 
1328     int32_t minKeyCode, maxKeyCode, keySymsPerKeyCode;
1329     KeySym *keySyms, *keySymsStart, keySym;
1330     int32_t i;
1331     int32_t kanaCount = 0;
1332 


1390  * Signature: (J)V
1391  */
1392 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetErrorHandler
1393 (JNIEnv *env, jclass clazz, jlong handler)
1394 {
1395     AWT_CHECK_HAVE_LOCK();
1396     XSetErrorHandler((XErrorHandler) jlong_to_ptr(handler));
1397 }
1398 
1399 /*
1400  * Class:     sun_awt_X11_XlibWrapper
1401  * Method:    CallErrorHandler
1402  * Signature: (JJJ)I
1403  */
1404 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_CallErrorHandler
1405 (JNIEnv *env, jclass clazz, jlong handler, jlong display, jlong event_ptr)
1406 {
1407     return (*(XErrorHandler)jlong_to_ptr(handler))((Display*) jlong_to_ptr(display), (XErrorEvent*) jlong_to_ptr(event_ptr));
1408 }
1409 
1410 
1411 /*
1412  * Class:     sun_awt_X11_XlibWrapper
1413  * Method:    PrintXErrorEvent
1414  * Signature: (JJ)V
1415  */
1416 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_PrintXErrorEvent
1417 (JNIEnv *env, jclass clazz, jlong display, jlong event_ptr)
1418 {
1419     char msg[128];
1420     char buf[128];
1421 
1422     XErrorEvent* err = (XErrorEvent *)jlong_to_ptr(event_ptr);
1423 
1424     XGetErrorText((Display *)jlong_to_ptr(display), err->error_code, msg, sizeof(msg));
1425     jio_fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid, err->serial);
1426     jio_snprintf(buf, sizeof(buf), "%d", err->request_code);
1427     XGetErrorDatabaseText((Display *)jlong_to_ptr(display), "XRequest", buf, "Unknown", msg, sizeof(msg));
1428     jio_fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg);
1429     if (err->request_code > 128) {
1430         jio_fprintf(stderr, "Minor opcode %d\n", err->minor_code);
1431     }
1432 }
1433 
1434 
1435 /*
1436  * Class:     sun_awt_X11_XlibWrapper
1437  * Method:    XInternAtoms
1438  * Signature: (J[Ljava/lang/String;ZJ)I
1439  */
1440 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XInternAtoms
1441 (JNIEnv *env, jclass clazz, jlong display, jobjectArray names_arr, jboolean only_if_exists, jlong atoms)
1442 {
1443     int status = 0;
1444     AWT_CHECK_HAVE_LOCK_RETURN(0);
1445     jsize length;
1446     char** names = stringArrayToNative(env, names_arr, &length);
1447     if (names) {
1448         status = XInternAtoms((Display*)jlong_to_ptr(display), names, length, only_if_exists, (Atom*) jlong_to_ptr(atoms));
1449         freeNativeStringArray(names, length);
1450     }
1451     return status;
1452 }
1453 
1454 
1455 
1456 /*
1457  * Class:     sun_awt_X11_XlibWrapper
1458  * Method:    XGetWindowAttributes
1459  * Signature: (JJJ)I
1460  */
1461 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWindowAttributes
1462 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong attr_ptr)
1463 {
1464     jint status;
1465     AWT_CHECK_HAVE_LOCK_RETURN(0);
1466     memset((XWindowAttributes*) jlong_to_ptr(attr_ptr), 0, sizeof(XWindowAttributes));
1467     status =  XGetWindowAttributes((Display*)jlong_to_ptr(display), window, (XWindowAttributes*) jlong_to_ptr(attr_ptr));
1468     return status;
1469 }
1470 
1471 
1472 /*
1473  * Class:     sun_awt_X11_XlibWrapper
1474  * Method:    XGetGeometry
1475  * Signature: (JJJJJJJJJ)I
1476  */
1477 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetGeometry
1478 (JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong root_return,
1479      jlong x_return, jlong y_return, jlong width_return, jlong height_return,
1480      jlong border_width_return, jlong depth_return)
1481 {
1482     jint status;
1483     AWT_CHECK_HAVE_LOCK_RETURN(0);
1484     status = XGetGeometry((Display *)jlong_to_ptr(display),
1485                           (Drawable)drawable, (Window *)jlong_to_ptr(root_return),
1486                           (int *)jlong_to_ptr(x_return), (int *)jlong_to_ptr(y_return),
1487                           (unsigned int *)jlong_to_ptr(width_return), (unsigned int *)jlong_to_ptr(height_return),
1488                           (unsigned int *)jlong_to_ptr(border_width_return),
1489                           (unsigned int *)jlong_to_ptr(depth_return));
1490     return status;
1491 }
1492 
1493 
1494 /*
1495  * Class:     sun_awt_X11_XlibWrapper
1496  * Method:    XGetWMNormalHints
1497  * Signature: (JJJJ)I
1498  */
1499 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWMNormalHints
1500 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints, jlong supplied_return)
1501 {
1502     AWT_CHECK_HAVE_LOCK_RETURN(0);
1503     return XGetWMNormalHints((Display*) jlong_to_ptr(display),
1504                              window,
1505                              (XSizeHints*) jlong_to_ptr(hints),
1506                              (long*) jlong_to_ptr(supplied_return));
1507 }
1508 
1509 /*
1510  * Class:     sun_awt_X11_XlibWrapper
1511  * Method:    XSetWMNormalHints
1512  * Signature: (JJJ)V
1513  */


1529     AWT_CHECK_HAVE_LOCK();
1530     XDeleteProperty((Display*) jlong_to_ptr(display), window, (Atom)atom);
1531 }
1532 
1533 /*
1534  * Class:     sun_awt_X11_XlibWrapper
1535  * Method:    XSendEvent
1536  * Signature: (JJZJJ)V
1537  */
1538 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XSendEvent
1539 (JNIEnv *env, jclass clazz, jlong display, jlong window, jboolean propagate, jlong event_mask, jlong event)
1540 {
1541     AWT_CHECK_HAVE_LOCK_RETURN(0);
1542     return XSendEvent((Display*) jlong_to_ptr(display),
1543                       window,
1544                       propagate==JNI_TRUE?True:False,
1545                       (long) event_mask,
1546                       (XEvent*) jlong_to_ptr(event));
1547 }
1548 
1549 
1550 /*
1551  * Class:     sun_awt_X11_XlibWrapper
1552  * Method:    XQueryTree
1553  * Signature: (JJJJJJ)I
1554  */
1555 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XQueryTree
1556 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong root_return, jlong parent_return, jlong children_return, jlong nchildren_return)
1557 {
1558     AWT_CHECK_HAVE_LOCK_RETURN(0);
1559     return XQueryTree((Display*) jlong_to_ptr(display),
1560                       window,
1561                       (Window *) jlong_to_ptr(root_return),
1562                       (Window*) jlong_to_ptr(parent_return),
1563                       (Window**) jlong_to_ptr(children_return),
1564                       (unsigned int*) jlong_to_ptr(nchildren_return));
1565 }
1566 
1567 
1568 /*
1569  * Class:     sun_awt_X11_XlibWrapper
1570  * Method:    memcpy
1571  * Signature: (JJJ)V
1572  */
1573 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_memcpy
1574 (JNIEnv *env, jclass clazz, jlong dest_ptr, jlong src_ptr, jlong length)
1575 {
1576     memcpy(jlong_to_ptr(dest_ptr), jlong_to_ptr(src_ptr), length);
1577 }
1578 
1579 
1580 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetMinMaxHints
1581 (JNIEnv *env, jclass clazz, jlong display, jlong window, jint x, jint y, jint width, jint height, jlong flags) {
1582     XSizeHints * hints;
1583     AWT_CHECK_HAVE_LOCK();
1584     hints = XAllocSizeHints();
1585     hints->flags = flags;
1586     hints->width = width;
1587     hints->min_width = width;
1588     hints->max_width = width;
1589     hints->height = height;
1590     hints->min_height = height;
1591     hints->max_height = height;
1592     hints->x = x;
1593     hints->y = y;
1594     XSetWMNormalHints((Display*) jlong_to_ptr(display), window, hints);
1595     XFree(hints);
1596 }
1597 
1598 
1599 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XGetVisualInfo
1600 (JNIEnv *env, jclass clazz, jlong display, jlong vinfo_mask, jlong vinfo_template,
1601  jlong nitems_return)
1602 {
1603     AWT_CHECK_HAVE_LOCK_RETURN(0);
1604     return ptr_to_jlong(XGetVisualInfo((Display*) jlong_to_ptr(display),
1605                                        (long) vinfo_mask,
1606                                        (XVisualInfo*) jlong_to_ptr(vinfo_template),
1607                                        (int*) jlong_to_ptr(nitems_return)));
1608 }
1609 
1610 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XAllocSizeHints
1611   (JNIEnv *env, jclass clazz)
1612 {
1613     AWT_CHECK_HAVE_LOCK_RETURN(0);
1614     return ptr_to_jlong(XAllocSizeHints());
1615 }
1616 
1617 /*
1618  * Class:     sun_awt_X11_XlibWrapper
1619  * Method:    XIconifyWindow
1620  * Signature: (JJJ)V
1621  */
1622 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XBell
1623 (JNIEnv *env, jclass clazz, jlong display, jint percent)
1624 {
1625     AWT_CHECK_HAVE_LOCK();
1626     XBell((Display*)jlong_to_ptr(display), percent);
1627 }
1628 
1629 
1630 /*
1631  * Class:     sun_awt_X11_XlibWrapper
1632  * Method:    XAllocColor
1633  * Signature: (JJJ)Z
1634  */
1635 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XAllocColor
1636 (JNIEnv *env, jclass clazz, jlong display , jlong colormap, jlong xcolor) {
1637 
1638     Status status;
1639     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
1640     status = XAllocColor((Display *) jlong_to_ptr(display), (Colormap) colormap, (XColor *) jlong_to_ptr(xcolor));
1641 
1642     if (status == 0) return JNI_FALSE;
1643     else return JNI_TRUE;
1644 }
1645 
1646 
1647 /*
1648  * Class:     sun_awt_X11_XlibWrapper
1649  * Method:    XCreateBitmapFromData
1650  * Signature: (JJJII)J
1651  */
1652 JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreateBitmapFromData
1653 (JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong data, jint width, jint height) {
1654     AWT_CHECK_HAVE_LOCK_RETURN(0);
1655 
1656     return (jlong) XCreateBitmapFromData((Display *) jlong_to_ptr(display), (Drawable) drawable,
1657                                          (char *) jlong_to_ptr(data), width, height);
1658 }
1659 
1660 
1661 /*
1662  * Class:     sun_awt_X11_XlibWrapper
1663  * Method:    XFreePixmap
1664  * Signature: (JJ)V
1665  */
1666 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFreePixmap
1667 (JNIEnv *env, jclass clazz, jlong display, jlong pixmap) {
1668     AWT_CHECK_HAVE_LOCK();
1669     XFreePixmap((Display *)jlong_to_ptr(display), (Pixmap) pixmap);
1670 }
1671 
1672 /*
1673  * Class:     sun_awt_X11_XlibWrapper
1674  * Method:    XReparentWindow
1675  * Signature: (JJJII)V
1676  */
1677 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XReparentWindow
1678 (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong parent, jint x, jint y) {
1679     AWT_CHECK_HAVE_LOCK();
1680     XReparentWindow((Display*)jlong_to_ptr(display), window, parent, x, y);


1755 JNIEXPORT jlong JNICALL
1756 Java_sun_awt_X11_XlibWrapper_XMaxRequestSize(JNIEnv *env, jclass clazz,
1757                          jlong display) {
1758     AWT_CHECK_HAVE_LOCK_RETURN(0);
1759     return XMaxRequestSize((Display*) jlong_to_ptr(display));
1760 }
1761 
1762 JNIEXPORT jlong JNICALL
1763 Java_sun_awt_X11_XlibWrapper_XAllocWMHints(JNIEnv *env, jclass clazz)
1764 {
1765     AWT_CHECK_HAVE_LOCK_RETURN(0);
1766     return ptr_to_jlong(XAllocWMHints());
1767 }
1768 
1769 JNIEXPORT jlong JNICALL
1770 Java_sun_awt_X11_XlibWrapper_XCreatePixmap(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jint width, jint height, jint depth)
1771 {
1772     AWT_CHECK_HAVE_LOCK_RETURN(0);
1773     return XCreatePixmap((Display*)jlong_to_ptr(display), (Drawable)drawable, width, height, depth);
1774 }

1775 JNIEXPORT jlong JNICALL
1776 Java_sun_awt_X11_XlibWrapper_XCreateImage
1777   (JNIEnv *env, jclass clazz, jlong display, jlong visual_ptr,
1778    jint depth, jint format, jint offset, jlong data, jint width,
1779    jint height, jint bitmap_pad, jint bytes_per_line)
1780 {
1781     AWT_CHECK_HAVE_LOCK_RETURN(0);
1782     return ptr_to_jlong(XCreateImage((Display*) jlong_to_ptr(display), (Visual*) jlong_to_ptr(visual_ptr),
1783                 depth, format, offset, (char*) jlong_to_ptr(data),
1784                 width, height, bitmap_pad, bytes_per_line));
1785 }

1786 JNIEXPORT jlong JNICALL
1787 Java_sun_awt_X11_XlibWrapper_XCreateGC
1788   (JNIEnv *env, jclass clazz, jlong display, jlong drawable,
1789    jlong valuemask, jlong values)
1790 {
1791     AWT_CHECK_HAVE_LOCK_RETURN(0);
1792     return ptr_to_jlong(XCreateGC((Display*) jlong_to_ptr(display), (Drawable)drawable, valuemask, (XGCValues*) jlong_to_ptr(values)));
1793 }
1794 
1795 JNIEXPORT void JNICALL
1796 Java_sun_awt_X11_XlibWrapper_XDestroyImage(JNIEnv *env, jclass clazz, jlong image)
1797 {
1798     XImage *img = (XImage*) jlong_to_ptr(image);
1799     AWT_CHECK_HAVE_LOCK();
1800 
1801     // Fix for bug 4903671 :
1802     // We should be careful to not double free the memory pointed to data
1803     // Since we use unsafe to allocate it, we should use unsafe to free it.
1804     // So we should NULL the data pointer before calling XDestroyImage so
1805     // that X does not free the pointer for us.
1806     img->data = NULL;
1807     XDestroyImage(img);
1808 }

1809 JNIEXPORT void JNICALL
1810 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)
1811 {
1812     AWT_CHECK_HAVE_LOCK();
1813     XPutImage((Display*)jlong_to_ptr(display), (Drawable)drawable, (GC) jlong_to_ptr(gc), (XImage*) jlong_to_ptr(image), src_x, src_y,
1814               dest_x, dest_y, width, height);
1815 }

1816 JNIEXPORT void JNICALL
1817 Java_sun_awt_X11_XlibWrapper_XFreeGC(JNIEnv *env, jclass clazz, jlong display, jlong gc)
1818 {
1819     AWT_CHECK_HAVE_LOCK();
1820     XFreeGC((Display*) jlong_to_ptr(display), (GC) jlong_to_ptr(gc));
1821 }

1822 JNIEXPORT void JNICALL
1823 Java_sun_awt_X11_XlibWrapper_XSetWindowBackgroundPixmap(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong pixmap)
1824 {
1825     AWT_CHECK_HAVE_LOCK();
1826     XSetWindowBackgroundPixmap((Display*) jlong_to_ptr(display), (Window)window, (Pixmap)pixmap);
1827 }

1828 JNIEXPORT void JNICALL
1829 Java_sun_awt_X11_XlibWrapper_XClearWindow(JNIEnv *env, jclass clazz, jlong display, jlong window)
1830 {
1831     AWT_CHECK_HAVE_LOCK();
1832     XClearWindow((Display*) jlong_to_ptr(display), (Window)window);
1833 }
1834 
1835 JNIEXPORT jint JNICALL
1836 Java_sun_awt_X11_XlibWrapper_XGetIconSizes(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong ret_sizes, jlong ret_count)
1837 {
1838     XIconSize** psize = (XIconSize**) jlong_to_ptr(ret_sizes);
1839     int * pcount = (int *) jlong_to_ptr(ret_count);
1840     Status res;
1841     AWT_CHECK_HAVE_LOCK_RETURN(0);
1842     res = XGetIconSizes((Display*) jlong_to_ptr(display), (Window)window, psize, pcount);
1843     return res;
1844 }
1845 
1846 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeQueryExtension
1847   (JNIEnv *env, jclass clazz, jlong display, jlong major_version_return,


1905     AWT_CHECK_HAVE_LOCK_RETURN(0);
1906     return XdbeBeginIdiom((Display*) jlong_to_ptr(display));
1907 }
1908 
1909 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeEndIdiom
1910   (JNIEnv *env, jclass clazz, jlong display)
1911 {
1912     AWT_CHECK_HAVE_LOCK_RETURN(0);
1913     return XdbeEndIdiom((Display*) jlong_to_ptr(display));
1914 }
1915 
1916 JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeSwapBuffers
1917   (JNIEnv *env, jclass clazz, jlong display, jlong swap_info, jint num_windows)
1918 {
1919     AWT_CHECK_HAVE_LOCK_RETURN(0);
1920     return XdbeSwapBuffers((Display*) jlong_to_ptr(display), (XdbeSwapInfo *) jlong_to_ptr(swap_info), num_windows);
1921 }
1922 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XQueryKeymap
1923 (JNIEnv *env, jclass clazz, jlong display, jlong vector)
1924 {
1925 
1926     AWT_CHECK_HAVE_LOCK();
1927     XQueryKeymap( (Display *) jlong_to_ptr(display), (char *) jlong_to_ptr(vector));
1928 }
1929 
1930 // XKeycodeToKeysym is deprecated but for compatibility we keep the API.
1931 JNIEXPORT jlong JNICALL
1932 Java_sun_awt_X11_XlibWrapper_XKeycodeToKeysym(JNIEnv *env, jclass clazz,
1933                                               jlong display, jint keycode,
1934                                               jint index) {
1935     AWT_CHECK_HAVE_LOCK_RETURN(0);
1936     return keycodeToKeysym((Display*)jlong_to_ptr(display), (unsigned int)keycode, (int)index);
1937 }
1938 
1939 JNIEXPORT jint JNICALL
1940 Java_sun_awt_X11_XlibWrapper_XkbGetEffectiveGroup(JNIEnv *env, jclass clazz,
1941                                               jlong display) {
1942     XkbStateRec sr;
1943     AWT_CHECK_HAVE_LOCK_RETURN(0);
1944     memset(&sr, 0, sizeof(XkbStateRec));
1945     XkbGetState((Display*) jlong_to_ptr(display), XkbUseCoreKbd, &sr);
1946 //    printf("-------------------------------------VVVV\n");
1947 //    printf("                 group:0x%0X\n",sr.group);
1948 //    printf("            base_group:0x%0X\n",sr.base_group);
1949 //    printf("         latched_group:0x%0X\n",sr.latched_group);
1950 //    printf("          locked_group:0x%0X\n",sr.locked_group);
1951 //    printf("                  mods:0x%0X\n",sr.mods);
1952 //    printf("             base_mods:0x%0X\n",sr.base_mods);
1953 //    printf("          latched_mods:0x%0X\n",sr.latched_mods);
1954 //    printf("           locked_mods:0x%0X\n",sr.locked_mods);
1955 //    printf("          compat_state:0x%0X\n",sr.compat_state);
1956 //    printf("             grab_mods:0x%0X\n",sr.grab_mods);
1957 //    printf("      compat_grab_mods:0x%0X\n",sr.compat_grab_mods);
1958 //    printf("           lookup_mods:0x%0X\n",sr.lookup_mods);
1959 //    printf("    compat_lookup_mods:0x%0X\n",sr.compat_lookup_mods);
1960 //    printf("           ptr_buttons:0x%0X\n",sr.ptr_buttons);
1961 //    printf("-------------------------------------^^^^\n");
1962     return (jint)(sr.group);
1963 }

1964 JNIEXPORT jlong JNICALL
1965 Java_sun_awt_X11_XlibWrapper_XkbKeycodeToKeysym(JNIEnv *env, jclass clazz,
1966                                               jlong display, jint keycode,
1967                                               jint group, jint level) {
1968     AWT_CHECK_HAVE_LOCK_RETURN(0);
1969     return XkbKeycodeToKeysym((Display*) jlong_to_ptr(display), (unsigned int)keycode, (unsigned int)group, (unsigned int)level);
1970 }
1971 
1972 JNIEXPORT jint JNICALL
1973 Java_sun_awt_X11_XlibWrapper_XKeysymToKeycode(JNIEnv *env, jclass clazz,
1974                                               jlong display, jlong keysym) {
1975     AWT_CHECK_HAVE_LOCK_RETURN(0);
1976     return XKeysymToKeycode((Display*) jlong_to_ptr(display), (KeySym)keysym);
1977 }
1978 
1979 JNIEXPORT jlong JNICALL
1980 Java_sun_awt_X11_XlibWrapper_XGetModifierMapping(JNIEnv *env, jclass clazz,
1981                                               jlong display) {
1982     AWT_CHECK_HAVE_LOCK_RETURN(0);
1983     return ptr_to_jlong(XGetModifierMapping((Display*) jlong_to_ptr(display)));
1984 }
1985 
1986 JNIEXPORT void JNICALL
1987 Java_sun_awt_X11_XlibWrapper_XFreeModifiermap(JNIEnv *env, jclass clazz,
1988                                               jlong keymap) {
1989     AWT_CHECK_HAVE_LOCK();
1990     XFreeModifiermap((XModifierKeymap*) jlong_to_ptr(keymap));
1991 }

1992 /*
1993  * Class:     sun_awt_X11_XlibWrapper
1994  * Method:    XRefreshKeyboardMapping
1995  * Signature: (J)V
1996  */
1997 JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRefreshKeyboardMapping
1998 (JNIEnv *env, jclass clazz, jlong event_ptr)
1999 {
2000     AWT_CHECK_HAVE_LOCK();
2001     XRefreshKeyboardMapping((XMappingEvent*) jlong_to_ptr(event_ptr));
2002 }
2003 
2004 JNIEXPORT void JNICALL
2005 Java_sun_awt_X11_XlibWrapper_XChangeActivePointerGrab(JNIEnv *env, jclass clazz,
2006                                                       jlong display, jint mask,
2007                                                       jlong cursor, jlong time) {
2008     AWT_CHECK_HAVE_LOCK();
2009     XChangeActivePointerGrab((Display*)jlong_to_ptr(display), (unsigned int)mask,
2010                              (Cursor)cursor, (Time)time);
2011 }


2017 
2018 /*
2019  * This predicate procedure allows the Toolkit thread to process specific events
2020  * while it is blocked waiting for the event dispatch thread to process
2021  * a SunDropTargetEvent. We need this to prevent deadlock when the client code
2022  * processing SunDropTargetEvent sets or gets the contents of the system
2023  * clipboard/selection. In this case the event dispatch thread waits for the
2024  * Toolkit thread to process PropertyNotify or SelectionNotify events.
2025  */
2026 static Bool
2027 secondary_loop_event(Display* dpy, XEvent* event, XPointer xawt_root_window) {
2028     return (
2029                 event->type == SelectionNotify ||
2030                 event->type == SelectionClear  ||
2031                 event->type == PropertyNotify  ||
2032                 (event->type == ConfigureNotify
2033                     && event->xany.window == *(Window*) xawt_root_window)
2034             ) ? True : False;
2035 }
2036 
2037 
2038 JNIEXPORT jboolean JNICALL
2039 Java_sun_awt_X11_XlibWrapper_XNextSecondaryLoopEvent(JNIEnv *env, jclass clazz,
2040                                                      jlong display, jlong ptr) {
2041     uint32_t timeout = 1;
2042 
2043     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
2044     exitSecondaryLoop = False;
2045     Window xawt_root_window = get_xawt_root_shell(env);
2046 
2047     while (!exitSecondaryLoop) {
2048         if (XCheckIfEvent((Display*) jlong_to_ptr(display),
2049                 (XEvent*) jlong_to_ptr(ptr), secondary_loop_event, (XPointer) &xawt_root_window)) {
2050             return JNI_TRUE;
2051         }
2052         timeout = (timeout < AWT_SECONDARY_LOOP_TIMEOUT) ? (timeout << 1) : AWT_SECONDARY_LOOP_TIMEOUT;
2053         AWT_WAIT(timeout);
2054     }
2055     return JNI_FALSE;
2056 }
2057 
2058 JNIEXPORT void JNICALL
2059 Java_sun_awt_X11_XlibWrapper_ExitSecondaryLoop(JNIEnv *env, jclass clazz) {
2060     DASSERT(!exitSecondaryLoop);
2061     AWT_CHECK_HAVE_LOCK();
2062     exitSecondaryLoop = True;
2063     AWT_NOTIFY_ALL();
2064 }
2065 /*******************************************************************************/
2066 
2067 JNIEXPORT jobjectArray JNICALL
2068 Java_sun_awt_X11_XlibWrapper_XTextPropertyToStringList(JNIEnv *env,
2069                                                        jclass clazz,
2070                                                        jbyteArray bytes,
2071                                                        jlong encodingAtom) {
2072     XTextProperty tp;
2073     jbyte         *value;
2074 
2075     char**        strings  = (char **)NULL;
2076     int32_t       nstrings = 0;
2077     jobjectArray  ret = NULL;
2078     int32_t       i;
2079     jsize         len;
2080     jboolean      isCopy = JNI_FALSE;
2081     static jclass stringClass = NULL;
2082     jclass        stringClassLocal = NULL;
2083 
2084     AWT_CHECK_HAVE_LOCK_RETURN(NULL);
2085 


2163         }
2164 
2165         (*env)->SetObjectArrayElement(env, ret, i, string);
2166 
2167         if ((*env)->ExceptionCheck(env)) {
2168             (*env)->ExceptionDescribe(env);
2169             (*env)->ExceptionClear(env);
2170             goto wayout;
2171         }
2172 
2173         (*env)->DeleteLocalRef(env, string);
2174     }
2175 
2176  wayout:
2177     /*
2178      * Clean up and return
2179      */
2180     XFreeStringList(strings);
2181     return ret;
2182 }
2183 
2184 
2185 JNIEXPORT void JNICALL
2186 Java_sun_awt_X11_XlibWrapper_XPutBackEvent(JNIEnv *env,
2187                                            jclass clazz,
2188                                            jlong display,
2189                                            jlong event) {
2190     XPutBackEvent((Display*)jlong_to_ptr(display), (XEvent*) jlong_to_ptr(event));
2191 }
2192 
2193 JNIEXPORT jlong JNICALL
2194 Java_sun_awt_X11_XlibWrapper_getAddress(JNIEnv *env,
2195                                            jclass clazz,
2196                                            jobject o) {
2197     return ptr_to_jlong(o);
2198 }
2199 
2200 JNIEXPORT void JNICALL
2201 Java_sun_awt_X11_XlibWrapper_copyIntArray(JNIEnv *env,
2202                                            jclass clazz,
2203                                            jlong dest, jobject array, jint size) {


   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     }


 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,


 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  */


 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);


 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


 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 


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 {


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  */


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 


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  */


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);


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,


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 }


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 


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) {


< prev index next >