# HG changeset patch # User anthony # Date 1320835419 -10800 # Node ID 34aa99149ff2525a48b34141ef542c9183d875ed # Parent 0c751364926531cef36369393d8c4790f08aa4e8 7045370: Java Statically Determines Display Size on Linux platforms Summary: Listen to ConfigureNotify events on the root window and update the current screen size accordingly Reviewed-by: art, bae diff -r 0c7513649265 -r 34aa99149ff2 jdk/src/share/classes/java/awt/Component.java --- a/jdk/src/share/classes/java/awt/Component.java Tue Nov 08 14:36:50 2011 +0300 +++ b/jdk/src/share/classes/java/awt/Component.java Wed Nov 09 13:43:39 2011 +0300 @@ -1158,6 +1158,10 @@ boolean updateGraphicsData(GraphicsConfiguration gc) { checkTreeLock(); + if (graphicsConfig == gc) { + return false; + } + graphicsConfig = gc; ComponentPeer peer = getPeer(); diff -r 0c7513649265 -r 34aa99149ff2 jdk/src/solaris/classes/sun/awt/X11/XToolkit.java --- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java Tue Nov 08 14:36:50 2011 +0300 +++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java Wed Nov 09 13:43:39 2011 +0300 @@ -51,6 +51,7 @@ import sun.awt.*; import sun.font.FontConfigManager; import sun.font.FontManager; +import sun.java2d.SunGraphicsEnvironment; import sun.misc.PerformanceLogger; import sun.print.PrintJob2D; import sun.security.action.GetBooleanAction; @@ -109,7 +110,7 @@ static int awt_multiclick_time; static boolean securityWarningEnabled; - private static int screenWidth = -1, screenHeight = -1; // Dimensions of default screen + private static volatile int screenWidth = -1, screenHeight = -1; // Dimensions of default screen static long awt_defaultFg; // Pixel private static XMouseInfoPeer xPeer; private static Method m_removeSourceEvents; @@ -310,6 +311,19 @@ System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled); saved_error_handler = XlibWrapper.SetToolkitErrorHandler(); + + // Detect display mode changes + XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask); + XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() { + @Override + public void dispatchEvent(XEvent ev) { + if (ev.get_type() == XConstants.ConfigureNotify) { + ((X11GraphicsEnvironment)GraphicsEnvironment. + getLocalGraphicsEnvironment()). + displayChanged(); + } + } + }); } finally { awtUnlock(); } @@ -684,29 +698,49 @@ } } - static int getDefaultScreenWidth() { - if (screenWidth == -1) { - long display = getDisplay(); + static { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + if (ge instanceof SunGraphicsEnvironment) { + ((SunGraphicsEnvironment)ge).addDisplayChangedListener( + new DisplayChangedListener() { + @Override + public void displayChanged() { + // 7045370: Reset the cached values + XToolkit.screenWidth = -1; + XToolkit.screenHeight = -1; + } + + @Override + public void paletteChanged() {} + }); + } + } + + private static void initScreenSize() { + if (screenWidth == -1 || screenHeight == -1) { awtLock(); try { - screenWidth = (int) XlibWrapper.DisplayWidth(display, XlibWrapper.DefaultScreen(display)); + XWindowAttributes pattr = new XWindowAttributes(); + try { + XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), pattr.pData); + screenWidth = (int) pattr.get_width(); + screenHeight = (int) pattr.get_height(); + } finally { + pattr.dispose(); + } } finally { awtUnlock(); } } + } + + static int getDefaultScreenWidth() { + initScreenSize(); return screenWidth; } static int getDefaultScreenHeight() { - if (screenHeight == -1) { - long display = getDisplay(); - awtLock(); - try { - screenHeight = (int) XlibWrapper.DisplayHeight(display, XlibWrapper.DefaultScreen(display)); - } finally { - awtUnlock(); - } - } + initScreenSize(); return screenHeight; } diff -r 0c7513649265 -r 34aa99149ff2 jdk/src/solaris/classes/sun/awt/X11GraphicsDevice.java --- a/jdk/src/solaris/classes/sun/awt/X11GraphicsDevice.java Tue Nov 08 14:36:50 2011 +0300 +++ b/jdk/src/solaris/classes/sun/awt/X11GraphicsDevice.java Wed Nov 09 13:43:39 2011 +0300 @@ -487,14 +487,9 @@ * X11GraphicsEnvironment when the display mode has been changed. */ public synchronized void displayChanged() { - // reset the list of configs (and default config) - defaultConfig = null; - configs = null; - doubleBufferVisuals = null; - - // reset the native data structures associated with this device (they - // will be reinitialized when the GraphicsConfigs are configured) - resetNativeData(screen); + // On X11 the visuals do not change, and therefore we don't need + // to reset the defaultConfig, config, doubleBufferVisuals, + // neither do we need to reset the native data. // pass on to all top-level windows on this screen topLevels.notifyListeners(); diff -r 0c7513649265 -r 34aa99149ff2 jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c --- a/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c Tue Nov 08 14:36:50 2011 +0300 +++ b/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c Wed Nov 09 13:43:39 2011 +0300 @@ -1434,11 +1434,17 @@ fbrects[screen].height); } else { + XWindowAttributes xwa; + memset(&xwa, 0, sizeof(xwa)); + + AWT_LOCK (); + XGetWindowAttributes(awt_display, + RootWindow(awt_display, adata->awt_visInfo.screen), + &xwa); + AWT_UNLOCK (); + bounds = (*env)->NewObject(env, clazz, mid, 0, 0, - DisplayWidth(awt_display, - adata->awt_visInfo.screen), - DisplayHeight(awt_display, - adata->awt_visInfo.screen)); + xwa.width, xwa.height); } if ((*env)->ExceptionOccurred(env)) {