From 0bb3e3321ecddc6aa32285ae1bab3edf3bae7226 Mon Sep 17 00:00:00 2001 From: caffeine01 Date: Wed, 11 Dec 2024 11:44:40 +0000 Subject: [PATCH] fix porblem where the plugin would take control of all clicks + problem where dragging was toggled on any click of the bar --- hyprbars/barDeco.cpp | 49 +++++++++++++++++++++++--------------------- hyprbars/barDeco.hpp | 26 +++++++++++------------ 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/hyprbars/barDeco.cpp b/hyprbars/barDeco.cpp index 97634a8..b463f13 100644 --- a/hyprbars/barDeco.cpp +++ b/hyprbars/barDeco.cpp @@ -18,8 +18,10 @@ CHyprBar::CHyprBar(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) { m_pTouchDownCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "touchDown", [&](void* self, SCallbackInfo& info, std::any param) { onTouchDown(info); }); + /* Not implemented (yet) m_pTipDownCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "tabletTip", [&](void* self, SCallbackInfo& info, std::any param) { onTipDown(info, std::any_cast(param)); }); + */ m_pMouseMoveCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseMove", [&](void* self, SCallbackInfo& info, std::any param) { onMouseMove(std::any_cast(param)); }); @@ -32,7 +34,7 @@ CHyprBar::~CHyprBar() { damageEntire(); HyprlandAPI::unregisterCallback(PHANDLE, m_pMouseButtonCallback); HyprlandAPI::unregisterCallback(PHANDLE, m_pTouchDownCallback); - HyprlandAPI::unregisterCallback(PHANDLE, m_pTipDownCallback); + /* HyprlandAPI::unregisterCallback(PHANDLE, m_pTipDownCallback); */ HyprlandAPI::unregisterCallback(PHANDLE, m_pMouseMoveCallback); std::erase(g_pGlobalState->bars, this); } @@ -62,22 +64,15 @@ std::string CHyprBar::getDisplayName() { } void CHyprBar::onMouseDown(SCallbackInfo& info, IPointer::SButtonEvent e) { - if (m_pWindow.lock() != g_pCompositor->m_pLastWindow.lock()) - return; - const auto PWINDOW = m_pWindow.lock(); + const auto COORDS = cursorRelativeToBar(); - const auto COORDS = cursorRelativeToBar(); - - static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr(); - static auto* const PBARBUTTONPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->getDataStaticPtr(); - static auto* const PBARPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_padding")->getDataStaticPtr(); - static auto* const PALIGNBUTTONS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->getDataStaticPtr(); + static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr(); + static auto* const PALIGNBUTTONS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->getDataStaticPtr(); const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left"; if (!VECINRECT(COORDS, 0, 0, assignedBoxGlobal().w, **PHEIGHT - 1)) { - if (m_bDraggingThis) { g_pKeybindManager->m_mDispatchers["mouse"]("0movewindow"); Debug::log(LOG, "[hyprbars] Dragging ended on {:x}", (uintptr_t)PWINDOW.get()); @@ -113,26 +108,37 @@ void CHyprBar::onMouseDown(SCallbackInfo& info, IPointer::SButtonEvent e) { info.cancelled = true; m_bCancelledDown = true; - // check if on a button + // do the button press - CHyprBar::doButtonPress(); + CHyprBar::doButtonPress(COORDS); m_bDragPending = true; } void CHyprBar::onTouchDown(SCallbackInfo& info) { - CHyprBar::doButtonPress(); + if (m_pWindow.lock() != g_pCompositor->m_pLastWindow.lock()) + return; + + const auto COORDS = cursorRelativeToBar(); + static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr(); + if (!VECINRECT(COORDS, 0, 0, assignedBoxGlobal().w, **PHEIGHT - 1)) + return; + CHyprBar::doButtonPress(COORDS); } +/* void CHyprBar::onTipDown(SCallbackInfo& info, CTablet::STipEvent e) { - HyprlandAPI::addNotification(PHANDLE, "[hyprbars] TIP DOWN", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000); if (!e.in) return; - CHyprBar::doButtonPress(); + CHyprBar::doButtonPress(cursorRelativeToBar()); } +*/ -void CHyprBar::doButtonPress() { - const auto COORDS = cursorRelativeToBar(); +void CHyprBar::doButtonPress(Vector2D coords) { + if (m_pWindow.lock() != g_pCompositor->m_pLastWindow.lock()) + return; + + const auto PWINDOW = m_pWindow.lock(); static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr(); static auto* const PBARBUTTONPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->getDataStaticPtr(); @@ -141,16 +147,13 @@ void CHyprBar::doButtonPress() { const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left"; - if (!VECINRECT(COORDS, 0, 0, assignedBoxGlobal().w, **PHEIGHT - 1)) - return; - - float offset = **PBARPADDING; + float offset = **PBARPADDING; for (auto& b : g_pGlobalState->buttons) { const auto BARBUF = Vector2D{(int)assignedBoxGlobal().w, **PHEIGHT}; Vector2D currentPos = Vector2D{(BUTTONSRIGHT ? BARBUF.x - **PBARBUTTONPADDING - b.size - offset : offset), (BARBUF.y - b.size) / 2.0}.floor(); - if (VECINRECT(COORDS, currentPos.x, currentPos.y, currentPos.x + b.size + **PBARBUTTONPADDING, currentPos.y + b.size)) { + if (VECINRECT(coords, currentPos.x, currentPos.y, currentPos.x + b.size + **PBARBUTTONPADDING, currentPos.y + b.size)) { // hit on close g_pKeybindManager->m_mDispatchers["exec"](b.cmd); return; diff --git a/hyprbars/barDeco.hpp b/hyprbars/barDeco.hpp index 76a28ba..ede0711 100644 --- a/hyprbars/barDeco.hpp +++ b/hyprbars/barDeco.hpp @@ -62,22 +62,22 @@ class CHyprBar : public IHyprWindowDecoration { void renderBarButtons(const Vector2D& bufferSize, const float scale); void renderBarButtonsText(CBox* barBox, const float scale, const float a); void onMouseDown(SCallbackInfo& info, IPointer::SButtonEvent e); - void onTipDown(SCallbackInfo& info, CTablet::STipEvent e); - void onTouchDown(SCallbackInfo& info); - void doButtonPress(); - void onMouseMove(Vector2D coords); - CBox assignedBoxGlobal(); + /* void onTipDown(SCallbackInfo& info, CTablet::STipEvent e); */ + void onTouchDown(SCallbackInfo& info); + void doButtonPress(Vector2D coords); + void onMouseMove(Vector2D coords); + CBox assignedBoxGlobal(); - SP m_pMouseButtonCallback; - SP m_pTouchDownCallback; - SP m_pTipDownCallback; - SP m_pMouseMoveCallback; + SP m_pMouseButtonCallback; + SP m_pTouchDownCallback; + /* SP m_pTipDownCallback; */ + SP m_pMouseMoveCallback; - std::string m_szLastTitle; + std::string m_szLastTitle; - bool m_bDraggingThis = false; - bool m_bDragPending = false; - bool m_bCancelledDown = false; + bool m_bDraggingThis = false; + bool m_bDragPending = false; + bool m_bCancelledDown = false; // for dynamic updates int m_iLastHeight = 0;