changeset 5191:e5e4a26f2a09

RT-32699: NPE on changing resolutions with sw pipeline Reviewed-by: anthony, zvegintsev, flar
author Petr Pchelko <petr.pchelko@oracle.com>
date Wed, 25 Sep 2013 12:24:11 +0400
parents 15579a6ca5b8
children d7772ae23f15
files modules/graphics/src/main/java/com/sun/glass/ui/Screen.java modules/graphics/src/main/java/com/sun/glass/ui/Window.java modules/graphics/src/main/native-glass/gtk/GlassApplication.cpp modules/graphics/src/main/native-glass/gtk/glass_general.cpp modules/graphics/src/main/native-glass/gtk/glass_general.h modules/graphics/src/main/native-glass/gtk/glass_screen.cpp modules/graphics/src/main/native-glass/gtk/glass_screen.h modules/graphics/src/main/native-glass/gtk/glass_window.cpp modules/graphics/src/main/native-glass/ios/GlassApplication.m modules/graphics/src/main/native-glass/mac/GlassScreen.h modules/graphics/src/main/native-glass/mac/GlassScreen.m modules/graphics/src/main/native-glass/mac/GlassWindow+Java.m modules/graphics/src/main/native-glass/mac/GlassWindow.m modules/graphics/src/main/native-glass/win/GlassScreen.cpp modules/graphics/src/main/native-glass/win/GlassScreen.h modules/graphics/src/main/native-glass/win/GlassWindow.cpp
diffstat 16 files changed, 287 insertions(+), 179 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/glass/ui/Screen.java	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/Screen.java	Wed Sep 25 12:24:11 2013 +0400
@@ -58,19 +58,6 @@
         return Application.GetApplication().staticScreen_getVideoRefreshPeriod();
     }
 
-    // Used by Window.notifyMoveToAnotherScreen
-    static Screen getScreenForPtr(long screenPtr) {
-        Application.checkEventThread();
-        for (Screen s : getScreens()) {
-            if (s != null && s.ptr == screenPtr) {
-                return s;
-            }
-        }
-
-        return null;
-    }
-
-
     /**
      * Could be called from any thread
      * @return the main screen
@@ -317,4 +304,42 @@
                 "    resolutionX:"+getResolutionX()+"\n"+
                 "    resolutionY:"+getResolutionY()+"\n";
     }
+
+    @Override public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        Screen screen = (Screen) o;
+        return ptr == screen.ptr
+                && depth == screen.depth
+                && x == screen.x
+                && y == screen.y
+                && width == screen.width
+                && height == screen.height
+                && visibleX == screen.visibleX
+                && visibleY == screen.visibleY
+                && visibleWidth == screen.visibleWidth
+                && visibleHeight == screen.visibleHeight
+                && resolutionX == screen.resolutionX
+                && resolutionY == screen.resolutionY
+                && Float.compare(screen.scale, scale) == 0;
+    }
+
+    @Override public int hashCode() {
+        int result = 17;
+        result = 31 * result + (int) (ptr ^ (ptr >>> 32));
+        result = 31 * result + depth;
+        result = 31 * result + x;
+        result = 31 * result + y;
+        result = 31 * result + width;
+        result = 31 * result + height;
+        result = 31 * result + visibleX;
+        result = 31 * result + visibleY;
+        result = 31 * result + visibleWidth;
+        result = 31 * result + visibleHeight;
+        result = 31 * result + resolutionX;
+        result = 31 * result + resolutionY;
+        result = 31 * result + (scale != +0.0f ? Float.floatToIntBits(scale) : 0);
+        return result;
+    }
 }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/Window.java	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/Window.java	Wed Sep 25 12:24:11 2013 +0400
@@ -380,8 +380,8 @@
         this.screen = screen;
 
         if (this.eventHandler != null) {
-            //TODO: RT-31098
-            if (old != this.screen) {
+            if ((old == null && this.screen != null) ||
+                (old != null && !old.equals(this.screen))) {
                 this.eventHandler.handleScreenChangedEvent(this, System.nanoTime(), old, this.screen);
             }
         }
@@ -1169,8 +1169,8 @@
         handleWindowEvent(System.nanoTime(), WindowEvent.MOVE);
     }
 
-    protected void notifyMoveToAnotherScreen(long fromScreenPtr, long toScreenPtr) {
-        setScreen(Screen.getScreenForPtr(toScreenPtr));
+    protected void notifyMoveToAnotherScreen(Screen newScreen) {
+        setScreen(newScreen);
     }
 
     /**
--- a/modules/graphics/src/main/native-glass/gtk/GlassApplication.cpp	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/gtk/GlassApplication.cpp	Wed Sep 25 12:24:11 2013 +0400
@@ -43,6 +43,7 @@
 #include "glass_evloop.h"
 #include "glass_dnd.h"
 #include "glass_window.h"
+#include "glass_screen.h"
 
 GdkEventFunc process_events_prev;
 static void process_events(GdkEvent*, gpointer);
@@ -62,136 +63,6 @@
     return FALSE;
 }
 
-static jobject createJavaScreen
-  (JNIEnv* env, GdkScreen* screen, GdkRectangle workArea, gint monitor_idx)
-{
-    GdkRectangle monitor_geometry;
-    gdk_screen_get_monitor_geometry(screen, monitor_idx, &monitor_geometry);
-    LOG1("convert monitor[%d] -> glass Screen\n", monitor_idx)
-    LOG4("[x: %d y: %d w: %d h: %d]\n",
-            monitor_geometry.x, monitor_geometry.y,
-            monitor_geometry.width, monitor_geometry.height)
-
-    GdkVisual* visual = gdk_screen_get_system_visual(screen);
-
-    GdkRectangle working_monitor_geometry;
-    gdk_rectangle_intersect(&workArea, &monitor_geometry, &working_monitor_geometry);
-
-    jobject jScreen = env->NewObject(jScreenCls, jScreenInit,
-                                    (jlong)monitor_idx,
-
-                                    visual ? visual->depth : 0,
-
-                                    monitor_geometry.x,
-                                    monitor_geometry.y,
-                                    monitor_geometry.width,
-                                    monitor_geometry.height,
-
-                                    working_monitor_geometry.x,
-                                    working_monitor_geometry.y,
-                                    working_monitor_geometry.width,
-                                    working_monitor_geometry.height,
-
-                                    (jint)gdk_screen_get_resolution(screen),
-                                    (jint)gdk_screen_get_resolution(screen),
-                                    1.0f);
-    JNI_EXCEPTION_TO_CPP(env);
-    return jScreen;
-}
-
-static guint get_current_desktop(GdkScreen *screen) {
-    Display* display = gdk_x11_display_get_xdisplay(gdk_display_get_default());
-    Atom currentDesktopAtom = XInternAtom(display, "_NET_CURRENT_DESKTOP", True);
-    guint ret = 0;
-
-    Atom type;
-    int format;
-    gulong num, left;
-    unsigned long *data = NULL;
-
-    if (currentDesktopAtom == None) {
-        return 0;
-    }
-
-    int result = XGetWindowProperty(display,
-            GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
-            currentDesktopAtom, 0, G_MAXLONG, False, XA_CARDINAL,
-            &type, &format, &num, &left, (unsigned char **)&data);
-
-    if ((result == Success) && (data != NULL)) {
-        if (type == XA_CARDINAL && format == 32) {
-            ret = data[0];
-        }
-
-        XFree(data);
-    }
-
-    return ret;
-
-}
-
-static GdkRectangle get_screen_workarea(GdkScreen *screen) {
-    Display* display = gdk_x11_display_get_xdisplay(gdk_display_get_default());
-    GdkRectangle ret = { 0, 0, gdk_screen_get_width(screen), gdk_screen_get_height(screen)};
-
-    Atom workareaAtom = XInternAtom(display, "_NET_WORKAREA", True);
-
-    Atom type;
-    int format;
-    gulong num, left;
-    unsigned long *data = NULL;
-
-    if (workareaAtom == None) {
-        return ret;
-    }
-
-    int result = XGetWindowProperty(display,
-            GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
-            workareaAtom, 0, G_MAXLONG, False, AnyPropertyType,
-            &type, &format, &num, &left, (unsigned char **)&data);
-
-    if ((result == Success) && (data != NULL)) {
-        if (type != None && format == 32) {
-            guint current_desktop = get_current_desktop(screen);
-            if (current_desktop < num / 4) {
-                ret.x = data[current_desktop * 4];
-                ret.y = data[current_desktop * 4 + 1];
-                ret.width = data[current_desktop * 4 + 2];
-                ret.height = data[current_desktop * 4 + 3];
-            }
-        }
-
-        XFree(data);
-    }
-
-    return ret;
-
-}
-
-static jobjectArray rebuild_screens(JNIEnv* env) {
-    GdkScreen *default_gdk_screen = gdk_screen_get_default();
-    gint n_monitors = gdk_screen_get_n_monitors(default_gdk_screen);
-
-    jobjectArray jscreens = env->NewObjectArray(n_monitors, jScreenCls, NULL);
-    JNI_EXCEPTION_TO_CPP(env)
-    LOG1("Available monitors: %d\n", n_monitors)
-    int i;
-    GdkRectangle workArea = get_screen_workarea(default_gdk_screen);
-    LOG4("Work Area: x:%d, y:%d, w:%d, h:%d\n", workArea.x, workArea.y, workArea.width, workArea.height);
-
-    for (i=0; i < n_monitors; i++) {
-        env->SetObjectArrayElement(jscreens, i, createJavaScreen(env, default_gdk_screen, workArea, i));
-        JNI_EXCEPTION_TO_CPP(env)
-    }
-
-    return jscreens;
-}
-
-static void screen_settings_changed(GdkScreen* screen, gpointer user_data) {
-    mainEnv->CallStaticVoidMethod(jScreenCls, jScreenNotifySettingsChanged);
-    LOG_EXCEPTION(mainEnv);
-}
-
 extern "C" {
 
 /*
--- a/modules/graphics/src/main/native-glass/gtk/glass_general.cpp	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/gtk/glass_general.cpp	Wed Sep 25 12:24:11 2013 +0400
@@ -167,7 +167,7 @@
     jWindowNotifyFocus = env->GetMethodID(clazz, "notifyFocus", "(I)V");
     jWindowNotifyFocusDisabled = env->GetMethodID(clazz, "notifyFocusDisabled", "()V");
     jWindowNotifyFocusUngrab = env->GetMethodID(clazz, "notifyFocusUngrab", "()V");
-    jWindowNotifyMoveToAnotherScreen = env->GetMethodID(clazz, "notifyMoveToAnotherScreen", "(JJ)V");
+    jWindowNotifyMoveToAnotherScreen = env->GetMethodID(clazz, "notifyMoveToAnotherScreen", "(Lcom/sun/glass/ui/Screen;)V");
     jWindowIsEnabled = env->GetMethodID(clazz, "isEnabled", "()Z");
     jWindowNotifyDelegatePtr = env->GetMethodID(clazz, "notifyDelegatePtr", "(J)V");
     jWindowPtr = env->GetFieldID(clazz, "ptr", "J");
--- a/modules/graphics/src/main/native-glass/gtk/glass_general.h	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/gtk/glass_general.h	Wed Sep 25 12:24:11 2013 +0400
@@ -144,7 +144,7 @@
     extern jmethodID jWindowNotifyFocus; // com.sun.glass.ui.Window#notifyFocus (I)V
     extern jmethodID jWindowNotifyFocusDisabled; // com.sun.glass.ui.Window#notifyFocusDisabled ()V
     extern jmethodID jWindowNotifyFocusUngrab; // com.sun.glass.ui.Window#notifyFocusUngrab ()V
-    extern jmethodID jWindowNotifyMoveToAnotherScreen; // com.sun.glass.ui.Window#notifyMoveToAnotherScreen (JJ)V
+    extern jmethodID jWindowNotifyMoveToAnotherScreen; // com.sun.glass.ui.Window#notifyMoveToAnotherScreen (Lcom/sun/glass/ui/Screen;)V
     extern jmethodID jWindowNotifyDelegatePtr; //com.sun.glass.ui.Window#notifyDelegatePtr (J)V
     extern jmethodID jWindowIsEnabled; // com.sun.glass.ui.Window#isEnabled ()Z
     extern jfieldID jWindowPtr; // com.sun.glass.ui.Window#ptr
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/native-glass/gtk/glass_screen.cpp	Wed Sep 25 12:24:11 2013 +0400
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 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
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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 "glass_screen.h"
+#include "glass_general.h"
+
+#include <X11/Xatom.h>
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
+static guint get_current_desktop(GdkScreen *screen) {
+    Display* display = gdk_x11_display_get_xdisplay(gdk_display_get_default());
+    Atom currentDesktopAtom = XInternAtom(display, "_NET_CURRENT_DESKTOP", True);
+    guint ret = 0;
+
+    Atom type;
+    int format;
+    gulong num, left;
+    unsigned long *data = NULL;
+
+    if (currentDesktopAtom == None) {
+        return 0;
+    }
+
+    int result = XGetWindowProperty(display,
+                                    GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
+                                    currentDesktopAtom, 0, G_MAXLONG, False, XA_CARDINAL,
+                                    &type, &format, &num, &left, (unsigned char **)&data);
+
+    if ((result == Success) && (data != NULL)) {
+        if (type == XA_CARDINAL && format == 32) {
+            ret = data[0];
+        }
+
+        XFree(data);
+    }
+
+    return ret;
+
+}
+
+static GdkRectangle get_screen_workarea(GdkScreen *screen) {
+    Display* display = gdk_x11_display_get_xdisplay(gdk_display_get_default());
+    GdkRectangle ret = { 0, 0, gdk_screen_get_width(screen), gdk_screen_get_height(screen)};
+
+    Atom workareaAtom = XInternAtom(display, "_NET_WORKAREA", True);
+
+    Atom type;
+    int format;
+    gulong num, left;
+    unsigned long *data = NULL;
+
+    if (workareaAtom == None) {
+        return ret;
+    }
+
+    int result = XGetWindowProperty(display,
+                                    GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
+                                    workareaAtom, 0, G_MAXLONG, False, AnyPropertyType,
+                                    &type, &format, &num, &left, (unsigned char **)&data);
+
+    if ((result == Success) && (data != NULL)) {
+        if (type != None && format == 32) {
+            guint current_desktop = get_current_desktop(screen);
+            if (current_desktop < num / 4) {
+                ret.x = data[current_desktop * 4];
+                ret.y = data[current_desktop * 4 + 1];
+                ret.width = data[current_desktop * 4 + 2];
+                ret.height = data[current_desktop * 4 + 3];
+            }
+        }
+
+        XFree(data);
+    }
+
+    return ret;
+
+}
+
+static jobject createJavaScreen(JNIEnv* env, GdkScreen* screen, gint monitor_idx)
+{
+    GdkRectangle workArea = get_screen_workarea(screen);
+    LOG4("Work Area: x:%d, y:%d, w:%d, h:%d\n", workArea.x, workArea.y, workArea.width, workArea.height);
+
+    GdkRectangle monitor_geometry;
+    gdk_screen_get_monitor_geometry(screen, monitor_idx, &monitor_geometry);
+    LOG1("convert monitor[%d] -> glass Screen\n", monitor_idx)
+    LOG4("[x: %d y: %d w: %d h: %d]\n",
+         monitor_geometry.x, monitor_geometry.y,
+         monitor_geometry.width, monitor_geometry.height)
+
+    GdkVisual* visual = gdk_screen_get_system_visual(screen);
+
+    GdkRectangle working_monitor_geometry;
+    gdk_rectangle_intersect(&workArea, &monitor_geometry, &working_monitor_geometry);
+
+    jobject jScreen = env->NewObject(jScreenCls, jScreenInit,
+                                     (jlong)monitor_idx,
+
+                                     visual ? visual->depth : 0,
+
+                                     monitor_geometry.x,
+                                     monitor_geometry.y,
+                                     monitor_geometry.width,
+                                     monitor_geometry.height,
+
+                                     working_monitor_geometry.x,
+                                     working_monitor_geometry.y,
+                                     working_monitor_geometry.width,
+                                     working_monitor_geometry.height,
+
+                                     (jint)gdk_screen_get_resolution(screen),
+                                     (jint)gdk_screen_get_resolution(screen),
+                                     1.0f);
+    JNI_EXCEPTION_TO_CPP(env);
+    return jScreen;
+}
+
+jobject createJavaScreen(JNIEnv* env, gint monitor_idx) {
+    GdkScreen *default_gdk_screen = gdk_screen_get_default();
+    return createJavaScreen(env, default_gdk_screen, monitor_idx);
+}
+
+jobjectArray rebuild_screens(JNIEnv* env) {
+    GdkScreen *default_gdk_screen = gdk_screen_get_default();
+    gint n_monitors = gdk_screen_get_n_monitors(default_gdk_screen);
+    
+    jobjectArray jscreens = env->NewObjectArray(n_monitors, jScreenCls, NULL);
+    JNI_EXCEPTION_TO_CPP(env)
+    LOG1("Available monitors: %d\n", n_monitors)
+    
+    int i;
+    for (i=0; i < n_monitors; i++) {
+        env->SetObjectArrayElement(jscreens, i, createJavaScreen(env, default_gdk_screen, i));
+        JNI_EXCEPTION_TO_CPP(env)
+    }
+    
+    return jscreens;
+}
+
+
+glong getScreenPtrForLocation(gint x, gint y) {
+    //Note: we are relying on the fact that javafx_screen_id == gdk_monitor_id
+    return gdk_screen_get_monitor_at_point(gdk_screen_get_default(), x, y);
+}
+
+void screen_settings_changed(GdkScreen* screen, gpointer user_data) {
+    mainEnv->CallStaticVoidMethod(jScreenCls, jScreenNotifySettingsChanged);
+    LOG_EXCEPTION(mainEnv);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/native-glass/gtk/glass_screen.h	Wed Sep 25 12:24:11 2013 +0400
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 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
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+#ifndef GLASS_SCREEN_H
+#define GLASS_SCREEN_H
+
+#include <jni.h>
+
+#include <gtk/gtk.h>
+
+jobject createJavaScreen(JNIEnv* env, gint monitor_idx);
+glong getScreenPtrForLocation(gint x, gint y);
+jobjectArray rebuild_screens(JNIEnv* env);
+void screen_settings_changed(GdkScreen* screen, gpointer user_data);
+
+#endif
--- a/modules/graphics/src/main/native-glass/gtk/glass_window.cpp	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/gtk/glass_window.cpp	Wed Sep 25 12:24:11 2013 +0400
@@ -26,6 +26,7 @@
 #include "glass_general.h"
 #include "glass_gtkcompat.h"
 #include "glass_key.h"
+#include "glass_screen.h"
 
 #include <com_sun_glass_events_WindowEvent.h>
 #include <com_sun_glass_events_ViewEvent.h>
@@ -911,11 +912,6 @@
     }
 }
 
-static glong getScreenPtrForLocation(gint x, gint y) { //TODO: refactor to GlassApplication.cpp ?
-    //Note: we are relying on the fact that javafx_screen_id == gdk_monitor_id
-    return gdk_screen_get_monitor_at_point(gdk_screen_get_default(), x, y);
-}
-
 void WindowContextTop::process_configure(GdkEventConfigure* event) {
 
     geometry.current_width = event->width + geometry.extents.left
@@ -967,7 +963,8 @@
         if (to_screen != screen) {
             if (jwindow) {
                 //notify screen changed
-                mainEnv->CallVoidMethod(jwindow, jWindowNotifyMoveToAnotherScreen, screen, (jlong) to_screen);
+                jobject jScreen = createJavaScreen(mainEnv, to_screen);
+                mainEnv->CallVoidMethod(jwindow, jWindowNotifyMoveToAnotherScreen, jScreen);
                 CHECK_JNI_EXCEPTION(mainEnv)
             }
             screen = to_screen;
--- a/modules/graphics/src/main/native-glass/ios/GlassApplication.m	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/ios/GlassApplication.m	Wed Sep 25 12:24:11 2013 +0400
@@ -666,7 +666,7 @@
     
     mat_jWindowNotifyMove = (*env)->GetMethodID(env, mat_jWindowBaseClass, "notifyMove", "(II)V");
     mat_jWindowNotifyResize = (*env)->GetMethodID(env, mat_jWindowBaseClass, "notifyResize", "(III)V");
-    mat_jWindowNotifyMoveToAnotherScreen = (*env)->GetMethodID(env, mat_jWindowBaseClass, "notifyMoveToAnotherScreen", "(JJ)V");
+    mat_jWindowNotifyMoveToAnotherScreen = (*env)->GetMethodID(env, mat_jWindowBaseClass, "notifyMoveToAnotherScreen", "(Lcom/sun/glass/ui/Screen;)V");
     mat_jWindowNotifyClose = (*env)->GetMethodID(env, mat_jWindowBaseClass, "notifyClose", "()V");
     mat_jWindowNotifyFocus = (*env)->GetMethodID(env, mat_jWindowBaseClass, "notifyFocus", "(I)V");
     mat_jWindowNotifyDestroy = (*env)->GetMethodID(env, mat_jWindowBaseClass, "notifyDestroy", "()V");
--- a/modules/graphics/src/main/native-glass/mac/GlassScreen.h	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/mac/GlassScreen.h	Wed Sep 25 12:24:11 2013 +0400
@@ -38,3 +38,4 @@
 
 CGFloat GetScreenScaleFactor(NSScreen *screen);
 jobjectArray createJavaScreens(JNIEnv* env);
+jobject createJavaScreen(JNIEnv *env, NSScreen* screen);
--- a/modules/graphics/src/main/native-glass/mac/GlassScreen.m	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/mac/GlassScreen.m	Wed Sep 25 12:24:11 2013 +0400
@@ -48,7 +48,7 @@
     }
 }
 
-static inline jobject createJavaScreen(JNIEnv *env, NSScreen* screen)
+jobject createJavaScreen(JNIEnv *env, NSScreen* screen)
 {
     jobject jscreen = NULL;
 
--- a/modules/graphics/src/main/native-glass/mac/GlassWindow+Java.m	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/mac/GlassWindow+Java.m	Wed Sep 25 12:24:11 2013 +0400
@@ -32,6 +32,7 @@
 
 #import "GlassMacros.h"
 #import "GlassWindow+Java.h"
+#import "GlassScreen.h"
 
 static NSWindow *s_grabWindow = nil;
 
@@ -56,7 +57,7 @@
         self->currentScreen = newScreen;
         
         GET_MAIN_JENV;
-        (*env)->CallVoidMethod(env, jWindow, jWindowNotifyMoveToAnotherScreen, ptr_to_jlong(self->currentScreen), ptr_to_jlong(newScreen));
+        (*env)->CallVoidMethod(env, jWindow, jWindowNotifyMoveToAnotherScreen, createJavaScreen(env, newScreen));
     }
 }
 
--- a/modules/graphics/src/main/native-glass/mac/GlassWindow.m	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/mac/GlassWindow.m	Wed Sep 25 12:24:11 2013 +0400
@@ -617,7 +617,7 @@
     
     if (jWindowNotifyMoveToAnotherScreen == NULL)
     {
-        jWindowNotifyMoveToAnotherScreen = (*env)->GetMethodID(env, jWindowClass, "notifyMoveToAnotherScreen", "(JJ)V");
+        jWindowNotifyMoveToAnotherScreen = (*env)->GetMethodID(env, jWindowClass, "notifyMoveToAnotherScreen", "(Lcom/sun/glass/ui/Screen;)V");
     }
     
     if (jWindowNotifyClose == NULL)
--- a/modules/graphics/src/main/native-glass/win/GlassScreen.cpp	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/win/GlassScreen.cpp	Wed Sep 25 12:24:11 2013 +0400
@@ -101,7 +101,7 @@
     return screenCls;
 }
 
-jobject CreateJavaMonitorWithSettings(JNIEnv *env, MonitorInfoStruct *mis)
+jobject GlassScreen::CreateJavaMonitor(JNIEnv *env, HMONITOR monitor)
 {
     jclass screenCls = GetScreenCls(env);
 
@@ -111,25 +111,29 @@
     }
     
     if (CheckAndClearException(env)) return NULL;
+
+    MonitorInfoStruct mis;
+    memset(&mis, 0, sizeof(MonitorInfoStruct));
+    GetMonitorSettings(monitor, &mis);
     
     return env->NewObject(screenCls, javaIDs.Screen.init,
-                          mis->ptr,
+                          mis.ptr,
 
-                          mis->colorDepth,
-                          mis->rcMonitor.left,
-                          mis->rcMonitor.top,
-                          mis->rcMonitor.right - mis->rcMonitor.left,
-                          mis->rcMonitor.bottom - mis->rcMonitor.top,
+                          mis.colorDepth,
+                          mis.rcMonitor.left,
+                          mis.rcMonitor.top,
+                          mis.rcMonitor.right - mis.rcMonitor.left,
+                          mis.rcMonitor.bottom - mis.rcMonitor.top,
                           
-                          mis->rcWork.left,
-                          mis->rcWork.top,
-                          mis->rcWork.right - mis->rcWork.left,
-                          mis->rcWork.bottom - mis->rcWork.top,
+                          mis.rcWork.left,
+                          mis.rcWork.top,
+                          mis.rcWork.right - mis.rcWork.left,
+                          mis.rcWork.bottom - mis.rcWork.top,
                               
-                          mis->dpiX,
-                          mis->dpiY,
+                          mis.dpiX,
+                          mis.dpiY,
                           
-                          mis->scale);
+                          mis.scale);
 }
 
 void GlassScreen::HandleDisplayChange()
@@ -161,11 +165,8 @@
     int arrayIndex = 1;
     for (int i = 0; i < numMonitors; i++) {
         if (g_hmpMonitors[i] != NULL) {
-            MonitorInfoStruct mis;
-            memset(&mis, 0, sizeof(MonitorInfoStruct));
-            GetMonitorSettings(g_hmpMonitors[i], &mis);
 
-            jobject jScreen = CreateJavaMonitorWithSettings(env, &mis);
+            jobject jScreen = CreateJavaMonitor(env, g_hmpMonitors[i]);
             const POINT ptZero = { 0, 0 };
 
             //The primary monitor should be set to the 0 index
--- a/modules/graphics/src/main/native-glass/win/GlassScreen.h	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/win/GlassScreen.h	Wed Sep 25 12:24:11 2013 +0400
@@ -28,6 +28,7 @@
 
 class GlassScreen {
 public:
+    static jobject CreateJavaMonitor(JNIEnv *env, HMONITOR monitor);
     static void HandleDisplayChange();
     static jobjectArray CreateJavaScreens(JNIEnv* env);
 };
--- a/modules/graphics/src/main/native-glass/win/GlassWindow.cpp	Tue Sep 24 23:34:57 2013 -0700
+++ b/modules/graphics/src/main/native-glass/win/GlassWindow.cpp	Wed Sep 25 12:24:11 2013 +0400
@@ -35,6 +35,7 @@
 #include "Pixels.h"
 #include "AccessibleRoot.h"
 #include "GlassCursor.h"
+#include "GlassScreen.h"
 
 #include "com_sun_glass_events_WindowEvent.h"
 #include "com_sun_glass_ui_Window.h"
@@ -565,7 +566,7 @@
     HMONITOR fromMonitor = GetMonitor();
     if (toMonitor != fromMonitor) {
         env->CallVoidMethod(m_grefThis, midNotifyMoveToAnotherScreen,
-                            ptr_to_jlong(fromMonitor), ptr_to_jlong(toMonitor));
+                            GlassScreen::CreateJavaMonitor(env, toMonitor));
         CheckAndClearException(env);
         SetMonitor(toMonitor);
     }
@@ -989,7 +990,7 @@
     javaIDs.Window.notifyFocusUngrab = env->GetMethodID(cls, "notifyFocusUngrab", "()V");
     ASSERT(javaIDs.Window.notifyFocusUngrab);
 
-    midNotifyMoveToAnotherScreen = env->GetMethodID(cls, "notifyMoveToAnotherScreen", "(JJ)V");
+    midNotifyMoveToAnotherScreen = env->GetMethodID(cls, "notifyMoveToAnotherScreen", "(Lcom/sun/glass/ui/Screen;)V");
     ASSERT(midNotifyMoveToAnotherScreen);