diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 990bfe5..013d4a5 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1,5 +1,6 @@ #include "ConfigManager.hpp" #include "../helpers/MiscFunctions.hpp" +#include "src/helpers/Log.hpp" #include #include #include diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 8b2f373..eedf85c 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -1,9 +1,7 @@ #pragma once -#include "../helpers/Log.hpp" - #include - +#include #include #include #include diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 7b3e856..5d0fb2b 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -4,7 +4,7 @@ #include "../renderer/Renderer.hpp" #include "Auth.hpp" #include "Egl.hpp" - +#include "linux-dmabuf-unstable-v1-protocol.h" #include #include #include @@ -1111,7 +1111,7 @@ void CHyprlock::attemptRestoreOnDeath() { return; // dirty hack - uint64_t timeNowMs = std::chrono::duration_cast(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t({0})).count(); + uint64_t timeNowMs = std::chrono::duration_cast(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t(0)).count(); const auto LASTRESTARTPATH = std::string{XDG_RUNTIME_DIR} + "/.hyprlockrestart"; diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 67a4d37..97b1680 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -3,14 +3,11 @@ #include #include "ext-session-lock-v1-protocol.h" #include "fractional-scale-v1-protocol.h" -#include "linux-dmabuf-unstable-v1-protocol.h" #include "wlr-screencopy-unstable-v1-protocol.h" #include "viewporter-protocol.h" #include "Output.hpp" #include "CursorShape.hpp" #include "Timer.hpp" -#include "Auth.hpp" - #include #include #include diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp index 9b88218..44f43a9 100644 --- a/src/helpers/Box.cpp +++ b/src/helpers/Box.cpp @@ -1,5 +1,5 @@ #include "Box.hpp" - +#include #include #include diff --git a/src/helpers/Box.hpp b/src/helpers/Box.hpp index c5f30d3..c9ce977 100644 --- a/src/helpers/Box.hpp +++ b/src/helpers/Box.hpp @@ -1,5 +1,4 @@ #pragma once - #include "Vector2D.hpp" class CBox { diff --git a/src/helpers/Jpeg.cpp b/src/helpers/Jpeg.cpp index 3616744..d63e802 100644 --- a/src/helpers/Jpeg.cpp +++ b/src/helpers/Jpeg.cpp @@ -1,6 +1,5 @@ #include "Jpeg.hpp" #include "Log.hpp" - #include #include #include diff --git a/src/helpers/Log.hpp b/src/helpers/Log.hpp index e11da90..d2bf211 100644 --- a/src/helpers/Log.hpp +++ b/src/helpers/Log.hpp @@ -19,7 +19,7 @@ enum eLogLevel { std::format(reason, ##__VA_ARGS__), __LINE__, \ ([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })().c_str()); \ printf("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \ - *((int*)nullptr) = 1; /* so that we crash and get a coredump */ \ + std::abort(); \ } #define ASSERT(expr) RASSERT(expr, "?") diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index aaaee3b..bbac1a0 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include + std::string absolutePath(const std::string&, const std::string&); diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp index 188d4b9..8e19408 100644 --- a/src/helpers/Vector2D.hpp +++ b/src/helpers/Vector2D.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/src/main.cpp b/src/main.cpp index 2cf92b7..f97945e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ #include "config/ConfigManager.hpp" #include "core/hyprlock.hpp" +#include "src/helpers/Log.hpp" #include +#include void help() { std::cout << "Usage: hyprlock [options]\n\n" diff --git a/src/renderer/AsyncResourceGatherer.cpp b/src/renderer/AsyncResourceGatherer.cpp index e43392a..59e593e 100644 --- a/src/renderer/AsyncResourceGatherer.cpp +++ b/src/renderer/AsyncResourceGatherer.cpp @@ -10,6 +10,8 @@ #include "../helpers/MiscFunctions.hpp" #include "../helpers/Jpeg.hpp" #include "../helpers/Webp.hpp" +#include "src/helpers/Color.hpp" +#include "src/helpers/Log.hpp" CAsyncResourceGatherer::CAsyncResourceGatherer() { if (g_pHyprlock->getScreencopy()) @@ -345,7 +347,7 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) { target.cairo = CAIRO; target.cairosurface = CAIROSURFACE; target.data = cairo_image_surface_get_data(CAIROSURFACE); - target.size = {layoutWidth / PANGO_SCALE, layoutHeight / PANGO_SCALE}; + target.size = {layoutWidth / (double)PANGO_SCALE, layoutHeight / (double)PANGO_SCALE}; std::lock_guard lg{preloadTargetsMutex}; preloadTargets.push_back(target); diff --git a/src/renderer/AsyncResourceGatherer.hpp b/src/renderer/AsyncResourceGatherer.hpp index ff4bb5d..7046cec 100644 --- a/src/renderer/AsyncResourceGatherer.hpp +++ b/src/renderer/AsyncResourceGatherer.hpp @@ -1,10 +1,6 @@ #pragma once -#include "Shader.hpp" -#include "../helpers/Box.hpp" -#include "../helpers/Color.hpp" #include "DMAFrame.hpp" -#include "Texture.hpp" #include #include #include diff --git a/src/renderer/DMAFrame.cpp b/src/renderer/DMAFrame.cpp index c67c6ac..134ad03 100644 --- a/src/renderer/DMAFrame.cpp +++ b/src/renderer/DMAFrame.cpp @@ -1,9 +1,9 @@ #include "DMAFrame.hpp" +#include "linux-dmabuf-unstable-v1-protocol.h" #include "wlr-screencopy-unstable-v1-protocol.h" #include "../helpers/Log.hpp" #include "../core/hyprlock.hpp" #include "../core/Egl.hpp" - #include #include #include diff --git a/src/renderer/DMAFrame.hpp b/src/renderer/DMAFrame.hpp index 7309432..e4b7c66 100644 --- a/src/renderer/DMAFrame.hpp +++ b/src/renderer/DMAFrame.hpp @@ -2,7 +2,6 @@ #include "../core/Output.hpp" #include -#include "Texture.hpp" #include "Shared.hpp" struct zwlr_screencopy_frame_v1; diff --git a/src/renderer/Framebuffer.cpp b/src/renderer/Framebuffer.cpp index 75de303..bec5dc3 100644 --- a/src/renderer/Framebuffer.cpp +++ b/src/renderer/Framebuffer.cpp @@ -41,14 +41,14 @@ bool CFramebuffer::alloc(int w, int h, bool highres) { if (firstAlloc || m_vSize != Vector2D(w, h)) { glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID); - glTexImage2D(GL_TEXTURE_2D, 0, glFormat, w, h, 0, GL_RGBA, glType, 0); + glTexImage2D(GL_TEXTURE_2D, 0, glFormat, w, h, 0, GL_RGBA, glType, nullptr); glBindFramebuffer(GL_FRAMEBUFFER, m_iFb); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_cTex.m_iTexID, 0); if (m_pStencilTex) { glBindTexture(GL_TEXTURE_2D, m_pStencilTex->m_iTexID); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr); glBindFramebuffer(GL_FRAMEBUFFER, m_iFb); @@ -73,15 +73,20 @@ bool CFramebuffer::alloc(int w, int h, bool highres) { } void CFramebuffer::addStencil() { + if (!m_pStencilTex) { + Debug::log(ERR, "No stencil texture allocated."); + return; + } + glBindTexture(GL_TEXTURE_2D, m_pStencilTex->m_iTexID); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_vSize.x, m_vSize.y, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_vSize.x, m_vSize.y, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr); glBindFramebuffer(GL_FRAMEBUFFER, m_iFb); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_pStencilTex->m_iTexID, 0); auto status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - RASSERT((status == GL_FRAMEBUFFER_COMPLETE), "Failed adding a stencil to fbo!", status); + RASSERT((status == GL_FRAMEBUFFER_COMPLETE), "Failed adding a stencil to fbo! (FB status: {})", status); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -99,9 +104,13 @@ void CFramebuffer::release() { if (m_cTex.m_iTexID) glDeleteTextures(1, &m_cTex.m_iTexID); + if (m_pStencilTex && m_pStencilTex->m_iTexID) + glDeleteTextures(1, &m_pStencilTex->m_iTexID); + m_cTex.m_iTexID = 0; m_iFb = -1; m_vSize = Vector2D(); + m_pStencilTex = nullptr; } CFramebuffer::~CFramebuffer() { diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp index 26fae5d..776fc76 100644 --- a/src/renderer/Renderer.cpp +++ b/src/renderer/Renderer.cpp @@ -6,14 +6,11 @@ #include "../core/hyprlock.hpp" #include "../renderer/DMAFrame.hpp" #include "mtx.hpp" - #include #include - #include - #include "Shaders.hpp" - +#include "src/helpers/Log.hpp" #include "widgets/PasswordInputField.hpp" #include "widgets/Background.hpp" #include "widgets/Label.hpp" diff --git a/src/renderer/Renderer.hpp b/src/renderer/Renderer.hpp index 07de9bc..77c8e73 100644 --- a/src/renderer/Renderer.hpp +++ b/src/renderer/Renderer.hpp @@ -3,7 +3,6 @@ #include #include #include - #include "../core/LockSurface.hpp" #include "Shader.hpp" #include "../helpers/Box.hpp" diff --git a/src/renderer/widgets/IWidget.cpp b/src/renderer/widgets/IWidget.cpp index 50d1e05..776fb1c 100644 --- a/src/renderer/widgets/IWidget.cpp +++ b/src/renderer/widgets/IWidget.cpp @@ -1,6 +1,7 @@ #include "IWidget.hpp" #include "../../helpers/Log.hpp" #include "../../core/hyprlock.hpp" +#include "src/core/Auth.hpp" #include #include #include diff --git a/src/renderer/widgets/Label.cpp b/src/renderer/widgets/Label.cpp index 29c335b..b7f7c7f 100644 --- a/src/renderer/widgets/Label.cpp +++ b/src/renderer/widgets/Label.cpp @@ -1,6 +1,7 @@ #include "Label.hpp" #include "../../helpers/Color.hpp" #include +#include #include "../Renderer.hpp" #include "../../helpers/Log.hpp" #include "../../core/hyprlock.hpp" @@ -13,6 +14,8 @@ CLabel::~CLabel() { } static void onTimer(std::shared_ptr self, void* data) { + if (data == nullptr) + return; const auto PLABEL = (CLabel*)data; // update label @@ -64,41 +67,49 @@ void CLabel::plantTimer() { CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map& props, const std::string& output) : outputStringPort(output), shadow(this, props, viewport_) { - labelPreFormat = std::any_cast(props.at("text")); - std::string textAlign = std::any_cast(props.at("text_align")); - std::string fontFamily = std::any_cast(props.at("font_family")); - CColor labelColor = std::any_cast(props.at("color")); - int fontSize = std::any_cast(props.at("font_size")); + try { + labelPreFormat = std::any_cast(props.at("text")); + std::string textAlign = std::any_cast(props.at("text_align")); + std::string fontFamily = std::any_cast(props.at("font_family")); + CColor labelColor = std::any_cast(props.at("color")); + int fontSize = std::any_cast(props.at("font_size")); - label = formatString(labelPreFormat); + label = formatString(labelPreFormat); - request.id = getUniqueResourceId(); - resourceID = request.id; - request.asset = label.formatted; - request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT; - request.props["font_family"] = fontFamily; - request.props["color"] = labelColor; - request.props["font_size"] = fontSize; - request.props["cmd"] = label.cmd; + request.id = getUniqueResourceId(); + resourceID = request.id; + request.asset = label.formatted; + request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT; + request.props["font_family"] = fontFamily; + request.props["color"] = labelColor; + request.props["font_size"] = fontSize; + request.props["cmd"] = label.cmd; - if (!textAlign.empty()) - request.props["text_align"] = textAlign; + if (!textAlign.empty()) + request.props["text_align"] = textAlign; - g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); + g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); - auto POS__ = std::any_cast(props.at("position")); - pos = {POS__.x, POS__.y}; - configPos = pos; + auto POS__ = std::any_cast(props.at("position")); + pos = {POS__.x, POS__.y}; + configPos = pos; - viewport = viewport_; + viewport = viewport_; - halign = std::any_cast(props.at("halign")); - valign = std::any_cast(props.at("valign")); + halign = std::any_cast(props.at("halign")); + valign = std::any_cast(props.at("valign")); - angle = std::any_cast(props.at("rotate")); - angle = angle * M_PI / 180.0; + angle = std::any_cast(props.at("rotate")); + angle = angle * M_PI / 180.0; - plantTimer(); + plantTimer(); + } catch (const std::bad_any_cast& e) { + Debug::log(ERR, "Failed to construct CLabel: {}", e.what()); + throw; + } catch (const std::out_of_range& e) { + Debug::log(ERR, "Missing propperty for CLabel:{}", e.what()); + throw; + } } bool CLabel::draw(const SRenderData& data) { diff --git a/src/renderer/widgets/Label.hpp b/src/renderer/widgets/Label.hpp index eb6a775..26b938d 100644 --- a/src/renderer/widgets/Label.hpp +++ b/src/renderer/widgets/Label.hpp @@ -42,7 +42,7 @@ class CLabel : public IWidget { CAsyncResourceGatherer::SPreloadRequest request; - std::shared_ptr labelTimer; + std::shared_ptr labelTimer = nullptr; CShadowable shadow; }; diff --git a/src/renderer/widgets/Shadowable.hpp b/src/renderer/widgets/Shadowable.hpp index 5dafb68..7e222a8 100644 --- a/src/renderer/widgets/Shadowable.hpp +++ b/src/renderer/widgets/Shadowable.hpp @@ -1,7 +1,6 @@ #pragma once #include "../Framebuffer.hpp" -#include "../Texture.hpp" #include "../../helpers/Color.hpp" #include "IWidget.hpp"