diff options
| author | tmk <nobody@nowhere> | 2013-04-05 03:28:10 +0900 | 
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-04-05 03:28:10 +0900 | 
| commit | a8c465215fce3dad502da868ca49eb446deadc4e (patch) | |
| tree | 9d74ea9c5062a53775ebe1d01b3067d89413e084 /common/action.c | |
| parent | 353a9b56e6caee853d3f808d2bfedf07056b4518 (diff) | |
| parent | fbea2a3aae5d66ecb00fcd3473f76337d34688fa (diff) | |
Merge branch 'action_refine'
Diffstat (limited to 'common/action.c')
| -rw-r--r-- | common/action.c | 378 | 
1 files changed, 68 insertions, 310 deletions
diff --git a/common/action.c b/common/action.c index 07a3a64d6c..0651887444 100644 --- a/common/action.c +++ b/common/action.c @@ -21,7 +21,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #include "command.h"  #include "debug.h"  #include "led.h" -#include "layer_switch.h" +#include "action_layer.h"  #include "action_tapping.h"  #include "action_oneshot.h"  #include "action_macro.h" @@ -50,15 +50,19 @@ void action_exec(keyevent_t event)  void process_action(keyrecord_t *record)  {      keyevent_t event = record->event; +#ifndef NO_ACTION_TAPPING      uint8_t tap_count = record->tap.count; +#endif      if (IS_NOEVENT(event)) { return; }      action_t action = layer_switch_get_action(event.key);      debug("ACTION: "); debug_action(action); -    debug(" overlays: "); overlay_debug(); -    debug(" keymaps: "); keymap_debug(); -    debug(" default_layer: "); debug_dec(default_layer); debug("\n"); +#ifndef NO_ACTION_LAYER +    debug(" layer_state: "); layer_debug(); +    debug(" default_layer_state: "); default_layer_debug(); +#endif +    debug("\n");      switch (action.kind.id) {          /* Key and Mods */ @@ -68,22 +72,17 @@ void process_action(keyrecord_t *record)                  uint8_t mods = (action.kind.id == ACT_LMODS) ?  action.key.mods :                                                                  action.key.mods<<4;                  if (event.pressed) { -                    uint8_t tmp_mods = host_get_mods();                      if (mods) {                          host_add_mods(mods);                          host_send_keyboard_report();                      }                      register_code(action.key.code); -                    if (mods && action.key.code) { -                        host_set_mods(tmp_mods); -                        host_send_keyboard_report(); -                    }                  } else { -                    if (mods && !action.key.code) { +                    unregister_code(action.key.code); +                    if (mods) {                          host_del_mods(mods);                          host_send_keyboard_report();                      } -                    unregister_code(action.key.code);                  }              }              break; @@ -93,7 +92,7 @@ void process_action(keyrecord_t *record)              {                  uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ?  action.key.mods :                                                                      action.key.mods<<4; -                switch (action.layer.code) { +                switch (action.layer_tap.code) {      #ifndef NO_ACTION_ONESHOT                      case 0x00:                          // Oneshot modifier @@ -199,323 +198,88 @@ void process_action(keyrecord_t *record)              }              break;  #endif -#ifndef NO_ACTION_KEYMAP -        case ACT_KEYMAP: -            switch (action.layer.code) { -                /* Keymap clear */ -                case OP_RESET: -                    switch (action.layer.val & 0x03) { -                        case 0: -                            // NOTE: reserved -                            overlay_clear(); -                            keymap_clear(); -                            break; -                        case ON_PRESS: -                            if (event.pressed) { -                                overlay_clear(); -                                keymap_clear(); -                            } -                            break; -                        case ON_RELEASE: -                            if (!event.pressed) { -                                overlay_clear(); -                                keymap_clear(); -                            } -                            break; -                        case ON_BOTH: -                            overlay_clear(); -                            keymap_clear(); -                            break; -                        /* NOTE: 4-7 rserved */ +#ifndef NO_ACTION_LAYER +        case ACT_LAYER: +            if (action.layer_bitop.on == 0) { +                /* Default Layer Bitwise Operation */ +                if (!event.pressed) { +                    uint8_t shift = action.layer_bitop.part*4; +                    uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift; +                    uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0; +                    switch (action.layer_bitop.op) { +                        case OP_BIT_AND: default_layer_and(bits | mask); break; +                        case OP_BIT_OR:  default_layer_or(bits | mask);  break; +                        case OP_BIT_XOR: default_layer_xor(bits | mask); break; +                        case OP_BIT_SET: default_layer_and(mask); default_layer_or(bits); break;                      } -                    break; -                /* Keymap Reset default layer */ -                case (OP_RESET | ON_PRESS): -                    if (event.pressed) { -                        default_layer_set(action.layer.val); -                    } -                    break; -                case (OP_RESET | ON_RELEASE): -                    if (!event.pressed) { -                        default_layer_set(action.layer.val); +                } +            } else { +                /* Layer Bitwise Operation */ +                if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : +                                    (action.layer_bitop.on & ON_RELEASE)) { +                    uint8_t shift = action.layer_bitop.part*4; +                    uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift; +                    uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0; +                    switch (action.layer_bitop.op) { +                        case OP_BIT_AND: layer_and(bits | mask); break; +                        case OP_BIT_OR:  layer_or(bits | mask);  break; +                        case OP_BIT_XOR: layer_xor(bits | mask); break; +                        case OP_BIT_SET: layer_and(mask); layer_or(bits); break;                      } -                    break; -                case (OP_RESET | ON_BOTH): -                    default_layer_set(action.layer.val); -                    break; - -                /* Keymap Bit invert */ -                case OP_INV: -                    /* with tap toggle */ +                } +            } +            break; +    #ifndef NO_ACTION_TAPPING +        case ACT_LAYER_TAP: +        case ACT_LAYER_TAP1: +            switch (action.layer_tap.code) { +                case OP_TAP_TOGGLE: +                    /* tap toggle */                      if (event.pressed) {                          if (tap_count < TAPPING_TOGGLE) { -                            debug("KEYMAP_INV: tap toggle(press).\n"); -                            keymap_invert(action.layer.val); +                            layer_invert(action.layer_tap.val);                          }                      } else {                          if (tap_count <= TAPPING_TOGGLE) { -                            debug("KEYMAP_INV: tap toggle(release).\n"); -                            keymap_invert(action.layer.val); +                            layer_invert(action.layer_tap.val);                          }                      }                      break; -                case (OP_INV | ON_PRESS): -                    if (event.pressed) { -                        keymap_invert(action.layer.val); -                    } -                    break; -                case (OP_INV | ON_RELEASE): -                    if (!event.pressed) { -                        keymap_invert(action.layer.val); -                    } +                case OP_ON_OFF: +                    event.pressed ? layer_on(action.layer_tap.val) : +                                    layer_off(action.layer_tap.val);                      break; -                case (OP_INV | ON_BOTH): -                    keymap_invert(action.layer.val); +                case OP_OFF_ON: +                    event.pressed ? layer_off(action.layer_tap.val) : +                                    layer_on(action.layer_tap.val);                      break; - -                /* Keymap Bit on */ -                case OP_ON: -                    if (event.pressed) { -                        keymap_on(action.layer.val); -                    } else { -                        keymap_off(action.layer.val); -                    } -                    break; -                case (OP_ON | ON_PRESS): -                    if (event.pressed) { -                        keymap_on(action.layer.val); -                    } -                    break; -                case (OP_ON | ON_RELEASE): -                    if (!event.pressed) { -                        keymap_on(action.layer.val); -                    } +                case OP_SET_CLEAR: +                    event.pressed ? layer_move(action.layer_tap.val) : +                                    layer_clear();                      break; -                case (OP_ON | ON_BOTH): -                    keymap_on(action.layer.val); -                    break; - -                /* Keymap Bit off */ -                case OP_OFF: -                    if (event.pressed) { -                        keymap_off(action.layer.val); -                    } else { -                        keymap_on(action.layer.val); -                    } -                    break; -                case (OP_OFF | ON_PRESS): -                    if (event.pressed) { -                        keymap_off(action.layer.val); -                    } -                    break; -                case (OP_OFF | ON_RELEASE): -                    if (!event.pressed) { -                        keymap_off(action.layer.val); -                    } -                    break; -                case (OP_OFF | ON_BOTH): -                    keymap_off(action.layer.val); -                    break; - -                /* Keymap Bit set */ -                case OP_SET: -                    if (event.pressed) { -                        keymap_set(action.layer.val); -                    } else { -                        keymap_clear(); -                    } -                    break; -                case (OP_SET | ON_PRESS): -                    if (event.pressed) { -                        keymap_set(action.layer.val); -                    } -                    break; -                case (OP_SET | ON_RELEASE): -                    if (!event.pressed) { -                        keymap_set(action.layer.val); -                    } -                    break; -                case (OP_SET | ON_BOTH): -                    keymap_set(action.layer.val); -                    break; - -                /* Keymap Bit invert with tap key */                  default: +                    /* tap key */                      if (event.pressed) {                          if (tap_count > 0) {                              debug("KEYMAP_TAP_KEY: Tap: register_code\n"); -                            register_code(action.layer.code); +                            register_code(action.layer_tap.code);                          } else {                              debug("KEYMAP_TAP_KEY: No tap: On on press\n"); -                            keymap_on(action.layer.val); +                            layer_on(action.layer_tap.val);                          }                      } else {                          if (tap_count > 0) {                              debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); -                            unregister_code(action.layer.code); +                            unregister_code(action.layer_tap.code);                          } else {                              debug("KEYMAP_TAP_KEY: No tap: Off on release\n"); -                            keymap_off(action.layer.val); -                        } -                    } -                    break; -            } -            break; -#endif -#ifndef NO_ACTION_OVERLAY -        case ACT_OVERLAY: -            switch (action.layer.code) { -                // Overlay Invert bit4 -                case OP_INV4 | 0: -                    if (action.layer.val == 0) { -                        // NOTE: reserved for future use -                        overlay_clear(); -                    } else { -                        overlay_set(overlay_stat ^ action.layer.val); -                    } -                    break; -                case OP_INV4 | 1: -                    if (action.layer.val == 0) { -                        // on pressed -                        if (event.pressed) overlay_clear(); -                    } else { -                        overlay_set(overlay_stat ^ action.layer.val<<4); -                    } -                    break; -                case OP_INV4 | 2: -                    if (action.layer.val == 0) { -                        // on released -                        if (!event.pressed) overlay_clear(); -                    } else { -                        overlay_set(overlay_stat ^ action.layer.val<<8); -                    } -                    break; -                case OP_INV4 | 3: -                    if (action.layer.val == 0) { -                        // on both -                        overlay_clear(); -                    } else { -                        overlay_set(overlay_stat ^ action.layer.val<<12); -                    } -                    break; - -                /* Overlay Bit invert */ -                case OP_INV: -                    /* with tap toggle */ -                    if (event.pressed) { -                        if (tap_count < TAPPING_TOGGLE) { -                            debug("OVERLAY_INV: tap toggle(press).\n"); -                            overlay_invert(action.layer.val); -                        } -                    } else { -                        if (tap_count <= TAPPING_TOGGLE) { -                            debug("OVERLAY_INV: tap toggle(release).\n"); -                            overlay_invert(action.layer.val); -                        } -                    } -                    break; -                case (OP_INV | ON_PRESS): -                    if (event.pressed) { -                        overlay_invert(action.layer.val); -                    } -                    break; -                case (OP_INV | ON_RELEASE): -                    if (!event.pressed) { -                        overlay_invert(action.layer.val); -                    } -                    break; -                case (OP_INV | ON_BOTH): -                    overlay_invert(action.layer.val); -                    break; - -                /* Overlay Bit on */ -                case OP_ON: -                    if (event.pressed) { -                        overlay_on(action.layer.val); -                    } else { -                        overlay_off(action.layer.val); -                    } -                    break; -                case (OP_ON | ON_PRESS): -                    if (event.pressed) { -                        overlay_on(action.layer.val); -                    } -                    break; -                case (OP_ON | ON_RELEASE): -                    if (!event.pressed) { -                        overlay_on(action.layer.val); -                    } -                    break; -                case (OP_ON | ON_BOTH): -                    overlay_on(action.layer.val); -                    break; - -                /* Overlay Bit off */ -                case OP_OFF: -                    if (event.pressed) { -                        overlay_off(action.layer.val); -                    } else { -                        overlay_on(action.layer.val); -                    } -                    break; -                case (OP_OFF | ON_PRESS): -                    if (event.pressed) { -                        overlay_off(action.layer.val); -                    } -                    break; -                case (OP_OFF | ON_RELEASE): -                    if (!event.pressed) { -                        overlay_off(action.layer.val); -                    } -                    break; -                case (OP_OFF | ON_BOTH): -                    overlay_off(action.layer.val); -                    break; - -                /* Overlay Bit set */ -                case OP_SET: -                    if (event.pressed) { -                        overlay_move(action.layer.val); -                    } else { -                        overlay_clear(); -                    } -                    break; -                case (OP_SET | ON_PRESS): -                    if (event.pressed) { -                        overlay_move(action.layer.val); -                    } -                    break; -                case (OP_SET | ON_RELEASE): -                    if (!event.pressed) { -                        overlay_move(action.layer.val); -                    } -                    break; -                case (OP_SET | ON_BOTH): -                    overlay_move(action.layer.val); -                    break; - -                /* Overlay Bit invert with tap key */ -                default: -                    if (event.pressed) { -                        if (tap_count > 0) { -                            debug("OVERLAY_TAP_KEY: Tap: register_code\n"); -                            register_code(action.layer.code); -                        } else { -                            debug("OVERLAY_TAP_KEY: No tap: On on press\n"); -                            overlay_on(action.layer.val); -                        } -                    } else { -                        if (tap_count > 0) { -                            debug("OVERLAY_TAP_KEY: Tap: unregister_code\n"); -                            unregister_code(action.layer.code); -                        } else { -                            debug("OVERLAY_TAP_KEY: No tap: Off on release\n"); -                            overlay_off(action.layer.val); +                            layer_off(action.layer_tap.val);                          }                      }                      break;              }              break; +    #endif  #endif          /* Extentions */  #ifndef NO_ACTION_MACRO @@ -667,16 +431,9 @@ bool is_tap_key(key_t key)      switch (action.kind.id) {          case ACT_LMODS_TAP:          case ACT_RMODS_TAP: +        case ACT_LAYER_TAP: +        case ACT_LAYER_TAP1:              return true; -        case ACT_KEYMAP: -        case ACT_OVERLAY: -            switch (action.layer.code) { -                case 0x04 ... 0xEF:    /* tap key */ -                case OP_INV: -                    return true; -                default: -                    return false; -            }          case ACT_MACRO:          case ACT_FUNCTION:              if (action.func.opt & FUNC_TAP) { return true; } @@ -714,8 +471,9 @@ void debug_action(action_t action)          case ACT_RMODS_TAP:         debug("ACT_RMODS_TAP");         break;          case ACT_USAGE:             debug("ACT_USAGE");             break;          case ACT_MOUSEKEY:          debug("ACT_MOUSEKEY");          break; -        case ACT_KEYMAP:            debug("ACT_KEYMAP");            break; -        case ACT_OVERLAY:           debug("ACT_OVERLAY");           break; +        case ACT_LAYER:             debug("ACT_LAYER");             break; +        case ACT_LAYER_TAP:         debug("ACT_LAYER_TAP");         break; +        case ACT_LAYER_TAP1:        debug("ACT_LAYER_TAP1");        break;          case ACT_MACRO:             debug("ACT_MACRO");             break;          case ACT_COMMAND:           debug("ACT_COMMAND");           break;          case ACT_FUNCTION:          debug("ACT_FUNCTION");          break;  | 
