From 6c7337f5fbd383e34b43170d5588a060b6b6dd12 Mon Sep 17 00:00:00 2001 From: auouymous Date: Sat, 17 Dec 2022 17:49:42 -0700 Subject: [PATCH] Process episode list selection changes every 250ms. A fast key repeat rate can cause on_episode_list_selection_changed to be called quicker than it can update the UI. This slows down shift-selections and results in continued processing long after the key has been released. The 250ms timer batches multiple events into a single update, and improves responsiveness on slower machines. --- src/gpodder/gtkui/main.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gpodder/gtkui/main.py b/src/gpodder/gtkui/main.py index 563f9f32..c0b07763 100644 --- a/src/gpodder/gtkui/main.py +++ b/src/gpodder/gtkui/main.py @@ -93,6 +93,8 @@ class gPodder(BuilderWidget, dbus.service.Object): self.last_episode_date_refresh = None self.refresh_episode_dates() + self.on_episode_list_selection_changed_id = None + def new(self): if self.application.want_headerbar: self.header_bar = Gtk.HeaderBar() @@ -1059,6 +1061,13 @@ class gPodder(BuilderWidget, dbus.service.Object): self._search_episodes.show_search(grab_focus=False) def on_episode_list_selection_changed(self, selection): + # Only update the UI every 250ms to prevent lag when rapidly changing selected episode or shift-selecting episodes + if self.on_episode_list_selection_changed_id is None: + self.on_episode_list_selection_changed_id = util.idle_timeout_add(250, self._on_episode_list_selection_changed) + + def _on_episode_list_selection_changed(self): + self.on_episode_list_selection_changed_id = None + # Update the toolbar buttons self.play_or_download() # and the shownotes