Skip to content

Commit

Permalink
DeferMods: send mods after timeout; drop FlashMods
Browse files Browse the repository at this point in the history
  • Loading branch information
sunaku committed Oct 28, 2022
1 parent dd3cb9d commit 2e0e480
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
12 changes: 7 additions & 5 deletions docs/tap_hold.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,18 @@ If `BILATERAL_COMBINATIONS` is defined to a value, hold times greater than that
#define BILATERAL_COMBINATIONS 500
```
To suppress "flashing mods" such as the GUI keys (which pop up the "Start Menu" in Microsoft Windows) during bilateral combinations, add the following to your `config.h`:
To delay the registration of modifiers (such as `KC_LGUI` and `KC_RGUI`, which are considered to be "flashing mods" because they suddenly "flash" or pop up the "Start Menu" in Microsoft Windows) during bilateral combinations:
1. Add the following line to your `config.h` and define a timeout value (measured in milliseconds). Hold times greater than this value will permit modifiers to be registered.
```c
#define BILATERAL_COMBINATIONS_FLASHMODS MOD_MASK_GUI
#define BILATERAL_COMBINATIONS_DEFERMODS 100
```

In addition, to also suppress the Alt keys (which pop up the "Ribbon Menu" in Microsoft Office) during bilateral combinations, specify a compound mask. For example:
2. Add the following line to your `rules.mk` file to enable QMK's deferred execution facility, which is needed by the `BILATERAL_COMBINATIONS_DEFERMODS` setting mentioned above.
```c
#define BILATERAL_COMBINATIONS_FLASHMODS (MOD_MASK_GUI|MOD_MASK_ALT)
```make
DEFERRED_EXEC_ENABLE = yes
```
To monitor activations in the background, enable debugging, enable the console, enable terminal bell, add `#define DEBUG_ACTION` to `config.h`, and use something like the following shell command line:
Expand Down
50 changes: 27 additions & 23 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ static struct {
# if (BILATERAL_COMBINATIONS + 0)
uint16_t time;
# endif
# if (BILATERAL_COMBINATIONS_DEFERMODS + 0)
deferred_token defermods;
# endif
} bilateral_combinations = { false };

static bool bilateral_combinations_left(keypos_t key) {
Expand All @@ -248,6 +251,15 @@ static bool bilateral_combinations_left(keypos_t key) {
# endif
}

# if (BILATERAL_COMBINATIONS_DEFERMODS + 0)
static uint32_t bilateral_combinations_defermods(uint32_t trigger_time, void *cb_arg) {
if (bilateral_combinations.active) {
register_mods(bilateral_combinations.mods);
}
return 0;
}
# endif

static void bilateral_combinations_hold(action_t action, keyevent_t event) {
dprint("BILATERAL_COMBINATIONS: hold\n");
bilateral_combinations.active = true;
Expand All @@ -258,20 +270,22 @@ static void bilateral_combinations_hold(action_t action, keyevent_t event) {
# if (BILATERAL_COMBINATIONS + 0)
bilateral_combinations.time = event.time;
# endif
# if (BILATERAL_COMBINATIONS_DEFERMODS + 0)
bilateral_combinations.defermods = defer_exec(BILATERAL_COMBINATIONS_DEFERMODS, bilateral_combinations_defermods, NULL);
# endif
}

static void bilateral_combinations_clear(void) {
bilateral_combinations.active = false;
# if (BILATERAL_COMBINATIONS_DEFERMODS + 0)
cancel_deferred_exec(bilateral_combinations.defermods);
# endif
}

static void bilateral_combinations_release(uint8_t code) {
dprint("BILATERAL_COMBINATIONS: release\n");
if (bilateral_combinations.active && (code == bilateral_combinations.code)) {
# ifdef BILATERAL_COMBINATIONS_FLASHMODS
if (bilateral_combinations.mods & BILATERAL_COMBINATIONS_FLASHMODS) {
// Send a single tap of the modifiers that we previously suppressed
// in process_action() before calling bilateral_combinations_hold().
register_mods(bilateral_combinations.mods);
unregister_mods(bilateral_combinations.mods);
}
# endif
bilateral_combinations.active = false;
bilateral_combinations_clear();
}
}

Expand All @@ -282,15 +296,15 @@ static void bilateral_combinations_tap(keyevent_t event) {
# if (BILATERAL_COMBINATIONS + 0)
if (TIMER_DIFF_16(event.time, bilateral_combinations.time) > BILATERAL_COMBINATIONS) {
dprint("BILATERAL_COMBINATIONS: timeout\n");
bilateral_combinations.active = false;
bilateral_combinations_clear();
return;
}
# endif
dprint("BILATERAL_COMBINATIONS: change\n");
unregister_mods(bilateral_combinations.mods);
tap_code(bilateral_combinations.tap);
}
bilateral_combinations.active = false;
bilateral_combinations_clear();
}
}
#endif
Expand Down Expand Up @@ -442,18 +456,8 @@ void process_action(keyrecord_t *record, action_t action) {
}
} else {
dprint("MODS_TAP: No tap: add_mods\n");
# ifdef BILATERAL_COMBINATIONS_FLASHMODS
if (mods & BILATERAL_COMBINATIONS_FLASHMODS) {
// Don't send these modifiers to computer yet!
// Instead, we'll just set them internally for
// bilateral_combinations_hold() to send later.
add_mods(mods);
}
else {
// Send these modifiers to the computer now so
// that mouse clicks with these modifiers work.
register_mods(mods);
}
# if defined(BILATERAL_COMBINATIONS) && (BILATERAL_COMBINATIONS_DEFERMODS + 0)
add_mods(mods);
# else
register_mods(mods);
# endif
Expand Down

0 comments on commit 2e0e480

Please sign in to comment.