diff --git a/widget/src/gtk2/nsScreenManagerGtk.cpp b/widget/src/gtk2/nsScreenManagerGtk.cpp index 53e8dbf976b..a0a60d8b9a7 100644 --- a/widget/src/gtk2/nsScreenManagerGtk.cpp +++ b/widget/src/gtk2/nsScreenManagerGtk.cpp @@ -342,13 +342,26 @@ nsScreenManagerGtk :: GetNumberOfScreens(PRUint32 *aNumberOfScreens) NS_IMETHODIMP nsScreenManagerGtk :: ScreenForNativeWidget (void *aWidget, nsIScreen **outScreen) { - // I don't know how to go from GtkWindow to nsIScreen, especially - // given xinerama and stuff, so let's just do this - gint x, y, width, height, depth; - x = y = width = height = 0; + nsresult rv; + rv = EnsureInit(); + if (NS_FAILED(rv)) { + NS_ERROR("nsScreenManagerGtk::EnsureInit() failed from ScreenForNativeWidget\n"); + return rv; + } - gdk_window_get_geometry(GDK_WINDOW(aWidget), &x, &y, &width, &height, - &depth); - gdk_window_get_origin(GDK_WINDOW(aWidget), &x, &y); - return ScreenForRect(x, y, width, height, outScreen); + if (mCachedScreenArray.Count() > 1) { + // I don't know how to go from GtkWindow to nsIScreen, especially + // given xinerama and stuff, so let's just do this + gint x, y, width, height, depth; + x = y = width = height = 0; + + gdk_window_get_geometry(GDK_WINDOW(aWidget), &x, &y, &width, &height, + &depth); + gdk_window_get_origin(GDK_WINDOW(aWidget), &x, &y); + rv = ScreenForRect(x, y, width, height, outScreen); + } else { + rv = GetPrimaryScreen(outScreen); + } + + return rv; }