qmk / qmk_firmware

Open-source keyboard firmware for Atmel AVR and Arm USB families
https://qmk.fm
GNU General Public License v2.0
17.8k stars 38.15k forks source link

Using one key for momentary switching and toggling of layer #49

Closed majutsushi closed 8 years ago

majutsushi commented 8 years ago

For some layers it would be useful if you could switch them temporarily and also toggle them. Since it would make sense with the hold/toggle functionality to assign both of these to one key I tried to do this: LT(2, TG(2)). Unfortunately this doesn't work, in fact it makes the key do nothing at all. It would be great if this functionality could be supported.

MatrixManAtYrService commented 8 years ago

I also would like to do this. They're talking about it at post #420 here:

https://geekhack.org/index.php?topic=41989.400

I tried using

  ACTION_LAYER_TAP_TOGGLE(1) 

instead of

   LT(1, TG(1))

But again I think there's a bit more to do, based on what jack said here: https://www.reddit.com/r/olkb/comments/3iaita/layout_tips_and_tricks/cydcx21

MatrixManAtYrService commented 8 years ago

I got this working, for the most part. KC_FN# refers to the #th item in the fn_actions array, which calls tap toggle in the code below:

// ~/qmk_firmware/keyboard/ergodox_ez/keymaps/keymap_matrixman.c

// the defalut values are shown here, but changing them has no effect 
#define TAPPING_TERM 200 // tap toggle timeout (ms)
#define TAPPING_TOGGLE 5 // tap toggle count

#define SYMB 1 // symbol layer
#define NAV 2 // nav layer

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[BASE] = KEYMAP(  // layer 0 : default                                     

// some rows omitted                                                       

KC_FN1, KC_FN2, KC_RGUI, KC_MENU, KC_RCTRL,                                

// more rows omitted                                                       

const uint16_t PROGMEM fn_actions[] = {                                    
    [1] = ACTION_LAYER_TAP_TOGGLE(SYMB),    // FN1 - Tap/Toggle Layer 1 (Symbols)
    [2] = ACTION_LAYER_TAP_TOGGLE(NAV)      // FN2 - Tap/Toggle Layer 2 (Nav)
};  

I'm not wise in the ways of preprocessor voodoo, so I don't have a good idea of why my changes to TAPPING_TERM or TAPPING_TOGGLE don't stick. If you don't care about how this will affect the behavior of your other keymaps, you can change the values globally here:

../../tmk_core/common/action_tapping.h

dragon788 commented 8 years ago

@MatrixManAtYrService I think that they also include other files that define those same variables, so I'd look for all the places they are set and see if you can determine the inheritance order.

mecanogrh commented 8 years ago

Can't we have double tap for this? So hold=momentary, double tap=toggle and tap=you just got a free key!

jackhumbert commented 8 years ago

@majutsushi You'd have to make a custom macro for that, but it's possible! See #57 for a quick example of using the timers. You'd probably want a counter variable to detect which tap is happening.

fuzzbomb commented 8 years ago

I noticed that the default keymap for Ergodox-EZ already has this behaviour working for KC_FN1, since 2739aa8. I discovered it by accident while using the keyboard. The Egodoz-EZ doesn't actually document this; it says the bottom right key is a temporary toggle only.

It uses an approach like @MatrixManAtYrService suggested on 1 Jan, but without messing with timing.

See https://github.com/jackhumbert/qmk_firmware/blob/master/keyboard/ergodox_ez/keymaps/default/keymap.c

jackhumbert commented 8 years ago

Support for the chainability mentioned won't happen unfortunately - it'll need to be a custom function with process_record_user. Closing this for now.