Draw the window title bar by the engine

The native Wayland backend had no window controls: no title, no close
button, no way to move or resize the window, and the fullscreen toggle
could throw the window to another monitor. GNOME does not implement
zxdg_decoration_manager_v1, so there is nobody to draw a frame for us:
the backend now falls back to its own decorations when the compositor
offers no server side ones, and the engine draws the visible part.

The bar itself is drawn by the engine (WindowBar.cpp) through the usual
batch and font, so it uses the same assets as the rest of the UI and the
backend only owns the behaviour: hit zones, cursor shapes, click
interception and the xdg-shell requests. Its geometry follows the
desktop's button layout, read and subscribed through
xdg-desktop-portal over sd-bus (libsystemd is an optional dependency,
gsettings is only a startup fallback).

Controls behave like they do elsewhere:
- pressing anywhere on the bar starts a move once the pointer leaves a
  5 px radius, so dragging works from the buttons as well;
- a button acts on release, only if the pointer stayed on it;
- a double click on the bar toggles maximize;
- the top edge and the top corners resize, the top 8 px of the sides,
  the sides and the bottom are 8 px wide resize strips;
- right and middle clicks and the scroll wheel over the bar never reach
  the game.

The in-game user interface is offset below the bar while menus keep the
whole window, so the translucent bar shows the menu background through
itself and never covers the HUD. The HUD lays its elements out against
the content height and the cursor is translated once, which fixes items
following the mouse one row above the pointer in game.

The window size is now written to the settings when the window is
resized in windowed mode and applied on the first configure, so the
window opens with the size it was left with, and leaving fullscreen or
borderless mode restores it instead of overwriting the settings with the
fullscreen size (an unconditional unmaximize made the compositor restore
the maximized geometry).

Measured: menu layout unchanged (706 bright pixels in the same place),
gui viewport 1123x751 in menus against 1123x721 in game, 1123x751 ->
2560x1080 -> 1123x751 round trip keeps the settings, a saved 1000x640
opens as 1000x640, no errors in the log.
This commit is contained in:
alexei-zebra 2026-10-09 20:56:55 +03:00
parent 4731ac0706
commit 6c2192b5d8
No known key found for this signature in database
GPG key ID: D19D450AC3D9A80E
14 changed files with 685 additions and 94 deletions

View file

@ -1,6 +1,9 @@
#pragma once
#include "window/wayland/WaylandCommon.hpp"
#include <algorithm>
#include "window/wayland/WaylandSettings.hpp"
#include "window/wayland/WaylandInput.hpp"
#include "graphics/core/ImageData.hpp"
@ -37,7 +40,25 @@ bool barEnabled = false;
bool fullscreen = false;
std::string title = "VoxelCore";
int hoveredButton = -1;
bool pointerInBar = false;
SettingsWatcher settingsWatcher;
bool layoutRead = false;
void applyLayoutValue(const std::string& value);
std::vector<DecorationButton> leftButtons;
std::vector<DecorationButton> rightButtons;
std::vector<DecorationButtonLayout> barButtons;
double lastLayoutCheck = 0.0;
double lastBarPress = 0.0;
double lastBarPressX = 0.0;
double lastBarPressY = 0.0;
double barPressX = 0.0;
double barPressY = 0.0;
uint32_t barPressSerial = 0;
bool barPressed = false;
bool barDragging = false;
int barPressedButton = -1;
int initialWidth = 0;
int initialHeight = 0;
double pointerX = 0.0;
double pointerY = 0.0;
bool frameOnCallback = false;
@ -89,6 +110,23 @@ glm::vec4 scissorArea {};
int getDecorationHeight() const override;
int getDecorationHoveredButton() const override;
static constexpr int BAR_HEIGHT = 30;
static constexpr int BAR_BUTTON = 30;
static constexpr int BAR_EDGE = 8;
int decorationOffset() const {
return barVisible() ? BAR_HEIGHT : 0;
}
const std::vector<DecorationButtonLayout>& getDecorationButtons() const override;
void updateButtonLayout();
void updateBarGeometry();
bool isIconSupported() const override {
return false;
}
@ -115,7 +153,8 @@ glm::vec4 scissorArea {};
uint32_t barEdgeAt(double x, double y) const;
static CursorShape edgeCursor(uint32_t edges);
bool handleBarMotion(double x, double y);
bool handleBarButton(uint32_t serial, bool pressed);
bool handleBarButton(uint32_t serial, int button, bool pressed);
bool handleBarScroll() const;
void onPointerLeave();
void onFrameDone();
void requestFrame();