Pastebin

Paste #26266: No description

< previous paste - next paste>

Pasted by Anonymous Coward

Download View as text

#include QMK_KEYBOARD_H
#include "version.h"
#include "i18n.h"
#define MOON_LED_LEVEL LED_LEVEL
#define ML_SAFE_RANGE SAFE_RANGE

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_LEFT_CTRL),KC_A,           KC_S,           KC_D,           KC_F,           KC_G,           DK_DIAE,                                                                        MT(MOD_RCTL, KC_INSERT),KC_H,           KC_J,           KC_K,           KC_L,           DK_AE,          DK_OSTR,        
    KC_LEFT_SHIFT,  KC_Z,           KC_X,           KC_C,           KC_V,           KC_B,                                           KC_N,           KC_M,           DK_COMM,        DK_DOT,         DK_MINS,        KC_RIGHT_SHIFT, 
    MT(MOD_LCTL, DK_LABK),KC_LEFT_GUI,    KC_LEFT,        KC_RIGHT,       KC_LEFT_ALT,    LT(1,KC_HOME),                                                                                                  LT(2,KC_END),   MT(MOD_RALT, KC_LEFT),KC_DOWN,        KC_UP,          KC_RIGHT,       KC_DELETE,      
    KC_ENTER,       KC_SPACE,       TD(DANCE_0),                    MT(MOD_LALT, KC_ENTER),KC_BSPC,        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_PSCR,        
    KC_TRANSPARENT, 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,         
    KC_TRANSPARENT, DK_PERC,        DK_CIRC,        DK_LBRC,        DK_RBRC,        KC_TILD,                                        KC_AMPR,        KC_1,           KC_2,           KC_3,           KC_KP_SLASH,    KC_PAGE_UP,     
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_LEFT,                                                                                                        KC_TRANSPARENT, DK_COMM,        KC_DOT,         KC_0,           DK_EQL,         KC_PGDN,        
    RGB_VAD,        RGB_VAI,        KC_TRANSPARENT,                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT
  ),
  [2] = LAYOUT_moonlander(
    AU_TOGG,        TO(0),          TO(5),          KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, QK_BOOT,        
    MU_TOGG,        KC_MS_WH_UP,    KC_MS_UP,       KC_MS_WH_DOWN,  KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, DK_LCBR,        DK_RCBR,        KC_TRANSPARENT, QK_DYNAMIC_TAPPING_TERM_PRINT,
    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, QK_DYNAMIC_TAPPING_TERM_UP,
    KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_PAGE_UP,     KC_UP,          KC_PGDN,        QK_DYNAMIC_TAPPING_TERM_DOWN,
    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, DK_EXLM,        KC_TRANSPARENT, KC_TRANSPARENT, DK_CURR,        KC_TRANSPARENT, KC_TRANSPARENT,                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, DK_PIPE,        KC_TRANSPARENT, KC_TRANSPARENT, DK_DLR,         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,           MT(MOD_LSFT, KC_T),KC_D,           KC_TRANSPARENT,                                                                 KC_TRANSPARENT, KC_H,           MT(MOD_RSFT, 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
  ),
  [6] = 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_LEFT_CTRL,   KC_LEFT_ALT,    KC_LEFT_GUI,    KC_TRANSPARENT, KC_TRANSPARENT,                                                                                                 KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, 
    KC_TRANSPARENT, KC_TRANSPARENT, TO(0),                          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[][RGB_MATRIX_LED_COUNT][3] = {
    [0] = { {0,255,255}, {0,0,255}, {94,255,255}, {94,255,255}, {94,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {216,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {47,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {47,255,255}, {0,0,255}, {0,0,255}, {94,255,255}, {0,0,255}, {94,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {115,255,255}, {115,255,255}, {115,255,255}, {0,0,255}, {0,0,255}, {128,206,255}, {0,0,255}, {0,255,255}, {0,0,255}, {0,0,255}, {94,255,255}, {0,255,255}, {128,206,255}, {0,0,255}, {0,0,255}, {115,97,255}, {47,255,255}, {43,114,255}, {0,0,255}, {0,0,255}, {115,97,255}, {47,255,255}, {43,114,255}, {0,0,255}, {0,0,255}, {115,97,255}, {47,255,255}, {128,206,255}, {0,0,255}, {94,255,255}, {0,0,255}, {94,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {115,255,255}, {115,255,255}, {47,255,255}, {0,0,255}, {0,0,255}, {0,0,255}, {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}, {115,255,255}, {115,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}, {0,0,255}, {43,255,255}, {0,0,255}, {155,255,255}, {155,255,255}, {216,255,255}, {0,0,255}, {0,0,255}, {155,255,255}, {155,255,255}, {155,255,255}, {43,255,255}, {0,0,255}, {155,255,255}, {43,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {43,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}, {94,255,255}, {94,255,255}, {94,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {155,255,255}, {115,255,255}, {0,0,255}, {155,255,255}, {0,0,255}, {155,255,255}, {0,0,255}, {0,0,255}, {155,255,255}, {0,0,255}, {155,255,255}, {115,255,255}, {0,0,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} },

    [6] = { {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {177,118,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {177,118,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {177,118,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {177,118,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {0,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255}, {128,255,255} },

};

void set_layer_color(int layer) {
  for (int i = 0; i < RGB_MATRIX_LED_COUNT; 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 );   
    }
  }
}

bool rgb_matrix_indicators_user(void) {
  if (rawhid_state.rgb_control) {
      return false;
  }
  if (keyboard_config.disable_layer_led) { return false; }
  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;
    case 6:
      set_layer_color(6);
      break;
   default:
    if (rgb_matrix_get_flags() == LED_FLAG_NONE)
      rgb_matrix_set_color_all(0, 0, 0);
    break;
  }
  return true;
}

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

    case RGB_SLD:
        if (rawhid_state.rgb_control) {
            return false;
        }
        if (record->event.pressed) {
            rgblight_mode(1);
        }
        return false;
      /**********************/
      /* CUSTOM CODES BEGIN */
      /**********************/
    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_BSPC);
        }
      } else { 
        unregister_code(DK_PLUS);
        unregister_code(KC_BSPC);
      }
      return false;

    case CUSTOM_CTRLBKSP:
      if (record->event.pressed) { 
        saved_mods = get_mods() & MOD_BIT(KC_LEFT_CTRL);
        if ((get_mods() & MOD_BIT(KC_LEFT_CTRL)) == MOD_BIT(KC_LEFT_CTRL)) { 
          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_BSPC);
        }
      } else { 
        register_code16(DK_PLUS);
        unregister_code(KC_BSPC);
      }
      return false;
      /**********************/
      /* CUSTOM CODES END   */
      /**********************/
    }
  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(tap_dance_state_t *state);

uint8_t dance_step(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 dance_0_finished(tap_dance_state_t *state, void *user_data);
void dance_0_reset(tap_dance_state_t *state, void *user_data);

void dance_0_finished(tap_dance_state_t *state, void *user_data) {
    dance_state[0].step = dance_step(state);
    switch (dance_state[0].step) {
        case SINGLE_TAP: layer_move(6); break;
        case SINGLE_HOLD: register_code16(KC_LEFT_GUI); break;
        case DOUBLE_TAP: layer_move(6); break;
        case DOUBLE_SINGLE_TAP: layer_move(6); break;
    }
}

void dance_0_reset(tap_dance_state_t *state, void *user_data) {
    wait_ms(10);
    switch (dance_state[0].step) {
        case SINGLE_HOLD: unregister_code16(KC_LEFT_GUI); break;
    }
    dance_state[0].step = 0;
}

tap_dance_action_t tap_dance_actions[] = {
        [DANCE_0] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, 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.