Skip to content

Commit b5e011b

Browse files
authored
Wayland windows (#200)
* Add missing case for the BGR5A1UNorm format * Support Wayland * Add a CMake option for enabling Wayland * Fix CI (Attempt 4) * Fix CI (Attempt 5) * Fix CI (Attempt 6) * Fix CI (Attempt 7) * Add missing return * WIP * Rebase on master * Basic Wayland window implementation * Implement Display::SetCursorPositionInternal * Implement LinuxDisplayX11::GetCursorPositionInternal * Remove unrelated changes * Generate Wayland protocols source files automatically * Check if Wayland is enabled * Handle mouse events * Remove implementations for Display functions from LinuxDisplayX11.cpp * Create Wayland window only when Wayland is enabled * Handle keyboard events * Initialize Wayland state only once * Apply suggestions * Some changes * Undo redundant changes * Check if Wayland supported at runtime * Create an EGL surface before selecting current context * Compile LinuxSharedEGLSurface only when Wayland is enabled * Create EGL surface before the first `eglMakeCurrent` * Implement window decorations * Misc changes * Provide the core context instead of the intermediate one * Fix building * Some changes * Rebase on master * Add an intermidiate hierarchy class LinuxDisplay * Some changes & Cleanup * Rename LinuxGLCore.h header guard * Add workaround for the issue with the LLGL_CASE_TO_STR macro * Link with EGL when Wayland is enabled * Revert "Link with EGL when Wayland is enabled" This reverts commit 2fea02a. * Test * Revert "Test" This reverts commit 6f289ce. * Compile LinuxGLCore files only when Wayland is enabled --------- Co-authored-by: st0rmbtw <>
1 parent 1808c75 commit b5e011b

26 files changed

+3760
-762
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ tests/Output
2929

3030
# VS Code folder
3131
.vscode
32+
33+
sources/Platform/Linux/protocols/

CMakeLists.txt

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ function(find_source_files OUTPUT_LIST FILTERS)
221221
list(APPEND FilteredProjectDirs "${ProjectSubdir}/${Filter}")
222222
endforeach()
223223
endforeach()
224-
224+
225225
# Find all source files
226226
file(GLOB FilteredProjectFiles ${FilteredProjectDirs})
227-
227+
228228
# Write filtered files to output variable
229229
set(${OUTPUT_LIST} ${${OUTPUT_LIST}} ${FilteredProjectFiles} PARENT_SCOPE)
230230
endfunction()
@@ -245,7 +245,7 @@ function(add_project_resource_files OUTPUT_LIST SRC_FOLDER)
245245
list(APPEND ResourceFiles "${SharedResourceFiles}" "${ProjectResourceFiles}")
246246
endif()
247247
endforeach()
248-
248+
249249
# Write expanded resource filenames to output variable
250250
set(${OUTPUT_LIST} ${${OUTPUT_LIST}} ${ResourceFiles} PARENT_SCOPE)
251251
endfunction()
@@ -346,13 +346,13 @@ function(add_llgl_module MODULE_NAME DEFINE_NAME SRC_FILES)
346346
else()
347347
add_library(${MODULE_NAME} SHARED ${SRC_FILES})
348348
endif()
349-
349+
350350
# Keep track of all active module names
351351
append_global_property(LLGL_GLOBAL_MODULE_LIST None ${MODULE_NAME})
352-
352+
353353
# Add basic link libraries and properties
354354
set_llgl_module_properties(${MODULE_NAME})
355-
355+
356356
ADD_PROJECT_DEFINE(LLGL ${DEFINE_NAME})
357357
endfunction()
358358

@@ -467,7 +467,7 @@ function(add_llgl_example_project PROJECT_NAME LINKER_LANG SRC_FILES LIB_FILES)
467467
else()
468468
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE ${LINKER_LANG})
469469
endif()
470-
470+
471471
# Configure working directory and project solution folder
472472
if(${PROJECT_NAME} MATCHES "Example_C99_+")
473473
string(SUBSTRING ${PROJECT_NAME} 12 -1 PROJECT_BASE_NAME)
@@ -684,7 +684,6 @@ if(LLGL_ANDROID_PLATFORM)
684684
source_group("native_app_glue" FILES ${FilesAndroidNativeAppGlue})
685685
endif()
686686

687-
688687
# === Include directories ===
689688

690689
include_directories("${PROJECT_INCLUDE_DIR}")
@@ -746,6 +745,71 @@ else()
746745
set_target_properties(LLGL PROPERTIES BUILD_RPATH "\$ORIGIN")
747746
endif()
748747

748+
# Generate Wayland protocols
749+
if(LLGL_LINUX_ENABLE_WAYLAND)
750+
find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner)
751+
if (NOT WAYLAND_SCANNER_EXECUTABLE)
752+
message(FATAL_ERROR "Failed to find wayland-scanner")
753+
endif()
754+
755+
file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols)
756+
757+
# xdg-shell.xml
758+
add_custom_command(
759+
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} private-code < /usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml > xdg-shell-protocol.c
760+
OUTPUT ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/xdg-shell-protocol.c
761+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols
762+
VERBATIM
763+
)
764+
765+
add_custom_command(
766+
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header < /usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml > xdg-shell-client-protocol.h
767+
OUTPUT ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/xdg-shell-client-protocol.h
768+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols
769+
VERBATIM
770+
)
771+
772+
# xdg-decoration-unstable-v1.xml
773+
add_custom_command(
774+
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header < /usr/share/wayland-protocols/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml > xdg-decoration-client-protocol.h
775+
OUTPUT ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/xdg-decoration-client-protocol.h
776+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols
777+
VERBATIM
778+
)
779+
780+
add_custom_command(
781+
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} private-code < /usr/share/wayland-protocols/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml > xdg-decoration-protocol.c
782+
OUTPUT ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/xdg-decoration-protocol.c
783+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols
784+
VERBATIM
785+
)
786+
787+
# viewporter.xml
788+
add_custom_command(
789+
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header < /usr/share/wayland-protocols/stable/viewporter/viewporter.xml > viewporter-client-protocol.h
790+
OUTPUT ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/viewporter-client-protocol.h
791+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols
792+
VERBATIM
793+
)
794+
795+
add_custom_command(
796+
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} private-code < /usr/share/wayland-protocols/stable/viewporter/viewporter.xml > viewporter-protocol.c
797+
OUTPUT ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/viewporter-protocol.c
798+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols
799+
VERBATIM
800+
)
801+
802+
target_sources(
803+
LLGL
804+
PRIVATE ${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/xdg-shell-client-protocol.h
805+
${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/xdg-shell-protocol.c
806+
${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/xdg-decoration-client-protocol.h
807+
${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/xdg-decoration-protocol.c
808+
${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/viewporter-client-protocol.h
809+
${PROJECT_SOURCE_DIR}/sources/Platform/Linux/protocols/viewporter-protocol.c
810+
)
811+
endif()
812+
749813
include(GNUInstallDirs)
750814
target_include_directories(LLGL INTERFACE
751815
$<BUILD_INTERFACE:${PROJECT_INCLUDE_DIR}>
@@ -767,6 +831,16 @@ elseif(EMSCRIPTEN)
767831
target_link_libraries(LLGL embind)
768832
elseif(UNIX)
769833
target_link_libraries(LLGL X11 pthread Xrandr)
834+
if(LLGL_LINUX_ENABLE_WAYLAND)
835+
find_library(LIBDECOR_LIBRARY NAMES libdecor-0.so)
836+
find_path(LIBDECOR_INCLUDE_DIR NAMES libdecor-0)
837+
838+
if (NOT LIBDECOR_LIBRARY OR NOT LIBDECOR_INCLUDE_DIR)
839+
message(FATAL_ERROR "libdecor not found. Please install it.")
840+
endif()
841+
842+
target_link_libraries(LLGL wayland-client xkbcommon ${LIBDECOR_LIBRARY})
843+
endif()
770844
#elseif(LLGL_UWP_PLATFORM)
771845
# set_target_properties(LLGL PROPERTIES VS_WINRT_REFERENCES "Windows.Foundation.UniversalApiContract")
772846
endif()

0 commit comments

Comments
 (0)