### Install Application Bundle Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/linux/CMakeLists.txt Defines installation rules for creating a relocatable application bundle. This includes cleaning the build directory, installing the executable, Flutter data, libraries, and assets. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Application Target and Runtime Files Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/CMakeLists.txt Configures the installation of the main application executable, ICU data, Flutter library, and bundled plugin libraries. Ensures all necessary files are placed correctly for runtime. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Assets Directory Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/CMakeLists.txt Installs the Flutter assets directory by first removing any existing directory and then copying the new one. This ensures assets are up-to-date. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Start Window Resizing from Edges Source: https://context7.com/leanflutter/window_manager/llms.txt Enable window resizing by calling `startResizing` with a specific `ResizeEdge`. This is applicable on Linux and Windows. ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; // Start resizing from a specific edge await windowManager.startResizing(ResizeEdge.top); await windowManager.startResizing(ResizeEdge.bottom); await windowManager.startResizing(ResizeEdge.left); await windowManager.startResizing(ResizeEdge.right); await windowManager.startResizing(ResizeEdge.topLeft); await windowManager.startResizing(ResizeEdge.topRight); await windowManager.startResizing(ResizeEdge.bottomLeft); await windowManager.startResizing(ResizeEdge.bottomRight); ``` -------------------------------- ### Set Installation Prefix for Visual Studio Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/CMakeLists.txt Configures the installation prefix to be next to the executable when using Visual Studio. This allows the application to run correctly from Visual Studio. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install AOT Library for Release Builds Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library on Profile and Release configurations. This is typically used for performance optimization. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Find and link GTK, GLIB, and GIO modules Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/linux/flutter/CMakeLists.txt This snippet finds system-level dependencies using PkgConfig and makes them available for the project. Ensure these libraries are installed on your system. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Start Window Dragging Source: https://context7.com/leanflutter/window_manager/llms.txt Enable window dragging functionality from custom areas, particularly useful when the native title bar is hidden. ```APIDOC ## startDragging ### Description Initiates window dragging from a custom drag area. This is typically used when the native window title bar is hidden, allowing users to move the window by interacting with a custom UI element. ### Method - `startDragging()`: Call this method within a gesture detector (e.g., `onPanStart`) to enable dragging. ### Request Example ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; class CustomTitleBar extends StatelessWidget { @override Widget build(BuildContext context) { return GestureDetector( behavior: HitTestBehavior.translucent, onPanStart: (details) { windowManager.startDragging(); }, onDoubleTap: () async { bool isMaximized = await windowManager.isMaximized(); if (isMaximized) { windowManager.unmaximize(); } else { windowManager.maximize(); } }, child: Container( height: 32, color: Colors.grey[200], child: Center(child: Text('Drag to move')), ), ); } } ``` ``` -------------------------------- ### Window Bounds Source: https://context7.com/leanflutter/window_manager/llms.txt Get or set the window's bounds, which include its position and size. ```APIDOC ## GET /window/bounds ### Description Retrieves the current bounds of the window, including its position and size. ### Method GET ### Endpoint /window/bounds ### Response #### Success Response (200) - **bounds** (Rect) - The current rectangular bounds of the window (left, top, width, height). #### Response Example { "bounds": {"left": 100.0, "top": 100.0, "width": 800.0, "height": 600.0} } ## POST /window/bounds ### Description Sets the bounds (position and/or size) of the window. Can be used to set position, size, or both. Can optionally animate the change. ### Method POST ### Endpoint /window/bounds ### Parameters #### Request Body - **bounds** (Rect) - Optional - The desired rectangular bounds for the window. If null, position and/or size can be specified independently. - **position** (Offset) - Optional - The desired position for the window. Overrides position if 'bounds' is provided. - **size** (Size) - Optional - The desired size for the window. Overrides size if 'bounds' is provided. - **animate** (boolean) - Optional - If true, animates the window to the new bounds. ### Request Example { "bounds": {"left": 100.0, "top": 100.0, "width": 800.0, "height": 600.0}, "animate": true } ### Request Example (Set only position) { "position": {"dx": 200.0, "dy": 200.0} } ### Request Example (Set only size) { "size": {"width": 1024.0, "height": 768.0} } ### Request Example (Set position and size with animation) { "position": {"dx": 100.0, "dy": 100.0}, "size": {"width": 800.0, "height": 600.0}, "animate": true } ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/CMakeLists.txt Specifies the minimum required CMake version and names the project. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.14) project(window_manager_example LANGUAGES CXX) ``` -------------------------------- ### Get and Set Window Bounds Source: https://context7.com/leanflutter/window_manager/llms.txt Retrieve or define the window's position and dimensions simultaneously. Supports setting only position, only size, or both, with optional animation. ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; // Get current bounds (position and size) Rect bounds = await windowManager.getBounds(); print('Bounds: x=${bounds.left}, y=${bounds.top}, width=${bounds.width}, height=${bounds.height}'); // Set bounds using Rect await windowManager.setBounds( Rect.fromLTWH(100, 100, 800, 600), animate: true, ); // Set only position await windowManager.setBounds( null, position: Offset(200, 200), ); // Set only size await windowManager.setBounds( null, size: Size(1024, 768), ); // Set both position and size await windowManager.setBounds( null, position: Offset(100, 100), size: Size(800, 600), animate: true, ); ``` -------------------------------- ### Control Window Position Source: https://context7.com/leanflutter/window_manager/llms.txt Get the current window position, set an absolute position, or center the window on the screen. Animation is supported for position changes on macOS. ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; // Get current position Offset position = await windowManager.getPosition(); print('Position: x=${position.dx}, y=${position.dy}'); // Set absolute position await windowManager.setPosition(Offset(100, 100)); // Set position with animation (macOS) await windowManager.setPosition(Offset(200, 200), animate: true); // Center window on screen await windowManager.center(); await windowManager.center(animate: true); // Align to specific screen position await windowManager.setAlignment(Alignment.topLeft); await windowManager.setAlignment(Alignment.topCenter); await windowManager.setAlignment(Alignment.topRight); await windowManager.setAlignment(Alignment.centerLeft); await windowManager.setAlignment(Alignment.center); await windowManager.setAlignment(Alignment.centerRight); await windowManager.setAlignment(Alignment.bottomLeft); await windowManager.setAlignment(Alignment.bottomCenter); await windowManager.setAlignment(Alignment.bottomRight, animate: true); ``` -------------------------------- ### Configure Window Options and Show Window Source: https://context7.com/leanflutter/window_manager/llms.txt Configure window options such as size, centering, title bar style, and minimum/maximum dimensions. Then, use waitUntilReadyToShow to apply these options and display the window when it's ready, preventing a flash of unstyled content. ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await windowManager.ensureInitialized(); WindowOptions windowOptions = const WindowOptions( size: Size(800, 600), center: true, backgroundColor: Colors.transparent, skipTaskbar: false, titleBarStyle: TitleBarStyle.hidden, windowButtonVisibility: false, minimumSize: Size(400, 300), maximumSize: Size(1920, 1080), alwaysOnTop: false, fullScreen: false, title: 'My Desktop App', ); windowManager.waitUntilReadyToShow(windowOptions, () async { await windowManager.show(); await windowManager.focus(); }); runApp(MyApp()); } ``` -------------------------------- ### Initialize and Configure Window Options Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/README.md Ensures the window manager is initialized and sets up initial window options like size, centering, background color, and title bar style. Use this in your main function before running the app. ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); // Must add this line. await windowManager.ensureInitialized(); WindowOptions windowOptions = WindowOptions( size: Size(800, 600), center: true, backgroundColor: Colors.transparent, skipTaskbar: false, titleBarStyle: TitleBarStyle.hidden, ); windowManager.waitUntilReadyToShow(windowOptions, () async { await windowManager.show(); await windowManager.focus(); }); runApp(MyApp()); } ``` -------------------------------- ### startResizing Source: https://context7.com/leanflutter/window_manager/llms.txt Enables window resizing from custom resize edges. This functionality is available on Linux and Windows platforms. ```APIDOC ## startResizing ### Description Enable window resizing from custom resize edges (Linux, Windows). ### Method `windowManager.startResizing(ResizeEdge edge)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```dart import 'package:window_manager/window_manager.dart'; // Start resizing from a specific edge await windowManager.startResizing(ResizeEdge.top); await windowManager.startResizing(ResizeEdge.bottom); await windowManager.startResizing(ResizeEdge.left); await windowManager.startResizing(ResizeEdge.right); await windowManager.startResizing(ResizeEdge.topLeft); await windowManager.startResizing(ResizeEdge.topRight); await windowManager.startResizing(ResizeEdge.bottomLeft); await windowManager.startResizing(ResizeEdge.bottomRight); ``` ### Response This method does not return a value. ``` -------------------------------- ### Get Native Window Identifier Source: https://context7.com/leanflutter/window_manager/llms.txt Retrieve the unique identifier for the native window. This is the HWND on Windows and the window number on macOS. ```dart import 'package:window_manager/window_manager.dart'; // Get window ID (HWND on Windows, window number on macOS) int windowId = await windowManager.getId(); print('Window ID: $windowId'); ``` -------------------------------- ### Configure Flutter Library Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/flutter/CMakeLists.txt Sets up the Flutter library and its associated headers and data files. Ensures the library is available for linking. ```cmake cmake_minimum_required(VERSION 3.14) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # TODO: Move the rest of this into files in ephemeral. See # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") # Set fallback configurations for older versions of the flutter tool. if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Set RPATH for Runtime Libraries Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/CMakeLists.txt Configures the RPATH to include the directory where shared libraries are installed. This helps the executable find its libraries at runtime. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Configure Flutter Tool Backend Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/flutter/CMakeLists.txt Sets up a custom command to run the Flutter tool backend, generating necessary build artifacts like the Flutter library and headers. Uses a phony target to ensure execution. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Configure CMake Project and Executable Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/runner/CMakeLists.txt Sets up the CMake minimum version, project name, and defines the main executable target with its source files and standard settings. Includes specific compile definitions and library linking for a Windows environment. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Set Background Color and Opacity Source: https://context7.com/leanflutter/window_manager/llms.txt Customize the window's background color and transparency level. ```APIDOC ## setBackgroundColor / getOpacity / setOpacity ### Description Allows customization of the window's background color and its transparency. ### Methods - `setBackgroundColor(Color color)`: Sets the background color of the window. - `getOpacity()`: Retrieves the current opacity of the window (0.0 to 1.0). - `setOpacity(double opacity)`: Sets the window's opacity level. ### Request Example ```dart // Set background color await windowManager.setBackgroundColor(Colors.transparent); await windowManager.setBackgroundColor(Colors.white); await windowManager.setBackgroundColor(Color(0xFF1C1C1C)); // Get current opacity (0.0 to 1.0) double opacity = await windowManager.getOpacity(); print('Window opacity: $opacity'); // Set window opacity await windowManager.setOpacity(1.0); // Fully opaque await windowManager.setOpacity(0.8); // 80% opaque await windowManager.setOpacity(0.5); // 50% transparent ``` ``` -------------------------------- ### Window Visibility and Focus API Source: https://context7.com/leanflutter/window_manager/llms.txt Control window visibility and focus state. Use `show()` to display the window, `hide()` to hide it without closing, `focus()` to bring it to front, and `blur()` to remove focus. ```APIDOC ## show / hide / focus / blur ### Description Control window visibility and focus state. Use `show()` to display the window, `hide()` to hide it without closing, `focus()` to bring it to front, and `blur()` to remove focus. ### Methods - `show({bool inactive = false})`: Displays the window. If `inactive` is true, the window will be shown without gaining focus. - `hide()`: Hides the window without closing it. - `focus()`: Brings the window to the front and gives it focus. - `blur()`: Removes focus from the window (supported on macOS and Windows). - `isVisible()`: Returns `true` if the window is currently visible, `false` otherwise. - `isFocused()`: Returns `true` if the window currently has focus, `false` otherwise. ``` -------------------------------- ### Fullscreen API Source: https://context7.com/leanflutter/window_manager/llms.txt Enter and exit fullscreen mode. ```APIDOC ## setFullScreen / isFullScreen ### Description Enter and exit fullscreen mode. ### Methods - `setFullScreen(bool fullscreen)`: Sets the window to fullscreen mode if `fullscreen` is true, or exits fullscreen mode if `fullscreen` is false. - `isFullScreen()`: Returns `true` if the window is currently in fullscreen mode, `false` otherwise. ``` -------------------------------- ### Application Build Configuration Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/linux/CMakeLists.txt Configures the main application executable, linking it with the Flutter library and GTK. It also sets runtime output directory to prevent running unbundled copies. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Linux: Show Window Widget Source: https://github.com/leanflutter/window_manager/blob/main/docs/en/quick-start.md Modify the `my_application.cc` file on Linux to use `gtk_widget_realize` instead of `gtk_widget_show` for window widgets. This change affects how the window is initially displayed. ```diff gtk_widget_set_default_size(window, 1280, 720); - gtk_widget_show(GTK_WIDGET(window)); + gtk_widget_realize(GTK_WIDGET(window)); ``` -------------------------------- ### Configure C++ Wrapper for Plugins Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/flutter/CMakeLists.txt Builds a static C++ wrapper library for plugins, including core implementations and plugin registrar sources. Links against the Flutter library. ```cmake # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Control Window Size and Constraints Source: https://context7.com/leanflutter/window_manager/llms.txt Manage the window's dimensions, including setting specific sizes, minimum and maximum size constraints, and aspect ratio. Use `getSize()` to retrieve the current dimensions. ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; // Get current window size Size size = await windowManager.getSize(); print('Current size: ${size.width}x${size.height}'); // Set window size await windowManager.setSize(Size(1024, 768)); // Set size with animation (macOS) await windowManager.setSize(Size(1280, 720), animate: true); // Set minimum size constraint await windowManager.setMinimumSize(Size(400, 300)); // Set maximum size constraint await windowManager.setMaximumSize(Size(1920, 1080)); // Set aspect ratio (window maintains ratio during resize) await windowManager.setAspectRatio(16 / 9); // 16:9 ratio await windowManager.setAspectRatio(1.0); // Square await windowManager.setAspectRatio(0); // Reset/disable ``` -------------------------------- ### DragToResizeArea Widget Source: https://context7.com/leanflutter/window_manager/llms.txt A widget that enables edge resizing for frameless windows on Linux and Windows. ```APIDOC ## DragToResizeArea Widget ### Description A widget that enables edge resizing when the window frame is hidden (Linux, Windows). ### Parameters - **resizeEdgeSize** (double) - Optional - The size of the resize edge. - **resizeEdgeColor** (Color) - Optional - The color of the resize edge. - **resizeEdgeMargin** (EdgeInsets) - Optional - The margin around the resize edge. - **enableResizeEdges** (List) - Optional - A list of edges on which resizing is enabled. ### Example ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; class ResizableWindow extends StatelessWidget { @override Widget build(BuildContext context) { return DragToResizeArea( resizeEdgeSize: 8, resizeEdgeColor: Colors.transparent, resizeEdgeMargin: EdgeInsets.zero, enableResizeEdges: [ ResizeEdge.top, ResizeEdge.bottom, ResizeEdge.left, ResizeEdge.right, ResizeEdge.topLeft, ResizeEdge.topRight, ResizeEdge.bottomLeft, ResizeEdge.bottomRight, ], child: Scaffold( body: Center(child: Text('Resize from edges')), ), ); } } ``` ``` -------------------------------- ### Windows: Defer Window Showing Source: https://github.com/leanflutter/window_manager/blob/main/docs/en/quick-start.md In `flutter_window.cpp` for newer Windows projects (Flutter 3.7+), comment out the `this->Show()` call within the `SetNextFrameCallback`. This defers the window display until after the initial frame is ready. ```diff flutter_controller_->engine()->SetNextFrameCallback([&]() { - this->Show(); + "" //delete this->Show() ``` -------------------------------- ### Configure Build Options for Multi-Config Generators Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/CMakeLists.txt Sets the available build configurations (Debug, Profile, Release) for multi-configuration generators. Ensures consistent build types are available. ```cmake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### VirtualWindowFrame Widget Source: https://context7.com/leanflutter/window_manager/llms.txt Provides a virtual window frame with shadow and border for frameless windows on Linux and Windows. ```APIDOC ## VirtualWindowFrame Widget ### Description A widget that provides a virtual window frame with shadow and border for frameless windows (Linux, Windows). ### Usage Wrap your `MaterialApp` or the root of your widget tree with `VirtualWindowFrame` or use the `VirtualWindowFrameInit` builder. ### Example ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await windowManager.ensureInitialized(); runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( builder: (context, child) { // Wrap with VirtualWindowFrame for frameless window styling return VirtualWindowFrame(child: child!); }, home: HomePage(), ); } } // Alternative: Use VirtualWindowFrameInit() builder class MyAppAlternative extends StatelessWidget { @override Widget build(BuildContext context) { final virtualWindowFrameBuilder = VirtualWindowFrameInit(); return MaterialApp( builder: (context, child) { return virtualWindowFrameBuilder(context, child); }, home: HomePage(), ); } } ``` ``` -------------------------------- ### Configure C++ Wrapper for Runner Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/flutter/CMakeLists.txt Builds a static C++ wrapper library for the runner application, including core and application-specific sources. Links against the Flutter library. ```cmake # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### WindowCaption Widget Source: https://context7.com/leanflutter/window_manager/llms.txt Simulates a Windows 11 style title bar, including minimize, maximize, and close buttons. ```APIDOC ## WindowCaption Widget ### Description A widget that simulates a Windows 11 style title bar with minimize, maximize, and close buttons. ### Parameters - **brightness** (Brightness) - Required - The brightness of the window caption. - **backgroundColor** (Color) - Optional - The background color of the caption. - **title** (Widget) - Required - The widget to display as the window title. ### Example ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; class MyScaffold extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(kWindowCaptionHeight), // 32 child: WindowCaption( brightness: Theme.of(context).brightness, backgroundColor: Colors.blue, title: Text('My Application'), ), ), body: Center(child: Text('Content')), ); } } ``` ``` -------------------------------- ### Control Window Visibility and Focus Source: https://context7.com/leanflutter/window_manager/llms.txt Manage the window's visibility and focus state. Use `show()` to display, `hide()` to conceal without closing, `focus()` to bring to the front, and `blur()` to remove focus. Check visibility and focus status with `isVisible()` and `isFocused()` respectively. ```dart import 'package:window_manager/window_manager.dart'; // Show the window (restores from minimized if needed) await windowManager.show(); // Show window without giving it focus await windowManager.show(inactive: true); // Hide the window (doesn't close it) await windowManager.hide(); // Check if window is visible bool isVisible = await windowManager.isVisible(); print('Window visible: $isVisible'); // Focus the window (bring to front) await windowManager.focus(); // Remove focus from window (macOS, Windows) await windowManager.blur(); // Check if window has focus (macOS, Windows) bool isFocused = await windowManager.isFocused(); print('Window focused: $isFocused'); ``` -------------------------------- ### Control Window Visibility on Workspaces Source: https://context7.com/leanflutter/window_manager/llms.txt Manage whether a window appears on all virtual desktops. Use `visibleOnFullScreen` to include fullscreen spaces. This feature is macOS only. ```dart import 'package:window_manager/window_manager.dart'; // Check if visible on all workspaces bool isVisible = await windowManager.isVisibleOnAllWorkspaces(); // Show on all workspaces await windowManager.setVisibleOnAllWorkspaces(true); // Show on all workspaces including fullscreen spaces await windowManager.setVisibleOnAllWorkspaces( true, visibleOnFullScreen: true, ); // Show only on current workspace await windowManager.setVisibleOnAllWorkspaces(false); ``` -------------------------------- ### macOS: Implement Window Visibility Source: https://github.com/leanflutter/window_manager/blob/main/docs/en/quick-start.md Add the `window_manager` import and override the `order` method in `MainFlutterWindow.swift` on macOS. This ensures `hiddenWindowAtLaunch` is called after the window's ordering status is updated. ```swift import Cocoa import FlutterMacOS +import window_manager class MainFlutterWindow: NSWindow { override func awakeFromNib() { let flutterViewController = FlutterViewController.init() let windowFrame = self.frame self.contentViewController = flutterViewController self.setFrame(windowFrame, display: true) RegisterGeneratedPlugins(registry: flutterViewController) super.awakeFromNib() } + override public func order(_ place: NSWindow.OrderingMode, relativeTo otherWin: Int) { + super.order(place, relativeTo: otherWin) + hiddenWindowAtLaunch() + } } ``` -------------------------------- ### Window Position and Alignment Source: https://context7.com/leanflutter/window_manager/llms.txt Control the position and alignment of the application window on the screen. ```APIDOC ## GET /window/position ### Description Retrieves the current position of the window on the screen. ### Method GET ### Endpoint /window/position ### Response #### Success Response (200) - **position** (Offset) - The current x and y coordinates of the window. #### Response Example { "position": {"dx": 100.0, "dy": 100.0} } ## POST /window/position ### Description Sets the absolute position of the window on the screen. Can optionally animate the change. ### Method POST ### Endpoint /window/position ### Parameters #### Request Body - **position** (Offset) - Required - The desired x and y coordinates for the window. - **animate** (boolean) - Optional - If true, animates the window to the new position (behavior may vary by platform). ### Request Example { "position": {"dx": 100.0, "dy": 100.0}, "animate": true } ## POST /window/center ### Description Centers the window on the screen. Can optionally animate the change. ### Method POST ### Endpoint /window/center ### Parameters #### Request Body - **animate** (boolean) - Optional - If true, animates the window to the center position. ### Request Example { "animate": true } ## POST /window/alignment ### Description Aligns the window to a specific position on the screen. Can optionally animate the change. ### Method POST ### Endpoint /window/alignment ### Parameters #### Request Body - **alignment** (Alignment) - Required - The desired alignment (e.g., Alignment.topLeft, Alignment.center). - **animate** (boolean) - Optional - If true, animates the window to the aligned position. ### Request Example { "alignment": "center", "animate": true } ``` -------------------------------- ### Window State Management API Source: https://context7.com/leanflutter/window_manager/llms.txt Control window state transitions for maximizing, minimizing, and restoring. ```APIDOC ## maximize / unmaximize / minimize / restore ### Description Control window state transitions for maximizing, minimizing, and restoring. ### Methods - `maximize({bool vertically = false})`: Maximizes the window. If `vertically` is true, it maximizes vertically only (Windows specific). - `unmaximize()`: Restores the window from a maximized state. - `minimize()`: Minimizes the window to the taskbar or dock. - `restore()`: Restores the window from a minimized state. - `isMaximized()`: Returns `true` if the window is currently maximized, `false` otherwise. - `isMinimized()`: Returns `true` if the window is currently minimized, `false` otherwise. ``` -------------------------------- ### Taskbar/Dock Visibility Source: https://context7.com/leanflutter/window_manager/llms.txt Determine and control whether the window appears in the system taskbar or dock. ```APIDOC ## setSkipTaskbar / isSkipTaskbar ### Description Control whether the window is visible in the system taskbar or dock. ### Methods - `isSkipTaskbar()`: Returns a boolean indicating if the window is currently hidden from the taskbar/dock. - `setSkipTaskbar(bool skip)`: Hides or shows the window in the taskbar/dock. ### Request Example ```dart // Check if skipping taskbar bool isSkipping = await windowManager.isSkipTaskbar(); // Hide from taskbar/dock await windowManager.setSkipTaskbar(true); // Show in taskbar/dock await windowManager.setSkipTaskbar(false); ``` ``` -------------------------------- ### Control Window State (Maximize, Minimize, Restore) Source: https://context7.com/leanflutter/window_manager/llms.txt Transition the window between maximized, minimized, and restored states. Check the current state using `isMaximized()` and `isMinimized()`. The window can be maximized vertically only on Windows. ```dart import 'package:window_manager/window_manager.dart'; // Check current state bool isMaximized = await windowManager.isMaximized(); bool isMinimized = await windowManager.isMinimized(); // Maximize the window await windowManager.maximize(); // Maximize vertically only (Windows - simulates aero snap) await windowManager.maximize(vertically: true); // Restore from maximized state await windowManager.unmaximize(); // Minimize to taskbar/dock await windowManager.minimize(); // Restore from minimized state await windowManager.restore(); // Toggle maximize state if (await windowManager.isMaximized()) { await windowManager.unmaximize(); } else { await windowManager.maximize(); } ``` -------------------------------- ### Apply Virtual Window Frame Styling Source: https://context7.com/leanflutter/window_manager/llms.txt Use the `VirtualWindowFrame` widget to apply styling like shadow and border to frameless windows on Linux and Windows. It can be used directly in the `MaterialApp` builder or via `VirtualWindowFrameInit`. ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await windowManager.ensureInitialized(); runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( builder: (context, child) { // Wrap with VirtualWindowFrame for frameless window styling return VirtualWindowFrame(child: child!); }, home: HomePage(), ); } } // Alternative: Use VirtualWindowFrameInit() builder class MyAppAlternative extends StatelessWidget { @override Widget build(BuildContext context) { final virtualWindowFrameBuilder = VirtualWindowFrameInit(); return MaterialApp( builder: (context, child) { return virtualWindowFrameBuilder(context, child); }, home: HomePage(), ); } ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/leanflutter/window_manager/blob/main/packages/window_manager/example/windows/CMakeLists.txt Adds definitions to enable Unicode support in the project. This is important for handling international characters correctly. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Taskbar Progress Indicator Source: https://context7.com/leanflutter/window_manager/llms.txt Display a progress indicator on the application's icon in the taskbar or dock. ```APIDOC ## setProgressBar ### Description Displays a progress indicator on the taskbar/dock icon. Supported on macOS and Windows. ### Method - `setProgressBar(double progress)`: Sets the progress value (0.0 to 1.0). Use -1 to remove the indicator. ### Request Example ```dart // Set progress (0.0 to 1.0) await windowManager.setProgressBar(0.0); // 0% await windowManager.setProgressBar(0.5); // 50% await windowManager.setProgressBar(1.0); // 100% // Remove progress indicator await windowManager.setProgressBar(-1); // Example: Progress animation for (var i = 0; i <= 100; i++) { await windowManager.setProgressBar(i / 100); await Future.delayed(Duration(milliseconds: 50)); } await windowManager.setProgressBar(-1); // Clear when done ``` ``` -------------------------------- ### Set Window Icon Source: https://context7.com/leanflutter/window_manager/llms.txt Set the application's icon for the window and taskbar (Windows only). ```APIDOC ## setIcon ### Description Sets the window and taskbar icon. This is primarily applicable on Windows. ### Method - `setIcon(String iconPath)`: Sets the icon using a file path. Supports common image formats like .ico and .png. ### Request Example ```dart // Set window icon from asset await windowManager.setIcon('assets/icons/app_icon.ico'); await windowManager.setIcon('assets/icons/app_icon.png'); ``` ``` -------------------------------- ### Window Size API Source: https://context7.com/leanflutter/window_manager/llms.txt Control window dimensions with specific sizes and constraints. ```APIDOC ## getSize / setSize / setMinimumSize / setMaximumSize / setAspectRatio ### Description Control window dimensions with specific sizes and constraints. ### Methods - `getSize()`: Returns the current size of the window as a `Size` object. - `setSize(Size size, {bool animate = false})`: Sets the window to the specified `size`. If `animate` is true, the resize will be animated (macOS specific). - `setMinimumSize(Size size)`: Sets the minimum allowed dimensions for the window. - `setMaximumSize(Size size)`: Sets the maximum allowed dimensions for the window. - `setAspectRatio(double aspectRatio)`: Sets the aspect ratio for the window. A value of `0` resets or disables the aspect ratio constraint. ``` -------------------------------- ### Listen to window events Source: https://github.com/leanflutter/window_manager/blob/main/docs/en/quick-start.md Implement the WindowListener interface to receive and handle various window events such as close, focus, maximize, minimize, and resize. ```dart import 'package:flutter/cupertino.dart'; import 'package:window_manager/window_manager.dart'; class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State with WindowListener { @override void initState() { super.initState(); windowManager.addListener(this); } @override void dispose() { windowManager.removeListener(this); super.dispose(); } @override Widget build(BuildContext context) { // ... } @override void onWindowEvent(String eventName) { print('[WindowManager] onWindowEvent: $eventName'); } @override void onWindowClose() { // do something } @override void onWindowFocus() { // do something } @override void onWindowBlur() { // do something } @override void onWindowMaximize() { // do something } @override void onWindowUnmaximize() { // do something } @override void onWindowMinimize() { // do something } @override void onWindowRestore() { // do something } @override void onWindowResize() { // do something } @override void onWindowMove() { // do something } @override void onWindowEnterFullScreen() { // do something } @override void onWindowLeaveFullScreen() { // do something } } ``` -------------------------------- ### Initialize Window Manager Source: https://context7.com/leanflutter/window_manager/llms.txt Initialize the window manager after WidgetsFlutterBinding.ensureInitialized() and before any other windowManager calls. This is a mandatory step for using the plugin's features. ```dart import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); // Must add this line before using any windowManager methods await windowManager.ensureInitialized(); runApp(MyApp()); } ``` -------------------------------- ### Windows: Adjust Window Creation Flags Source: https://github.com/leanflutter/window_manager/blob/main/docs/en/quick-start.md In `win32_window.cpp` on Windows, remove the `WS_VISIBLE` flag from `CreateWindow` parameters. This prevents the window from being shown immediately, allowing for controlled visibility later. ```diff window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + window_class, title.c_str(), + WS_OVERLAPPEDWINDOW, // do not add WS_VISIBLE since the window will be shown later ``` -------------------------------- ### Window Z-Order Source: https://context7.com/leanflutter/window_manager/llms.txt Control whether the window stays on top of or below other windows. ```APIDOC ## GET /window/alwaysOnTop ### Description Checks if the window is set to always be on top of other windows. ### Method GET ### Endpoint /window/alwaysOnTop ### Response #### Success Response (200) - **alwaysOnTop** (boolean) - True if the window is always on top, false otherwise. #### Response Example { "alwaysOnTop": false } ## POST /window/alwaysOnTop ### Description Sets the window to always stay on top of or below other windows. ### Method POST ### Endpoint /window/alwaysOnTop ### Parameters #### Request Body - **alwaysOnTop** (boolean) - Required - Set to true to keep the window on top, false to allow it to be covered by other windows. ### Request Example { "alwaysOnTop": true } ## GET /window/alwaysOnBottom ### Description Checks if the window is set to always be on the bottom of other windows (Linux, Windows). ### Method GET ### Endpoint /window/alwaysOnBottom ### Response #### Success Response (200) - **alwaysOnBottom** (boolean) - True if the window is always on the bottom, false otherwise. #### Response Example { "alwaysOnBottom": false } ## POST /window/alwaysOnBottom ### Description Sets the window to always stay on the bottom of other windows (Linux, Windows). ### Method POST ### Endpoint /window/alwaysOnBottom ### Parameters #### Request Body - **alwaysOnBottom** (boolean) - Required - Set to true to keep the window on the bottom, false otherwise. ### Request Example { "alwaysOnBottom": true } ```