Commit graph

30 commits

Author SHA1 Message Date
alexei-zebra
fbedfad478
Fix the issues found while reviewing the engine frame
Use util::str2wstr_utf8 for the window title instead of the deprecated
codecvt conversion, choose the bar control icon with a switch, and keep
the frontend layout in sync when a frame is drawn from the refresh
callback the platform calls while it blocks the main loop.

The frame forgets its interaction state when the window mode changes or
the cursor gets locked, a bar click that only moved the window is no
longer a double click, and one frame per size is drawn per resize.

The tooltips of the two window settings were only present in the Russian
locale and under a key the settings page never asks for: they are named
display.<id>.tooltip now and translated in both locales. The version label
of the debug build moves below the bar that covers the menu screen.
2026-10-11 20:06:11 +03:00
alexei-zebra
68d4214627
Fix the engine window frame on windows
Four things came out of testing on windows.

The window settings were hidden outside of wayland because the check used
the backend name, while the bar height matters wherever the engine draws
the frame. The window now reports that (hasEngineFrame: barEnabled on
wayland, engineFrame on glfw) and the display page asks for it. Only the
live resize switch stays wayland specific, since the glfw backend always
draws a fresh frame.

The simplified mode is gone: when the frame is active and the surface has
alpha, the shadow and the outer resize border are always there.

The bar and its controls are drawn even when the font is missing: the early
return used to make the whole bar invisible while its hit zones kept
working.

GLFW rewrites the window style on every mode change and dropped the thick
frame the native resize border and snapping need, so the frame is set up
again after such a change.

Windows runs a modal loop while a window border is dragged and the main
loop is blocked inside it, which froze the content during a resize. The
backend draws and presents a frame from the refresh callback now, and
skips the framerate limit there.
2026-10-10 22:02:33 +03:00
alexei-zebra
f13b75475f
Let the window frame keep its cursor
The GUI sets the cursor of the hovered widget every frame, and over the
window that widget is usually the background with a plain arrow. The frame
sets its resize cursors on pointer motion, so the GUI replaced them on the
next frame: hovering a window edge did not show a resize cursor, it flickered
and stayed an arrow.

The window now reports whether the frame owns the cursor, and the GUI only
sets the hovered cursor when it does not. The GLFW backend claims it inside
the frame and gives it back in the client area together with the arrow, since
the GUI sets a cursor only while a widget is hovered.

Wayland keeps returning false, so the GUI behaves exactly as before there.
2026-10-10 16:04:39 +03:00
alexei-zebra
ab7f542d61
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().
2026-10-10 12:23:42 +03:00
alexei-zebra
b5416d1219
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.
2026-10-10 12:23:42 +03:00
alexei-zebra
6c2192b5d8
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.
2026-10-10 12:23:41 +03:00
alexei-zebra
1dbd445027
give Window::getTitle a default implementation
Keeps the interface non-breaking for other window backends: the
decoration height and hovered button already have defaults, and now so
does the title.
2026-10-10 12:23:31 +03:00
alexei-zebra
3b337241f5
draw window decorations with the engine GUI
The bar used to be drawn by the Wayland backend with its own shader,
bitmap font and textures, straight into the engine's GL frame. That
leaked GL state (the batch caches bound textures, so the engine kept
sampling the backend texture and all text turned into solid white
rectangles) and it duplicated fonts and styling.

Now the backend only owns the behaviour: hit zones, cursor shapes,
click interception and the compositor requests (move, resize,
minimize, maximize/restore, close). The bar itself is drawn by the
engine in WindowBar.cpp through the regular Batch2D/Font path, so it
looks like the rest of the UI.

Window gained getTitle(), getDecorationHeight() and
getDecorationHoveredButton(); GLFW keeps the defaults, so X11 and
Windows are unaffected. The backend's decoration drawing (bitmap font,
shader, quad batches) is removed: WaylandBar.cpp went from 630 to 140
lines.

Fixes found while debugging:
- GlStateGuard was defined but never used after the file split, so the
  stretched frame left its texture bound and broke text rendering after
  a window mode change; it is now applied around the cache capture and
  the stretched frame;
- takeScreenshot() now reads the front buffer and restores the read
  buffer afterwards.
2026-10-10 12:23:18 +03:00
alexei-zebra
1e689e88b1
add native Wayland window backend
Wayland support was missing a proper windowing layer: the GLFW backend
leaves the known platform gaps (cursor themes, window icon, window
position, fullscreen output selection).

The new backend talks to the compositor directly:
- xdg-shell, EGL, xkbcommon (keyboard, repeat, layout) instead of GLFW;
- cursors through wp_cursor_shape_manager_v1, so no cursor theme lookup
  is required and no "standard cursor shape unavailable" errors appear;
- window icon and title are drawn by the engine itself, since Wayland
  has no window icon protocol and GNOME provides no server-side
  decorations;
- fullscreen requests the current output (set_fullscreen with NULL), so
  the window no longer jumps to another monitor;
- interactive resize presents a cached frame scaled to the new size
  while the pointer is down and refreshes the real frame when the drag
  pauses, keeping the window glued to the cursor.

libdecor is not used: libdecor_frame_commit() redraws the whole
decoration and acks the configure in the same call, and mutter sends
200-330 configures per second during an interactive resize, so the
decoration was redrawn hundreds of times per second (measured: 2 s of
work per second, loop stalls up to 6 s). The decorations are drawn by
the engine instead, which measured 2.3 ms average configure-to-present
latency during a real drag.

GLFW stays the backend for X11 and Windows; VOXEL_WINDOW_BACKEND=x11
forces it on Wayland sessions.
2026-10-10 12:23:18 +03:00
MihailRis
c42d661223 add app.focus function 2025-11-15 21:22:18 +03:00
MihailRis
7d367a9793 add app.set_title 2025-11-10 20:48:26 +03:00
MihailRis
7fc3703ad2 feat: refresh on demand in menu (adaptive framerate) 2025-11-09 22:22:24 +03:00
ChancellorIkseew
b30b19e836
Add borderless window mode (from tasks) (#630) 2025-09-30 23:53:15 +03:00
MihailRis
7262119f5b refactor GLFWWindow 2025-04-02 15:01:24 +03:00
MihailRis
0b8d56afe1 cleanup 2025-04-02 14:59:53 +03:00
MihailRis
9694a59649 refactor: add Window interface 2025-04-02 14:59:53 +03:00
MihailRis
4c48afbb90 refactor: add GUI instance reference to UI nodes 2025-04-02 14:55:53 +03:00
MihailRis
74a94f869c refactor: reduce Window references 2025-04-02 14:55:53 +03:00
boolean-false
0042d8a60c
add check for OpenGL Debug extension support (#498)
* Fix crash on Osx Arm
* Check OpenGL extension support safely
* Replace on cstring
* Moved to Window.cpp and added extensions cache
2025-04-02 12:34:12 +03:00
MihailRis
cb9690ebc7 add 'cursor' ui property 2024-12-30 21:41:05 +03:00
MihailRis
de5c75d782 replace include guards with pragma once 2024-08-10 01:57:59 +03:00
MihailRis
f43cc93cd2 update project includes format 2024-08-10 01:37:48 +03:00
InfiniteCoder
d5dc68dd38 Root includes 2024-08-04 10:24:11 +03:00
Vyacheslav Ivanov
bbf33e8e4d
format: reformat project
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
2024-08-03 19:53:48 +03:00
MihailRis
ba046a52c0
Revert "fix: optimization: Various PVS-Studio warnings" 2024-08-02 14:51:44 +03:00
Vyacheslav Ivanov
2c1103307f
fix: optimization: PVS-Studio warning V813
Passing large objects by const reference avoids unnecessary copying and enhances efficiency.

Reported by: PVS-Studio
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
2024-08-02 05:35:55 +03:00
MihailRis
b021339a8a add window icon 2024-07-28 23:47:49 +03:00
MihailRis
a856b4f140 add framerate control (WIP) 2024-07-25 22:33:21 +03:00
MihailRis
1627e21c1d the final rename 2024-05-06 03:38:19 +03:00
MihailRis
7f8a86b740 minor refactor 2024-05-05 20:08:25 +03:00
Renamed from src/window/Window.h (Browse further)