stasmarkin / sm_td

SM Tap Dance user library for QMK
GNU General Public License v3.0
152 stars 5 forks source link

Compatibility with Layer Lock #21

Open iovis opened 1 month ago

iovis commented 1 month ago

Hi! I was wondering if you'd know how I'd make sm_td work with layer lock.

I'm guessing I should add the appropriate range from sm_td here:

  switch (keycode) {
    case QK_MOMENTARY ... QK_MOMENTARY_MAX:  // `MO(layer)` keys.
      return handle_mo_or_tt(QK_MOMENTARY_GET_LAYER(keycode), record);

    case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:  // `TT(layer)`.
      return handle_mo_or_tt(QK_LAYER_TAP_TOGGLE_GET_LAYER(keycode), record);

    case QK_LAYER_MOD ... QK_LAYER_MOD_MAX: {  // `LM(layer, mod)`.
      uint8_t layer = QK_LAYER_MOD_GET_LAYER(keycode);
      if (is_layer_locked(layer)) {
        if (record->event.pressed) {  // On press, unlock the layer.
          layer_lock_invert(layer);
        } else {  // On release, clear the mods.
          clear_mods();
          send_keyboard_report();
        }
        return false;  // Skip default handling.
      }
    } break;

#ifndef NO_ACTION_TAPPING
    case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:  // `LT(layer, key)` keys.
      if (record->tap.count == 0 && !record->event.pressed &&
          is_layer_locked(QK_LAYER_TAP_GET_LAYER(keycode))) {
        // Release event on a held layer-tap key where the layer is locked.
        return false;  // Skip default handling so that layer stays on.
      }
      break;
#endif  // NO_ACTION_TAPPING
  }

But I'm not sure what range would that be. I tried using SMTD_KEYCODES_BEGIN ... SMTD_KEYCODES_END but it didn't work, I'm guessing I need some kind of modifier keycode?

Thank you!

iovis commented 1 month ago

For context, I'm using SMTD_LT(NV_SLSH, KC_SLSH, _NV), you can see my current layout here

stasmarkin commented 1 month ago

Unfortunately there is no easy way to make layer_lock work with sm_td. I use a custom layer switching mechanism for the SMTD_LT macro because the default from QMK doesn't work well with sm_td. So all custom functions with layer switching won't work here.

stasmarkin commented 1 month ago

I've added this to the backlog, I'll probably be able to figure something out.

iovis commented 1 month ago

Thank you!