Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions hyprbars/barDeco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITouch::SDownEvent>(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<ITouch::SUpEvent>(param)); });

//move events
m_pTouchMoveCallback = HyprlandAPI::registerCallbackDynamic(
Expand Down Expand Up @@ -126,43 +126,66 @@ 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;
handleMovement();
}

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<ITouch::SDownEvent> 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();
Expand All @@ -176,11 +199,8 @@ void CHyprBar::handleDownEvent(SCallbackInfo& info, std::optional<ITouch::SDownE
if (!VECINRECT(COORDS, 0, 0, assignedBoxGlobal().w, **PHEIGHT - 1)) {

if (m_bDraggingThis) {
if (m_bTouchEv) {
ITouch::SDownEvent e = touchEvent.value();
g_pCompositor->warpCursorTo(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());
}
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions hyprbars/barDeco.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down