Skip to content

Commit

Permalink
Refactor main source file
Browse files Browse the repository at this point in the history
  • Loading branch information
filterpaper committed May 5, 2024
1 parent fb0d128 commit b02528e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
34 changes: 32 additions & 2 deletions filterpaper.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
// Copyright @filterpaper
// SPDX-License-Identifier: GPL-2.0+

#include "filterpaper.h"
#include QMK_KEYBOARD_H
#include "autocorrect.h"
#ifdef COMBO_ENABLE
# include "combos.h"
#endif

// Convert 5-bit packed mod-tap modifiers to 8-bit packed MOD_MASK modifiers
#define MOD_TAP_GET_MOD_BITS(kc) (((kc) & 0x0f00) >> (((kc) & 0x1000) ? 4 : 8))
// Basic keycode filter for tap-hold keys
#define GET_TAP_KEYCODE(kc) ((kc) & 0xff)

// Tap-hold decision helper macros
#define IS_HOMEROW(r) (r->event.key.row == 1 || r->event.key.row == 5)
#define IS_MOD_TAP_SHIFT(kc) (IS_QK_MOD_TAP(kc) && (kc) & (QK_LSFT))
#define IS_MOD_TAP_CS(kc) (IS_QK_MOD_TAP(kc) && (kc) & (QK_LCTL | QK_LSFT))
#define IS_MOD_TAP_CAG(kc) (IS_QK_MOD_TAP(kc) && (kc) & (QK_LCTL | QK_LALT | QK_LGUI))
#define IS_LAYER_TAP(kc) (IS_QK_LAYER_TAP(kc) && QK_LAYER_TAP_GET_LAYER(kc))

#define IS_TYPING(kc) ( \
last_input_activity_elapsed() < INPUT_INTERVAL && \
(KC_A <= (uint8_t)(kc) && (uint8_t)(kc) <= KC_0) && \
!IS_LAYER_TAP(kc) )

#define IS_UNILATERAL(r, n) ( \
(0 <= r->event.key.row && r->event.key.row <= 2 && 0 <= n.event.key.row && n.event.key.row <= 2) || \
(4 <= r->event.key.row && r->event.key.row <= 6 && 4 <= n.event.key.row && n.event.key.row <= 6) )

#define IS_BILATERAL(r, n) ( \
(r->event.key.row == 1 && 4 <= n.event.key.row && n.event.key.row <= 7) || \
(r->event.key.row == 5 && 0 <= n.event.key.row && n.event.key.row <= 3) )


static uint16_t next_keycode;
static keyrecord_t next_record;
Expand Down Expand Up @@ -102,7 +132,7 @@ static inline bool process_tap_hold(uint16_t keycode, keyrecord_t *record) {

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
#ifdef COMBO_SHOULD_TRIGGER
#if defined (COMBO_ENABLE) && defined (COMBO_SHOULD_TRIGGER)
if (record->event.type != COMBO_EVENT) input_timer = timer_read_fast();
#endif
if (!process_autocorrect(keycode, record) || !process_caps_unlock(keycode, record)) return false;
Expand Down
35 changes: 0 additions & 35 deletions filterpaper.h

This file was deleted.

0 comments on commit b02528e

Please sign in to comment.