-
-
Notifications
You must be signed in to change notification settings - Fork 40.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2d095f
commit 287c8d1
Showing
10 changed files
with
245 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "process_chording.h" | ||
|
||
bool keys_chord(uint8_t keys[]) { | ||
uint8_t keys_size = sizeof(keys)/sizeof(keys[0]); | ||
bool pass = true; | ||
uint8_t in = 0; | ||
for (uint8_t i = 0; i < chord_key_count; i++) { | ||
bool found = false; | ||
for (uint8_t j = 0; j < keys_size; j++) { | ||
if (chord_keys[i] == (keys[j] & 0xFF)) { | ||
in++; // detects key in chord | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (found) | ||
continue; | ||
if (chord_keys[i] != 0) { | ||
pass = false; // makes sure rest are blank | ||
} | ||
} | ||
return (pass && (in == keys_size)); | ||
} | ||
|
||
bool process_chording(uint16_t keycode, keyrecord_t *record) { | ||
if (keycode >= QK_CHORDING && keycode <= QK_CHORDING_MAX) { | ||
if (record->event.pressed) { | ||
if (!chording) { | ||
chording = true; | ||
for (uint8_t i = 0; i < CHORDING_MAX; i++) | ||
chord_keys[i] = 0; | ||
chord_key_count = 0; | ||
chord_key_down = 0; | ||
} | ||
chord_keys[chord_key_count] = (keycode & 0xFF); | ||
chord_key_count++; | ||
chord_key_down++; | ||
return false; | ||
} else { | ||
if (chording) { | ||
chord_key_down--; | ||
if (chord_key_down == 0) { | ||
chording = false; | ||
// Chord Dictionary | ||
if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) { | ||
register_code(KC_A); | ||
unregister_code(KC_A); | ||
return false; | ||
} | ||
for (uint8_t i = 0; i < chord_key_count; i++) { | ||
register_code(chord_keys[i]); | ||
unregister_code(chord_keys[i]); | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef PROCESS_CHORDING_H | ||
#define PROCESS_CHORDING_H | ||
|
||
#include "quantum.h" | ||
|
||
// Chording stuff | ||
#define CHORDING_MAX 4 | ||
bool chording = false; | ||
|
||
uint8_t chord_keys[CHORDING_MAX] = {0}; | ||
uint8_t chord_key_count = 0; | ||
uint8_t chord_key_down = 0; | ||
|
||
bool process_chording(uint16_t keycode, keyrecord_t *record); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "process_leader.h" | ||
|
||
__attribute__ ((weak)) | ||
void leader_start(void) {} | ||
|
||
__attribute__ ((weak)) | ||
void leader_end(void) {} | ||
|
||
// Leader key stuff | ||
bool leading = false; | ||
uint16_t leader_time = 0; | ||
|
||
uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; | ||
uint8_t leader_sequence_size = 0; | ||
|
||
bool process_leader(uint16_t keycode, keyrecord_t *record) { | ||
// Leader key set-up | ||
if (record->event.pressed) { | ||
if (!leading && keycode == KC_LEAD) { | ||
leader_start(); | ||
leading = true; | ||
leader_time = timer_read(); | ||
leader_sequence_size = 0; | ||
leader_sequence[0] = 0; | ||
leader_sequence[1] = 0; | ||
leader_sequence[2] = 0; | ||
leader_sequence[3] = 0; | ||
leader_sequence[4] = 0; | ||
return false; | ||
} | ||
if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) { | ||
leader_sequence[leader_sequence_size] = keycode; | ||
leader_sequence_size++; | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef PROCESS_LEADER_H | ||
#define PROCESS_LEADER_H | ||
|
||
#include "quantum.h" | ||
|
||
bool process_leader(uint16_t keycode, keyrecord_t *record); | ||
|
||
void leader_start(void); | ||
void leader_end(void); | ||
|
||
#ifndef LEADER_TIMEOUT | ||
#define LEADER_TIMEOUT 200 | ||
#endif | ||
#define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0 && leader_sequence[3] == 0 && leader_sequence[4] == 0) | ||
#define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0 && leader_sequence[3] == 0 && leader_sequence[4] == 0) | ||
#define SEQ_THREE_KEYS(key1, key2, key3) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == 0 && leader_sequence[4] == 0) | ||
#define SEQ_FOUR_KEYS(key1, key2, key3, key4) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == 0) | ||
#define SEQ_FIVE_KEYS(key1, key2, key3, key4, key5) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == (key5)) | ||
|
||
#define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[5]; extern uint8_t leader_sequence_size | ||
#define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "process_unicode.h" | ||
|
||
static uint8_t input_mode; | ||
|
||
uint16_t hex_to_keycode(uint8_t hex) | ||
{ | ||
if (hex == 0x0) { | ||
return KC_0; | ||
} else if (hex < 0xA) { | ||
return KC_1 + (hex - 0x1); | ||
} else { | ||
return KC_A + (hex - 0xA); | ||
} | ||
} | ||
|
||
void set_unicode_mode(uint8_t os_target) | ||
{ | ||
input_mode = os_target; | ||
} | ||
|
||
bool process_unicode(uint16_t keycode, keyrecord_t *record) { | ||
if (keycode > QK_UNICODE && record->event.pressed) { | ||
uint16_t unicode = keycode & 0x7FFF; | ||
switch(input_mode) { | ||
case UC_OSX: | ||
register_code(KC_LALT); | ||
break; | ||
case UC_LNX: | ||
register_code(KC_LCTL); | ||
register_code(KC_LSFT); | ||
register_code(KC_U); | ||
unregister_code(KC_U); | ||
break; | ||
case UC_WIN: | ||
register_code(KC_LALT); | ||
register_code(KC_PPLS); | ||
unregister_code(KC_PPLS); | ||
break; | ||
} | ||
for(int i = 3; i >= 0; i--) { | ||
uint8_t digit = ((unicode >> (i*4)) & 0xF); | ||
register_code(hex_to_keycode(digit)); | ||
unregister_code(hex_to_keycode(digit)); | ||
} | ||
switch(input_mode) { | ||
case UC_OSX: | ||
case UC_WIN: | ||
unregister_code(KC_LALT); | ||
break; | ||
case UC_LNX: | ||
unregister_code(KC_LCTL); | ||
unregister_code(KC_LSFT); | ||
break; | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef PROCESS_UNICODE_H | ||
#define PROCESS_UNICODE_H | ||
|
||
#include "quantum.h" | ||
|
||
#define UC_OSX 0 | ||
#define UC_LNX 1 | ||
#define UC_WIN 2 | ||
#define UC_BSD 3 | ||
|
||
void set_unicode_input_mode(uint8_t os_target); | ||
|
||
bool process_unicode(uint16_t keycode, keyrecord_t *record); | ||
|
||
#endif |
Oops, something went wrong.