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

7160293: [macosx] FileDialog appears on secondary display

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