Commit b74c265f authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

gtk: Delegate GtkEventLoopX11 initialization

Delegate GtkEventLoopX11 initialization to platform code so that we can
get rid of the ugly hack to start it, during GtkUi initialization, for
both ozone and legacy X11.

Bug: 963419, 1002674
Change-Id: Ib9e9d635bed5095fb730f778cc54d8cd3c71e07c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2093252Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarAntonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Auto-Submit: Nick Yamane <nickdiego@igalia.com>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#754668}
parent b1f00b1a
...@@ -83,15 +83,7 @@ jumbo_component("gtk") { ...@@ -83,15 +83,7 @@ jumbo_component("gtk") {
public_deps = [ "//chrome/browser:theme_properties" ] public_deps = [ "//chrome/browser:theme_properties" ]
if (use_x11 || ozone_platform_x11) { if (use_x11 || ozone_platform_x11) {
sources += [
"gtk_event_loop_x11.cc",
"gtk_event_loop_x11.h",
]
configs += [ "//build/config/linux:x11" ] configs += [ "//build/config/linux:x11" ]
defines += [ "USE_GTK_EVENT_LOOP_X11" ]
deps += [ deps += [
"//ui/events/platform/x11", "//ui/events/platform/x11",
"//ui/gfx/x", "//ui/gfx/x",
......
...@@ -68,10 +68,6 @@ ...@@ -68,10 +68,6 @@
#include "chrome/browser/ui/gtk/settings_provider_gsettings.h" #include "chrome/browser/ui/gtk/settings_provider_gsettings.h"
#endif #endif
#if defined(USE_GTK_EVENT_LOOP_X11)
#include "chrome/browser/ui/gtk/gtk_event_loop_x11.h"
#endif
#if defined(USE_OZONE) #if defined(USE_OZONE)
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/ozone_platform.h"
...@@ -312,19 +308,6 @@ views::LinuxUI::WindowFrameAction GetDefaultMiddleClickAction() { ...@@ -312,19 +308,6 @@ views::LinuxUI::WindowFrameAction GetDefaultMiddleClickAction() {
} }
} }
#if defined(USE_GTK_EVENT_LOOP_X11)
bool ShouldCreateGtkEventLoopX11() {
#if defined(USE_OZONE)
// TODO(crbug.com/1002674): This is a temporary layering violation, supported
// during X11 migration to Ozone.
std::string ozone_platform{ui::OzonePlatform::GetPlatformName()};
return ozone_platform == "x11";
#else
return true;
#endif
}
#endif // defined(USE_GTK_EVENT_LOOP_X11)
const SkBitmap GdkPixbufToSkBitmap(GdkPixbuf* pixbuf) { const SkBitmap GdkPixbufToSkBitmap(GdkPixbuf* pixbuf) {
// TODO(erg): What do we do in the case where the pixbuf fails these dchecks? // TODO(erg): What do we do in the case where the pixbuf fails these dchecks?
// I would prefer to use our gtk based canvas, but that would require // I would prefer to use our gtk based canvas, but that would require
...@@ -465,11 +448,7 @@ void GtkUi::Initialize() { ...@@ -465,11 +448,7 @@ void GtkUi::Initialize() {
indicators_count = 0; indicators_count = 0;
#if defined(USE_GTK_EVENT_LOOP_X11) GetDelegate()->OnInitialized();
if (ShouldCreateGtkEventLoopX11())
// Instantiate the singleton instance of GtkEventLoopX11.
GtkEventLoopX11::GetInstance();
#endif
} }
bool GtkUi::GetTint(int id, color_utils::HSL* tint) const { bool GtkUi::GetTint(int id, color_utils::HSL* tint) const {
......
...@@ -23,12 +23,16 @@ component("gtk") { ...@@ -23,12 +23,16 @@ component("gtk") {
component("x") { component("x") {
output_name = "ui_gtk_x" output_name = "ui_gtk_x"
sources = [ sources = [
"gtk_event_loop_x11.cc",
"gtk_event_loop_x11.h",
"gtk_ui_delegate_x11.cc", "gtk_ui_delegate_x11.cc",
"gtk_ui_delegate_x11.h", "gtk_ui_delegate_x11.h",
] ]
public_deps = [ ":gtk" ] public_deps = [ ":gtk" ]
deps = [ deps = [
"//base", "//base",
"//ui/base",
"//ui/events/platform/x11",
"//ui/gfx/x", "//ui/gfx/x",
] ]
defines = [ "IS_UI_GTK_X_IMPL" ] defines = [ "IS_UI_GTK_X_IMPL" ]
......
include_rules = [ include_rules = [
"+ui/gfx", "+ui/gfx",
"+ui/gfx/x", "+ui/gfx/x",
"+ui/events/platform/x11",
"+ui/base/glib",
] ]
...@@ -2,23 +2,28 @@ ...@@ -2,23 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/gtk/gtk_event_loop_x11.h" #include "ui/gtk/gtk_event_loop_x11.h"
#include "ui/gfx/x/x11.h"
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11.h"
namespace ui {
namespace {
int BuildXkbStateFromGdkEvent(unsigned int state, unsigned char group) {
return state | ((group & 0x3) << 13);
}
namespace gtk { } // namespace
// static // static
GtkEventLoopX11* GtkEventLoopX11::GetInstance() { GtkEventLoopX11* GtkEventLoopX11::EnsureInstance() {
return base::Singleton<GtkEventLoopX11>::get(); return base::Singleton<GtkEventLoopX11>::get();
} }
...@@ -83,4 +88,4 @@ void GtkEventLoopX11::ProcessGdkEventKey(const GdkEventKey& gdk_event_key) { ...@@ -83,4 +88,4 @@ void GtkEventLoopX11::ProcessGdkEventKey(const GdkEventKey& gdk_event_key) {
XPutBackEvent(x_event.xkey.display, &x_event); XPutBackEvent(x_event.xkey.display, &x_event);
} }
} // namespace gtk } // namespace ui
...@@ -2,38 +2,38 @@ ...@@ -2,38 +2,38 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_GTK_GTK_EVENT_LOOP_X11_H_ #ifndef UI_GTK_GTK_EVENT_LOOP_X11_H_
#define CHROME_BROWSER_UI_GTK_GTK_EVENT_LOOP_X11_H_ #define UI_GTK_GTK_EVENT_LOOP_X11_H_
#include "base/macros.h" #include "base/macros.h"
#include "ui/base/glib/glib_integers.h" #include "ui/base/glib/glib_integers.h"
typedef union _GdkEvent GdkEvent; using GdkEvent = union _GdkEvent;
typedef struct _GdkEventKey GdkEventKey; using GdkEventKey = struct _GdkEventKey;
namespace base { namespace base {
template <typename Type> template <typename Type>
struct DefaultSingletonTraits; struct DefaultSingletonTraits;
} }
namespace gtk { namespace ui {
class GtkEventLoopX11 { class GtkEventLoopX11 {
public: public:
static GtkEventLoopX11* GetInstance(); static GtkEventLoopX11* EnsureInstance();
private: private:
friend struct base::DefaultSingletonTraits<GtkEventLoopX11>; friend struct base::DefaultSingletonTraits<GtkEventLoopX11>;
GtkEventLoopX11(); GtkEventLoopX11();
GtkEventLoopX11(const GtkEventLoopX11&) = delete;
GtkEventLoopX11& operator=(const GtkEventLoopX11&) = delete;
~GtkEventLoopX11(); ~GtkEventLoopX11();
static void DispatchGdkEvent(GdkEvent* gdk_event, gpointer); static void DispatchGdkEvent(GdkEvent* gdk_event, gpointer);
static void ProcessGdkEventKey(const GdkEventKey& gdk_event_key); static void ProcessGdkEventKey(const GdkEventKey& gdk_event_key);
DISALLOW_COPY_AND_ASSIGN(GtkEventLoopX11);
}; };
} // namespace gtk } // namespace ui
#endif // CHROME_BROWSER_UI_GTK_GTK_EVENT_LOOP_X11_H_ #endif // UI_GTK_GTK_EVENT_LOOP_X11_H_
...@@ -33,6 +33,9 @@ class COMPONENT_EXPORT(UI_GTK) GtkUiDelegate { ...@@ -33,6 +33,9 @@ class COMPONENT_EXPORT(UI_GTK) GtkUiDelegate {
// Returns the current active instance. // Returns the current active instance.
static GtkUiDelegate* instance(); static GtkUiDelegate* instance();
// Called when the GtkUi instance initialization process finished.
virtual void OnInitialized() = 0;
// Gets the GdkKeymap instance, which is used to translate KeyEvents into // Gets the GdkKeymap instance, which is used to translate KeyEvents into
// GdkEvents before filtering them through GtkIM API. // GdkEvents before filtering them through GtkIM API.
virtual GdkKeymap* GetGdkKeymap() = 0; virtual GdkKeymap* GetGdkKeymap() = 0;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11.h"
#include "ui/gtk/gtk_event_loop_x11.h"
namespace ui { namespace ui {
...@@ -19,6 +20,11 @@ GtkUiDelegateX11::GtkUiDelegateX11(XDisplay* display) : xdisplay_(display) { ...@@ -19,6 +20,11 @@ GtkUiDelegateX11::GtkUiDelegateX11(XDisplay* display) : xdisplay_(display) {
GtkUiDelegateX11::~GtkUiDelegateX11() = default; GtkUiDelegateX11::~GtkUiDelegateX11() = default;
void GtkUiDelegateX11::OnInitialized() {
// Ensure the singleton instance of GtkEventLoopX11 is created and started.
GtkEventLoopX11::EnsureInstance();
}
GdkKeymap* GtkUiDelegateX11::GetGdkKeymap() { GdkKeymap* GtkUiDelegateX11::GetGdkKeymap() {
return gdk_keymap_get_for_display(GetGdkDisplay()); return gdk_keymap_get_for_display(GetGdkDisplay());
} }
......
...@@ -27,6 +27,7 @@ class COMPONENT_EXPORT(UI_GTK_X) GtkUiDelegateX11 : public GtkUiDelegate { ...@@ -27,6 +27,7 @@ class COMPONENT_EXPORT(UI_GTK_X) GtkUiDelegateX11 : public GtkUiDelegate {
~GtkUiDelegateX11() override; ~GtkUiDelegateX11() override;
// GtkUiDelegate: // GtkUiDelegate:
void OnInitialized() override;
GdkKeymap* GetGdkKeymap() override; GdkKeymap* GetGdkKeymap() override;
GdkWindow* GetGdkWindow(gfx::AcceleratedWidget window_id) override; GdkWindow* GetGdkWindow(gfx::AcceleratedWidget window_id) override;
bool SetGdkWindowTransientFor(GdkWindow* window, bool SetGdkWindowTransientFor(GdkWindow* window,
......
...@@ -21,6 +21,10 @@ GtkUiDelegateWayland::GtkUiDelegateWayland(WaylandConnection* connection) ...@@ -21,6 +21,10 @@ GtkUiDelegateWayland::GtkUiDelegateWayland(WaylandConnection* connection)
GtkUiDelegateWayland::~GtkUiDelegateWayland() = default; GtkUiDelegateWayland::~GtkUiDelegateWayland() = default;
void GtkUiDelegateWayland::OnInitialized() {
// Nothing to do upon initialization for Wayland.
}
GdkKeymap* GtkUiDelegateWayland::GetGdkKeymap() { GdkKeymap* GtkUiDelegateWayland::GetGdkKeymap() {
NOTIMPLEMENTED_LOG_ONCE(); NOTIMPLEMENTED_LOG_ONCE();
return nullptr; return nullptr;
......
...@@ -20,6 +20,7 @@ class GtkUiDelegateWayland : public GtkUiDelegate { ...@@ -20,6 +20,7 @@ class GtkUiDelegateWayland : public GtkUiDelegate {
~GtkUiDelegateWayland() override; ~GtkUiDelegateWayland() override;
// GtkUiDelegate: // GtkUiDelegate:
void OnInitialized() override;
GdkKeymap* GetGdkKeymap() override; GdkKeymap* GetGdkKeymap() override;
GdkWindow* GetGdkWindow(gfx::AcceleratedWidget window_id) override; GdkWindow* GetGdkWindow(gfx::AcceleratedWidget window_id) override;
bool SetGdkWindowTransientFor(GdkWindow* window, bool SetGdkWindowTransientFor(GdkWindow* window,
......
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