Skip to content

Linux/Wayland new feature: Accept native parent window handle - #153

Merged
btzy merged 4 commits into
masterfrom
nativewindow-wayland
Feb 14, 2026
Merged

Linux/Wayland new feature: Accept native parent window handle#153
btzy merged 4 commits into
masterfrom
nativewindow-wayland

Conversation

@btzy

@btzy btzy commented Dec 6, 2024

Copy link
Copy Markdown
Owner

#136 added support for passing a parent window handle, ensuring that the file dialog always stays on top of the parent window and other platform-specific effects. Support was not added for Wayland then, due to implementation complexity and the scarcity of good documentation for the unstable xdg-foreign protocol for Wayland. This PR adds this missing support, using the xdg_foreign_unstable_v1 protocol. (There is a xdg_foreign_unstable_v2 protocol, but it seems that all platforms supporting v2 also support v1.)

Under Wayland, a client cannot simply hand over a window handle to another client. The sending client calls a Wayland function that takes a window handle and returns a string token representing it (known as exporting the window), and then sends that token over to the receiving client. The receiving client then calls another Wayland function that takes the string token and returns a "foreign" window handle (known as importing the window). The receiving client can then make this "foreign" window the transient parent of its own windows. On Portal, the receiving client is a different process (the xdg-desktop-portal implementor); on GTK, the receiving client is wrapped in a GdkDisplay on the same process.

Due to the need to call a Wayland function, Native File Dialog Extended now depends on the wayland-protocols repository (https://gitlab.freedesktop.org/wayland/wayland-protocols) as a git submodule (checked out to v1.47, but it shouldn't really matter much since Wayland protocols are meant to be backward compatible). New CMake feature flags NFD_X11 and NFD_WAYLAND have also been added to control whether the library is built with X11 and Wayland support respectively. By default both X11 and Wayland are supported, and this will lead to a runtime dependency on libwayland-client.

The GTK implementation has also been adjusted somewhat to do things more correctly. Before the dialog is realized (i.e. is made into a real GdkWindow), it needs to be told the GdkScreen to use (which can be any GdkScreen that uses the correct display server (X11 or Wayland)), but we can only set the transient parent after realization.

  • Portal
  • GTK

Note: Under XWayland, window parenting does not work (it behaves as if you did not pass a parent window handle). It behaves this way on both GTK and Portal. I'm not sure why, but since this is the behaviour for Portal, it's probably a limitation of XWayland.

Note: On GLFW < 3.4, the GLFW library on Linux either comes with X11 or Wayland, but not both. This means that on a system that supports both X11 and Wayland, an application using GLFW < 3.4 will only work with one display server.

@btzy
btzy force-pushed the nativewindow-wayland branch 9 times, most recently from e703e7a to 4c40579 Compare December 9, 2024 17:44
@btzy
btzy force-pushed the nativewindow-wayland branch from 4c40579 to cdb7b25 Compare January 1, 2025 17:11
@btzy
btzy force-pushed the nativewindow-wayland branch 6 times, most recently from 373c0f7 to b39eea4 Compare March 15, 2025 10:45
@btzy
btzy force-pushed the master branch 2 times, most recently from 6fc3f6c to a1a4010 Compare March 15, 2025 16:17
@btzy
btzy force-pushed the nativewindow-wayland branch 7 times, most recently from 79af96c to 06096fa Compare March 16, 2025 06:06
@btzy
btzy force-pushed the nativewindow-wayland branch 2 times, most recently from ce1a059 to 0537750 Compare April 5, 2025 10:46
@btzy btzy mentioned this pull request Jan 6, 2026
@btzy
btzy force-pushed the nativewindow-wayland branch from c172bb4 to 266c283 Compare February 8, 2026 08:22
@btzy
btzy force-pushed the nativewindow-wayland branch from 266c283 to 853e207 Compare February 8, 2026 08:26
@btzy
btzy force-pushed the nativewindow-wayland branch 18 times, most recently from bd3856b to 5b20d54 Compare February 14, 2026 10:47
@btzy

btzy commented Feb 14, 2026

Copy link
Copy Markdown
Owner Author

Initially I said ...

This PR will currently cause NFDe to have a runtime dependency on wayland-client, which provide the exporting and importing APIs. This is undesirable as it will cause applications using NFDe to fail to start on a pure X11 system.

... but I'm not really sure this is actually a concern now. Is it the package manager's responsibility to serve the correct package?

Turns out this is not a concern, and most Linux applications simply link both X11 and Wayland libraries.

@btzy
btzy force-pushed the nativewindow-wayland branch from 5b20d54 to 74a6900 Compare February 14, 2026 11:26
@btzy
btzy merged commit 59d2bbf into master Feb 14, 2026
42 checks passed
@btzy
btzy deleted the nativewindow-wayland branch June 14, 2026 15:08
Tom94 pushed a commit to mitsuba-renderer/nativefiledialog-extended that referenced this pull request Jun 29, 2026
* Linux/Wayland: Support parent windows

* Set screen from display server

* Update readme

* Add GLFW3 test
@wolfpld

wolfpld commented Jul 2, 2026

Copy link
Copy Markdown

(There is a xdg_foreign_unstable_v2 protocol, but it seems that all platforms supporting v2 also support v1.)

This is not true.

$ WAYLAND_DEBUG=1 ./tracy-profiler 2>&1|grep exporter
[2306841.693] {Default Queue} wl_registry#2.global(35, "zxdg_exporter_v2", 1)
[2306861.541] wl_registry#20.global(35, "zxdg_exporter_v2", 1)
[2306879.993] wl_registry#24.global(35, "zxdg_exporter_v2", 1)
[2306933.552] {Default Queue} wl_registry#36.global(35, "zxdg_exporter_v2", 1)

(KDE 6.7.2)

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.

2 participants