jdk/src/solaris/classes/sun/awt/X11/XToolkit.java
changeset 2802 d05a9dcc8296
parent 2660 3c98e01dcbcf
child 2803 e0fa1a27f1c1
equal deleted inserted replaced
2760:f038acdbdf9c 2802:d05a9dcc8296
   147             setupModifierMap();
   147             setupModifierMap();
   148             initIDs();
   148             initIDs();
   149             setBackingStoreType();
   149             setBackingStoreType();
   150         }
   150         }
   151         m_removeSourceEvents = SunToolkit.getMethod(EventQueue.class, "removeSourceEvents", new Class[] {Object.class, Boolean.TYPE}) ;
   151         m_removeSourceEvents = SunToolkit.getMethod(EventQueue.class, "removeSourceEvents", new Class[] {Object.class, Boolean.TYPE}) ;
   152     }
   152 
   153 
   153         noisyAwtHandler = AccessController.doPrivileged(new GetBooleanAction("sun.awt.noisyerrorhandler"));
   154     // Error handler stuff
   154     }
   155     static XErrorEvent saved_error;
   155 
   156     static long saved_error_handler;
   156     //---- ERROR HANDLER CODE ----//
   157     static XErrorHandler curErrorHandler;
   157 
   158     // Should be called under LOCK, before releasing LOCK RESTORE_XERROR_HANDLER should be called
   158     /*
   159     static void WITH_XERROR_HANDLER(XErrorHandler handler) {
   159      * Error handler at the moment of XToolkit initialization
       
   160      */
       
   161     private static long saved_error_handler;
       
   162 
       
   163     /*
       
   164      * XErrorEvent being handled
       
   165      */
       
   166     static volatile XErrorEvent saved_error;
       
   167 
       
   168     /*
       
   169      * Current error handler or null if no error handler is set
       
   170      */
       
   171     private static XErrorHandler current_error_handler;
       
   172 
       
   173     /*
       
   174      * Value of sun.awt.noisyerrorhandler system property
       
   175      */
       
   176     private static boolean noisyAwtHandler;
       
   177 
       
   178     public static void WITH_XERROR_HANDLER(XErrorHandler handler) {
   160         saved_error = null;
   179         saved_error = null;
   161         curErrorHandler = handler;
   180         current_error_handler = handler;
   162         XSync();
   181     }
   163         saved_error_handler = XlibWrapper.SetToolkitErrorHandler();
   182 
   164     }
   183     public static void RESTORE_XERROR_HANDLER() {
   165     static void XERROR_SAVE(XErrorEvent event) {
   184         current_error_handler = null;
       
   185     }
       
   186 
       
   187     // Should be called under LOCK
       
   188     public static int SAVED_ERROR_HANDLER(long display, XErrorEvent error) {
       
   189         if (saved_error_handler != 0) {
       
   190             // Default XErrorHandler may just terminate the process. Don't call it.
       
   191             // return XlibWrapper.CallErrorHandler(saved_error_handler, display, error.pData);
       
   192         }
       
   193         if (log.isLoggable(Level.FINE)) {
       
   194             log.log(Level.FINE, "Unhandled XErrorEvent: " +
       
   195                     "id=" + error.get_resourceid() + ", " +
       
   196                     "serial=" + error.get_serial() + ", " +
       
   197                     "ec=" + error.get_error_code() + ", " +
       
   198                     "rc=" + error.get_request_code() + ", " +
       
   199                     "mc=" + error.get_minor_code());
       
   200         }
       
   201         return 0;
       
   202     }
       
   203 
       
   204     // Called from the native code when an error occurs
       
   205     private static int globalErrorHandler(long display, long event_ptr) {
       
   206         if (noisyAwtHandler) {
       
   207             XlibWrapper.PrintXErrorEvent(display, event_ptr);
       
   208         }
       
   209         XErrorEvent event = new XErrorEvent(event_ptr);
   166         saved_error = event;
   210         saved_error = event;
   167     }
   211         try {
   168     // Should be called under LOCK
   212             if (current_error_handler != null) {
   169     static void RESTORE_XERROR_HANDLER() {
   213                 return current_error_handler.handleError(display, event);
   170        XSync();
       
   171         XlibWrapper.XSetErrorHandler(saved_error_handler);
       
   172         curErrorHandler = null;
       
   173     }
       
   174     // Should be called under LOCK
       
   175     static int SAVED_ERROR_HANDLER(long display, XErrorEvent error) {
       
   176         return XlibWrapper.CallErrorHandler(saved_error_handler, display, error.pData);
       
   177     }
       
   178     interface XErrorHandler {
       
   179         int handleError(long display, XErrorEvent err);
       
   180     }
       
   181     static int GlobalErrorHandler(long display, long event_ptr) {
       
   182         XErrorEvent event = new XErrorEvent(event_ptr);
       
   183         try {
       
   184             if (curErrorHandler != null) {
       
   185                 return curErrorHandler.handleError(display, event);
       
   186             } else {
   214             } else {
   187                 return SAVED_ERROR_HANDLER(display, event);
   215                 return SAVED_ERROR_HANDLER(display, event);
   188             }
   216             }
   189         } finally {
   217         } catch (Throwable z) {
   190         }
   218             log.log(Level.FINE, "Error in GlobalErrorHandler", z);
   191     }
   219         }
   192 
   220         return 0;
   193 /*
   221     }
   194  * Instead of validating window id, we simply call XGetWindowProperty,
   222 
   195  * but temporary install this function as the error handler to ignore
   223     //---- END OF ERROR HANDLER CODE ----//
   196  * BadWindow error.
       
   197  */
       
   198     static XErrorHandler IgnoreBadWindowHandler = new XErrorHandler() {
       
   199             public int handleError(long display, XErrorEvent err) {
       
   200                 XERROR_SAVE(err);
       
   201                 if (err.get_error_code() == XConstants.BadWindow) {
       
   202                     return 0;
       
   203                 } else {
       
   204                     return SAVED_ERROR_HANDLER(display, err);
       
   205                 }
       
   206             }
       
   207         };
       
   208 
       
   209 
   224 
   210     private native static void initIDs();
   225     private native static void initIDs();
   211     native static void waitForEvents(long nextTaskTime);
   226     native static void waitForEvents(long nextTaskTime);
   212     static Thread toolkitThread;
   227     static Thread toolkitThread;
   213     static boolean isToolkitThread() {
   228     static boolean isToolkitThread() {
   300             arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(),
   315             arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(),
   301                 XCursorFontConstants.XC_arrow);
   316                 XCursorFontConstants.XC_arrow);
   302             areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
   317             areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
   303             //set system property if not yet assigned
   318             //set system property if not yet assigned
   304             System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
   319             System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
       
   320 
       
   321             saved_error_handler = XlibWrapper.SetToolkitErrorHandler();
   305         } finally {
   322         } finally {
   306             awtUnlock();
   323             awtUnlock();
   307         }
   324         }
   308 
   325 
   309         Runtime.getRuntime().addShutdownHook(new Thread() {
   326         Runtime.getRuntime().addShutdownHook(new Thread() {
   310                 public void run() {
   327             public void run() {
   311                     XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
   328                 XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
   312                     if (peer != null) {
   329                 if (peer != null) {
   313                         peer.dispose();
   330                     peer.dispose();
   314                     }
   331                 }
   315                     if (xs != null) {
   332                 if (xs != null) {
   316                         ((XAWTXSettings)xs).dispose();
   333                     ((XAWTXSettings)xs).dispose();
   317                     }
   334                 }
   318                     freeXKB();
   335                 freeXKB();
   319                     if (log.isLoggable(Level.FINE)) {
   336                 if (log.isLoggable(Level.FINE)) {
   320                         dumpPeers();
   337                     dumpPeers();
   321                     }
   338                 }
   322                 }
   339 
   323             });
   340                 awtLock();
       
   341                 try {
       
   342                     XlibWrapper.XSetErrorHandler(saved_error_handler);
       
   343                 } finally {
       
   344                     awtUnlock();
       
   345                 }
       
   346             }
       
   347         });
   324     }
   348     }
   325 
   349 
   326     static String getCorrectXIDString(String val) {
   350     static String getCorrectXIDString(String val) {
   327         if (val != null) {
   351         if (val != null) {
   328             return val.replace('.', '-');
   352             return val.replace('.', '-');
  2407 
  2431 
  2408     public DesktopPeer createDesktopPeer(Desktop target){
  2432     public DesktopPeer createDesktopPeer(Desktop target){
  2409         return new XDesktopPeer();
  2433         return new XDesktopPeer();
  2410     }
  2434     }
  2411 
  2435 
  2412     public static native void setNoisyXErrorHandler();
       
  2413 
       
  2414     public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
  2436     public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
  2415         return areExtraMouseButtonsEnabled;
  2437         return areExtraMouseButtonsEnabled;
  2416     }
  2438     }
  2417 
  2439 
  2418     @Override
  2440     @Override