diff --git a/hyprbars/barDeco.cpp b/hyprbars/barDeco.cpp index 59810441..ef86533b 100644 --- a/hyprbars/barDeco.cpp +++ b/hyprbars/barDeco.cpp @@ -29,7 +29,7 @@ CHyprBar::CHyprBar(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) { m_pTouchDownCallback = HyprlandAPI::registerCallbackDynamic( PHANDLE, "touchDown", [&](void* self, SCallbackInfo& info, std::any param) { onTouchDown(info, std::any_cast(param)); }); m_pTouchUpCallback = HyprlandAPI::registerCallbackDynamic( // - PHANDLE, "touchUp", [&](void* self, SCallbackInfo& info, std::any param) { handleUpEvent(info); }); + PHANDLE, "touchUp", [&](void* self, SCallbackInfo& info, std::any param) { onTouchUp(info, std::any_cast(param)); }); //move events m_pTouchMoveCallback = HyprlandAPI::registerCallbackDynamic( @@ -126,23 +126,27 @@ void CHyprBar::onMouseButton(SCallbackInfo& info, IPointer::SButtonEvent e) { } void CHyprBar::onTouchDown(SCallbackInfo& info, ITouch::SDownEvent e) { - if (!inputIsValid()) + // Don't do anything if you're already grabbed a window with another finger + if (!inputIsValid() || e.touchID != 0) return; - auto PMONITOR = g_pCompositor->getMonitorFromName(!e.device->m_boundOutput.empty() ? e.device->m_boundOutput : ""); - PMONITOR = PMONITOR ? PMONITOR : g_pCompositor->m_lastMonitor.lock(); - g_pCompositor->warpCursorTo({PMONITOR->m_position.x + e.pos.x * PMONITOR->m_size.x, PMONITOR->m_position.y + e.pos.y * PMONITOR->m_size.y}, true); - handleDownEvent(info, e); } +void CHyprBar::onTouchUp(SCallbackInfo& info, ITouch::SUpEvent e) { + if (!m_bDragPending || !m_bTouchEv || e.touchID != m_touchId) + return; + + handleUpEvent(info); +} + void CHyprBar::onMouseMove(Vector2D coords) { // ensure proper redraws of button icons on hover when using hardware cursors static auto* const PICONONHOVER = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:icon_on_hover")->getDataStaticPtr(); if (**PICONONHOVER) damageOnButtonHover(); - if (!m_bDragPending || m_bTouchEv || !validMapped(m_pWindow)) + if (!m_bDragPending || m_bTouchEv || !validMapped(m_pWindow) || m_touchId != 0) return; m_bDragPending = false; @@ -150,19 +154,38 @@ void CHyprBar::onMouseMove(Vector2D coords) { } void CHyprBar::onTouchMove(SCallbackInfo& info, ITouch::SMotionEvent e) { - if (!m_bDragPending || !m_bTouchEv || !validMapped(m_pWindow)) + if (!m_bDragPending || !m_bTouchEv || !validMapped(m_pWindow) || e.touchID != m_touchId) return; - g_pInputManager->mouseMoveUnified(e.timeMs); - handleMovement(); + auto PMONITOR = m_pWindow->m_monitor.lock(); + PMONITOR = PMONITOR ? PMONITOR : g_pCompositor->m_lastMonitor.lock(); + const auto COORDS = Vector2D(PMONITOR->m_position.x + e.pos.x * PMONITOR->m_size.x, PMONITOR->m_position.y + e.pos.y * PMONITOR->m_size.y); + + if (!m_bDraggingThis) { + // Initial setup for dragging a window. + g_pKeybindManager->m_dispatchers["setfloating"]("activewindow"); + g_pKeybindManager->m_dispatchers["resizewindowpixel"]("exact 50% 50%,activewindow"); + // pin it so you can change workspaces while dragging a window + g_pKeybindManager->m_dispatchers["pin"]("activewindow"); + } + g_pKeybindManager->m_dispatchers["movewindowpixel"](std::format("exact {} {},activewindow", (int)(COORDS.x - (assignedBoxGlobal().w / 2)), (int)COORDS.y)); + m_bDraggingThis = true; } void CHyprBar::handleDownEvent(SCallbackInfo& info, std::optional touchEvent) { m_bTouchEv = touchEvent.has_value(); + if (m_bTouchEv) + m_touchId = touchEvent.value().touchID; - const auto PWINDOW = m_pWindow.lock(); + const auto PWINDOW = m_pWindow.lock(); - const auto COORDS = cursorRelativeToBar(); + auto COORDS = cursorRelativeToBar(); + if (m_bTouchEv) { + ITouch::SDownEvent e = touchEvent.value(); + auto PMONITOR = g_pCompositor->getMonitorFromName(!e.device->m_boundOutput.empty() ? e.device->m_boundOutput : ""); + PMONITOR = PMONITOR ? PMONITOR : g_pCompositor->m_lastMonitor.lock(); + COORDS = Vector2D(PMONITOR->m_position.x + e.pos.x * PMONITOR->m_size.x, PMONITOR->m_position.y + e.pos.y * PMONITOR->m_size.y) - assignedBoxGlobal().pos(); + } 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(); @@ -176,11 +199,8 @@ void CHyprBar::handleDownEvent(SCallbackInfo& info, std::optionalwarpCursorTo(Vector2D(e.pos.x, e.pos.y)); - g_pInputManager->mouseMoveUnified(e.timeMs); - } + if (m_bTouchEv) + g_pKeybindManager->m_dispatchers["settiled"]("activewindow"); g_pKeybindManager->m_dispatchers["mouse"]("0movewindow"); Debug::log(LOG, "[hyprbars] Dragging ended on {:x}", (uintptr_t)PWINDOW.get()); } @@ -225,12 +245,15 @@ void CHyprBar::handleUpEvent(SCallbackInfo& info) { if (m_bDraggingThis) { g_pKeybindManager->m_dispatchers["mouse"]("0movewindow"); m_bDraggingThis = false; + if (m_bTouchEv) + g_pKeybindManager->m_dispatchers["settiled"]("activewindow"); Debug::log(LOG, "[hyprbars] Dragging ended on {:x}", (uintptr_t)m_pWindow.lock().get()); } m_bDragPending = false; m_bTouchEv = false; + m_touchId = 0; } void CHyprBar::handleMovement() { diff --git a/hyprbars/barDeco.hpp b/hyprbars/barDeco.hpp index 5b754be2..f8c86f7e 100644 --- a/hyprbars/barDeco.hpp +++ b/hyprbars/barDeco.hpp @@ -82,6 +82,7 @@ class CHyprBar : public IHyprWindowDecoration { bool inputIsValid(); void onMouseButton(SCallbackInfo& info, IPointer::SButtonEvent e); void onTouchDown(SCallbackInfo& info, ITouch::SDownEvent e); + void onTouchUp(SCallbackInfo& info, ITouch::SUpEvent e); void onMouseMove(Vector2D coords); void onTouchMove(SCallbackInfo& info, ITouch::SMotionEvent e); @@ -105,6 +106,7 @@ class CHyprBar : public IHyprWindowDecoration { bool m_bTouchEv = false; bool m_bDragPending = false; bool m_bCancelledDown = false; + int m_touchId = 0; // store hover state for buttons as a bitfield unsigned int m_iButtonHoverState = 0;