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().
This commit is contained in:
alexei-zebra 2026-10-10 00:12:37 +03:00
parent 01ed8b7dc5
commit ab7f542d61
No known key found for this signature in database
GPG key ID: D19D450AC3D9A80E
10 changed files with 133 additions and 17 deletions

View file

@ -66,6 +66,22 @@ function on_open()
"</select>", 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")

View file

@ -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=Перезагрузить Чанки

View file

@ -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);

View file

@ -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<l_open_folder>},
{"open_url", lua::wrap<l_open_url>},
/// window
{"get_window_backend", lua::wrap<l_get_window_backend>},
{"focus", lua::wrap<l_focus>},
{"set_title", lua::wrap<l_set_title>},
{"quit", lua::wrap<l_quit>},

View file

@ -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 {

View file

@ -64,6 +64,8 @@ public:
return empty;
}
virtual const char* getBackendName() const = 0;
virtual int getDecorationHeight() const {
return 0;
}

View file

@ -384,6 +384,10 @@ public:
std::string title;
const char* getBackendName() const override {
return "glfw";
}
const std::string& getTitle() const override {
return title;
}

View file

@ -149,18 +149,22 @@ void WaylandWindow::updateBarGeometry() {
}
barButtons.clear();
const float width = static_cast<float>(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<float>(i) * pitch;
const float x = padding + static_cast<float>(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<float>(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() {

View file

@ -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};

View file

@ -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();
}