Skip to content

Commit 25494c6

Browse files
committed
hyprbars: Don't react to touch events with mismatching touchID
so you can do things with your other fingers
1 parent 28dc18e commit 25494c6

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

hyprbars/barDeco.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CHyprBar::CHyprBar(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) {
2929
m_pTouchDownCallback = HyprlandAPI::registerCallbackDynamic(
3030
PHANDLE, "touchDown", [&](void* self, SCallbackInfo& info, std::any param) { onTouchDown(info, std::any_cast<ITouch::SDownEvent>(param)); });
3131
m_pTouchUpCallback = HyprlandAPI::registerCallbackDynamic( //
32-
PHANDLE, "touchUp", [&](void* self, SCallbackInfo& info, std::any param) { handleUpEvent(info); });
32+
PHANDLE, "touchUp", [&](void* self, SCallbackInfo& info, std::any param) { onTouchUp(info, std::any_cast<ITouch::SUpEvent>(param)); });
3333

3434
//move events
3535
m_pTouchMoveCallback = HyprlandAPI::registerCallbackDynamic(
@@ -126,27 +126,35 @@ void CHyprBar::onMouseButton(SCallbackInfo& info, IPointer::SButtonEvent e) {
126126
}
127127

128128
void CHyprBar::onTouchDown(SCallbackInfo& info, ITouch::SDownEvent e) {
129-
if (!inputIsValid())
129+
// Don't do anything if you're already grabbed a window with another finger
130+
if (!inputIsValid() || e.touchID != 0)
130131
return;
131132

132133
handleDownEvent(info, e);
133134
}
134135

136+
void CHyprBar::onTouchUp(SCallbackInfo& info, ITouch::SUpEvent e) {
137+
if (!m_bDragPending || !m_bTouchEv || e.touchID != m_touchId)
138+
return;
139+
140+
handleUpEvent(info);
141+
}
142+
135143
void CHyprBar::onMouseMove(Vector2D coords) {
136144
// ensure proper redraws of button icons on hover when using hardware cursors
137145
static auto* const PICONONHOVER = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:icon_on_hover")->getDataStaticPtr();
138146
if (**PICONONHOVER)
139147
damageOnButtonHover();
140148

141-
if (!m_bDragPending || m_bTouchEv || !validMapped(m_pWindow))
149+
if (!m_bDragPending || m_bTouchEv || !validMapped(m_pWindow) || m_touchId != 0)
142150
return;
143151

144152
m_bDragPending = false;
145153
handleMovement();
146154
}
147155

148156
void CHyprBar::onTouchMove(SCallbackInfo& info, ITouch::SMotionEvent e) {
149-
if (!m_bDragPending || !m_bTouchEv || !validMapped(m_pWindow))
157+
if (!m_bDragPending || !m_bTouchEv || !validMapped(m_pWindow) || e.touchID != m_touchId)
150158
return;
151159

152160
auto PMONITOR = m_pWindow->m_monitor.lock();
@@ -166,6 +174,8 @@ void CHyprBar::onTouchMove(SCallbackInfo& info, ITouch::SMotionEvent e) {
166174

167175
void CHyprBar::handleDownEvent(SCallbackInfo& info, std::optional<ITouch::SDownEvent> touchEvent) {
168176
m_bTouchEv = touchEvent.has_value();
177+
if (m_bTouchEv)
178+
m_touchId = touchEvent.value().touchID;
169179

170180
const auto PWINDOW = m_pWindow.lock();
171181

@@ -243,6 +253,7 @@ void CHyprBar::handleUpEvent(SCallbackInfo& info) {
243253

244254
m_bDragPending = false;
245255
m_bTouchEv = false;
256+
m_touchId = 0;
246257
}
247258

248259
void CHyprBar::handleMovement() {

hyprbars/barDeco.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class CHyprBar : public IHyprWindowDecoration {
8282
bool inputIsValid();
8383
void onMouseButton(SCallbackInfo& info, IPointer::SButtonEvent e);
8484
void onTouchDown(SCallbackInfo& info, ITouch::SDownEvent e);
85+
void onTouchUp(SCallbackInfo& info, ITouch::SUpEvent e);
8586
void onMouseMove(Vector2D coords);
8687
void onTouchMove(SCallbackInfo& info, ITouch::SMotionEvent e);
8788

@@ -105,6 +106,7 @@ class CHyprBar : public IHyprWindowDecoration {
105106
bool m_bTouchEv = false;
106107
bool m_bDragPending = false;
107108
bool m_bCancelledDown = false;
109+
int m_touchId = 0;
108110

109111
// store hover state for buttons as a bitfield
110112
unsigned int m_iButtonHoverState = 0;

0 commit comments

Comments
 (0)