add native Wayland window backend

Wayland support was missing a proper windowing layer: the GLFW backend
leaves the known platform gaps (cursor themes, window icon, window
position, fullscreen output selection).

The new backend talks to the compositor directly:
- xdg-shell, EGL, xkbcommon (keyboard, repeat, layout) instead of GLFW;
- cursors through wp_cursor_shape_manager_v1, so no cursor theme lookup
  is required and no "standard cursor shape unavailable" errors appear;
- window icon and title are drawn by the engine itself, since Wayland
  has no window icon protocol and GNOME provides no server-side
  decorations;
- fullscreen requests the current output (set_fullscreen with NULL), so
  the window no longer jumps to another monitor;
- interactive resize presents a cached frame scaled to the new size
  while the pointer is down and refreshes the real frame when the drag
  pauses, keeping the window glued to the cursor.

libdecor is not used: libdecor_frame_commit() redraws the whole
decoration and acks the configure in the same call, and mutter sends
200-330 configures per second during an interactive resize, so the
decoration was redrawn hundreds of times per second (measured: 2 s of
work per second, loop stalls up to 6 s). The decorations are drawn by
the engine instead, which measured 2.3 ms average configure-to-present
latency during a real drag.

GLFW stays the backend for X11 and Windows; VOXEL_WINDOW_BACKEND=x11
forces it on Wayland sessions.
This commit is contained in:
alexei-zebra 2026-10-09 00:43:41 +03:00
parent 1dd1af1a72
commit 1e689e88b1
No known key found for this signature in database
GPG key ID: D19D450AC3D9A80E
18 changed files with 6567 additions and 526 deletions

View file

@ -72,6 +72,67 @@ endif()
target_include_directories(VoxelCoreSrc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
option(VOXELENGINE_WAYLAND "Build the native Wayland window backend" ON)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND VOXELENGINE_WAYLAND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(wayland-client IMPORTED_TARGET wayland-client)
pkg_check_modules(xkbcommon IMPORTED_TARGET xkbcommon)
pkg_check_modules(egl IMPORTED_TARGET egl)
find_library(WAYLAND_EGL_LIBRARY NAMES wayland-egl libwayland-egl.so.1)
find_program(WAYLAND_SCANNER wayland-scanner)
if(NOT wayland-client_FOUND OR NOT xkbcommon_FOUND OR NOT egl_FOUND
OR NOT WAYLAND_EGL_LIBRARY OR NOT WAYLAND_SCANNER)
message(STATUS "Wayland backend is off: dependencies are not found")
else()
set(WAYLAND_PROTOCOLS ${CMAKE_CURRENT_SOURCE_DIR}/window/wayland/protocols)
set(WAYLAND_GENERATED ${CMAKE_CURRENT_BINARY_DIR}/wayland-protocols)
file(MAKE_DIRECTORY ${WAYLAND_GENERATED})
set(WAYLAND_SOURCES)
function(voxel_wayland_protocol XML NAME)
add_custom_command(
OUTPUT ${WAYLAND_GENERATED}/${NAME}-client-protocol.h
${WAYLAND_GENERATED}/${NAME}-protocol.c
COMMAND ${WAYLAND_SCANNER} client-header
${WAYLAND_PROTOCOLS}/${XML}
${WAYLAND_GENERATED}/${NAME}-client-protocol.h
COMMAND ${WAYLAND_SCANNER} private-code
${WAYLAND_PROTOCOLS}/${XML}
${WAYLAND_GENERATED}/${NAME}-protocol.c
DEPENDS ${WAYLAND_PROTOCOLS}/${XML}
VERBATIM)
set(WAYLAND_SOURCES ${WAYLAND_SOURCES}
${WAYLAND_GENERATED}/${NAME}-protocol.c
PARENT_SCOPE)
endfunction()
voxel_wayland_protocol(xdg-shell.xml xdg-shell)
voxel_wayland_protocol(cursor-shape-v1.xml cursor-shape-v1)
voxel_wayland_protocol(idle-inhibit-unstable-v1.xml
idle-inhibit-unstable-v1)
voxel_wayland_protocol(pointer-constraints-unstable-v1.xml
pointer-constraints-unstable-v1)
voxel_wayland_protocol(relative-pointer-unstable-v1.xml
relative-pointer-unstable-v1)
voxel_wayland_protocol(xdg-decoration-unstable-v1.xml
xdg-decoration-unstable-v1)
# tablet is referenced by cursor-shape-v1
voxel_wayland_protocol(tablet-unstable-v2.xml tablet-unstable-v2)
target_sources(VoxelCoreSrc PRIVATE ${WAYLAND_SOURCES})
target_include_directories(VoxelCoreSrc PUBLIC ${WAYLAND_GENERATED})
target_compile_definitions(VoxelCoreSrc PUBLIC VOXELENGINE_WAYLAND=1)
target_link_libraries(
VoxelCoreSrc
PRIVATE PkgConfig::wayland-client
PkgConfig::xkbcommon
PkgConfig::egl
${WAYLAND_EGL_LIBRARY})
message(STATUS "Wayland backend is on")
endif()
endif()
target_link_libraries(
VoxelCoreSrc
PRIVATE glfw