1111#include < hyprland/src/devices/ITouch.hpp>
1212#include < hyprland/src/managers/KeybindManager.hpp>
1313#include < hyprland/src/managers/LayoutManager.hpp>
14+ #include < hyprland/src/managers/SeatManager.hpp>
1415#include < hyprland/src/managers/input/InputManager.hpp>
16+ #include < hyprland/src/protocols/core/Compositor.hpp>
17+ #include < hyprland/src/protocols/core/Seat.hpp>
1518#undef private
1619
1720#include < algorithm>
@@ -267,23 +270,12 @@ void GestureManager::sendCancelEventsToWindows() {
267270 return ;
268271 }
269272
270- for (const auto & surface : this ->touchedSurfaces ) {
271- if (!surface)
272- continue ;
273-
274- // Retrieve the client from the surface
275- // wl_client* client = wl_resource_get_client(surface->resource);
276- // if (!client)
277- // continue;
278-
279- // FIXME: couldn't find replacement for g_pCompositor->m_sSeat
280- // wlr_seat_client* seat_client = wlr_seat_client_for_wl_client(g_pCompositor->m_sSeat.seat, client);
281- //
282- // if (seat_client) {
283- // wlr_seat_touch_notify_cancel(g_pCompositor->m_sSeat.seat, seat_client);
284- // }
273+ for (const auto & touch : this ->touchedResources .all ()) {
274+ const auto t = touch.lock ();
275+ if (t.impl_ ) { // FIXME: idk how to check weak pointer validity
276+ t->sendCancel ();
277+ }
285278 }
286- this ->touchedSurfaces .clear ();
287279}
288280
289281// @return whether or not to inhibit further actions
@@ -295,23 +287,43 @@ bool GestureManager::onTouchDown(ITouch::SDownEvent ev) {
295287 // if (g_pCompositor->m_sSeat.exclusiveClient) // lock screen, I think
296288 // return false;
297289
298- if (!eventForwardingInhibited () && **SEND_CANCEL && g_pInputManager->m_sTouchData .touchFocusSurface ) {
299- // remember which surfaces were touched, to later send cancel events
300- const auto surface = g_pInputManager->m_sTouchData .touchFocusSurface ;
301- const auto TOUCHED = std::find (touchedSurfaces.begin (), touchedSurfaces.end (), surface);
302- if (TOUCHED == touchedSurfaces.end ()) {
303- touchedSurfaces.push_back (surface);
304- }
305- }
306290 this ->m_pLastTouchedMonitor =
307291 g_pCompositor->getMonitorFromName (!ev.device ->boundOutput .empty () ? ev.device ->boundOutput : " " );
308292
309293 this ->m_pLastTouchedMonitor =
310294 this ->m_pLastTouchedMonitor ? this ->m_pLastTouchedMonitor : g_pCompositor->m_pLastMonitor .get ();
311295
312- const auto & position = m_pLastTouchedMonitor->vecPosition ;
313- const auto & geometry = m_pLastTouchedMonitor->vecSize ;
314- this ->m_sMonitorArea = {position.x , position.y , geometry.x , geometry.y };
296+ const auto & monitorPos = m_pLastTouchedMonitor->vecPosition ;
297+ const auto & monitorSize = m_pLastTouchedMonitor->vecSize ;
298+ this ->m_sMonitorArea = {monitorPos.x , monitorPos.y , monitorSize.x , monitorSize.y };
299+
300+ g_pCompositor->warpCursorTo ({
301+ monitorPos.x + ev.pos .x * monitorSize.x ,
302+ monitorPos.y + ev.pos .y * monitorSize.y ,
303+ });
304+
305+ g_pInputManager->refocus ();
306+
307+ if (!eventForwardingInhibited () && **SEND_CANCEL && g_pInputManager->m_sTouchData .touchFocusSurface ) {
308+ // remember which surfaces were touched, to later send cancel events
309+ const auto surface = g_pInputManager->m_sTouchData .touchFocusSurface ;
310+
311+ if (this ->m_sGestureState .fingers .size () == 0 ) {
312+ this ->touchedResources .clear ();
313+ }
314+
315+ wl_client* client = surface.get ()->client ();
316+ if (client) {
317+ SP<CWLSeatResource> seat = g_pSeatManager->seatResourceForClient (client);
318+
319+ if (seat) {
320+ auto touches = seat.get ()->touches ;
321+ for (const auto & touch : touches) {
322+ this ->touchedResources .insert (touch);
323+ }
324+ }
325+ }
326+ }
315327
316328 // NOTE @wlr_touch_down_event.x and y uses a number between 0 and 1 to
317329 // represent "how many percent of screen" whereas
@@ -352,6 +364,20 @@ bool GestureManager::onTouchUp(ITouch::SUpEvent ev) {
352364
353365 const auto BLOCK = IGestureManager::onTouchUp (gesture_event);
354366 if (**SEND_CANCEL) {
367+ const auto surface = g_pInputManager->m_sTouchData .touchFocusSurface ;
368+
369+ wl_client* client = surface.get ()->client ();
370+ if (client) {
371+ SP<CWLSeatResource> seat = g_pSeatManager->seatResourceForClient (client);
372+
373+ if (seat) {
374+ auto touches = seat.get ()->touches ;
375+ for (const auto & touch : touches) {
376+ this ->touchedResources .remove (touch);
377+ }
378+ }
379+ }
380+
355381 return BLOCK;
356382 } else {
357383 // send_cancel is turned off; we need to rely on touchup events
0 commit comments