Explorar o código

Improve text rendering compatibility (5/5) (#571)

* Update src/WallpaperEngine/Input/Drivers/WaylandMouseInput.cpp

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Support dynamic text point size settings

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Gaiser147 <gaiser147@users.noreply.github.com>
Graiser147 hai 4 meses
pai
achega
8a00ff7930

+ 2 - 2
src/WallpaperEngine/Data/Model/Object.h

@@ -596,8 +596,8 @@ struct TextData {
     std::map<std::string, UserSettingUniquePtr> scriptProperties;
     /** Font reference from scene (e.g. "fonts/VCR_OSD_MONO.ttf" or "systemfont_arial") */
     std::string font;
-    /** Font size in points */
-    UserSettingUniquePtr pointsize;
+    /** Font size in points, optionally bound to a user setting or script */
+    UserSettingUniquePtr pointSize;
     /** Bounding box size */
     glm::vec2 size;
     /** Scale (x, y, z) */

+ 2 - 1
src/WallpaperEngine/Data/Parsers/ObjectParser.cpp

@@ -250,7 +250,7 @@ TextUniquePtr ObjectParser::parseText (const JSON& it, const Project& project, O
 	    .script = std::move (script),
 	    .scriptProperties = std::move (scriptProps),
 	    .font = it.optional ("font", std::string ()),
-	    .pointsize = it.user ("pointsize", properties, 32.0f),
+	    .pointSize = it.user ("pointsize", properties, 32.0f),
 	    .size = it.optional ("size", glm::vec2 (0.0f)),
 	    .scale = it.user ("scale", properties, glm::vec3 (1.0f)),
 	    .color = it.user ("color", properties, glm::vec4 (1.0f)),
@@ -267,6 +267,7 @@ TextUniquePtr ObjectParser::parseText (const JSON& it, const Project& project, O
     bindScriptContext (result->color, result->id, result->name, "color");
     bindScriptContext (result->alpha, result->id, result->name, "alpha");
     bindScriptContext (result->scale, result->id, result->name, "scale");
+    bindScriptContext (result->pointSize, result->id, result->name, "pointSize");
 
     return result;
 }

+ 1 - 1
src/WallpaperEngine/Input/Drivers/WaylandMouseInput.cpp

@@ -146,7 +146,7 @@ std::optional<glm::dvec2> WaylandMouseInput::queryHyprlandCursorPosition () cons
     }
 
     constexpr const char* request = "j/cursorpos";
-    if (send (fd, request, std::strlen (request), 0) < 0) {
+    if (send (fd, request, std::strlen (request), MSG_NOSIGNAL) < 0) {
 	close (fd);
 	return std::nullopt;
     }

+ 14 - 5
src/WallpaperEngine/Render/Objects/CText.cpp

@@ -101,7 +101,8 @@ void CText::setup () {
     if (!loadEmbeddedFont () && !loadSystemFont ())
 	return;
 
-    FT_Set_Pixel_Sizes (m_ftFace, 0, static_cast<FT_UInt> (computeEffectivePixelSize ()));
+    m_lastPixelSize = computeEffectivePixelSize ();
+    FT_Set_Pixel_Sizes (m_ftFace, 0, static_cast<FT_UInt> (m_lastPixelSize));
 
     buildShader ();
     // Scripted text may have an empty placeholder; use a single space so the
@@ -179,7 +180,7 @@ unsigned int CText::computeEffectivePixelSize () const {
 	? std::min (1.0f / avgScale, 32.0f)
 	: 1.0f;
     return std::max<unsigned int> (
-	1u, static_cast<unsigned int> (m_text.pointsize->value->getFloat () * compensate));
+	1u, static_cast<unsigned int> (m_text.pointSize->value->getFloat () * compensate));
 }
 
 void CText::initScriptLayer () {
@@ -337,6 +338,7 @@ void CText::render () {
     if (!m_valid) return;
     if (!m_text.visible->value->getBool ()) return;
 
+    std::string renderedText = m_lastRenderedText;
     if (m_layerHandle != Scripting::kInvalidLayerHandle) {
 	auto& se = Scripting::ScriptEngine::instance ();
 	se.tickLayer (
@@ -346,9 +348,16 @@ void CText::render () {
 	    static_cast<double> (getScene ().getFps ())
 	);
 	const std::string current = se.layerText (m_layerHandle);
-	if (current != m_lastRenderedText) {
-	    rebuildTextureFrom (current.empty () ? std::string (" ") : current);
-	}
+	renderedText = current.empty () ? std::string (" ") : current;
+    }
+
+    const unsigned int pixelSize = computeEffectivePixelSize ();
+    if (pixelSize != m_lastPixelSize) {
+	m_lastPixelSize = pixelSize;
+	FT_Set_Pixel_Sizes (m_ftFace, 0, static_cast<FT_UInt> (m_lastPixelSize));
+	rebuildTextureFrom (renderedText);
+    } else if (renderedText != m_lastRenderedText) {
+	rebuildTextureFrom (renderedText);
     }
 
     const glm::vec4 color = m_text.color->value->getVec4 ();

+ 1 - 0
src/WallpaperEngine/Render/Objects/CText.h

@@ -61,6 +61,7 @@ private:
 
     const Text& m_text;
     std::string m_lastRenderedText;
+    unsigned int m_lastPixelSize = 0;
     Scripting::ScriptLayerHandle m_layerHandle = Scripting::kInvalidLayerHandle;
 
     FT_Library m_ftLibrary = nullptr;

+ 1 - 0
src/WallpaperEngine/Render/Wallpapers/CScene.cpp

@@ -372,6 +372,7 @@ void CScene::collectScriptedValues () {
 	    this->registerScriptedValue (text->color);
 	    this->registerScriptedValue (text->alpha);
 	    this->registerScriptedValue (text->scale);
+	    this->registerScriptedValue (text->pointSize);
 	}
     }
 }

+ 1 - 0
src/WallpaperEngine/Scripting/ScriptEngine.cpp

@@ -483,6 +483,7 @@ static UserSetting* textSettingForProperty (const Text& text, const std::string&
     if (property == "visible") return text.visible.get ();
     if (property == "alpha") return text.alpha.get ();
     if (property == "color") return text.color.get ();
+    if (property == "pointSize") return text.pointSize.get ();
     return nullptr;
 }