From ab7f542d619aedbb3546d9ca67b81d0f5e3a4edb Mon Sep 17 00:00:00 2001 From: alexei-zebra Date: Sat, 10 Oct 2026 00:12:37 +0300 Subject: [PATCH] Add display settings for the wayland window frame The frame the native wayland backend draws gets three switches in the display tab: a narrow 24px bar instead of the 48px one, the shadow with the outer resize area, and redrawing the content while the window is resized (off keeps the previous behaviour of stretching the last frame). The settings are applied at runtime: the bar geometry is rebuilt and the surface is resized together with the toplevel geometry, no restart needed. The narrow bar drops the insets and the gap of its controls, so that they sit flush against the window edge. The switches are hidden outside of the wayland backend, which reports its name through Window::getBackendName(). --- res/layouts/pages/settings_display.xml.lua | 16 ++++++ res/texts/ru_RU.txt | 6 +++ src/io/settings_io.cpp | 3 ++ src/logic/scripting/lua/libs/libapp.cpp | 6 +++ src/settings.hpp | 6 +++ src/window/Window.hpp | 2 + src/window/detail/GLFWWindow.cpp | 4 ++ src/window/wayland/WaylandDecorations.cpp | 26 +++++---- src/window/wayland/WaylandWindow.cpp | 62 +++++++++++++++++++--- src/window/wayland/WaylandWindow.hpp | 19 +++++++ 10 files changed, 133 insertions(+), 17 deletions(-) diff --git a/res/layouts/pages/settings_display.xml.lua b/res/layouts/pages/settings_display.xml.lua index a3941bf2a..b82bd0966 100644 --- a/res/layouts/pages/settings_display.xml.lua +++ b/res/layouts/pages/settings_display.xml.lua @@ -66,6 +66,22 @@ function on_open() "", app.get_setting("display.window-mode")) ) + -- these only affect the window frame the native wayland backend draws + if app.get_window_backend() == "wayland" then + create_checkbox( + "display.compact-window-bar", "Narrow Window Bar", + "display.compact-window-bar.tooltip" + ) + create_checkbox( + "display.window-shadow", "Window Shadow", + "display.window-shadow.tooltip" + ) + create_checkbox( + "display.live-resize", "Live Window Resize", + "display.live-resize.tooltip" + ) + end + create_checkbox("camera.shaking", "Camera Shaking") create_checkbox("camera.inertia", "Camera Inertia") create_checkbox("camera.fov-effects", "Camera FOV Effects") diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index 295d467af..6a95f8454 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -118,6 +118,12 @@ settings.microphone.None=Нет settings.Clouds quality=Качество облаков settings.Acoustic effects=Акустические эффекты settings.Microphone access=Доступ к микрофону +settings.Narrow Window Bar=Узкая шапка окна +settings.Window Shadow=Тень окна +settings.Live Window Resize=Живой ресайз окна +settings.display.compact-window-bar.tooltip=Шапка окна высотой 24 px вместо 48 px +settings.display.window-shadow.tooltip=Тень вокруг окна и внешняя область для изменения размера (без неё окно рисуется упрощённо) +settings.display.live-resize.tooltip=Перерисовывать содержимое окна при изменении размера (выключено — последний кадр растягивается) # Управление chunks.reload=Перезагрузить Чанки diff --git a/src/io/settings_io.cpp b/src/io/settings_io.cpp index e72cb009d..772b5ccd8 100644 --- a/src/io/settings_io.cpp +++ b/src/io/settings_io.cpp @@ -55,6 +55,9 @@ SettingsHandler::SettingsHandler(EngineSettings& settings) { builder.add("limit-fps-iconified", &settings.display.limitFpsIconified); builder.add("window-mode", &settings.display.windowMode); builder.add("adaptive-menu-fps", &settings.display.adaptiveFpsInMenu); + builder.add("compact-window-bar", &settings.display.compactWindowBar); + builder.add("window-shadow", &settings.display.windowShadow); + builder.add("live-resize", &settings.display.liveResize); builder.addSection("camera"); builder.add("sensitivity", &settings.camera.sensitivity); diff --git a/src/logic/scripting/lua/libs/libapp.cpp b/src/logic/scripting/lua/libs/libapp.cpp index 0058fcada..b69908624 100644 --- a/src/logic/scripting/lua/libs/libapp.cpp +++ b/src/logic/scripting/lua/libs/libapp.cpp @@ -229,6 +229,11 @@ static int l_open_url(lua::State* L) { } +/// @brief Name of the windowing backend ("glfw" or "wayland") +static int l_get_window_backend(lua::State* L) { + return lua::pushstring(L, engine->getWindow().getBackendName()); +} + /// @brief Bring application window to focus static int l_focus(lua::State* L) { engine->getWindow().focus(); @@ -502,6 +507,7 @@ const luaL_Reg applib[] = { {"open_folder", lua::wrap}, {"open_url", lua::wrap}, /// window + {"get_window_backend", lua::wrap}, {"focus", lua::wrap}, {"set_title", lua::wrap}, {"quit", lua::wrap}, diff --git a/src/settings.hpp b/src/settings.hpp index 320d0fc8d..7d84d6786 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -38,6 +38,12 @@ struct DisplaySettings { FlagSetting limitFpsIconified {false}; /// @brief Adaptive framerate in menu (experimental) FlagSetting adaptiveFpsInMenu {false}; + /// @brief Draw the narrow (24px) window bar instead of the 48px one + FlagSetting compactWindowBar {false}; + /// @brief Draw the window shadow and keep the outer area for resizing + FlagSetting windowShadow {true}; + /// @brief Render the window content every frame while it is resized + FlagSetting liveResize {true}; }; struct ChunksSettings { diff --git a/src/window/Window.hpp b/src/window/Window.hpp index d0a62394a..b1840175c 100644 --- a/src/window/Window.hpp +++ b/src/window/Window.hpp @@ -64,6 +64,8 @@ public: return empty; } + virtual const char* getBackendName() const = 0; + virtual int getDecorationHeight() const { return 0; } diff --git a/src/window/detail/GLFWWindow.cpp b/src/window/detail/GLFWWindow.cpp index ee772c3cd..c1fa8e482 100644 --- a/src/window/detail/GLFWWindow.cpp +++ b/src/window/detail/GLFWWindow.cpp @@ -384,6 +384,10 @@ public: std::string title; + const char* getBackendName() const override { + return "glfw"; + } + const std::string& getTitle() const override { return title; } diff --git a/src/window/wayland/WaylandDecorations.cpp b/src/window/wayland/WaylandDecorations.cpp index e9f0b1341..90a44d74b 100644 --- a/src/window/wayland/WaylandDecorations.cpp +++ b/src/window/wayland/WaylandDecorations.cpp @@ -149,18 +149,22 @@ void WaylandWindow::updateBarGeometry() { } barButtons.clear(); const float width = static_cast(size.x); - constexpr float pitch = BAR_BUTTON + BAR_GAP; + // The narrow bar has no room for the insets of the wide one, so its + // controls sit flush against the window edge and each other. + const float padding = compactBar() ? 0.0f : BAR_PADDING; + const float gap = compactBar() ? 0.0f : BAR_GAP; + const float pitch = BAR_BUTTON + gap; for (size_t i = 0; i < leftButtons.size(); i++) { - const float x = BAR_PADDING + static_cast(i) * pitch; + const float x = padding + static_cast(i) * pitch; if (x + BAR_BUTTON > width) { break; } barButtons.push_back({leftButtons[i], x, BAR_BUTTON}); } for (size_t i = 0; i < rightButtons.size(); i++) { - const float x = width - BAR_PADDING - + const float x = width - padding - static_cast(rightButtons.size() - i) * pitch + - BAR_GAP; + gap; if (x < 0.0f) { break; } @@ -178,7 +182,7 @@ const std::string& WaylandWindow::getTitle() const { } int WaylandWindow::getDecorationHeight() const { - return barVisible() ? BAR_HEIGHT : 0; + return barVisible() ? barHeight() : 0; } int WaylandWindow::getDecorationHoveredButton() const { @@ -204,7 +208,7 @@ bool WaylandWindow::barVisible() const { } int WaylandWindow::barButtonAt(double x, double y) const { - constexpr int top = (BAR_HEIGHT - BAR_BUTTON) / 2; + const int top = (barHeight() - BAR_BUTTON) / 2; if (!barVisible() || y < top || y >= top + BAR_BUTTON) { return -1; } @@ -221,7 +225,7 @@ uint32_t WaylandWindow::barEdgeAt(double x, double y) const { if (barButtonAt(x, y) >= 0) { return 0; } - const bool inBar = barVisible() && y >= 0.0 && y < BAR_HEIGHT; + const bool inBar = barVisible() && y >= 0.0 && y < barHeight(); uint32_t edges = 0; if (y < BAR_EDGE) { edges |= XDG_TOPLEVEL_RESIZE_EDGE_TOP; @@ -312,7 +316,8 @@ bool WaylandWindow::handleBarMotion(double x, double y) { return true; } const double contentY = this->contentY(y); - const bool inBar = barVisible() && contentY >= 0.0 && contentY < BAR_HEIGHT; + const bool inBar = + barVisible() && contentY >= 0.0 && contentY < barHeight(); if (inBar && !pointerInBar) { lastLayoutCheck = 0.0; } @@ -334,7 +339,7 @@ bool WaylandWindow::handleBarButton(uint32_t serial, int button, bool pressed) { const double x = contentX(pointerX); const double y = contentY(pointerY); const uint32_t edges = pointerEdges(); - const bool inBar = barVisible() && y >= 0.0 && y < BAR_HEIGHT; + const bool inBar = barVisible() && y >= 0.0 && y < barHeight(); if (button != 0) { return inBar || edges != 0; } @@ -395,7 +400,8 @@ bool WaylandWindow::handleBarButton(uint32_t serial, int button, bool pressed) { bool WaylandWindow::handleBarScroll() const { const double y = contentY(pointerY); - return (barVisible() && y >= 0.0 && y < BAR_HEIGHT) || pointerEdges() != 0; + return (barVisible() && y >= 0.0 && y < barHeight()) || + pointerEdges() != 0; } void WaylandWindow::onPointerLeave() { diff --git a/src/window/wayland/WaylandWindow.cpp b/src/window/wayland/WaylandWindow.cpp index 8467dadd4..9724d82a8 100644 --- a/src/window/wayland/WaylandWindow.cpp +++ b/src/window/wayland/WaylandWindow.cpp @@ -107,15 +107,22 @@ double WaylandWindow::time() { } void WaylandWindow::swapBuffers() { + updateSettings(); updateResizing(); if (resizing && !presentPending && !frameDone) { resetScissor(); return; } - if (resizing) { + if (liveResizeEnabled()) { + if (frameRendered) { + cacheContent(); + } + } else if (resizing) { + // While the pointer drags the window border the content is only + // redrawn when the engine asked for it, otherwise the last frame is + // stretched into the new size. if (renderPending) { cacheContent(); - renderPending = false; } else if (marginSize() == 0) { drawStretched(); } @@ -123,6 +130,7 @@ void WaylandWindow::swapBuffers() { cacheContent(); } frameRendered = false; + renderPending = false; composeFrame(); requestFrame(); eglSwapBuffers(eglDisplay, eglSurface); @@ -187,11 +195,18 @@ bool WaylandWindow::isIconified() const { } bool WaylandWindow::isFrameRequired() const { - const bool required = !resizing || renderPending; - if (required) { - frameRendered = true; + if (!liveResizeEnabled()) { + const bool required = !resizing || renderPending; + if (required) { + frameRendered = true; + } + return required; } - return required; + // The engine draws every frame, also while the window is being resized: + // resizing only paces the presentation now, it no longer freezes the + // content into a stretched copy of the last frame. + frameRendered = true; + return true; } bool WaylandWindow::isShouldClose() const { @@ -266,7 +281,8 @@ void WaylandWindow::setMaximized(bool enabled) { } int WaylandWindow::marginSize() const { - if (!barEnabled || !shadowEnabled) { + if (!barEnabled || !shadowEnabled || + (settings != nullptr && !settings->windowShadow.get())) { return 0; } if (fullscreen || maximized || Window::mode != WindowMode::WINDOWED) { @@ -275,6 +291,38 @@ int WaylandWindow::marginSize() const { return SHADOW_MARGIN; } +bool WaylandWindow::compactBar() const { + return settings != nullptr && settings->compactWindowBar.get(); +} + +int WaylandWindow::barHeight() const { + return compactBar() ? BAR_HEIGHT_COMPACT : BAR_HEIGHT; +} + +bool WaylandWindow::liveResizeEnabled() const { + return settings == nullptr || settings->liveResize.get(); +} + +void WaylandWindow::updateSettings() { + if (settings == nullptr) { + return; + } + const bool shadow = settings->windowShadow.get(); + if (shadow != shadowSetting) { + shadowSetting = shadow; + // The surface size depends on whether the frame around the content is + // drawn at all, so the egl window and the toplevel geometry change. + resize(size.x, size.y); + setShouldRefresh(); + } + const bool compactBar = settings->compactWindowBar.get(); + if (compactBar != compactBarSetting) { + compactBarSetting = compactBar; + updateBarGeometry(); + setShouldRefresh(); + } +} + glm::ivec2 WaylandWindow::surfaceSize() const { const int margin = marginSize() * 2; return {size.x + margin, size.y + margin}; diff --git a/src/window/wayland/WaylandWindow.hpp b/src/window/wayland/WaylandWindow.hpp index a50c81313..77bdd8543 100644 --- a/src/window/wayland/WaylandWindow.hpp +++ b/src/window/wayland/WaylandWindow.hpp @@ -114,10 +114,18 @@ class WaylandWindow : public Window { void focus() override; void setTitle(const std::string& title) override; const std::string& getTitle() const override; + const char* getBackendName() const override { + return "wayland"; + } + + /// @brief Whether the narrow window bar is selected + bool compactBar() const; + int getDecorationHeight() const override; int getDecorationHoveredButton() const override; static constexpr int BAR_HEIGHT = 48; + static constexpr int BAR_HEIGHT_COMPACT = 24; static constexpr int BAR_BUTTON = 24; static constexpr int BAR_PADDING = 12; static constexpr int BAR_GAP = 12; @@ -125,12 +133,23 @@ class WaylandWindow : public Window { static constexpr int SHADOW_MARGIN = 10; static constexpr int RESIZE_GRAB_EXTRA = 2; bool shadowEnabled = false; + bool shadowSetting = true; + bool compactBarSetting = false; GLuint shadowProgram = 0; GLint shadowUniforms[8] {}; int marginSize() const; + /// @brief Window bar height, which the display settings may reduce + int barHeight() const; + + /// @brief Whether the content is redrawn every frame during a resize + bool liveResizeEnabled() const; + + /// @brief Applies the display settings that affect the window frame + void updateSettings(); + double contentX(double x) const { return x - marginSize(); }