Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: Accept native parent window handle and implement glue code to major platform abstraction frameworks #136

Merged
merged 1 commit into from
Jun 23, 2024

Conversation

btzy
Copy link
Owner

@btzy btzy commented May 12, 2024

On at least Windows and Linux (both GTK and Portal), the dialog misbehaves in a noticeable way when the parent window handle is not passed to the underlying platform-specific API. The macOS (Cocoa) backend guesses the parent from the key window (the window receiving keyboard events). The parent window handle, however, is platform-specific (and on Linux, also specific to the windowing system) (e.g. HWND on Windows, NSWindow* on macOS, Window on X11, wl_surface* on Wayland), which means that NFDe necessarily needs to expose an API that is not fully platform-agnostic, if it is to allow users to pass it the parent window handle.

This is acceptable if the user is not using any platform abstraction framework (e.g. SDL2 or GLFW), since the user must already be writing platform-specific code.

However, a significant benefit of NFDe is realised when the user also uses a platform abstraction framework, as it allows them to write code in a platform-agnostic manner throughout their codebase. It would be unwieldy if they had to write platform-specific code to glue NFDe to their framework.

Platform abstraction frameworks typically define their own type to represent a window handle (e.g SDL_Window* on SDL2, GLFWwindow* on GLFW), and it is possible to get the native window handle from it (via platform-specific APIs). By implementing the conversions from the window type as an optional component of NFDe, it frees the user from having to write their own glue code.

This PR adds a new argument to all the main APIs (OpenFile, OpenFileMultiple, SaveFile, PickFolder, PickFolderMultiple) to take a native window handle, which can be a Windows, macOS, or X11 handle. Wayland is not yet supported as it looks complicated and documentation is scant, though it will probably be implemented in the future. This PR also implements framework-specific window handle conversion functions in optional separate headers.

Resolves #90.
Resolves #126.

@btzy btzy added this to the New API milestone May 12, 2024
@btzy btzy force-pushed the pickfoldermultiple branch from edd69c3 to ca6ae11 Compare May 12, 2024 17:11
@btzy btzy changed the base branch from pickfoldermultiple to master May 16, 2024 16:55
@btzy btzy force-pushed the nativewindow branch 21 times, most recently from a633967 to ce8c00d Compare May 20, 2024 17:48
@btzy btzy force-pushed the nativewindow branch 5 times, most recently from 4586369 to edcfc7c Compare May 25, 2024 17:03
@btzy btzy force-pushed the nativewindow branch 10 times, most recently from 32112a1 to 7c1cf3b Compare June 4, 2024 14:59
@btzy btzy force-pushed the nativewindow branch 10 times, most recently from a973ad6 to 9ca8a7b Compare June 18, 2024 18:25
@btzy btzy force-pushed the nativewindow branch 2 times, most recently from 35ae5d6 to 401f455 Compare June 23, 2024 09:44
@btzy btzy marked this pull request as ready for review June 23, 2024 09:57
@btzy btzy changed the base branch from master to pickfoldermultiple June 23, 2024 10:02
@btzy btzy changed the base branch from pickfoldermultiple to master June 23, 2024 10:03
This is necessary for platforms to present the dialog properly, e.g. ensuring that the dialog never goes behind the parent window.
@btzy btzy merged commit 1e20206 into master Jun 23, 2024
32 checks passed
@btzy btzy deleted the nativewindow branch June 23, 2024 12:32
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.

Don't use nullptr in fileOpenDialog->Show File dialogs do not block application UI
1 participant