diff --git a/engine/src/flutter/shell/platform/glfw/client_wrapper/flutter_window_controller.cc b/engine/src/flutter/shell/platform/glfw/client_wrapper/flutter_window_controller.cc index c73d6e7078..235be0b2bd 100644 --- a/engine/src/flutter/shell/platform/glfw/client_wrapper/flutter_window_controller.cc +++ b/engine/src/flutter/shell/platform/glfw/client_wrapper/flutter_window_controller.cc @@ -24,6 +24,7 @@ FlutterWindowController::~FlutterWindowController() { bool FlutterWindowController::CreateWindow( int width, int height, + const std::string& title, const std::string& assets_path, const std::vector& arguments) { if (!init_succeeded_) { @@ -44,7 +45,7 @@ bool FlutterWindowController::CreateWindow( size_t arg_count = engine_arguments.size(); window_ = FlutterDesktopCreateWindow( - width, height, assets_path.c_str(), icu_data_path_.c_str(), + width, height, title.c_str(), assets_path.c_str(), icu_data_path_.c_str(), arg_count > 0 ? &engine_arguments[0] : nullptr, arg_count); if (!window_) { std::cerr << "Failed to create window." << std::endl; @@ -68,6 +69,16 @@ void FlutterWindowController::SetHoverEnabled(bool enabled) { FlutterDesktopSetHoverEnabled(window_, enabled); } +void FlutterWindowController::SetTitle(const std::string& title) { + FlutterDesktopSetWindowTitle(window_, title.c_str()); +} + +void FlutterWindowController::SetIcon(uint8_t* pixel_data, + int width, + int height) { + FlutterDesktopSetWindowIcon(window_, pixel_data, width, height); +} + void FlutterWindowController::RunEventLoop() { if (window_) { FlutterDesktopRunWindowLoop(window_); diff --git a/engine/src/flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h b/engine/src/flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h index 24496252c8..70169e48cc 100644 --- a/engine/src/flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h +++ b/engine/src/flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h @@ -46,6 +46,7 @@ class FlutterWindowController { // Only one Flutter window can exist at a time; see constructor comment. bool CreateWindow(int width, int height, + const std::string& title, const std::string& assets_path, const std::vector& arguments); @@ -63,6 +64,16 @@ class FlutterWindowController { // Defaults to off. void SetHoverEnabled(bool enabled); + // Sets the displayed title of the window. + void SetTitle(const std::string& title); + + // Sets the displayed icon for the window. + // + // The pixel format is 32-bit RGBA. The provided image data only needs to be + // valid for the duration of the call to this method. Pass a nullptr to revert + // to the default icon. + void SetIcon(uint8_t* pixel_data, int width, int height); + // Loops on Flutter window events until the window closes. void RunEventLoop(); diff --git a/engine/src/flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.cc b/engine/src/flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.cc index f3a5e9a436..db564018bc 100644 --- a/engine/src/flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.cc +++ b/engine/src/flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.cc @@ -50,14 +50,15 @@ void FlutterDesktopTerminate() { FlutterDesktopWindowRef FlutterDesktopCreateWindow(int initial_width, int initial_height, + const char* title, const char* assets_path, const char* icu_data_path, const char** arguments, size_t argument_count) { if (s_stub_implementation) { - return s_stub_implementation->CreateWindow(initial_width, initial_height, - assets_path, icu_data_path, - arguments, argument_count); + return s_stub_implementation->CreateWindow( + initial_width, initial_height, title, assets_path, icu_data_path, + arguments, argument_count); } return nullptr; } @@ -69,6 +70,22 @@ void FlutterDesktopSetHoverEnabled(FlutterDesktopWindowRef flutter_window, } } +void FlutterDesktopSetWindowTitle(FlutterDesktopWindowRef flutter_window, + const char* title) { + if (s_stub_implementation) { + s_stub_implementation->SetWindowTitle(title); + } +} + +void FlutterDesktopSetWindowIcon(FlutterDesktopWindowRef flutter_window, + uint8_t* pixel_data, + int width, + int height) { + if (s_stub_implementation) { + s_stub_implementation->SetWindowIcon(pixel_data, width, height); + } +} + void FlutterDesktopRunWindowLoop(FlutterDesktopWindowRef flutter_window) { if (s_stub_implementation) { s_stub_implementation->RunWindowLoop(); diff --git a/engine/src/flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.h b/engine/src/flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.h index 70f993646d..95f2be2148 100644 --- a/engine/src/flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.h +++ b/engine/src/flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.h @@ -38,6 +38,7 @@ class StubFlutterGlfwApi { // Called for FlutterDesktopCreateWindow. virtual FlutterDesktopWindowRef CreateWindow(int initial_width, int initial_height, + const char* title, const char* assets_path, const char* icu_data_path, const char** arguments, @@ -45,9 +46,15 @@ class StubFlutterGlfwApi { return nullptr; } - // Called for FlutterDesktopSetHoverEnabled + // Called for FlutterDesktopSetHoverEnabled. virtual void SetHoverEnabled(bool enabled) {} + // Called for FlutterDesktopSetWindowTitle. + virtual void SetWindowTitle(const char* title) {} + + // Called for FlutterDesktopSetWindowIcon. + virtual void SetWindowIcon(uint8_t* pixel_data, int width, int height) {} + // Called for FlutterDesktopRunWindowLoop. virtual void RunWindowLoop() {} diff --git a/engine/src/flutter/shell/platform/glfw/flutter_glfw.cc b/engine/src/flutter/shell/platform/glfw/flutter_glfw.cc index 98e76f02c5..77a3d40e6a 100644 --- a/engine/src/flutter/shell/platform/glfw/flutter_glfw.cc +++ b/engine/src/flutter/shell/platform/glfw/flutter_glfw.cc @@ -94,8 +94,6 @@ struct FlutterDesktopMessenger { shell::IncomingMessageDispatcher* dispatcher; }; -static constexpr char kDefaultWindowTitle[] = "Flutter"; - // Retrieves state bag for the window in question from the GLFWWindow. static FlutterDesktopWindowState* GetSavedWindowState(GLFWwindow* window) { return reinterpret_cast( @@ -473,6 +471,7 @@ void FlutterDesktopTerminate() { FlutterDesktopWindowRef FlutterDesktopCreateWindow(int initial_width, int initial_height, + const char* title, const char* assets_path, const char* icu_data_path, const char** arguments, @@ -481,8 +480,8 @@ FlutterDesktopWindowRef FlutterDesktopCreateWindow(int initial_width, gtk_init(0, nullptr); #endif // Create the window. - auto window = glfwCreateWindow(initial_width, initial_height, - kDefaultWindowTitle, NULL, NULL); + auto window = + glfwCreateWindow(initial_width, initial_height, title, NULL, NULL); if (window == nullptr) { return nullptr; } @@ -543,6 +542,21 @@ void FlutterDesktopSetHoverEnabled(FlutterDesktopWindowRef flutter_window, SetHoverCallbacksEnabled(flutter_window->window, enabled); } +void FlutterDesktopSetWindowTitle(FlutterDesktopWindowRef flutter_window, + const char* title) { + GLFWwindow* window = flutter_window->window; + glfwSetWindowTitle(window, title); +} + +void FlutterDesktopSetWindowIcon(FlutterDesktopWindowRef flutter_window, + uint8_t* pixel_data, + int width, + int height) { + GLFWwindow* window = flutter_window->window; + GLFWimage image = {width, height, static_cast(pixel_data)}; + glfwSetWindowIcon(window, pixel_data ? 1 : 0, &image); +} + void FlutterDesktopRunWindowLoop(FlutterDesktopWindowRef flutter_window) { GLFWwindow* window = flutter_window->window; #ifdef __linux__ diff --git a/engine/src/flutter/shell/platform/glfw/public/flutter_glfw.h b/engine/src/flutter/shell/platform/glfw/public/flutter_glfw.h index c969581e16..85dbe14325 100644 --- a/engine/src/flutter/shell/platform/glfw/public/flutter_glfw.h +++ b/engine/src/flutter/shell/platform/glfw/public/flutter_glfw.h @@ -52,6 +52,7 @@ FLUTTER_EXPORT void FlutterDesktopTerminate(); FLUTTER_EXPORT FlutterDesktopWindowRef FlutterDesktopCreateWindow(int initial_width, int initial_height, + const char* title, const char* assets_path, const char* icu_data_path, const char** arguments, @@ -66,6 +67,22 @@ FLUTTER_EXPORT void FlutterDesktopSetHoverEnabled( FlutterDesktopWindowRef flutter_window, bool enabled); +// Sets the displayed title for |flutter_window|. +FLUTTER_EXPORT void FlutterDesktopSetWindowTitle( + FlutterDesktopWindowRef flutter_window, + const char* title); + +// Sets the displayed icon for |flutter_window|. +// +// The pixel format is 32-bit RGBA. The provided image data only needs to be +// valid for the duration of the call to this method. Pass a nullptr to revert +// to the default icon. +FLUTTER_EXPORT void FlutterDesktopSetWindowIcon( + FlutterDesktopWindowRef flutter_window, + uint8_t* pixel_data, + int width, + int height); + // Loops on Flutter window events until the window is closed. // // Once this function returns, FlutterDesktopWindowRef is no longer valid, and