2005-09-15 09:58:31 -04:00
|
|
|
/* Internal inactivity timer. */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "config/kbdbind.h"
|
|
|
|
#include "config/options.h"
|
2007-03-21 06:01:06 -04:00
|
|
|
#include "intl/gettext/libintl.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "main/module.h"
|
|
|
|
#include "main/timer.h"
|
|
|
|
#include "terminal/event.h"
|
|
|
|
#include "terminal/kbd.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/time.h"
|
|
|
|
#include "viewer/timer.h"
|
|
|
|
|
|
|
|
#define COUNT_DOWN_DELAY ((milliseconds_T) 1000)
|
|
|
|
|
|
|
|
static timer_id_T countdown = TIMER_ID_UNDEF;
|
|
|
|
|
|
|
|
static int timer_duration = 0;
|
|
|
|
|
|
|
|
int
|
|
|
|
get_timer_duration(void)
|
|
|
|
{
|
|
|
|
return timer_duration;
|
|
|
|
}
|
|
|
|
|
2006-12-02 11:35:03 -05:00
|
|
|
/* Timer callback for @countdown. As explained in @install_timer,
|
|
|
|
* this function must erase the expired timer ID from all variables. */
|
2005-09-15 09:58:31 -04:00
|
|
|
static void
|
|
|
|
count_down(void *xxx)
|
|
|
|
{
|
|
|
|
struct keybinding *keybinding;
|
|
|
|
|
|
|
|
timer_duration--;
|
|
|
|
if (timer_duration) {
|
|
|
|
install_timer(&countdown, COUNT_DOWN_DELAY, count_down, NULL);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
countdown = TIMER_ID_UNDEF;
|
|
|
|
}
|
2006-12-02 11:35:03 -05:00
|
|
|
/* The expired timer ID has now been erased. */
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
keybinding = kbd_nm_lookup(KEYMAP_MAIN,
|
|
|
|
get_opt_str("ui.timer.action", NULL));
|
2005-09-15 09:58:31 -04:00
|
|
|
if (keybinding) {
|
|
|
|
struct terminal *terminal;
|
|
|
|
struct term_event ev;
|
|
|
|
|
|
|
|
set_kbd_term_event(&ev, keybinding->kbd.key,
|
|
|
|
keybinding->kbd.modifier);
|
|
|
|
|
|
|
|
foreach (terminal, terminals) {
|
|
|
|
term_send_event(terminal, &ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reset_timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
reset_timer(void)
|
|
|
|
{
|
|
|
|
kill_timer(&countdown);
|
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
if (!get_opt_int("ui.timer.enable", NULL)) return;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
timer_duration = get_opt_int("ui.timer.duration", NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
install_timer(&countdown, COUNT_DOWN_DELAY, count_down, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_timer(struct module *module)
|
|
|
|
{
|
|
|
|
reset_timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
done_timer(struct module *module)
|
|
|
|
{
|
|
|
|
kill_timer(&countdown);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct module timer_module = struct_module(
|
2007-03-21 06:01:06 -04:00
|
|
|
/* name: */ N_("Timer"),
|
2005-09-15 09:58:31 -04:00
|
|
|
/* options: */ NULL,
|
|
|
|
/* hooks: */ NULL,
|
|
|
|
/* submodules: */ NULL,
|
|
|
|
/* data: */ NULL,
|
|
|
|
/* init: */ init_timer,
|
|
|
|
/* done: */ done_timer
|
|
|
|
);
|