core: move to UP and make widgets use SPs

This commit is contained in:
Maximilian Seidler 2025-02-06 09:04:35 +01:00
parent e588351d1d
commit 15dbc17281
24 changed files with 172 additions and 165 deletions

View file

@ -11,10 +11,10 @@
CAuth::CAuth() { CAuth::CAuth() {
static const auto ENABLEPAM = g_pConfigManager->getValue<Hyprlang::INT>("auth:pam:enabled"); static const auto ENABLEPAM = g_pConfigManager->getValue<Hyprlang::INT>("auth:pam:enabled");
if (*ENABLEPAM) 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"); static const auto ENABLEFINGERPRINT = g_pConfigManager->getValue<Hyprlang::INT>("auth:fingerprint:enabled");
if (*ENABLEFINGERPRINT) 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!"); 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() { bool CAuth::checkWaiting() {
for (const auto& i : m_vImpls) { return std::ranges::any_of(m_vImpls, [](const auto& i) { return i->checkWaiting(); });
if (i->checkWaiting())
return true;
}
return false;
} }
const std::string& CAuth::getCurrentFailText() { const std::string& CAuth::getCurrentFailText() {
@ -64,7 +59,7 @@ size_t CAuth::getFailedAttempts() {
return m_sCurrentFail.failedAttempts; return m_sCurrentFail.failedAttempts;
} }
std::shared_ptr<IAuthImplementation> CAuth::getImpl(eAuthImplementations implType) { SP<IAuthImplementation> CAuth::getImpl(eAuthImplementations implType) {
for (const auto& i : m_vImpls) { for (const auto& i : m_vImpls) {
if (i->getImplType() == implType) if (i->getImplType() == implType)
return i; return i;

View file

@ -1,9 +1,10 @@
#pragma once #pragma once
#include <memory>
#include <optional> #include <optional>
#include <vector> #include <vector>
#include "../defines.hpp"
enum eAuthImplementations { enum eAuthImplementations {
AUTH_IMPL_PAM = 0, AUTH_IMPL_PAM = 0,
AUTH_IMPL_FINGERPRINT = 1, AUTH_IMPL_FINGERPRINT = 1,
@ -28,23 +29,23 @@ class CAuth {
public: public:
CAuth(); CAuth();
void start(); void start();
void submitInput(const std::string& input); void submitInput(const std::string& input);
bool checkWaiting(); bool checkWaiting();
const std::string& getCurrentFailText(); const std::string& getCurrentFailText();
std::optional<std::string> getFailText(eAuthImplementations implType); std::optional<std::string> getFailText(eAuthImplementations implType);
std::optional<std::string> getPrompt(eAuthImplementations implType); std::optional<std::string> getPrompt(eAuthImplementations implType);
size_t getFailedAttempts(); size_t getFailedAttempts();
std::shared_ptr<IAuthImplementation> getImpl(eAuthImplementations implType); SP<IAuthImplementation> getImpl(eAuthImplementations implType);
void terminate(); void terminate();
void enqueueUnlock(); void enqueueUnlock();
void enqueueFail(const std::string& failText, eAuthImplementations implType); void enqueueFail(const std::string& failText, eAuthImplementations implType);
// Should only be set via the main thread // Should only be set via the main thread
bool m_bDisplayFailText = false; bool m_bDisplayFailText = false;
@ -56,7 +57,7 @@ class CAuth {
size_t failedAttempts = 0; size_t failedAttempts = 0;
} m_sCurrentFail; } 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;

View file

@ -5,7 +5,6 @@
#include <hyprlang.hpp> #include <hyprlang.hpp>
#include <optional> #include <optional>
#include <vector> #include <vector>
#include <memory>
#include <unordered_map> #include <unordered_map>
#include "../defines.hpp" #include "../defines.hpp"
@ -41,4 +40,4 @@ class CConfigManager {
Hyprlang::CConfig m_config; Hyprlang::CConfig m_config;
}; };
inline std::unique_ptr<CConfigManager> g_pConfigManager; inline UP<CConfigManager> g_pConfigManager;

View file

@ -4,7 +4,6 @@
#include <hyprutils/animation/AnimatedVariable.hpp> #include <hyprutils/animation/AnimatedVariable.hpp>
#include "../helpers/AnimatedVariable.hpp" #include "../helpers/AnimatedVariable.hpp"
#include "../helpers/Math.hpp"
#include "../defines.hpp" #include "../defines.hpp"
class CHyprlockAnimationManager : public Hyprutils::Animation::CAnimationManager { class CHyprlockAnimationManager : public Hyprutils::Animation::CAnimationManager {
@ -31,4 +30,4 @@ class CHyprlockAnimationManager : public Hyprutils::Animation::CAnimationManager
bool m_bTickScheduled = false; bool m_bTickScheduled = false;
}; };
inline std::unique_ptr<CHyprlockAnimationManager> g_pAnimationManager; inline UP<CHyprlockAnimationManager> g_pAnimationManager;

View file

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <memory>
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include "../defines.hpp"
class CEGL { class CEGL {
public: public:
CEGL(wl_display*); CEGL(wl_display*);
@ -19,4 +19,4 @@ class CEGL {
void makeCurrent(EGLSurface surf); void makeCurrent(EGLSurface surf);
}; };
inline std::unique_ptr<CEGL> g_pEGL; inline UP<CEGL> g_pEGL;

View file

@ -11,13 +11,9 @@ CSessionLockSurface::~CSessionLockSurface() {
wl_egl_window_destroy(eglWindow); wl_egl_window_destroy(eglWindow);
} }
CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) { CSessionLockSurface::CSessionLockSurface(const SP<COutput>& pOutput) : m_outputRef(pOutput) {
surface = makeShared<CCWlSurface>(g_pHyprlock->getCompositor()->sendCreateSurface()); surface = makeShared<CCWlSurface>(g_pHyprlock->getCompositor()->sendCreateSurface());
RASSERT(surface, "Couldn't create wl_surface");
if (!surface) {
Debug::log(CRIT, "Couldn't create wl_surface");
exit(1);
}
static const auto FRACTIONALSCALING = g_pConfigManager->getValue<Hyprlang::INT>("general:fractional_scaling"); static const auto FRACTIONALSCALING = g_pConfigManager->getValue<Hyprlang::INT>("general:fractional_scaling");
const auto ENABLE_FSV1 = *FRACTIONALSCALING == 1 || /* auto enable */ (*FRACTIONALSCALING == 2); const auto ENABLE_FSV1 = *FRACTIONALSCALING == 1 || /* auto enable */ (*FRACTIONALSCALING == 2);
@ -45,7 +41,7 @@ CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) {
if (!PVIEWPORTER) if (!PVIEWPORTER)
Debug::log(LOG, "No viewporter support! Oops, won't be able to scale!"); 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) { if (!lockSurface) {
Debug::log(CRIT, "Couldn't create ext_session_lock_surface_v1"); 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 SAMESIZE = logicalSize == size_;
const bool SAMESCALE = appliedScale == fractionalScale; const bool SAMESCALE = appliedScale == fractionalScale;
const auto POUTPUT = m_outputRef.lock();
serial = serial_; serial = serial_;
logicalSize = size_; logicalSize = size_;
appliedScale = fractionalScale; appliedScale = fractionalScale;
@ -71,8 +69,8 @@ void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) {
viewport->sendSetDestination(logicalSize.x, logicalSize.y); viewport->sendSetDestination(logicalSize.x, logicalSize.y);
surface->sendSetBufferScale(1); surface->sendSetBufferScale(1);
} else { } else {
size = size_ * output->scale; size = size_ * POUTPUT->scale;
surface->sendSetBufferScale(output->scale); surface->sendSetBufferScale(POUTPUT->scale);
} }
if (!SAMESERIAL) if (!SAMESERIAL)
@ -129,7 +127,10 @@ void CSessionLockSurface::render() {
if (g_pHyprlock->m_bTerminate) if (g_pHyprlock->m_bTerminate)
return; 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; m_lastFrameTime = frameTime;

View file

@ -14,7 +14,7 @@ class CRenderer;
class CSessionLockSurface { class CSessionLockSurface {
public: public:
CSessionLockSurface(COutput* output); CSessionLockSurface(const SP<COutput>& pOutput);
~CSessionLockSurface(); ~CSessionLockSurface();
void configure(const Vector2D& size, uint32_t serial); void configure(const Vector2D& size, uint32_t serial);
@ -28,7 +28,8 @@ class CSessionLockSurface {
void onScaleUpdate(); void onScaleUpdate();
private: private:
COutput* output = nullptr; WP<COutput> m_outputRef;
SP<CCWlSurface> surface = nullptr; SP<CCWlSurface> surface = nullptr;
SP<CCExtSessionLockSurfaceV1> lockSurface = nullptr; SP<CCExtSessionLockSurfaceV1> lockSurface = nullptr;
uint32_t serial = 0; uint32_t serial = 0;
@ -49,4 +50,4 @@ class CSessionLockSurface {
SP<CCWlCallback> frameCallback = nullptr; SP<CCWlCallback> frameCallback = nullptr;
friend class CRenderer; friend class CRenderer;
}; };

View file

@ -1,32 +1,35 @@
#include "Output.hpp" #include "Output.hpp"
#include "../helpers/Log.hpp" #include "../helpers/Log.hpp"
#include "hyprlock.hpp" #include "hyprlock.hpp"
#include "../renderer/Renderer.hpp"
COutput::COutput(SP<CCWlOutput> output_, uint32_t name_) : name(name_), output(output_) { void COutput::create(WP<COutput> pSelf, SP<CCWlOutput> pWlOutput, uint32_t _name) {
output->setDescription([this](CCWlOutput* r, const char* description) { name = _name;
m_wlOutput = pWlOutput;
m_self = pSelf;
m_wlOutput->setDescription([this](CCWlOutput* r, const char* description) {
stringDesc = description ? std::string{description} : ""; stringDesc = description ? std::string{description} : "";
Debug::log(LOG, "output {} description {}", name, stringDesc); Debug::log(LOG, "output {} description {}", name, stringDesc);
}); });
output->setName([this](CCWlOutput* r, const char* name) { m_wlOutput->setName([this](CCWlOutput* r, const char* name) {
stringName = std::string{name} + stringName; stringName = std::string{name} + stringName;
stringPort = std::string{name}; stringPort = std::string{name};
Debug::log(LOG, "output {} name {}", name, 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; done = true;
Debug::log(LOG, "output {} done", name); Debug::log(LOG, "output {} done", name);
if (g_pHyprlock->m_lockAquired && !sessionLockSurface) { if (g_pHyprlock->m_lockAquired && !m_sessionLockSurface) {
Debug::log(LOG, "output {} creating a new lock surface", name); Debug::log(LOG, "output {} creating a new lock surface", name);
sessionLockSurface = std::make_unique<CSessionLockSurface>(this); 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 // handle portrait mode and flipped cases
if (transform % 2 == 1) if (transform % 2 == 1)
size = {height, width}; size = {height, width};
@ -34,10 +37,14 @@ COutput::COutput(SP<CCWlOutput> output_, uint32_t name_) : name(name_), output(o
size = {width, height}; 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_) { [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_; transform = (wl_output_transform)transform_;
Debug::log(LOG, "output {} make {} model {}", name, make ? make : "", model ? model : ""); Debug::log(LOG, "output {} make {} model {}", name, make ? make : "", model ? model : "");
}); });
} }
void COutput::createSessionLockSurface() {
m_sessionLockSurface = makeUnique<CSessionLockSurface>(m_self.lock());
}

View file

@ -2,27 +2,26 @@
#include "../defines.hpp" #include "../defines.hpp"
#include "wayland.hpp" #include "wayland.hpp"
#include "../helpers/Math.hpp"
#include "LockSurface.hpp" #include "LockSurface.hpp"
#include <memory>
class COutput { class COutput {
public: public:
COutput(SP<CCWlOutput> output, uint32_t name); COutput(SP<CCWlOutput> output, uint32_t name);
uint32_t name = 0; uint32_t name = 0;
bool focused = false; bool focused = false;
bool done = false; bool done = false;
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL; wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
Vector2D size; Vector2D size;
int scale = 1; int scale = 1;
std::string stringName = ""; std::string stringName = "";
std::string stringPort = ""; std::string stringPort = "";
std::string stringDesc = ""; std::string stringDesc = "";
std::unique_ptr<CSessionLockSurface> sessionLockSurface; SP<CCWlOutput> output = nullptr;
SP<CCWlOutput> output = nullptr; void createSessionLockSurface();
private: private:
std::unique_ptr<CSessionLockSurface> m_sessionLockSurface;
}; };

View file

@ -131,7 +131,7 @@ void CSeatManager::registerSeat(SP<CCWlSeat> seat) {
} }
void CSeatManager::registerCursorShape(SP<CCWpCursorShapeManagerV1> shape) { void CSeatManager::registerCursorShape(SP<CCWpCursorShapeManagerV1> shape) {
m_pCursorShape = std::make_unique<CCursorShape>(shape); m_pCursorShape = makeUnique<CCursorShape>(shape);
} }
bool CSeatManager::registered() { bool CSeatManager::registered() {

View file

@ -5,29 +5,28 @@
#include "wayland.hpp" #include "wayland.hpp"
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-compose.h> #include <xkbcommon/xkbcommon-compose.h>
#include <memory>
class CSeatManager { class CSeatManager {
public: public:
CSeatManager() = default; CSeatManager() = default;
~CSeatManager(); ~CSeatManager();
void registerSeat(SP<CCWlSeat> seat); void registerSeat(SP<CCWlSeat> seat);
void registerCursorShape(SP<CCWpCursorShapeManagerV1> shape); void registerCursorShape(SP<CCWpCursorShapeManagerV1> shape);
bool registered(); bool registered();
SP<CCWlKeyboard> m_pKeeb; SP<CCWlKeyboard> m_pKeeb;
SP<CCWlPointer> m_pPointer; SP<CCWlPointer> m_pPointer;
std::unique_ptr<CCursorShape> m_pCursorShape; UP<CCursorShape> m_pCursorShape;
xkb_context* m_pXKBContext = nullptr; xkb_context* m_pXKBContext = nullptr;
xkb_keymap* m_pXKBKeymap = nullptr; xkb_keymap* m_pXKBKeymap = nullptr;
xkb_state* m_pXKBState = nullptr; xkb_state* m_pXKBState = nullptr;
xkb_compose_state* m_pXKBComposeState = nullptr; xkb_compose_state* m_pXKBComposeState = nullptr;
private: private:
SP<CCWlSeat> m_pSeat; SP<CCWlSeat> m_pSeat;
}; };
inline std::unique_ptr<CSeatManager> g_pSeatManager = std::make_unique<CSeatManager>(); inline UP<CSeatManager> g_pSeatManager = makeUnique<CSeatManager>();

View file

@ -6,6 +6,7 @@
#include "../auth/Auth.hpp" #include "../auth/Auth.hpp"
#include "../auth/Fingerprint.hpp" #include "../auth/Fingerprint.hpp"
#include "Egl.hpp" #include "Egl.hpp"
#include <hyprutils/memory/UniquePtr.hpp>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <sys/mman.h> #include <sys/mman.h>
@ -43,7 +44,7 @@ CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const b
exit(1); exit(1);
} }
g_pEGL = std::make_unique<CEGL>(m_sWaylandState.display); g_pEGL = makeUnique<CEGL>(m_sWaylandState.display);
if (!immediate) { if (!immediate) {
static const auto GRACE = g_pConfigManager->getValue<Hyprlang::INT>("general:grace"); 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) } else if (IFACE == ext_session_lock_manager_v1_interface.name)
m_sWaylandState.sessionLock = m_sWaylandState.sessionLock =
makeShared<CCExtSessionLockManagerV1>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &ext_session_lock_manager_v1_interface, 1)); 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) else if (IFACE == wl_output_interface.name) {
m_vOutputs.emplace_back( m_vOutputs.emplace_back(makeShared<COutput>());
std::make_unique<COutput>(makeShared<CCWlOutput>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wl_output_interface, 4)), name)); 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) } else if (IFACE == wp_cursor_shape_manager_v1_interface.name)
g_pSeatManager->registerCursorShape( g_pSeatManager->registerCursorShape(
makeShared<CCWpCursorShapeManagerV1>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wp_cursor_shape_manager_v1_interface, 1))); 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) else if (IFACE == wl_compositor_interface.name)
@ -310,7 +311,7 @@ void CHyprlock::run() {
Debug::log(LOG, " | removed iface {}", 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, [name](const auto& other) { return other->name == name; });
if (outputIt != m_vOutputs.end()) { if (outputIt != m_vOutputs.end()) {
g_pRenderer->removeWidgetsFor(outputIt->get()->sessionLockSurface.get()); g_pRenderer->removeWidgetsFor((*outputIt)->m_sessionLockSurface.get());
m_vOutputs.erase(outputIt); m_vOutputs.erase(outputIt);
} }
}); });
@ -325,8 +326,8 @@ void CHyprlock::run() {
// gather info about monitors // gather info about monitors
wl_display_roundtrip(m_sWaylandState.display); wl_display_roundtrip(m_sWaylandState.display);
g_pRenderer = std::make_unique<CRenderer>(); g_pRenderer = makeUnique<CRenderer>();
g_pAuth = std::make_unique<CAuth>(); g_pAuth = makeUnique<CAuth>();
g_pAuth->start(); g_pAuth->start();
Debug::log(LOG, "Running on {}", m_sCurrentDesktop); Debug::log(LOG, "Running on {}", m_sCurrentDesktop);
@ -554,23 +555,23 @@ void CHyprlock::clearPasswordBuffer() {
void CHyprlock::renderOutput(const std::string& stringPort) { void CHyprlock::renderOutput(const std::string& stringPort) {
const auto MON = std::ranges::find_if(m_vOutputs, [stringPort](const auto& other) { return other->stringPort == 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; return;
const auto PMONITOR = MON->get(); const auto& PMONITOR = *MON;
if (!PMONITOR->sessionLockSurface) if (!PMONITOR->m_sessionLockSurface)
return; return;
PMONITOR->sessionLockSurface->render(); PMONITOR->m_sessionLockSurface->render();
} }
void CHyprlock::renderAllOutputs() { void CHyprlock::renderAllOutputs() {
for (auto& o : m_vOutputs) { for (auto& o : m_vOutputs) {
if (!o->sessionLockSurface) if (!o->m_sessionLockSurface)
continue; continue;
o->sessionLockSurface->render(); o->m_sessionLockSurface->render();
} }
} }
@ -723,7 +724,7 @@ bool CHyprlock::acquireSessionLock() {
if (!o->done) if (!o->done)
continue; continue;
o->sessionLockSurface = std::make_unique<CSessionLockSurface>(o.get()); o->createSessionLockSurface();
} }
return true; return true;

View file

@ -37,9 +37,6 @@ class CHyprlock {
void unlock(); void unlock();
bool isUnlocked(); 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, 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); bool force = false);
@ -103,7 +100,7 @@ class CHyprlock {
std::shared_ptr<CTimer> m_pKeyRepeatTimer = nullptr; 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(); std::vector<std::shared_ptr<CTimer>> getTimers();
struct { struct {
@ -167,4 +164,4 @@ class CHyprlock {
std::vector<uint32_t> m_vPressedKeys; std::vector<uint32_t> m_vPressedKeys;
}; };
inline std::unique_ptr<CHyprlock> g_pHyprlock; inline UP<CHyprlock> g_pHyprlock;

View file

@ -1,8 +1,10 @@
#pragma once #pragma once
#include <hyprutils/memory/WeakPtr.hpp> #include <hyprutils/memory/WeakPtr.hpp>
#include <hyprutils/memory/UniquePtr.hpp>
#include <hyprgraphics/color/Color.hpp> #include <hyprgraphics/color/Color.hpp>
using namespace Hyprutils::Memory; using namespace Hyprutils::Memory;
using namespace Hyprgraphics; using namespace Hyprgraphics;
#define SP CSharedPointer #define SP CSharedPointer
#define WP CWeakPointer #define WP CWeakPointer
#define UP CUniquePointer

View file

@ -90,10 +90,10 @@ int main(int argc, char** argv, char** envp) {
} }
} }
g_pAnimationManager = std::make_unique<CHyprlockAnimationManager>(); g_pAnimationManager = makeUnique<CHyprlockAnimationManager>();
try { try {
g_pConfigManager = std::make_unique<CConfigManager>(configPath); g_pConfigManager = makeUnique<CConfigManager>(configPath);
g_pConfigManager->init(); g_pConfigManager->init();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
Debug::log(CRIT, "ConfigManager threw: {}", ex.what()); 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"); g_pConfigManager->m_AnimationTree.setConfigForNode("fadeIn", false, 0.f, "default");
try { try {
g_pHyprlock = std::make_unique<CHyprlock>(wlDisplay, immediate, immediateRender); g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender);
g_pHyprlock->run(); g_pHyprlock->run();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
Debug::log(CRIT, "Hyprlock threw: {}", ex.what()); Debug::log(CRIT, "Hyprlock threw: {}", ex.what());

View file

@ -48,15 +48,12 @@ void CAsyncResourceGatherer::enqueueScreencopyFrames() {
} }
for (auto& mon : mons) { for (auto& mon : mons) {
const auto MON = std::find_if(g_pHyprlock->m_vOutputs.begin(), g_pHyprlock->m_vOutputs.end(), const auto MON = std::ranges::find_if(g_pHyprlock->m_vOutputs, [mon](const auto& other) { return other->stringPort == mon || other->stringDesc.starts_with(mon); });
[mon](const auto& other) { return other->stringPort == mon || other->stringDesc.starts_with(mon); });
if (MON == g_pHyprlock->m_vOutputs.end()) if (MON == g_pHyprlock->m_vOutputs.end())
continue; continue;
const auto PMONITOR = MON->get(); scframes.emplace_back(makeUnique<CScreencopyFrame>(*MON));
scframes.emplace_back(std::make_unique<CScreencopyFrame>(PMONITOR));
} }
} }

View file

@ -75,7 +75,7 @@ class CAsyncResourceGatherer {
Vector2D size; Vector2D size;
}; };
std::vector<std::unique_ptr<CScreencopyFrame>> scframes; std::vector<UP<CScreencopyFrame>> scframes;
std::vector<SPreloadTarget> preloadTargets; std::vector<SPreloadTarget> preloadTargets;
std::mutex preloadTargetsMutex; std::mutex preloadTargetsMutex;

View file

@ -194,7 +194,7 @@ CRenderer::CRenderer() {
borderShader.gradientLerp = glGetUniformLocation(prog, "gradientLerp"); borderShader.gradientLerp = glGetUniformLocation(prog, "gradientLerp");
borderShader.alpha = glGetUniformLocation(prog, "alpha"); 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")); g_pAnimationManager->createAnimation(0.f, opacity, g_pConfigManager->m_AnimationTree.getConfig("fadeIn"));
} }
@ -397,9 +397,8 @@ void CRenderer::renderTextureMix(const CBox& box, const CTexture& tex, const CTe
glBindTexture(tex.m_iTarget, 0); glBindTexture(tex.m_iTarget, 0);
} }
std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface* surf) { std::vector<SP<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface* surf) {
if (!widgets.contains(surf)) { if (!widgets.contains(surf)) {
auto CWIDGETS = g_pConfigManager->getWidgetConfigs(); auto CWIDGETS = g_pConfigManager->getWidgetConfigs();
std::ranges::sort(CWIDGETS, [](CConfigManager::SWidgetConfig& a, CConfigManager::SWidgetConfig& b) { std::ranges::sort(CWIDGETS, [](CConfigManager::SWidgetConfig& a, CConfigManager::SWidgetConfig& b) {
@ -407,8 +406,8 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
}); });
for (auto& c : CWIDGETS) { for (auto& c : CWIDGETS) {
if (!c.monitor.empty() && c.monitor != surf->output->stringPort && !surf->output->stringDesc.starts_with(c.monitor) && const auto POUTPUT = surf->m_outputRef.lock();
!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; continue;
// by type // by type
@ -417,7 +416,7 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
std::string resourceID = ""; std::string resourceID = "";
if (PATH == "screenshot") { if (PATH == "screenshot") {
resourceID = CScreencopyFrame::getResourceId(surf->output); resourceID = CScreencopyFrame::getResourceId(POUTPUT);
// When the initial gather of the asyncResourceGatherer is completed (ready), all DMAFrames are available. // 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. // Dynamic ones are tricky, because a screencopy would copy hyprlock itself.
if (asyncResourceGatherer->gathered) { if (asyncResourceGatherer->gathered) {
@ -433,13 +432,13 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
} else if (!PATH.empty()) } else if (!PATH.empty())
resourceID = "background:" + PATH; resourceID = "background:" + PATH;
widgets[surf].emplace_back(std::make_unique<CBackground>(surf->size, surf->output, resourceID, c.values, PATH == "screenshot")); widgets[surf].emplace_back(makeShared<CBackground>(surf->size, POUTPUT.get(), resourceID, c.values, PATH == "screenshot"));
} else if (c.type == "input-field") { } else if (c.type == "input-field") {
widgets[surf].emplace_back(std::make_unique<CPasswordInputField>(surf->size, c.values, surf->output->stringPort)); widgets[surf].emplace_back(makeShared<CPasswordInputField>(surf->size, c.values, POUTPUT->stringPort));
} else if (c.type == "label") { } else if (c.type == "label") {
widgets[surf].emplace_back(std::make_unique<CLabel>(surf->size, c.values, surf->output->stringPort)); widgets[surf].emplace_back(makeShared<CLabel>(surf->size, c.values, POUTPUT->stringPort));
} else if (c.type == "shape") { } else if (c.type == "shape") {
widgets[surf].emplace_back(std::make_unique<CShape>(surf->size, c.values)); widgets[surf].emplace_back(makeShared<CShape>(surf->size, c.values));
} else if (c.type == "image") { } else if (c.type == "image") {
const std::string PATH = std::any_cast<Hyprlang::STRING>(c.values.at("path")); const std::string PATH = std::any_cast<Hyprlang::STRING>(c.values.at("path"));
@ -447,7 +446,7 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
if (!PATH.empty()) if (!PATH.empty())
resourceID = "image:" + PATH; resourceID = "image:" + PATH;
widgets[surf].emplace_back(std::make_unique<CImage>(surf->size, surf->output, resourceID, c.values)); widgets[surf].emplace_back(makeShared<CImage>(surf->size, POUTPUT.get(), resourceID, c.values));
} }
} }
} }

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include <memory>
#include <chrono> #include <chrono>
#include <optional> #include <optional>
#include "Shader.hpp" #include "Shader.hpp"
#include "../defines.hpp"
#include "../core/LockSurface.hpp" #include "../core/LockSurface.hpp"
#include "../helpers/AnimatedVariable.hpp" #include "../helpers/AnimatedVariable.hpp"
#include "../helpers/Color.hpp" #include "../helpers/Color.hpp"
@ -12,7 +12,7 @@
#include "widgets/IWidget.hpp" #include "widgets/IWidget.hpp"
#include "Framebuffer.hpp" #include "Framebuffer.hpp"
typedef std::unordered_map<const CSessionLockSurface*, std::vector<std::unique_ptr<IWidget>>> widgetMap_t; typedef std::unordered_map<const CSessionLockSurface*, std::vector<SP<IWidget>>> widgetMap_t;
class CRenderer { class CRenderer {
public: public:
@ -29,7 +29,7 @@ class CRenderer {
float boostA = 1.0; 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 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); void renderBorder(const CBox& box, const CGradientValueData& gradient, int thickness, int rounding = 0, float alpha = 1.0);
@ -37,37 +37,37 @@ 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 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); void blurFB(const CFramebuffer& outfb, SBlurParams params);
std::unique_ptr<CAsyncResourceGatherer> asyncResourceGatherer; UP<CAsyncResourceGatherer> asyncResourceGatherer;
std::chrono::system_clock::time_point firstFullFrameTime; std::chrono::system_clock::time_point firstFullFrameTime;
void pushFb(GLint fb); void pushFb(GLint fb);
void popFb(); void popFb();
void removeWidgetsFor(const CSessionLockSurface* surf); void removeWidgetsFor(const CSessionLockSurface* surf);
void startFadeIn(); void startFadeIn();
void startFadeOut(bool unlock = false, bool immediate = true); void startFadeOut(bool unlock = false, bool immediate = true);
private: 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 rectShader;
CShader texShader; CShader texShader;
CShader texMixShader; CShader texMixShader;
CShader blurShader1; CShader blurShader1;
CShader blurShader2; CShader blurShader2;
CShader blurPrepareShader; CShader blurPrepareShader;
CShader blurFinishShader; CShader blurFinishShader;
CShader borderShader; CShader borderShader;
Mat3x3 projMatrix = Mat3x3::identity(); Mat3x3 projMatrix = Mat3x3::identity();
Mat3x3 projection; 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;

View file

@ -11,6 +11,7 @@
#include <array> #include <array>
#include <cstdint> #include <cstdint>
#include <gbm.h> #include <gbm.h>
#include <hyprutils/memory/UniquePtr.hpp>
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <libdrm/drm_fourcc.h> #include <libdrm/drm_fourcc.h>
@ -22,24 +23,27 @@ static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = nullpt
static PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT = nullptr; static PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT = nullptr;
// //
std::string CScreencopyFrame::getResourceId(COutput* output) { std::string CScreencopyFrame::getResourceId(SP<COutput> pOutput) {
return std::format("screencopy:{}-{}x{}", output->stringPort, output->size.x, output->size.y); return std::format("screencopy:{}-{}x{}", pOutput->stringPort, pOutput->size.x, pOutput->size.y);
} }
CScreencopyFrame::CScreencopyFrame(COutput* output) : m_output(output) { CScreencopyFrame::CScreencopyFrame(SP<COutput> pOutput) : m_outputRef(pOutput) {
m_resourceID = getResourceId(m_output);
captureOutput(); captureOutput();
static const auto SCMODE = g_pConfigManager->getValue<Hyprlang::INT>("general:screencopy_mode"); static const auto SCMODE = g_pConfigManager->getValue<Hyprlang::INT>("general:screencopy_mode");
if (*SCMODE == 1) if (*SCMODE == 1)
m_frame = std::make_unique<CSCSHMFrame>(m_sc); m_frame = makeUnique<CSCSHMFrame>(m_sc);
else else
m_frame = std::make_unique<CSCDMAFrame>(m_sc); m_frame = makeUnique<CSCDMAFrame>(m_sc);
} }
void CScreencopyFrame::captureOutput() { 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) { m_sc->setBufferDone([this](CCZwlrScreencopyFrameV1* r) {
Debug::log(TRACE, "[sc] wlrOnBufferDone for {}", (void*)this); Debug::log(TRACE, "[sc] wlrOnBufferDone for {}", (void*)this);

View file

@ -22,9 +22,9 @@ class ISCFrame {
class CScreencopyFrame { class CScreencopyFrame {
public: public:
static std::string getResourceId(COutput* output); static std::string getResourceId(SP<COutput> pOutput);
CScreencopyFrame(COutput* mon); CScreencopyFrame(SP<COutput> pOutput);
~CScreencopyFrame() = default; ~CScreencopyFrame() = default;
void captureOutput(); void captureOutput();
@ -35,10 +35,10 @@ class CScreencopyFrame {
SPreloadedAsset m_asset; SPreloadedAsset m_asset;
private: private:
COutput* m_output = nullptr; WP<COutput> m_outputRef;
std::unique_ptr<ISCFrame> m_frame = nullptr; UP<ISCFrame> m_frame = nullptr;
bool m_dmaFailed = false; bool m_dmaFailed = false;
}; };
// Uses a gpu buffer created via gbm_bo // Uses a gpu buffer created via gbm_bo

View file

@ -150,8 +150,14 @@ bool CBackground::draw(const SRenderData& data) {
HYPRUTILS_TRANSFORM_NORMAL); // this could be omitted but whatever it's only once and makes code cleaner plus less blurring on large texs HYPRUTILS_TRANSFORM_NORMAL); // this could be omitted but whatever it's only once and makes code cleaner plus less blurring on large texs
if (blurPasses > 0) if (blurPasses > 0)
g_pRenderer->blurFB(blurredFB, CRenderer::SBlurParams{ g_pRenderer->blurFB(blurredFB,
.size = blurSize, .passes = blurPasses, .noise = noise, .contrast = contrast, .brightness = brightness, .vibrancy = vibrancy, .vibrancy_darkness = vibrancy_darkness}); CRenderer::SBlurParams{.size = blurSize,
.passes = blurPasses,
.noise = noise,
.contrast = contrast,
.brightness = brightness,
.vibrancy = vibrancy,
.vibrancy_darkness = vibrancy_darkness});
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
} }
@ -190,7 +196,7 @@ void CBackground::onCrossFadeTimerUpdate() {
if (fade) { if (fade) {
fade->crossFadeTimer.reset(); fade->crossFadeTimer.reset();
fade.reset(nullptr); fade.reset();
} }
if (blurPasses <= 0 && !isScreenshot) if (blurPasses <= 0 && !isScreenshot)
@ -262,7 +268,7 @@ void CBackground::startCrossFadeOrUpdateRender() {
if (crossFadeTime > 0) { if (crossFadeTime > 0) {
// Start a fade // Start a fade
if (!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 { else {
// Maybe we where already fading so reset it just in case, but should'nt be happening. // Maybe we where already fading so reset it just in case, but should'nt be happening.
if (fade->crossFadeTimer) { if (fade->crossFadeTimer) {

View file

@ -60,11 +60,11 @@ class CBackground : public IWidget {
SPreloadedAsset* pendingAsset = nullptr; SPreloadedAsset* pendingAsset = nullptr;
bool firstRender = true; bool firstRender = true;
std::unique_ptr<SFade> fade; UP<SFade> fade;
int reloadTime = -1; int reloadTime = -1;
std::string reloadCommand; std::string reloadCommand;
CAsyncResourceGatherer::SPreloadRequest request; CAsyncResourceGatherer::SPreloadRequest request;
std::shared_ptr<CTimer> reloadTimer; std::shared_ptr<CTimer> reloadTimer;
std::filesystem::file_time_type modificationTime; std::filesystem::file_time_type modificationTime;
}; };

View file

@ -29,4 +29,4 @@ class CShadowable {
bool ignoreDraw = false; bool ignoreDraw = false;
CFramebuffer shadowFB; CFramebuffer shadowFB;
}; };