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


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


 288         }
 289     }
 290 
 291     void init() {
 292         awtLock();
 293         try {
 294             XlibWrapper.XSupportsLocale();
 295             if (XlibWrapper.XSetLocaleModifiers("") == null) {
 296                 log.finer("X locale modifiers are not supported, using default");
 297             }
 298             tryXKB();
 299 
 300             AwtScreenData defaultScreen = new AwtScreenData(XToolkit.getDefaultScreenData());
 301             awt_defaultFg = defaultScreen.get_blackpixel();
 302 
 303             arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(),
 304                 XCursorFontConstants.XC_arrow);
 305             areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
 306             //set system property if not yet assigned
 307             System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
 308 
 309             saved_error_handler = XlibWrapper.SetToolkitErrorHandler();
 310 
 311             // Detect display mode changes
 312             XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask);
 313             XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
 314                 @Override
 315                 public void dispatchEvent(XEvent ev) {
 316                     if (ev.get_type() == XConstants.ConfigureNotify) {
 317                         ((X11GraphicsEnvironment)GraphicsEnvironment.
 318                          getLocalGraphicsEnvironment()).
 319                             displayChanged();
 320                     }
 321                 }
 322             });
 323         } finally {
 324             awtUnlock();
 325         }
 326         PrivilegedAction<Void> a = new PrivilegedAction<Void>() {
 327             public Void run() {
 328                 ThreadGroup mainTG = Thread.currentThread().getThreadGroup();
 329                 ThreadGroup parentTG = mainTG.getParent();


   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


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

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








































































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


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


 235 
 236             // Detect display mode changes
 237             XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask);
 238             XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
 239                 @Override
 240                 public void dispatchEvent(XEvent ev) {
 241                     if (ev.get_type() == XConstants.ConfigureNotify) {
 242                         ((X11GraphicsEnvironment)GraphicsEnvironment.
 243                          getLocalGraphicsEnvironment()).
 244                             displayChanged();
 245                     }
 246                 }
 247             });
 248         } finally {
 249             awtUnlock();
 250         }
 251         PrivilegedAction<Void> a = new PrivilegedAction<Void>() {
 252             public Void run() {
 253                 ThreadGroup mainTG = Thread.currentThread().getThreadGroup();
 254                 ThreadGroup parentTG = mainTG.getParent();