mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 09:59:44 +00:00
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:
parent
4731ac0706
commit
6c2192b5d8
14 changed files with 685 additions and 94 deletions
|
|
@ -1,5 +1,9 @@
|
|||
#include "window/wayland/WaylandWindow.hpp"
|
||||
|
||||
#include <csignal>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "settings.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "util/platform.hpp"
|
||||
|
|
@ -7,7 +11,11 @@
|
|||
WaylandWindow::WaylandWindow(
|
||||
WaylandInput& input, DisplaySettings* settings, int width, int height
|
||||
)
|
||||
: Window({width, height}), input(input), settings(settings) {
|
||||
: Window({width, height}),
|
||||
input(input),
|
||||
settings(settings),
|
||||
initialWidth(width),
|
||||
initialHeight(height) {
|
||||
scissorArea = glm::vec4(0.0f, 0.0f, size.x, size.y);
|
||||
}
|
||||
|
||||
|
|
@ -184,9 +192,10 @@ void WaylandWindow::setMode(WindowMode mode) {
|
|||
break;
|
||||
case WindowMode::WINDOWED:
|
||||
setFullscreen(false);
|
||||
setMaximized(false);
|
||||
if (maximized) {
|
||||
setMaximized(false);
|
||||
}
|
||||
setIdleInhibit(false);
|
||||
resize(settings->width.get(), settings->height.get());
|
||||
break;
|
||||
}
|
||||
wl_surface_commit(state.surface);
|
||||
|
|
@ -238,6 +247,11 @@ void WaylandWindow::resize(int width, int height) {
|
|||
}
|
||||
glViewport(0, 0, width, height);
|
||||
size = {width, height};
|
||||
if (Window::mode == WindowMode::WINDOWED && !maximized) {
|
||||
settings->width.set(width);
|
||||
settings->height.set(height);
|
||||
}
|
||||
updateBarGeometry();
|
||||
scissorArea = glm::vec4(0.0f, 0.0f, size.x, size.y);
|
||||
}
|
||||
|
||||
|
|
@ -264,11 +278,19 @@ void WaylandWindow::onConfigure(int32_t width, int32_t height, wl_array* states)
|
|||
}
|
||||
|
||||
void WaylandWindow::applyConfigure() {
|
||||
if (pendingWidth > 0 && pendingHeight > 0) {
|
||||
resize(pendingWidth, pendingHeight);
|
||||
}
|
||||
maximized = stateMaximized;
|
||||
suspended = stateSuspended;
|
||||
if (pendingWidth > 0 && pendingHeight > 0) {
|
||||
if (!configured && Window::mode == WindowMode::WINDOWED && !maximized &&
|
||||
initialWidth > 0 && initialHeight > 0) {
|
||||
pendingWidth = initialWidth;
|
||||
pendingHeight = initialHeight;
|
||||
}
|
||||
resize(pendingWidth, pendingHeight);
|
||||
}
|
||||
if (stateActivated && !activated) {
|
||||
lastLayoutCheck = 0.0;
|
||||
}
|
||||
activated = stateActivated;
|
||||
configured = true;
|
||||
setShouldRefresh();
|
||||
|
|
@ -339,10 +361,10 @@ std::unique_ptr<ImageData> WaylandWindow::takeScreenshot() {
|
|||
auto data = std::make_unique<ubyte[]>(size.x * size.y * 3);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(0, 0, size.x, size.y, GL_RGB, GL_UNSIGNED_BYTE, data.get());
|
||||
glReadBuffer(static_cast<GLenum>(readBuffer));
|
||||
return std::make_unique<ImageData>(
|
||||
ImageFormat::RGB888, size.x, size.y, data.release()
|
||||
);
|
||||
glReadBuffer(static_cast<GLenum>(readBuffer));
|
||||
}
|
||||
|
||||
void WaylandWindow::setFramerate(int framerate) {
|
||||
|
|
@ -471,6 +493,7 @@ void WaylandWindow::requestFrame() {
|
|||
}
|
||||
|
||||
void WaylandWindow::paceFrame() {
|
||||
updateButtonLayout();
|
||||
frameOnCallback = frameDone;
|
||||
if (lastSwapEnd > 0.0) {
|
||||
const double cost = now() - lastSwapEnd;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue