Skip to content

Commit d27292f

Browse files
committed
Added Wayland support to NFD and fixed SDL3 header portability
1 parent 3f70a05 commit d27292f

5 files changed

Lines changed: 268 additions & 8 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Copyright © 2008-2013 Kristian Høgsberg
2+
Copyright © 2010-2013 Intel Corporation
3+
Copyright © 2013 Rafael Antognolli
4+
Copyright © 2013 Jasper St. Pierre
5+
Copyright © 2014 Jonas Ådahl
6+
Copyright © 2014 Jason Ekstrand
7+
Copyright © 2014-2015 Collabora, Ltd.
8+
Copyright © 2015 Red Hat Inc.
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice (including the next
18+
paragraph) shall be included in all copies or substantial portions of the
19+
Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27+
DEALINGS IN THE SOFTWARE.
28+
29+
---
30+
31+
The above is the version of the MIT "Expat" License used by X.org:
32+
33+
http://cgit.freedesktop.org/xorg/xserver/tree/COPYING
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<protocol name="xdg_foreign_unstable_v1">
3+
4+
<copyright>
5+
Copyright © 2015-2016 Red Hat Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a
8+
copy of this software and associated documentation files (the "Software"),
9+
to deal in the Software without restriction, including without limitation
10+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11+
and/or sell copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice (including the next
15+
paragraph) shall be included in all copies or substantial portions of the
16+
Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24+
DEALINGS IN THE SOFTWARE.
25+
</copyright>
26+
27+
<description summary="Protocol for exporting xdg surface handles">
28+
This protocol specifies a way for making it possible to reference a surface
29+
of a different client. With such a reference, a client can, by using the
30+
interfaces provided by this protocol, manipulate the relationship between
31+
its own surfaces and the surface of some other client. For example, stack
32+
some of its own surface above the other clients surface.
33+
34+
In order for a client A to get a reference of a surface of client B, client
35+
B must first export its surface using xdg_exporter.export. Upon doing this,
36+
client B will receive a handle (a unique string) that it may share with
37+
client A in some way (for example D-Bus). After client A has received the
38+
handle from client B, it may use xdg_importer.import to create a reference
39+
to the surface client B just exported. See the corresponding requests for
40+
details.
41+
42+
A possible use case for this is out-of-process dialogs. For example when a
43+
sandboxed client without file system access needs the user to select a file
44+
on the file system, given sandbox environment support, it can export its
45+
surface, passing the exported surface handle to an unsandboxed process that
46+
can show a file browser dialog and stack it above the sandboxed client's
47+
surface.
48+
49+
Warning! The protocol described in this file is experimental and backward
50+
incompatible changes may be made. Backward compatible changes may be added
51+
together with the corresponding interface version bump. Backward
52+
incompatible changes are done by bumping the version number in the protocol
53+
and interface names and resetting the interface version. Once the protocol
54+
is to be declared stable, the 'z' prefix and the version number in the
55+
protocol and interface names are removed and the interface version number is
56+
reset.
57+
</description>
58+
59+
<interface name="zxdg_exporter_v1" version="1">
60+
<description summary="interface for exporting surfaces">
61+
A global interface used for exporting surfaces that can later be imported
62+
using xdg_importer.
63+
</description>
64+
65+
<request name="destroy" type="destructor">
66+
<description summary="destroy the xdg_exporter object">
67+
Notify the compositor that the xdg_exporter object will no longer be
68+
used.
69+
</description>
70+
</request>
71+
72+
<request name="export">
73+
<description summary="export a surface">
74+
The export request exports the passed surface so that it can later be
75+
imported via xdg_importer. When called, a new xdg_exported object will
76+
be created and xdg_exported.handle will be sent immediately. See the
77+
corresponding interface and event for details.
78+
79+
A surface may be exported multiple times, and each exported handle may
80+
be used to create an xdg_imported multiple times. Only xdg_surface
81+
surfaces may be exported.
82+
</description>
83+
<arg name="id" type="new_id" interface="zxdg_exported_v1"
84+
summary="the new xdg_exported object"/>
85+
<arg name="surface" type="object" interface="wl_surface"
86+
summary="the surface to export"/>
87+
</request>
88+
</interface>
89+
90+
<interface name="zxdg_importer_v1" version="1">
91+
<description summary="interface for importing surfaces">
92+
A global interface used for importing surfaces exported by xdg_exporter.
93+
With this interface, a client can create a reference to a surface of
94+
another client.
95+
</description>
96+
97+
<request name="destroy" type="destructor">
98+
<description summary="destroy the xdg_importer object">
99+
Notify the compositor that the xdg_importer object will no longer be
100+
used.
101+
</description>
102+
</request>
103+
104+
<request name="import">
105+
<description summary="import a surface">
106+
The import request imports a surface from any client given a handle
107+
retrieved by exporting said surface using xdg_exporter.export. When
108+
called, a new xdg_imported object will be created. This new object
109+
represents the imported surface, and the importing client can
110+
manipulate its relationship using it. See xdg_imported for details.
111+
</description>
112+
<arg name="id" type="new_id" interface="zxdg_imported_v1"
113+
summary="the new xdg_imported object"/>
114+
<arg name="handle" type="string"
115+
summary="the exported surface handle"/>
116+
</request>
117+
</interface>
118+
119+
<interface name="zxdg_exported_v1" version="1">
120+
<description summary="an exported surface handle">
121+
An xdg_exported object represents an exported reference to a surface. The
122+
exported surface may be referenced as long as the xdg_exported object not
123+
destroyed. Destroying the xdg_exported invalidates any relationship the
124+
importer may have established using xdg_imported.
125+
</description>
126+
127+
<request name="destroy" type="destructor">
128+
<description summary="unexport the exported surface">
129+
Revoke the previously exported surface. This invalidates any
130+
relationship the importer may have set up using the xdg_imported created
131+
given the handle sent via xdg_exported.handle.
132+
</description>
133+
</request>
134+
135+
<event name="handle">
136+
<description summary="the exported surface handle">
137+
The handle event contains the unique handle of this exported surface
138+
reference. It may be shared with any client, which then can use it to
139+
import the surface by calling xdg_importer.import. A handle may be
140+
used to import the surface multiple times.
141+
</description>
142+
<arg name="handle" type="string" summary="the exported surface handle"/>
143+
</event>
144+
</interface>
145+
146+
<interface name="zxdg_imported_v1" version="1">
147+
<description summary="an imported surface handle">
148+
An xdg_imported object represents an imported reference to surface exported
149+
by some client. A client can use this interface to manipulate
150+
relationships between its own surfaces and the imported surface.
151+
</description>
152+
153+
<request name="destroy" type="destructor">
154+
<description summary="destroy the xdg_imported object">
155+
Notify the compositor that it will no longer use the xdg_imported
156+
object. Any relationship that may have been set up will at this point
157+
be invalidated.
158+
</description>
159+
</request>
160+
161+
<request name="set_parent_of">
162+
<description summary="set as the parent of some surface">
163+
Set the imported surface as the parent of some surface of the client.
164+
The passed surface must be a toplevel xdg_surface. Calling this function
165+
sets up a surface to surface relation with the same stacking and positioning
166+
semantics as xdg_surface.set_parent.
167+
</description>
168+
<arg name="surface" type="object" interface="wl_surface"
169+
summary="the child surface"/>
170+
</request>
171+
172+
<event name="destroyed">
173+
<description summary="the imported surface handle has been destroyed">
174+
The imported surface handle has been destroyed and any relationship set
175+
up has been invalidated. This may happen for various reasons, for
176+
example if the exported surface or the exported surface handle has been
177+
destroyed, if the handle used for importing was invalid.
178+
</description>
179+
</event>
180+
</interface>
181+
182+
</protocol>

libs/nfd/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.10)
2-
project(nativefiledialog-extended VERSION 1.2.1)
2+
project(nativefiledialog-extended VERSION 1.3.0)
33

44
set(nfd_ROOT_PROJECT OFF)
55
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
@@ -9,7 +9,7 @@ endif ()
99
option(BUILD_SHARED_LIBS "Build a shared library instead of static" OFF)
1010
option(NFD_BUILD_TESTS "Build tests for nfd" ${nfd_ROOT_PROJECT})
1111
option(NFD_BUILD_SDL2_TESTS "Build SDL2 tests for nfd" OFF)
12-
option(NFD_BUILD_SDL3_TESTS "Build SDL3 tests for nfd" OFF)
12+
option(NFD_BUILD_GLFW3_TESTS "Build GLFW3 tests for nfd" OFF)
1313
option(NFD_INSTALL "Generate install target for nfd" ${nfd_ROOT_PROJECT})
1414

1515
set(nfd_PLATFORM Undefined)
@@ -48,6 +48,6 @@ endif()
4848

4949
add_subdirectory(src)
5050

51-
if(${NFD_BUILD_TESTS} OR ${NFD_BUILD_SDL2_TESTS} OR ${NFD_BUILD_SDL3_TESTS})
51+
if(${NFD_BUILD_TESTS} OR ${NFD_BUILD_SDL2_TESTS} OR ${NFD_BUILD_GLFW3_TESTS})
5252
add_subdirectory(test)
5353
endif()

libs/nfd/src/CMakeLists.txt

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,33 @@ if(nfd_PLATFORM STREQUAL PLATFORM_LINUX)
1919
option(NFD_PORTAL "Use xdg-desktop-portal instead of GTK" OFF)
2020
if(NOT NFD_PORTAL)
2121
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
22-
message("Using GTK version: ${GTK3_VERSION}")
22+
message(STATUS "Using GTK version: ${GTK3_VERSION}")
2323
list(APPEND SOURCE_FILES nfd_gtk.cpp)
2424
else()
2525
pkg_check_modules(DBUS REQUIRED dbus-1)
26-
message("Using DBUS version: ${DBUS_VERSION}")
26+
message(STATUS "Using D-Bus version: ${DBUS_VERSION}")
2727
list(APPEND SOURCE_FILES nfd_portal.cpp)
2828
endif()
29+
30+
# for Linux, we support X11, Wayland, or both
31+
option(NFD_X11 "Support X11 on Linux" ON)
32+
option(NFD_WAYLAND "Support Wayland on Linux" ON)
33+
if(NFD_WAYLAND)
34+
pkg_check_modules(WAYLAND REQUIRED wayland-client)
35+
message(STATUS "Using Wayland version: ${WAYLAND_VERSION}")
36+
set(NFD_WAYLAND_PROTOCOL_XDG_FOREIGN ${CMAKE_CURRENT_SOURCE_DIR}/../3ps/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v1.xml)
37+
add_custom_command(
38+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.h
39+
COMMAND wayland-scanner client-header < ${NFD_WAYLAND_PROTOCOL_XDG_FOREIGN} > ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.h
40+
MAIN_DEPENDENCY ${NFD_WAYLAND_PROTOCOL_XDG_FOREIGN}
41+
)
42+
add_custom_command(
43+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.c
44+
COMMAND wayland-scanner private-code < ${NFD_WAYLAND_PROTOCOL_XDG_FOREIGN} > ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.c
45+
MAIN_DEPENDENCY ${NFD_WAYLAND_PROTOCOL_XDG_FOREIGN}
46+
)
47+
list(APPEND SOURCE_FILES ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.h ${CMAKE_CURRENT_BINARY_DIR}/xdg-foreign-unstable-v1.c)
48+
endif()
2949
endif()
3050

3151
if(nfd_PLATFORM STREQUAL PLATFORM_MACOS)
@@ -95,6 +115,21 @@ if(nfd_PLATFORM STREQUAL PLATFORM_LINUX)
95115
if(NFD_APPEND_EXTENSION)
96116
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_APPEND_EXTENSION)
97117
endif()
118+
119+
option(NFD_CASE_SENSITIVE_FILTER "Make filters case sensitive" OFF)
120+
if(NFD_CASE_SENSITIVE_FILTER)
121+
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_CASE_SENSITIVE_FILTER)
122+
endif()
123+
124+
if(NFD_X11)
125+
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_X11)
126+
endif()
127+
if(NFD_WAYLAND)
128+
target_include_directories(${TARGET_NAME} PRIVATE ${WAYLAND_INCLUDE_DIRS})
129+
target_link_libraries(${TARGET_NAME} PRIVATE ${WAYLAND_LINK_LIBRARIES})
130+
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_WAYLAND)
131+
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
132+
endif()
98133
endif()
99134

100135
if(nfd_PLATFORM STREQUAL PLATFORM_MACOS)
@@ -119,7 +154,7 @@ if(nfd_COMPILER STREQUAL COMPILER_CLANGCL)
119154
endif()
120155

121156
if(nfd_COMPILER STREQUAL COMPILER_GNU)
122-
target_compile_options(${TARGET_NAME} PRIVATE -nostdlib -fno-exceptions -fno-rtti)
157+
target_compile_options(${TARGET_NAME} PRIVATE -nostdlib -fno-exceptions $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
123158
endif()
124159

125160
set_target_properties(${TARGET_NAME} PROPERTIES
@@ -129,6 +164,14 @@ set_target_properties(${TARGET_NAME} PROPERTIES
129164

130165
if (NFD_INSTALL)
131166
include(GNUInstallDirs)
167+
include(CMakePackageConfigHelpers)
168+
169+
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}-config-version.cmake"
170+
VERSION "${PROJECT_VERSION}"
171+
COMPATIBILITY SameMajorVersion
172+
)
173+
174+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}-config-version.cmake" DESTINATION lib/cmake/${TARGET_NAME})
132175

133176
install(TARGETS ${TARGET_NAME} EXPORT ${TARGET_NAME}-export
134177
LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}

libs/nfd/src/include/nfd_sdl3.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ NFD_INLINE bool NFD_SetDisplayPropertiesFromSDLWindow(SDL_Window* window) {
3333
SDL_PropertiesID props = SDL_GetWindowProperties(window);
3434
if (!props) return false;
3535

36+
#if defined(SDL_PLATFORM_UNIX) && !defined(SDL_PLATFORM_APPLE)
3637
const char* driver = SDL_GetCurrentVideoDriver();
3738
if (driver && SDL_strcmp(driver, "wayland") == 0) {
38-
wl_display* display = (wl_display*)SDL_GetPointerProperty(
39+
struct wl_display* display = (struct wl_display*)SDL_GetPointerProperty(
3940
props, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL
4041
);
4142
if (display) {
4243
NFD_SetWaylandDisplay(display);
4344
return true;
4445
}
4546
}
47+
#endif
4648

4749
return false;
4850
}
@@ -103,4 +105,4 @@ NFD_INLINE nfdresult_t NFD_GetNativeWindowFromSDLWindow(
103105
}
104106
#endif // __cplusplus
105107

106-
#endif // _NFD_SDL2_H
108+
#endif // _NFD_SDL3_H

0 commit comments

Comments
 (0)