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() {
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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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) {
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)
@ -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;

View file

@ -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,8 @@ class CSessionLockSurface {
void onScaleUpdate();
private:
COutput* output = nullptr;
WP<COutput> m_outputRef;
SP<CCWlSurface> surface = nullptr;
SP<CCExtSessionLockSurfaceV1> lockSurface = nullptr;
uint32_t serial = 0;
@ -49,4 +50,4 @@ class CSessionLockSurface {
SP<CCWlCallback> frameCallback = nullptr;
friend class CRenderer;
};
};

View file

@ -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) {
name = _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);
});
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) {
if (g_pHyprlock->m_lockAquired && !m_sessionLockSurface) {
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
if (transform % 2 == 1)
size = {height, width};
@ -34,10 +37,14 @@ 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 : "");
});
}
void COutput::createSessionLockSurface() {
m_sessionLockSurface = makeUnique<CSessionLockSurface>(m_self.lock());
}

View file

@ -2,27 +2,26 @@
#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);
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 = "";
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 = "";
std::unique_ptr<CSessionLockSurface> sessionLockSurface;
SP<CCWlOutput> output = nullptr;
SP<CCWlOutput> output = nullptr;
void createSessionLockSurface();
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) {
m_pCursorShape = std::make_unique<CCursorShape>(shape);
m_pCursorShape = makeUnique<CCursorShape>(shape);
}
bool CSeatManager::registered() {

View file

@ -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>();

View file

@ -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)
@ -310,7 +311,7 @@ void CHyprlock::run() {
Debug::log(LOG, " | removed iface {}", name);
auto outputIt = std::ranges::find_if(m_vOutputs, [name](const auto& other) { return other->name == name; });
if (outputIt != m_vOutputs.end()) {
g_pRenderer->removeWidgetsFor(outputIt->get()->sessionLockSurface.get());
g_pRenderer->removeWidgetsFor((*outputIt)->m_sessionLockSurface.get());
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;

View file

@ -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;

View file

@ -1,8 +1,10 @@
#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

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 {
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());

View file

@ -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));
}
}

View file

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

View file

@ -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"));
}
@ -397,9 +397,8 @@ 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) {
std::vector<SP<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface* surf) {
if (!widgets.contains(surf)) {
auto CWIDGETS = g_pConfigManager->getWidgetConfigs();
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) {
if (!c.monitor.empty() && c.monitor != surf->output->stringPort && !surf->output->stringDesc.starts_with(c.monitor) &&
!surf->output->stringDesc.starts_with("desc:" + c.monitor))
const auto POUTPUT = surf->m_outputRef.lock();
if (!c.monitor.empty() && c.monitor != POUTPUT->stringPort && !POUTPUT->stringDesc.starts_with(c.monitor) && !POUTPUT->stringDesc.starts_with("desc:" + c.monitor))
continue;
// by type
@ -417,7 +416,7 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
std::string resourceID = "";
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.
// Dynamic ones are tricky, because a screencopy would copy hyprlock itself.
if (asyncResourceGatherer->gathered) {
@ -433,13 +432,13 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
} else if (!PATH.empty())
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") {
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") {
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") {
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") {
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())
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
#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<const CSessionLockSurface*, 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,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 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(const CSessionLockSurface* surf);
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;

View file

@ -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);

View file

@ -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

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
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);
}
@ -190,7 +196,7 @@ void CBackground::onCrossFadeTimerUpdate() {
if (fade) {
fade->crossFadeTimer.reset();
fade.reset(nullptr);
fade.reset();
}
if (blurPasses <= 0 && !isScreenshot)
@ -262,7 +268,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) {

View file

@ -60,11 +60,11 @@ class CBackground : public IWidget {
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;
};
};

View file

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