mirror of
https://github.com/hyprwm/hyprlock.git
synced 2025-05-12 21:30:37 +01:00
core: more hyprutils smart pointer usage and safe references to widgets (#686)
* core: move to UP and make widgets use SPs * widgets: make widgets have a self ref to avoid UB * fix shadows and let them have a WP to widgets
This commit is contained in:
parent
712ab62a42
commit
9f37c1c8e9
36 changed files with 546 additions and 385 deletions
|
@ -11,10 +11,10 @@
|
|||
CAuth::CAuth() {
|
||||
static const auto ENABLEPAM = g_pConfigManager->getValue<Hyprlang::INT>("auth:pam:enabled");
|
||||
if (*ENABLEPAM)
|
||||
m_vImpls.push_back(std::make_shared<CPam>());
|
||||
m_vImpls.emplace_back(makeShared<CPam>());
|
||||
static const auto ENABLEFINGERPRINT = g_pConfigManager->getValue<Hyprlang::INT>("auth:fingerprint:enabled");
|
||||
if (*ENABLEFINGERPRINT)
|
||||
m_vImpls.push_back(std::make_shared<CFingerprint>());
|
||||
m_vImpls.emplace_back(makeShared<CFingerprint>());
|
||||
|
||||
RASSERT(!m_vImpls.empty(), "At least one authentication method must be enabled!");
|
||||
}
|
||||
|
@ -32,12 +32,7 @@ void CAuth::submitInput(const std::string& input) {
|
|||
}
|
||||
|
||||
bool CAuth::checkWaiting() {
|
||||
for (const auto& i : m_vImpls) {
|
||||
if (i->checkWaiting())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return std::ranges::any_of(m_vImpls, [](const auto& i) { return i->checkWaiting(); });
|
||||
}
|
||||
|
||||
const std::string& CAuth::getCurrentFailText() {
|
||||
|
@ -64,7 +59,7 @@ size_t CAuth::getFailedAttempts() {
|
|||
return m_sCurrentFail.failedAttempts;
|
||||
}
|
||||
|
||||
std::shared_ptr<IAuthImplementation> CAuth::getImpl(eAuthImplementations implType) {
|
||||
SP<IAuthImplementation> CAuth::getImpl(eAuthImplementations implType) {
|
||||
for (const auto& i : m_vImpls) {
|
||||
if (i->getImplType() == implType)
|
||||
return i;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "../defines.hpp"
|
||||
|
||||
enum eAuthImplementations {
|
||||
AUTH_IMPL_PAM = 0,
|
||||
AUTH_IMPL_FINGERPRINT = 1,
|
||||
|
@ -28,23 +29,23 @@ class CAuth {
|
|||
public:
|
||||
CAuth();
|
||||
|
||||
void start();
|
||||
void start();
|
||||
|
||||
void submitInput(const std::string& input);
|
||||
bool checkWaiting();
|
||||
void submitInput(const std::string& input);
|
||||
bool checkWaiting();
|
||||
|
||||
const std::string& getCurrentFailText();
|
||||
const std::string& getCurrentFailText();
|
||||
|
||||
std::optional<std::string> getFailText(eAuthImplementations implType);
|
||||
std::optional<std::string> getPrompt(eAuthImplementations implType);
|
||||
size_t getFailedAttempts();
|
||||
std::optional<std::string> getFailText(eAuthImplementations implType);
|
||||
std::optional<std::string> getPrompt(eAuthImplementations implType);
|
||||
size_t getFailedAttempts();
|
||||
|
||||
std::shared_ptr<IAuthImplementation> getImpl(eAuthImplementations implType);
|
||||
SP<IAuthImplementation> getImpl(eAuthImplementations implType);
|
||||
|
||||
void terminate();
|
||||
void terminate();
|
||||
|
||||
void enqueueUnlock();
|
||||
void enqueueFail(const std::string& failText, eAuthImplementations implType);
|
||||
void enqueueUnlock();
|
||||
void enqueueFail(const std::string& failText, eAuthImplementations implType);
|
||||
|
||||
// Should only be set via the main thread
|
||||
bool m_bDisplayFailText = false;
|
||||
|
@ -56,7 +57,7 @@ class CAuth {
|
|||
size_t failedAttempts = 0;
|
||||
} m_sCurrentFail;
|
||||
|
||||
std::vector<std::shared_ptr<IAuthImplementation>> m_vImpls;
|
||||
std::vector<SP<IAuthImplementation>> m_vImpls;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CAuth> g_pAuth;
|
||||
inline UP<CAuth> g_pAuth;
|
||||
|
|
|
@ -27,7 +27,7 @@ class ICustomConfigValueData {
|
|||
|
||||
class CLayoutValueData : public ICustomConfigValueData {
|
||||
public:
|
||||
CLayoutValueData() {};
|
||||
CLayoutValueData() = default;
|
||||
virtual ~CLayoutValueData() {};
|
||||
|
||||
virtual eConfigValueDataTypes getDataType() {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <hyprlang.hpp>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "../defines.hpp"
|
||||
|
@ -41,4 +40,4 @@ class CConfigManager {
|
|||
Hyprlang::CConfig m_config;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CConfigManager> g_pConfigManager;
|
||||
inline UP<CConfigManager> g_pConfigManager;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <hyprutils/animation/AnimatedVariable.hpp>
|
||||
|
||||
#include "../helpers/AnimatedVariable.hpp"
|
||||
#include "../helpers/Math.hpp"
|
||||
#include "../defines.hpp"
|
||||
|
||||
class CHyprlockAnimationManager : public Hyprutils::Animation::CAnimationManager {
|
||||
|
@ -31,4 +30,4 @@ class CHyprlockAnimationManager : public Hyprutils::Animation::CAnimationManager
|
|||
bool m_bTickScheduled = false;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CHyprlockAnimationManager> g_pAnimationManager;
|
||||
inline UP<CHyprlockAnimationManager> g_pAnimationManager;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "../defines.hpp"
|
||||
|
||||
class CEGL {
|
||||
public:
|
||||
CEGL(wl_display*);
|
||||
|
@ -19,4 +19,4 @@ class CEGL {
|
|||
void makeCurrent(EGLSurface surf);
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CEGL> g_pEGL;
|
||||
inline UP<CEGL> g_pEGL;
|
||||
|
|
|
@ -11,13 +11,9 @@ CSessionLockSurface::~CSessionLockSurface() {
|
|||
wl_egl_window_destroy(eglWindow);
|
||||
}
|
||||
|
||||
CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) {
|
||||
CSessionLockSurface::CSessionLockSurface(const SP<COutput>& pOutput) : m_outputRef(pOutput), m_outputID(pOutput->m_ID) {
|
||||
surface = makeShared<CCWlSurface>(g_pHyprlock->getCompositor()->sendCreateSurface());
|
||||
|
||||
if (!surface) {
|
||||
Debug::log(CRIT, "Couldn't create wl_surface");
|
||||
exit(1);
|
||||
}
|
||||
RASSERT(surface, "Couldn't create wl_surface");
|
||||
|
||||
static const auto FRACTIONALSCALING = g_pConfigManager->getValue<Hyprlang::INT>("general:fractional_scaling");
|
||||
const auto ENABLE_FSV1 = *FRACTIONALSCALING == 1 || /* auto enable */ (*FRACTIONALSCALING == 2);
|
||||
|
@ -45,7 +41,7 @@ CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) {
|
|||
if (!PVIEWPORTER)
|
||||
Debug::log(LOG, "No viewporter support! Oops, won't be able to scale!");
|
||||
|
||||
lockSurface = makeShared<CCExtSessionLockSurfaceV1>(g_pHyprlock->getSessionLock()->sendGetLockSurface(surface->resource(), output->output->resource()));
|
||||
lockSurface = makeShared<CCExtSessionLockSurfaceV1>(g_pHyprlock->getSessionLock()->sendGetLockSurface(surface->resource(), pOutput->m_wlOutput->resource()));
|
||||
|
||||
if (!lockSurface) {
|
||||
Debug::log(CRIT, "Couldn't create ext_session_lock_surface_v1");
|
||||
|
@ -62,6 +58,8 @@ void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) {
|
|||
const bool SAMESIZE = logicalSize == size_;
|
||||
const bool SAMESCALE = appliedScale == fractionalScale;
|
||||
|
||||
const auto POUTPUT = m_outputRef.lock();
|
||||
|
||||
serial = serial_;
|
||||
logicalSize = size_;
|
||||
appliedScale = fractionalScale;
|
||||
|
@ -71,8 +69,8 @@ void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) {
|
|||
viewport->sendSetDestination(logicalSize.x, logicalSize.y);
|
||||
surface->sendSetBufferScale(1);
|
||||
} else {
|
||||
size = size_ * output->scale;
|
||||
surface->sendSetBufferScale(output->scale);
|
||||
size = size_ * POUTPUT->scale;
|
||||
surface->sendSetBufferScale(POUTPUT->scale);
|
||||
}
|
||||
|
||||
if (!SAMESERIAL)
|
||||
|
@ -103,8 +101,8 @@ void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) {
|
|||
}
|
||||
|
||||
if (readyForFrame && !(SAMESIZE && SAMESCALE)) {
|
||||
g_pRenderer->removeWidgetsFor(this);
|
||||
Debug::log(LOG, "Reloading widgets");
|
||||
Debug::log(LOG, "output {} changed, reloading widgets!", POUTPUT->stringPort);
|
||||
g_pRenderer->reconfigureWidgetsFor(POUTPUT->m_ID);
|
||||
}
|
||||
|
||||
readyForFrame = true;
|
||||
|
@ -129,7 +127,10 @@ void CSessionLockSurface::render() {
|
|||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
Debug::log(TRACE, "[{}] frame {}, Current fps: {:.2f}", output->stringPort, m_frames, 1000.f / (frameTime - m_lastFrameTime));
|
||||
if (Debug::verbose) {
|
||||
const auto POUTPUT = m_outputRef.lock();
|
||||
Debug::log(TRACE, "[{}] frame {}, Current fps: {:.2f}", POUTPUT->stringPort, m_frames, 1000.f / (frameTime - m_lastFrameTime));
|
||||
}
|
||||
|
||||
m_lastFrameTime = frameTime;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class CRenderer;
|
|||
|
||||
class CSessionLockSurface {
|
||||
public:
|
||||
CSessionLockSurface(COutput* output);
|
||||
CSessionLockSurface(const SP<COutput>& pOutput);
|
||||
~CSessionLockSurface();
|
||||
|
||||
void configure(const Vector2D& size, uint32_t serial);
|
||||
|
@ -28,7 +28,9 @@ class CSessionLockSurface {
|
|||
void onScaleUpdate();
|
||||
|
||||
private:
|
||||
COutput* output = nullptr;
|
||||
WP<COutput> m_outputRef;
|
||||
OUTPUTID m_outputID = OUTPUT_INVALID;
|
||||
|
||||
SP<CCWlSurface> surface = nullptr;
|
||||
SP<CCExtSessionLockSurfaceV1> lockSurface = nullptr;
|
||||
uint32_t serial = 0;
|
||||
|
@ -49,4 +51,5 @@ class CSessionLockSurface {
|
|||
SP<CCWlCallback> frameCallback = nullptr;
|
||||
|
||||
friend class CRenderer;
|
||||
};
|
||||
friend class COutput;
|
||||
};
|
||||
|
|
|
@ -1,32 +1,35 @@
|
|||
#include "Output.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "hyprlock.hpp"
|
||||
#include "../renderer/Renderer.hpp"
|
||||
|
||||
COutput::COutput(SP<CCWlOutput> output_, uint32_t name_) : name(name_), output(output_) {
|
||||
output->setDescription([this](CCWlOutput* r, const char* description) {
|
||||
void COutput::create(WP<COutput> pSelf, SP<CCWlOutput> pWlOutput, uint32_t _name) {
|
||||
m_ID = _name;
|
||||
m_wlOutput = pWlOutput;
|
||||
m_self = pSelf;
|
||||
|
||||
m_wlOutput->setDescription([this](CCWlOutput* r, const char* description) {
|
||||
stringDesc = description ? std::string{description} : "";
|
||||
Debug::log(LOG, "output {} description {}", name, stringDesc);
|
||||
Debug::log(LOG, "output {} description {}", m_ID, stringDesc);
|
||||
});
|
||||
|
||||
output->setName([this](CCWlOutput* r, const char* name) {
|
||||
m_wlOutput->setName([this](CCWlOutput* r, const char* name) {
|
||||
stringName = std::string{name} + stringName;
|
||||
stringPort = std::string{name};
|
||||
Debug::log(LOG, "output {} name {}", name, name);
|
||||
});
|
||||
|
||||
output->setScale([this](CCWlOutput* r, int32_t sc) { scale = sc; });
|
||||
m_wlOutput->setScale([this](CCWlOutput* r, int32_t sc) { scale = sc; });
|
||||
|
||||
output->setDone([this](CCWlOutput* r) {
|
||||
m_wlOutput->setDone([this](CCWlOutput* r) {
|
||||
done = true;
|
||||
Debug::log(LOG, "output {} done", name);
|
||||
if (g_pHyprlock->m_lockAquired && !sessionLockSurface) {
|
||||
Debug::log(LOG, "output {} creating a new lock surface", name);
|
||||
sessionLockSurface = std::make_unique<CSessionLockSurface>(this);
|
||||
Debug::log(LOG, "output {} done", m_ID);
|
||||
if (g_pHyprlock->m_lockAquired && !m_sessionLockSurface) {
|
||||
Debug::log(LOG, "output {} creating a new lock surface", m_ID);
|
||||
createSessionLockSurface();
|
||||
}
|
||||
});
|
||||
|
||||
output->setMode([this](CCWlOutput* r, uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
|
||||
m_wlOutput->setMode([this](CCWlOutput* r, uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
|
||||
// handle portrait mode and flipped cases
|
||||
if (transform % 2 == 1)
|
||||
size = {height, width};
|
||||
|
@ -34,10 +37,18 @@ COutput::COutput(SP<CCWlOutput> output_, uint32_t name_) : name(name_), output(o
|
|||
size = {width, height};
|
||||
});
|
||||
|
||||
output->setGeometry(
|
||||
m_wlOutput->setGeometry(
|
||||
[this](CCWlOutput* r, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform_) {
|
||||
transform = (wl_output_transform)transform_;
|
||||
|
||||
Debug::log(LOG, "output {} make {} model {}", name, make ? make : "", model ? model : "");
|
||||
Debug::log(LOG, "output {} make {} model {}", m_ID, make ? make : "", model ? model : "");
|
||||
});
|
||||
}
|
||||
|
||||
void COutput::createSessionLockSurface() {
|
||||
m_sessionLockSurface = makeUnique<CSessionLockSurface>(m_self.lock());
|
||||
}
|
||||
|
||||
Vector2D COutput::getViewport() const {
|
||||
return (m_sessionLockSurface) ? m_sessionLockSurface->size : size;
|
||||
}
|
||||
|
|
|
@ -2,27 +2,32 @@
|
|||
|
||||
#include "../defines.hpp"
|
||||
#include "wayland.hpp"
|
||||
#include "../helpers/Math.hpp"
|
||||
#include "LockSurface.hpp"
|
||||
#include <memory>
|
||||
|
||||
class COutput {
|
||||
public:
|
||||
COutput(SP<CCWlOutput> output, uint32_t name);
|
||||
COutput() = default;
|
||||
~COutput() = default;
|
||||
|
||||
uint32_t name = 0;
|
||||
bool focused = false;
|
||||
bool done = false;
|
||||
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
Vector2D size;
|
||||
int scale = 1;
|
||||
std::string stringName = "";
|
||||
std::string stringPort = "";
|
||||
std::string stringDesc = "";
|
||||
void create(WP<COutput> pSelf, SP<CCWlOutput> pWlOutput, uint32_t name);
|
||||
|
||||
std::unique_ptr<CSessionLockSurface> sessionLockSurface;
|
||||
OUTPUTID m_ID = 0;
|
||||
bool focused = false;
|
||||
bool done = false;
|
||||
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
Vector2D size;
|
||||
int scale = 1;
|
||||
std::string stringName = "";
|
||||
std::string stringPort = "";
|
||||
std::string stringDesc = "";
|
||||
|
||||
SP<CCWlOutput> output = nullptr;
|
||||
UP<CSessionLockSurface> m_sessionLockSurface;
|
||||
|
||||
private:
|
||||
SP<CCWlOutput> m_wlOutput = nullptr;
|
||||
|
||||
WP<COutput> m_self;
|
||||
|
||||
void createSessionLockSurface();
|
||||
|
||||
Vector2D getViewport() const;
|
||||
};
|
||||
|
|
|
@ -131,7 +131,7 @@ void CSeatManager::registerSeat(SP<CCWlSeat> seat) {
|
|||
}
|
||||
|
||||
void CSeatManager::registerCursorShape(SP<CCWpCursorShapeManagerV1> shape) {
|
||||
m_pCursorShape = std::make_unique<CCursorShape>(shape);
|
||||
m_pCursorShape = makeUnique<CCursorShape>(shape);
|
||||
}
|
||||
|
||||
bool CSeatManager::registered() {
|
||||
|
|
|
@ -5,29 +5,28 @@
|
|||
#include "wayland.hpp"
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <xkbcommon/xkbcommon-compose.h>
|
||||
#include <memory>
|
||||
|
||||
class CSeatManager {
|
||||
public:
|
||||
CSeatManager() = default;
|
||||
~CSeatManager();
|
||||
|
||||
void registerSeat(SP<CCWlSeat> seat);
|
||||
void registerCursorShape(SP<CCWpCursorShapeManagerV1> shape);
|
||||
bool registered();
|
||||
void registerSeat(SP<CCWlSeat> seat);
|
||||
void registerCursorShape(SP<CCWpCursorShapeManagerV1> shape);
|
||||
bool registered();
|
||||
|
||||
SP<CCWlKeyboard> m_pKeeb;
|
||||
SP<CCWlPointer> m_pPointer;
|
||||
SP<CCWlKeyboard> m_pKeeb;
|
||||
SP<CCWlPointer> m_pPointer;
|
||||
|
||||
std::unique_ptr<CCursorShape> m_pCursorShape;
|
||||
UP<CCursorShape> m_pCursorShape;
|
||||
|
||||
xkb_context* m_pXKBContext = nullptr;
|
||||
xkb_keymap* m_pXKBKeymap = nullptr;
|
||||
xkb_state* m_pXKBState = nullptr;
|
||||
xkb_compose_state* m_pXKBComposeState = nullptr;
|
||||
xkb_context* m_pXKBContext = nullptr;
|
||||
xkb_keymap* m_pXKBKeymap = nullptr;
|
||||
xkb_state* m_pXKBState = nullptr;
|
||||
xkb_compose_state* m_pXKBComposeState = nullptr;
|
||||
|
||||
private:
|
||||
SP<CCWlSeat> m_pSeat;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CSeatManager> g_pSeatManager = std::make_unique<CSeatManager>();
|
||||
inline UP<CSeatManager> g_pSeatManager = makeUnique<CSeatManager>();
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "../auth/Auth.hpp"
|
||||
#include "../auth/Fingerprint.hpp"
|
||||
#include "Egl.hpp"
|
||||
#include <hyprutils/memory/UniquePtr.hpp>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -43,7 +44,7 @@ CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const b
|
|||
exit(1);
|
||||
}
|
||||
|
||||
g_pEGL = std::make_unique<CEGL>(m_sWaylandState.display);
|
||||
g_pEGL = makeUnique<CEGL>(m_sWaylandState.display);
|
||||
|
||||
if (!immediate) {
|
||||
static const auto GRACE = g_pConfigManager->getValue<Hyprlang::INT>("general:grace");
|
||||
|
@ -283,10 +284,10 @@ void CHyprlock::run() {
|
|||
} else if (IFACE == ext_session_lock_manager_v1_interface.name)
|
||||
m_sWaylandState.sessionLock =
|
||||
makeShared<CCExtSessionLockManagerV1>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &ext_session_lock_manager_v1_interface, 1));
|
||||
else if (IFACE == wl_output_interface.name)
|
||||
m_vOutputs.emplace_back(
|
||||
std::make_unique<COutput>(makeShared<CCWlOutput>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wl_output_interface, 4)), name));
|
||||
else if (IFACE == wp_cursor_shape_manager_v1_interface.name)
|
||||
else if (IFACE == wl_output_interface.name) {
|
||||
m_vOutputs.emplace_back(makeShared<COutput>());
|
||||
m_vOutputs.back()->create(m_vOutputs.back(), makeShared<CCWlOutput>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wl_output_interface, 4)), name);
|
||||
} else if (IFACE == wp_cursor_shape_manager_v1_interface.name)
|
||||
g_pSeatManager->registerCursorShape(
|
||||
makeShared<CCWpCursorShapeManagerV1>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wp_cursor_shape_manager_v1_interface, 1)));
|
||||
else if (IFACE == wl_compositor_interface.name)
|
||||
|
@ -308,9 +309,9 @@ void CHyprlock::run() {
|
|||
});
|
||||
m_sWaylandState.registry->setGlobalRemove([this](CCWlRegistry* r, uint32_t name) {
|
||||
Debug::log(LOG, " | removed iface {}", name);
|
||||
auto outputIt = std::ranges::find_if(m_vOutputs, [name](const auto& other) { return other->name == name; });
|
||||
auto outputIt = std::ranges::find_if(m_vOutputs, [id = name](const auto& other) { return other->m_ID == id; });
|
||||
if (outputIt != m_vOutputs.end()) {
|
||||
g_pRenderer->removeWidgetsFor(outputIt->get()->sessionLockSurface.get());
|
||||
g_pRenderer->removeWidgetsFor((*outputIt)->m_ID);
|
||||
m_vOutputs.erase(outputIt);
|
||||
}
|
||||
});
|
||||
|
@ -325,8 +326,8 @@ void CHyprlock::run() {
|
|||
// gather info about monitors
|
||||
wl_display_roundtrip(m_sWaylandState.display);
|
||||
|
||||
g_pRenderer = std::make_unique<CRenderer>();
|
||||
g_pAuth = std::make_unique<CAuth>();
|
||||
g_pRenderer = makeUnique<CRenderer>();
|
||||
g_pAuth = makeUnique<CAuth>();
|
||||
g_pAuth->start();
|
||||
|
||||
Debug::log(LOG, "Running on {}", m_sCurrentDesktop);
|
||||
|
@ -554,23 +555,23 @@ void CHyprlock::clearPasswordBuffer() {
|
|||
void CHyprlock::renderOutput(const std::string& stringPort) {
|
||||
const auto MON = std::ranges::find_if(m_vOutputs, [stringPort](const auto& other) { return other->stringPort == stringPort; });
|
||||
|
||||
if (MON == m_vOutputs.end() || !MON->get())
|
||||
if (MON == m_vOutputs.end() || !*MON)
|
||||
return;
|
||||
|
||||
const auto PMONITOR = MON->get();
|
||||
const auto& PMONITOR = *MON;
|
||||
|
||||
if (!PMONITOR->sessionLockSurface)
|
||||
if (!PMONITOR->m_sessionLockSurface)
|
||||
return;
|
||||
|
||||
PMONITOR->sessionLockSurface->render();
|
||||
PMONITOR->m_sessionLockSurface->render();
|
||||
}
|
||||
|
||||
void CHyprlock::renderAllOutputs() {
|
||||
for (auto& o : m_vOutputs) {
|
||||
if (!o->sessionLockSurface)
|
||||
if (!o->m_sessionLockSurface)
|
||||
continue;
|
||||
|
||||
o->sessionLockSurface->render();
|
||||
o->m_sessionLockSurface->render();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -723,7 +724,7 @@ bool CHyprlock::acquireSessionLock() {
|
|||
if (!o->done)
|
||||
continue;
|
||||
|
||||
o->sessionLockSurface = std::make_unique<CSessionLockSurface>(o.get());
|
||||
o->createSessionLockSurface();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -37,9 +37,6 @@ class CHyprlock {
|
|||
void unlock();
|
||||
bool isUnlocked();
|
||||
|
||||
void onGlobal(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version);
|
||||
void onGlobalRemoved(void* data, struct wl_registry* registry, uint32_t name);
|
||||
|
||||
std::shared_ptr<CTimer> addTimer(const std::chrono::system_clock::duration& timeout, std::function<void(std::shared_ptr<CTimer> self, void* data)> cb_, void* data,
|
||||
bool force = false);
|
||||
|
||||
|
@ -103,7 +100,7 @@ class CHyprlock {
|
|||
|
||||
std::shared_ptr<CTimer> m_pKeyRepeatTimer = nullptr;
|
||||
|
||||
std::vector<std::unique_ptr<COutput>> m_vOutputs;
|
||||
std::vector<SP<COutput>> m_vOutputs;
|
||||
std::vector<std::shared_ptr<CTimer>> getTimers();
|
||||
|
||||
struct {
|
||||
|
@ -167,4 +164,4 @@ class CHyprlock {
|
|||
std::vector<uint32_t> m_vPressedKeys;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CHyprlock> g_pHyprlock;
|
||||
inline UP<CHyprlock> g_pHyprlock;
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <hyprutils/memory/WeakPtr.hpp>
|
||||
#include <hyprutils/memory/UniquePtr.hpp>
|
||||
#include <hyprgraphics/color/Color.hpp>
|
||||
|
||||
using namespace Hyprutils::Memory;
|
||||
using namespace Hyprgraphics;
|
||||
#define SP CSharedPointer
|
||||
#define WP CWeakPointer
|
||||
#define WP CWeakPointer
|
||||
#define UP CUniquePointer
|
||||
|
||||
typedef int64_t OUTPUTID;
|
||||
constexpr OUTPUTID OUTPUT_INVALID = -1;
|
||||
|
|
|
@ -90,10 +90,10 @@ int main(int argc, char** argv, char** envp) {
|
|||
}
|
||||
}
|
||||
|
||||
g_pAnimationManager = std::make_unique<CHyprlockAnimationManager>();
|
||||
g_pAnimationManager = makeUnique<CHyprlockAnimationManager>();
|
||||
|
||||
try {
|
||||
g_pConfigManager = std::make_unique<CConfigManager>(configPath);
|
||||
g_pConfigManager = makeUnique<CConfigManager>(configPath);
|
||||
g_pConfigManager->init();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "ConfigManager threw: {}", ex.what());
|
||||
|
@ -107,7 +107,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
g_pConfigManager->m_AnimationTree.setConfigForNode("fadeIn", false, 0.f, "default");
|
||||
|
||||
try {
|
||||
g_pHyprlock = std::make_unique<CHyprlock>(wlDisplay, immediate, immediateRender);
|
||||
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender);
|
||||
g_pHyprlock->run();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "Hyprlock threw: {}", ex.what());
|
||||
|
|
|
@ -48,15 +48,12 @@ void CAsyncResourceGatherer::enqueueScreencopyFrames() {
|
|||
}
|
||||
|
||||
for (auto& mon : mons) {
|
||||
const auto MON = std::find_if(g_pHyprlock->m_vOutputs.begin(), g_pHyprlock->m_vOutputs.end(),
|
||||
[mon](const auto& other) { return other->stringPort == mon || other->stringDesc.starts_with(mon); });
|
||||
const auto MON = std::ranges::find_if(g_pHyprlock->m_vOutputs, [mon](const auto& other) { return other->stringPort == mon || other->stringDesc.starts_with(mon); });
|
||||
|
||||
if (MON == g_pHyprlock->m_vOutputs.end())
|
||||
continue;
|
||||
|
||||
const auto PMONITOR = MON->get();
|
||||
|
||||
scframes.emplace_back(std::make_unique<CScreencopyFrame>(PMONITOR));
|
||||
scframes.emplace_back(makeUnique<CScreencopyFrame>(*MON));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,17 +301,6 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
|
|||
preloadTargets.push_back(target);
|
||||
}
|
||||
|
||||
struct STimerCallbackData {
|
||||
void (*cb)(void*) = nullptr;
|
||||
void* data = nullptr;
|
||||
};
|
||||
|
||||
static void timerCallback(std::shared_ptr<CTimer> self, void* data_) {
|
||||
auto data = (STimerCallbackData*)data_;
|
||||
data->cb(data->data);
|
||||
delete data;
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::asyncAssetSpinLock() {
|
||||
while (!g_pHyprlock->m_bTerminate) {
|
||||
|
||||
|
@ -349,7 +335,7 @@ void CAsyncResourceGatherer::asyncAssetSpinLock() {
|
|||
|
||||
// plant timer for callback
|
||||
if (r.callback)
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), timerCallback, new STimerCallbackData{.cb = r.callback, .data = r.callbackData});
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), [cb = r.callback](auto, auto) { cb(); }, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,7 @@ class CAsyncResourceGatherer {
|
|||
// optional. Callbacks will be dispatched from the main thread,
|
||||
// so wayland/gl calls are OK.
|
||||
// will fire once the resource is fully loaded and ready.
|
||||
void (*callback)(void*) = nullptr;
|
||||
void* callbackData = nullptr;
|
||||
std::function<void()> callback = nullptr;
|
||||
};
|
||||
|
||||
void requestAsyncAssetPreload(const SPreloadRequest& request);
|
||||
|
@ -75,7 +74,7 @@ class CAsyncResourceGatherer {
|
|||
Vector2D size;
|
||||
};
|
||||
|
||||
std::vector<std::unique_ptr<CScreencopyFrame>> scframes;
|
||||
std::vector<UP<CScreencopyFrame>> scframes;
|
||||
|
||||
std::vector<SPreloadTarget> preloadTargets;
|
||||
std::mutex preloadTargetsMutex;
|
||||
|
|
|
@ -194,7 +194,7 @@ CRenderer::CRenderer() {
|
|||
borderShader.gradientLerp = glGetUniformLocation(prog, "gradientLerp");
|
||||
borderShader.alpha = glGetUniformLocation(prog, "alpha");
|
||||
|
||||
asyncResourceGatherer = std::make_unique<CAsyncResourceGatherer>();
|
||||
asyncResourceGatherer = makeUnique<CAsyncResourceGatherer>();
|
||||
|
||||
g_pAnimationManager->createAnimation(0.f, opacity, g_pConfigManager->m_AnimationTree.getConfig("fadeIn"));
|
||||
}
|
||||
|
@ -231,8 +231,8 @@ CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf
|
|||
} else {
|
||||
|
||||
// render widgets
|
||||
const auto WIDGETS = getOrCreateWidgetsFor(&surf);
|
||||
for (auto& w : *WIDGETS) {
|
||||
const auto WIDGETS = getOrCreateWidgetsFor(surf);
|
||||
for (auto& w : WIDGETS) {
|
||||
feedback.needsFrame = w->draw({opacity->value()}) || feedback.needsFrame;
|
||||
}
|
||||
}
|
||||
|
@ -397,62 +397,49 @@ void CRenderer::renderTextureMix(const CBox& box, const CTexture& tex, const CTe
|
|||
glBindTexture(tex.m_iTarget, 0);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface* surf) {
|
||||
if (!widgets.contains(surf)) {
|
||||
template <class Widget>
|
||||
static void createWidget(std::vector<SP<IWidget>>& widgets) {
|
||||
const auto W = makeShared<Widget>();
|
||||
W->registerSelf(W);
|
||||
widgets.emplace_back(W);
|
||||
}
|
||||
|
||||
std::vector<SP<IWidget>>& CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface& surf) {
|
||||
RASSERT(surf.m_outputID != OUTPUT_INVALID, "Invalid output ID!");
|
||||
|
||||
if (!widgets.contains(surf.m_outputID)) {
|
||||
auto CWIDGETS = g_pConfigManager->getWidgetConfigs();
|
||||
|
||||
std::ranges::sort(CWIDGETS, [](CConfigManager::SWidgetConfig& a, CConfigManager::SWidgetConfig& b) {
|
||||
return std::any_cast<Hyprlang::INT>(a.values.at("zindex")) < std::any_cast<Hyprlang::INT>(b.values.at("zindex"));
|
||||
});
|
||||
|
||||
const auto POUTPUT = surf.m_outputRef.lock();
|
||||
for (auto& c : CWIDGETS) {
|
||||
if (!c.monitor.empty() && c.monitor != surf->output->stringPort && !surf->output->stringDesc.starts_with(c.monitor) &&
|
||||
!surf->output->stringDesc.starts_with("desc:" + c.monitor))
|
||||
if (!c.monitor.empty() && c.monitor != POUTPUT->stringPort && !POUTPUT->stringDesc.starts_with(c.monitor) && !POUTPUT->stringDesc.starts_with("desc:" + c.monitor))
|
||||
continue;
|
||||
|
||||
// by type
|
||||
if (c.type == "background") {
|
||||
const std::string PATH = std::any_cast<Hyprlang::STRING>(c.values.at("path"));
|
||||
|
||||
std::string resourceID = "";
|
||||
if (PATH == "screenshot") {
|
||||
resourceID = CScreencopyFrame::getResourceId(surf->output);
|
||||
// When the initial gather of the asyncResourceGatherer is completed (ready), all DMAFrames are available.
|
||||
// Dynamic ones are tricky, because a screencopy would copy hyprlock itself.
|
||||
if (asyncResourceGatherer->gathered) {
|
||||
if (!asyncResourceGatherer->getAssetByID(resourceID))
|
||||
resourceID = ""; // Fallback to solid color (background:color)
|
||||
}
|
||||
|
||||
if (!g_pHyprlock->getScreencopy()) {
|
||||
Debug::log(ERR, "No screencopy support! path=screenshot won't work. Falling back to background color.");
|
||||
resourceID = "";
|
||||
}
|
||||
|
||||
} else if (!PATH.empty())
|
||||
resourceID = "background:" + PATH;
|
||||
|
||||
widgets[surf].emplace_back(std::make_unique<CBackground>(surf->size, surf->output, resourceID, c.values, PATH == "screenshot"));
|
||||
createWidget<CBackground>(widgets[surf.m_outputID]);
|
||||
} else if (c.type == "input-field") {
|
||||
widgets[surf].emplace_back(std::make_unique<CPasswordInputField>(surf->size, c.values, surf->output->stringPort));
|
||||
createWidget<CPasswordInputField>(widgets[surf.m_outputID]);
|
||||
} else if (c.type == "label") {
|
||||
widgets[surf].emplace_back(std::make_unique<CLabel>(surf->size, c.values, surf->output->stringPort));
|
||||
createWidget<CLabel>(widgets[surf.m_outputID]);
|
||||
} else if (c.type == "shape") {
|
||||
widgets[surf].emplace_back(std::make_unique<CShape>(surf->size, c.values));
|
||||
createWidget<CShape>(widgets[surf.m_outputID]);
|
||||
} else if (c.type == "image") {
|
||||
const std::string PATH = std::any_cast<Hyprlang::STRING>(c.values.at("path"));
|
||||
|
||||
std::string resourceID = "";
|
||||
if (!PATH.empty())
|
||||
resourceID = "image:" + PATH;
|
||||
|
||||
widgets[surf].emplace_back(std::make_unique<CImage>(surf->size, surf->output, resourceID, c.values));
|
||||
createWidget<CImage>(widgets[surf.m_outputID]);
|
||||
} else {
|
||||
Debug::log(ERR, "Unknown widget type: {}", c.type);
|
||||
continue;
|
||||
}
|
||||
|
||||
widgets[surf.m_outputID].back()->configure(c.values, POUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
return &widgets[surf];
|
||||
return widgets[surf.m_outputID];
|
||||
}
|
||||
|
||||
void CRenderer::blurFB(const CFramebuffer& outfb, SBlurParams params) {
|
||||
|
@ -618,8 +605,15 @@ void CRenderer::popFb() {
|
|||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, boundFBs.empty() ? 0 : boundFBs.back());
|
||||
}
|
||||
|
||||
void CRenderer::removeWidgetsFor(const CSessionLockSurface* surf) {
|
||||
widgets.erase(surf);
|
||||
void CRenderer::removeWidgetsFor(OUTPUTID id) {
|
||||
widgets.erase(id);
|
||||
}
|
||||
|
||||
void CRenderer::reconfigureWidgetsFor(OUTPUTID id) {
|
||||
// TODO: reconfigure widgets by just calling their configure method again.
|
||||
// Requires a way to get a widgets config properties.
|
||||
// I think the best way would be to store the anonymos key of the widget config.
|
||||
removeWidgetsFor(id);
|
||||
}
|
||||
|
||||
void CRenderer::startFadeIn() {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include "Shader.hpp"
|
||||
#include "../defines.hpp"
|
||||
#include "../core/LockSurface.hpp"
|
||||
#include "../helpers/AnimatedVariable.hpp"
|
||||
#include "../helpers/Color.hpp"
|
||||
|
@ -12,7 +12,7 @@
|
|||
#include "widgets/IWidget.hpp"
|
||||
#include "Framebuffer.hpp"
|
||||
|
||||
typedef std::unordered_map<const CSessionLockSurface*, std::vector<std::unique_ptr<IWidget>>> widgetMap_t;
|
||||
typedef std::unordered_map<OUTPUTID, std::vector<SP<IWidget>>> widgetMap_t;
|
||||
|
||||
class CRenderer {
|
||||
public:
|
||||
|
@ -29,7 +29,7 @@ class CRenderer {
|
|||
float boostA = 1.0;
|
||||
};
|
||||
|
||||
SRenderFeedback renderLock(const CSessionLockSurface& surface);
|
||||
SRenderFeedback renderLock(const CSessionLockSurface& surf);
|
||||
|
||||
void renderRect(const CBox& box, const CHyprColor& col, int rounding = 0);
|
||||
void renderBorder(const CBox& box, const CGradientValueData& gradient, int thickness, int rounding = 0, float alpha = 1.0);
|
||||
|
@ -37,37 +37,38 @@ class CRenderer {
|
|||
void renderTextureMix(const CBox& box, const CTexture& tex, const CTexture& tex2, float a = 1.0, float mixFactor = 0.0, int rounding = 0, std::optional<eTransform> tr = {});
|
||||
void blurFB(const CFramebuffer& outfb, SBlurParams params);
|
||||
|
||||
std::unique_ptr<CAsyncResourceGatherer> asyncResourceGatherer;
|
||||
std::chrono::system_clock::time_point firstFullFrameTime;
|
||||
UP<CAsyncResourceGatherer> asyncResourceGatherer;
|
||||
std::chrono::system_clock::time_point firstFullFrameTime;
|
||||
|
||||
void pushFb(GLint fb);
|
||||
void popFb();
|
||||
void pushFb(GLint fb);
|
||||
void popFb();
|
||||
|
||||
void removeWidgetsFor(const CSessionLockSurface* surf);
|
||||
void removeWidgetsFor(OUTPUTID id);
|
||||
void reconfigureWidgetsFor(OUTPUTID id);
|
||||
|
||||
void startFadeIn();
|
||||
void startFadeOut(bool unlock = false, bool immediate = true);
|
||||
void startFadeIn();
|
||||
void startFadeOut(bool unlock = false, bool immediate = true);
|
||||
|
||||
private:
|
||||
widgetMap_t widgets;
|
||||
widgetMap_t widgets;
|
||||
|
||||
std::vector<std::unique_ptr<IWidget>>* getOrCreateWidgetsFor(const CSessionLockSurface* surf);
|
||||
std::vector<SP<IWidget>>& getOrCreateWidgetsFor(const CSessionLockSurface& surf);
|
||||
|
||||
CShader rectShader;
|
||||
CShader texShader;
|
||||
CShader texMixShader;
|
||||
CShader blurShader1;
|
||||
CShader blurShader2;
|
||||
CShader blurPrepareShader;
|
||||
CShader blurFinishShader;
|
||||
CShader borderShader;
|
||||
CShader rectShader;
|
||||
CShader texShader;
|
||||
CShader texMixShader;
|
||||
CShader blurShader1;
|
||||
CShader blurShader2;
|
||||
CShader blurPrepareShader;
|
||||
CShader blurFinishShader;
|
||||
CShader borderShader;
|
||||
|
||||
Mat3x3 projMatrix = Mat3x3::identity();
|
||||
Mat3x3 projection;
|
||||
Mat3x3 projMatrix = Mat3x3::identity();
|
||||
Mat3x3 projection;
|
||||
|
||||
PHLANIMVAR<float> opacity;
|
||||
PHLANIMVAR<float> opacity;
|
||||
|
||||
std::vector<GLint> boundFBs;
|
||||
std::vector<GLint> boundFBs;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CRenderer> g_pRenderer;
|
||||
inline UP<CRenderer> g_pRenderer;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <gbm.h>
|
||||
#include <hyprutils/memory/UniquePtr.hpp>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <libdrm/drm_fourcc.h>
|
||||
|
@ -22,24 +23,27 @@ static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = nullpt
|
|||
static PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT = nullptr;
|
||||
|
||||
//
|
||||
std::string CScreencopyFrame::getResourceId(COutput* output) {
|
||||
return std::format("screencopy:{}-{}x{}", output->stringPort, output->size.x, output->size.y);
|
||||
std::string CScreencopyFrame::getResourceId(SP<COutput> pOutput) {
|
||||
return std::format("screencopy:{}-{}x{}", pOutput->stringPort, pOutput->size.x, pOutput->size.y);
|
||||
}
|
||||
|
||||
CScreencopyFrame::CScreencopyFrame(COutput* output) : m_output(output) {
|
||||
m_resourceID = getResourceId(m_output);
|
||||
|
||||
CScreencopyFrame::CScreencopyFrame(SP<COutput> pOutput) : m_outputRef(pOutput) {
|
||||
captureOutput();
|
||||
|
||||
static const auto SCMODE = g_pConfigManager->getValue<Hyprlang::INT>("general:screencopy_mode");
|
||||
if (*SCMODE == 1)
|
||||
m_frame = std::make_unique<CSCSHMFrame>(m_sc);
|
||||
m_frame = makeUnique<CSCSHMFrame>(m_sc);
|
||||
else
|
||||
m_frame = std::make_unique<CSCDMAFrame>(m_sc);
|
||||
m_frame = makeUnique<CSCDMAFrame>(m_sc);
|
||||
}
|
||||
|
||||
void CScreencopyFrame::captureOutput() {
|
||||
m_sc = makeShared<CCZwlrScreencopyFrameV1>(g_pHyprlock->getScreencopy()->sendCaptureOutput(false, m_output->output->resource()));
|
||||
const auto POUTPUT = m_outputRef.lock();
|
||||
RASSERT(POUTPUT, "Screencopy, but no valid output");
|
||||
|
||||
m_resourceID = getResourceId(POUTPUT);
|
||||
|
||||
m_sc = makeShared<CCZwlrScreencopyFrameV1>(g_pHyprlock->getScreencopy()->sendCaptureOutput(false, POUTPUT->m_wlOutput->resource()));
|
||||
|
||||
m_sc->setBufferDone([this](CCZwlrScreencopyFrameV1* r) {
|
||||
Debug::log(TRACE, "[sc] wlrOnBufferDone for {}", (void*)this);
|
||||
|
|
|
@ -22,9 +22,9 @@ class ISCFrame {
|
|||
|
||||
class CScreencopyFrame {
|
||||
public:
|
||||
static std::string getResourceId(COutput* output);
|
||||
static std::string getResourceId(SP<COutput> pOutput);
|
||||
|
||||
CScreencopyFrame(COutput* mon);
|
||||
CScreencopyFrame(SP<COutput> pOutput);
|
||||
~CScreencopyFrame() = default;
|
||||
|
||||
void captureOutput();
|
||||
|
@ -35,10 +35,10 @@ class CScreencopyFrame {
|
|||
SPreloadedAsset m_asset;
|
||||
|
||||
private:
|
||||
COutput* m_output = nullptr;
|
||||
std::unique_ptr<ISCFrame> m_frame = nullptr;
|
||||
WP<COutput> m_outputRef;
|
||||
UP<ISCFrame> m_frame = nullptr;
|
||||
|
||||
bool m_dmaFailed = false;
|
||||
bool m_dmaFailed = false;
|
||||
};
|
||||
|
||||
// Uses a gpu buffer created via gbm_bo
|
||||
|
|
|
@ -10,23 +10,15 @@
|
|||
#include <GLES3/gl32.h>
|
||||
|
||||
CBackground::~CBackground() {
|
||||
|
||||
if (reloadTimer) {
|
||||
reloadTimer->cancel();
|
||||
reloadTimer.reset();
|
||||
}
|
||||
|
||||
if (fade) {
|
||||
if (fade->crossFadeTimer) {
|
||||
fade->crossFadeTimer->cancel();
|
||||
fade->crossFadeTimer.reset();
|
||||
}
|
||||
fade.reset();
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
CBackground::CBackground(const Vector2D& viewport_, COutput* output_, const std::string& resourceID_, const std::unordered_map<std::string, std::any>& props, bool ss) :
|
||||
viewport(viewport_), resourceID(resourceID_), output(output_), isScreenshot(ss) {
|
||||
void CBackground::registerSelf(const SP<CBackground>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
void CBackground::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
try {
|
||||
color = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
|
@ -48,6 +40,29 @@ CBackground::CBackground(const Vector2D& viewport_, COutput* output_, const std:
|
|||
RASSERT(false, "Missing propperty for CBackground: {}", e.what()); //
|
||||
}
|
||||
|
||||
isScreenshot = path == "screenshot";
|
||||
|
||||
viewport = pOutput->getViewport();
|
||||
outputPort = pOutput->stringPort;
|
||||
transform = isScreenshot ? wlTransformToHyprutils(invertTransform(pOutput->transform)) : HYPRUTILS_TRANSFORM_NORMAL;
|
||||
|
||||
if (isScreenshot) {
|
||||
resourceID = CScreencopyFrame::getResourceId(pOutput);
|
||||
// When the initial gather of the asyncResourceGatherer is completed (ready), all DMAFrames are available.
|
||||
// Dynamic ones are tricky, because a screencopy would copy hyprlock itself.
|
||||
if (g_pRenderer->asyncResourceGatherer->gathered) {
|
||||
if (!g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID))
|
||||
resourceID = ""; // Fallback to solid color (background:color)
|
||||
}
|
||||
|
||||
if (!g_pHyprlock->getScreencopy()) {
|
||||
Debug::log(ERR, "No screencopy support! path=screenshot won't work. Falling back to background color.");
|
||||
resourceID = "";
|
||||
}
|
||||
|
||||
} else if (!path.empty())
|
||||
resourceID = "background:" + path;
|
||||
|
||||
if (!isScreenshot && reloadTime > -1) {
|
||||
try {
|
||||
modificationTime = std::filesystem::last_write_time(absolutePath(path, ""));
|
||||
|
@ -57,30 +72,41 @@ CBackground::CBackground(const Vector2D& viewport_, COutput* output_, const std:
|
|||
}
|
||||
}
|
||||
|
||||
void CBackground::reset() {
|
||||
if (reloadTimer) {
|
||||
reloadTimer->cancel();
|
||||
reloadTimer.reset();
|
||||
}
|
||||
|
||||
if (fade) {
|
||||
if (fade->crossFadeTimer) {
|
||||
fade->crossFadeTimer->cancel();
|
||||
fade->crossFadeTimer.reset();
|
||||
}
|
||||
fade.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void CBackground::renderRect(CHyprColor color) {
|
||||
CBox monbox = {0, 0, viewport.x, viewport.y};
|
||||
g_pRenderer->renderRect(monbox, color, 0);
|
||||
}
|
||||
|
||||
static void onReloadTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
const auto PBG = (CBackground*)data;
|
||||
|
||||
PBG->onReloadTimerUpdate();
|
||||
PBG->plantReloadTimer();
|
||||
static void onReloadTimer(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG) {
|
||||
PBG->onReloadTimerUpdate();
|
||||
PBG->plantReloadTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void onCrossFadeTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
const auto PBG = (CBackground*)data;
|
||||
PBG->onCrossFadeTimerUpdate();
|
||||
static void onCrossFadeTimer(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG)
|
||||
PBG->onCrossFadeTimerUpdate();
|
||||
}
|
||||
|
||||
static void onAssetCallback(void* data) {
|
||||
const auto PBG = (CBackground*)data;
|
||||
PBG->startCrossFadeOrUpdateRender();
|
||||
}
|
||||
|
||||
static void onAssetCallbackTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
onAssetCallback(data);
|
||||
static void onAssetCallback(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG)
|
||||
PBG->startCrossFadeOrUpdateRender();
|
||||
}
|
||||
|
||||
bool CBackground::draw(const SRenderData& data) {
|
||||
|
@ -115,7 +141,7 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
|
||||
// make it brah
|
||||
Vector2D size = asset->texture.m_vSize;
|
||||
if (output->transform % 2 == 1 && isScreenshot) {
|
||||
if (transform % 2 == 1 && isScreenshot) {
|
||||
size.x = asset->texture.m_vSize.y;
|
||||
size.y = asset->texture.m_vSize.x;
|
||||
}
|
||||
|
@ -142,16 +168,19 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
if (fade)
|
||||
g_pRenderer->renderTextureMix(texbox, asset->texture, pendingAsset->texture, 1.0,
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - fade->start).count() / (1000 * crossFadeTime), 0,
|
||||
HYPRUTILS_TRANSFORM_NORMAL);
|
||||
transform);
|
||||
else
|
||||
g_pRenderer->renderTexture(texbox, asset->texture, 1.0, 0,
|
||||
isScreenshot ?
|
||||
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
|
||||
g_pRenderer->renderTexture(texbox, asset->texture, 1.0, 0, transform);
|
||||
|
||||
if (blurPasses > 0)
|
||||
g_pRenderer->blurFB(blurredFB, CRenderer::SBlurParams{
|
||||
.size = blurSize, .passes = blurPasses, .noise = noise, .contrast = contrast, .brightness = brightness, .vibrancy = vibrancy, .vibrancy_darkness = vibrancy_darkness});
|
||||
g_pRenderer->blurFB(blurredFB,
|
||||
CRenderer::SBlurParams{.size = blurSize,
|
||||
.passes = blurPasses,
|
||||
.noise = noise,
|
||||
.contrast = contrast,
|
||||
.brightness = brightness,
|
||||
.vibrancy = vibrancy,
|
||||
.vibrancy_darkness = vibrancy_darkness});
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
|
@ -179,9 +208,9 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
void CBackground::plantReloadTimer() {
|
||||
|
||||
if (reloadTime == 0)
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::hours(1), onReloadTimer, this, true);
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::hours(1), [REF = m_self](auto, auto) { onReloadTimer(REF); }, nullptr, true);
|
||||
else if (reloadTime > 0)
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), onReloadTimer, this, false);
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), [REF = m_self](auto, auto) { onReloadTimer(REF); }, nullptr, true);
|
||||
}
|
||||
|
||||
void CBackground::onCrossFadeTimerUpdate() {
|
||||
|
@ -190,7 +219,7 @@ void CBackground::onCrossFadeTimerUpdate() {
|
|||
|
||||
if (fade) {
|
||||
fade->crossFadeTimer.reset();
|
||||
fade.reset(nullptr);
|
||||
fade.reset();
|
||||
}
|
||||
|
||||
if (blurPasses <= 0 && !isScreenshot)
|
||||
|
@ -202,7 +231,7 @@ void CBackground::onCrossFadeTimerUpdate() {
|
|||
pendingAsset = nullptr;
|
||||
firstRender = true;
|
||||
|
||||
g_pHyprlock->renderOutput(output->stringPort);
|
||||
g_pHyprlock->renderOutput(outputPort);
|
||||
}
|
||||
|
||||
void CBackground::onReloadTimerUpdate() {
|
||||
|
@ -245,8 +274,7 @@ void CBackground::onReloadTimerUpdate() {
|
|||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
|
||||
request.callback = onAssetCallback;
|
||||
request.callbackData = this;
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
@ -262,7 +290,7 @@ void CBackground::startCrossFadeOrUpdateRender() {
|
|||
if (crossFadeTime > 0) {
|
||||
// Start a fade
|
||||
if (!fade)
|
||||
fade = std::make_unique<SFade>(std::chrono::system_clock::now(), 0, nullptr);
|
||||
fade = makeUnique<SFade>(std::chrono::system_clock::now(), 0, nullptr);
|
||||
else {
|
||||
// Maybe we where already fading so reset it just in case, but should'nt be happening.
|
||||
if (fade->crossFadeTimer) {
|
||||
|
@ -270,17 +298,18 @@ void CBackground::startCrossFadeOrUpdateRender() {
|
|||
fade->crossFadeTimer.reset();
|
||||
}
|
||||
}
|
||||
fade->start = std::chrono::system_clock::now();
|
||||
fade->a = 0;
|
||||
fade->crossFadeTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)(1000.0 * crossFadeTime)), onCrossFadeTimer, this);
|
||||
fade->start = std::chrono::system_clock::now();
|
||||
fade->a = 0;
|
||||
fade->crossFadeTimer =
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds((int)(1000.0 * crossFadeTime)), [REF = m_self](auto, auto) { onCrossFadeTimer(REF); }, nullptr);
|
||||
} else {
|
||||
onCrossFadeTimerUpdate();
|
||||
}
|
||||
}
|
||||
} else if (!pendingResourceID.empty()) {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), onAssetCallbackTimer, this);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(output->stringPort);
|
||||
g_pHyprlock->renderOutput(outputPort);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "../../core/Timer.hpp"
|
||||
#include "../Framebuffer.hpp"
|
||||
#include "../AsyncResourceGatherer.hpp"
|
||||
#include <hyprutils/math/Misc.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <any>
|
||||
|
@ -23,10 +24,16 @@ struct SFade {
|
|||
|
||||
class CBackground : public IWidget {
|
||||
public:
|
||||
CBackground(const Vector2D& viewport, COutput* output_, const std::string& resourceID, const std::unordered_map<std::string, std::any>& props, bool ss_);
|
||||
CBackground() = default;
|
||||
~CBackground();
|
||||
|
||||
void registerSelf(const SP<CBackground>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
|
||||
void reset(); // Unload assets, remove timers, etc.
|
||||
|
||||
void renderRect(CHyprColor color);
|
||||
|
||||
void onReloadTimerUpdate();
|
||||
|
@ -35,6 +42,8 @@ class CBackground : public IWidget {
|
|||
void startCrossFadeOrUpdateRender();
|
||||
|
||||
private:
|
||||
WP<CBackground> m_self;
|
||||
|
||||
// if needed
|
||||
CFramebuffer blurredFB;
|
||||
|
||||
|
@ -48,6 +57,9 @@ class CBackground : public IWidget {
|
|||
Vector2D viewport;
|
||||
std::string path = "";
|
||||
|
||||
std::string outputPort;
|
||||
Hyprutils::Math::eTransform transform;
|
||||
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID;
|
||||
|
||||
|
@ -55,16 +67,15 @@ class CBackground : public IWidget {
|
|||
|
||||
CHyprColor color;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
COutput* output = nullptr;
|
||||
bool isScreenshot = false;
|
||||
SPreloadedAsset* pendingAsset = nullptr;
|
||||
bool firstRender = true;
|
||||
|
||||
std::unique_ptr<SFade> fade;
|
||||
UP<SFade> fade;
|
||||
|
||||
int reloadTime = -1;
|
||||
std::string reloadCommand;
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
std::shared_ptr<CTimer> reloadTimer;
|
||||
std::filesystem::file_time_type modificationTime;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace std {
|
|||
}
|
||||
#endif
|
||||
|
||||
Vector2D rotateVector(const Vector2D& vec, const double& ang) {
|
||||
static 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));
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../helpers/Math.hpp"
|
||||
#include "../../defines.hpp"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <any>
|
||||
|
||||
class COutput;
|
||||
|
||||
class IWidget {
|
||||
public:
|
||||
struct SRenderData {
|
||||
float opacity = 1;
|
||||
};
|
||||
|
||||
virtual ~IWidget() = default;
|
||||
|
||||
virtual bool draw(const SRenderData& data) = 0;
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput) = 0;
|
||||
virtual bool draw(const SRenderData& data) = 0;
|
||||
|
||||
static Vector2D posFromHVAlign(const Vector2D& viewport, const Vector2D& size, const Vector2D& offset, const std::string& halign, const std::string& valign,
|
||||
const double& ang = 0);
|
||||
|
|
|
@ -8,26 +8,23 @@
|
|||
#include <hyprlang.hpp>
|
||||
|
||||
CImage::~CImage() {
|
||||
if (imageTimer) {
|
||||
imageTimer->cancel();
|
||||
imageTimer.reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
void CImage::registerSelf(const SP<CImage>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
static void onTimer(WP<CImage> ref) {
|
||||
if (auto PIMAGE = ref.lock(); PIMAGE) {
|
||||
PIMAGE->onTimerUpdate();
|
||||
PIMAGE->plantTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void onTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
const auto PIMAGE = (CImage*)data;
|
||||
|
||||
PIMAGE->onTimerUpdate();
|
||||
PIMAGE->plantTimer();
|
||||
}
|
||||
|
||||
static void onAssetCallback(void* data) {
|
||||
const auto PIMAGE = (CImage*)data;
|
||||
PIMAGE->renderUpdate();
|
||||
}
|
||||
|
||||
static void onAssetCallbackTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
onAssetCallback(data);
|
||||
static void onAssetCallback(WP<CImage> ref) {
|
||||
if (auto PIMAGE = ref.lock(); PIMAGE)
|
||||
PIMAGE->renderUpdate();
|
||||
}
|
||||
|
||||
void CImage::onTimerUpdate() {
|
||||
|
@ -65,9 +62,7 @@ void CImage::onTimerUpdate() {
|
|||
pendingResourceID = request.id;
|
||||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
|
||||
request.callback = onAssetCallback;
|
||||
request.callbackData = this;
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
@ -75,20 +70,24 @@ void CImage::onTimerUpdate() {
|
|||
void CImage::plantTimer() {
|
||||
|
||||
if (reloadTime == 0) {
|
||||
imageTimer = g_pHyprlock->addTimer(std::chrono::hours(1), onTimer, this, true);
|
||||
imageTimer = g_pHyprlock->addTimer(std::chrono::hours(1), [REF = m_self](auto, auto) { onTimer(REF); }, nullptr, true);
|
||||
} else if (reloadTime > 0)
|
||||
imageTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), onTimer, this, false);
|
||||
imageTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), [REF = m_self](auto, auto) { onTimer(REF); }, nullptr, false);
|
||||
}
|
||||
|
||||
CImage::CImage(const Vector2D& viewport_, COutput* output_, const std::string& resourceID_, const std::unordered_map<std::string, std::any>& props) :
|
||||
viewport(viewport_), resourceID(resourceID_), output(output_), shadow(this, props, viewport_) {
|
||||
void CImage::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
|
||||
try {
|
||||
size = std::any_cast<Hyprlang::INT>(props.at("size"));
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport_);
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
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"));
|
||||
|
@ -113,6 +112,25 @@ CImage::CImage(const Vector2D& viewport_, COutput* output_, const std::string& r
|
|||
}
|
||||
}
|
||||
|
||||
void CImage::reset() {
|
||||
if (imageTimer) {
|
||||
imageTimer->cancel();
|
||||
imageTimer.reset();
|
||||
}
|
||||
|
||||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
imageFB.release();
|
||||
|
||||
if (asset)
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
|
||||
asset = nullptr;
|
||||
pendingResourceID = "";
|
||||
resourceID = "";
|
||||
}
|
||||
|
||||
bool CImage::draw(const SRenderData& data) {
|
||||
|
||||
if (resourceID.empty())
|
||||
|
@ -204,8 +222,11 @@ void CImage::renderUpdate() {
|
|||
pendingResourceID = "";
|
||||
} else if (!pendingResourceID.empty()) {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
pendingResourceID = "";
|
||||
} else if (!pendingResourceID.empty()) {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), onAssetCallbackTimer, this);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(output->stringPort);
|
||||
|
|
|
@ -17,16 +17,23 @@ class COutput;
|
|||
|
||||
class CImage : public IWidget {
|
||||
public:
|
||||
CImage(const Vector2D& viewport, COutput* output_, const std::string& resourceID, const std::unordered_map<std::string, std::any>& props);
|
||||
CImage() = default;
|
||||
~CImage();
|
||||
|
||||
void registerSelf(const SP<CImage>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
|
||||
void reset();
|
||||
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
|
||||
private:
|
||||
WP<CImage> m_self;
|
||||
|
||||
CFramebuffer imageFB;
|
||||
|
||||
int size;
|
||||
|
|
|
@ -8,31 +8,25 @@
|
|||
#include <stdexcept>
|
||||
|
||||
CLabel::~CLabel() {
|
||||
if (labelTimer) {
|
||||
labelTimer->cancel();
|
||||
labelTimer.reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
void CLabel::registerSelf(const SP<CLabel>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
static void onTimer(WP<CLabel> ref) {
|
||||
if (auto PLABEL = ref.lock(); PLABEL) {
|
||||
// update label
|
||||
PLABEL->onTimerUpdate();
|
||||
// plant new timer
|
||||
PLABEL->plantTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void onTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
if (data == nullptr)
|
||||
return;
|
||||
const auto PLABEL = (CLabel*)data;
|
||||
|
||||
// update label
|
||||
PLABEL->onTimerUpdate();
|
||||
|
||||
// plant new timer
|
||||
PLABEL->plantTimer();
|
||||
}
|
||||
|
||||
static void onAssetCallback(void* data) {
|
||||
const auto PLABEL = (CLabel*)data;
|
||||
PLABEL->renderUpdate();
|
||||
}
|
||||
|
||||
static void onAssetCallbackTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
onAssetCallback(data);
|
||||
static void onAssetCallback(WP<CLabel> ref) {
|
||||
if (auto PLABEL = ref.lock(); PLABEL)
|
||||
PLABEL->renderUpdate();
|
||||
}
|
||||
|
||||
std::string CLabel::getUniqueResourceId() {
|
||||
|
@ -57,23 +51,29 @@ void CLabel::onTimerUpdate() {
|
|||
pendingResourceID = request.id;
|
||||
request.asset = label.formatted;
|
||||
|
||||
request.callback = onAssetCallback;
|
||||
request.callbackData = this;
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
||||
void CLabel::plantTimer() {
|
||||
|
||||
if (label.updateEveryMs != 0)
|
||||
labelTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)label.updateEveryMs), onTimer, this, label.allowForceUpdate);
|
||||
labelTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)label.updateEveryMs), [REF = m_self](auto, auto) { onTimer(REF); }, this, label.allowForceUpdate);
|
||||
else if (label.updateEveryMs == 0 && label.allowForceUpdate)
|
||||
labelTimer = g_pHyprlock->addTimer(std::chrono::hours(1), onTimer, this, true);
|
||||
labelTimer = g_pHyprlock->addTimer(std::chrono::hours(1), [REF = m_self](auto, auto) { onTimer(REF); }, this, true);
|
||||
}
|
||||
|
||||
CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) :
|
||||
outputStringPort(output), shadow(this, props, viewport_) {
|
||||
void CLabel::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
outputStringPort = pOutput->stringPort;
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
|
||||
try {
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport_);
|
||||
configPos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
labelPreFormat = std::any_cast<Hyprlang::STRING>(props.at("text"));
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
|
@ -82,7 +82,7 @@ CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map<std::string,
|
|||
|
||||
std::string textAlign = std::any_cast<Hyprlang::STRING>(props.at("text_align"));
|
||||
std::string fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
|
||||
CHyprColor labelColor = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
CHyprColor labelColor = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
int fontSize = std::any_cast<Hyprlang::INT>(props.at("font_size"));
|
||||
|
||||
label = formatString(labelPreFormat);
|
||||
|
@ -105,14 +105,30 @@ CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map<std::string,
|
|||
RASSERT(false, "Missing property for CLabel: {}", e.what()); //
|
||||
}
|
||||
|
||||
configPos = pos;
|
||||
viewport = viewport_;
|
||||
pos = configPos; // Label size not known yet
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
|
||||
plantTimer();
|
||||
}
|
||||
|
||||
void CLabel::reset() {
|
||||
if (labelTimer) {
|
||||
labelTimer->cancel();
|
||||
labelTimer.reset();
|
||||
}
|
||||
|
||||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
if (asset)
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
|
||||
asset = nullptr;
|
||||
pendingResourceID.clear();
|
||||
resourceID.clear();
|
||||
}
|
||||
|
||||
bool CLabel::draw(const SRenderData& data) {
|
||||
if (!asset) {
|
||||
asset = g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID);
|
||||
|
@ -150,7 +166,7 @@ void CLabel::renderUpdate() {
|
|||
} else {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), onAssetCallbackTimer, this);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,16 +14,23 @@ class CSessionLockSurface;
|
|||
|
||||
class CLabel : public IWidget {
|
||||
public:
|
||||
CLabel(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, const std::string& output);
|
||||
CLabel() = default;
|
||||
~CLabel();
|
||||
|
||||
void registerSelf(const SP<CLabel>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
|
||||
void reset();
|
||||
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
|
||||
private:
|
||||
WP<CLabel> m_self;
|
||||
|
||||
std::string getUniqueResourceId();
|
||||
|
||||
std::string labelPreFormat;
|
||||
|
|
|
@ -15,11 +15,25 @@
|
|||
|
||||
using namespace Hyprutils::String;
|
||||
|
||||
CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) :
|
||||
viewport(viewport_), outputStringPort(output), shadow(this, props, viewport_) {
|
||||
CPasswordInputField::~CPasswordInputField() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void CPasswordInputField::registerSelf(const SP<CPasswordInputField>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
void CPasswordInputField::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
outputStringPort = pOutput->stringPort;
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
|
||||
try {
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport_);
|
||||
configSize = CLayoutValueData::fromAnyPv(props.at("size"))->getAbsolute(viewport_);
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
configSize = CLayoutValueData::fromAnyPv(props.at("size"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
outThick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
|
||||
|
@ -61,6 +75,16 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
|
|||
|
||||
colorConfig.caps = colorConfig.caps->m_bIsFallback ? colorConfig.fail : colorConfig.caps;
|
||||
|
||||
g_pAnimationManager->createAnimation(0.f, fade.a, g_pConfigManager->m_AnimationTree.getConfig("inputFieldFade"));
|
||||
g_pAnimationManager->createAnimation(0.f, dots.currentAmount, g_pConfigManager->m_AnimationTree.getConfig("inputFieldDots"));
|
||||
g_pAnimationManager->createAnimation(configSize, size, g_pConfigManager->m_AnimationTree.getConfig("inputFieldWidth"));
|
||||
g_pAnimationManager->createAnimation(colorConfig.inner, colorState.inner, g_pConfigManager->m_AnimationTree.getConfig("inputFieldColors"));
|
||||
g_pAnimationManager->createAnimation(*colorConfig.outer, colorState.outer, g_pConfigManager->m_AnimationTree.getConfig("inputFieldColors"));
|
||||
|
||||
srand(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
|
||||
pos = posFromHVAlign(viewport, size->goal(), configPos, halign, valign);
|
||||
|
||||
if (!dots.textFormat.empty()) {
|
||||
dots.textResourceID = std::format("input:{}-{}", (uintptr_t)this, dots.textFormat);
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
|
@ -74,23 +98,30 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
|
|||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
||||
g_pAnimationManager->createAnimation(0.f, fade.a, g_pConfigManager->m_AnimationTree.getConfig("inputFieldFade"));
|
||||
g_pAnimationManager->createAnimation(0.f, dots.currentAmount, g_pConfigManager->m_AnimationTree.getConfig("inputFieldDots"));
|
||||
g_pAnimationManager->createAnimation(configSize, size, g_pConfigManager->m_AnimationTree.getConfig("inputFieldWidth"));
|
||||
|
||||
g_pAnimationManager->createAnimation(colorConfig.inner, colorState.inner, g_pConfigManager->m_AnimationTree.getConfig("inputFieldColors"));
|
||||
g_pAnimationManager->createAnimation(*colorConfig.outer, colorState.outer, g_pConfigManager->m_AnimationTree.getConfig("inputFieldColors"));
|
||||
|
||||
srand(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
|
||||
// request the inital placeholder asset
|
||||
updatePlaceholder();
|
||||
}
|
||||
|
||||
static void fadeOutCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
CPasswordInputField* p = (CPasswordInputField*)data;
|
||||
void CPasswordInputField::reset() {
|
||||
if (fade.fadeOutTimer.get()) {
|
||||
fade.fadeOutTimer->cancel();
|
||||
fade.fadeOutTimer.reset();
|
||||
}
|
||||
|
||||
p->onFadeOutTimer();
|
||||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
if (placeholder.asset)
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(placeholder.asset);
|
||||
|
||||
placeholder.asset = nullptr;
|
||||
placeholder.resourceID.clear();
|
||||
placeholder.currentText.clear();
|
||||
}
|
||||
|
||||
static void fadeOutCallback(WP<CPasswordInputField> ref) {
|
||||
if (const auto PP = ref.lock(); PP)
|
||||
PP->onFadeOutTimer();
|
||||
}
|
||||
|
||||
void CPasswordInputField::onFadeOutTimer() {
|
||||
|
@ -121,7 +152,8 @@ void CPasswordInputField::updateFade() {
|
|||
*fade.a = 0.0;
|
||||
fade.allowFadeOut = false;
|
||||
} else if (!fade.fadeOutTimer.get())
|
||||
fade.fadeOutTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(fadeTimeoutMs), fadeOutCallback, this);
|
||||
fade.fadeOutTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(fadeTimeoutMs), [REF = m_self](auto, auto) { fadeOutCallback(REF); }, nullptr);
|
||||
|
||||
} else if (INPUTUSED && fade.a->goal() != 1.0)
|
||||
*fade.a = 1.0;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include "../../helpers/AnimatedVariable.hpp"
|
||||
#include <chrono>
|
||||
#include <hyprutils/math/Vector2D.hpp>
|
||||
#include <vector>
|
||||
#include <any>
|
||||
#include <unordered_map>
|
||||
|
@ -16,37 +17,45 @@ struct SPreloadedAsset;
|
|||
|
||||
class CPasswordInputField : public IWidget {
|
||||
public:
|
||||
CPasswordInputField(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, const std::string& output);
|
||||
CPasswordInputField() = default;
|
||||
virtual ~CPasswordInputField();
|
||||
|
||||
void registerSelf(const SP<CPasswordInputField>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
|
||||
void reset();
|
||||
void onFadeOutTimer();
|
||||
|
||||
private:
|
||||
void updateDots();
|
||||
void updateFade();
|
||||
void updatePlaceholder();
|
||||
void updateWidth();
|
||||
void updateHiddenInputState();
|
||||
void updateInputState();
|
||||
void updateColors();
|
||||
WP<CPasswordInputField> m_self;
|
||||
|
||||
bool firstRender = true;
|
||||
bool redrawShadow = false;
|
||||
bool checkWaiting = false;
|
||||
bool displayFail = false;
|
||||
void updateDots();
|
||||
void updateFade();
|
||||
void updatePlaceholder();
|
||||
void updateWidth();
|
||||
void updateHiddenInputState();
|
||||
void updateInputState();
|
||||
void updateColors();
|
||||
|
||||
size_t passwordLength = 0;
|
||||
bool firstRender = true;
|
||||
bool redrawShadow = false;
|
||||
bool checkWaiting = false;
|
||||
bool displayFail = false;
|
||||
|
||||
PHLANIMVAR<Vector2D> size;
|
||||
Vector2D pos;
|
||||
Vector2D viewport;
|
||||
Vector2D configPos;
|
||||
Vector2D configSize;
|
||||
size_t passwordLength = 0;
|
||||
|
||||
std::string halign, valign, configFailText, outputStringPort, configPlaceholderText, fontFamily;
|
||||
uint64_t configFailTimeoutMs = 2000;
|
||||
PHLANIMVAR<Vector2D> size;
|
||||
Vector2D pos;
|
||||
Vector2D viewport;
|
||||
Vector2D configPos;
|
||||
Vector2D configSize;
|
||||
|
||||
int outThick, rounding;
|
||||
std::string halign, valign, configFailText, outputStringPort, configPlaceholderText, fontFamily;
|
||||
uint64_t configFailTimeoutMs = 2000;
|
||||
|
||||
int outThick, rounding;
|
||||
|
||||
struct {
|
||||
PHLANIMVAR<float> currentAmount;
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
#include "../Renderer.hpp"
|
||||
#include <hyprlang.hpp>
|
||||
|
||||
CShadowable::CShadowable(IWidget* widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_) : widget(widget_), viewport(viewport_) {
|
||||
void CShadowable::configure(WP<IWidget> widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_) {
|
||||
m_widget = widget_;
|
||||
viewport = viewport_;
|
||||
|
||||
size = std::any_cast<Hyprlang::INT>(props.at("shadow_size"));
|
||||
passes = std::any_cast<Hyprlang::INT>(props.at("shadow_passes"));
|
||||
color = std::any_cast<Hyprlang::INT>(props.at("shadow_color"));
|
||||
|
@ -10,6 +13,10 @@ CShadowable::CShadowable(IWidget* widget_, const std::unordered_map<std::string,
|
|||
}
|
||||
|
||||
void CShadowable::markShadowDirty() {
|
||||
const auto WIDGET = m_widget.lock();
|
||||
|
||||
if (!m_widget)
|
||||
return;
|
||||
|
||||
if (passes == 0)
|
||||
return;
|
||||
|
@ -22,7 +29,7 @@ void CShadowable::markShadowDirty() {
|
|||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
ignoreDraw = true;
|
||||
widget->draw(IWidget::SRenderData{.opacity = 1.0});
|
||||
WIDGET->draw(IWidget::SRenderData{.opacity = 1.0});
|
||||
ignoreDraw = false;
|
||||
|
||||
g_pRenderer->blurFB(shadowFB, CRenderer::SBlurParams{.size = size, .passes = passes, .colorize = color, .boostA = boostA});
|
||||
|
@ -31,7 +38,7 @@ void CShadowable::markShadowDirty() {
|
|||
}
|
||||
|
||||
bool CShadowable::draw(const IWidget::SRenderData& data) {
|
||||
if (passes == 0)
|
||||
if (!m_widget || passes == 0)
|
||||
return true;
|
||||
|
||||
if (!shadowFB.isAllocated() || ignoreDraw)
|
||||
|
@ -40,4 +47,4 @@ bool CShadowable::draw(const IWidget::SRenderData& data) {
|
|||
CBox box = {0, 0, viewport.x, viewport.y};
|
||||
g_pRenderer->renderTexture(box, shadowFB.m_cTex, data.opacity, 0, HYPRUTILS_TRANSFORM_NORMAL);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,22 +11,24 @@
|
|||
|
||||
class CShadowable {
|
||||
public:
|
||||
CShadowable(IWidget* widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_ /* TODO: make this not the entire viewport */);
|
||||
virtual ~CShadowable() = default;
|
||||
CShadowable() = default;
|
||||
void configure(WP<IWidget> widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_ /* TODO: make this not the entire viewport */);
|
||||
|
||||
// instantly re-renders the shadow using the widget's draw() method
|
||||
void markShadowDirty();
|
||||
virtual bool draw(const IWidget::SRenderData& data);
|
||||
|
||||
private:
|
||||
IWidget* widget = nullptr;
|
||||
int size = 10;
|
||||
int passes = 4;
|
||||
float boostA = 1.0;
|
||||
CHyprColor color{0, 0, 0, 1.0};
|
||||
Vector2D viewport;
|
||||
WP<IWidget> m_widget;
|
||||
int size = 10;
|
||||
int passes = 4;
|
||||
float boostA = 1.0;
|
||||
CHyprColor color{0, 0, 0, 1.0};
|
||||
Vector2D viewport;
|
||||
|
||||
// to avoid recursive shadows
|
||||
bool ignoreDraw = false;
|
||||
|
||||
CFramebuffer shadowFB;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -4,15 +4,22 @@
|
|||
#include <cmath>
|
||||
#include <hyprlang.hpp>
|
||||
|
||||
CShape::CShape(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props) : shadow(this, props, viewport_) {
|
||||
void CShape::registerSelf(const SP<CShape>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
void CShape::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
|
||||
try {
|
||||
size = CLayoutValueData::fromAnyPv(props.at("size"))->getAbsolute(viewport_);
|
||||
size = CLayoutValueData::fromAnyPv(props.at("size"))->getAbsolute(viewport);
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
borderGrad = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport_);
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
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"));
|
||||
|
@ -23,8 +30,7 @@ CShape::CShape(const Vector2D& viewport_, const std::unordered_map<std::string,
|
|||
RASSERT(false, "Missing property for CShape: {}", e.what()); //
|
||||
}
|
||||
|
||||
viewport = viewport_;
|
||||
angle = angle * M_PI / 180.0;
|
||||
angle = angle * M_PI / 180.0;
|
||||
|
||||
const Vector2D VBORDER = {border, border};
|
||||
const Vector2D REALSIZE = size + VBORDER * 2.0;
|
||||
|
|
|
@ -11,11 +11,17 @@
|
|||
|
||||
class CShape : public IWidget {
|
||||
public:
|
||||
CShape(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props);
|
||||
CShape() = default;
|
||||
virtual ~CShape() = default;
|
||||
|
||||
void registerSelf(const SP<CShape>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
|
||||
private:
|
||||
WP<CShape> m_self;
|
||||
|
||||
CFramebuffer shapeFB;
|
||||
|
||||
int rounding;
|
||||
|
|
Loading…
Reference in a new issue