Skip to content

feat(widgets): let the platform drive caption button hover and press - #608

Open
palmoni5 wants to merge 1 commit into
leanflutter:mainfrom
palmoni5:upstream/caption-button-external-state
Open

palmoni5 wants to merge 1 commit into
leanflutter:mainfrom
palmoni5:upstream/caption-button-external-state

Conversation

@palmoni5

Copy link
Copy Markdown

What

WindowCaptionButton gets two optional parameters, hovered and pressed (default false). When either one is set, the button shows that look even though Flutter itself does not see the pointer.

Why

On Windows 11 the Snap Layouts flyout (#122) opens only when the top-level window answers HTMAXBUTTON to WM_NCHITTEST over the maximize button. From then on the pointer belongs to the system: Flutter gets WM_MOUSELEAVE, and its MouseRegion drops the hover state. The app gets hover, press and click back from the non-client messages (WM_NCMOUSEMOVE, WM_NCLBUTTONDOWN/UP), but there was no way to show that state on the button.

Usage:

WindowCaptionButton.maximize(
  onPressed: windowManager.maximize,
  hovered: hoveredBySystem,
  pressed: pressedBySystem,
)

Tests

test/window_caption_button_test.dart covers: the idle look, the hover look with no pointer, pressed winning over hovered, and the close button's own hover color.

Note: flutter pub get on main needs Flutter 3.50, so I ran the same test on the identical change in the 0.5.2 code, where it passes (4/4). The change to the code is the same on both.

WindowCaptionButton gains hovered and pressed. They show the hover or
pressed look when the pointer is handled outside Flutter, such as a
Windows 11 maximize button that reports HTMAXBUTTON so the system opens
Snap Layouts (leanflutter#122).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant