Skip to content

Commit

Permalink
Common keyevent_t construction.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzarc committed Mar 9, 2022
1 parent 7c42095 commit ee3df11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
10 changes: 7 additions & 3 deletions quantum/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@ static inline bool IS_RELEASED(keyevent_t event) {
return !IS_NOEVENT(event) && !event.pressed;
}

/* Common keyevent object factory */
#define MAKE_KEYPOS(row_num, col_num) ((keypos_t){.row = (row_num), .col = (col_num)})
#define MAKE_KEYEVENT(row_num, col_num, press) ((keyevent_t){.key = MAKE_KEYPOS((row_num), (col_num)), .pressed = (press), .time = (timer_read() | 1)})

/* Tick event */
#define TICK ((keyevent_t){.key = (keypos_t){.row = KEYLOC_TICK, .col = KEYLOC_TICK}, .pressed = false, .time = (timer_read() | 1)})
#define TICK MAKE_KEYEVENT(KEYLOC_TICK, KEYLOC_TICK, false)

#ifdef ENCODER_MAP_ENABLE
/* Encoder events */
# define ENCODER_CW_EVENT(enc_id, press) ((keyevent_t){.key = (keypos_t){.row = KEYLOC_ENCODER_CW, .col = enc_id}, .pressed = press, .time = (timer_read() | 1)})
# define ENCODER_CCW_EVENT(enc_id, press) ((keyevent_t){.key = (keypos_t){.row = KEYLOC_ENCODER_CCW, .col = enc_id}, .pressed = press, .time = (timer_read() | 1)})
# define ENCODER_CW_EVENT(enc_id, press) MAKE_KEYEVENT(KEYLOC_ENCODER_CW, (enc_id), (press))
# define ENCODER_CCW_EVENT(enc_id, press) MAKE_KEYEVENT(KEYLOC_ENCODER_CCW, (enc_id), (press))
#endif // ENCODER_MAP_ENABLE

/* it runs once at early stage of startup before keyboard_init. */
Expand Down
11 changes: 2 additions & 9 deletions quantum/process_keycode/process_combo.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH];

#define INCREMENT_MOD(i) i = (i + 1) % COMBO_BUFFER_LENGTH

#define COMBO_KEY_POS ((keypos_t){.col = KEYLOC_COMBO, .row = KEYLOC_COMBO})

#ifndef EXTRA_SHORT_COMBOS
/* flags are their own elements in combo_t struct. */
# define COMBO_ACTIVE(combo) (combo->active)
Expand Down Expand Up @@ -140,12 +138,7 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH];
static inline void release_combo(uint16_t combo_index, combo_t *combo) {
if (combo->keycode) {
keyrecord_t record = {
.event =
{
.key = COMBO_KEY_POS,
.time = timer_read() | 1,
.pressed = false,
},
.event = MAKE_KEYEVENT(KEYLOC_COMBO, KEYLOC_COMBO, false),
.keycode = combo->keycode,
};
#ifndef NO_ACTION_TAPPING
Expand Down Expand Up @@ -325,7 +318,7 @@ void apply_combo(uint16_t combo_index, combo_t *combo) {
if (ALL_COMBO_KEYS_ARE_DOWN(state, key_count)) {
// this in the end executes the combo when the key_buffer is dumped.
record->keycode = combo->keycode;
record->event.key = COMBO_KEY_POS;
record->event.key = MAKE_KEYPOS(KEYLOC_COMBO, KEYLOC_COMBO);

qrecord->combo_index = combo_index;
ACTIVATE_COMBO(combo);
Expand Down

0 comments on commit ee3df11

Please sign in to comment.