1 /* Internal inactivity timer. */
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;
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. */
37 struct keybinding
*keybinding
;
41 install_timer(&countdown
, COUNT_DOWN_DELAY
, count_down
, NULL
);
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
));
51 struct terminal
*terminal
;
54 set_kbd_term_event(&ev
, keybinding
->kbd
.key
,
55 keybinding
->kbd
.modifier
);
57 foreach (terminal
, terminals
) {
58 term_send_event(terminal
, &ev
);
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
);
77 init_timer(struct module
*module
)
83 done_timer(struct module
*module
)
85 kill_timer(&countdown
);
88 struct module timer_module
= struct_module(
89 /* name: */ N_("Timer"),
92 /* submodules: */ NULL
,
94 /* init: */ init_timer
,
95 /* done: */ done_timer