From 72fe01f513ba28a3f8c4b90a77b479a60972286a Mon Sep 17 00:00:00 2001 From: r-zakarya <82443831+r-zakarya@users.noreply.github.com> Date: Sat, 25 Jul 2026 22:50:26 +0100 Subject: [PATCH] fix(window): don't filter the hook on the form HWND MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hook installed but never fired: an FMX app owns TWO top-level windows — the form and the taskbar proxy (the one FindFMXAppWindow digs out in PM.Bridge) — and Win+D minimises the proxy. Comparing the event HWND against the form handle rejected every event. Dropped the comparison; the hook is already scoped to our process and WebView2 lives in separate ones, so any window event arriving here is ours. Logs the install result and each event's HWND so a silent failure is visible next time. Co-Authored-By: Claude Opus 4.8 --- delphi-backend/UMainForm.pas | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/delphi-backend/UMainForm.pas b/delphi-backend/UMainForm.pas index ce171b1..1459258 100644 --- a/delphi-backend/UMainForm.pas +++ b/delphi-backend/UMainForm.pas @@ -213,6 +213,8 @@ begin FWinEventHook := SetWinEventHook( EVENT_SYSTEM_MINIMIZESTART, EVENT_SYSTEM_MINIMIZEEND, 0, @WinStateEventProc, GetCurrentProcessId, 0, WINEVENT_OUTOFCONTEXT); + LogLine('[winstate] minimise hook installed=' + + BoolToStr(FWinEventHook <> 0, True)); FRestoring := False; OnResize := FormResizeTrackState; @@ -1561,7 +1563,13 @@ procedure WinStateEventProc(hWinEventHook: THandle; AEvent: DWORD; AWnd: HWND; idObject, idChild: LongInt; idEventThread, dwmsEventTime: DWORD); stdcall; begin if (idObject <> OBJID_WINDOW) or (AWnd = 0) or (MainForm = nil) then Exit; - if AWnd <> WindowHandleToPlatform(MainForm.Handle).Wnd then Exit; + // No HWND filter: an FMX app owns TWO top-level windows — the form and the + // taskbar proxy (see FindFMXAppWindow in PM.Bridge) — and Win+D minimises + // the proxy, which an equality test against the form handle rejected. The + // hook is already scoped to our own process, and WebView2 lives in separate + // processes, so anything arriving here is ours. + MainForm.LogLine(Format('[winstate] hook event=%d hwnd=%d form=%d', + [AEvent, AWnd, WindowHandleToPlatform(MainForm.Handle).Wnd])); if AEvent = EVENT_SYSTEM_MINIMIZESTART then MainForm.WinStateMinimizeStart else if AEvent = EVENT_SYSTEM_MINIMIZEEND then MainForm.WinStateMinimizeEnd; end;