@@ -105,6 +105,45 @@ namespace {
105105 }
106106 };
107107
108+ class ResizeRequest
109+ {
110+ public:
111+ ResizeRequest ()
112+ : m_width {0 }
113+ , m_height {0 }
114+ {}
115+
116+ unsigned int get_width () const { return m_width; }
117+ unsigned int get_height () const { return m_height; }
118+
119+ bool is_due () const
120+ {
121+ if (m_applied_at >= m_received_at) {
122+ return false ;
123+ }
124+ const double seconds_passed = (LV::Time::now () - m_received_at).to_secs ();
125+ return seconds_passed >= 0.2 ; // >=300ms is known to feel slow to humans
126+ }
127+
128+ void store (unsigned int width, unsigned int height)
129+ {
130+ m_width = width;
131+ m_height = height;
132+ m_received_at = LV::Time::now ();
133+ }
134+
135+ void mark_as_applied ()
136+ {
137+ m_applied_at = LV::Time::now ();
138+ }
139+
140+ private:
141+ unsigned int m_width;
142+ unsigned int m_height;
143+ LV::Time m_received_at;
144+ LV::Time m_applied_at;
145+ };
146+
108147 /* * print info about libvisual plugin */
109148 void print_plugin_info (VisPluginInfo const & info)
110149 {
@@ -543,6 +582,7 @@ int main (int argc, char **argv)
543582
544583 // main loop
545584 bool running = true ;
585+ ResizeRequest resize_request;
546586 // bool visible = true;
547587
548588 while (running)
@@ -611,17 +651,7 @@ int main (int argc, char **argv)
611651
612652 case VISUAL_EVENT_RESIZE:
613653 {
614- DisplayLock lock {display};
615-
616- width = ev.event .resize .width ;
617- height = ev.event .resize .height ;
618-
619- video = display.create (depth, vidoptions, width, height, true );
620- display.set_title (_ (" lv-tool" ));
621-
622- bin.set_video (video);
623- bin.sync (false );
624-
654+ resize_request.store (ev.event .resize .width , ev.event .resize .height );
625655 break ;
626656 }
627657
@@ -699,6 +729,21 @@ int main (int argc, char **argv)
699729 }
700730 }
701731
732+ if (resize_request.is_due ()) {
733+ DisplayLock lock {display};
734+
735+ width = resize_request.get_width ();
736+ height = resize_request.get_height ();
737+
738+ video = display.create (depth, vidoptions, width, height, true );
739+ display.set_title (_ (" lv-tool" ));
740+
741+ bin.set_video (video);
742+ bin.sync (false );
743+
744+ resize_request.mark_as_applied ();
745+ }
746+
702747 if (bin.depth_changed ())
703748 {
704749 DisplayLock lock {display};
0 commit comments