mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-12-22 05:19:48 +01:00
core: Label exception handling + Frambuffer checks + headers (#413)
* Added exception handling in label constructor * Framebuffer fix + moved headers * added optional header
This commit is contained in:
parent
3bedae4436
commit
d8ccc6f96a
22 changed files with 66 additions and 58 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "ConfigManager.hpp"
|
||||
#include "../helpers/MiscFunctions.hpp"
|
||||
#include "src/helpers/Log.hpp"
|
||||
#include <filesystem>
|
||||
#include <glob.h>
|
||||
#include <cstring>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../helpers/Log.hpp"
|
||||
|
||||
#include <hyprlang.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "../renderer/Renderer.hpp"
|
||||
#include "Auth.hpp"
|
||||
#include "Egl.hpp"
|
||||
|
||||
#include "linux-dmabuf-unstable-v1-protocol.h"
|
||||
#include <sys/wait.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -1111,7 +1111,7 @@ void CHyprlock::attemptRestoreOnDeath() {
|
|||
return;
|
||||
|
||||
// dirty hack
|
||||
uint64_t timeNowMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t({0})).count();
|
||||
uint64_t timeNowMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t(0)).count();
|
||||
|
||||
const auto LASTRESTARTPATH = std::string{XDG_RUNTIME_DIR} + "/.hyprlockrestart";
|
||||
|
||||
|
|
|
@ -3,14 +3,11 @@
|
|||
#include <wayland-client.h>
|
||||
#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 <memory>
|
||||
#include <vector>
|
||||
#include <condition_variable>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "Box.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
#include "Vector2D.hpp"
|
||||
|
||||
class CBox {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "Jpeg.hpp"
|
||||
#include "Log.hpp"
|
||||
|
||||
#include <jpeglib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -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, "?")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
|
||||
std::string absolutePath(const std::string&, const std::string&);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <format>
|
||||
#include <hyprlang.hpp>
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
|
||||
#include "config/ConfigManager.hpp"
|
||||
#include "core/hyprlock.hpp"
|
||||
#include "src/helpers/Log.hpp"
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
|
||||
void help() {
|
||||
std::cout << "Usage: hyprlock [options]\n\n"
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Shader.hpp"
|
||||
#include "../helpers/Box.hpp"
|
||||
#include "../helpers/Color.hpp"
|
||||
#include "DMAFrame.hpp"
|
||||
#include "Texture.hpp"
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
|
|
@ -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 <EGL/eglext.h>
|
||||
#include <libdrm/drm_fourcc.h>
|
||||
#include <GLES3/gl32.h>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "../core/Output.hpp"
|
||||
#include <gbm.h>
|
||||
#include "Texture.hpp"
|
||||
#include "Shared.hpp"
|
||||
|
||||
struct zwlr_screencopy_frame_v1;
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -6,14 +6,11 @@
|
|||
#include "../core/hyprlock.hpp"
|
||||
#include "../renderer/DMAFrame.hpp"
|
||||
#include "mtx.hpp"
|
||||
|
||||
#include <GLES3/gl32.h>
|
||||
#include <GLES3/gl3ext.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "Shaders.hpp"
|
||||
|
||||
#include "src/helpers/Log.hpp"
|
||||
#include "widgets/PasswordInputField.hpp"
|
||||
#include "widgets/Background.hpp"
|
||||
#include "widgets/Label.hpp"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
|
||||
#include "../core/LockSurface.hpp"
|
||||
#include "Shader.hpp"
|
||||
#include "../helpers/Box.hpp"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "IWidget.hpp"
|
||||
#include "../../helpers/Log.hpp"
|
||||
#include "../../core/hyprlock.hpp"
|
||||
#include "src/core/Auth.hpp"
|
||||
#include <chrono>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Label.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include <hyprlang.hpp>
|
||||
#include <stdexcept>
|
||||
#include "../Renderer.hpp"
|
||||
#include "../../helpers/Log.hpp"
|
||||
#include "../../core/hyprlock.hpp"
|
||||
|
@ -13,6 +14,8 @@ CLabel::~CLabel() {
|
|||
}
|
||||
|
||||
static void onTimer(std::shared_ptr<CTimer> 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<std::string, std::any>& props, const std::string& output) :
|
||||
outputStringPort(output), shadow(this, props, viewport_) {
|
||||
labelPreFormat = std::any_cast<Hyprlang::STRING>(props.at("text"));
|
||||
std::string textAlign = std::any_cast<Hyprlang::STRING>(props.at("text_align"));
|
||||
std::string fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
|
||||
CColor labelColor = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
int fontSize = std::any_cast<Hyprlang::INT>(props.at("font_size"));
|
||||
try {
|
||||
labelPreFormat = std::any_cast<Hyprlang::STRING>(props.at("text"));
|
||||
std::string textAlign = std::any_cast<Hyprlang::STRING>(props.at("text_align"));
|
||||
std::string fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
|
||||
CColor labelColor = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
int fontSize = std::any_cast<Hyprlang::INT>(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<Hyprlang::VEC2>(props.at("position"));
|
||||
pos = {POS__.x, POS__.y};
|
||||
configPos = pos;
|
||||
auto POS__ = std::any_cast<Hyprlang::VEC2>(props.at("position"));
|
||||
pos = {POS__.x, POS__.y};
|
||||
configPos = pos;
|
||||
|
||||
viewport = viewport_;
|
||||
viewport = viewport_;
|
||||
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
angle = angle * M_PI / 180.0;
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(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) {
|
||||
|
|
|
@ -42,7 +42,7 @@ class CLabel : public IWidget {
|
|||
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
|
||||
std::shared_ptr<CTimer> labelTimer;
|
||||
std::shared_ptr<CTimer> labelTimer = nullptr;
|
||||
|
||||
CShadowable shadow;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "../Framebuffer.hpp"
|
||||
#include "../Texture.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include "IWidget.hpp"
|
||||
|
||||
|
|
Loading…
Reference in a new issue