mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 09:59:44 +00:00
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.
167 lines
5 KiB
C++
167 lines
5 KiB
C++
#pragma once
|
|
|
|
#include "window/wayland/WaylandCommon.hpp"
|
|
|
|
#include <algorithm>
|
|
#include "window/wayland/WaylandSettings.hpp"
|
|
#include "window/wayland/WaylandInput.hpp"
|
|
|
|
#include "graphics/core/ImageData.hpp"
|
|
#include "window/Window.hpp"
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <string>
|
|
#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);
|
|
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;
|
|
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 );
|
|
~WaylandWindow() override;
|
|
double time() override;
|
|
void swapBuffers() override;
|
|
void setShouldRefresh() override;
|
|
bool checkShouldRefresh() override;
|
|
bool isMaximized() const override;
|
|
bool isFocused() const override;
|
|
bool isIconified() const override;
|
|
bool isFrameRequired() const override;
|
|
bool isShouldClose() const override;
|
|
void setShouldClose(bool flag) override;
|
|
void setCursor(CursorShape shape) override;
|
|
void setMode(WindowMode mode) override;
|
|
WindowMode getMode() const override;
|
|
void focus() override;
|
|
void setTitle(const std::string& title) override;
|
|
const std::string& getTitle() const override;
|
|
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;
|
|
}
|
|
|
|
void setIcon(const ImageData*) override {
|
|
}
|
|
void setFullscreen(bool enabled);
|
|
void setMaximized(bool enabled);
|
|
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();
|
|
void resizeCache(int width, int height);
|
|
void cacheContent();
|
|
void drawStretched();
|
|
void enableOwnDecorations();
|
|
bool barVisible() const;
|
|
int barButtonAt(double x, double y) const;
|
|
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, int button, bool pressed);
|
|
bool handleBarScroll() const;
|
|
void onPointerLeave();
|
|
void onFrameDone();
|
|
void requestFrame();
|
|
void paceFrame();
|
|
void markResizing();
|
|
void updateResizing();
|
|
void setIdleInhibit(bool enabled);
|
|
static const wl_callback_listener& frameListener();
|
|
static double now();
|
|
};
|