diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index c85a50671c04..586c5199e9c5 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -4,6 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef MOZ_WIDGET_GTK +# include +# include +#endif + #include "BrowserChild.h" #include "ContentChild.h" #include "GeckoProfiler.h" @@ -281,9 +286,7 @@ #include "private/pprio.h" #ifdef MOZ_WIDGET_GTK -# include "mozilla/WidgetUtilsGtk.h" # include "nsAppRunner.h" -# include #endif #ifdef MOZ_CODE_COVERAGE @@ -724,7 +727,8 @@ bool ContentChild::Init(MessageLoop* aIOLoop, base::ProcessId aParentPid, #ifdef MOZ_X11 # ifdef MOZ_WIDGET_GTK - if (GdkIsX11Display() && !gfxPlatform::IsHeadless()) { + if (GDK_IS_X11_DISPLAY(gdk_display_get_default()) && + !gfxPlatform::IsHeadless()) { // Send the parent our X socket to act as a proxy reference for our X // resources. int xSocketFd = ConnectionNumber(DefaultXDisplay()); diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp index 4a54b78949ed..7b1ab80ee1dd 100644 --- a/dom/plugins/base/nsPluginHost.cpp +++ b/dom/plugins/base/nsPluginHost.cpp @@ -113,7 +113,8 @@ # include "winbase.h" #endif #if (MOZ_WIDGET_GTK) -# include "mozilla/WidgetUtilsGtk.h" +# include +# include #endif using namespace mozilla; @@ -288,8 +289,11 @@ nsPluginHost::nsPluginHost() Preferences::GetBool("plugin.override_internal_types", false); bool waylandBackend = false; -#if defined(MOZ_WIDGET_GTK) - waylandBackend = mozilla::widget::GdkIsWaylandDisplay(); +#if defined(MOZ_WIDGET_GTK) && defined(MOZ_X11) + GdkDisplay* display = gdk_display_get_default(); + if (display) { + waylandBackend = !GDK_IS_X11_DISPLAY(display); + } #endif mPluginsDisabled = Preferences::GetBool("plugin.disable", false) || waylandBackend; diff --git a/dom/plugins/ipc/PluginModuleChild.cpp b/dom/plugins/ipc/PluginModuleChild.cpp index e29b13917672..81eb8467d468 100644 --- a/dom/plugins/ipc/PluginModuleChild.cpp +++ b/dom/plugins/ipc/PluginModuleChild.cpp @@ -13,7 +13,6 @@ #include "mozilla/ipc/MessageChannel.h" #ifdef MOZ_WIDGET_GTK -# include "mozilla/WidgetUtilsGtk.h" # include # include #endif @@ -1552,7 +1551,7 @@ NPError PluginModuleChild::DoNP_Initialize(const PluginSettings& aSettings) { #ifdef MOZ_X11 # ifdef MOZ_WIDGET_GTK - if (!GdkIsX11Display()) { + if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) { // We don't support NPAPI plugins on Wayland. return NPERR_GENERIC_ERROR; } diff --git a/gfx/gl/GLContextProviderEGL.cpp b/gfx/gl/GLContextProviderEGL.cpp index 60578735c7ab..52bd92742b96 100644 --- a/gfx/gl/GLContextProviderEGL.cpp +++ b/gfx/gl/GLContextProviderEGL.cpp @@ -78,14 +78,32 @@ #if defined(MOZ_WIDGET_GTK) # include "mozilla/widget/GtkCompositorWidget.h" -# include "mozilla/WidgetUtilsGtk.h" # if defined(MOZ_WAYLAND) +# include # include # include # define MOZ_GTK_WAYLAND 1 # endif #endif +inline bool IsWaylandDisplay() { +#ifdef MOZ_GTK_WAYLAND + return gdk_display_get_default() && + GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default()); +#else + return false; +#endif +} + +inline bool IsX11Display() { +#ifdef MOZ_WIDGET_GTK + return gdk_display_get_default() && + GDK_IS_X11_DISPLAY(gdk_display_get_default()); +#else + return false; +#endif +} + struct wl_egl_window; using namespace mozilla::gfx; @@ -110,17 +128,15 @@ class WaylandGLSurface { static nsDataHashtable, WaylandGLSurface*> sWaylandGLSurface; void DeleteWaylandGLSurface(EGLSurface surface) { -# ifdef MOZ_GTK_WAYLAND // We're running on Wayland which means our EGLSurface may // have attached Wayland backend data which must be released. - if (GdkIsWaylandDisplay()) { + if (IsWaylandDisplay()) { auto entry = sWaylandGLSurface.Lookup(surface); if (entry) { delete entry.Data(); entry.Remove(); } } -# endif } #endif @@ -253,10 +269,10 @@ already_AddRefed GLContextEGLFactory::CreateImpl( } int visualID = 0; + if (IsX11Display()) { #ifdef MOZ_X11 - GdkDisplay* gdkDisplay = gdk_display_get_default(); - if (GdkIsX11Display(gdkDisplay)) { - auto* display = GDK_DISPLAY_XDISPLAY(gdkDisplay); + GdkDisplay* gdkDisplay = gdk_display_get_default(); + auto display = gdkDisplay ? GDK_DISPLAY_XDISPLAY(gdkDisplay) : nullptr; if (display) { XWindowAttributes windowAttrs; if (!XGetWindowAttributes(display, (Window)aWindow, &windowAttrs)) { @@ -265,8 +281,8 @@ already_AddRefed GLContextEGLFactory::CreateImpl( } visualID = XVisualIDFromVisual(windowAttrs.visual); } - } #endif + } bool doubleBuffered = true; @@ -330,12 +346,10 @@ already_AddRefed GLContextEGLFactory::CreateImpl( gl->MakeCurrent(); gl->SetIsDoubleBuffered(doubleBuffered); -#ifdef MOZ_GTK_WAYLAND - if (surface && GdkIsWaylandDisplay()) { + if (surface && IsWaylandDisplay()) { // Make eglSwapBuffers() non-blocking on wayland egl->fSwapInterval(0); } -#endif if (aWebRender && egl->mLib->IsANGLE()) { MOZ_ASSERT(doubleBuffered); egl->fSwapInterval(0); @@ -515,12 +529,10 @@ bool GLContextEGL::RenewSurface(CompositorWidget* aWidget) { } const bool ok = MakeCurrent(true); MOZ_ASSERT(ok); -#ifdef MOZ_GTK_WAYLAND - if (mSurface && GdkIsWaylandDisplay()) { + if (mSurface && IsWaylandDisplay()) { // Make eglSwapBuffers() non-blocking on wayland mEgl->fSwapInterval(0); } -#endif return ok; } @@ -1043,14 +1055,11 @@ EGLSurface GLContextEGL::CreateCompatibleSurface(void* aWindow) const { static void FillContextAttribs(bool es3, bool useGles, nsTArray* out) { out->AppendElement(LOCAL_EGL_SURFACE_TYPE); -#ifdef MOZ_GTK_WAYLAND - if (GdkIsWaylandDisplay()) { + if (IsWaylandDisplay()) { // Wayland on desktop does not support PBuffer or FBO. // We create a dummy wl_egl_window instead. out->AppendElement(LOCAL_EGL_WINDOW_BIT); - } else -#endif - { + } else { out->AppendElement(LOCAL_EGL_PBUFFER_BIT); } @@ -1166,12 +1175,9 @@ RefPtr GLContextEGL::CreateEGLPBufferOffscreenContextImpl( mozilla::gfx::IntSize pbSize(size); EGLSurface surface = nullptr; -#ifdef MOZ_GTK_WAYLAND - if (GdkIsWaylandDisplay()) { + if (IsWaylandDisplay()) { surface = GLContextEGL::CreateWaylandBufferSurface(*egl, config, pbSize); - } else -#endif - { + } else { surface = GLContextEGL::CreatePBufferSurfaceTryingPowerOfTwo( *egl, config, LOCAL_EGL_NONE, pbSize); } diff --git a/gfx/gl/GLContextProviderWayland.cpp b/gfx/gl/GLContextProviderWayland.cpp index 26982106bcc6..4f7c15380c27 100644 --- a/gfx/gl/GLContextProviderWayland.cpp +++ b/gfx/gl/GLContextProviderWayland.cpp @@ -4,7 +4,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifdef MOZ_WIDGET_GTK -# include "mozilla/WidgetUtilsGtk.h" +# include +# include #endif #include "GLContextProvider.h" @@ -20,7 +21,7 @@ static class GLContextProviderEGL sGLContextProviderEGL; already_AddRefed GLContextProviderWayland::CreateForCompositorWidget( CompositorWidget* aCompositorWidget, bool aWebRender, bool aForceAccelerated) { - if (GdkIsX11Display()) { + if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { return sGLContextProviderX11.CreateForCompositorWidget( aCompositorWidget, aWebRender, aForceAccelerated); } else { @@ -32,7 +33,7 @@ already_AddRefed GLContextProviderWayland::CreateForCompositorWidget( /*static*/ already_AddRefed GLContextProviderWayland::CreateHeadless( const GLContextCreateDesc& desc, nsACString* const out_failureId) { - if (GdkIsX11Display()) { + if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { return sGLContextProviderX11.CreateHeadless(desc, out_failureId); } else { return sGLContextProviderEGL.CreateHeadless(desc, out_failureId); @@ -41,7 +42,7 @@ already_AddRefed GLContextProviderWayland::CreateHeadless( /*static*/ GLContext* GLContextProviderWayland::GetGlobalContext() { - if (GdkIsX11Display()) { + if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { return sGLContextProviderX11.GetGlobalContext(); } else { return sGLContextProviderEGL.GetGlobalContext(); @@ -50,7 +51,7 @@ GLContext* GLContextProviderWayland::GetGlobalContext() { /*static*/ void GLContextProviderWayland::Shutdown() { - if (GdkIsX11Display()) { + if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { sGLContextProviderX11.Shutdown(); } else { sGLContextProviderEGL.Shutdown(); diff --git a/gfx/gl/GLLibraryEGL.cpp b/gfx/gl/GLLibraryEGL.cpp index a385ef58bb97..02c93f8381c9 100644 --- a/gfx/gl/GLLibraryEGL.cpp +++ b/gfx/gl/GLLibraryEGL.cpp @@ -37,12 +37,13 @@ #include "GLReadTexImageHelper.h" #include "ScopedGLHelpers.h" #ifdef MOZ_WIDGET_GTK -# include "mozilla/WidgetUtilsGtk.h" +# include # ifdef MOZ_WAYLAND +# include +# include # include "mozilla/widget/nsWaylandDisplay.h" # endif // MOZ_WIDGET_GTK -# include -#endif // MOZ_WAYLAND +#endif // MOZ_WAYLAND namespace mozilla { namespace gl { @@ -783,7 +784,7 @@ std::shared_ptr GLLibraryEGL::CreateDisplay( #ifdef MOZ_WAYLAND // Some drivers doesn't support EGL_DEFAULT_DISPLAY GdkDisplay* gdkDisplay = gdk_display_get_default(); - if (widget::GdkIsWaylandDisplay(gdkDisplay)) { + if (gdkDisplay && !GDK_IS_X11_DISPLAY(gdkDisplay)) { nativeDisplay = widget::WaylandDisplayGetWLDisplay(gdkDisplay); if (!nativeDisplay) { NS_WARNING("Failed to get wl_display."); diff --git a/gfx/src/X11Util.h b/gfx/src/X11Util.h index cfa86bec5b0b..fc583fb6d420 100644 --- a/gfx/src/X11Util.h +++ b/gfx/src/X11Util.h @@ -12,7 +12,6 @@ #if defined(MOZ_WIDGET_GTK) # include # include -# include "mozilla/WidgetUtilsGtk.h" # include "X11UndefineNone.h" #else # error Unknown toolkit @@ -29,7 +28,7 @@ namespace mozilla { inline Display* DefaultXDisplay() { #if defined(MOZ_WIDGET_GTK) GdkDisplay* gdkDisplay = gdk_display_get_default(); - if (mozilla::widget::GdkIsX11Display(gdkDisplay)) { + if (GDK_IS_X11_DISPLAY(gdkDisplay)) { return GDK_DISPLAY_XDISPLAY(gdkDisplay); } #endif diff --git a/gfx/thebes/gfxFcPlatformFontList.cpp b/gfx/thebes/gfxFcPlatformFontList.cpp index c6feec8642ce..b647a619ac9a 100644 --- a/gfx/thebes/gfxFcPlatformFontList.cpp +++ b/gfx/thebes/gfxFcPlatformFontList.cpp @@ -39,7 +39,6 @@ #ifdef MOZ_WIDGET_GTK # include # include "gfxPlatformGtk.h" -# include "mozilla/WidgetUtilsGtk.h" #endif #ifdef MOZ_X11 @@ -717,7 +716,7 @@ static void PreparePattern(FcPattern* aPattern, bool aIsPrinterFont) { int lcdfilter; if (FcPatternGet(aPattern, FC_LCD_FILTER, 0, &value) == FcResultNoMatch) { GdkDisplay* dpy = gdk_display_get_default(); - if (mozilla::widget::GdkIsX11Display(dpy) && + if (GDK_IS_X11_DISPLAY(dpy) && GetXftInt(GDK_DISPLAY_XDISPLAY(dpy), "lcdfilter", &lcdfilter)) { FcPatternAddInteger(aPattern, FC_LCD_FILTER, lcdfilter); } diff --git a/gfx/thebes/gfxPlatformGtk.cpp b/gfx/thebes/gfxPlatformGtk.cpp index 86d0e979d8a9..93ada3d9f996 100644 --- a/gfx/thebes/gfxPlatformGtk.cpp +++ b/gfx/thebes/gfxPlatformGtk.cpp @@ -97,7 +97,9 @@ gfxPlatformGtk::gfxPlatformGtk() { } mMaxGenericSubstitutions = UNINITIALIZED_VALUE; - mIsX11Display = gfxPlatform::IsHeadless() ? false : GdkIsX11Display(); + mIsX11Display = gfxPlatform::IsHeadless() + ? false + : GDK_IS_X11_DISPLAY(gdk_display_get_default()); if (XRE_IsParentProcess()) { #ifdef MOZ_X11 if (mIsX11Display && mozilla::Preferences::GetBool("gfx.xrender.enabled")) { diff --git a/gfx/webrender_bindings/RenderCompositorEGL.cpp b/gfx/webrender_bindings/RenderCompositorEGL.cpp index b35b30929830..9bc88bde148b 100644 --- a/gfx/webrender_bindings/RenderCompositorEGL.cpp +++ b/gfx/webrender_bindings/RenderCompositorEGL.cpp @@ -18,8 +18,9 @@ #include "mozilla/widget/CompositorWidget.h" #ifdef MOZ_WAYLAND -# include "mozilla/WidgetUtilsGtk.h" # include "mozilla/widget/GtkCompositorWidget.h" +# include +# include #endif #ifdef MOZ_WIDGET_ANDROID @@ -36,7 +37,8 @@ namespace mozilla::wr { UniquePtr RenderCompositorEGL::Create( RefPtr aWidget, nsACString& aError) { #ifdef MOZ_WAYLAND - if (!mozilla::widget::GdkIsWaylandDisplay()) { + if (!gdk_display_get_default() || + GDK_IS_X11_DISPLAY(gdk_display_get_default())) { return nullptr; } #endif diff --git a/gfx/webrender_bindings/RenderThread.cpp b/gfx/webrender_bindings/RenderThread.cpp index 4f031f27adbb..a59d648ff920 100644 --- a/gfx/webrender_bindings/RenderThread.cpp +++ b/gfx/webrender_bindings/RenderThread.cpp @@ -41,7 +41,7 @@ #endif #ifdef MOZ_WIDGET_GTK -# include "mozilla/WidgetUtilsGtk.h" +# include #endif #ifdef MOZ_WAYLAND @@ -1125,7 +1125,8 @@ static already_AddRefed CreateGLContext(nsACString& aError) { #elif defined(MOZ_WIDGET_ANDROID) gl = CreateGLContextEGL(); #elif defined(MOZ_WAYLAND) - if (mozilla::widget::GdkIsWaylandDisplay()) { + if (gdk_display_get_default() && + !GDK_IS_X11_DISPLAY(gdk_display_get_default())) { gl = CreateGLContextEGL(); } #elif XP_MACOSX diff --git a/layout/xul/nsMenuPopupFrame.cpp b/layout/xul/nsMenuPopupFrame.cpp index da1b56fdae35..192113d37c40 100644 --- a/layout/xul/nsMenuPopupFrame.cpp +++ b/layout/xul/nsMenuPopupFrame.cpp @@ -58,7 +58,9 @@ #include "mozilla/dom/KeyboardEventBinding.h" #include #ifdef MOZ_WAYLAND -# include "mozilla/WidgetUtilsGtk.h" +# include +# include +# include #endif /* MOZ_WAYLAND */ #include "X11UndefineNone.h" @@ -544,7 +546,8 @@ void nsMenuPopupFrame::LayoutPopup(nsBoxLayoutState& aState, prefSize = XULBoundsCheck(minSize, prefSize, maxSize); #ifdef MOZ_WAYLAND - static bool inWayland = mozilla::widget::GdkIsWaylandDisplay(); + static bool inWayland = gdk_display_get_default() && + !GDK_IS_X11_DISPLAY(gdk_display_get_default()); #else static bool inWayland = false; #endif @@ -1447,7 +1450,8 @@ nsresult nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame, // the popup's margin. #ifdef MOZ_WAYLAND - if (mozilla::widget::GdkIsWaylandDisplay()) { + if (gdk_display_get_default() && + !GDK_IS_X11_DISPLAY(gdk_display_get_default())) { screenPoint = nsPoint(anchorRect.x, anchorRect.y); mAnchorRect = anchorRect; } @@ -1584,7 +1588,8 @@ nsresult nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame, // because we don't know the absolute position of the window on the // screen. #ifdef MOZ_WAYLAND - static bool inWayland = mozilla::widget::GdkIsWaylandDisplay(); + static bool inWayland = gdk_display_get_default() && + !GDK_IS_X11_DISPLAY(gdk_display_get_default()); #else static bool inWayland = false; #endif @@ -1724,7 +1729,8 @@ LayoutDeviceIntRect nsMenuPopupFrame::GetConstraintRect( nsCOMPtr sm( do_GetService("@mozilla.org/gfx/screenmanager;1")); #ifdef MOZ_WAYLAND - static bool inWayland = mozilla::widget::GdkIsWaylandDisplay(); + static bool inWayland = gdk_display_get_default() && + !GDK_IS_X11_DISPLAY(gdk_display_get_default()); #else static bool inWayland = false; #endif diff --git a/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp b/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp index a43b39ff0be0..3083ebc4a129 100644 --- a/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp +++ b/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp @@ -37,8 +37,11 @@ #endif #ifdef MOZ_WIDGET_GTK -# include "mozilla/WidgetUtilsGtk.h" # include +# ifdef MOZ_WAYLAND +# include +# include +# endif #endif #include @@ -504,9 +507,13 @@ void SandboxBrokerPolicyFactory::InitContentPolicy() { #if defined(MOZ_WIDGET_GTK) && defined(MOZ_X11) // Allow local X11 connections, for Primus and VirtualGL to contact // the secondary X server. No exception for Wayland. - if (mozilla::widget::GdkIsX11Display()) { +# if defined(MOZ_WAYLAND) + if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { policy->AddPrefix(SandboxBroker::MAY_CONNECT, "/tmp/.X11-unix/X"); } +# else + policy->AddPrefix(SandboxBroker::MAY_CONNECT, "/tmp/.X11-unix/X"); +# endif if (const auto xauth = PR_GetEnv("XAUTHORITY")) { policy->AddPath(rdonly, xauth); } diff --git a/security/sandbox/linux/launch/SandboxLaunch.cpp b/security/sandbox/linux/launch/SandboxLaunch.cpp index 1efcd3846696..6f00bd41727b 100644 --- a/security/sandbox/linux/launch/SandboxLaunch.cpp +++ b/security/sandbox/linux/launch/SandboxLaunch.cpp @@ -47,7 +47,6 @@ # ifndef MOZ_WIDGET_GTK # error "Unknown toolkit" # endif -# include "mozilla/WidgetUtilsGtk.h" # include # include # include "X11UndefineNone.h" @@ -77,7 +76,7 @@ static bool IsDisplayLocal() { if (NS_WARN_IF(display == nullptr)) { return false; } - if (mozilla::widget::GdkIsX11Display(display)) { + if (GDK_IS_X11_DISPLAY(display)) { const int xSocketFd = ConnectionNumber(GDK_DISPLAY_XDISPLAY(display)); if (NS_WARN_IF(xSocketFd < 0)) { return false; diff --git a/toolkit/components/remote/nsRemoteService.cpp b/toolkit/components/remote/nsRemoteService.cpp index 289fa506f4b2..7da905a4112a 100644 --- a/toolkit/components/remote/nsRemoteService.cpp +++ b/toolkit/components/remote/nsRemoteService.cpp @@ -11,7 +11,6 @@ #endif #ifdef MOZ_WIDGET_GTK -# include "mozilla/WidgetUtilsGtk.h" # include "nsGTKRemoteServer.h" # include "nsXRemoteClient.h" # ifdef MOZ_ENABLE_DBUS @@ -104,7 +103,7 @@ RemoteResult nsRemoteService::StartClient(const char* aDesktopStartupID) { UniquePtr client; #ifdef MOZ_WIDGET_GTK - bool useX11Remote = mozilla::widget::GdkIsX11Display(); + bool useX11Remote = GDK_IS_X11_DISPLAY(gdk_display_get_default()); # if defined(MOZ_ENABLE_DBUS) if (!useX11Remote || getenv(DBUS_REMOTE_ENV)) { @@ -153,7 +152,7 @@ void nsRemoteService::StartupServer() { } #ifdef MOZ_WIDGET_GTK - bool useX11Remote = mozilla::widget::GdkIsX11Display(); + bool useX11Remote = GDK_IS_X11_DISPLAY(gdk_display_get_default()); # if defined(MOZ_ENABLE_DBUS) if (!useX11Remote || getenv(DBUS_REMOTE_ENV)) { diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index f57ac38333cd..acbc52ffcc9e 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -303,7 +303,6 @@ nsString gProcessStartupShortcut; #endif #if defined(MOZ_WIDGET_GTK) -# include "mozilla/WidgetUtilsGtk.h" # include # if defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING) # define CLEANUP_MEMORY 1 @@ -4462,11 +4461,11 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) { gdk_display_manager_set_default_display(gdk_display_manager_get(), mGdkDisplay); if (saveDisplayArg) { - if (GdkIsX11Display(mGdkDisplay)) { + if (GDK_IS_X11_DISPLAY(mGdkDisplay)) { SaveWordToEnv("DISPLAY", nsDependentCString(display_name)); } # ifdef MOZ_WAYLAND - else if (GdkIsWaylandDisplay(mGdkDisplay)) { + else if (!GDK_IS_X11_DISPLAY(mGdkDisplay)) { SaveWordToEnv("WAYLAND_DISPLAY", nsDependentCString(display_name)); } # endif diff --git a/widget/GfxInfoX11.cpp b/widget/GfxInfoX11.cpp index 5fc96d592b8d..7ef60878ad60 100644 --- a/widget/GfxInfoX11.cpp +++ b/widget/GfxInfoX11.cpp @@ -26,7 +26,6 @@ #include #ifdef MOZ_WAYLAND -# include "mozilla/WidgetUtilsGtk.h" # include "mozilla/widget/nsWaylandDisplay.h" # include "mozilla/widget/DMABufLibWrapper.h" #endif @@ -460,7 +459,8 @@ void GfxInfo::GetData() { mAdapterDescription.Assign(glRenderer); #ifdef MOZ_WAYLAND - mIsWayland = GdkIsWaylandDisplay(); + mIsWayland = gdk_display_get_default() && + !GDK_IS_X11_DISPLAY(gdk_display_get_default()); #endif // Make a best effort guess at whether or not we are using the XWayland compat diff --git a/widget/ScreenManager.cpp b/widget/ScreenManager.cpp index 7c8bab31c3af..90324ebca47b 100644 --- a/widget/ScreenManager.cpp +++ b/widget/ScreenManager.cpp @@ -12,7 +12,9 @@ #include "mozilla/Logging.h" #include "mozilla/StaticPtr.h" #ifdef MOZ_WAYLAND -# include "mozilla/WidgetUtilsGtk.h" +# include +# include +# include #endif /* MOZ_WAYLAND */ static mozilla::LazyLogModule sScreenLog("WidgetScreen"); @@ -107,7 +109,8 @@ NS_IMETHODIMP ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight, nsIScreen** aOutScreen) { #if defined(MOZ_WAYLAND) && defined(MOZ_LOGGING) - static bool inWayland = mozilla::widget::GdkIsWaylandDisplay(); + static bool inWayland = gdk_display_get_default() && + !GDK_IS_X11_DISPLAY(gdk_display_get_default()); if (inWayland) { MOZ_LOG(sScreenLog, LogLevel::Warning, ("Getting screen in wayland, primary display will be returned.")); diff --git a/widget/gtk/DMABufLibWrapper.cpp b/widget/gtk/DMABufLibWrapper.cpp index 95e8e52d0224..fff0c4f54a91 100644 --- a/widget/gtk/DMABufLibWrapper.cpp +++ b/widget/gtk/DMABufLibWrapper.cpp @@ -10,7 +10,9 @@ #include "mozilla/StaticPrefs_widget.h" #include "mozilla/StaticPrefs_media.h" #include "mozilla/gfx/gfxVars.h" -#include "WidgetUtilsGtk.h" + +#include +#include #include #include @@ -169,7 +171,8 @@ nsDMABufDevice::nsDMABufDevice() mARGBFormat({true, true, GBM_FORMAT_ARGB8888, nullptr, 0}), mGbmDevice(nullptr), mGbmFd(-1) { - if (GdkIsWaylandDisplay()) { + if (gdk_display_get_default() && + !GDK_IS_X11_DISPLAY(gdk_display_get_default())) { wl_display* display = WaylandDisplayGetWLDisplay(); mRegistry = (void*)wl_display_get_registry(display); wl_registry_add_listener((wl_registry*)mRegistry, ®istry_listener, this); diff --git a/widget/gtk/ScreenHelperGTK.cpp b/widget/gtk/ScreenHelperGTK.cpp index 52f0100ce8fe..67410b25a1fb 100644 --- a/widget/gtk/ScreenHelperGTK.cpp +++ b/widget/gtk/ScreenHelperGTK.cpp @@ -18,7 +18,6 @@ #include "gfxPlatformGtk.h" #include "mozilla/dom/DOMTypes.h" #include "mozilla/Logging.h" -#include "mozilla/WidgetUtilsGtk.h" #include "nsGtkUtils.h" #include "nsTArray.h" @@ -94,7 +93,7 @@ ScreenHelperGTK::ScreenHelperGTK() G_CALLBACK(screen_resolution_changed), this); #ifdef MOZ_X11 gdk_window_add_filter(mRootWindow, root_window_event_filter, this); - if (GdkIsX11Display()) { + if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { mNetWorkareaAtom = XInternAtom(GDK_WINDOW_XDISPLAY(mRootWindow), "_NET_WORKAREA", X11False); } @@ -151,7 +150,8 @@ static already_AddRefed MakeScreen(GdkScreen* aScreen, // Use per-monitor scaling factor in gtk/wayland, or 1.0 otherwise. DesktopToLayoutDeviceScale contentsScale(1.0); #ifdef MOZ_WAYLAND - if (GdkIsWaylandDisplay()) { + GdkDisplay* gdkDisplay = gdk_display_get_default(); + if (!GDK_IS_X11_DISPLAY(gdkDisplay)) { contentsScale.scale = gdkScaleFactor; } #endif diff --git a/widget/gtk/WakeLockListener.cpp b/widget/gtk/WakeLockListener.cpp index c14cf6b7fe5e..df76a69e4bbf 100644 --- a/widget/gtk/WakeLockListener.cpp +++ b/widget/gtk/WakeLockListener.cpp @@ -12,8 +12,6 @@ # include # include -# include "WidgetUtilsGtk.h" - # if defined(MOZ_X11) # include "gfxPlatformGtk.h" # include "prlink.h" @@ -199,7 +197,7 @@ bool WakeLockTopic::CheckXScreenSaverSupport() { } GdkDisplay* gDisplay = gdk_display_get_default(); - if (!GdkIsX11Display(gDisplay)) { + if (!gDisplay || !GDK_IS_X11_DISPLAY(gDisplay)) { return false; } Display* display = GDK_DISPLAY_XDISPLAY(gDisplay); @@ -224,7 +222,7 @@ bool WakeLockTopic::InhibitXScreenSaver(bool inhibit) { return false; } GdkDisplay* gDisplay = gdk_display_get_default(); - if (!GdkIsX11Display(gDisplay)) { + if (!gDisplay || !GDK_IS_X11_DISPLAY(gDisplay)) { return false; } Display* display = GDK_DISPLAY_XDISPLAY(gDisplay); diff --git a/widget/gtk/WidgetUtilsGtk.cpp b/widget/gtk/WidgetUtilsGtk.cpp index 66e764e26799..a0299bdf1419 100644 --- a/widget/gtk/WidgetUtilsGtk.cpp +++ b/widget/gtk/WidgetUtilsGtk.cpp @@ -6,7 +6,6 @@ #include "WidgetUtilsGtk.h" #include "nsWindow.h" #include -#include namespace mozilla { @@ -48,31 +47,6 @@ bool IsMainWindowTransparent() { return nsWindow::IsToplevelWindowTransparent(); } -// We avoid linking gdk_*_display_get_type directly in order to avoid a runtime -// dependency on GTK built with both backends. Other X11- and Wayland-specific -// functions get stubbed out by libmozgtk and crash when called, but those -// should only be called when the matching backend is already in use. - -bool GdkIsWaylandDisplay(GdkDisplay* display) { - static auto sGdkWaylandDisplayGetType = - (GType(*)())dlsym(RTLD_DEFAULT, "gdk_wayland_display_get_type"); - return sGdkWaylandDisplayGetType && - G_TYPE_CHECK_INSTANCE_TYPE(display, sGdkWaylandDisplayGetType()); -} - -bool GdkIsX11Display(GdkDisplay* display) { - static auto sGdkX11DisplayGetType = - (GType(*)())dlsym(RTLD_DEFAULT, "gdk_x11_display_get_type"); - return sGdkX11DisplayGetType && - G_TYPE_CHECK_INSTANCE_TYPE(display, sGdkX11DisplayGetType()); -} - -bool GdkIsWaylandDisplay() { - return GdkIsWaylandDisplay(gdk_display_get_default()); -} - -bool GdkIsX11Display() { return GdkIsX11Display(gdk_display_get_default()); } - } // namespace widget } // namespace mozilla diff --git a/widget/gtk/WidgetUtilsGtk.h b/widget/gtk/WidgetUtilsGtk.h index bc3393644b52..5ede9aa52026 100644 --- a/widget/gtk/WidgetUtilsGtk.h +++ b/widget/gtk/WidgetUtilsGtk.h @@ -7,7 +7,6 @@ #define WidgetUtilsGtk_h__ #include -#include namespace mozilla { namespace widget { @@ -20,12 +19,6 @@ class WidgetUtilsGTK { bool IsMainWindowTransparent(); -bool GdkIsWaylandDisplay(GdkDisplay* display); -bool GdkIsX11Display(GdkDisplay* display); - -bool GdkIsWaylandDisplay(); -bool GdkIsX11Display(); - } // namespace widget } // namespace mozilla diff --git a/widget/gtk/compat/gdk/gdkx.h b/widget/gtk/compat/gdk/gdkx.h index 7b0718f3cb9f..3d13c88b4d1c 100644 --- a/widget/gtk/compat/gdk/gdkx.h +++ b/widget/gtk/compat/gdk/gdkx.h @@ -33,6 +33,10 @@ static inline Window gdk_x11_window_get_xid(GdkWindow* window) { return (GDK_WINDOW_XWINDOW(window)); } +#ifndef GDK_IS_X11_DISPLAY +# define GDK_IS_X11_DISPLAY(a) (true) +#endif + #if !GTK_CHECK_VERSION(2, 24, 0) # undef gdk_x11_set_sm_client_id static inline void gdk_x11_set_sm_client_id(const gchar* sm_client_id) { diff --git a/widget/gtk/mozgtk/mozgtk.c b/widget/gtk/mozgtk/mozgtk.c index 81f1c0fbc40d..0d376188a7f6 100644 --- a/widget/gtk/mozgtk/mozgtk.c +++ b/widget/gtk/mozgtk/mozgtk.c @@ -555,6 +555,8 @@ STUB(gdk_window_get_frame_clock) STUB(gdk_window_get_type) STUB(gdk_window_set_opaque_region) STUB(gdk_x11_window_get_xid) +STUB(gdk_x11_display_get_type) +STUB(gdk_wayland_display_get_type) STUB(gdk_wayland_display_get_wl_compositor) STUB(gdk_wayland_display_get_wl_display) STUB(gdk_wayland_window_get_wl_surface) diff --git a/widget/gtk/nsClipboardX11.cpp b/widget/gtk/nsClipboardX11.cpp index 652b2396be47..0439c2e68c41 100644 --- a/widget/gtk/nsClipboardX11.cpp +++ b/widget/gtk/nsClipboardX11.cpp @@ -18,7 +18,6 @@ #include "nsStringStream.h" #include "mozilla/RefPtr.h" #include "mozilla/TimeStamp.h" -#include "WidgetUtilsGtk.h" #include @@ -106,7 +105,7 @@ bool nsRetrievalContextX11::WaitForX11Content() { GdkDisplay* gdkDisplay = gdk_display_get_default(); // gdk_display_get_default() returns null on headless - if (mozilla::widget::GdkIsX11Display(gdkDisplay)) { + if (gdkDisplay && GDK_IS_X11_DISPLAY(gdkDisplay)) { Display* xDisplay = GDK_DISPLAY_XDISPLAY(gdkDisplay); checkEventContext context; context.cbWidget = nullptr; diff --git a/widget/gtk/nsGtkKeyUtils.cpp b/widget/gtk/nsGtkKeyUtils.cpp index c8b18e43c745..67d1cea404b7 100644 --- a/widget/gtk/nsGtkKeyUtils.cpp +++ b/widget/gtk/nsGtkKeyUtils.cpp @@ -19,7 +19,6 @@ #include "X11UndefineNone.h" #include "IMContextWrapper.h" #include "WidgetUtils.h" -#include "WidgetUtilsGtk.h" #include "keysym2ucs.h" #include "nsContentUtils.h" #include "nsGtkUtils.h" @@ -1762,7 +1761,7 @@ void KeymapWrapper::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent, // key release events, the result isn't what we want. guint modifierState = aGdkKeyEvent->state; GdkDisplay* gdkDisplay = gdk_display_get_default(); - if (aGdkKeyEvent->is_modifier && GdkIsX11Display(gdkDisplay)) { + if (aGdkKeyEvent->is_modifier && GDK_IS_X11_DISPLAY(gdkDisplay)) { Display* display = gdk_x11_display_get_xdisplay(gdkDisplay); if (XEventsQueued(display, QueuedAfterReading)) { XEvent nextEvent; diff --git a/widget/gtk/nsUserIdleServiceGTK.cpp b/widget/gtk/nsUserIdleServiceGTK.cpp index 884d52a6cab9..882ded8cade6 100644 --- a/widget/gtk/nsUserIdleServiceGTK.cpp +++ b/widget/gtk/nsUserIdleServiceGTK.cpp @@ -11,7 +11,6 @@ #include "nsDebug.h" #include "prlink.h" #include "mozilla/Logging.h" -#include "WidgetUtilsGtk.h" using mozilla::LogLevel; @@ -31,7 +30,8 @@ static _XScreenSaverAllocInfo_fn _XSSAllocInfo = nullptr; static _XScreenSaverQueryInfo_fn _XSSQueryInfo = nullptr; static void Initialize() { - if (!mozilla::widget::GdkIsX11Display()) { + if (!gdk_display_get_default() || + !GDK_IS_X11_DISPLAY(gdk_display_get_default())) { return; } diff --git a/widget/gtk/nsWaylandDisplay.cpp b/widget/gtk/nsWaylandDisplay.cpp index 063228cf33f8..310917a27bf2 100644 --- a/widget/gtk/nsWaylandDisplay.cpp +++ b/widget/gtk/nsWaylandDisplay.cpp @@ -11,7 +11,6 @@ #include "base/task.h" // for NewRunnableMethod, etc #include "mozilla/StaticMutex.h" #include "mozilla/StaticPrefs_widget.h" -#include "WidgetUtilsGtk.h" namespace mozilla { namespace widget { @@ -75,7 +74,7 @@ RefPtr WaylandDisplayGet(GdkDisplay* aGdkDisplay) { wl_display* WaylandDisplayGetWLDisplay(GdkDisplay* aGdkDisplay) { if (!aGdkDisplay) { aGdkDisplay = gdk_display_get_default(); - if (!GdkIsWaylandDisplay(aGdkDisplay)) { + if (!aGdkDisplay || GDK_IS_X11_DISPLAY(aGdkDisplay)) { return nullptr; } } diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 0e281c6ca1f3..b0d239a48b26 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -50,7 +50,6 @@ #include "nsGtkKeyUtils.h" #include "nsGtkCursors.h" #include "ScreenHelperGTK.h" -#include "WidgetUtilsGtk.h" #include #include @@ -2172,7 +2171,7 @@ guint32 nsWindow::GetLastUserInputTime() { // button and key releases. Therefore use the most recent of // gdk_x11_display_get_user_time and the last time that we have seen. GdkDisplay* gdkDisplay = gdk_display_get_default(); - guint32 timestamp = GdkIsX11Display(gdkDisplay) + guint32 timestamp = GDK_IS_X11_DISPLAY(gdkDisplay) ? gdk_x11_display_get_user_time(gdkDisplay) : gtk_get_current_event_time(); @@ -2490,7 +2489,7 @@ void* nsWindow::GetNativeData(uint32_t aDataType) { case NS_NATIVE_DISPLAY: { #ifdef MOZ_X11 GdkDisplay* gdkDisplay = gdk_display_get_default(); - if (GdkIsX11Display(gdkDisplay)) { + if (gdkDisplay && GDK_IS_X11_DISPLAY(gdkDisplay)) { return GDK_DISPLAY_XDISPLAY(gdkDisplay); } #endif /* MOZ_X11 */ @@ -7065,7 +7064,7 @@ static gboolean key_press_event_cb(GtkWidget* widget, GdkEventKey* event) { # define KeyPress 2 # endif GdkDisplay* gdkDisplay = gtk_widget_get_display(widget); - if (GdkIsX11Display(gdkDisplay)) { + if (GDK_IS_X11_DISPLAY(gdkDisplay)) { Display* dpy = GDK_DISPLAY_XDISPLAY(gdkDisplay); while (XPending(dpy)) { XEvent next_event; @@ -8174,7 +8173,7 @@ nsWindow::GtkWindowDecoration nsWindow::GetSystemGtkWindowDecoration() { // nsWindow::GetSystemGtkWindowDecoration can be called from various threads // so we can't use gfxPlatformGtk here. - if (GdkIsWaylandDisplay()) { + if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) { sGtkWindowDecoration = GTK_DECORATION_CLIENT; return sGtkWindowDecoration; }