Bug 1608361 [Wayland] Use WaylandDisplayGet() to get and check Wayland display, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Mon, 13 Jan 2020 10:53:31 +0000
changeset 509937 84f82c379f4362419538f6fd7bda053bb2aee9ef
parent 509936 4c28141e68545858a01045d83893f1079917fe31
child 509938 24f9ca7b6c8b34fa5caf9a9b3982abd986ce8da8
push id104943
push userdluca@mozilla.com
push dateMon, 13 Jan 2020 11:38:47 +0000
treeherderautoland@84f82c379f43 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1608361
milestone74.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1608361 [Wayland] Use WaylandDisplayGet() to get and check Wayland display, r=jhorak Differential Revision: https://phabricator.services.mozilla.com/D59473
widget/gtk/WakeLockListener.cpp
--- a/widget/gtk/WakeLockListener.cpp
+++ b/widget/gtk/WakeLockListener.cpp
@@ -28,16 +28,17 @@
 
 #  define SESSION_MANAGER_TARGET "org.gnome.SessionManager"
 #  define SESSION_MANAGER_OBJECT "/org/gnome/SessionManager"
 #  define SESSION_MANAGER_INTERFACE "org.gnome.SessionManager"
 
 #  define DBUS_TIMEOUT (-1)
 
 using namespace mozilla;
+using namespace mozilla::widget;
 
 NS_IMPL_ISUPPORTS(WakeLockListener, nsIDOMMozWakeLockListener)
 
 StaticRefPtr<WakeLockListener> WakeLockListener::sSingleton;
 
 enum DesktopEnvironment {
   FreeDesktop,
   GNOME,
@@ -184,17 +185,19 @@ bool WakeLockTopic::CheckXScreenSaverSup
       sXssLib, "XScreenSaverQueryVersion");
   _XSSSuspend = (_XScreenSaverSuspend_fn)PR_FindFunctionSymbol(
       sXssLib, "XScreenSaverSuspend");
   if (!_XSSQueryExtension || !_XSSQueryVersion || !_XSSSuspend) {
     return false;
   }
 
   GdkDisplay* gDisplay = gdk_display_get_default();
-  if (!GDK_IS_X11_DISPLAY(gDisplay)) return false;
+  if (!gDisplay || !GDK_IS_X11_DISPLAY(gDisplay)) {
+    return false;
+  }
   Display* display = GDK_DISPLAY_XDISPLAY(gDisplay);
 
   int throwaway;
   if (!_XSSQueryExtension(display, &throwaway, &throwaway)) return false;
 
   int major, minor;
   if (!_XSSQueryVersion(display, &major, &minor)) return false;
   // Needs to be compatible with version 1.1
@@ -203,53 +206,48 @@ bool WakeLockTopic::CheckXScreenSaverSup
 
   return true;
 }
 
 /* static */
 bool WakeLockTopic::InhibitXScreenSaver(bool inhibit) {
   // Should only be called if CheckXScreenSaverSupport returns true.
   // There's a couple of safety checks here nonetheless.
-  if (!_XSSSuspend) return false;
+  if (!_XSSSuspend) {
+    return false;
+  }
   GdkDisplay* gDisplay = gdk_display_get_default();
-  if (!GDK_IS_X11_DISPLAY(gDisplay)) return false;
+  if (!gDisplay || !GDK_IS_X11_DISPLAY(gDisplay)) {
+    return false;
+  }
   Display* display = GDK_DISPLAY_XDISPLAY(gDisplay);
   _XSSSuspend(display, inhibit);
   return true;
 }
 
 #  endif
 
 #  if defined(MOZ_WAYLAND)
 
 /* static */
 bool WakeLockTopic::CheckWaylandIdleInhibitSupport() {
-  // Gtk is not guaranteed to be built with Wayland support, so we have to
-  // check for every non-Wayland backend instead of checking for Wayland
-  if (gfxPlatform::IsHeadless()) return false;
-
-  GdkDisplay* gDisplay = gdk_display_get_default();
-  if (!gDisplay) return false;
-  if (GDK_IS_X11_DISPLAY(gDisplay)) return false;
-
-  widget::nsWaylandDisplay* waylandDisplay =
-      widget::WaylandDisplayGet(gDisplay);
-  if (!waylandDisplay->GetIdleInhibitManager()) return false;
-
-  return true;
+  nsWaylandDisplay* waylandDisplay = WaylandDisplayGet();
+  return waylandDisplay && waylandDisplay->GetIdleInhibitManager() != nullptr;
 }
 
 bool WakeLockTopic::InhibitWaylandIdle() {
-  GdkDisplay* gDisplay = gdk_display_get_default();
-
-  widget::nsWaylandDisplay* waylandDisplay =
-      widget::WaylandDisplayGet(gDisplay);
+  nsWaylandDisplay* waylandDisplay = WaylandDisplayGet();
+  if (!waylandDisplay) {
+    return false;
+  }
 
   nsWindow* focusedWindow = nsWindow::GetFocusedWindow();
-  if (!focusedWindow) return false;
+  if (!focusedWindow) {
+    return false;
+  }
 
   UninhibitWaylandIdle();
 
   mWaylandInhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(
       waylandDisplay->GetIdleInhibitManager(),
       focusedWindow->GetWaylandSurface());
 
   return true;