Pastebin

Paste #24885: No description

< previous paste - next paste>

Pasted by Anonymous Coward

Download View as text

#include QMK_KEYBOARD_H
#include "version.h"
// #include "keymap_german.h"
// #include "keymap_nordic.h"
// #include "keymap_french.h"
// #include "keymap_spanish.h"
// #include "keymap_hungarian.h"
// #include "keymap_swedish.h"
// #include "keymap_br_abnt2.h"
// #include "keymap_canadian_multilingual.h"
// #include "keymap_german_ch.h"
// #include "keymap_jp.h"
// #include "keymap_korean.h"
// #include "keymap_bepo.h"
// #include "keymap_italian.h"
// #include "keymap_slovenian.h"
// #include "keymap_lithuanian_azerty.h"
#include "keymap_danish.h"
// #include "keymap_norwegian.h"
// #include "keymap_portuguese.h"
// #include "keymap_contributions.h"
// #include "keymap_czech.h"
// #include "keymap_romanian.h"
// #include "keymap_russian.h"
// #include "keymap_uk.h"
// #include "keymap_estonian.h"
// #include "keymap_belgian.h"
// #include "keymap_us_international.h"
// #include "keymap_croatian.h"
// #include "keymap_turkish_q.h"
// #include "keymap_slovak.h"

#define KC_MAC_UNDO LGUI(KC_Z)
#define KC_MAC_CUT LGUI(KC_X)
#define KC_MAC_COPY LGUI(KC_C)
#define KC_MAC_PASTE LGUI(KC_V)
#define KC_PC_UNDO LCTL(KC_Z)
#define KC_PC_CUT LCTL(KC_X)
#define KC_PC_COPY LCTL(KC_C)
#define KC_PC_PASTE LCTL(KC_V)
#define ES_LESS_MAC KC_GRAVE
#define ES_GRTR_MAC LSFT(KC_GRAVE)
#define ES_BSLS_MAC ALGR(KC_6)
#define NO_PIPE_ALT KC_GRAVE
#define NO_BSLS_ALT KC_EQUAL
#define LSA_T(kc) MT(MOD_LSFT | MOD_LALT, kc)
#define BP_NDSH_MAC ALGR(KC_8)
#define SE_SECT_MAC ALGR(KC_6)
#define MOON_LED_LEVEL LED_LEVEL

enum custom_keycodes {
  RGB_SLD = ML_SAFE_RANGE,
  HSV_0_255_255,
  HSV_86_255_128,
  HSV_172_255_255,
  DK_LSPO,
  DK_RSPC,
  CUSTOM_ALTGR1,    // Map AltGr+1 to |
  CUSTOM_SHIFT4,    // Map Shift+4 to '
  CUSTOM_SHIFTBKSP, // Map Shift+Backspace to ?
  CUSTOM_CTRLBKSP   // Map Ctrl+Backspace to Delete
};


enum tap_dance_codes {
  DANCE_0,
};

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  [0] = LAYOUT_moonlander(
    KC_ESCAPE,      CUSTOM_ALTGR1,  KC_2,           KC_3,           CUSTOM_SHIFT4,  KC_5,           DK_QUOT,                                        DK_PLUS,        KC_6,           KC_7,           KC_8,           KC_9,           KC_0,           CUSTOM_SHIFTBKSP,      
    KC_TAB,         KC_Q,           KC_W,           KC_E,           KC_R,           KC_T,           DK_LABK,                                        DK_ACUT,        KC_Y,           KC_U,           KC_I,           KC_O,           KC_P,           DK_ARNG,        
    LT(2,KC_LCTRL), KC_A,           KC_S,           KC_D,           KC_F,           KC_G,           KC_TRANSPARENT,                                                                 MT(MOD_RCTL, KC_INSERT),KC_H,           KC_J,           KC_K,           KC_L,           DK_AE,          DK_OSTR,        
    KC_LSHIFT,      KC_Z,           KC_X,           KC_C,           KC_V,           KC_B,                                           KC_N,           KC_M,           DK_COMM,        DK_DOT,         DK_MINS,        KC_RSHIFT,      
    MT(MOD_LCTL, DK_LABK),KC_LGUI,        KC_LEFT,        KC_RIGHT,       KC_LALT,        LT(1,KC_HOME),                                                                                                  LT(2,KC_END),   KC_RALT,        KC_UP,          KC_DOWN,        DK_DIAE,        KC_DELETE,      
    KC_ENTER,       TD(DANCE_0),    KC_LGUI,                        MT(MOD_LALT, KC_ENTER),KC_BSPACE,      KC_SPACE
  ),
  [1] = LAYOUT_moonlander(
    KC_ESCAPE,      KC_F1,          KC_F2,          KC_F3,          KC_F4,          KC_F5,          KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_F6,          KC_F7,          KC_F8,          KC_F9,          KC_F10,         KC_PSCREEN,     
    RGB_SAI,        KC_EXLM,        DK_AT,          DK_LCBR,        DK_RCBR,        KC_PIPE,        KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_UP,          KC_7,           KC_8,           KC_9,           KC_KP_ASTERISK, KC_F11,         
    KC_TRANSPARENT, KC_HASH,        KC_DLR,         DK_LPRN,        DK_RPRN,        DK_ACUT,        KC_TRANSPARENT,                                                                 TO(5),          KC_DOWN,        KC_4,           KC_5,           KC_6,           KC_KP_PLUS,     KC_F12,         
    RGB_SPI,        DK_PERC,        DK_CIRC,        DK_LBRC,        DK_RBRC,        KC_TILD,                                        KC_AMPR,        KC_1,           KC_2,           KC_3,           KC_KP_SLASH,    KC_TRANSPARENT, 
    RGB_SPD,        RGB_MOD,        HSV_0_255_255,  HSV_86_255_128, HSV_172_255_255,KC_TRANSPARENT,                                                                                                 KC_TRANSPARENT, DK_COMM,        KC_DOT,         KC_0,           DK_EQL,         KC_TRANSPARENT, 
    RGB_VAD,        RGB_VAI,        TOGGLE_LAYER_COLOR,                RGB_SLD,        RGB_HUD,        RGB_HUI
  ),
  [2] = LAYOUT_moonlander(
    AU_TOG,         KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_AUDIO_VOL_UP,KC_AUDIO_VOL_DOWN,KC_AUDIO_MUTE,  KC_MEDIA_PREV_TRACK,KC_MEDIA_PLAY_PAUSE,KC_MEDIA_NEXT_TRACK,RESET,          
    MU_TOG,         KC_MS_WH_UP,    KC_MS_UP,       KC_MS_WH_DOWN,  KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_MS_LEFT,     KC_MS_DOWN,     KC_MS_RIGHT,    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_PGUP,        KC_UP,          KC_PGDOWN,      KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_BTN2,     KC_MS_BTN1,     KC_TRANSPARENT,                                                                                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_LEFT,        KC_DOWN,        KC_RIGHT,       KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                 KC_HOME,        KC_END,         KC_TRANSPARENT
  ),
  [3] = LAYOUT_moonlander(
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, DK_QUOT,        KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                                                                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT
  ),
  [4] = LAYOUT_moonlander(
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                                                                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT
  ),
  [5] = LAYOUT_moonlander(
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_Q,           KC_W,           KC_F,           KC_P,           KC_G,           KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_J,           KC_L,           KC_I,           KC_Y,           DK_AE,          DK_ARNG,        
    KC_TRANSPARENT, KC_A,           KC_R,           KC_S,           KC_T,           KC_D,           KC_TRANSPARENT,                                                                 KC_TRANSPARENT, KC_H,           KC_N,           KC_E,           KC_I,           KC_O,           DK_OSTR,        
    KC_TRANSPARENT, KC_Z,           KC_X,           KC_C,           KC_V,           KC_B,                                           KC_K,           KC_M,           DK_COMM,        DK_DOT,         DK_MINS,        KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                                                                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT
  ),
};


extern rgb_config_t rgb_matrix_config;

void keyboard_post_init_user(void) {
  rgb_matrix_enable();
}


const uint8_t PROGMEM ledmap[][DRIVER_LED_TOTAL][3] = {
    [0] = { {0,255,255}, {0,0,255}, {0,0,255}, {177,255,179}, {177,255,179}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {177,255,179}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,0}, {27,247,255}, {27,247,255}, {0,0,255}, {0,0,255}, {41,255,255}, {0,0,255}, {128,111,255}, {177,255,179}, {41,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {41,255,255}, {41,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {41,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {41,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {177,255,179}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {178,255,168}, {0,0,255}, {0,0,255}, {178,255,168}, {0,0,255} },

    [1] = { {74,255,255}, {41,255,255}, {41,255,255}, {41,255,255}, {41,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {41,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {41,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {41,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {41,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {128,111,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {41,255,255}, {41,255,255}, {41,255,255}, {41,255,255}, {74,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {74,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {41,255,255}, {74,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {41,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255}, {74,255,255} },

    [2] = { {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {41,255,255}, {41,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {41,255,255}, {41,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {41,255,255}, {41,255,255}, {155,255,255}, {41,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {41,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {0,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {25,255,255}, {41,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {41,255,255}, {41,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {25,255,255}, {41,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255} },

    [5] = { {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255}, {218,163,255} },

};

void set_layer_color(int layer) {
  for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
    HSV hsv = {
      .h = pgm_read_byte(&ledmap[layer][i][0]),
      .s = pgm_read_byte(&ledmap[layer][i][1]),
      .v = pgm_read_byte(&ledmap[layer][i][2]),
    };
    if (!hsv.h && !hsv.s && !hsv.v) {
        rgb_matrix_set_color( i, 0, 0, 0 );
    } else {
        RGB rgb = hsv_to_rgb( hsv );
        float f = (float)rgb_matrix_config.hsv.v / UINT8_MAX;
        rgb_matrix_set_color( i, f * rgb.r, f * rgb.g, f * rgb.b );
    }
  }
}

void rgb_matrix_indicators_user(void) {
  if (keyboard_config.disable_layer_led) { return; }
  switch (biton32(layer_state)) {
    case 0:
      set_layer_color(0);
      break;
    case 1:
      set_layer_color(1);
      break;
    case 2:
      set_layer_color(2);
      break;
    case 5:
      set_layer_color(5);
      break;
   default:
    if (rgb_matrix_get_flags() == LED_FLAG_NONE)
      rgb_matrix_set_color_all(0, 0, 0);
    break;
  }
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  static uint8_t saved_mods = 0;
  switch (keycode) {

    case RGB_SLD:
      if (record->event.pressed) {
        rgblight_mode(1);
      }
      return false;
    case HSV_0_255_255:
      if (record->event.pressed) {
        rgblight_mode(1);
        rgblight_sethsv(0,255,255);
      }
      return false;
    case HSV_86_255_128:
      if (record->event.pressed) {
        rgblight_mode(1);
        rgblight_sethsv(86,255,128);
      }
      return false;
    case HSV_172_255_255:
      if (record->event.pressed) {
        rgblight_mode(1);
        rgblight_sethsv(172,255,255);
      }
      return false;
    case CUSTOM_ALTGR1:
      if (record->event.pressed) { 
        if ((get_mods() & MOD_BIT(KC_RALT)) == MOD_BIT(KC_RALT)) { 
          register_code16(DK_PIPE);
        }
        else { 
          register_code(DK_1);
        }
      } else { 
        unregister_code16(DK_PIPE);
        unregister_code(DK_1);
      }
      return false;
    case CUSTOM_SHIFT4:
      if (record->event.pressed) { 
        saved_mods = get_mods() & MOD_MASK_SHIFT;
        if ((get_mods() & MOD_MASK_SHIFT) == MOD_MASK_SHIFT) { 
          del_mods(saved_mods);
          register_code(KC_NUHS);
          add_mods(saved_mods);
        }
        else if (saved_mods) {
          del_mods(saved_mods);
          register_code(KC_NUHS);
          add_mods(saved_mods);
        }
        else { 
          register_code(DK_4);
        }
      } else { 
        unregister_code(KC_NUHS);
        unregister_code(DK_4);
      }
      return false;

    case CUSTOM_SHIFTBKSP:
      if (record->event.pressed) { 
        saved_mods = get_mods() & MOD_MASK_SHIFT;
        if ((saved_mods == MOD_MASK_SHIFT) || saved_mods ){ 
          register_code(DK_PLUS);
        }
        else { 
          register_code(KC_BSPACE);
        }
      } else { 
        unregister_code(DK_PLUS);
        unregister_code(KC_BSPACE);
      }
      return false;

    case CUSTOM_CTRLBKSP:
      if (record->event.pressed) { 
        saved_mods = get_mods() & MOD_BIT(KC_LCTRL);
        if ((get_mods() & MOD_BIT(KC_LCTRL)) == MOD_BIT(KC_LCTRL)) { 
          del_mods(saved_mods);
          register_code16(DK_PLUS);
          add_mods(saved_mods);
        }
        else if (saved_mods) {
          del_mods(saved_mods);
          register_code16(DK_PLUS);
          add_mods(saved_mods);
        }
        else { 
          register_code(KC_BSPACE);
        }
      } else { 
        register_code16(DK_PLUS);
        unregister_code(KC_BSPACE);
      }
      return false;
  }
  return true;
}

typedef struct {
    bool is_press_action;
    uint8_t step;
} tap;

enum {
    SINGLE_TAP = 1,
    SINGLE_HOLD,
    DOUBLE_TAP,
    DOUBLE_HOLD,
    DOUBLE_SINGLE_TAP,
    MORE_TAPS
};

static tap dance_state[1];

uint8_t dance_step(qk_tap_dance_state_t *state);

uint8_t dance_step(qk_tap_dance_state_t *state) {
    if (state->count == 1) {
        if (state->interrupted || !state->pressed) return SINGLE_TAP;
        else return SINGLE_HOLD;
    } else if (state->count == 2) {
        if (state->interrupted) return DOUBLE_SINGLE_TAP;
        else if (state->pressed) return DOUBLE_HOLD;
        else return DOUBLE_TAP;
    }
    return MORE_TAPS;
}


void on_dance_0(qk_tap_dance_state_t *state, void *user_data);
void dance_0_finished(qk_tap_dance_state_t *state, void *user_data);
void dance_0_reset(qk_tap_dance_state_t *state, void *user_data);

void on_dance_0(qk_tap_dance_state_t *state, void *user_data) {
    if(state->count == 3) {
        tap_code16(KC_BSPACE);
        tap_code16(KC_BSPACE);
        tap_code16(KC_BSPACE);
    }
    if(state->count > 3) {
        tap_code16(KC_BSPACE);
    }
}

void dance_0_finished(qk_tap_dance_state_t *state, void *user_data) {
    dance_state[0].step = dance_step(state);
    switch (dance_state[0].step) {
        case SINGLE_TAP: register_code16(KC_BSPACE); break;
        case DOUBLE_TAP: register_code16(KC_BSPACE); register_code16(KC_BSPACE); break;
        case DOUBLE_HOLD: register_code16(KC_SPACE); break;
        case DOUBLE_SINGLE_TAP: tap_code16(KC_BSPACE); register_code16(KC_BSPACE);
    }
}

void dance_0_reset(qk_tap_dance_state_t *state, void *user_data) {
    wait_ms(10);
    switch (dance_state[0].step) {
        case SINGLE_TAP: unregister_code16(KC_BSPACE); break;
        case DOUBLE_TAP: unregister_code16(KC_BSPACE); break;
        case DOUBLE_HOLD: unregister_code16(KC_SPACE); break;
        case DOUBLE_SINGLE_TAP: unregister_code16(KC_BSPACE); break;
    }
    dance_state[0].step = 0;
}

qk_tap_dance_action_t tap_dance_actions[] = {
        [DANCE_0] = ACTION_TAP_DANCE_FN_ADVANCED(on_dance_0, dance_0_finished, dance_0_reset),
};
/* vim: set sw=2 sts=2: */ 

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.