Commit 9c848d2d authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

ozone, libgtkui: Properly set gdk backend in GtkUi initialization

Currently Gdk backend is auto-selected in Ozone, which leads to crashes
when, for example, ozone platform is set to x11 while the browser is
being executed in a Wayland compositor (e.g: Gnome/Wayland for example).

CL modifies GtkUi ctor to set allowed gdk backends based on the current
ozone plarform.

Bug: 1008924
Change-Id: I12163357e4d3d517c4c98672ed9db3c064c2d244
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1829319
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701575}
parent 8644eeb2
...@@ -119,4 +119,8 @@ jumbo_component("libgtkui") { ...@@ -119,4 +119,8 @@ jumbo_component("libgtkui") {
"//ui/gfx/x", "//ui/gfx/x",
] ]
} }
if (use_ozone) {
deps += [ "//ui/ozone" ]
}
} }
...@@ -75,6 +75,8 @@ ...@@ -75,6 +75,8 @@
#if defined(USE_X11) #if defined(USE_X11)
#include "ui/gfx/x/x11.h" // nogncheck #include "ui/gfx/x/x11.h" // nogncheck
#include "ui/gfx/x/x11_types.h" // nogncheck #include "ui/gfx/x/x11_types.h" // nogncheck
#elif defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif #endif
#if BUILDFLAG(ENABLE_PRINTING) #if BUILDFLAG(ENABLE_PRINTING)
...@@ -332,11 +334,15 @@ GtkUi::GtkUi() { ...@@ -332,11 +334,15 @@ GtkUi::GtkUi() {
{ActionSource::kRightClick, Action::kMenu}}; {ActionSource::kRightClick, Action::kMenu}};
#if defined(USE_X11) #if defined(USE_X11)
// Force Gtk to use Xwayland if it would have used wayland. In Aura/X11, // Force Gtk to use Xwayland (in case a Wayland compositor is being used).
// libgtkui assumes the use of X11 (eg. InputMethodContextImplGtk) and will
// crash under other backends.
// TODO(thomasanderson): Change this logic once Wayland support is added.
gdk_set_allowed_backends("x11"); gdk_set_allowed_backends("x11");
#elif defined(USE_OZONE)
// TODO(crbug.com/1002674): This is a temporary layering violation, supported
// during X11 migration to Ozone. Once LinuxUI/GtkUi is reworked to be more
// aligned with Ozone design, this will be moved into ozone backend code.
std::string ozone_platform{ui::OzonePlatform::GetPlatformName()};
if (ozone_platform == "x11" || ozone_platform == "wayland")
gdk_set_allowed_backends(ozone_platform.c_str());
#endif #endif
// Avoid GTK initializing atk-bridge, and let AuraLinux implementation // Avoid GTK initializing atk-bridge, and let AuraLinux implementation
......
...@@ -57,6 +57,11 @@ OzonePlatform* OzonePlatform::GetInstance() { ...@@ -57,6 +57,11 @@ OzonePlatform* OzonePlatform::GetInstance() {
return g_instance; return g_instance;
} }
// static
const char* OzonePlatform::GetPlatformName() {
return GetOzonePlatformName();
}
// static // static
OzonePlatform* OzonePlatform::EnsureInstance() { OzonePlatform* OzonePlatform::EnsureInstance() {
if (!g_instance) { if (!g_instance) {
......
...@@ -138,6 +138,14 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform { ...@@ -138,6 +138,14 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform {
static OzonePlatform* GetInstance(); static OzonePlatform* GetInstance();
// Returns the current ozone platform name.
// TODO(crbug.com/1002674): This is temporary and meant to make it possible
// for higher level components to take run-time actions depending on the
// current ozone platform selected. Which implies in layering violations,
// which are tolerated during the X11 migration to Ozone and must be fixed
// once it is done.
static const char* GetPlatformName();
// Factory getters to override in subclasses. The returned objects will be // Factory getters to override in subclasses. The returned objects will be
// injected into the appropriate layer at startup. Subclasses should not // injected into the appropriate layer at startup. Subclasses should not
// inject these objects themselves. Ownership is retained by OzonePlatform. // inject these objects themselves. Ownership is retained by OzonePlatform.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment