From c445a20a67323f8f1d3b8002621afa7ed4529b58 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 4 Feb 2023 23:10:41 +0100 Subject: [PATCH 1/2] lv-tool: Debounce resize requests (cherry picked from commit 5ff4ad84059dbae42cac8269bb9e30033115a7fd) --- libvisual/tools/lv-tool/lv-tool.cpp | 67 ++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/libvisual/tools/lv-tool/lv-tool.cpp b/libvisual/tools/lv-tool/lv-tool.cpp index 9585d1cd0..bb731e6fc 100644 --- a/libvisual/tools/lv-tool/lv-tool.cpp +++ b/libvisual/tools/lv-tool/lv-tool.cpp @@ -105,6 +105,45 @@ namespace { } }; + class ResizeRequest + { + public: + ResizeRequest() + : m_width {0} + , m_height {0} + {} + + unsigned int get_width() const { return m_width; } + unsigned int get_height() const { return m_height; } + + bool is_due() const + { + if (m_applied_at >= m_received_at) { + return false; + } + const double seconds_passed = (LV::Time::now() - m_received_at).to_secs(); + return seconds_passed >= 0.2; // >=300ms is known to feel slow to humans + } + + void store(unsigned int width, unsigned int height) + { + m_width = width; + m_height = height; + m_received_at = LV::Time::now(); + } + + void mark_as_applied() + { + m_applied_at = LV::Time::now(); + } + + private: + unsigned int m_width; + unsigned int m_height; + LV::Time m_received_at; + LV::Time m_applied_at; + }; + /** print info about libvisual plugin */ void print_plugin_info(VisPluginInfo const& info) { @@ -543,6 +582,7 @@ int main (int argc, char **argv) // main loop bool running = true; + ResizeRequest resize_request; //bool visible = true; while (running) @@ -611,17 +651,7 @@ int main (int argc, char **argv) case VISUAL_EVENT_RESIZE: { - DisplayLock lock {display}; - - width = ev.event.resize.width; - height = ev.event.resize.height; - - video = display.create(depth, vidoptions, width, height, true); - display.set_title(_("lv-tool")); - - bin.set_video (video); - bin.sync(false); - + resize_request.store(ev.event.resize.width, ev.event.resize.height); break; } @@ -699,6 +729,21 @@ int main (int argc, char **argv) } } + if (resize_request.is_due ()) { + DisplayLock lock {display}; + + width = resize_request.get_width(); + height = resize_request.get_height(); + + video = display.create(depth, vidoptions, width, height, true); + display.set_title(_("lv-tool")); + + bin.set_video (video); + bin.sync(false); + + resize_request.mark_as_applied(); + } + if (bin.depth_changed()) { DisplayLock lock {display}; From 05ffce281cd9a37bb6c2c6af33541e0983203f7f Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sun, 5 Feb 2023 23:24:00 +0100 Subject: [PATCH 2/2] lv-tool: Stop calling create(..) twice per window resize (related to 0.4.x commit e8c6682b87ff8ad3570d81bf68e4e36c8c9e3013) --- libvisual/tools/lv-tool/display/sdl_driver.cpp | 2 -- libvisual/tools/lv-tool/display/stdout_sdl_driver.cpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/libvisual/tools/lv-tool/display/sdl_driver.cpp b/libvisual/tools/lv-tool/display/sdl_driver.cpp index 1cde3ee67..f8ce6e6b7 100644 --- a/libvisual/tools/lv-tool/display/sdl_driver.cpp +++ b/libvisual/tools/lv-tool/display/sdl_driver.cpp @@ -285,8 +285,6 @@ namespace { visual_event_queue_add (&eventqueue, visual_event_new_resize (event.resize.w, event.resize.h)); - - create (m_display.get_video ()->get_depth (), nullptr, event.resize.w, event.resize.h, m_resizable); break; case SDL_MOUSEMOTION: diff --git a/libvisual/tools/lv-tool/display/stdout_sdl_driver.cpp b/libvisual/tools/lv-tool/display/stdout_sdl_driver.cpp index 123f2135f..4d47bd731 100644 --- a/libvisual/tools/lv-tool/display/stdout_sdl_driver.cpp +++ b/libvisual/tools/lv-tool/display/stdout_sdl_driver.cpp @@ -330,8 +330,6 @@ namespace { visual_event_queue_add (&eventqueue, visual_event_new_resize (event.resize.w, event.resize.h)); - - create (m_display.get_video ()->get_depth (), nullptr, event.resize.w, event.resize.h, m_resizable); break; case SDL_MOUSEMOTION: