Skip to content

Commit cdb7b25

Browse files
committed
Linux/Wayland: Support parent windows
1 parent 29e3bcb commit cdb7b25

File tree

7 files changed

+212
-17
lines changed

7 files changed

+212
-17
lines changed

.github/workflows/cmake.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,50 +38,63 @@ jobs:
3838

3939
build-ubuntu:
4040

41-
name: Ubuntu ${{ matrix.os.name }} - ${{ matrix.compiler.name }}, ${{ matrix.portal.name }}, ${{ matrix.autoappend.name }}, ${{ matrix.shared_lib.name }}, C++${{ matrix.cppstd }}
41+
name: Ubuntu ${{ matrix.os.name }} - ${{ matrix.compiler.name }}, ${{ matrix.portal.name }}, ${{ matrix.wayland.name }}, ${{ matrix.autoappend.name }}, ${{ matrix.shared_lib.name }}, C++${{ matrix.cppstd }}
4242
runs-on: ${{ matrix.os.label }}
4343

4444
strategy:
4545
matrix:
4646
os: [ {label: ubuntu-latest, name: latest}, {label: ubuntu-20.04, name: 20.04} ]
4747
portal: [ {flag: OFF, dep: libgtk-3-dev, name: GTK}, {flag: ON, dep: libdbus-1-dev, name: Portal} ] # The NFD_PORTAL setting defaults to OFF (i.e. uses GTK)
4848
autoappend: [ {flag: OFF, name: NoAppendExtn} ] # By default the NFD_PORTAL mode does not append extensions, because it breaks some features of the portal
49+
wayland: [ {flag: OFF, dep: , name: NoWayland} ]
4950
compiler: [ {c: gcc, cpp: g++, name: GCC}, {c: clang, cpp: clang++, name: Clang} ] # The default compiler is gcc/g++
5051
cppstd: [20, 11]
5152
shared_lib: [ {flag: OFF, name: Static} ]
5253
include:
5354
- os: {label: ubuntu-latest, name: latest}
5455
portal: {flag: ON, dep: libdbus-1-dev, name: Portal}
5556
autoappend: {flag: ON, name: AutoAppendExtn}
57+
wayland: {flag: OFF, dep: , name: NoWayland}
5658
compiler: {c: gcc, cpp: g++, name: GCC}
5759
cppstd: 11
5860
shared_lib: {flag: OFF, name: Static}
5961
- os: {label: ubuntu-latest, name: latest}
6062
portal: {flag: ON, dep: libdbus-1-dev, name: Portal}
6163
autoappend: {flag: ON, name: AutoAppendExtn}
64+
wayland: {flag: OFF, dep: , name: NoWayland}
6265
compiler: {c: clang, cpp: clang++, name: Clang}
6366
cppstd: 11
6467
shared_lib: {flag: OFF, name: Static}
6568
- os: {label: ubuntu-latest, name: latest}
6669
portal: {flag: ON, dep: libdbus-1-dev, name: Portal}
6770
autoappend: {flag: OFF, name: NoAppendExtn}
71+
wayland: {flag: OFF, dep: , name: NoWayland}
6872
compiler: {c: gcc, cpp: g++, name: GCC}
6973
cppstd: 11
7074
shared_lib: {flag: ON, name: Shared}
75+
- os: {label: ubuntu-latest, name: latest}
76+
portal: {flag: ON, dep: libdbus-1-dev, name: Portal}
77+
autoappend: {flag: OFF, name: NoAppendExtn}
78+
wayland: {flag: ON, dep: libwayland-dev libwayland-bin, name: Wayland}
79+
compiler: {c: gcc, cpp: g++, name: GCC}
80+
cppstd: 11
81+
shared_lib: {flag: ON, name: Static}
7182

7283
steps:
7384
- name: Checkout
7485
uses: actions/checkout@v4
86+
with:
87+
submodules: true
7588
- name: Install Dependencies
76-
run: sudo apt-get update && sudo apt-get install ${{ matrix.portal.dep }}
89+
run: sudo apt-get update && sudo apt-get install ${{ matrix.portal.dep }} ${{ matrix.wayland.dep }}
7790
- name: Configure
78-
run: mkdir build && mkdir install && cd build && cmake -DCMAKE_INSTALL_PREFIX="../install" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${{ matrix.compiler.c }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cpp }} -DCMAKE_CXX_STANDARD=${{ matrix.cppstd }} -DCMAKE_C_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DNFD_PORTAL=${{ matrix.portal.flag }} -DNFD_APPEND_EXTENSION=${{ matrix.autoappend.flag }} -DBUILD_SHARED_LIBS=${{ matrix.shared_lib.flag }} -DNFD_BUILD_TESTS=ON ..
91+
run: mkdir build && mkdir install && cd build && cmake -DCMAKE_INSTALL_PREFIX="../install" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${{ matrix.compiler.c }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cpp }} -DCMAKE_CXX_STANDARD=${{ matrix.cppstd }} -DCMAKE_C_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wshadow -Werror -pedantic" -DNFD_WAYLAND=OFF -DNFD_PORTAL=${{ matrix.portal.flag }} -DNFD_APPEND_EXTENSION=${{ matrix.autoappend.flag }} -DBUILD_SHARED_LIBS=${{ matrix.shared_lib.flag }} -DNFD_BUILD_TESTS=ON ..
7992
- name: Build
8093
run: cmake --build build --target install
8194
- name: Upload test binaries
8295
uses: actions/upload-artifact@v4
8396
with:
84-
name: Ubuntu ${{ matrix.os.name }} - ${{ matrix.compiler.name }}, ${{ matrix.portal.name }}, ${{ matrix.autoappend.name }}, ${{ matrix.shared_lib.name }}, C++${{ matrix.cppstd }}
97+
name: Ubuntu ${{ matrix.os.name }} - ${{ matrix.compiler.name }}, ${{ matrix.portal.name }}, ${{ matrix.wayland.name }}, ${{ matrix.autoappend.name }}, ${{ matrix.shared_lib.name }}, C++${{ matrix.cppstd }}
8598
path: |
8699
build/src/*
87100
build/test/*

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "3ps/wayland-protocols"]
2+
path = 3ps/wayland-protocols
3+
url = https://gitlab.freedesktop.org/wayland/wayland-protocols.git

3ps/wayland-protocols

Submodule wayland-protocols added at 122a47a

src/CMakeLists.txt

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

3050
if(nfd_PLATFORM STREQUAL PLATFORM_MACOS)
@@ -94,6 +114,16 @@ if(nfd_PLATFORM STREQUAL PLATFORM_LINUX)
94114
if(NFD_APPEND_EXTENSION)
95115
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_APPEND_EXTENSION)
96116
endif()
117+
118+
if(NFD_X11)
119+
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_X11)
120+
endif()
121+
if(NFD_WAYLAND)
122+
target_include_directories(${TARGET_NAME} PRIVATE ${WAYLAND_INCLUDE_DIRS})
123+
target_link_libraries(${TARGET_NAME} PRIVATE ${WAYLAND_LINK_LIBRARIES})
124+
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_WAYLAND)
125+
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
126+
endif()
97127
endif()
98128

99129
if(nfd_PLATFORM STREQUAL PLATFORM_MACOS)
@@ -118,7 +148,7 @@ if(nfd_COMPILER STREQUAL COMPILER_CLANGCL)
118148
endif()
119149

120150
if(nfd_COMPILER STREQUAL COMPILER_GNU)
121-
target_compile_options(${TARGET_NAME} PRIVATE -nostdlib -fno-exceptions -fno-rtti)
151+
target_compile_options(${TARGET_NAME} PRIVATE -nostdlib -fno-exceptions $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
122152
endif()
123153

124154
set_target_properties(${TARGET_NAME} PROPERTIES

src/include/nfd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ enum {
105105
NFD_WINDOW_HANDLE_TYPE_COCOA = 2,
106106
// X11: handle is Window
107107
NFD_WINDOW_HANDLE_TYPE_X11 = 3,
108-
// Wayland support will be implemented separately in the future
108+
// Wayland: handle is wl_surface*
109+
NFD_WINDOW_HANDLE_TYPE_WAYLAND = 4,
109110
};
110111
// The native window handle. If using a platform abstraction framework (e.g. SDL2), this should be
111112
// obtained using the corresponding NFD glue header (e.g. nfd_sdl2.h).

src/include/nfd_sdl2.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ NFD_INLINE bool NFD_GetNativeWindowFromSDLWindow(SDL_Window* sdlWindow,
5959
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_X11;
6060
nativeWindow->handle = (void*)info.info.x11.window;
6161
return true;
62+
#endif
63+
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
64+
case SDL_SYSWM_WAYLAND:
65+
nativeWindow->type = NFD_WINDOW_HANDLE_TYPE_WAYLAND;
66+
nativeWindow->handle = (void*)info.info.wl.surface;
67+
return true;
6268
#endif
6369
default:
6470
// Silence the warning in case we are not using a supported backend.

0 commit comments

Comments
 (0)