Repository navigation
lv-tool: Debounce resize requests (fixes #161) #257
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
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. Opening brace for function bodies should be in a new line. |
||
| m_height = height; | ||
| m_received_at = LV::Time::now(); | ||
| } | ||
|
|
||
| void mark_as_applied() | ||
| { | ||
| m_applied_at = LV::Time::now(); | ||
|
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. Opening brace for function bodies should be in a new line. |
||
| } | ||
|
|
||
| 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}; | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Use uniform (brace) initialization and have each member variable on its own line: