mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-08 13:44:54 +08:00
ui: timeout touch points (#36550)
This commit is contained in:
@@ -24,6 +24,7 @@ FPS_DROP_THRESHOLD = 0.9 # FPS drop threshold for triggering a warning
|
||||
FPS_CRITICAL_THRESHOLD = 0.5 # Critical threshold for triggering strict actions
|
||||
MOUSE_THREAD_RATE = 140 # touch controller runs at 140Hz
|
||||
MAX_TOUCH_SLOTS = 2
|
||||
TOUCH_HISTORY_TIMEOUT = 3.0 # Seconds before touch points fade out
|
||||
|
||||
ENABLE_VSYNC = os.getenv("ENABLE_VSYNC", "0") == "1"
|
||||
SHOW_FPS = os.getenv("SHOW_FPS") == "1"
|
||||
@@ -69,6 +70,12 @@ class MousePos(NamedTuple):
|
||||
y: float
|
||||
|
||||
|
||||
class MousePosWithTime(NamedTuple):
|
||||
x: float
|
||||
y: float
|
||||
t: float
|
||||
|
||||
|
||||
class MouseEvent(NamedTuple):
|
||||
pos: MousePos
|
||||
slot: int
|
||||
@@ -162,7 +169,7 @@ class GuiApplication:
|
||||
self._should_render = True
|
||||
|
||||
# Debug variables
|
||||
self._mouse_history: deque[MousePos] = deque(maxlen=MOUSE_THREAD_RATE)
|
||||
self._mouse_history: deque[MousePosWithTime] = deque(maxlen=MOUSE_THREAD_RATE)
|
||||
self._show_touches = SHOW_TOUCHES
|
||||
self._show_fps = SHOW_FPS
|
||||
|
||||
@@ -398,10 +405,16 @@ class GuiApplication:
|
||||
rl.draw_fps(10, 10)
|
||||
|
||||
if self._show_touches:
|
||||
current_time = time.monotonic()
|
||||
|
||||
for mouse_event in self._mouse_events:
|
||||
if mouse_event.left_pressed:
|
||||
self._mouse_history.clear()
|
||||
self._mouse_history.append(mouse_event.pos)
|
||||
self._mouse_history.append(MousePosWithTime(mouse_event.pos.x, mouse_event.pos.y, current_time))
|
||||
|
||||
# Remove old touch points that exceed the timeout
|
||||
while self._mouse_history and (current_time - self._mouse_history[0].t) > TOUCH_HISTORY_TIMEOUT:
|
||||
self._mouse_history.popleft()
|
||||
|
||||
if self._mouse_history:
|
||||
mouse_pos = self._mouse_history[-1]
|
||||
|
||||
Reference in New Issue
Block a user