Minor fixes/adjustments to the GLFW shell (#8990)
- Makes json_method_codec.cc compatible with the last stable RapidJSON release.
- Allows removing the GTK dependency with a compile flag.
- Fixes a missing break in a switch flagged by some toolchains.
diff --git a/shell/platform/common/cpp/client_wrapper/json_method_codec.cc b/shell/platform/common/cpp/client_wrapper/json_method_codec.cc
index f576d4e..6c9528ff 100644
--- a/shell/platform/common/cpp/client_wrapper/json_method_codec.cc
+++ b/shell/platform/common/cpp/client_wrapper/json_method_codec.cc
@@ -44,7 +44,12 @@
// Pull the arguments subtree up to the root of json_message. This is
// destructive to json_message, but the full value is no longer needed, and
// this avoids a subtree copy.
- json_message->Swap(arguments_iter->value);
+ // Note: The static_cast is for compatibility with RapidJSON 1.1; master
+ // already allows swapping a Document with a Value directly. Once there is
+ // a new RapidJSON release (at which point clients can be expected to have
+ // that change in the version they depend on) remove the cast.
+ static_cast<rapidjson::Value*>(json_message.get())
+ ->Swap(arguments_iter->value);
// Swap it into |arguments|. This moves the allocator ownership, so that
// the data won't be deleted when json_message goes out of scope.
arguments = std::make_unique<rapidjson::Document>();
diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc
index 1dd37f5..20f2c86 100644
--- a/shell/platform/glfw/flutter_glfw.cc
+++ b/shell/platform/glfw/flutter_glfw.cc
@@ -19,7 +19,14 @@
#include "flutter/shell/platform/glfw/keyboard_hook_handler.h"
#include "flutter/shell/platform/glfw/text_input_plugin.h"
-#ifdef __linux__
+// For compatibility with GTK-based plugins, special message loop setup is
+// required (e.g., for GTK modal windows). This can be disabled for cases where
+// a GTK dependency is undesirable by defining FLUTTER_DISABLE_GTK.
+#if defined(__linux__) && !defined(FLUTTER_DISABLE_GTK)
+#define FLUTTER_USE_GTK 1
+#endif
+
+#ifdef FLUTTER_USE_GTK
// For plugin-compatible event handling (e.g., modal windows).
#include <X11/Xlib.h>
#include <gtk/gtk.h>
@@ -519,7 +526,7 @@
const char* icu_data_path,
const char** arguments,
size_t argument_count) {
-#ifdef __linux__
+#ifdef FLUTTER_USE_GTK
gtk_init(0, nullptr);
#endif
@@ -659,13 +666,13 @@
void FlutterDesktopRunWindowLoop(FlutterDesktopWindowControllerRef controller) {
GLFWwindow* window = controller->window.get();
-#ifdef __linux__
+#ifdef FLUTTER_USE_GTK
// Necessary for GTK thread safety.
XInitThreads();
#endif
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
-#ifdef __linux__
+#ifdef FLUTTER_USE_GTK
if (gtk_events_pending()) {
gtk_main_iteration();
}
diff --git a/shell/platform/glfw/text_input_plugin.cc b/shell/platform/glfw/text_input_plugin.cc
index 87706de..3779510 100644
--- a/shell/platform/glfw/text_input_plugin.cc
+++ b/shell/platform/glfw/text_input_plugin.cc
@@ -86,6 +86,7 @@
break;
case GLFW_KEY_ENTER:
EnterPressed(active_model_);
+ break;
default:
break;
}