### CMake Project Setup and Configuration Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/linux/CMakeLists.txt Initializes the CMake project, sets the project name and version, defines binary and application IDs, and configures CMake policies and installation paths. It also handles cross-compilation by setting the sysroot and find root paths. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "bitsdojo_window_example") set(APPLICATION_ID "com.example.bitsdojo_window_example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Root filesystem for cross-building. if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() # Configure build options. 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() ``` -------------------------------- ### CMake Installation Rules Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/windows/CMakeLists.txt Defines the installation process for the bitsdojo_window application, including setting the installation prefix, copying the executable, data files, libraries, and assets, and conditionally installing the AOT library. ```cmake # === Installation === # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. 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() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 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() # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. 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) # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Linux Setup for bitsdojo_window Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/README.md Sets up the bitsdojo_window plugin for Linux applications by modifying the my_application.cc file. Enables custom window frames by using bitsdojo_window_from and setCustomFrame. ```cpp #include // ... other code ... auto bdw = bitsdojo_window_from(window); bdw->setCustomFrame(true); //gtk_window_set_default_size(window, 1280, 720); // <-- comment this line gtk_widget_show(GTK_WIDGET(window)); ``` -------------------------------- ### CMake Project Setup and Library Definition Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window_windows/windows/CMakeLists.txt Configures the CMake project, defines the library name, and lists source files for the BitsDojo Window plugin. ```cmake cmake_minimum_required(VERSION 3.15) set(PROJECT_NAME "bitsdojo_window_windows") set(PARENT_PROJECT_NAME,"bitsdojo_window") project(${PROJECT_NAME} LANGUAGES CXX) set(PLUGIN_NAME "${PROJECT_NAME}_plugin") add_library(${PLUGIN_NAME} STATIC "bitsdojo_window.cpp" "bitsdojo_window_api.cpp" "bitsdojo_window_plugin.cpp" ) ``` -------------------------------- ### Installation Rules for Application Bundle Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/linux/CMakeLists.txt Defines the installation rules for creating a relocatable application bundle. This includes cleaning the build bundle directory, installing the executable, Flutter ICU data, Flutter library, bundled plugin libraries, and assets. It also conditionally installs the AOT library for non-Debug builds. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. 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() # Start with a clean build bundle directory every time. 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() # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. 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) # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Windows Setup for bitsdojo_window Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/README.md Integrates the bitsdojo_window plugin into a Windows Flutter application by modifying the main.cpp file. Allows for custom window frames and hiding the window on startup. ```cpp #include auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP); ``` -------------------------------- ### Complete Custom Window Example Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/README.md This comprehensive example showcases a Flutter application with a custom-styled window using bitsdojo_window. It includes setting the window title, implementing a draggable title bar, and adding minimize, maximize, and close buttons. ```dart import 'package:flutter/material.dart'; import 'package:bitsdojo_window/bitsdojo_window.dart'; void main() { runApp(const MyApp()); doWhenWindowReady(() { final win = appWindow; const initialSize = Size(600, 450); win.minSize = initialSize; win.size = initialSize; win.alignment = Alignment.center; win.title = "Custom window with Flutter"; win.show(); }); } const borderColor = Color(0xFF805306); class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: WindowBorder( color: borderColor, width: 1, child: Row(children: const [LeftSide(), RightSide()]), ), ), ); } } const sidebarColor = Color(0xFFF6A00C); class LeftSide extends StatelessWidget { const LeftSide({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return SizedBox( width: 200, child: Container( color: sidebarColor, child: Column( children: [WindowTitleBarBox(child: MoveWindow()), Expanded(child: Container())] ))); } } const backgroundStartColor = Color(0xFFFFD500); const backgroundEndColor = Color(0xFFF6A00C); class RightSide extends StatelessWidget { const RightSide({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Expanded( child: Container( decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [backgroundStartColor, backgroundEndColor], stops: [0.0, 1.0]), ), child: Column(children: [ WindowTitleBarBox( child: Row( children: [Expanded(child: MoveWindow()), const WindowButtons()] ), ) ]), ), ); } } final buttonColors = WindowButtonColors( iconNormal: const Color(0xFF805306), mouseOver: const Color(0xFFF6A00C), mouseDown: const Color(0xFF805306), iconMouseOver: const Color(0xFF805306), iconMouseDown: const Color(0xFFFFD500)); final closeButtonColors = WindowButtonColors( mouseOver: const Color(0xFFD32F2F), mouseDown: const Color(0xFFB71C1C), iconNormal: const Color(0xFF805306), iconMouseOver: Colors.white); class WindowButtons extends StatelessWidget { const WindowButtons({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Row( children: [ MinimizeWindowButton(colors: buttonColors), MaximizeWindowButton(colors: buttonColors), CloseWindowButton(colors: closeButtonColors), ], ); } } ``` -------------------------------- ### Full Example: Custom Window with Title Bar and Controls Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/README.md This comprehensive example demonstrates a complete Flutter application setup using bitsdojo_window. It includes custom window borders, a draggable title bar using `MoveWindow`, and custom window buttons (minimize, maximize, close) with specific color schemes. ```dart import 'package:flutter/material.dart'; import 'package:bitsdojo_window/bitsdojo_window.dart'; void main() { runApp(const MyApp()); doWhenWindowReady({ () { final win = appWindow; const initialSize = Size(600, 450); win.minSize = initialSize; win.size = initialSize; win.alignment = Alignment.center; win.title = "Custom window with Flutter"; win.show(); } }); } const borderColor = Color(0xFF805306); class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: WindowBorder( color: borderColor, width: 1, child: Row( children: const [LeftSide(), RightSide()], ), ), ), ); } } const sidebarColor = Color(0xFFF6A00C); class LeftSide extends StatelessWidget { const LeftSide({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return SizedBox( width: 200, child: Container( color: sidebarColor, child: Column( children: [ WindowTitleBarBox(child: MoveWindow()), Expanded(child: Container()) ], ))); } } const backgroundStartColor = Color(0xFFFFD500); const backgroundEndColor = Color(0xFFF6A00C); class RightSide extends StatelessWidget { const RightSide({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Expanded( child: Container( decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [backgroundStartColor, backgroundEndColor], stops: [0.0, 1.0]), ), child: Column(children: [ WindowTitleBarBox( child: Row( children: [Expanded(child: MoveWindow()), const WindowButtons()], ), ) ]), ), ); } } final buttonColors = WindowButtonColors( iconNormal: const Color(0xFF805306), mouseOver: const Color(0xFFF6A00C), mouseDown: const Color(0xFF805306), iconMouseOver: const Color(0xFF805306), iconMouseDown: const Color(0xFFFFD500)); final closeButtonColors = WindowButtonColors( mouseOver: const Color(0xFFD32F2F), mouseDown: const Color(0xFFB71C1C), iconNormal: const Color(0xFF805306), iconMouseOver: Colors.white); class WindowButtons extends StatelessWidget { const WindowButtons({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Row( children: [ MinimizeWindowButton(colors: buttonColors), MaximizeWindowButton(colors: buttonColors), CloseWindowButton(colors: closeButtonColors), ], ); } } ``` -------------------------------- ### Flutter Library Setup Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/linux/flutter/CMakeLists.txt Configures the Flutter library by finding system dependencies (GTK, GLIB, GIO), setting library paths, and defining include directories and link libraries for the Flutter interface target. ```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) set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 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/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Flutter Library Setup Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/windows/flutter/CMakeLists.txt Configures the Flutter library and its headers for the project. It sets up include directories and links the necessary Flutter Windows DLL. This snippet defines the interface library 'flutter' which is used by other targets. ```cmake cmake_minimum_required(VERSION 3.15) 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") # === 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) ``` -------------------------------- ### macOS Setup for bitsdojo_window Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/README.md Configures the bitsdojo_window plugin for macOS applications by modifying the MainFlutterWindow.swift file. Enables custom window frames and hiding the window on startup by subclassing BitsdojoWindow. ```swift import FlutterMacOS import bitsdojo_window_macos // Add this line class MainFlutterWindow: BitsdojoWindow { override func bitsdojo_window_configure() -> UInt { return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP } override func awakeFromNib() { ... //rest of your code } } ``` -------------------------------- ### Initialize Window Settings in main.dart Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/README.md This snippet shows how to use `doWhenWindowReady` to set the initial and minimum size of the application window, center it on the screen, and then display it. This is a fundamental step for customizing window behavior. ```dart import 'package:flutter/material.dart'; import 'package:bitsdojo_window/bitsdojo_window.dart'; void main() { runApp(MyApp()); doWhenWindowReady({ () { const initialSize = Size(600, 450); appWindow.minSize = initialSize; appWindow.size = initialSize; appWindow.alignment = Alignment.center; appWindow.show(); } }); } ``` -------------------------------- ### Set Initial Window Properties Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/README.md This code snippet demonstrates how to set the initial size, minimum size, and alignment for the application window using the `doWhenWindowReady` function. It also shows how to display the window. ```dart void main() { runApp(MyApp()); // Add this code below doWhenWindowReady(() { const initialSize = Size(600, 450); appWindow.minSize = initialSize; appWindow.size = initialSize; appWindow.alignment = Alignment.center; appWindow.show(); }); } ``` -------------------------------- ### Linking Libraries for the Plugin Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window_windows/windows/CMakeLists.txt Links necessary libraries, including Flutter, its wrapper, Dwmapi, and Comctl32, to the plugin target. ```cmake target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin Dwmapi Comctl32) ``` -------------------------------- ### Implementing BitsdojoWindowPlatform Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window_platform_interface/README.md This snippet demonstrates how to implement a new platform-specific version of the bitsdojo_window plugin. It involves extending the `BitsdojoWindowPlatform` class and setting the default instance with your custom implementation. ```dart import 'package:bitsdojo_window_platform_interface/bitsdojo_window_platform_interface.dart'; class MyPlatformBitsdojoWindow extends BitsdojoWindowPlatform { // Implement platform-specific behavior here } void main() { BitsdojoWindowPlatform.instance = MyPlatformBitsdojoWindow(); // ... rest of your application setup } ``` -------------------------------- ### Linux: Configure Custom Frame Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/README.md Modifies the my_application.cc file for Linux applications to enable a custom window frame using bitsdojo_window_from and setCustomFrame. ```diff // linux/my_application.cc ... #include "flutter/generated_plugin_registrant.h" + #include struct _MyApplication { ... } + auto bdw = bitsdojo_window_from(window); + bdw->setCustomFrame(true); - gtk_window_set_default_size(window, 1280, 720); gtk_widget_show(GTK_WIDGET(window)); g_autoptr(FlDartProject) project = fl_dart_project_new(); ... } ``` -------------------------------- ### CMake Build Configuration Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/windows/CMakeLists.txt Configures the CMake build process, including setting the minimum version, project name, binary name, and managing build types (Debug, Profile, Release) for multi-configuration generators and single-configuration generators. ```cmake cmake_minimum_required(VERSION 3.15) project(bitsdojo_window_example LANGUAGES CXX) set(BINARY_NAME "bitsdojo_window_example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Configure build options. 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() set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") # Use Unicode for all projects. add_definitions(-DUNICODE -D_UNICODE) # Compilation settings that should be applied to most targets. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$:_DEBUG") endfunction() set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # Application build add_subdirectory("runner") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Application Build Configuration Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/linux/CMakeLists.txt Configures the main executable target, including source files, standard settings, linking libraries (flutter and GTK), and adding dependencies on Flutter assembly. It also sets runtime output properties to place the executable in a specific intermediate directory. ```cmake # Application build 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) # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Windows: Configure Custom Frame and Hide on Startup Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/README.md Modifies the main.cpp file for Windows applications to enable a custom window frame and hide the window upon startup using bitsdojo_window_configure. ```diff // windows/runner/main.cpp ... #include "flutter_window.h" #include "utils.h" + #include + auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP); int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, ... ``` -------------------------------- ### CMake Build Configuration Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/windows/runner/CMakeLists.txt This snippet details the CMake build configuration for the BitsDojo window project. It sets the minimum required CMake version, defines the project name, and configures the executable with its source files, compiler definitions, linked libraries, and dependencies. ```cmake cmake_minimum_required(VERSION 3.15) project(runner LANGUAGES CXX) add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "run_loop.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) ``` -------------------------------- ### macOS: Configure Custom Frame and Hide on Startup Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/README.md Updates the MainFlutterWindow.swift file for macOS applications to inherit from BitsdojoWindow and configure custom frame and hide-on-startup behavior. ```diff // macos/runner/MainFlutterWindow.swift import Cocoa import FlutterMacOS + import bitsdojo_window_macos - class MainFlutterWindow: NSWindow { + class MainFlutterWindow: BitsdojoWindow { + override func bitsdojo_window_configure() -> UInt { + return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP + } override func awakeFromNib() { ... } } ``` -------------------------------- ### Applying Standard Settings and Target Properties Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window_windows/windows/CMakeLists.txt Applies standard build settings and sets C++ visibility to hidden for the plugin library. ```cmake apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") ``` -------------------------------- ### Bundled Libraries Configuration Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window_windows/windows/CMakeLists.txt Defines a list for absolute paths to libraries that should be bundled with the plugin. Currently set to an empty string. ```cmake # List of absolute paths to libraries that should be bundled with the plugin set(bitsdojo_window_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Add bitsdojo_window Dependency Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/README.md Instructions on how to add the bitsdojo_window package to your Flutter project's pubspec.yaml file. ```shell pub add bitsdojo_window ``` ```diff // pubspec.yaml ... dependencies: flutter: sdk: flutter + bitsdojo_window: ^0.1.6 dev_dependencies: ... ``` -------------------------------- ### Linux Plugin Build Configuration Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window_linux/linux/CMakeLists.txt Configures the CMake build for the bitsdojo_window Linux plugin. It defines the project, creates a shared library with specified source files, applies standard build settings, sets C++ visibility to hidden, defines compile-time flags, includes necessary directories, and links against the Flutter and GTK libraries. ```cmake cmake_minimum_required(VERSION 3.10) set(PROJECT_NAME "bitsdojo_window_linux") project(${PROJECT_NAME} LANGUAGES CXX) set(PLUGIN_NAME "${PROJECT_NAME}_plugin") add_library(${PLUGIN_NAME} SHARED "debug_helper.cpp" "gtk_utils.cpp" "window_info.cpp" "window_impl.cpp" "api_impl.cpp" "api.cpp" "bitsdojo_window_plugin.cpp" ) apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter PkgConfig::GTK) set(bitsdojo_window_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Flutter Integration and System Dependencies Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/linux/CMakeLists.txt Integrates the Flutter managed directory and its generated plugins. It also finds and checks PkgConfig for GTK+ 3.0, adding a definition for the application ID. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### C++ Wrapper Library for Application Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/windows/flutter/CMakeLists.txt Defines a static C++ library for the main application. It includes core wrapper implementations and application-specific sources like Flutter engine and view controller. This library is linked by the application executable. ```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) ``` -------------------------------- ### C++ Wrapper Library for Plugins Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/windows/flutter/CMakeLists.txt Defines a static C++ library for Flutter plugins. It includes core wrapper implementations and plugin-specific sources. This library is designed to be linked by plugin projects, providing necessary Flutter integration functionalities. ```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) ``` -------------------------------- ### Standard Compilation Settings Function Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/linux/CMakeLists.txt Defines a CMake function `APPLY_STANDARD_SETTINGS` that applies common compilation features and options to a target. This includes setting the C++ standard to C++14, enabling Wall and Werror, optimizing for non-Debug builds, and defining NDEBUG for non-Debug builds. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/windows/flutter/CMakeLists.txt Configures a custom command to run the Flutter tool backend. This command is responsible for generating necessary files like the Flutter library and wrapper sources. It uses a phony target to ensure execution on every build. ```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" windows-x64 $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Flutter Tool Backend Command Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/linux/flutter/CMakeLists.txt Defines a custom CMake command to execute the Flutter tool backend script. This command is responsible for generating the Flutter library and headers. It uses a phony target to ensure it runs every time due to the difficulty in tracking all inputs/outputs. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### List Prepend Function Source: https://github.com/bitsdojo/bitsdojo_window/blob/master/bitsdojo_window/example/linux/flutter/CMakeLists.txt A custom CMake function to prepend a prefix to each element of a list. This is used as a workaround for older CMake versions that do not support the list(TRANSFORM ... PREPEND ...) command. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.