src/solaris/classes/sun/awt/X11/XToolkit.java

Print this page


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


 110     private static int screenWidth = -1, screenHeight = -1; // Dimensions of default screen
 111     static long awt_defaultFg; // Pixel
 112     private static XMouseInfoPeer xPeer;
 113 
 114     static {
 115         initSecurityWarning();
 116         if (GraphicsEnvironment.isHeadless()) {
 117             config = null;
 118         } else {
 119             localEnv = (X11GraphicsEnvironment) GraphicsEnvironment
 120                 .getLocalGraphicsEnvironment();
 121             device = (X11GraphicsDevice) localEnv.getDefaultScreenDevice();
 122             config = (X11GraphicsConfig) (device.getDefaultConfiguration());
 123             if (device != null) {
 124                 _display = device.getDisplay();
 125             }
 126             setupModifierMap();
 127             initIDs();
 128             setBackingStoreType();
 129         }
 130         noisyAwtHandler = AccessController.doPrivileged(new GetBooleanAction("sun.awt.noisyerrorhandler"));
 131     }
 132 
 133     /*
 134      * Return (potentially) platform specific display timeout for the
 135      * tray icon
 136      */
 137     static native long getTrayIconDisplayTimeout();
 138 
 139     //---- ERROR HANDLER CODE ----//
 140 
 141     /*
 142      * Error handler at the moment of XToolkit initialization
 143      */
 144     private static long saved_error_handler;
 145 
 146     /*
 147      * XErrorEvent being handled
 148      */
 149     static volatile XErrorEvent saved_error;
 150 
 151     /*
 152      * Current error handler or null if no error handler is set
 153      */
 154     private static XErrorHandler current_error_handler;
 155 
 156     /*
 157      * Value of sun.awt.noisyerrorhandler system property
 158      */
 159     private static boolean noisyAwtHandler;
 160 
 161     public static void WITH_XERROR_HANDLER(XErrorHandler handler) {
 162         saved_error = null;
 163         current_error_handler = handler;
 164     }
 165 
 166     public static void RESTORE_XERROR_HANDLER() {
 167         // wait until all requests are processed by the X server
 168         // and only then uninstall the error handler
 169         XSync();
 170         current_error_handler = null;
 171     }
 172 
 173     // Should be called under LOCK
 174     public static int SAVED_ERROR_HANDLER(long display, XErrorEvent error) {
 175         if (saved_error_handler != 0) {
 176             // Default XErrorHandler may just terminate the process. Don't call it.
 177             // return XlibWrapper.CallErrorHandler(saved_error_handler, display, error.pData);
 178         }
 179         if (log.isLoggable(PlatformLogger.FINE)) {
 180             log.fine("Unhandled XErrorEvent: " +
 181                      "id=" + error.get_resourceid() + ", " +
 182                      "serial=" + error.get_serial() + ", " +
 183                      "ec=" + error.get_error_code() + ", " +
 184                      "rc=" + error.get_request_code() + ", " +
 185                      "mc=" + error.get_minor_code());
 186         }
 187         return 0;
 188     }
 189 
 190     // Called from the native code when an error occurs
 191     private static int globalErrorHandler(long display, long event_ptr) {
 192         if (noisyAwtHandler) {
 193             XlibWrapper.PrintXErrorEvent(display, event_ptr);
 194         }
 195         XErrorEvent event = new XErrorEvent(event_ptr);
 196         saved_error = event;
 197         try {
 198             if (current_error_handler != null) {
 199                 return current_error_handler.handleError(display, event);
 200             } else {
 201                 return SAVED_ERROR_HANDLER(display, event);
 202             }
 203         } catch (Throwable z) {
 204             log.fine("Error in GlobalErrorHandler", z);
 205         }
 206         return 0;
 207     }
 208 
 209     //---- END OF ERROR HANDLER CODE ----//
 210 
 211     private native static void initIDs();
 212     native static void waitForEvents(long nextTaskTime);
 213     static Thread toolkitThread;
 214     static boolean isToolkitThread() {
 215         return Thread.currentThread() == toolkitThread;
 216     }
 217 
 218     static void initSecurityWarning() {
 219         // Enable warning only for internal builds
 220         String runtime = AccessController.doPrivileged(
 221                              new GetPropertyAction("java.runtime.version"));
 222         securityWarningEnabled = (runtime != null && runtime.contains("internal"));
 223     }
 224 
 225     static boolean isSecurityWarningEnabled() {
 226         return securityWarningEnabled;
 227     }
 228 
 229     static native void awt_output_flush();
 230 


 287         }
 288     }
 289 
 290     void init() {
 291         awtLock();
 292         try {
 293             XlibWrapper.XSupportsLocale();
 294             if (XlibWrapper.XSetLocaleModifiers("") == null) {
 295                 log.finer("X locale modifiers are not supported, using default");
 296             }
 297             tryXKB();
 298 
 299             AwtScreenData defaultScreen = new AwtScreenData(XToolkit.getDefaultScreenData());
 300             awt_defaultFg = defaultScreen.get_blackpixel();
 301 
 302             arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(),
 303                 XCursorFontConstants.XC_arrow);
 304             areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
 305             //set system property if not yet assigned
 306             System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
 307 
 308             saved_error_handler = XlibWrapper.SetToolkitErrorHandler();
 309         } finally {
 310             awtUnlock();
 311         }
 312         PrivilegedAction<Void> a = new PrivilegedAction<Void>() {
 313             public Void run() {
 314                 ThreadGroup mainTG = Thread.currentThread().getThreadGroup();
 315                 ThreadGroup parentTG = mainTG.getParent();
 316                 while (parentTG != null) {
 317                     mainTG = parentTG;
 318                     parentTG = mainTG.getParent();
 319                 }
 320                 Thread shutdownThread = new Thread(mainTG, "XToolkt-Shutdown-Thread") {
 321                         public void run() {
 322                             XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
 323                             if (peer != null) {
 324                                 peer.dispose();
 325                             }
 326                             if (xs != null) {
 327                                 ((XAWTXSettings)xs).dispose();
 328                             }


   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


 110     private static int screenWidth = -1, screenHeight = -1; // Dimensions of default screen
 111     static long awt_defaultFg; // Pixel
 112     private static XMouseInfoPeer xPeer;
 113 
 114     static {
 115         initSecurityWarning();
 116         if (GraphicsEnvironment.isHeadless()) {
 117             config = null;
 118         } else {
 119             localEnv = (X11GraphicsEnvironment) GraphicsEnvironment
 120                 .getLocalGraphicsEnvironment();
 121             device = (X11GraphicsDevice) localEnv.getDefaultScreenDevice();
 122             config = (X11GraphicsConfig) (device.getDefaultConfiguration());
 123             if (device != null) {
 124                 _display = device.getDisplay();
 125             }
 126             setupModifierMap();
 127             initIDs();
 128             setBackingStoreType();
 129         }

 130     }
 131 
 132     /*
 133      * Return (potentially) platform specific display timeout for the
 134      * tray icon
 135      */
 136     static native long getTrayIconDisplayTimeout();
 137 








































































 138     private native static void initIDs();
 139     native static void waitForEvents(long nextTaskTime);
 140     static Thread toolkitThread;
 141     static boolean isToolkitThread() {
 142         return Thread.currentThread() == toolkitThread;
 143     }
 144 
 145     static void initSecurityWarning() {
 146         // Enable warning only for internal builds
 147         String runtime = AccessController.doPrivileged(
 148                              new GetPropertyAction("java.runtime.version"));
 149         securityWarningEnabled = (runtime != null && runtime.contains("internal"));
 150     }
 151 
 152     static boolean isSecurityWarningEnabled() {
 153         return securityWarningEnabled;
 154     }
 155 
 156     static native void awt_output_flush();
 157 


 214         }
 215     }
 216 
 217     void init() {
 218         awtLock();
 219         try {
 220             XlibWrapper.XSupportsLocale();
 221             if (XlibWrapper.XSetLocaleModifiers("") == null) {
 222                 log.finer("X locale modifiers are not supported, using default");
 223             }
 224             tryXKB();
 225 
 226             AwtScreenData defaultScreen = new AwtScreenData(XToolkit.getDefaultScreenData());
 227             awt_defaultFg = defaultScreen.get_blackpixel();
 228 
 229             arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(),
 230                 XCursorFontConstants.XC_arrow);
 231             areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
 232             //set system property if not yet assigned
 233             System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);


 234         } finally {
 235             awtUnlock();
 236         }
 237         PrivilegedAction<Void> a = new PrivilegedAction<Void>() {
 238             public Void run() {
 239                 ThreadGroup mainTG = Thread.currentThread().getThreadGroup();
 240                 ThreadGroup parentTG = mainTG.getParent();
 241                 while (parentTG != null) {
 242                     mainTG = parentTG;
 243                     parentTG = mainTG.getParent();
 244                 }
 245                 Thread shutdownThread = new Thread(mainTG, "XToolkt-Shutdown-Thread") {
 246                         public void run() {
 247                             XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
 248                             if (peer != null) {
 249                                 peer.dispose();
 250                             }
 251                             if (xs != null) {
 252                                 ((XAWTXSettings)xs).dispose();
 253                             }