Skip to content

Resolve Windows GetCurrent across threads and hidden startup windows - #95

Merged
lijy91 merged 1 commit into
mainfrom
fix/windows-get-current-issue-39
Nov 19, 2026
Merged

lijy91 merged 1 commit into
mainfrom
fix/windows-get-current-issue-39

Conversation

@lijy91

@lijy91 lijy91 commented Nov 19, 2026

Copy link
Copy Markdown
Member

Summary

  • Filter EnumWindowsCallback (WindowManager::GetAll()) with IsOwnProcessWindow(hwnd) so GetAll() only enumerates top-level windows owned by the current process instead of foreign processes' windows.
  • Update WindowManager::GetCurrent() on Windows so when GetActiveWindow() is null or not owned by this process (for example when called from Flutter's separate Dart UI isolate thread, or while the main window is still hidden before the first frame during waitUntilReadyToShow), it falls back to:
    1. Own-process GetForegroundWindow() (GA_ROOT),
    2. Tracked g_focused_hwnd,
    3. EnumWindows selecting the current process's first visible top-level window or first hidden normal top-level window.
  • Add regression tests in tests/window_manager_ui_thread_windows_test.cpp covering cross-thread GetCurrent(), hidden startup GetCurrent() with ID stability across ShowWindow, and own-process filtering in GetAll().

Related to libnativeapi/nativeapi#39.

Verification

  • Passed window_cross_thread_dialog_windows_test, window_property_changed_test, window_manager_ui_thread_windows_test, window_controls_test, window_startup_maximize_windows_test, window_close_windows_test, and run_on_main_thread_windows_test on Windows.
  • Verified with window_manager on Windows: cross-thread owned IFileOpenDialog opens in ~0.36s (vs ~20.32s in nativeapi 0.6.1) and cross-thread getCurrent() resolves the app window instead of null.

@lijy91
lijy91 merged commit a3af6df into main Nov 19, 2026
9 of 10 checks passed
@lijy91
lijy91 deleted the fix/windows-get-current-issue-39 branch November 19, 2026 10:46
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