提交 1c454ad2 编写于 作者: D dcherepanov

7160293: [macosx] FileDialog appears on secondary display

Reviewed-by: art, bae
上级 5821288d
......@@ -181,6 +181,10 @@ public class CGraphicsEnvironment extends SunGraphicsEnvironment {
return devices.values().toArray(new CGraphicsDevice[devices.values().size()]);
}
public synchronized GraphicsDevice getScreenDevice(int displayID) {
return devices.get(displayID);
}
@Override
protected synchronized int getNumScreens() {
return devices.size();
......
......@@ -68,7 +68,7 @@ public class LWWindowPeer
private Insets insets = new Insets(0, 0, 0, 0);
private int screenOn = -1;
private GraphicsDevice graphicsDevice;
private GraphicsConfiguration graphicsConfig;
private SurfaceData surfaceData;
......@@ -868,17 +868,6 @@ public class LWWindowPeer
return 0;
}
private static GraphicsConfiguration getScreenGraphicsConfig(int screen) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (screen >= gds.length) {
// This could happen during device addition/removal. Use
// the default screen device in this case
return ge.getDefaultScreenDevice().getDefaultConfiguration();
}
return gds[screen].getDefaultConfiguration();
}
/*
* This method is called when window's graphics config is changed from
* the app code (e.g. when the window is made non-opaque) or when
......@@ -893,7 +882,7 @@ public class LWWindowPeer
}
// If window's graphics config is changed from the app code, the
// config correspond to the same device as before; when the window
// is moved by user, screenOn is updated in checkIfOnNewScreen().
// is moved by user, graphicsDevice is updated in checkIfOnNewScreen().
// In either case, there's nothing to do with screenOn here
graphicsConfig = gc;
}
......@@ -902,16 +891,17 @@ public class LWWindowPeer
}
private void checkIfOnNewScreen() {
int windowScreen = platformWindow.getScreenImOn();
GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
synchronized (getStateLock()) {
if (windowScreen == screenOn) {
if (graphicsDevice == newGraphicsDevice) {
return;
}
screenOn = windowScreen;
graphicsDevice = newGraphicsDevice;
}
// TODO: DisplayChangedListener stuff
final GraphicsConfiguration newGC = getScreenGraphicsConfig(windowScreen);
final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
if (!setGraphicsConfig(newGC)) return;
SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
......
......@@ -67,9 +67,9 @@ public interface PlatformWindow {
public void setBounds(int x, int y, int w, int h);
/*
* Returns the screen number where the window is.
* Returns the graphics device where the window is.
*/
public int getScreenImOn();
public GraphicsDevice getGraphicsDevice();
/*
* Returns the location of the window.
......
......@@ -86,11 +86,10 @@ public class CPlatformEmbeddedFrame implements PlatformWindow {
}
@Override
public int getScreenImOn() {
public GraphicsDevice getGraphicsDevice() {
// REMIND: return the main screen for the initial implementation
CGraphicsConfig gc = (CGraphicsConfig)peer.getGraphicsConfiguration();
CGraphicsDevice device = gc.getDevice();
return device.getCoreGraphicsScreen();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
return ge.getDefaultScreenDevice();
}
@Override
......
......@@ -64,7 +64,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr);
private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr);
private static native int nativeGetNSWindowDisplayID_AppKitThread(long nsWindowPtr);
// Loger to report issues happened during execution but that do not affect functionality
private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
......@@ -452,13 +452,18 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
return new Point(nativeBounds.x, nativeBounds.y);
}
@Override // PlatformWindow
public int getScreenImOn() {
// REMIND: we could also acquire screenID from the
// graphicsConfig.getDevice().getCoreGraphicsScreen()
// which might look a bit less natural but don't
// require new native accessor.
return nativeGetScreenNSWindowIsOn_AppKitThread(getNSWindowPtr());
@Override
public GraphicsDevice getGraphicsDevice() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
CGraphicsEnvironment cge = (CGraphicsEnvironment)ge;
int displayID = nativeGetNSWindowDisplayID_AppKitThread(getNSWindowPtr());
GraphicsDevice gd = cge.getScreenDevice(displayID);
if (gd == null) {
// this could possibly happen during device removal
// use the default screen device in this case
gd = ge.getDefaultScreenDevice();
}
return gd;
}
@Override // PlatformWindow
......
......@@ -1080,38 +1080,28 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMou
/*
* Class: sun_lwawt_macosx_CPlatformWindow
* Method: nativeGetScreenNSWindowIsOn_AppKitThread
* Method: nativeGetDisplayID_AppKitThread
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetScreenNSWindowIsOn_1AppKitThread
JNIEXPORT jint JNICALL
Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowDisplayID_1AppKitThread
(JNIEnv *env, jclass clazz, jlong windowPtr)
{
jint index = -1;
jint ret; // CGDirectDisplayID
JNF_COCOA_ENTER(env);
AWT_ASSERT_APPKIT_THREAD;
NSWindow *nsWindow = OBJC(windowPtr);
NSScreen* screen = [nsWindow screen];
//+++gdb NOTE: This is using a linear search of the screens. If it should
// prove to be a bottleneck, this can definitely be improved. However,
// many screens should prove to be the exception, rather than the rule.
NSArray* screens = [NSScreen screens];
NSUInteger i;
for (i = 0; i < [screens count]; i++)
{
if ([[screens objectAtIndex:i] isEqualTo:screen])
{
index = i;
break;
}
}
NSWindow *window = OBJC(windowPtr);
NSScreen *screen = [window screen];
NSDictionary *deviceDescription = [screen deviceDescription];
NSNumber *displayID = [deviceDescription objectForKey:@"NSScreenNumber"];
ret = (jint)[displayID intValue];
JNF_COCOA_EXIT(env);
return 1;
}
return ret;
}
/*
* Class: sun_lwawt_macosx_CPlatformWindow
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册