diff --git a/res/layouts/pages/settings_display.xml.lua b/res/layouts/pages/settings_display.xml.lua index 8c7986989..4525b92ed 100644 --- a/res/layouts/pages/settings_display.xml.lua +++ b/res/layouts/pages/settings_display.xml.lua @@ -66,16 +66,16 @@ function on_open() "", app.get_setting("display.window-mode")) ) - -- these only affect the window frame the native wayland backend draws - if app.get_window_backend() == "wayland" then + -- the bar height matters wherever the engine draws the window frame + if app.has_engine_window_frame() then create_checkbox( "display.compact-window-bar", "Narrow Window Bar", "display.compact-window-bar.tooltip" ) - create_checkbox( - "display.simple-window", "Simple Window", - "display.simple-window.tooltip" - ) + end + -- live rendering only has the cached frame as its alternative, which is + -- what the native wayland backend does + if app.get_window_backend() == "wayland" then create_checkbox( "display.live-resize", "Live Window Resize", "display.live-resize.tooltip" diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index 97372af89..38d4048c8 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -119,10 +119,8 @@ settings.Clouds quality=Качество облаков settings.Acoustic effects=Акустические эффекты settings.Microphone access=Доступ к микрофону settings.Narrow Window Bar=Узкая шапка окна -settings.Simple Window=Простое окно settings.Live Window Resize=Живой ресайз окна settings.display.compact-window-bar.tooltip=Шапка окна высотой 24 px вместо 48 px -settings.display.simple-window.tooltip=Без тени и внешней рамки ресайза settings.display.live-resize.tooltip=Перерисовывать содержимое окна при изменении размера (выключено — последний кадр растягивается) # Управление diff --git a/src/engine/WindowBar.cpp b/src/engine/WindowBar.cpp index 0c28c0f7c..68fdeabd8 100644 --- a/src/engine/WindowBar.cpp +++ b/src/engine/WindowBar.cpp @@ -40,9 +40,6 @@ void draw_window_bar(Engine& engine) { } auto* batch = engine.getGUI().getBatch2D(); auto font = engine.requireAssets().getShared(BAR_FONT); - if (font == nullptr) { - return; - } const auto size = window.getSize(); const float barHeight = static_cast(height); @@ -81,30 +78,35 @@ void draw_window_bar(Engine& engine) { titleRight = std::min(titleRight, item.x - 8.0f); } } - const std::wstring title = to_wide(window.getTitle()); - const float available = std::max(0.0f, titleRight - titleLeft); - size_t titleLength = title.size(); - while (titleLength > 0 && font->calcWidth(title, titleLength) > available) { - titleLength--; - } - if (titleLength > 0) { - const float textWidth = static_cast( - font->calcWidth(title, titleLength) - ); - const float centered = (static_cast(size.x) - textWidth) * 0.5f; - const float titleX = std::clamp( - centered, - titleLeft, - std::max(titleLeft, titleRight - textWidth) - ); - batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, 0.85f)); - font->draw( - *batch, std::wstring_view(title).substr(0, titleLength), - static_cast(titleX), - (height - font->getLineHeight()) / 2, - nullptr, 0 - ); - batch->untexture(); + // the bar and its controls do not need the font, only the title does + if (font != nullptr) { + const std::wstring title = to_wide(window.getTitle()); + const float available = std::max(0.0f, titleRight - titleLeft); + size_t titleLength = title.size(); + while (titleLength > 0 && + font->calcWidth(title, titleLength) > available) { + titleLength--; + } + if (titleLength > 0) { + const float textWidth = static_cast( + font->calcWidth(title, titleLength) + ); + const float centered = + (static_cast(size.x) - textWidth) * 0.5f; + const float titleX = std::clamp( + centered, + titleLeft, + std::max(titleLeft, titleRight - textWidth) + ); + batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, 0.85f)); + font->draw( + *batch, std::wstring_view(title).substr(0, titleLength), + static_cast(titleX), + (height - font->getLineHeight()) / 2, + nullptr, 0 + ); + batch->untexture(); + } } for (size_t i = 0; i < buttons.size(); i++) { diff --git a/src/engine/WindowControl.cpp b/src/engine/WindowControl.cpp index 19119fb12..add00ba1a 100644 --- a/src/engine/WindowControl.cpp +++ b/src/engine/WindowControl.cpp @@ -66,6 +66,14 @@ WindowControl::Result WindowControl::initialize() { } } + // Windows blocks the main loop inside its own modal loop while the user + // drags a window border, and asks for a repaint instead: drawing a frame + // from there is what keeps the content alive during such a resize. + window->setRefreshHandler([this] { + engine.renderFrame(); + engine.getWindow().swapBuffers(); + }); + return Result {std::move(window), std::move(input)}; } diff --git a/src/io/settings_io.cpp b/src/io/settings_io.cpp index 4c2b3c218..8ccb24839 100644 --- a/src/io/settings_io.cpp +++ b/src/io/settings_io.cpp @@ -56,7 +56,6 @@ SettingsHandler::SettingsHandler(EngineSettings& settings) { builder.add("window-mode", &settings.display.windowMode); builder.add("adaptive-menu-fps", &settings.display.adaptiveFpsInMenu); builder.add("compact-window-bar", &settings.display.compactWindowBar); - builder.add("simple-window", &settings.display.simpleWindow); builder.add("live-resize", &settings.display.liveResize); builder.addSection("camera"); diff --git a/src/logic/scripting/lua/libs/libapp.cpp b/src/logic/scripting/lua/libs/libapp.cpp index b69908624..13146979d 100644 --- a/src/logic/scripting/lua/libs/libapp.cpp +++ b/src/logic/scripting/lua/libs/libapp.cpp @@ -229,6 +229,11 @@ static int l_open_url(lua::State* L) { } +/// @brief Whether the engine draws the window frame itself +static int l_has_engine_window_frame(lua::State* L) { + return lua::pushboolean(L, engine->getWindow().hasEngineFrame()); +} + /// @brief Name of the windowing backend ("glfw" or "wayland") static int l_get_window_backend(lua::State* L) { return lua::pushstring(L, engine->getWindow().getBackendName()); @@ -508,6 +513,7 @@ const luaL_Reg applib[] = { {"open_url", lua::wrap}, /// window {"get_window_backend", lua::wrap}, + {"has_engine_window_frame", lua::wrap}, {"focus", lua::wrap}, {"set_title", lua::wrap}, {"quit", lua::wrap}, diff --git a/src/settings.hpp b/src/settings.hpp index 9d9b3c80a..88a6ec133 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -40,8 +40,6 @@ struct DisplaySettings { FlagSetting adaptiveFpsInMenu {false}; /// @brief Draw the narrow (24px) window bar instead of the 48px one FlagSetting compactWindowBar {false}; - /// @brief Draw the window without the shadow and the resize border - FlagSetting simpleWindow {false}; /// @brief Render the window content every frame while it is resized FlagSetting liveResize {true}; }; diff --git a/src/window/Window.hpp b/src/window/Window.hpp index db837eade..7fac8dff3 100644 --- a/src/window/Window.hpp +++ b/src/window/Window.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -72,6 +73,29 @@ public: return empty; } + /// @brief Whether the engine draws the window frame itself here + /// + /// The bar height and its buttons only mean something when it does, and + /// the window settings are only shown where that is the case. + /// @brief Handler the windowing system calls when it wants a repaint + /// + /// Windows runs a modal loop while the user drags a window border and the + /// main loop is blocked inside it, so the only way to keep the content + /// alive during such a resize is to draw a frame from the message loop. + using RefreshHandler = std::function; + + void setRefreshHandler(RefreshHandler handler) { + refreshHandler = std::move(handler); + } + + const RefreshHandler& getRefreshHandler() const { + return refreshHandler; + } + + virtual bool hasEngineFrame() const { + return false; + } + virtual const char* getBackendName() const = 0; virtual int getDecorationHeight() const { @@ -118,6 +142,7 @@ protected: std::stack scissorStack; glm::vec4 scissorArea {}; WindowMode mode = WindowMode::WINDOWED; + RefreshHandler refreshHandler; }; namespace display { diff --git a/src/window/detail/GLFWWindow.cpp b/src/window/detail/GLFWWindow.cpp index c6ec88758..28a753269 100644 --- a/src/window/detail/GLFWWindow.cpp +++ b/src/window/detail/GLFWWindow.cpp @@ -307,7 +307,7 @@ public: void swapBuffers() override { glfwSwapBuffers(window); resetScissor(); - if (framerate > 0) { + if (framerate > 0 && !inRefreshCallback) { auto elapsedTime = time() - prevSwap; auto frameTime = 1.0 / framerate; if (elapsedTime < frameTime) { @@ -361,6 +361,13 @@ public: return hoveredButton; } + bool hasEngineFrame() const override { + return engineFrame; + } + + /// @brief Set while a frame is drawn from the refresh callback + bool inRefreshCallback = false; + bool ownsCursor() const override { return frameCursorActive; } @@ -739,8 +746,9 @@ private: void applyDecoration() { if (engineFrame) { - // frame_setup_native() owns the window style, GLFW would drop the - // thick frame the native resize border and snapping need + // GLFW rewrites the window style on every mode change and drops + // the thick frame the native resize border and snapping need + frame_setup_native(window, &frame_hit_test, this); return; } glfwSetWindowAttrib(window, GLFW_DECORATED, GLFW_TRUE); @@ -904,6 +912,12 @@ static void create_standard_cursors() { static void refresh_callback(GLFWwindow* window) { auto handler = static_cast(glfwGetWindowUserPointer(window)); handler->setShouldRefresh(); + const auto& refresh = handler->getRefreshHandler(); + if (refresh) { + handler->inRefreshCallback = true; + refresh(); + handler->inRefreshCallback = false; + } } static void setup_callbacks(GLFWwindow* window) { diff --git a/src/window/wayland/WaylandWindow.cpp b/src/window/wayland/WaylandWindow.cpp index c7cbb37ef..5f38dabc6 100644 --- a/src/window/wayland/WaylandWindow.cpp +++ b/src/window/wayland/WaylandWindow.cpp @@ -281,8 +281,7 @@ void WaylandWindow::setMaximized(bool enabled) { } int WaylandWindow::marginSize() const { - if (!barEnabled || !shadowEnabled || - (settings != nullptr && settings->simpleWindow.get())) { + if (!barEnabled || !shadowEnabled) { return 0; } if (fullscreen || maximized || Window::mode != WindowMode::WINDOWED) { @@ -307,14 +306,6 @@ void WaylandWindow::updateSettings() { if (settings == nullptr) { return; } - const bool simple = settings->simpleWindow.get(); - if (simple != simpleWindowSetting) { - simpleWindowSetting = simple; - // The surface size depends on whether the frame around the content is - // drawn at all, so the egl window and the toplevel geometry change. - resize(size.x, size.y); - setShouldRefresh(); - } const bool compactBar = settings->compactWindowBar.get(); if (compactBar != compactBarSetting) { compactBarSetting = compactBar; diff --git a/src/window/wayland/WaylandWindow.hpp b/src/window/wayland/WaylandWindow.hpp index 9754126cd..495236a0c 100644 --- a/src/window/wayland/WaylandWindow.hpp +++ b/src/window/wayland/WaylandWindow.hpp @@ -114,6 +114,10 @@ class WaylandWindow : public Window { void focus() override; void setTitle(const std::string& title) override; const std::string& getTitle() const override; + bool hasEngineFrame() const override { + return barEnabled; + } + const char* getBackendName() const override { return "wayland"; } @@ -133,7 +137,6 @@ class WaylandWindow : public Window { static constexpr int SHADOW_MARGIN = 10; static constexpr int RESIZE_GRAB_EXTRA = 2; bool shadowEnabled = false; - bool simpleWindowSetting = false; bool compactBarSetting = false; GLuint shadowProgram = 0;