diff --git a/CMakeLists.txt b/CMakeLists.txt index 73c864f..bf1773c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,7 @@ pkg_check_modules( pangocairo libdrm gbm - hyprutils>=0.2.0) + hyprutils>=0.2.3) file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") add_executable(hyprlock ${SRCFILES}) diff --git a/flake.lock b/flake.lock index fd41c3c..d29dbb2 100644 --- a/flake.lock +++ b/flake.lock @@ -13,11 +13,11 @@ ] }, "locked": { - "lastModified": 1721324361, - "narHash": "sha256-BiJKO0IIdnSwHQBSrEJlKlFr753urkLE48wtt0UhNG4=", + "lastModified": 1728168612, + "narHash": "sha256-AnB1KfiXINmuiW7BALYrKqcjCnsLZPifhb/7BsfPbns=", "owner": "hyprwm", "repo": "hyprlang", - "rev": "adbefbf49664a6c2c8bf36b6487fd31e3eb68086", + "rev": "f054f2e44d6a0b74607a6bc0f52dba337a3db38e", "type": "github" }, "original": { @@ -36,11 +36,11 @@ ] }, "locked": { - "lastModified": 1721324102, - "narHash": "sha256-WAZ0X6yJW1hFG6otkHBfyJDKRpNP5stsRqdEuHrFRpk=", + "lastModified": 1727300645, + "narHash": "sha256-OvAtVLaSRPnbXzOwlR1fVqCXR7i+ICRX3aPMCdIiv+c=", "owner": "hyprwm", "repo": "hyprutils", - "rev": "962582a090bc233c4de9d9897f46794280288989", + "rev": "3f5293432b6dc6a99f26aca2eba3876d2660665c", "type": "github" }, "original": { @@ -51,11 +51,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1721138476, - "narHash": "sha256-+W5eZOhhemLQxelojLxETfbFbc19NWawsXBlapYpqIA=", + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ad0b5eed1b6031efaed382844806550c3dcb4206", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", "type": "github" }, "original": { diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index baabebb..b570b06 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1,6 +1,6 @@ #include "ConfigManager.hpp" #include "../helpers/MiscFunctions.hpp" -#include "src/helpers/Log.hpp" +#include "../helpers/Log.hpp" #include #include #include diff --git a/src/core/LockSurface.cpp b/src/core/LockSurface.cpp index 755b253..c8e4f82 100644 --- a/src/core/LockSurface.cpp +++ b/src/core/LockSurface.cpp @@ -7,7 +7,7 @@ static void handleConfigure(void* data, ext_session_lock_surface_v1* surf, uint32_t serial, uint32_t width, uint32_t height) { const auto PSURF = (CSessionLockSurface*)data; - PSURF->configure({width, height}, serial); + PSURF->configure({(double)width, (double)height}, serial); } static const ext_session_lock_surface_v1_listener lockListener = { diff --git a/src/core/LockSurface.hpp b/src/core/LockSurface.hpp index 16a8294..f1f1918 100644 --- a/src/core/LockSurface.hpp +++ b/src/core/LockSurface.hpp @@ -4,8 +4,8 @@ #include "ext-session-lock-v1-protocol.h" #include "viewporter-protocol.h" #include "fractional-scale-v1-protocol.h" +#include "../helpers/Math.hpp" #include -#include "../helpers/Vector2D.hpp" #include class COutput; diff --git a/src/core/Output.hpp b/src/core/Output.hpp index 6a0b0e0..d642902 100644 --- a/src/core/Output.hpp +++ b/src/core/Output.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include "../helpers/Vector2D.hpp" +#include "../helpers/Math.hpp" #include "LockSurface.hpp" #include diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp deleted file mode 100644 index 44f43a9..0000000 --- a/src/helpers/Box.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "Box.hpp" -#include -#include -#include - -#define VECINRECT(vec, x1, y1, x2, y2) ((vec).x >= (x1) && (vec).x <= (x2) && (vec).y >= (y1) && (vec).y <= (y2)) - -CBox& CBox::scale(double scale) { - x *= scale; - y *= scale; - w *= scale; - h *= scale; - - return *this; -} - -CBox& CBox::scale(const Vector2D& scale) { - x *= scale.x; - y *= scale.y; - w *= scale.x; - h *= scale.y; - - return *this; -} - -CBox& CBox::translate(const Vector2D& vec) { - x += vec.x; - y += vec.y; - - return *this; -} - -Vector2D CBox::middle() const { - return Vector2D{x + w / 2.0, y + h / 2.0}; -} - -bool CBox::containsPoint(const Vector2D& vec) const { - return VECINRECT(vec, x, y, x + w, y + h); -} - -bool CBox::empty() const { - return w == 0 || h == 0; -} - -CBox& CBox::round() { - float newW = x + w - std::round(x); - float newH = y + h - std::round(y); - x = std::round(x); - y = std::round(y); - w = std::round(newW); - h = std::round(newH); - - return *this; -} - -CBox& CBox::scaleFromCenter(double scale) { - double oldW = w, oldH = h; - - w *= scale; - h *= scale; - - x -= (w - oldW) / 2.0; - y -= (h - oldH) / 2.0; - - return *this; -} - -CBox& CBox::expand(const double& value) { - x -= value; - y -= value; - w += value * 2.0; - h += value * 2.0; - - return *this; -} - -CBox& CBox::noNegativeSize() { - std::clamp(w, 0.0, std::numeric_limits::infinity()); - std::clamp(h, 0.0, std::numeric_limits::infinity()); - - return *this; -} - -CBox CBox::roundInternal() { - float newW = x + w - std::floor(x); - float newH = y + h - std::floor(y); - - return CBox{std::floor(x), std::floor(y), std::floor(newW), std::floor(newH)}; -} - -CBox CBox::copy() const { - return CBox{*this}; -} - -Vector2D CBox::pos() const { - return {x, y}; -} - -Vector2D CBox::size() const { - return {w, h}; -} \ No newline at end of file diff --git a/src/helpers/Box.hpp b/src/helpers/Box.hpp deleted file mode 100644 index c9ce977..0000000 --- a/src/helpers/Box.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once -#include "Vector2D.hpp" - -class CBox { - public: - CBox(double x_, double y_, double w_, double h_) { - x = x_; - y = y_; - w = w_; - h = h_; - } - - CBox() { - w = 0; - h = 0; - } - - CBox(const double d) { - x = d; - y = d; - w = d; - h = d; - } - - CBox(const Vector2D& pos, const Vector2D& size) { - x = pos.x; - y = pos.y; - w = size.x; - h = size.y; - } - - CBox& scale(double scale); - CBox& scaleFromCenter(double scale); - CBox& scale(const Vector2D& scale); - CBox& translate(const Vector2D& vec); - CBox& round(); - CBox& expand(const double& value); - CBox& noNegativeSize(); - - CBox copy() const; - - Vector2D middle() const; - Vector2D pos() const; - Vector2D size() const; - - bool containsPoint(const Vector2D& vec) const; - bool empty() const; - - double x = 0, y = 0; - union { - double w; - double width; - }; - union { - double h; - double height; - }; - - double rot = 0; /* rad, ccw */ - - // - bool operator==(const CBox& rhs) const { - return x == rhs.x && y == rhs.y && w == rhs.w && h == rhs.h; - } - - private: - CBox roundInternal(); -}; diff --git a/src/helpers/Math.cpp b/src/helpers/Math.cpp new file mode 100644 index 0000000..d111690 --- /dev/null +++ b/src/helpers/Math.cpp @@ -0,0 +1,23 @@ +#include "Math.hpp" + +Hyprutils::Math::eTransform wlTransformToHyprutils(wl_output_transform t) { + switch (t) { + case WL_OUTPUT_TRANSFORM_NORMAL: return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_NORMAL; + case WL_OUTPUT_TRANSFORM_180: return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_180; + case WL_OUTPUT_TRANSFORM_90: return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_90; + case WL_OUTPUT_TRANSFORM_270: return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_270; + case WL_OUTPUT_TRANSFORM_FLIPPED: return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_FLIPPED; + case WL_OUTPUT_TRANSFORM_FLIPPED_180: return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_FLIPPED_180; + case WL_OUTPUT_TRANSFORM_FLIPPED_270: return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_FLIPPED_270; + case WL_OUTPUT_TRANSFORM_FLIPPED_90: return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_FLIPPED_90; + default: break; + } + return Hyprutils::Math::eTransform::HYPRUTILS_TRANSFORM_NORMAL; +} + +wl_output_transform invertTransform(wl_output_transform tr) { + if ((tr & WL_OUTPUT_TRANSFORM_90) && !(tr & WL_OUTPUT_TRANSFORM_FLIPPED)) + tr = (wl_output_transform)(tr ^ (int)WL_OUTPUT_TRANSFORM_180); + + return tr; +} diff --git a/src/helpers/Math.hpp b/src/helpers/Math.hpp new file mode 100644 index 0000000..b54edff --- /dev/null +++ b/src/helpers/Math.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +#include +#include +#include + +using namespace Hyprutils::Math; + +eTransform wlTransformToHyprutils(wl_output_transform t); +wl_output_transform invertTransform(wl_output_transform tr); diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index afab9be..50b4d66 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -1,5 +1,12 @@ #pragma once #include +#include +#include std::string absolutePath(const std::string&, const std::string&); + +// +inline Hyprutils::Math::Vector2D Vector2DFromHyprlang(const Hyprlang::VEC2& vec) { + return Hyprutils::Math::Vector2D{vec.x, vec.y}; +}; diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp deleted file mode 100644 index b299cbc..0000000 --- a/src/helpers/Vector2D.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "Vector2D.hpp" -#include -#include - -Vector2D::Vector2D(double xx, double yy) { - x = xx; - y = yy; -} - -Vector2D::Vector2D() { - x = 0; - y = 0; -} - -Vector2D::~Vector2D() {} - -double Vector2D::normalize() { - // get max abs - const auto max = std::abs(x) > std::abs(y) ? std::abs(x) : std::abs(y); - - x /= max; - y /= max; - - return max; -} - -Vector2D Vector2D::floor() const { - return Vector2D(std::floor(x), std::floor(y)); -} - -Vector2D Vector2D::round() const { - return Vector2D(std::round(x), std::round(y)); -} - -Vector2D Vector2D::clamp(const Vector2D& min, const Vector2D& max) const { - return Vector2D(std::clamp(this->x, min.x, max.x < min.x ? INFINITY : max.x), std::clamp(this->y, min.y, max.y < min.y ? INFINITY : max.y)); -} - -double Vector2D::distance(const Vector2D& other) const { - double dx = x - other.x; - double dy = y - other.y; - return std::sqrt(dx * dx + dy * dy); -} - -double Vector2D::size() const { - return std::sqrt(x * x + y * y); -} - -Vector2D Vector2D::getComponentMax(const Vector2D& other) const { - return Vector2D(std::max(this->x, other.x), std::max(this->y, other.y)); -} - -Vector2D Vector2D::rotated(const double& ang) const { - const double COS = std::abs(std::cos(ang)); - const double SIN = std::abs(std::sin(ang)); - return Vector2D(x * COS + y * SIN, x * SIN + y * COS); -} diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp deleted file mode 100644 index 8e19408..0000000 --- a/src/helpers/Vector2D.hpp +++ /dev/null @@ -1,159 +0,0 @@ -#pragma once - -#include -#include - -class Vector2D { - public: - Vector2D(double, double); - Vector2D(); - Vector2D(const Hyprlang::VEC2& v) { - x = v.x; - y = v.y; - } - ~Vector2D(); - - double x = 0; - double y = 0; - - // returns the scale - double normalize(); - - Vector2D operator+(const Vector2D& a) const { - return Vector2D(this->x + a.x, this->y + a.y); - } - Vector2D operator-(const Vector2D& a) const { - return Vector2D(this->x - a.x, this->y - a.y); - } - Vector2D operator-() const { - return Vector2D(-this->x, -this->y); - } - Vector2D operator*(const double& a) const { - return Vector2D(this->x * a, this->y * a); - } - Vector2D operator/(const double& a) const { - return Vector2D(this->x / a, this->y / a); - } - - bool operator==(const Vector2D& a) const { - return a.x == x && a.y == y; - } - - bool operator!=(const Vector2D& a) const { - return a.x != x || a.y != y; - } - - Vector2D operator*(const Vector2D& a) const { - return Vector2D(this->x * a.x, this->y * a.y); - } - - Vector2D operator/(const Vector2D& a) const { - return Vector2D(this->x / a.x, this->y / a.y); - } - - bool operator>(const Vector2D& a) const { - return this->x > a.x && this->y > a.y; - } - - bool operator<(const Vector2D& a) const { - return this->x < a.x && this->y < a.y; - } - Vector2D& operator+=(const Vector2D& a) { - this->x += a.x; - this->y += a.y; - return *this; - } - Vector2D& operator-=(const Vector2D& a) { - this->x -= a.x; - this->y -= a.y; - return *this; - } - Vector2D& operator*=(const Vector2D& a) { - this->x *= a.x; - this->y *= a.y; - return *this; - } - Vector2D& operator/=(const Vector2D& a) { - this->x /= a.x; - this->y /= a.y; - return *this; - } - Vector2D& operator*=(const double& a) { - this->x *= a; - this->y *= a; - return *this; - } - Vector2D& operator/=(const double& a) { - this->x /= a; - this->y /= a; - return *this; - } - - double distance(const Vector2D& other) const; - double size() const; - Vector2D clamp(const Vector2D& min, const Vector2D& max = Vector2D{-1, -1}) const; - - Vector2D floor() const; - Vector2D round() const; - - Vector2D getComponentMax(const Vector2D& other) const; - Vector2D rotated(const double& ang) const; -}; - -/** - format specification - - 'j', as json array - - 'X', same as std::format("{}x{}", vec.x, vec.y) - - number, floating point precision, use `0` to format as integer -*/ -// absolutely ridiculous formatter spec parsing -#define FORMAT_PARSE(specs__, type__) \ - template \ - constexpr auto parse(FormatContext& ctx) { \ - auto it = ctx.begin(); \ - for (; it != ctx.end() && *it != '}'; it++) { \ - switch (*it) { specs__ default : throw std::format_error("invalid format specification"); } \ - } \ - return it; \ - } - -#define FORMAT_FLAG(spec__, flag__) \ - case spec__: (flag__) = true; break; - -#define FORMAT_NUMBER(buf__) \ - case '0': \ - case '1': \ - case '2': \ - case '3': \ - case '4': \ - case '5': \ - case '6': \ - case '7': \ - case '8': \ - case '9': (buf__).push_back(*it); break; -template -struct std::formatter : std::formatter { - bool formatJson = false; - bool formatX = false; - std::string precision = ""; - FORMAT_PARSE(FORMAT_FLAG('j', formatJson) // - FORMAT_FLAG('X', formatX) // - FORMAT_NUMBER(precision), - Vector2D) - - template - auto format(const Vector2D& vec, FormatContext& ctx) const { - std::string formatString = precision.empty() ? "{}" : std::format("{{:.{}f}}", precision); - - if (formatJson) - formatString = std::format("[{0}, {0}]", formatString); - else if (formatX) - formatString = std::format("{0}x{0}", formatString); - else - formatString = std::format("[Vector2D: x: {0}, y: {0}]", formatString); - try { - string buf = std::vformat(formatString, std::make_format_args(vec.x, vec.y)); - return std::format_to(ctx.out(), "{}", buf); - } catch (std::format_error& e) { return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y); } - } -}; diff --git a/src/renderer/Framebuffer.hpp b/src/renderer/Framebuffer.hpp index 07fd772..02a4fb1 100644 --- a/src/renderer/Framebuffer.hpp +++ b/src/renderer/Framebuffer.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../helpers/Vector2D.hpp" +#include "../helpers/Math.hpp" #include #include "Texture.hpp" diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp index 971c90f..42e3d9c 100644 --- a/src/renderer/Renderer.cpp +++ b/src/renderer/Renderer.cpp @@ -5,7 +5,6 @@ #include "../core/Output.hpp" #include "../core/hyprlock.hpp" #include "../renderer/DMAFrame.hpp" -#include "mtx.hpp" #include #include #include @@ -151,8 +150,6 @@ CRenderer::CRenderer() { blurFinishShader.colorizeTint = glGetUniformLocation(prog, "colorizeTint"); blurFinishShader.boostA = glGetUniformLocation(prog, "boostA"); - wlr_matrix_identity(projMatrix.data()); - asyncResourceGatherer = std::make_unique(); } @@ -164,7 +161,7 @@ CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf static auto* const PDISABLEBAR = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:disable_loading_bar"); static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out"); - matrixProjection(projection.data(), surf.size.x, surf.size.y, WL_OUTPUT_TRANSFORM_NORMAL); + projection = Mat3x3::outputProjection(surf.size, HYPRUTILS_TRANSFORM_NORMAL); g_pEGL->makeCurrent(surf.eglSurface); glViewport(0, 0, surf.size.x, surf.size.y); @@ -226,16 +223,12 @@ CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf } void CRenderer::renderRect(const CBox& box, const CColor& col, int rounding) { - float matrix[9]; - wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, box.rot, - projMatrix.data()); // TODO: write own, don't use WLR here - - float glMatrix[9]; - wlr_matrix_multiply(glMatrix, projection.data(), matrix); + Mat3x3 matrix = projMatrix.projectBox(box, HYPRUTILS_TRANSFORM_NORMAL, box.rot); + Mat3x3 glMatrix = projection.copy().multiply(matrix); glUseProgram(rectShader.program); - glUniformMatrix3fv(rectShader.proj, 1, GL_TRUE, glMatrix); + glUniformMatrix3fv(rectShader.proj, 1, GL_TRUE, glMatrix.getMatrix().data()); // premultiply the color as well as we don't work with straight alpha glUniform4f(rectShader.color, col.r * col.a, col.g * col.a, col.b * col.a, col.a); @@ -257,13 +250,9 @@ void CRenderer::renderRect(const CBox& box, const CColor& col, int rounding) { glDisableVertexAttribArray(rectShader.posAttrib); } -void CRenderer::renderTexture(const CBox& box, const CTexture& tex, float a, int rounding, std::optional tr) { - float matrix[9]; - wlr_matrix_project_box(matrix, &box, tr.value_or(WL_OUTPUT_TRANSFORM_FLIPPED_180) /* ugh coordinate spaces */, box.rot, - projMatrix.data()); // TODO: write own, don't use WLR here - - float glMatrix[9]; - wlr_matrix_multiply(glMatrix, projection.data(), matrix); +void CRenderer::renderTexture(const CBox& box, const CTexture& tex, float a, int rounding, std::optional tr) { + Mat3x3 matrix = projMatrix.projectBox(box, tr.value_or(HYPRUTILS_TRANSFORM_FLIPPED_180), box.rot); + Mat3x3 glMatrix = projection.copy().multiply(matrix); CShader* shader = &texShader; @@ -272,7 +261,7 @@ void CRenderer::renderTexture(const CBox& box, const CTexture& tex, float a, int glUseProgram(shader->program); - glUniformMatrix3fv(shader->proj, 1, GL_TRUE, glMatrix); + glUniformMatrix3fv(shader->proj, 1, GL_TRUE, glMatrix.getMatrix().data()); glUniform1i(shader->tex, 0); glUniform1f(shader->alpha, a); const auto TOPLEFT = Vector2D(box.x, box.y); @@ -363,13 +352,9 @@ void CRenderer::blurFB(const CFramebuffer& outfb, SBlurParams params) { glDisable(GL_BLEND); glDisable(GL_STENCIL_TEST); - float matrix[9]; - CBox box{0, 0, outfb.m_vSize.x, outfb.m_vSize.y}; - wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, - projMatrix.data()); // TODO: write own, don't use WLR here - - float glMatrix[9]; - wlr_matrix_multiply(glMatrix, projection.data(), matrix); + CBox box{0, 0, outfb.m_vSize.x, outfb.m_vSize.y}; + Mat3x3 matrix = projMatrix.projectBox(box, HYPRUTILS_TRANSFORM_NORMAL, 0); + Mat3x3 glMatrix = projection.copy().multiply(matrix); CFramebuffer mirrors[2]; mirrors[0].alloc(outfb.m_vSize.x, outfb.m_vSize.y, true); @@ -390,7 +375,7 @@ void CRenderer::blurFB(const CFramebuffer& outfb, SBlurParams params) { glUseProgram(blurPrepareShader.program); - glUniformMatrix3fv(blurPrepareShader.proj, 1, GL_TRUE, glMatrix); + glUniformMatrix3fv(blurPrepareShader.proj, 1, GL_TRUE, glMatrix.getMatrix().data()); glUniform1f(blurPrepareShader.contrast, params.contrast); glUniform1f(blurPrepareShader.brightness, params.brightness); glUniform1i(blurPrepareShader.tex, 0); @@ -425,7 +410,7 @@ void CRenderer::blurFB(const CFramebuffer& outfb, SBlurParams params) { glUseProgram(pShader->program); // prep two shaders - glUniformMatrix3fv(pShader->proj, 1, GL_TRUE, glMatrix); + glUniformMatrix3fv(pShader->proj, 1, GL_TRUE, glMatrix.getMatrix().data()); glUniform1f(pShader->radius, params.size); if (pShader == &blurShader1) { glUniform2f(blurShader1.halfpixel, 0.5f / (outfb.m_vSize.x / 2.f), 0.5f / (outfb.m_vSize.y / 2.f)); @@ -481,7 +466,7 @@ void CRenderer::blurFB(const CFramebuffer& outfb, SBlurParams params) { glUseProgram(blurFinishShader.program); - glUniformMatrix3fv(blurFinishShader.proj, 1, GL_TRUE, glMatrix); + glUniformMatrix3fv(blurFinishShader.proj, 1, GL_TRUE, glMatrix.getMatrix().data()); glUniform1f(blurFinishShader.noise, params.noise); glUniform1f(blurFinishShader.brightness, params.brightness); glUniform1i(blurFinishShader.colorize, params.colorize.has_value()); @@ -510,7 +495,7 @@ void CRenderer::blurFB(const CFramebuffer& outfb, SBlurParams params) { // finish outfb.bind(); - renderTexture(box, currentRenderToFB->m_cTex, 1.0, 0, WL_OUTPUT_TRANSFORM_NORMAL); + renderTexture(box, currentRenderToFB->m_cTex, 1.0, 0, HYPRUTILS_TRANSFORM_NORMAL); glEnable(GL_BLEND); } @@ -527,4 +512,4 @@ void CRenderer::popFb() { void CRenderer::removeWidgetsFor(const CSessionLockSurface* surf) { widgets.erase(surf); -} +} \ No newline at end of file diff --git a/src/renderer/Renderer.hpp b/src/renderer/Renderer.hpp index 77c8e73..8418ca5 100644 --- a/src/renderer/Renderer.hpp +++ b/src/renderer/Renderer.hpp @@ -3,10 +3,10 @@ #include #include #include -#include "../core/LockSurface.hpp" #include "Shader.hpp" -#include "../helpers/Box.hpp" +#include "../core/LockSurface.hpp" #include "../helpers/Color.hpp" +#include "../helpers/Math.hpp" #include "AsyncResourceGatherer.hpp" #include "widgets/IWidget.hpp" #include "Framebuffer.hpp" @@ -31,7 +31,7 @@ class CRenderer { SRenderFeedback renderLock(const CSessionLockSurface& surface); void renderRect(const CBox& box, const CColor& col, int rounding = 0); - void renderTexture(const CBox& box, const CTexture& tex, float a = 1.0, int rounding = 0, std::optional tr = {}); + void renderTexture(const CBox& box, const CTexture& tex, float a = 1.0, int rounding = 0, std::optional tr = {}); void blurFB(const CFramebuffer& outfb, SBlurParams params); std::unique_ptr asyncResourceGatherer; @@ -54,10 +54,10 @@ class CRenderer { CShader blurPrepareShader; CShader blurFinishShader; - std::array projMatrix; - std::array projection; + Mat3x3 projMatrix = Mat3x3::identity(); + Mat3x3 projection; std::vector boundFBs; }; -inline std::unique_ptr g_pRenderer; \ No newline at end of file +inline std::unique_ptr g_pRenderer; diff --git a/src/renderer/Texture.hpp b/src/renderer/Texture.hpp index 606d2a4..c2cab65 100644 --- a/src/renderer/Texture.hpp +++ b/src/renderer/Texture.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include "../helpers/Vector2D.hpp" +#include "../helpers/Math.hpp" enum TEXTURETYPE { TEXTURE_INVALID, // Invalid diff --git a/src/renderer/widgets/Background.cpp b/src/renderer/widgets/Background.cpp index f3601c8..ac7ea0b 100644 --- a/src/renderer/widgets/Background.cpp +++ b/src/renderer/widgets/Background.cpp @@ -1,6 +1,6 @@ #include "Background.hpp" #include "../Renderer.hpp" -#include "../mtx.hpp" +#include CBackground::CBackground(const Vector2D& viewport_, COutput* output_, const std::string& resourceID_, const std::unordered_map& props, bool ss) : viewport(viewport_), resourceID(resourceID_), output(output_), isScreenshot(ss) { @@ -72,8 +72,8 @@ bool CBackground::draw(const SRenderData& data) { g_pRenderer->renderTexture(texbox, asset->texture, 1.0, 0, isScreenshot ? - wlr_output_transform_invert(output->transform) : - WL_OUTPUT_TRANSFORM_NORMAL); // this could be omitted but whatever it's only once and makes code cleaner plus less blurring on large texs + wlTransformToHyprutils(invertTransform(output->transform)) : + HYPRUTILS_TRANSFORM_NORMAL); // this could be omitted but whatever it's only once and makes code cleaner plus less blurring on large texs if (blurPasses > 0) g_pRenderer->blurFB(blurredFB, CRenderer::SBlurParams{blurSize, blurPasses, noise, contrast, brightness, vibrancy, vibrancy_darkness}); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); @@ -95,7 +95,7 @@ bool CBackground::draw(const SRenderData& data) { else texbox.x = -(texbox.w - viewport.x) / 2.f; texbox.round(); - g_pRenderer->renderTexture(texbox, *tex, data.opacity, 0, WL_OUTPUT_TRANSFORM_FLIPPED_180); + g_pRenderer->renderTexture(texbox, *tex, data.opacity, 0, HYPRUTILS_TRANSFORM_FLIPPED_180); return data.opacity < 1.0; } \ No newline at end of file diff --git a/src/renderer/widgets/Background.hpp b/src/renderer/widgets/Background.hpp index a2a648e..bc3d981 100644 --- a/src/renderer/widgets/Background.hpp +++ b/src/renderer/widgets/Background.hpp @@ -1,8 +1,8 @@ #pragma once #include "IWidget.hpp" -#include "../../helpers/Vector2D.hpp" #include "../../helpers/Color.hpp" +#include "../../helpers/Math.hpp" #include "../Framebuffer.hpp" #include #include diff --git a/src/renderer/widgets/IWidget.cpp b/src/renderer/widgets/IWidget.cpp index f6ef001..ef89ad4 100644 --- a/src/renderer/widgets/IWidget.cpp +++ b/src/renderer/widgets/IWidget.cpp @@ -1,7 +1,7 @@ #include "IWidget.hpp" #include "../../helpers/Log.hpp" #include "../../core/hyprlock.hpp" -#include "src/core/Auth.hpp" +#include "../../core/Auth.hpp" #include #include #include @@ -20,12 +20,18 @@ namespace std { } #endif +Vector2D rotateVector(const Vector2D& vec, const double& ang) { + const double COS = std::abs(std::cos(ang)); + const double SIN = std::abs(std::sin(ang)); + return Vector2D(vec.x * COS + vec.y * SIN, vec.x * SIN + vec.y * COS); +} + Vector2D IWidget::posFromHVAlign(const Vector2D& viewport, const Vector2D& size, const Vector2D& offset, const std::string& halign, const std::string& valign, const double& ang) { // offset after rotation for alignment Vector2D rot; if (ang != 0) - rot = (size - size.rotated(ang)) / 2.0; + rot = (size - rotateVector(size, ang)) / 2.0; Vector2D pos = offset; if (halign == "center") diff --git a/src/renderer/widgets/IWidget.hpp b/src/renderer/widgets/IWidget.hpp index 8f65b79..05c6e5e 100644 --- a/src/renderer/widgets/IWidget.hpp +++ b/src/renderer/widgets/IWidget.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../../helpers/Vector2D.hpp" +#include "../../helpers/Math.hpp" #include class IWidget { diff --git a/src/renderer/widgets/Image.cpp b/src/renderer/widgets/Image.cpp index 2e7a1b3..91299f6 100644 --- a/src/renderer/widgets/Image.cpp +++ b/src/renderer/widgets/Image.cpp @@ -2,7 +2,9 @@ #include "../Renderer.hpp" #include "../../core/hyprlock.hpp" #include "../../helpers/Log.hpp" +#include "../../helpers/MiscFunctions.hpp" #include +#include CImage::~CImage() { if (imageTimer) { @@ -84,7 +86,7 @@ CImage::CImage(const Vector2D& viewport_, COutput* output_, const std::string& r rounding = std::any_cast(props.at("rounding")); border = std::any_cast(props.at("border_size")); color = std::any_cast(props.at("border_color")); - pos = std::any_cast(props.at("position")); + pos = Vector2DFromHyprlang(std::any_cast(props.at("position"))); halign = std::any_cast(props.at("halign")); valign = std::any_cast(props.at("valign")); angle = std::any_cast(props.at("rotate")); @@ -151,7 +153,7 @@ bool CImage::draw(const SRenderData& data) { g_pRenderer->renderRect(borderBox, color, ALLOWROUND ? (rounding == 0 ? 0 : rounding + std::round(border / M_PI)) : std::min(borderBox.w, borderBox.h) / 2.0); texbox.round(); - g_pRenderer->renderTexture(texbox, asset->texture, 1.0, ALLOWROUND ? rounding : std::min(texbox.w, texbox.h) / 2.0, WL_OUTPUT_TRANSFORM_NORMAL); + g_pRenderer->renderTexture(texbox, asset->texture, 1.0, ALLOWROUND ? rounding : std::min(texbox.w, texbox.h) / 2.0, HYPRUTILS_TRANSFORM_NORMAL); g_pRenderer->popFb(); } @@ -172,7 +174,7 @@ bool CImage::draw(const SRenderData& data) { texbox.round(); texbox.rot = angle; - g_pRenderer->renderTexture(texbox, *tex, data.opacity, 0, WL_OUTPUT_TRANSFORM_FLIPPED_180); + g_pRenderer->renderTexture(texbox, *tex, data.opacity, 0, HYPRUTILS_TRANSFORM_FLIPPED_180); return data.opacity < 1.0; } diff --git a/src/renderer/widgets/Image.hpp b/src/renderer/widgets/Image.hpp index 81fd374..f12e1d8 100644 --- a/src/renderer/widgets/Image.hpp +++ b/src/renderer/widgets/Image.hpp @@ -1,8 +1,8 @@ #pragma once #include "IWidget.hpp" -#include "../../helpers/Vector2D.hpp" #include "../../helpers/Color.hpp" +#include "../../helpers/Math.hpp" #include "../../core/Timer.hpp" #include "../AsyncResourceGatherer.hpp" #include "Shadowable.hpp" diff --git a/src/renderer/widgets/Label.cpp b/src/renderer/widgets/Label.cpp index 9559bcb..56a1855 100644 --- a/src/renderer/widgets/Label.cpp +++ b/src/renderer/widgets/Label.cpp @@ -1,10 +1,11 @@ #include "Label.hpp" -#include "../../helpers/Color.hpp" -#include -#include #include "../Renderer.hpp" #include "../../helpers/Log.hpp" #include "../../core/hyprlock.hpp" +#include "../../helpers/Color.hpp" +#include "../../helpers/MiscFunctions.hpp" +#include +#include CLabel::~CLabel() { if (labelTimer) { @@ -94,9 +95,8 @@ CLabel::CLabel(const Vector2D& viewport_, const std::unordered_mapasyncResourceGatherer->requestAsyncAssetPreload(request); - auto POS__ = std::any_cast(props.at("position")); - pos = {POS__.x, POS__.y}; - configPos = pos; + pos = Vector2DFromHyprlang(std::any_cast(props.at("position"))); + configPos = pos; viewport = viewport_; diff --git a/src/renderer/widgets/Label.hpp b/src/renderer/widgets/Label.hpp index d9bad77..0822218 100644 --- a/src/renderer/widgets/Label.hpp +++ b/src/renderer/widgets/Label.hpp @@ -2,7 +2,7 @@ #include "IWidget.hpp" #include "Shadowable.hpp" -#include "../../helpers/Vector2D.hpp" +#include "../../helpers/Math.hpp" #include "../../core/Timer.hpp" #include "../AsyncResourceGatherer.hpp" #include diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index 3284b2e..446590d 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -2,14 +2,16 @@ #include "../Renderer.hpp" #include "../../core/hyprlock.hpp" #include "../../core/Auth.hpp" +#include "../../helpers/MiscFunctions.hpp" #include #include +#include using namespace Hyprutils::String; CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::unordered_map& props, const std::string& output) : outputStringPort(output), shadow(this, props, viewport_) { - size = std::any_cast(props.at("size")); + size = Vector2DFromHyprlang(std::any_cast(props.at("size"))); outThick = std::any_cast(props.at("outline_thickness")); dots.size = std::any_cast(props.at("dots_size")); dots.spacing = std::any_cast(props.at("dots_spacing")); diff --git a/src/renderer/widgets/PasswordInputField.hpp b/src/renderer/widgets/PasswordInputField.hpp index 0c2b04f..1de7574 100644 --- a/src/renderer/widgets/PasswordInputField.hpp +++ b/src/renderer/widgets/PasswordInputField.hpp @@ -1,8 +1,8 @@ #pragma once #include "IWidget.hpp" -#include "../../helpers/Vector2D.hpp" #include "../../helpers/Color.hpp" +#include "../../helpers/Math.hpp" #include "../../core/Timer.hpp" #include "Shadowable.hpp" #include diff --git a/src/renderer/widgets/Shadowable.cpp b/src/renderer/widgets/Shadowable.cpp index d4fb5a5..0eabedc 100644 --- a/src/renderer/widgets/Shadowable.cpp +++ b/src/renderer/widgets/Shadowable.cpp @@ -1,5 +1,6 @@ #include "Shadowable.hpp" #include "../Renderer.hpp" +#include CShadowable::CShadowable(IWidget* widget_, const std::unordered_map& props, const Vector2D& viewport_) : widget(widget_), viewport(viewport_) { size = std::any_cast(props.at("shadow_size")); @@ -37,6 +38,6 @@ bool CShadowable::draw(const IWidget::SRenderData& data) { return true; CBox box = {0, 0, viewport.x, viewport.y}; - g_pRenderer->renderTexture(box, shadowFB.m_cTex, data.opacity, 0, WL_OUTPUT_TRANSFORM_NORMAL); + g_pRenderer->renderTexture(box, shadowFB.m_cTex, data.opacity, 0, HYPRUTILS_TRANSFORM_NORMAL); return true; } \ No newline at end of file diff --git a/src/renderer/widgets/Shadowable.hpp b/src/renderer/widgets/Shadowable.hpp index 7e222a8..1b06fdb 100644 --- a/src/renderer/widgets/Shadowable.hpp +++ b/src/renderer/widgets/Shadowable.hpp @@ -2,6 +2,7 @@ #include "../Framebuffer.hpp" #include "../../helpers/Color.hpp" +#include "../../helpers/Math.hpp" #include "IWidget.hpp" #include diff --git a/src/renderer/widgets/Shape.cpp b/src/renderer/widgets/Shape.cpp index 2ff7553..3377311 100644 --- a/src/renderer/widgets/Shape.cpp +++ b/src/renderer/widgets/Shape.cpp @@ -1,15 +1,17 @@ #include "Shape.hpp" #include "../Renderer.hpp" +#include "../../helpers/MiscFunctions.hpp" #include +#include CShape::CShape(const Vector2D& viewport_, const std::unordered_map& props) : shadow(this, props, viewport_) { - size = std::any_cast(props.at("size")); + size = Vector2DFromHyprlang(std::any_cast(props.at("size"))); rounding = std::any_cast(props.at("rounding")); border = std::any_cast(props.at("border_size")); color = std::any_cast(props.at("color")); borderColor = std::any_cast(props.at("border_color")); - pos = std::any_cast(props.at("position")); + pos = Vector2DFromHyprlang(std::any_cast(props.at("position"))); halign = std::any_cast(props.at("halign")); valign = std::any_cast(props.at("valign")); angle = std::any_cast(props.at("rotate")); @@ -83,7 +85,7 @@ bool CShape::draw(const SRenderData& data) { texbox.round(); texbox.rot = angle; - g_pRenderer->renderTexture(texbox, *tex, data.opacity, 0, WL_OUTPUT_TRANSFORM_FLIPPED_180); + g_pRenderer->renderTexture(texbox, *tex, data.opacity, 0, HYPRUTILS_TRANSFORM_FLIPPED_180); return data.opacity < 1.0; } diff --git a/src/renderer/widgets/Shape.hpp b/src/renderer/widgets/Shape.hpp index d749d68..2431239 100644 --- a/src/renderer/widgets/Shape.hpp +++ b/src/renderer/widgets/Shape.hpp @@ -1,10 +1,9 @@ #pragma once #include "IWidget.hpp" -#include "../../helpers/Vector2D.hpp" #include "../../helpers/Color.hpp" -#include "../../helpers/Box.hpp" #include "Shadowable.hpp" +#include #include #include #include