hyprerror: refactor class member vars (#10227)

This commit is contained in:
davc0n 2025-05-01 13:26:43 +02:00 committed by GitHub
parent 8d6618104e
commit ce4766772d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 61 deletions

View File

@ -12,40 +12,40 @@
using namespace Hyprutils::Animation; using namespace Hyprutils::Animation;
CHyprError::CHyprError() { CHyprError::CHyprError() {
g_pAnimationManager->createAnimation(0.f, m_fFadeOpacity, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), AVARDAMAGE_NONE); g_pAnimationManager->createAnimation(0.f, m_fadeOpacity, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), AVARDAMAGE_NONE);
static auto P = g_pHookSystem->hookDynamic("focusedMon", [&](void* self, SCallbackInfo& info, std::any param) { static auto P = g_pHookSystem->hookDynamic("focusedMon", [&](void* self, SCallbackInfo& info, std::any param) {
if (!m_bIsCreated) if (!m_isCreated)
return; return;
g_pHyprRenderer->damageMonitor(g_pCompositor->m_lastMonitor.lock()); g_pHyprRenderer->damageMonitor(g_pCompositor->m_lastMonitor.lock());
m_bMonitorChanged = true; m_monitorChanged = true;
}); });
static auto P2 = g_pHookSystem->hookDynamic("preRender", [&](void* self, SCallbackInfo& info, std::any param) { static auto P2 = g_pHookSystem->hookDynamic("preRender", [&](void* self, SCallbackInfo& info, std::any param) {
if (!m_bIsCreated) if (!m_isCreated)
return; return;
if (m_fFadeOpacity->isBeingAnimated() || m_bMonitorChanged) if (m_fadeOpacity->isBeingAnimated() || m_monitorChanged)
g_pHyprRenderer->damageBox(m_bDamageBox); g_pHyprRenderer->damageBox(m_damageBox);
}); });
m_pTexture = makeShared<CTexture>(); m_texture = makeShared<CTexture>();
} }
void CHyprError::queueCreate(std::string message, const CHyprColor& color) { void CHyprError::queueCreate(std::string message, const CHyprColor& color) {
m_szQueued = message; m_queued = message;
m_cQueued = color; m_queuedColor = color;
} }
void CHyprError::createQueued() { void CHyprError::createQueued() {
if (m_bIsCreated) if (m_isCreated)
m_pTexture->destroyTexture(); m_texture->destroyTexture();
m_fFadeOpacity->setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeIn")); m_fadeOpacity->setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeIn"));
m_fFadeOpacity->setValueAndWarp(0.f); m_fadeOpacity->setValueAndWarp(0.f);
*m_fFadeOpacity = 1.f; *m_fadeOpacity = 1.f;
const auto PMONITOR = g_pCompositor->m_monitors.front(); const auto PMONITOR = g_pCompositor->m_monitors.front();
@ -63,7 +63,7 @@ void CHyprError::createQueued() {
cairo_paint(CAIRO); cairo_paint(CAIRO);
cairo_restore(CAIRO); cairo_restore(CAIRO);
const auto LINECOUNT = Hyprlang::INT{1} + std::count(m_szQueued.begin(), m_szQueued.end(), '\n'); const auto LINECOUNT = Hyprlang::INT{1} + std::count(m_queued.begin(), m_queued.end(), '\n');
static auto LINELIMIT = CConfigValue<Hyprlang::INT>("debug:error_limit"); static auto LINELIMIT = CConfigValue<Hyprlang::INT>("debug:error_limit");
static auto BAR_POSITION = CConfigValue<Hyprlang::INT>("debug:error_position"); static auto BAR_POSITION = CConfigValue<Hyprlang::INT>("debug:error_position");
@ -82,7 +82,7 @@ void CHyprError::createQueued() {
const double X = PAD; const double X = PAD;
const double Y = TOPBAR ? PAD : PMONITOR->m_pixelSize.y - HEIGHT - PAD; const double Y = TOPBAR ? PAD : PMONITOR->m_pixelSize.y - HEIGHT - PAD;
m_bDamageBox = {0, 0, (int)PMONITOR->m_pixelSize.x, (int)HEIGHT + (int)PAD * 2}; m_damageBox = {0, 0, (int)PMONITOR->m_pixelSize.x, (int)HEIGHT + (int)PAD * 2};
cairo_new_sub_path(CAIRO); cairo_new_sub_path(CAIRO);
cairo_arc(CAIRO, X + WIDTH - RADIUS, Y + RADIUS, RADIUS, -90 * DEGREES, 0 * DEGREES); cairo_arc(CAIRO, X + WIDTH - RADIUS, Y + RADIUS, RADIUS, -90 * DEGREES, 0 * DEGREES);
@ -93,7 +93,7 @@ void CHyprError::createQueued() {
cairo_set_source_rgba(CAIRO, 0.06, 0.06, 0.06, 1.0); cairo_set_source_rgba(CAIRO, 0.06, 0.06, 0.06, 1.0);
cairo_fill_preserve(CAIRO); cairo_fill_preserve(CAIRO);
cairo_set_source_rgba(CAIRO, m_cQueued.r, m_cQueued.g, m_cQueued.b, m_cQueued.a); cairo_set_source_rgba(CAIRO, m_queuedColor.r, m_queuedColor.g, m_queuedColor.b, m_queuedColor.a);
cairo_set_line_width(CAIRO, 2); cairo_set_line_width(CAIRO, 2);
cairo_stroke(CAIRO); cairo_stroke(CAIRO);
@ -113,12 +113,12 @@ void CHyprError::createQueued() {
float yoffset = TOPBAR ? 0 : Y - PAD; float yoffset = TOPBAR ? 0 : Y - PAD;
int renderedcnt = 0; int renderedcnt = 0;
while (!m_szQueued.empty() && renderedcnt < VISLINECOUNT) { while (!m_queued.empty() && renderedcnt < VISLINECOUNT) {
std::string current = m_szQueued.substr(0, m_szQueued.find('\n')); std::string current = m_queued.substr(0, m_queued.find('\n'));
if (const auto NEWLPOS = m_szQueued.find('\n'); NEWLPOS != std::string::npos) if (const auto NEWLPOS = m_queued.find('\n'); NEWLPOS != std::string::npos)
m_szQueued = m_szQueued.substr(NEWLPOS + 1); m_queued = m_queued.substr(NEWLPOS + 1);
else else
m_szQueued = ""; m_queued = "";
cairo_move_to(CAIRO, PAD + 1 + RADIUS, yoffset + PAD + 1); cairo_move_to(CAIRO, PAD + 1 + RADIUS, yoffset + PAD + 1);
pango_layout_set_text(layoutText, current.c_str(), -1); pango_layout_set_text(layoutText, current.c_str(), -1);
pango_cairo_show_layout(CAIRO, layoutText); pango_cairo_show_layout(CAIRO, layoutText);
@ -131,9 +131,9 @@ void CHyprError::createQueued() {
pango_layout_set_text(layoutText, moreString.c_str(), -1); pango_layout_set_text(layoutText, moreString.c_str(), -1);
pango_cairo_show_layout(CAIRO, layoutText); pango_cairo_show_layout(CAIRO, layoutText);
} }
m_szQueued = ""; m_queued = "";
m_fLastHeight = yoffset + PAD + 1 - (TOPBAR ? 0 : Y - PAD); m_lastHeight = yoffset + PAD + 1 - (TOPBAR ? 0 : Y - PAD);
pango_font_description_free(pangoFD); pango_font_description_free(pangoFD);
g_object_unref(layoutText); g_object_unref(layoutText);
@ -142,8 +142,8 @@ void CHyprError::createQueued() {
// copy the data to an OpenGL texture we have // copy the data to an OpenGL texture we have
const auto DATA = cairo_image_surface_get_data(CAIROSURFACE); const auto DATA = cairo_image_surface_get_data(CAIROSURFACE);
m_pTexture->allocate(); m_texture->allocate();
glBindTexture(GL_TEXTURE_2D, m_pTexture->m_iTexID); glBindTexture(GL_TEXTURE_2D, m_texture->m_iTexID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -158,9 +158,9 @@ void CHyprError::createQueued() {
cairo_destroy(CAIRO); cairo_destroy(CAIRO);
cairo_surface_destroy(CAIROSURFACE); cairo_surface_destroy(CAIROSURFACE);
m_bIsCreated = true; m_isCreated = true;
m_szQueued = ""; m_queued = "";
m_cQueued = CHyprColor(); m_queuedColor = CHyprColor();
g_pHyprRenderer->damageMonitor(PMONITOR); g_pHyprRenderer->damageMonitor(PMONITOR);
@ -168,19 +168,19 @@ void CHyprError::createQueued() {
} }
void CHyprError::draw() { void CHyprError::draw() {
if (!m_bIsCreated || m_szQueued != "") { if (!m_isCreated || m_queued != "") {
if (m_szQueued != "") if (m_queued != "")
createQueued(); createQueued();
return; return;
} }
if (m_bQueuedDestroy) { if (m_queuedDestroy) {
if (!m_fFadeOpacity->isBeingAnimated()) { if (!m_fadeOpacity->isBeingAnimated()) {
if (m_fFadeOpacity->value() == 0.f) { if (m_fadeOpacity->value() == 0.f) {
m_bQueuedDestroy = false; m_queuedDestroy = false;
m_pTexture->destroyTexture(); m_texture->destroyTexture();
m_bIsCreated = false; m_isCreated = false;
m_szQueued = ""; m_queued = "";
for (auto& m : g_pCompositor->m_monitors) { for (auto& m : g_pCompositor->m_monitors) {
g_pHyprRenderer->arrangeLayersForMonitor(m->m_id); g_pHyprRenderer->arrangeLayersForMonitor(m->m_id);
@ -188,8 +188,8 @@ void CHyprError::draw() {
return; return;
} else { } else {
m_fFadeOpacity->setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeOut")); m_fadeOpacity->setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeOut"));
*m_fFadeOpacity = 0.f; *m_fadeOpacity = 0.f;
} }
} }
} }
@ -198,33 +198,33 @@ void CHyprError::draw() {
CBox monbox = {0, 0, PMONITOR->m_pixelSize.x, PMONITOR->m_pixelSize.y}; CBox monbox = {0, 0, PMONITOR->m_pixelSize.x, PMONITOR->m_pixelSize.y};
m_bDamageBox.x = (int)PMONITOR->m_position.x; m_damageBox.x = (int)PMONITOR->m_position.x;
m_bDamageBox.y = (int)PMONITOR->m_position.y; m_damageBox.y = (int)PMONITOR->m_position.y;
if (m_fFadeOpacity->isBeingAnimated() || m_bMonitorChanged) if (m_fadeOpacity->isBeingAnimated() || m_monitorChanged)
g_pHyprRenderer->damageBox(m_bDamageBox); g_pHyprRenderer->damageBox(m_damageBox);
m_bMonitorChanged = false; m_monitorChanged = false;
CTexPassElement::SRenderData data; CTexPassElement::SRenderData data;
data.tex = m_pTexture; data.tex = m_texture;
data.box = monbox; data.box = monbox;
data.a = m_fFadeOpacity->value(); data.a = m_fadeOpacity->value();
g_pHyprRenderer->m_sRenderPass.add(makeShared<CTexPassElement>(data)); g_pHyprRenderer->m_sRenderPass.add(makeShared<CTexPassElement>(data));
} }
void CHyprError::destroy() { void CHyprError::destroy() {
if (m_bIsCreated) if (m_isCreated)
m_bQueuedDestroy = true; m_queuedDestroy = true;
else else
m_szQueued = ""; m_queued = "";
} }
bool CHyprError::active() { bool CHyprError::active() {
return m_bIsCreated; return m_isCreated;
} }
float CHyprError::height() { float CHyprError::height() {
return m_fLastHeight; return m_lastHeight;
} }

View File

@ -20,16 +20,16 @@ class CHyprError {
private: private:
void createQueued(); void createQueued();
std::string m_szQueued = ""; std::string m_queued = "";
CHyprColor m_cQueued; CHyprColor m_queuedColor;
bool m_bQueuedDestroy = false; bool m_queuedDestroy = false;
bool m_bIsCreated = false; bool m_isCreated = false;
SP<CTexture> m_pTexture; SP<CTexture> m_texture;
PHLANIMVAR<float> m_fFadeOpacity; PHLANIMVAR<float> m_fadeOpacity;
CBox m_bDamageBox = {0, 0, 0, 0}; CBox m_damageBox = {0, 0, 0, 0};
float m_fLastHeight = 0.F; float m_lastHeight = 0.F;
bool m_bMonitorChanged = false; bool m_monitorChanged = false;
}; };
inline UP<CHyprError> g_pHyprError; // This is a full-screen error. Treat it with respect, and there can only be one at a time. inline UP<CHyprError> g_pHyprError; // This is a full-screen error. Treat it with respect, and there can only be one at a time.