提交 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,
boolean updateGraphicsData(GraphicsConfiguration gc) {
checkTreeLock();
if (graphicsConfig == gc) {
return false;
}
graphicsConfig = gc;
ComponentPeer peer = getPeer();
......
......@@ -51,6 +51,7 @@ import javax.swing.UIDefaults;
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 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
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 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
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 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
}
}
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;
}
......
......@@ -487,14 +487,9 @@ public class X11GraphicsDevice
* 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();
......
......@@ -1434,11 +1434,17 @@ Java_sun_awt_X11GraphicsConfig_pGetBounds(JNIEnv *env, jobject this, jint screen
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)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册