mirror of
https://github.com/rkd77/elinks.git
synced 2024-09-28 03:06:20 -04:00
Adjust LED update interval according to need
Add new routine compute_redraw_interval, which returns the appropriate interval in milliseconds for updating the LED panel, namely 100ms if there are any downloads, 1000 if the clock is enabled (with a TODO noted to check whether the date format includes seconds), or 0 otherwise to indicate that the LED paanel need not be updated Use the new compute_redraw_interval routine in draw_leds and redraw_leds. This fixes bug 973, "LED indicators wake system up every 100ms".
This commit is contained in:
parent
bbee237ff0
commit
3433c9d0f6
@ -31,8 +31,6 @@
|
||||
#include "util/time.h"
|
||||
#include "viewer/timer.h"
|
||||
|
||||
#define LEDS_REFRESH_DELAY ((milliseconds_T) 100)
|
||||
|
||||
/* Current leds allocation:
|
||||
* 0 - SSL connection indicator
|
||||
* 1 - Insert-mode indicator
|
||||
@ -187,6 +185,21 @@ draw_clock(struct terminal *term, int xpos, int ypos, struct color_pair *color)
|
||||
}
|
||||
#endif
|
||||
|
||||
static milliseconds_T
|
||||
compute_redraw_interval(void)
|
||||
{
|
||||
if (are_there_downloads())
|
||||
return 100;
|
||||
|
||||
/* TODO: Check whether the time format includes seconds. If not,
|
||||
* return milliseconds to next minute. */
|
||||
|
||||
if (get_leds_clock_enable())
|
||||
return 1000;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
draw_leds(struct session *ses)
|
||||
{
|
||||
@ -238,8 +251,12 @@ draw_leds(struct session *ses)
|
||||
|
||||
end:
|
||||
/* Redraw each 100ms. */
|
||||
if (!drawing && redraw_timer == TIMER_ID_UNDEF)
|
||||
install_timer(&redraw_timer, LEDS_REFRESH_DELAY, redraw_leds, NULL);
|
||||
if (!drawing && redraw_timer == TIMER_ID_UNDEF) {
|
||||
milliseconds_T delay = compute_redraw_interval();
|
||||
|
||||
if (delay)
|
||||
install_timer(&redraw_timer, delay, redraw_leds, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine if leds redrawing is necessary. Returns non-zero if so. */
|
||||
@ -302,15 +319,18 @@ static void
|
||||
redraw_leds(void *xxx)
|
||||
{
|
||||
struct terminal *term;
|
||||
milliseconds_T delay;
|
||||
|
||||
redraw_timer = TIMER_ID_UNDEF;
|
||||
|
||||
if (!get_leds_panel_enable()
|
||||
&& get_opt_int("ui.timer.enable", NULL) != 2) {
|
||||
redraw_timer = TIMER_ID_UNDEF;
|
||||
return;
|
||||
}
|
||||
|
||||
install_timer(&redraw_timer, LEDS_REFRESH_DELAY, redraw_leds, NULL);
|
||||
/* The expired timer ID has now been erased. */
|
||||
delay = compute_redraw_interval();
|
||||
if (delay)
|
||||
install_timer(&redraw_timer, delay, redraw_leds, NULL);
|
||||
|
||||
if (drawing) return;
|
||||
drawing = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user