aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-21 04:37:39 +0100
committerSven Gothel <[email protected]>2015-03-21 04:37:39 +0100
commit7438540ee6604cf91e14f12da891834d4cd83cfe (patch)
treef08c7ebae83b406450b83c6b8f17c608ad1c7c48 /src/nativewindow
parent9a8ae7c79cb6a89626eeb6a9a00fc9e32f9c0a71 (diff)
Bug 1148 - OSX MonitorDevice: Use unique and native deviceID instead of index
Adopt to bug 1147, commit 2c88b6dfd4eb7e2cd9a50fa48e08ecafc980931a. Using the native unique deviceID makes monitor identification more robust. This also allows us simplify displayID -> NSScreen-idx -> MonitorDevice into displayID -> MonitorDevice and to survive a primary monitor change.
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java9
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java20
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m72
3 files changed, 23 insertions, 78 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
index 93c3dbaf7..3b824cfe4 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
@@ -550,19 +550,18 @@ public class JAWTUtil {
return jawtToolkitLock;
}
- public static final int getMonitorIndex(final GraphicsDevice device) {
- int idx = -1;
+ public static final int getMonitorDisplayID(final GraphicsDevice device) {
+ int displayID = 0;
if( null != getCGDisplayIDMethodOnOSX ) {
// OSX specific
try {
final Object res = getCGDisplayIDMethodOnOSX.invoke(device);
if (res instanceof Integer) {
- final int displayID = ((Integer)res).intValue();
- idx = OSXUtil.GetNSScreenIdx(displayID);
+ displayID = ((Integer)res).intValue();
}
} catch (final Throwable t) {}
}
- return idx;
+ return displayID;
}
/**
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index a5970b87c..8ad089a56 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -107,17 +107,19 @@ public class OSXUtil implements ToolkitProperties {
return (Insets) GetInsets0(windowOrView);
}
- public static int GetNSScreenIdx(final int displayID) {
- return GetNSScreenIdx0(displayID);
- }
- public static double GetPixelScaleByScreenIdx(final int screenIndex) {
- return GetPixelScale0(screenIndex);
- }
public static double GetPixelScaleByDisplayID(final int displayID) {
- return GetPixelScale1(displayID);
+ if( 0 != displayID ) {
+ return GetPixelScale1(displayID);
+ } else {
+ return 1.0; // default
+ }
}
public static double GetPixelScale(final long windowOrView) {
- return GetPixelScale2(windowOrView);
+ if( 0 != windowOrView ) {
+ return GetPixelScale2(windowOrView);
+ } else {
+ return 1.0; // default
+ }
}
public static long CreateNSWindow(final int x, final int y, final int width, final int height) {
@@ -398,8 +400,6 @@ public class OSXUtil implements ToolkitProperties {
private static native boolean isNSWindow0(long object);
private static native Object GetLocationOnScreen0(long windowOrView, int src_x, int src_y);
private static native Object GetInsets0(long windowOrView);
- private static native int GetNSScreenIdx0(int displayID);
- private static native double GetPixelScale0(int screenIndex);
private static native double GetPixelScale1(int displayID);
private static native double GetPixelScale2(long windowOrView);
private static native long CreateNSWindow0(int x, int y, int width, int height);
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m
index 87494e946..919108db9 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -138,6 +138,9 @@ Java_jogamp_nativewindow_macosx_OSXUtil_isNSWindow0(JNIEnv *env, jclass _unused,
}
static CGDirectDisplayID OSXUtil_getCGDirectDisplayIDByNSScreen(NSScreen *screen) {
+ if( NULL == screen ) {
+ return (CGDirectDisplayID)0;
+ }
// Mind: typedef uint32_t CGDirectDisplayID;
NSDictionary * dict = [screen deviceDescription];
NSNumber * val = (NSNumber *) [dict objectForKey: @"NSScreenNumber"];
@@ -154,19 +157,7 @@ static NSScreen * OSXUtil_getNSScreenByCGDirectDisplayID(CGDirectDisplayID displ
return screen;
}
}
- return (NSScreen *) [screens objectAtIndex: 0];
-}
-static int OSXUtil_getNSScreenIdxByCGDirectDisplayID(CGDirectDisplayID displayID) {
- NSArray *screens = [NSScreen screens];
- int i;
- for(i=[screens count]-1; i>=0; i--) {
- NSScreen * screen = (NSScreen *) [screens objectAtIndex: i];
- CGDirectDisplayID dID = OSXUtil_getCGDirectDisplayIDByNSScreen(screen);
- if( dID == displayID ) {
- return i;
- }
- }
- return -1;
+ return NULL;
}
/*
@@ -275,52 +266,6 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetInsets0
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
- * Method: GetNSScreenIdx0
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSScreenIdx0
- (JNIEnv *env, jclass unused, jint displayID)
-{
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
-
- int idx = OSXUtil_getNSScreenIdxByCGDirectDisplayID((CGDirectDisplayID)displayID);
- [pool release];
-
- return idx;
-}
-
-/*
- * Class: Java_jogamp_nativewindow_macosx_OSXUtil
- * Method: GetPixelScale0
- * Signature: (I)D
- */
-JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale0
- (JNIEnv *env, jclass unused, jint screen_idx)
-{
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
-
- CGFloat pixelScale;
- NSScreen *screen;
- NSArray *screens = [NSScreen screens];
- if( screen_idx<0 || screen_idx>=[screens count] ) {
- screen = NULL;
- pixelScale = 1.0;
- } else {
- screen = (NSScreen *) [screens objectAtIndex: screen_idx];
- pixelScale = 1.0; // default
-NS_DURING
- // Available >= 10.7
- pixelScale = [screen backingScaleFactor]; // HiDPI scaling
-NS_HANDLER
-NS_ENDHANDLER
- }
- [pool release];
-
- return (jdouble)pixelScale;
-}
-
-/*
- * Class: Java_jogamp_nativewindow_macosx_OSXUtil
* Method: GetPixelScale1
* Signature: (I)D
*/
@@ -329,14 +274,15 @@ JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale1
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- CGFloat pixelScale;
+ CGFloat pixelScale = 1.0; // default
NSScreen *screen = OSXUtil_getNSScreenByCGDirectDisplayID((CGDirectDisplayID)displayID);
- pixelScale = 1.0; // default
+ if( NULL != screen ) {
NS_DURING
- // Available >= 10.7
- pixelScale = [screen backingScaleFactor]; // HiDPI scaling
+ // Available >= 10.7
+ pixelScale = [screen backingScaleFactor]; // HiDPI scaling
NS_HANDLER
NS_ENDHANDLER
+ }
[pool release];
return (jdouble)pixelScale;