From 42f85ae201dd0c0c043e82a81788541be376fa14 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 17 Jun 2015 23:12:13 -0700 Subject: [PATCH] Add nsIGfxInfo::GetMonitor support for Linux. (bug 1175005 part 4, r=nical) --- widget/GfxInfoX11.cpp | 29 +++++++++++++++++++++++++++++ widget/GfxInfoX11.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/widget/GfxInfoX11.cpp b/widget/GfxInfoX11.cpp index 6bd14a2522b..9276a85dfe5 100644 --- a/widget/GfxInfoX11.cpp +++ b/widget/GfxInfoX11.cpp @@ -14,6 +14,7 @@ #include "prenv.h" #include "GfxInfoX11.h" +#include "mozilla/X11Util.h" #ifdef MOZ_CRASHREPORTER #include "nsExceptionHandler.h" @@ -534,6 +535,34 @@ GfxInfo::GetIsGPU2Active(bool* aIsGPU2Active) return NS_ERROR_FAILURE; } +nsresult +GfxInfo::FindMonitors(JSContext* aCx, JS::HandleObject aOutArray) +{ +#if defined(MOZ_WIDGET_GTK) + // No display in xpcshell mode. + if (!gdk_display_get_default()) { + return NS_OK; + } +#endif + + // Note: this doesn't support Xinerama. Two physical displays will be + // reported as one monitor covering the entire virtual screen. + Display* display = DefaultXDisplay(); + Screen* screen = DefaultScreenOfDisplay(display); + + JS::Rooted obj(aCx, JS_NewPlainObject(aCx)); + + JS::Rooted screenWidth(aCx, JS::Int32Value(WidthOfScreen(screen))); + JS_SetProperty(aCx, obj, "screenWidth", screenWidth); + + JS::Rooted screenHeight(aCx, JS::Int32Value(HeightOfScreen(screen))); + JS_SetProperty(aCx, obj, "screenHeight", screenHeight); + + JS::Rooted element(aCx, JS::ObjectValue(*obj)); + JS_SetElement(aCx, aOutArray, 0, element); + return NS_OK; +} + #ifdef DEBUG // Implement nsIGfxInfoDebug diff --git a/widget/GfxInfoX11.h b/widget/GfxInfoX11.h index 545f0736a1f..48ed81e06af 100644 --- a/widget/GfxInfoX11.h +++ b/widget/GfxInfoX11.h @@ -48,6 +48,8 @@ public: NS_IMETHOD_(void) GetData() override; + nsresult FindMonitors(JSContext* cx, JS::HandleObject array) override; + #ifdef DEBUG NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIGFXINFODEBUG