Fix the issues found while reviewing the Wayland frame work

A review of the branch turned up a number of defects, gaps and leftovers;
this commit addresses all of them.

Defects:
- the shadow uniform array held seven entries while eight locations were
  written, so the last one landed outside the object;
- CursorShape::LAST stayed in the middle of the enum after the new corner
  shapes were appended, which made the GLFW cursor table read out of
  bounds; the extra shapes are now mapped onto the ones GLFW knows, and
  the table is only filled for those;
- GlStateGuard asked glIsEnabled for an attribute pname, so it always got
  GL_INVALID_ENUM and never restored the vertex attribute arrays;
- the early returns in wayland_window_initialize left the global window
  and input pointers dangling when falling back to GLFW;
- the icon textures were listed nowhere, so none of them ever loaded;
- a shader failure disabled the shadow after the surface had already been
  sized for it, and VOXEL_DECORATIONS outlived the switch cleanup.

Behavior:
- the keyboard now releases every pressed key when it loses focus, and a
  repeat rate of zero means no repeat;
- the fourth UTF-8 lead byte is decoded with the right mask, control
  characters no longer reach text fields, and a vanished clipboard offer
  clears the cached text;
- compositor side decorations disable ours again instead of leaving two
  titles, the window destructor releases the rest of the state, and the
  content inset is computed before the GUI acts so the HUD and the
  container never disagree for a frame; the HUD clamps it;
- the window controls fall back to minimize, maximize and close, and the
  icons are drawn from textures only.

Cleanups: one monotonic timer instead of three, one vertex shader shared
by both renderers with a link check, one button layout parser, the inset
rule moved into Screen, the scissor stack moved into the base Window
(about 110 duplicated lines), named shadow and evdev constants, trimmed
includes, a README note about the Wayland dependencies, and the long
lines introduced by this branch wrapped.
This commit is contained in:
alexei-zebra 2026-10-09 23:07:58 +03:00
parent c269d6efb3
commit b5416d1219
No known key found for this signature in database
GPG key ID: D19D450AC3D9A80E
25 changed files with 523 additions and 402 deletions

View file

@ -15,84 +15,85 @@
#include <vector>
class WaylandWindow : public Window {
public:
WaylandInput& input;
DisplaySettings* settings;
EGLDisplay eglDisplay = EGL_NO_DISPLAY;
EGLContext eglContext = EGL_NO_CONTEXT;
EGLSurface eglSurface = EGL_NO_SURFACE;
wl_egl_window* eglWindow = nullptr;
int32_t pendingWidth = 0;
int32_t pendingHeight = 0;
bool stateMaximized = false;
bool stateSuspended = false;
bool stateActivated = true;
bool configured = false;
static constexpr double RESIZE_TIMEOUT = 0.4;
static constexpr double FRAME_TIMEOUT = 0.025;
static constexpr double RESIZE_PAUSE = 0.12;
static constexpr double MIN_CACHE_TIMEOUT = 0.3;
static constexpr double MAX_CACHE_TIMEOUT = 3.0;
int framerate = -1;
double prevSwap = 0.0;
double lastResize = 0.0;
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);
public:
WaylandInput& input;
DisplaySettings* settings;
EGLDisplay eglDisplay = EGL_NO_DISPLAY;
EGLContext eglContext = EGL_NO_CONTEXT;
EGLSurface eglSurface = EGL_NO_SURFACE;
wl_egl_window* eglWindow = nullptr;
int32_t pendingWidth = 0;
int32_t pendingHeight = 0;
bool stateMaximized = false;
bool stateSuspended = false;
bool stateActivated = true;
bool configured = false;
static constexpr double RESIZE_TIMEOUT = 0.4;
static constexpr double FRAME_TIMEOUT = 0.025;
static constexpr double RESIZE_PAUSE = 0.12;
static constexpr double MIN_CACHE_TIMEOUT = 0.3;
static constexpr double MAX_CACHE_TIMEOUT = 3.0;
int framerate = -1;
double prevSwap = 0.0;
double lastResize = 0.0;
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 initialSizeApplied = false;
mutable bool frameRendered = false;
bool sizeChanged = false;
bool barDragging = false;
int barPressedButton = -1;
int initialWidth = 0;
int initialHeight = 0;
double pointerX = 0.0;
double pointerY = 0.0;
bool frameOnCallback = false;
double frameInterval = 0.0;
double nextFrameTime = 0.0;
double frameCost = 0.0;
double cacheTimeout = 0.5;
bool resizing = false;
bool renderPending = true;
bool presentPending = true;
double lastPresent = 0.0;
wl_callback* frameCallback = nullptr;
bool frameDone = false;
GLuint stretchProgram = 0;
GLuint stretchVao = 0;
GLuint stretchVbo = 0;
GLuint cacheFbo = 0;
GLuint cacheTexture = 0;
int cacheWidth = 0;
int cacheHeight = 0;
double lastCacheTime = 0.0;
double lastSwapEnd = 0.0;
bool shouldRefresh = true;
bool shouldClose = false;
bool maximized = false;
bool suspended = false;
bool activated = true;
bool focusWarning = false;
std::stack<glm::vec4> scissorStack;
glm::vec4 scissorArea {};
WaylandWindow( WaylandInput& input, DisplaySettings* settings, int width, int height );
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 initialSizeApplied = false;
mutable bool frameRendered = false;
bool sizeChanged = false;
bool barDragging = false;
int barPressedButton = -1;
int initialWidth = 0;
int initialHeight = 0;
double pointerX = 0.0;
double pointerY = 0.0;
bool frameOnCallback = false;
double frameInterval = 0.0;
double nextFrameTime = 0.0;
double frameCost = 0.0;
double cacheTimeout = 0.5;
bool resizing = false;
bool renderPending = true;
bool presentPending = true;
double lastPresent = 0.0;
wl_callback* frameCallback = nullptr;
bool frameDone = false;
GLuint stretchProgram = 0;
GLint stretchTextureUniform = -1;
GLuint stretchVao = 0;
GLuint stretchVbo = 0;
GLuint cacheFbo = 0;
GLuint cacheTexture = 0;
int cacheWidth = 0;
int cacheHeight = 0;
double lastCacheTime = 0.0;
double lastSwapEnd = 0.0;
bool shouldRefresh = true;
bool shouldClose = false;
bool maximized = false;
bool suspended = false;
bool activated = true;
bool focusWarning = false;
WaylandWindow(
WaylandInput& input, DisplaySettings* settings, int width, int height
);
~WaylandWindow() override;
double time() override;
void swapBuffers() override;
@ -101,6 +102,9 @@ glm::vec4 scissorArea {};
bool isMaximized() const override;
bool isFocused() const override;
bool isIconified() const override;
/// @brief Whether the engine is going to draw a frame now.
/// The answer is remembered, so swapBuffers() can tell a freshly drawn
/// frame from a buffer the engine skipped (it would be undefined).
bool isFrameRequired() const override;
bool isShouldClose() const override;
void setShouldClose(bool flag) override;
@ -113,9 +117,6 @@ glm::vec4 scissorArea {};
int getDecorationHeight() const override;
int getDecorationHoveredButton() const override;
static constexpr int BAR_HEIGHT = 48;
static constexpr int BAR_BUTTON = 24;
static constexpr int BAR_PADDING = 12;
@ -126,7 +127,7 @@ glm::vec4 scissorArea {};
bool shadowEnabled = false;
GLuint shadowProgram = 0;
GLint shadowUniforms[7] {};
GLint shadowUniforms[8] {};
int marginSize() const;
@ -151,11 +152,8 @@ glm::vec4 scissorArea {};
void makeContentOpaque(int x, int y, int width, int height);
int decorationOffset() const {
return barVisible() ? BAR_HEIGHT : 0;
}
const std::vector<DecorationButtonLayout>& getDecorationButtons() const override;
const std::vector<DecorationButtonLayout>& getDecorationButtons() const
override;
void updateButtonLayout();
@ -172,9 +170,6 @@ glm::vec4 scissorArea {};
void resize(int width, int height);
void onConfigure(int32_t width, int32_t height, wl_array* states);
void applyConfigure();
void pushScissor(glm::vec4 area) override;
void popScissor() override;
void resetScissor() override;
std::unique_ptr<ImageData> takeScreenshot() override;
void setFramerate(int framerate) override;
void initStretchRenderer();
@ -182,6 +177,7 @@ glm::vec4 scissorArea {};
void cacheContent();
void drawStretched();
void enableOwnDecorations();
void disableOwnDecorations();
bool barVisible() const;
int barButtonAt(double x, double y) const;
uint32_t barEdgeAt(double x, double y) const;