Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Support Windows Transparent Title Bar (#1578)
* feat: support windows transparent title bar. 1. Add windows transparent title bar. 2. Move macOS special window adaption to MacOSWindowFrame.kt. 3. Refactor WindowsWindowUtils.kt partially. * Fix: Cache the HitTestResult constructor Cache the `HitTestResult` constructor to avoid reflection overhead on every hit test. * update nc_cal_size behavior * Update some comments. * Fix: Remove some unnecessary reflection invoke. * Remove println in LayoutHitTestOwner.kt * Remove LaunchedEffect and directly update title bar theme The `LaunchedEffect` used to update the title bar theme based on dark mode settings and system theme has been removed. The title bar theme is now updated directly, eliminating the need for a coroutine scope. * Refactor: Simplify window state flows in WindowsWindowUtils Simplify the `windowIsActive` and `windowAccentColor` flows in `WindowsWindowUtils` by using `flowOf` instead of `flow` for emitting null or default values. This makes the code more concise and readable. * Refactor: Use `isTopRight()` function for window insets This commit refactors the code to use the `isTopRight()` function for checking if window insets are on the top right. This simplifies the logic and makes the code more readable. * Fix: Handle null titleBarController in DarkCaptionButtonAppearance The change handles the case when titleBarController is null in DarkCaptionButtonAppearance by returning early. * Add comments to clarify usage of TitleBarThemeController * Refactor: Update desktop hit test to use _layersCopyCache Update the desktop hit test implementation to use the `_layersCopyCache` field instead of the `layers` field. This ensures that the hit test is performed on the correct set of layers and improves performance. * Fix: Avoid title bar buttons hit test interference This change avoids title bar buttons hit test interference by excluding AbstractClickableNodes and HoverableNodes from hit test results. This ensures that pointer input for Material 3 components is detected correctly. * Fix: Handle null layoutHitTestOwner in WindowsWindowFrame The change handles the case when layoutHitTestOwner is null in WindowsWindowFrame by returning early and calling the content function. * Refactor: Remove window hit test constants in WindowsWindowUtils. This change improves the organization of the code and makes it more maintainable. * Refactor: Update TitleBarWindowProc post ncbutton message logic the `SkiaLayerHitTestWindowProc` class is now internal and its `contentHandle` property is exposed for access. * Refactor: Move windowsBuildNumber() to WindowsWindowUtils Move the `windowsBuildNumber()` function to `WindowsWindowUtils` to avoid redundant code and improve maintainability. Also draw a fake top border when window is inactive on Windows version less than 22000 (Windows 11). * Mark some raw platform methods in WindowUtils. * Apply window title property only when dependencies changes. * Fix: Draw fake top border when window is inactive on Windows version less than 22000 (Windows 11) This commit fixes the issue where the top border of the window is not drawn correctly when the window is inactive on Windows versions less than 22000 (Windows 11). It achieves this by drawing a fake top border using `drawLine` when the window is inactive and the Windows version is less than 22000. The color of the fake border is determined based on whether the window frame is colorful and the window's active state. If the window frame is colorful and the window is active, the accent color is used. If the window frame is not colorful or the window is inactive, a default color is used. * Fix: Correct top padding calculation for maximized windows on Windows The top padding calculation for maximized windows on Windows has been corrected. Previously, it was not taking into account the frameX value, which could result in incorrect padding. This change ensures that the top padding is calculated correctly, even when the window is maximized. * Refactor: Update `hitTest` logic in `WindowsWindowUtils` The `hitTest` logic in `WindowsWindowUtils` has been updated to improve window resizing behavior. - Add `hitTestWindowResizerBorder` method to determine if the cursor is within the window resizer border. - Call `hitTestWindowResizerBorder` before `childHitTest` and only call it if the window is not maximized. - Update `WM_NCHITTEST` message logic. - Return `HTNOWHERE` when `hitTestWindowResizerBorder` is not triggered. - `hitTestResult` will use the result of `callResult.toInt()` from `CallWindowProc` in some cases. * Refactor: Move window hit test constants to WindowsWindowUtils This commit moves the window hit test constants (such as `HTCLIENT`, `HTMAXBUTTON`, etc.) to `WindowsWindowUtils` for better organization and accessibility. This change also update the usages of these constants in `WindowsWindowFrame` to use the new locations. * Refactor: Improve Windows title bar and fix maximized window padding - Refactor `WindowsWindowUtils` to calculate and apply correct padding for maximized windows. - Add `NCCalcSizeParams` to `TitleBarWindowProc` to handle window frame and padding calculations. - Workaround background erase. - Hide and show window in init to solve background erase. - Remove top border fix workaround in `WindowsWindowFrame`. - Update `isWindowInMaximized()` function to `WindowsWindowUtils`. - Update title bar logic in `TitleBarWindowProc` to support maximized windows. - The behavior of full screen is now call `WM_NCCALCSIZE` in `TitleBarWindowProc`. - Remove the wrong window inset padding. * Refactor: Use system accent color for title bar caption buttons on Windows This commit refactors the title bar caption buttons on Windows to use the system accent color when available. If the system's accent color is enabled, the title bar buttons will use the accent color as their background. Otherwise, they will use the default colors. Also use `shellCloseColor` for Close button when the accent color is available. * Refactor: Update `LayoutHitTestOwner` to use `ComposeSceneContext` - Update `rememberLayoutHitTestOwner` to use `LocalComposeSceneContext` instead of `LocalComposeScene`. - Change `scene::class.qualifiedName` to `scene::class.java.canonicalName` for class name comparison. * Refactor: Refactor `WindowsWindowFrame` and add `WindowsWindowFrameState` - Introduce `WindowsWindowFrameState` to manage window frame state, such as title bar visibility, caption button rects, and window insets. - Move the logic of extending the window content to the title bar into `ExtendToTitleBar`. - Move caption button colors logic to `WindowsWindowFrameState.collectCaptionButtonColors`. - Add `rememberFontIconFamily` function to get the windows system font icon. - Update `hitTest` logic to be within `WindowsWindowFrameState`. - Call `collectWindowIsActive()` in `WindowsWindowFrameState`. - Move `windowIsActive` flow collect logic to `WindowsWindowFrameState`. - Remove the dependency between `layoutHitTestOwner` and `WindowsWindowFrame`. - Remove redundant `captionButtonThemeController` and `isTitleBarVisible`. - Update the visibility of `WindowsWindowFrame`. - Update the title bar visibility logic in `WindowsWindowFrame`. - Hide title bar if window is full screen mode and title bar is not hovered. - Update `CaptionButtonRow` parameters to use `frameState` instead of `isActive` and `layoutHitTestOwner`. * Refactor: Update title bar theme logic with stack-based approach - Introduce a `TitleBarThemeController` to manage the title bar's dark mode theme. - Implement a stack-based approach to manage the title bar theme requests, allowing multiple components to request changes. - Update `DarkCaptionButtonAppearance` to request a dark theme when active and remove the request on dispose. - Add tests for `DarkCaptionButtonAppearance` to verify theme behavior. - Update `AniDesktop` to use the `TitleBarThemeController` to set the window title bar theme. - Remove direct theme setting from `TitleBarThemeController`. * Update comment * Refactor: Rename DarkCaptionButtonAppearance to OverrideCaptionButtonAppearance This commit renames `DarkCaptionButtonAppearance` to `OverrideCaptionButtonAppearance` for better clarity and to support overriding the default caption button appearance based on the application theme. - Rename `DarkCaptionButtonAppearance` to `OverrideCaptionButtonAppearance` in common, desktop, ios, and android modules. - Add `isDark` parameter to `OverrideCaptionButtonAppearance` to allow the app to override caption buttons based on light/dark mode. - Update `OverrideCaptionButtonAppearance` behavior: caption buttons will use the theme requested by the caller of `OverrideCaptionButtonAppearance` if `isDark` is true. - Update `EpisodePage` and `AniDesktop` to use `OverrideCaptionButtonAppearance` and set `isDark` as needed. - Update `OverrideCaptionButtonAppearanceTest` to reflect the changes. * Refactor: Improve Desktop Title Bar Integration - Add `WindowInsets.desktopTitleBar` to provide proper window insets for the desktop title bar. - Add `consumeWindowInsets` in `VideoScaffold` for better integration with the desktop title bar. - Add `windowInsets` parameters in `EpisodePage` to pass windowInsets to `VideoScaffold`. - Add `pointerInput` Modifier for title bar in `VideoScaffold` to skip layout hit test. - Use `Spacer` to add the title bar padding in `VideoScaffold` instead of using `contentWindowInsets`. * update comments * remove WindowsWindowUtils from CaptionButtonRow. --------- Co-authored-by: StageGuard <[email protected]>
- Loading branch information