From d10d9c2e9c2c381dfde29740ef21c52524c944e2 Mon Sep 17 00:00:00 2001 From: ObaraEmmanuel Date: Fri, 8 Nov 2024 01:06:43 +0300 Subject: [PATCH] [STUDIO] Bypass scroll frame rate limiting for longer intervals (#49) --- hoverset/ui/widgets.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hoverset/ui/widgets.py b/hoverset/ui/widgets.py index 66e4965..b728a41 100644 --- a/hoverset/ui/widgets.py +++ b/hoverset/ui/widgets.py @@ -12,6 +12,7 @@ import functools import logging import os +import time import tkinter as tk import tkinter.ttk as ttk import webbrowser @@ -1253,6 +1254,7 @@ def __init__(self, master=None, **cnf): # self.after(200, self.on_configure) self._limit_var = [0, 0] # limit var for x and y self._max_frame_skip = 3 + self._last_render = time.perf_counter_ns() self.fill_x = True # Set to True to disable the x scrollbar and fit content to width self.fill_y = False # Set to True to disable the y scrollbar and fit content to height self._prev_region = (0, 0, 0, 0) @@ -1284,7 +1286,13 @@ def config_all(self, **cnf): def _limiter(self, callback, axis, *args): # Frame limiting reduces lags while scrolling by skipping a number of scroll events to reduce the burden # of performing expensive redrawing by tkinter - if self._limit_var[axis] == self._max_frame_skip: + render_time = time.perf_counter_ns() + render_diff = render_time - self._last_render + self._last_render = render_time + + # Max human click rate is about 15 CPS = 70ms/click + # Always render if it's been longer than 70ms since last render + if self._limit_var[axis] == self._max_frame_skip or render_diff > 7e7: callback(*args) self._limit_var[axis] = 0 else: