diff --git a/data/keyd-application-mapper.1.gz b/data/keyd-application-mapper.1.gz index 3cc0207..5b3fdb7 100644 Binary files a/data/keyd-application-mapper.1.gz and b/data/keyd-application-mapper.1.gz differ diff --git a/data/keyd.1.gz b/data/keyd.1.gz index 37f5e33..fc00b4c 100644 Binary files a/data/keyd.1.gz and b/data/keyd.1.gz differ diff --git a/docs/keyd.scdoc b/docs/keyd.scdoc index 5e43840..e3cb824 100644 --- a/docs/keyd.scdoc +++ b/docs/keyd.scdoc @@ -543,7 +543,10 @@ any of the following options: *chord_hold_timeout:* The length of time a chord must be held before being activated. (default: 0) + (default: 0) + *oneshot_timeout:* If non-zero, timeout a oneshot layer + activation after the supplied number of milliseconds. (default: 0) *Note:* Unicode characters and key sequences are treated as macros, and diff --git a/src/config.c b/src/config.c index 821894a..3904f69 100644 --- a/src/config.c +++ b/src/config.c @@ -419,10 +419,10 @@ static void config_init(struct config *config) /* In ms */ config->chord_interkey_timeout = 50; config->chord_hold_timeout = 0; + config->oneshot_timeout = 0; config->macro_timeout = 600; config->macro_repeat_timeout = 50; - } /* Modifies the input string */ @@ -730,6 +730,8 @@ static void parse_global_section(struct config *config, struct ini_section *sect config->macro_timeout = atoi(ent->val); else if (!strcmp(ent->key, "macro_sequence_timeout")) config->macro_sequence_timeout = atoi(ent->val); + else if (!strcmp(ent->key, "oneshot_timeout")) + config->oneshot_timeout = atoi(ent->val); else if (!strcmp(ent->key, "chord_hold_timeout")) config->chord_hold_timeout = atoi(ent->val); else if (!strcmp(ent->key, "chord_timeout")) diff --git a/src/config.h b/src/config.h index 79c6a82..8be0153 100644 --- a/src/config.h +++ b/src/config.h @@ -130,6 +130,7 @@ struct config { long macro_timeout; long macro_sequence_timeout; long macro_repeat_timeout; + long oneshot_timeout; long chord_interkey_timeout; long chord_hold_timeout; diff --git a/src/keyboard.c b/src/keyboard.c index 1a8c498..9faecb1 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -404,6 +404,7 @@ static void clear_oneshot(struct keyboard *kbd) } kbd->oneshot_latch = 0; + kbd->oneshot_timeout = 0; } static void clear(struct keyboard *kbd) @@ -605,6 +606,10 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, } else { if (kbd->oneshot_latch) { kbd->layer_state[idx].oneshot = 1; + if (kbd->config.oneshot_timeout) { + kbd->oneshot_timeout = time + kbd->config.oneshot_timeout; + schedule_timeout(kbd, kbd->oneshot_timeout); + } } else { deactivate_layer(kbd, idx); update_mods(kbd, -1, 0); @@ -1039,6 +1044,11 @@ static long process_event(struct keyboard *kbd, uint8_t code, int pressed, long if (handle_pending_key(kbd, code, pressed, time)) goto exit; + if (kbd->oneshot_timeout && time >= kbd->oneshot_timeout) { + clear_oneshot(kbd); + update_mods(kbd, -1, 0); + } + if (kbd->active_macro) { if (code) { kbd->active_macro = NULL; diff --git a/src/keyboard.h b/src/keyboard.h index 934b216..127af34 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -49,6 +49,7 @@ struct keyboard { struct macro *active_macro; int active_macro_layer; long macro_timeout; + long oneshot_timeout; long macro_repeat_interval;