fix-debug-crash-and-log-spam-with-GTK3-Wayland.patch 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. From f40f0f994d6fbabf75f6acf796fa4b62809851c0 Mon Sep 17 00:00:00 2001
  2. From: Tom Anderson <thomasanderson@chromium.org>
  3. Date: Thu, 18 Aug 2022 23:00:41 +0000
  4. Subject: [PATCH] Fix debug crash and log spam with
  5. GTK3+Wayland+text-input-unstable-v3
  6. This fixes a regression after [1]. The GTK IME doesn't work on
  7. Wayland+GTK3, so this change skips GTK IME creation for that case.
  8. This effectively restores the behavior to before [1].
  9. [1] https://chromium-review.googlesource.com/c/chromium/src/+/3759236
  10. Change-Id: I4019e8da6929489e302ba7f8699ad62ca604b4aa
  11. Fixed: 1347979
  12. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3836775
  13. Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
  14. Reviewed-by: Nick Yamane <nickdiego@igalia.com>
  15. Commit-Queue: Nick Yamane <nickdiego@igalia.com>
  16. Cr-Commit-Position: refs/heads/main@{#1036838}
  17. ---
  18. ui/gtk/gtk_ui.cc | 2 +-
  19. ui/gtk/gtk_ui_platform.h | 10 +++++++++-
  20. ui/gtk/gtk_ui_platform_stub.cc | 6 ++++++
  21. ui/gtk/gtk_ui_platform_stub.h | 2 ++
  22. ui/gtk/wayland/gtk_ui_platform_wayland.cc | 12 ++++++++++++
  23. ui/gtk/wayland/gtk_ui_platform_wayland.h | 2 ++
  24. ui/gtk/x/gtk_ui_platform_x11.cc | 7 +++++++
  25. ui/gtk/x/gtk_ui_platform_x11.h | 2 ++
  26. 8 files changed, 41 insertions(+), 2 deletions(-)
  27. diff --git a/ui/gtk/gtk_ui.cc b/ui/gtk/gtk_ui.cc
  28. index 1fbb58152c..dd42b1e87c 100644
  29. --- a/ui/gtk/gtk_ui.cc
  30. +++ b/ui/gtk/gtk_ui.cc
  31. @@ -447,7 +447,7 @@ void GtkUi::SetWindowFrameAction(WindowFrameActionSource source,
  32. std::unique_ptr<ui::LinuxInputMethodContext> GtkUi::CreateInputMethodContext(
  33. ui::LinuxInputMethodContextDelegate* delegate) const {
  34. - return std::make_unique<InputMethodContextImplGtk>(delegate);
  35. + return GetPlatform()->CreateInputMethodContext(delegate);
  36. }
  37. gfx::FontRenderParams GtkUi::GetDefaultFontRenderParams() const {
  38. diff --git a/ui/gtk/gtk_ui_platform.h b/ui/gtk/gtk_ui_platform.h
  39. index 390d90af83..633efbcf16 100644
  40. --- a/ui/gtk/gtk_ui_platform.h
  41. +++ b/ui/gtk/gtk_ui_platform.h
  42. @@ -10,11 +10,15 @@
  43. #include "ui/gfx/native_widget_types.h"
  44. #include "ui/gtk/gtk_compat.h"
  45. -using GdkKeymap = struct _GdkKeymap;
  46. using GtkWindow = struct _GtkWindow;
  47. using GtkWidget = struct _GtkWidget;
  48. using GdkWindow = struct _GdkWindow;
  49. +namespace ui {
  50. +class LinuxInputMethodContext;
  51. +class LinuxInputMethodContextDelegate;
  52. +} // namespace ui
  53. +
  54. namespace gtk {
  55. // GtkUiPlatform encapsulates platform-specific functionalities required by
  56. @@ -52,6 +56,10 @@ class GtkUiPlatform {
  57. // Presents |window|, doing all the necessary platform-specific operations
  58. // needed, if any.
  59. virtual void ShowGtkWindow(GtkWindow* window) = 0;
  60. +
  61. + // Creates a new IME context or may return nullptr.
  62. + virtual std::unique_ptr<ui::LinuxInputMethodContext> CreateInputMethodContext(
  63. + ui::LinuxInputMethodContextDelegate* delegate) const = 0;
  64. };
  65. } // namespace gtk
  66. diff --git a/ui/gtk/gtk_ui_platform_stub.cc b/ui/gtk/gtk_ui_platform_stub.cc
  67. index 76746254ef..5f01c8bd8f 100644
  68. --- a/ui/gtk/gtk_ui_platform_stub.cc
  69. +++ b/ui/gtk/gtk_ui_platform_stub.cc
  70. @@ -43,4 +43,10 @@ void GtkUiPlatformStub::ShowGtkWindow(GtkWindow* window) {
  71. gtk_window_present(window);
  72. }
  73. +std::unique_ptr<ui::LinuxInputMethodContext>
  74. +GtkUiPlatformStub::CreateInputMethodContext(
  75. + ui::LinuxInputMethodContextDelegate* delegate) const {
  76. + return nullptr;
  77. +}
  78. +
  79. } // namespace gtk
  80. diff --git a/ui/gtk/gtk_ui_platform_stub.h b/ui/gtk/gtk_ui_platform_stub.h
  81. index ae186455bd..708e05ab04 100644
  82. --- a/ui/gtk/gtk_ui_platform_stub.h
  83. +++ b/ui/gtk/gtk_ui_platform_stub.h
  84. @@ -26,6 +26,8 @@ class GtkUiPlatformStub : public GtkUiPlatform {
  85. gfx::AcceleratedWidget parent) override;
  86. void ClearTransientFor(gfx::AcceleratedWidget parent) override;
  87. void ShowGtkWindow(GtkWindow* window) override;
  88. + std::unique_ptr<ui::LinuxInputMethodContext> CreateInputMethodContext(
  89. + ui::LinuxInputMethodContextDelegate* delegate) const override;
  90. };
  91. } // namespace gtk
  92. diff --git a/ui/gtk/wayland/gtk_ui_platform_wayland.cc b/ui/gtk/wayland/gtk_ui_platform_wayland.cc
  93. index 13fb58a84a..cae3475b14 100644
  94. --- a/ui/gtk/wayland/gtk_ui_platform_wayland.cc
  95. +++ b/ui/gtk/wayland/gtk_ui_platform_wayland.cc
  96. @@ -11,7 +11,9 @@
  97. #include "base/logging.h"
  98. #include "ui/base/glib/glib_cast.h"
  99. #include "ui/events/event_utils.h"
  100. +#include "ui/gtk/gtk_compat.h"
  101. #include "ui/gtk/gtk_util.h"
  102. +#include "ui/gtk/input_method_context_impl_gtk.h"
  103. #include "ui/linux/linux_ui_delegate.h"
  104. namespace gtk {
  105. @@ -145,4 +147,14 @@ void GtkUiPlatformWayland::OnHandleSetTransient(GtkWidget* widget,
  106. }
  107. }
  108. +std::unique_ptr<ui::LinuxInputMethodContext>
  109. +GtkUiPlatformWayland::CreateInputMethodContext(
  110. + ui::LinuxInputMethodContextDelegate* delegate) const {
  111. + // GDK3 doesn't have a way to create foreign wayland windows, so we can't
  112. + // translate from ui::KeyEvent to GdkEventKey for InputMethodContextImplGtk.
  113. + if (!GtkCheckVersion(4))
  114. + return nullptr;
  115. + return std::make_unique<InputMethodContextImplGtk>(delegate);
  116. +}
  117. +
  118. } // namespace gtk
  119. diff --git a/ui/gtk/wayland/gtk_ui_platform_wayland.h b/ui/gtk/wayland/gtk_ui_platform_wayland.h
  120. index 2c444793db..315d6ced31 100644
  121. --- a/ui/gtk/wayland/gtk_ui_platform_wayland.h
  122. +++ b/ui/gtk/wayland/gtk_ui_platform_wayland.h
  123. @@ -31,6 +31,8 @@ class GtkUiPlatformWayland : public GtkUiPlatform {
  124. gfx::AcceleratedWidget parent) override;
  125. void ClearTransientFor(gfx::AcceleratedWidget parent) override;
  126. void ShowGtkWindow(GtkWindow* window) override;
  127. + std::unique_ptr<ui::LinuxInputMethodContext> CreateInputMethodContext(
  128. + ui::LinuxInputMethodContextDelegate* delegate) const override;
  129. private:
  130. GdkDisplay* GetDefaultGdkDisplay();
  131. diff --git a/ui/gtk/x/gtk_ui_platform_x11.cc b/ui/gtk/x/gtk_ui_platform_x11.cc
  132. index 5fa9d040c6..f7ba25c30c 100644
  133. --- a/ui/gtk/x/gtk_ui_platform_x11.cc
  134. +++ b/ui/gtk/x/gtk_ui_platform_x11.cc
  135. @@ -19,6 +19,7 @@
  136. #include "ui/gfx/x/xproto_util.h"
  137. #include "ui/gtk/gtk_compat.h"
  138. #include "ui/gtk/gtk_util.h"
  139. +#include "ui/gtk/input_method_context_impl_gtk.h"
  140. #include "ui/gtk/x/gtk_event_loop_x11.h"
  141. #include "ui/linux/linux_ui_delegate.h"
  142. @@ -114,4 +115,10 @@ void GtkUiPlatformX11::ShowGtkWindow(GtkWindow* window) {
  143. static_cast<uint32_t>(ui::X11EventSource::GetInstance()->GetTimestamp()));
  144. }
  145. +std::unique_ptr<ui::LinuxInputMethodContext>
  146. +GtkUiPlatformX11::CreateInputMethodContext(
  147. + ui::LinuxInputMethodContextDelegate* delegate) const {
  148. + return std::make_unique<InputMethodContextImplGtk>(delegate);
  149. +}
  150. +
  151. } // namespace gtk
  152. diff --git a/ui/gtk/x/gtk_ui_platform_x11.h b/ui/gtk/x/gtk_ui_platform_x11.h
  153. index 3055b7d7ff..74011a8a1c 100644
  154. --- a/ui/gtk/x/gtk_ui_platform_x11.h
  155. +++ b/ui/gtk/x/gtk_ui_platform_x11.h
  156. @@ -34,6 +34,8 @@ class GtkUiPlatformX11 : public GtkUiPlatform {
  157. gfx::AcceleratedWidget parent) override;
  158. void ClearTransientFor(gfx::AcceleratedWidget parent) override;
  159. void ShowGtkWindow(GtkWindow* window) override;
  160. + std::unique_ptr<ui::LinuxInputMethodContext> CreateInputMethodContext(
  161. + ui::LinuxInputMethodContextDelegate* delegate) const override;
  162. private:
  163. GdkDisplay* GetGdkDisplay();