mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 17:39:46 +00:00
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:
parent
1dd1af1a72
commit
1e689e88b1
18 changed files with 6567 additions and 526 deletions
41
src/window/Window.cpp
Normal file
41
src/window/Window.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include "Window.hpp"
|
||||
|
||||
#include "debug/Logger.hpp"
|
||||
#include "detail/WindowBackends.hpp"
|
||||
#include "window/input.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
static debug::Logger logger("window");
|
||||
|
||||
#ifdef VOXELENGINE_WAYLAND
|
||||
static bool prefer_wayland() {
|
||||
const char* backend = getenv("VOXEL_WINDOW_BACKEND");
|
||||
if (backend != nullptr) {
|
||||
return strcmp(backend, "wayland") == 0;
|
||||
}
|
||||
const char* display = getenv("WAYLAND_DISPLAY");
|
||||
if (display != nullptr && *display) {
|
||||
return true;
|
||||
}
|
||||
return getenv("DISPLAY") == nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::tuple<
|
||||
std::unique_ptr<Window>,
|
||||
std::unique_ptr<Input>
|
||||
> Window::initialize(DisplaySettings* settings, std::string title) {
|
||||
input_util::initialize();
|
||||
#ifdef VOXELENGINE_WAYLAND
|
||||
if (prefer_wayland()) {
|
||||
auto result = wayland_window_initialize(settings, title);
|
||||
if (std::get<0>(result) && std::get<1>(result)) {
|
||||
return result;
|
||||
}
|
||||
logger.warning() << "could not initialize the Wayland backend";
|
||||
}
|
||||
#endif
|
||||
return glfw_window_initialize(settings, std::move(title));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue