From a8b0d8e7b4902788c5bebd686ccc24136d4982b6 Mon Sep 17 00:00:00 2001 From: Xiaowei Guan Date: Tue, 8 Sep 2026 10:59:35 +0800 Subject: [PATCH] Add flutter tizen window api --- flutter/shell/platform/tizen/BUILD.gn | 1 + flutter/shell/platform/tizen/flutter_tizen.cc | 93 +++++++++++++++++++ .../tizen/public/flutter_tizen_window.h | 79 ++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 flutter/shell/platform/tizen/public/flutter_tizen_window.h diff --git a/flutter/shell/platform/tizen/BUILD.gn b/flutter/shell/platform/tizen/BUILD.gn index 899babc..670c73b 100644 --- a/flutter/shell/platform/tizen/BUILD.gn +++ b/flutter/shell/platform/tizen/BUILD.gn @@ -7,6 +7,7 @@ import("//flutter/shell/platform/common/client_wrapper/publish.gni") _public_headers = [ "public/flutter_platform_view.h", "public/flutter_tizen.h", + "public/flutter_tizen_window.h", ] config("flutter_tizen_config") { diff --git a/flutter/shell/platform/tizen/flutter_tizen.cc b/flutter/shell/platform/tizen/flutter_tizen.cc index 5105c0e..e97345e 100644 --- a/flutter/shell/platform/tizen/flutter_tizen.cc +++ b/flutter/shell/platform/tizen/flutter_tizen.cc @@ -4,6 +4,7 @@ // found in the LICENSE file. #include "public/flutter_tizen.h" +#include "public/flutter_tizen_window.h" #include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h" #include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h" @@ -295,3 +296,95 @@ FlutterDesktopMessengerRef FlutterDesktopMessengerLock( } void FlutterDesktopMessengerUnlock(FlutterDesktopMessengerRef messenger) {} + +// ========== Window API ========== + +// Returns the TizenWindow associated with the given view, or nullptr if the +// view does not have a TizenWindow. +static flutter::TizenWindow* TizenWindowFromView( + FlutterDesktopViewRef view_ref) { + flutter::FlutterTizenView* view = ViewFromHandle(view_ref); + if (!view || !view->tizen_view()) { + return nullptr; + } + // The tizen_view() returns a TizenViewBase*. We need to check if it's + // actually a TizenWindow by dynamic_cast. + return dynamic_cast(view->tizen_view()); +} + +FlutterDesktopWindowGeometry FlutterDesktopWindowGetGeometry( + FlutterDesktopViewRef view) { + FlutterDesktopWindowGeometry result = {0, 0, 0, 0}; + flutter::TizenWindow* window = TizenWindowFromView(view); + if (!window) { + return result; + } + flutter::TizenGeometry geometry = window->GetGeometry(); + result.x = geometry.left; + result.y = geometry.top; + result.width = geometry.width; + result.height = geometry.height; + return result; +} + +bool FlutterDesktopWindowSetGeometry( + FlutterDesktopViewRef view, + const FlutterDesktopWindowGeometry* geometry) { + if (!geometry) { + return false; + } + flutter::TizenWindow* window = TizenWindowFromView(view); + if (!window) { + return false; + } + flutter::TizenGeometry current = window->GetGeometry(); + flutter::TizenGeometry target = { + geometry->x != -1 ? geometry->x : current.left, + geometry->y != -1 ? geometry->y : current.top, + geometry->width != -1 ? geometry->width : current.width, + geometry->height != -1 ? geometry->height : current.height, + }; + return window->SetGeometry(target); +} + +FlutterDesktopScreenGeometry FlutterDesktopWindowGetScreenGeometry( + FlutterDesktopViewRef view) { + FlutterDesktopScreenGeometry result = {0, 0}; + flutter::TizenWindow* window = TizenWindowFromView(view); + if (!window) { + return result; + } + flutter::TizenGeometry geometry = window->GetScreenGeometry(); + result.width = geometry.width; + result.height = geometry.height; + return result; +} + +int32_t FlutterDesktopWindowGetRotation(FlutterDesktopViewRef view) { + flutter::TizenWindow* window = TizenWindowFromView(view); + if (!window) { + return 0; + } + return window->GetRotation(); +} + +void FlutterDesktopWindowActivate(FlutterDesktopViewRef view) { + flutter::TizenWindow* window = TizenWindowFromView(view); + if (window) { + window->ActivateWindow(); + } +} + +void FlutterDesktopWindowRaise(FlutterDesktopViewRef view) { + flutter::TizenWindow* window = TizenWindowFromView(view); + if (window) { + window->RaiseWindow(); + } +} + +void FlutterDesktopWindowLower(FlutterDesktopViewRef view) { + flutter::TizenWindow* window = TizenWindowFromView(view); + if (window) { + window->LowerWindow(); + } +} diff --git a/flutter/shell/platform/tizen/public/flutter_tizen_window.h b/flutter/shell/platform/tizen/public/flutter_tizen_window.h new file mode 100644 index 0000000..7a188a6 --- /dev/null +++ b/flutter/shell/platform/tizen/public/flutter_tizen_window.h @@ -0,0 +1,79 @@ +// Copyright 2026 Samsung Electronics Co., Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_TIZEN_WINDOW_H_ +#define FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_TIZEN_WINDOW_H_ + +#include +#include + +#include "flutter_export.h" +#include "flutter_tizen.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +// The geometry (position and size) of a window. +typedef struct { + // The x-coordinate of the top left corner of the window. + int32_t x; + // The y-coordinate of the top left corner of the window. + int32_t y; + // The width of the window. + int32_t width; + // The height of the window. + int32_t height; +} FlutterDesktopWindowGeometry; + +// The geometry (size) of the display screen. +typedef struct { + // The width of the screen. + int32_t width; + // The height of the screen. + int32_t height; +} FlutterDesktopScreenGeometry; + +// ========== Window ========== + +// Returns the geometry (position and size) of the window associated with +// the given view. +FLUTTER_EXPORT FlutterDesktopWindowGeometry +FlutterDesktopWindowGetGeometry(FlutterDesktopViewRef view); + +// Sets the geometry (position and size) of the window associated with +// the given view. +// +// If any field of |geometry| is -1, the current value for that field is +// preserved. +// +// Returns true if the geometry was successfully set, false otherwise. +FLUTTER_EXPORT bool FlutterDesktopWindowSetGeometry( + FlutterDesktopViewRef view, + const FlutterDesktopWindowGeometry* geometry); + +// Returns the geometry (size) of the screen that the window is on. +FLUTTER_EXPORT FlutterDesktopScreenGeometry +FlutterDesktopWindowGetScreenGeometry(FlutterDesktopViewRef view); + +// Returns the current rotation (in degrees) of the window. +FLUTTER_EXPORT int32_t +FlutterDesktopWindowGetRotation(FlutterDesktopViewRef view); + +// Activates the window associated with the given view. +FLUTTER_EXPORT void FlutterDesktopWindowActivate(FlutterDesktopViewRef view); + +// Raises the window associated with the given view to the top of the +// stacking order. +FLUTTER_EXPORT void FlutterDesktopWindowRaise(FlutterDesktopViewRef view); + +// Lowers the window associated with the given view to the bottom of the +// stacking order. +FLUTTER_EXPORT void FlutterDesktopWindowLower(FlutterDesktopViewRef view); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_TIZEN_WINDOW_H_