feat: add SetWillCloseHook to WindowManager - #51
Open
brennodewinter wants to merge 1 commit into
Open
Conversation
Adds a WindowWillCloseHook following the same pattern as the existing WindowWillShowHook and WindowWillHideHook. This allows FFI consumers (notably Flutter apps via nativeapi-flutter) to intercept window close and decide whether to proceed — needed for "unsaved changes" dialogs. Changes per layer: - window_manager.h: WindowWillCloseHook typedef, SetWillCloseHook, HasWillCloseHook, HandleWillClose, CallOriginalClose declarations. - macOS: swizzles performClose: on NSWindow (same pattern as makeKeyAndOrderFront: and orderOut:). CallOriginalClose calls the swizzled original. - Linux: adds a delete-event emission hook alongside show/hide. CallOriginalClose destroys the toplevel GtkWidget. - Windows: stores the hook; CallOriginalClose posts WM_CLOSE. Full WM_CLOSE interception (WH_CBT or window subclassing) is left as a follow-up — noted with a ponytail: comment. - C API: native_window_manager_set_will_close_hook, has_will_close_hook, handle_will_close, call_original_close. - Tests: window_manager_hook_test — verifies set/clear, dispatch, no-hook safety, and coexistence with show/hide hooks. All 6 tests pass on macOS. Build verified on macOS (CMake + make).
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
WindowWillCloseHooktoWindowManager, following the exact same pattern as the existingWindowWillShowHookandWindowWillHideHook. This allows FFI consumers (notably Flutter apps vianativeapi-flutter) to intercept window close and decide whether to proceed — needed for "unsaved changes" dialogs before closing.Changes per layer
window_manager.h:WindowWillCloseHooktypedef,SetWillCloseHook,HasWillCloseHook,HandleWillClose,CallOriginalClosedeclarations.performClose:onNSWindow(same pattern asmakeKeyAndOrderFront:andorderOut:).CallOriginalClosecalls the swizzled original.delete-eventemission hook alongside show/hide.CallOriginalClosedestroys the toplevelGtkWidget.CallOriginalClosepostsWM_CLOSE. FullWM_CLOSEinterception (WH_CBTor window subclassing) is left as a follow-up — noted with aponytail:comment naming the ceiling and upgrade path.native_window_manager_set_will_close_hook,has_will_close_hook,handle_will_close,call_original_close.window_manager_hook_test— verifies set/clear, dispatch with correct ID, no-hook safety, and coexistence with show/hide hooks.How the hook works
The pattern is identical to will-show/will-hide:
SetWillCloseHook(callback)— platform installs swizzle/emission hook.HandleWillClose(id)and returns without calling the original.CallOriginalClose(id)to proceed, or do nothing to prevent close.Test plan
window_manager_hook_test— 4 tests, all pass on macOSUse case
OciDeck (a LibreKAT presentation tool) needs
setPreventCloseto show an "unsaved changes" dialog before the window closes. The current workaround useswindow_manager'ssetPreventClose, but OciDeck is migrating tonativeapi. This hook is the missing piece.