expo: fix a few crash points

fixes #494
This commit is contained in:
Vaxry
2025-12-20 19:13:54 +00:00
parent 9b2b156197
commit 3e29d68d5a
2 changed files with 23 additions and 12 deletions

View File

@ -26,6 +26,9 @@ void CExpoGesture::update(const ITrackpadGesture::STrackpadGestureUpdate& e) {
return; return;
} }
if (!g_pOverview)
return;
m_lastDelta += distance(e); m_lastDelta += distance(e);
if (m_lastDelta <= 0.01) // plugin will crash if swipe ends at <= 0 if (m_lastDelta <= 0.01) // plugin will crash if swipe ends at <= 0
@ -35,7 +38,9 @@ void CExpoGesture::update(const ITrackpadGesture::STrackpadGestureUpdate& e) {
} }
void CExpoGesture::end(const ITrackpadGesture::STrackpadGestureEnd& e) { void CExpoGesture::end(const ITrackpadGesture::STrackpadGestureEnd& e) {
if (!g_pOverview)
return;
g_pOverview->setClosing(false); g_pOverview->setClosing(false);
g_pOverview->onSwipeEnd(); g_pOverview->onSwipeEnd();
g_pOverview->resetSwipe();
} }

View File

@ -10,6 +10,7 @@
#include <hyprland/src/managers/animation/DesktopAnimationManager.hpp> #include <hyprland/src/managers/animation/DesktopAnimationManager.hpp>
#include <hyprland/src/managers/cursor/CursorShapeOverrideController.hpp> #include <hyprland/src/managers/cursor/CursorShapeOverrideController.hpp>
#include <hyprland/src/managers/input/InputManager.hpp> #include <hyprland/src/managers/input/InputManager.hpp>
#include <hyprland/src/managers/eventLoop/EventLoopManager.hpp>
#include <hyprland/src/helpers/time/Time.hpp> #include <hyprland/src/helpers/time/Time.hpp>
#undef private #undef private
#include "OverviewPassElement.hpp" #include "OverviewPassElement.hpp"
@ -18,10 +19,6 @@ static void damageMonitor(WP<Hyprutils::Animation::CBaseAnimatedVariable> thispt
g_pOverview->damage(); g_pOverview->damage();
} }
static void removeOverview(WP<Hyprutils::Animation::CBaseAnimatedVariable> thisptr) {
g_pOverview.reset();
}
COverview::~COverview() { COverview::~COverview() {
g_pHyprRenderer->makeEGLCurrent(); g_pHyprRenderer->makeEGLCurrent();
images.clear(); // otherwise we get a vram leak images.clear(); // otherwise we get a vram leak
@ -250,6 +247,9 @@ void COverview::selectHoveredWorkspace() {
} }
void COverview::redrawID(int id, bool forcelowres) { void COverview::redrawID(int id, bool forcelowres) {
if (!pMonitor)
return;
if (pMonitor->m_activeWorkspace != startedOn && !closing) { if (pMonitor->m_activeWorkspace != startedOn && !closing) {
// likely user changed. // likely user changed.
onWorkspaceChange(); onWorkspaceChange();
@ -321,6 +321,8 @@ void COverview::redrawID(int id, bool forcelowres) {
} }
void COverview::redrawAll(bool forcelowres) { void COverview::redrawAll(bool forcelowres) {
if (!pMonitor)
return;
for (size_t i = 0; i < (size_t)(SIDE_LENGTH * SIDE_LENGTH); ++i) { for (size_t i = 0; i < (size_t)(SIDE_LENGTH * SIDE_LENGTH); ++i) {
redrawID(i, forcelowres); redrawID(i, forcelowres);
} }
@ -362,11 +364,12 @@ void COverview::close() {
Vector2D tileSize = (pMonitor->m_size / SIDE_LENGTH); Vector2D tileSize = (pMonitor->m_size / SIDE_LENGTH);
size->warp();
pos->warp();
*size = pMonitor->m_size * pMonitor->m_size / tileSize; *size = pMonitor->m_size * pMonitor->m_size / tileSize;
*pos = (-((pMonitor->m_size / (double)SIDE_LENGTH) * Vector2D{ID % SIDE_LENGTH, ID / SIDE_LENGTH}) * pMonitor->m_scale) * (pMonitor->m_size / tileSize); *pos = (-((pMonitor->m_size / (double)SIDE_LENGTH) * Vector2D{ID % SIDE_LENGTH, ID / SIDE_LENGTH}) * pMonitor->m_scale) * (pMonitor->m_size / tileSize);
size->setCallbackOnEnd(removeOverview);
closing = true; closing = true;
redrawAll(); redrawAll();
@ -393,6 +396,8 @@ void COverview::close() {
startedOn = pMonitor->m_activeWorkspace; startedOn = pMonitor->m_activeWorkspace;
} }
size->setCallbackOnEnd([](auto) { g_pEventLoopManager->doLater([] { g_pOverview.reset(); }); });
} }
void COverview::onPreRender() { void COverview::onPreRender() {
@ -417,7 +422,8 @@ void COverview::onWorkspaceChange() {
} }
closeOnID = openedID; closeOnID = openedID;
close(); if (!closing)
close();
} }
void COverview::render() { void COverview::render() {
@ -469,9 +475,6 @@ void COverview::resetSwipe() {
void COverview::onSwipeUpdate(double delta) { void COverview::onSwipeUpdate(double delta) {
m_isSwiping = true; m_isSwiping = true;
if (swipeWasCommenced)
return;
static auto* const* PDISTANCE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:gesture_distance")->getDataStaticPtr(); static auto* const* PDISTANCE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:gesture_distance")->getDataStaticPtr();
const float PERC = closing ? std::clamp(delta / (double)**PDISTANCE, 0.0, 1.0) : 1.0 - std::clamp(delta / (double)**PDISTANCE, 0.0, 1.0); const float PERC = closing ? std::clamp(delta / (double)**PDISTANCE, 0.0, 1.0) : 1.0 - std::clamp(delta / (double)**PDISTANCE, 0.0, 1.0);
@ -491,6 +494,9 @@ void COverview::onSwipeUpdate(double delta) {
} }
void COverview::onSwipeEnd() { void COverview::onSwipeEnd() {
if (closing || !m_isSwiping)
return;
const auto SIZEMIN = pMonitor->m_size; const auto SIZEMIN = pMonitor->m_size;
const auto SIZEMAX = pMonitor->m_size * pMonitor->m_size / (pMonitor->m_size / SIDE_LENGTH); const auto SIZEMAX = pMonitor->m_size * pMonitor->m_size / (pMonitor->m_size / SIDE_LENGTH);
const auto PERC = (size->value() - SIZEMIN).x / (SIZEMAX - SIZEMIN).x; const auto PERC = (size->value() - SIZEMIN).x / (SIZEMAX - SIZEMIN).x;
@ -503,6 +509,6 @@ void COverview::onSwipeEnd() {
size->setCallbackOnEnd([this](WP<Hyprutils::Animation::CBaseAnimatedVariable> thisptr) { redrawAll(true); }); size->setCallbackOnEnd([this](WP<Hyprutils::Animation::CBaseAnimatedVariable> thisptr) { redrawAll(true); });
swipeWasCommenced = true; swipeWasCommenced = false;
m_isSwiping = false; m_isSwiping = false;
} }