< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java

Print this page
rev 60071 : 8211999: Window positioning bugs due to overlapping GraphicsDevice bounds (Windows/HiDPI)
Reviewed-by: XXX

*** 59,72 **** import sun.awt.DisplayChangedListener; import sun.awt.SunToolkit; import sun.awt.Win32GraphicsConfig; import sun.awt.Win32GraphicsDevice; import sun.awt.Win32GraphicsEnvironment; - import sun.java2d.SunGraphicsEnvironment; import sun.java2d.pipe.Region; import sun.util.logging.PlatformLogger; public class WWindowPeer extends WPanelPeer implements WindowPeer, DisplayChangedListener { private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WWindowPeer"); --- 59,73 ---- import sun.awt.DisplayChangedListener; import sun.awt.SunToolkit; import sun.awt.Win32GraphicsConfig; import sun.awt.Win32GraphicsDevice; import sun.awt.Win32GraphicsEnvironment; import sun.java2d.pipe.Region; import sun.util.logging.PlatformLogger; + import static sun.java2d.SunGraphicsEnvironment.toUserSpace; + public class WWindowPeer extends WPanelPeer implements WindowPeer, DisplayChangedListener { private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WWindowPeer");
*** 104,115 **** /* * Called (on the Toolkit thread) before the appropriate * WindowStateEvent is posted to the EventQueue. */ private WindowListener windowListener; - private float scaleX; - private float scaleY; /** * Initialize JNI field IDs */ private static native void initIDs(); --- 105,114 ----
*** 218,229 **** // Express our interest in display changes GraphicsConfiguration gc = getGraphicsConfiguration(); Win32GraphicsDevice gd = (Win32GraphicsDevice) gc.getDevice(); gd.addDisplayChangedListener(this); - scaleX = gd.getDefaultScaleX(); - scaleY = gd.getDefaultScaleY(); initActiveWindowsTracking((Window)target); updateIconImages(); --- 217,226 ----
*** 306,315 **** --- 303,317 ---- Rectangle b = getBounds(); handleExpose(0, 0, b.width, b.height); } } + final void syncBounds(){ + // The Windows will take care of the top-level window/frame/dialog, + // and update the location/size when DPI changes. + } + // Synchronize the insets members (here & in helper) with actual window // state. native void updateInsets(Insets i); static native int getSysMinWidth();
*** 400,412 **** Dimension minimumSize = null; if (((Component)target).isMinimumSizeSet()) { minimumSize = ((Component)target).getMinimumSize(); } if (minimumSize != null) { ! int w = Math.max(minimumSize.width, scaleDownX(getSysMinWidth())); ! int h = Math.max(minimumSize.height, scaleDownY(getSysMinHeight())); ! setMinSize(w, h); } else { setMinSize(0, 0); } } --- 402,415 ---- Dimension minimumSize = null; if (((Component)target).isMinimumSizeSet()) { minimumSize = ((Component)target).getMinimumSize(); } if (minimumSize != null) { ! Dimension sysMin = toUserSpace(getGraphicsConfiguration(), ! getSysMinWidth(), getSysMinHeight()); ! setMinSize(Math.max(minimumSize.width, sysMin.width), ! Math.max(minimumSize.height, sysMin.height)); } else { setMinSize(0, 0); } }
*** 560,584 **** newDev.addDisplayChangedListener(this); } AWTAccessor.getComponentAccessor(). setGraphicsConfiguration((Component)target, winGraphicsConfig); - - checkDPIChange(oldDev, newDev); - } - - private void checkDPIChange(Win32GraphicsDevice oldDev, - Win32GraphicsDevice newDev) { - float newScaleX = newDev.getDefaultScaleX(); - float newScaleY = newDev.getDefaultScaleY(); - - if (scaleX != newScaleX || scaleY != newScaleY) { - windowDPIChange(oldDev.getScreen(), scaleX, scaleY, - newDev.getScreen(), newScaleX, newScaleY); - scaleX = newScaleX; - scaleY = newScaleY; - } } /** * From the DisplayChangedListener interface. * --- 563,572 ----
*** 628,709 **** boolean isTargetUndecorated() { return true; } - // These are the peer bounds. They get updated at: - // 1. the WWindowPeer.setBounds() method. - // 2. the native code (on WM_SIZE/WM_MOVE) - private volatile int sysX = 0; - private volatile int sysY = 0; - private volatile int sysW = 0; - private volatile int sysH = 0; - @Override public native void repositionSecurityWarning(); @Override - public void setBounds(int x, int y, int width, int height, int op) { - sysX = x; - sysY = y; - sysW = width; - sysH = height; - - int cx = x + width / 2; - int cy = y + height / 2; - GraphicsConfiguration current = getGraphicsConfiguration(); - GraphicsConfiguration other = SunGraphicsEnvironment - .getGraphicsConfigurationAtPoint(current, cx, cy); - if (!current.equals(other)) { - AffineTransform tx = other.getDefaultTransform(); - double otherScaleX = tx.getScaleX(); - double otherScaleY = tx.getScaleY(); - initScales(); - if (scaleX != otherScaleX || scaleY != otherScaleY) { - x = (int) Math.floor(x * otherScaleX / scaleX); - y = (int) Math.floor(y * otherScaleY / scaleY); - } - } - - super.setBounds(x, y, width, height, op); - } - - private void initScales() { - - if (scaleX >= 1 && scaleY >= 1) { - return; - } - - GraphicsConfiguration gc = getGraphicsConfiguration(); - if (gc instanceof Win32GraphicsConfig) { - Win32GraphicsDevice gd = ((Win32GraphicsConfig) gc).getDevice(); - scaleX = gd.getDefaultScaleX(); - scaleY = gd.getDefaultScaleY(); - } else { - AffineTransform tx = gc.getDefaultTransform(); - scaleX = (float) tx.getScaleX(); - scaleY = (float) tx.getScaleY(); - } - } - - final int scaleUpX(int x) { - return Region.clipRound(x * scaleX); - } - - final int scaleUpY(int y) { - return Region.clipRound(y * scaleY); - } - - final int scaleDownX(int x) { - return Region.clipRound(x / scaleX); - } - - final int scaleDownY(int y) { - return Region.clipRound(y / scaleY); - } - - @Override public void print(Graphics g) { // We assume we print the whole frame, // so we expect no clip was set previously Shape shape = ((Window)target).getShape(); if (shape != null) { --- 616,629 ----
*** 867,879 **** log.finer("Translucent window painter is null in updateWindow"); } } } - native void windowDPIChange(int prevScreen, float prevScaleX, float prevScaleY, - int newScreen, float newScaleX, float newScaleY); - /* * The method maps the list of the active windows to the window's AppContext, * then the method registers ActiveWindowListener, GuiDisposedListener listeners; * it executes the initilialization only once per AppContext. */ --- 787,796 ----
< prev index next >