From b02528e13e5387dc56961371ad2f07b4ecb03a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Sun, 5 May 2024 10:18:56 +0800 Subject: [PATCH] Refactor main source file --- filterpaper.c | 34 ++++++++++++++++++++++++++++++++-- filterpaper.h | 35 ----------------------------------- 2 files changed, 32 insertions(+), 37 deletions(-) delete mode 100644 filterpaper.h diff --git a/filterpaper.c b/filterpaper.c index 0fa9f8b7..d1834132 100644 --- a/filterpaper.c +++ b/filterpaper.c @@ -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; @@ -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; diff --git a/filterpaper.h b/filterpaper.h deleted file mode 100644 index 74bd7eea..00000000 --- a/filterpaper.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright @filterpaper -// SPDX-License-Identifier: GPL-2.0+ - -#pragma once -#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) )