diff --git a/hyprbars/barDeco.cpp b/hyprbars/barDeco.cpp index d60992e..2476172 100644 --- a/hyprbars/barDeco.cpp +++ b/hyprbars/barDeco.cpp @@ -19,6 +19,8 @@ CHyprBar::CHyprBar(CWindow* pWindow) { m_pMouseButtonCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseButton", [&](void* self, std::any param) { onMouseDown(std::any_cast(param)); }); + + m_pMouseMoveCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseMove", [&](void* self, std::any param) { onMouseMove(std::any_cast(param)); }); } CHyprBar::~CHyprBar() { @@ -26,6 +28,10 @@ CHyprBar::~CHyprBar() { HyprlandAPI::unregisterCallback(PHANDLE, m_pMouseButtonCallback); } +bool CHyprBar::allowsInput() { + return true; +} + SWindowDecorationExtents CHyprBar::getWindowDecorationExtents() { return m_seExtents; } @@ -36,8 +42,16 @@ void CHyprBar::onMouseDown(wlr_pointer_button_event* e) { const auto COORDS = cursorRelativeToBar(); - if (e->state != WLR_BUTTON_PRESSED) + if (e->state != WLR_BUTTON_PRESSED) { + if (m_bDraggingThis) { + g_pKeybindManager->m_mDispatchers["mouse"]("0movewindow"); + m_bDraggingThis = false; + + Debug::log(LOG, "[hyprbars] Dragging ended on %x", m_pWindow); + } + return; + } // check if on a button static auto* const PBORDERSIZE = &HyprlandAPI::getConfigValue(PHANDLE, "general:border_size")->intValue; @@ -61,6 +75,23 @@ void CHyprBar::onMouseDown(wlr_pointer_button_event* e) { g_pKeybindManager->m_mDispatchers["fullscreen"]("1"); return; } + + // if we do this here the handler later will remove our mouse bind + m_bDragPending = true; +} + +void CHyprBar::onMouseMove(Vector2D coords) { + static auto* const PHEIGHT = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->intValue; + + if (m_bDragPending) { + m_bDragPending = false; + g_pKeybindManager->m_mDispatchers["mouse"]("1movewindow"); + m_bDraggingThis = true; + + Debug::log(LOG, "[hyprbars] Dragging initiated on %x", m_pWindow); + + return; + } } void CHyprBar::renderBarTitle(const Vector2D& bufferSize) { diff --git a/hyprbars/barDeco.hpp b/hyprbars/barDeco.hpp index 7541e0b..ef59508 100644 --- a/hyprbars/barDeco.hpp +++ b/hyprbars/barDeco.hpp @@ -23,6 +23,8 @@ class CHyprBar : public IHyprWindowDecoration { virtual SWindowDecorationExtents getWindowDecorationReservedArea(); + virtual bool allowsInput(); + private: SWindowDecorationExtents m_seExtents; @@ -41,8 +43,13 @@ class CHyprBar : public IHyprWindowDecoration { void renderBarTitle(const Vector2D& bufferSize); void renderBarButtons(const Vector2D& bufferSize); void onMouseDown(wlr_pointer_button_event* e); + void onMouseMove(Vector2D coords); HOOK_CALLBACK_FN* m_pMouseButtonCallback; + HOOK_CALLBACK_FN* m_pMouseMoveCallback; std::string m_szLastTitle; + + bool m_bDraggingThis = false; + bool m_bDragPending = false; }; \ No newline at end of file