window decorator: limit update rate to 50 fps

This commit is contained in:
Norman Feske 2015-06-04 16:32:11 +02:00 committed by Christian Helmuth
parent 69da1fa1ed
commit d7256c60a0
2 changed files with 28 additions and 3 deletions

View File

@ -82,6 +82,20 @@ struct Decorator::Main : Window_factory_base
Animator animator;
/**
* Process the update every 'frame_period' nitpicker sync signals. The
* 'frame_cnt' holds the counter of the nitpicker sync signals.
*
* A lower 'frame_period' value makes the decorations more responsive
* but it also puts more load on the system.
*
* If the nitpicker sync signal fires every 10 milliseconds, a
* 'frame_period' of 2 results in an update rate of 1000/20 = 50 frames per
* second.
*/
unsigned frame_cnt = 0;
unsigned frame_period = 2;
/**
* Install handler for responding to nitpicker sync events
*/
@ -184,6 +198,11 @@ void Decorator::Main::handle_window_layout_update(unsigned)
void Decorator::Main::handle_nitpicker_sync(unsigned)
{
if (frame_cnt++ < frame_period)
return;
frame_cnt = 0;
bool model_updated = false;
if (window_layout_update_needed && window_layout.is_valid()) {
@ -217,7 +236,13 @@ void Decorator::Main::handle_nitpicker_sync(unsigned)
bool const windows_animated = window_stack.schedule_animated_windows();
animator.animate();
/*
* To make the perceived animation speed independent from the setting of
* 'frame_period', we update the animation as often as the nitpicker
* sync signal occurs.
*/
for (unsigned i = 0; i < frame_period; i++)
animator.animate();
if (!model_updated && !windows_animated)
return;

View File

@ -97,10 +97,10 @@ class Decorator::Window : public Window_base
{
/* quick fade-in when gaining the focus or hover highlight */
if ((!_focused && focused) || (!_highlighted && highlighted))
return 20;
return 15;
/* slow fade-out when leaving focus or hover highlight */
return 180;
return 20;
}
bool _apply_state(bool focused, bool highlighted, Color base_color)