Minor fixes/adjustments to the GLFW shell (flutter/engine#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.
This commit is contained in:
stuartmorgan
2019-05-20 14:36:59 -04:00
committed by GitHub
parent 6e4d0dc733
commit f0ab13a0bb
3 changed files with 18 additions and 5 deletions

View File

@@ -44,7 +44,12 @@ JsonMethodCodec::DecodeMethodCallInternal(const uint8_t* message,
// 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>();

View File

@@ -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 @@ FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow(
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 @@ double FlutterDesktopWindowGetScaleFactor(
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();
}

View File

@@ -86,6 +86,7 @@ void TextInputPlugin::KeyboardHook(GLFWwindow* window,
break;
case GLFW_KEY_ENTER:
EnterPressed(active_model_);
break;
default:
break;
}