src/solaris/native/sun/xawt/XlibWrapper.c

Print this page


   1 /*
   2  * Copyright (c) 2002, 2010, 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


1929 
1930 /*
1931  * This predicate procedure allows the Toolkit thread to process specific events
1932  * while it is blocked waiting for the event dispatch thread to process
1933  * a SunDropTargetEvent. We need this to prevent deadlock when the client code
1934  * processing SunDropTargetEvent sets or gets the contents of the system
1935  * clipboard/selection. In this case the event dispatch thread waits for the
1936  * Toolkit thread to process PropertyNotify or SelectionNotify events.
1937  */
1938 static Bool
1939 secondary_loop_event(Display* dpy, XEvent* event, char* arg) {
1940     return (event->type == SelectionNotify ||
1941             event->type == SelectionClear  ||
1942             event->type == PropertyNotify) ? True : False;
1943 }
1944 
1945 
1946 JNIEXPORT jboolean JNICALL
1947 Java_sun_awt_X11_XlibWrapper_XNextSecondaryLoopEvent(JNIEnv *env, jclass clazz,
1948                                                      jlong display, jlong ptr) {


1949     AWT_CHECK_HAVE_LOCK();
1950     exitSecondaryLoop = False;
1951     while (!exitSecondaryLoop) {
1952         if (XCheckIfEvent((Display*) jlong_to_ptr(display), (XEvent*) jlong_to_ptr(ptr), secondary_loop_event, NULL)) {
1953             return JNI_TRUE;
1954         }
1955         AWT_WAIT(AWT_SECONDARY_LOOP_TIMEOUT);

1956     }
1957     return JNI_FALSE;
1958 }
1959 
1960 JNIEXPORT void JNICALL
1961 Java_sun_awt_X11_XlibWrapper_ExitSecondaryLoop(JNIEnv *env, jclass clazz) {
1962     DASSERT(!exitSecondaryLoop);
1963     AWT_CHECK_HAVE_LOCK();
1964     exitSecondaryLoop = True;
1965     AWT_NOTIFY_ALL();
1966 }
1967 /*******************************************************************************/
1968 
1969 JNIEXPORT jobjectArray JNICALL
1970 Java_sun_awt_X11_XlibWrapper_XTextPropertyToStringList(JNIEnv *env,
1971                                                        jclass clazz,
1972                                                        jbyteArray bytes,
1973                                                        jlong encodingAtom) {
1974     XTextProperty tp;
1975     jbyte         *value;


   1 /*
   2  * Copyright (c) 2002, 2013, 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


1929 
1930 /*
1931  * This predicate procedure allows the Toolkit thread to process specific events
1932  * while it is blocked waiting for the event dispatch thread to process
1933  * a SunDropTargetEvent. We need this to prevent deadlock when the client code
1934  * processing SunDropTargetEvent sets or gets the contents of the system
1935  * clipboard/selection. In this case the event dispatch thread waits for the
1936  * Toolkit thread to process PropertyNotify or SelectionNotify events.
1937  */
1938 static Bool
1939 secondary_loop_event(Display* dpy, XEvent* event, char* arg) {
1940     return (event->type == SelectionNotify ||
1941             event->type == SelectionClear  ||
1942             event->type == PropertyNotify) ? True : False;
1943 }
1944 
1945 
1946 JNIEXPORT jboolean JNICALL
1947 Java_sun_awt_X11_XlibWrapper_XNextSecondaryLoopEvent(JNIEnv *env, jclass clazz,
1948                                                      jlong display, jlong ptr) {
1949     uint32_t timeout = 1;
1950 
1951     AWT_CHECK_HAVE_LOCK();
1952     exitSecondaryLoop = False;
1953     while (!exitSecondaryLoop) {
1954         if (XCheckIfEvent((Display*) jlong_to_ptr(display), (XEvent*) jlong_to_ptr(ptr), secondary_loop_event, NULL)) {
1955             return JNI_TRUE;
1956         }
1957         timeout = (timeout < AWT_SECONDARY_LOOP_TIMEOUT) ? (timeout << 1) : AWT_SECONDARY_LOOP_TIMEOUT;
1958         AWT_WAIT(timeout);
1959     }
1960     return JNI_FALSE;
1961 }
1962 
1963 JNIEXPORT void JNICALL
1964 Java_sun_awt_X11_XlibWrapper_ExitSecondaryLoop(JNIEnv *env, jclass clazz) {
1965     DASSERT(!exitSecondaryLoop);
1966     AWT_CHECK_HAVE_LOCK();
1967     exitSecondaryLoop = True;
1968     AWT_NOTIFY_ALL();
1969 }
1970 /*******************************************************************************/
1971 
1972 JNIEXPORT jobjectArray JNICALL
1973 Java_sun_awt_X11_XlibWrapper_XTextPropertyToStringList(JNIEnv *env,
1974                                                        jclass clazz,
1975                                                        jbyteArray bytes,
1976                                                        jlong encodingAtom) {
1977     XTextProperty tp;
1978     jbyte         *value;