Retry only for https protocol
[elinks.git] / src / viewer / timer.c
blobb7f67215cc691ab557582dc17e0527ded3511a53
1 /* Internal inactivity timer. */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include "elinks.h"
9 #include "config/kbdbind.h"
10 #include "config/options.h"
11 #include "intl/gettext/libintl.h"
12 #include "main/module.h"
13 #include "main/timer.h"
14 #include "terminal/event.h"
15 #include "terminal/kbd.h"
16 #include "terminal/terminal.h"
17 #include "util/time.h"
18 #include "viewer/timer.h"
20 #define COUNT_DOWN_DELAY ((milliseconds_T) 1000)
22 static timer_id_T countdown = TIMER_ID_UNDEF;
24 static int timer_duration = 0;
26 int
27 get_timer_duration(void)
29 return timer_duration;
32 /* Timer callback for @countdown. As explained in @install_timer,
33 * this function must erase the expired timer ID from all variables. */
34 static void
35 count_down(void *xxx)
37 struct keybinding *keybinding;
39 timer_duration--;
40 if (timer_duration) {
41 install_timer(&countdown, COUNT_DOWN_DELAY, count_down, NULL);
42 return;
43 } else {
44 countdown = TIMER_ID_UNDEF;
46 /* The expired timer ID has now been erased. */
48 keybinding = kbd_nm_lookup(KEYMAP_MAIN,
49 get_opt_str("ui.timer.action", NULL));
50 if (keybinding) {
51 struct terminal *terminal;
52 struct term_event ev;
54 set_kbd_term_event(&ev, keybinding->kbd.key,
55 keybinding->kbd.modifier);
57 foreach (terminal, terminals) {
58 term_send_event(terminal, &ev);
62 reset_timer();
65 void
66 reset_timer(void)
68 kill_timer(&countdown);
70 if (!get_opt_int("ui.timer.enable", NULL)) return;
72 timer_duration = get_opt_int("ui.timer.duration", NULL);
73 install_timer(&countdown, COUNT_DOWN_DELAY, count_down, NULL);
76 static void
77 init_timer(struct module *module)
79 reset_timer();
82 static void
83 done_timer(struct module *module)
85 kill_timer(&countdown);
88 struct module timer_module = struct_module(
89 /* name: */ N_("Timer"),
90 /* options: */ NULL,
91 /* hooks: */ NULL,
92 /* submodules: */ NULL,
93 /* data: */ NULL,
94 /* init: */ init_timer,
95 /* done: */ done_timer