提交 db3c5799 编写于 作者: A anthony

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
上级 822ac46b
...@@ -1158,6 +1158,10 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -1158,6 +1158,10 @@ public abstract class Component implements ImageObserver, MenuContainer,
boolean updateGraphicsData(GraphicsConfiguration gc) { boolean updateGraphicsData(GraphicsConfiguration gc) {
checkTreeLock(); checkTreeLock();
if (graphicsConfig == gc) {
return false;
}
graphicsConfig = gc; graphicsConfig = gc;
ComponentPeer peer = getPeer(); ComponentPeer peer = getPeer();
......
...@@ -51,6 +51,7 @@ import javax.swing.UIDefaults; ...@@ -51,6 +51,7 @@ import javax.swing.UIDefaults;
import sun.awt.*; import sun.awt.*;
import sun.font.FontConfigManager; import sun.font.FontConfigManager;
import sun.font.FontManager; import sun.font.FontManager;
import sun.java2d.SunGraphicsEnvironment;
import sun.misc.PerformanceLogger; import sun.misc.PerformanceLogger;
import sun.print.PrintJob2D; import sun.print.PrintJob2D;
import sun.security.action.GetBooleanAction; import sun.security.action.GetBooleanAction;
...@@ -109,7 +110,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable { ...@@ -109,7 +110,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
static int awt_multiclick_time; static int awt_multiclick_time;
static boolean securityWarningEnabled; 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 static long awt_defaultFg; // Pixel
private static XMouseInfoPeer xPeer; private static XMouseInfoPeer xPeer;
private static Method m_removeSourceEvents; private static Method m_removeSourceEvents;
...@@ -310,6 +311,19 @@ public final class XToolkit extends UNIXToolkit implements Runnable { ...@@ -310,6 +311,19 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled); System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
saved_error_handler = XlibWrapper.SetToolkitErrorHandler(); 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 { } finally {
awtUnlock(); awtUnlock();
} }
...@@ -684,29 +698,49 @@ public final class XToolkit extends UNIXToolkit implements Runnable { ...@@ -684,29 +698,49 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
} }
} }
static int getDefaultScreenWidth() { static {
if (screenWidth == -1) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
long display = getDisplay(); if (ge instanceof SunGraphicsEnvironment) {
awtLock(); ((SunGraphicsEnvironment)ge).addDisplayChangedListener(
try { new DisplayChangedListener() {
screenWidth = (int) XlibWrapper.DisplayWidth(display, XlibWrapper.DefaultScreen(display)); @Override
} finally { public void displayChanged() {
awtUnlock(); // 7045370: Reset the cached values
XToolkit.screenWidth = -1;
XToolkit.screenHeight = -1;
} }
@Override
public void paletteChanged() {}
});
} }
return screenWidth;
} }
static int getDefaultScreenHeight() { private static void initScreenSize() {
if (screenHeight == -1) { if (screenWidth == -1 || screenHeight == -1) {
long display = getDisplay();
awtLock(); awtLock();
try { try {
screenHeight = (int) XlibWrapper.DisplayHeight(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 { } finally {
awtUnlock(); awtUnlock();
} }
} }
}
static int getDefaultScreenWidth() {
initScreenSize();
return screenWidth;
}
static int getDefaultScreenHeight() {
initScreenSize();
return screenHeight; return screenHeight;
} }
......
...@@ -487,14 +487,9 @@ public class X11GraphicsDevice ...@@ -487,14 +487,9 @@ public class X11GraphicsDevice
* X11GraphicsEnvironment when the display mode has been changed. * X11GraphicsEnvironment when the display mode has been changed.
*/ */
public synchronized void displayChanged() { public synchronized void displayChanged() {
// reset the list of configs (and default config) // On X11 the visuals do not change, and therefore we don't need
defaultConfig = null; // to reset the defaultConfig, config, doubleBufferVisuals,
configs = null; // neither do we need to reset the native data.
doubleBufferVisuals = null;
// reset the native data structures associated with this device (they
// will be reinitialized when the GraphicsConfigs are configured)
resetNativeData(screen);
// pass on to all top-level windows on this screen // pass on to all top-level windows on this screen
topLevels.notifyListeners(); topLevels.notifyListeners();
......
...@@ -1434,11 +1434,17 @@ Java_sun_awt_X11GraphicsConfig_pGetBounds(JNIEnv *env, jobject this, jint screen ...@@ -1434,11 +1434,17 @@ Java_sun_awt_X11GraphicsConfig_pGetBounds(JNIEnv *env, jobject this, jint screen
fbrects[screen].height); fbrects[screen].height);
} }
else { 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, bounds = (*env)->NewObject(env, clazz, mid, 0, 0,
DisplayWidth(awt_display, xwa.width, xwa.height);
adata->awt_visInfo.screen),
DisplayHeight(awt_display,
adata->awt_visInfo.screen));
} }
if ((*env)->ExceptionOccurred(env)) { if ((*env)->ExceptionOccurred(env)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册