src/macosx/native/sun/awt/CGraphicsDevice.m

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -21,11 +21,12 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-#include "LWCToolkit.h"
+#import "LWCToolkit.h"
+#import "ThreadUtilities.h"
 
 /*
  * Convert the mode string to the more convinient bits per pixel value
  */
 static int getBPPFromModeString(CFStringRef mode)

@@ -146,10 +147,51 @@
     return dpi;
 }
 
 /*
  * Class:     sun_awt_CGraphicsDevice
+ * Method:    nativeGetScreenInsets
+ * Signature: (I)D
+ */
+JNIEXPORT jobject JNICALL
+Java_sun_awt_CGraphicsDevice_nativeGetScreenInsets
+  (JNIEnv *env, jclass class, jint displayID)
+{
+    jobject ret = NULL;
+    __block NSRect frame = NSZeroRect;
+    __block NSRect visibleFrame = NSZeroRect;
+JNF_COCOA_ENTER(env);
+    
+    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
+        NSArray *screens = [NSScreen screens];
+        for (NSScreen *screen in screens) {
+            NSDictionary *screenInfo = [screen deviceDescription];
+            NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
+            if ([screenID pointerValue] == displayID){
+                frame = [screen frame];
+                visibleFrame = [screen visibleFrame];
+                break;
+            }
+        }
+    }];
+    // Convert between Cocoa's coordinate system and Java.
+    jint bottom = visibleFrame.origin.y - frame.origin.y;
+    jint top = frame.size.height - visibleFrame.size.height - bottom;
+    jint left = visibleFrame.origin.x - frame.origin.x;
+    jint right = frame.size.width - visibleFrame.size.width - left;
+    
+    static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets");
+    static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V");
+    ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right);
+
+JNF_COCOA_EXIT(env);
+
+    return ret;
+}
+
+/*
+ * Class:     sun_awt_CGraphicsDevice
  * Method:    nativeSetDisplayMode
  * Signature: (IIIII)V
  */
 JNIEXPORT void JNICALL
 Java_sun_awt_CGraphicsDevice_nativeSetDisplayMode