Repository navigation
[0.4.x] lv-tool: Debounce resize requests (fixes #161) #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,10 +128,21 @@ namespace LV { | |
| return Time(SDL_GetTicks()); | ||
| } | ||
|
|
||
| Time operator-(Time & other) const { | ||
| return Time(this->m_moment - other.m_moment); | ||
| friend Time operator-(Time const& lhs, Time const& rhs) { | ||
| return Time(lhs.m_moment - rhs.m_moment); | ||
| } | ||
|
|
||
| friend bool operator>=(Time const& lhs, Time const& rhs) { | ||
| return lhs.m_moment >= rhs.m_moment; | ||
| } | ||
|
|
||
| //! Converts the time to seconds | ||
| double to_secs() const | ||
| { | ||
| return this->m_moment / 1000.0; | ||
| } | ||
|
|
||
| //! Converts the time to microseconds | ||
| uint64_t to_usecs() const { | ||
| return this->m_moment * 1000; | ||
| }; | ||
|
|
@@ -455,6 +466,39 @@ namespace { | |
| } | ||
| }; | ||
|
|
||
| class ResizeRequest | ||
| { | ||
| unsigned int m_width; | ||
| unsigned int m_height; | ||
| LV::Time m_received_at; | ||
| LV::Time m_applied_at; | ||
|
|
||
| public: | ||
| ResizeRequest() : m_width(0), m_height(0) { | ||
| } | ||
|
|
||
| unsigned int width() const { return m_width; } | ||
| unsigned int 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to backport
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kaixiong good idea, done |
||
| } | ||
|
|
||
| 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(); | ||
| } | ||
| }; | ||
|
|
||
| /** print info about libvisual plugin */ | ||
| void print_plugin_info(VisPluginInfo const& info) | ||
| { | ||
|
|
@@ -856,6 +900,7 @@ int main (int argc, char **argv) | |
|
|
||
| // main loop | ||
| bool running = true; | ||
| ResizeRequest resize_request; | ||
| //bool visible = true; | ||
|
|
||
| while (running) | ||
|
|
@@ -925,17 +970,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; | ||
| } | ||
|
|
||
|
|
@@ -1017,6 +1052,21 @@ int main (int argc, char **argv) | |
| } | ||
| } | ||
|
|
||
| if (resize_request.is_due ()) { | ||
| DisplayLock lock {display}; | ||
|
|
||
| width = resize_request.width(); | ||
| height = resize_request.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}; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason to implement the subtraction operator as a member function? The implementation in master uses a free function, following the practice of the C++ standard library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaixiong no particular reason, changed now as suggested.