SHARE
TWEET

Untitled

a guest Dec 9th, 2019 104 in 131 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "kb.h"
  2.  
  3. typedef struct {
  4.   bool is_press_action;
  5.   int state;
  6. } tap;
  7.  
  8. //Define a type for as many tap dance states as you need
  9. enum {
  10.   SINGLE_TAP = 1,
  11.   SINGLE_HOLD = 2
  12. };
  13.  
  14.  
  15. enum custom_keycodes {
  16.   CUST_ALTTAB = SAFE_RANGE,
  17. };
  18.  
  19. enum {
  20.   NONE = 0,     //Our custom tap dance key; add any other tap dance keys to this enum
  21.   QUOT_LAYR,
  22.   COMMA_TD,
  23.   ALTAB,
  24. };
  25.  
  26. //Declare the functions to be used with your tap dance key(s)
  27.  
  28. //Function associated with all tap dances
  29. int cur_dance (qk_tap_dance_state_t *state);
  30.  
  31. //Functions associated with individual tap dances
  32. void ql_finished (qk_tap_dance_state_t *state, void *user_data);
  33. void ql_reset (qk_tap_dance_state_t *state, void *user_data);
  34. void ql_altab (qk_tap_dance_state_t *state, void *user_data);
  35. void ql_resaltab (qk_tap_dance_state_t *state, void *user_data);
  36.  
  37. enum keyboard_layers {
  38.   _BASE = 0,        // Base Layer
  39.   _NAVC,    // Function Layer
  40.   _MOUS,
  41.   _GAME,
  42.   _INAC,
  43.   _NUMBP,
  44.   _EMPT
  45. };
  46.  
  47.  
  48. //
  49. // please beware that the signum3.1 has a non linear matrix. the middle two rows (6 and 5 downwards) are located at the
  50. // bottom (see _BASE layout for reference)
  51. // also, this layout is optimised for GERMAN(!) (NUBS for example)
  52. //
  53. // The right modifier key activates the mouse layer and the function keys on hold.
  54. //
  55. // The left modifier key has dual functionality. On tap the _NUMBP layer activates. A numbpad for the right hand.
  56. // Tap again to switch back to _BASE.
  57. // The second functionality uses hold. _NAVC activates. A navcluster for the right hand. Additionaly, the layers _GAME,
  58. // _INAC and _EMPT are activated via KC_9, KC_0 and KC_MINS. ESC via KC_GRAVE.
  59. // Also, pressing KC_3 mimics ALT+F4 and KC_TAB mimics ALT+TAB. ALT+TAB is done via tapdance; if TAB is pressed ALT and TAB
  60. // are registered subsequently. Then, TAB is unregistered while ALT stays on hold. ALT is deregistered on release of the left
  61. // modifier key. So, additionaly the arrow keys, jkli, can be used to navigate the ALT+TAB screen. The screen switches on
  62. // release of the modifier. The caveat of this ALT+TAB is, that it only works after the modifier TD has timed out. So,
  63. // it takes a bit longer than normal. (I have not yet found a sollution for this)
  64. //
  65. // The game layer _GAME moves most of the keys one row to the right. (wasd to esdf)
  66. // _INAC is a locked layer. Deactivate via KC_GRAVE.
  67. // _EMPT is a transparent layer with only one key. KC_MINS activated FLASH mode.
  68. // KC_GRAVE switches back to _BASE
  69. //
  70.  
  71. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  72.  
  73. [_BASE] = KEYMAP(
  74.         KC_GRAVE, KC_1, KC_2, KC_3, KC_4, KC_7, KC_8, KC_9, KC_0, KC_MINS,
  75.         KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_U, KC_I, KC_O, KC_P, KC_LBRC,
  76.         KC_LSFT, KC_A, KC_S, KC_D, KC_F, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  77.         KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_BSLS,
  78.       TD(QUOT_LAYR), KC_LGUI, KC_LALT, KC_LCTL, KC_BSPC, KC_ENT, KC_RALT, KC_RBRC, KC_APP, MO(_MOUS),
  79.         KC_LSFT, KC_B, KC_G, KC_T, KC_5, KC_6, KC_Y, KC_H, KC_N, KC_SPC),
  80.  
  81. [_NAVC] = KEYMAP(
  82.         KC_ESC, KC_NO, KC_NO, LALT(KC_F4), KC_NO, KC_NO, KC_NO, TO(_EMPT), TO(_INAC), TO(_GAME),
  83.         CUST_ALTTAB, KC_NO, KC_NO, KC_NO, KC_NO, KC_HOME, KC_UP, KC_END, KC_PGUP, KC_NO,
  84.         KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_LEFT, KC_DOWN, KC_RGHT, KC_PGDN, KC_NO,
  85.         KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_TRNS,
  86.         KC_NO, KC_NO, KC_LALT, KC_LCTL, KC_DEL, KC_ENT, KC_NO, KC_NO, KC_NO, KC_TRNS,
  87.         KC_LSFT, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_SPC),
  88.  
  89. [_MOUS] =   KEYMAP(
  90.         KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  91.         KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_MS_BTN1, KC_MS_UP, KC_MS_BTN2, KC_MS_WH_UP, KC_NO,
  92.         KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT, KC_MS_WH_DOWN, KC_NO,
  93.         KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_MS_WH_LEFT, KC_NO, KC_NO, KC_MS_WH_RIGHT, KC_NO,
  94.         KC_TRNS, KC_NO, KC_NO, KC_LCTL, KC_DEL, KC_NO, KC_RALT, KC_NO, KC_NO, KC_NO,
  95.         KC_LSFT, KC_NO, KC_NO, KC_NO, KC_F6, KC_F7, KC_NO, KC_NO, KC_NO, KC_NO),
  96.  
  97. [_GAME] = KEYMAP(
  98.         TO(_BASE), KC_1, KC_1, KC_2, KC_3, KC_6, KC_7, KC_8, KC_9, KC_0,
  99.         KC_ESC, KC_TAB, KC_Q, KC_W, KC_E, KC_Y, KC_U, KC_I, KC_O, KC_P,
  100.         KC_NO, KC_LSFT, KC_A, KC_S, KC_D, KC_H, KC_J, KC_K, KC_L, KC_SCLN,
  101.         KC_NO, KC_Z, KC_Z, KC_X, KC_C, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH,
  102.         KC_LCTL, KC_NO, KC_LALT, KC_LCTL, KC_BSPC, KC_ENT, KC_RALT, KC_C, KC_D, KC_NO,
  103.         KC_SPC, KC_V, KC_F, KC_R, KC_4, KC_5, KC_T, KC_G, KC_B, KC_LSFT),
  104.  
  105. [_INAC] =   KEYMAP(
  106.         TO(_BASE), KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
  107.     KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
  108.     KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
  109.     KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
  110.     KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
  111.     KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO),
  112. // make kc_no for almost all of them, excl: enter,backspace,space,tab
  113. [_NUMBP] = KEYMAP(
  114.         TO(_BASE), KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, LSFT(KC_7), KC_NO,
  115.         KC_TAB, KC_NO, KC_NO, KC_NO, KC_NO, KC_7, KC_8, KC_9, LSFT(KC_RBRC), KC_NO,
  116.         KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_4, KC_5, KC_6, KC_RBRC, KC_NO,
  117.         KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_1, KC_2, KC_3, KC_SLSH, KC_NO,
  118.         TO(_BASE), KC_NO, KC_NO, KC_NO, KC_BSPC, KC_ENT, KC_0, TD(COMMA_TD), KC_NO, KC_NO,
  119.         KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_SPC),
  120.  
  121. [_EMPT] =   KEYMAP(
  122.         TO(_BASE), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RESET,
  123.         KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  124.         KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  125.         KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  126.         KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  127.         KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS),
  128.  
  129. };
  130.  
  131. void matrix_init_user(void) {
  132. }
  133.  
  134. void matrix_scan_user(void) {
  135. }
  136.  
  137. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  138.   switch (keycode) {
  139.     case CUST_ALTTAB:
  140.       if (record->event.pressed) {
  141.         register_code(KC_LALT);
  142.         register_code(KC_TAB);
  143.       } else {
  144.         unregister_code(KC_TAB);
  145.       }
  146.       break;
  147.   }
  148.     return true;
  149. }
  150.  
  151. void led_set_user(uint8_t usb_led) {
  152.  
  153.     if (usb_led & (1 << USB_LED_NUM_LOCK)) {
  154.        
  155.     } else {
  156.        
  157.     }
  158.  
  159.     if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
  160.        
  161.     } else {
  162.        
  163.     }
  164.  
  165.     if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
  166.         DDRB |= (1 << 6); PORTB &= ~(1 << 6);
  167.     } else {
  168.         DDRB &= ~(1 << 6); PORTB &= ~(1 << 6);
  169.     }
  170.  
  171.     if (usb_led & (1 << USB_LED_COMPOSE)) {
  172.        
  173.     } else {
  174.        
  175.     }
  176.  
  177.     if (usb_led & (1 << USB_LED_KANA)) {
  178.        
  179.     } else {
  180.        
  181.     }
  182.  
  183. }
  184.  
  185. //Determine the current tap dance state
  186. int cur_dance (qk_tap_dance_state_t *state) {
  187.   if (state->count == 1) {
  188.     if (!state->pressed) {
  189.       return SINGLE_TAP;
  190.     } else {
  191.       return SINGLE_HOLD;
  192.     }
  193.   }
  194.   else return 8;
  195. }
  196.  
  197. //int cur_dance (qk_tap_dance_state_t *state) {  // from discord; has a strange behaviour; hold below timer acts as tap, above as normal
  198. //  if (state->count == 1) {
  199. //    if (state->interrupted || !state->pressed)  return SINGLE_TAP;
  200. //    //key has not been interrupted, but they key is still held. Means you want to send a 'HOLD'.
  201. //    else return SINGLE_HOLD;
  202. //  }
  203. //  else return 8;
  204. //};
  205.  
  206. //Initialize tap structure associated with example tap dance key
  207. static tap ql_tap_state = {
  208.   .is_press_action = true,
  209.   .state = 0
  210. };
  211.  
  212. //Functions that control what our tap dance key does
  213. void ql_finished (qk_tap_dance_state_t *state, void *user_data) {
  214.   ql_tap_state.state = cur_dance(state);
  215.   switch (ql_tap_state.state) {
  216.     case SINGLE_TAP:
  217.       if (!layer_state_is(_NUMBP)) {layer_on(_NUMBP);} //
  218.       break;
  219.     case SINGLE_HOLD:
  220.       if (!layer_state_is(_NAVC)) {layer_on(_NAVC);} //
  221.       break;
  222.   }
  223. }
  224.  
  225. void ql_reset (qk_tap_dance_state_t *state, void *user_data) {
  226.   //if the key was held down and now is released then switch off the layer
  227.   if (ql_tap_state.state==SINGLE_HOLD) {
  228.     if(layer_state_is(_NAVC)) {layer_off(_NAVC);}
  229.     //break;
  230.   }
  231.   unregister_code(KC_LALT);        // for alt tab functionality ALTAB
  232.   ql_tap_state.state = 0;
  233. }
  234.  
  235. // hold alt, then hold tab
  236. //void ql_altab (qk_tap_dance_state_t *state, void *user_data) {
  237.   //if (ql_tap_state.state==SINGLE_HOLD) {
  238. //    register_code(KC_LALT);
  239. //    register_code(KC_TAB);
  240.   //}
  241. //}
  242.  
  243. // on release, unhold tab (while alt is still on hold, QUOT_LAYR is used for unregistering)
  244. //void ql_resaltab ( qk_tap_dance_state_t *state, void *user_data) {
  245. //  unregister_code(KC_TAB);
  246. //}
  247.  
  248. //Associate our tap dance key with its functionality
  249. qk_tap_dance_action_t tap_dance_actions[] = {
  250.   [QUOT_LAYR] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, ql_finished, ql_reset, 175),
  251.   [COMMA_TD] = ACTION_TAP_DANCE_DOUBLE(KC_DOT,KC_COMM),
  252. //  [ALTAB] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(ql_altab, NULL, ql_resaltab, 5),  // very small timer for rapid button pressing ability (alt tab)
  253. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top