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

@ -1,11 +1,11 @@
#include "WindowBar.hpp"
#include "Engine.hpp"
#include "debug/Logger.hpp"
#include "graphics/core/Batch2D.hpp"
#include <GL/glew.h>
#include <glm/gtc/matrix_transform.hpp>
#include "graphics/core/Shader.hpp"
#include "constants.hpp"
#include "graphics/core/Font.hpp"
#include "graphics/core/Texture.hpp"
#include "graphics/ui/GUI.hpp"
@ -23,9 +23,15 @@ namespace {
return converter.from_bytes(text);
}
constexpr const char* BAR_FONT = "normal";
const std::string BAR_FONT = FONT_DEFAULT;
}
/// @brief Draws the window bar the backend cannot draw itself.
///
/// The bar lives in window coordinates while the GUI container is shifted
/// down by its height in game, so the GUI camera cannot be reused here: the
/// bar sets its own viewport and projection. It borrows the GUI batch only
/// because the ui shader it needs is the one the GUI already loads.
void draw_window_bar(Engine& engine) {
auto& window = engine.getWindow();
const int height = window.getDecorationHeight();
@ -34,14 +40,17 @@ void draw_window_bar(Engine& engine) {
}
auto* batch = engine.getGUI().getBatch2D();
auto font = engine.requireAssets().getShared<Font>(BAR_FONT);
if (batch == nullptr || font == nullptr) {
if (font == nullptr) {
return;
}
const auto size = window.getSize();
const float barHeight = static_cast<float>(height);
glViewport(0, 0, static_cast<GLsizei>(size.x), static_cast<GLsizei>(size.y));
if (auto shader = engine.requireAssets().get<Shader>("ui"); shader != nullptr) {
glViewport(
0, 0, static_cast<GLsizei>(size.x), static_cast<GLsizei>(size.y)
);
auto shader = engine.requireAssets().get<Shader>("ui");
if (shader != nullptr) {
shader->use();
shader->uniformMatrix(
"u_projview",
@ -98,7 +107,6 @@ void draw_window_bar(Engine& engine) {
batch->untexture();
}
const float thickness = 2.0f;
for (size_t i = 0; i < buttons.size(); i++) {
const auto& item = buttons[i];
const float x = item.x;
@ -132,29 +140,8 @@ void draw_window_bar(Engine& engine) {
iconSize, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, ink
);
batch->untexture();
continue;
}
if (item.button == DecorationButton::CLOSE) {
for (int step = 0; step < 8; step++) {
batch->rect(cx - 5.0f + step, cy - 5.0f + step, thickness, thickness);
batch->rect(cx + 3.0f - step, cy - 5.0f + step, thickness, thickness);
}
} else if (item.button == DecorationButton::MINIMIZE) {
batch->rect(cx - 6.0f, cy - 1.0f, 12.0f, thickness);
} else if (!window.isMaximized()) {
batch->rect(cx - 6.0f, cy - 6.0f, 12.0f, thickness);
batch->rect(cx - 6.0f, cy + 4.0f, 12.0f, thickness);
batch->rect(cx - 6.0f, cy - 6.0f, thickness, 12.0f);
batch->rect(cx + 4.0f, cy - 6.0f, thickness, 12.0f);
} else {
batch->rect(cx - 7.0f, cy + 1.0f, 11.0f, thickness);
batch->rect(cx - 7.0f, cy + 1.0f, thickness, 6.0f);
batch->rect(cx + 2.0f, cy + 1.0f, thickness, 6.0f);
batch->rect(cx - 7.0f, cy + 5.0f, 11.0f, thickness);
batch->rect(cx - 2.0f, cy - 5.0f, 9.0f, thickness);
batch->rect(cx - 2.0f, cy - 5.0f, thickness, 6.0f);
batch->rect(cx + 5.0f, cy - 5.0f, thickness, 6.0f);
}
}
batch->flush();
}