2021-12-30 04:17:34 +00:00
|
|
|
// Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-12-15 04:53:36 +00:00
|
|
|
|
|
|
|
#include "pointing.h"
|
|
|
|
|
|
|
|
static uint16_t mouse_timer = 0;
|
|
|
|
static uint16_t mouse_debounce_timer = 0;
|
|
|
|
static uint8_t mouse_keycode_tracker = 0;
|
|
|
|
bool tap_toggling = false, enable_acceleration = false;
|
|
|
|
|
|
|
|
#ifdef TAPPING_TERM_PER_KEY
|
|
|
|
# define TAP_CHECK get_tapping_term(KC_BTN1, NULL)
|
|
|
|
#else
|
|
|
|
# ifndef TAPPING_TERM
|
|
|
|
# define TAPPING_TERM 200
|
|
|
|
# endif
|
|
|
|
# define TAP_CHECK TAPPING_TERM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__attribute__((weak)) report_mouse_t pointing_device_task_keymap(report_mouse_t mouse_report) {
|
|
|
|
return mouse_report;
|
|
|
|
}
|
|
|
|
|
|
|
|
report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
|
2022-08-28 19:55:19 +00:00
|
|
|
mouse_xy_report_t x = mouse_report.x, y = mouse_report.y;
|
2021-12-15 04:53:36 +00:00
|
|
|
mouse_report.x = 0;
|
|
|
|
mouse_report.y = 0;
|
|
|
|
|
|
|
|
if (x != 0 && y != 0) {
|
|
|
|
mouse_timer = timer_read();
|
|
|
|
#ifdef OLED_ENABLE
|
2022-05-31 05:02:55 +00:00
|
|
|
oled_timer_reset();
|
2021-12-15 04:53:36 +00:00
|
|
|
#endif
|
|
|
|
if (timer_elapsed(mouse_debounce_timer) > TAP_CHECK) {
|
|
|
|
if (enable_acceleration) {
|
2022-08-28 19:55:19 +00:00
|
|
|
x = (mouse_xy_report_t)(x > 0 ? x * x / 16 + x : -x * x / 16 + x);
|
|
|
|
y = (mouse_xy_report_t)(y > 0 ? y * y / 16 + y : -y * y / 16 + y);
|
2021-12-15 04:53:36 +00:00
|
|
|
}
|
|
|
|
mouse_report.x = x;
|
|
|
|
mouse_report.y = y;
|
|
|
|
if (!layer_state_is(_MOUSE)) {
|
|
|
|
layer_on(_MOUSE);
|
|
|
|
}
|
|
|
|
}
|
2022-01-30 21:20:33 +00:00
|
|
|
} else if (timer_elapsed(mouse_timer) > 650 && layer_state_is(_MOUSE) && !mouse_keycode_tracker && !tap_toggling) {
|
2021-12-15 04:53:36 +00:00
|
|
|
layer_off(_MOUSE);
|
2022-01-30 21:20:33 +00:00
|
|
|
} else if (tap_toggling) {
|
2021-12-15 04:53:36 +00:00
|
|
|
if (!layer_state_is(_MOUSE)) {
|
|
|
|
layer_on(_MOUSE);
|
|
|
|
}
|
|
|
|
}
|
2022-01-30 21:20:33 +00:00
|
|
|
|
|
|
|
return pointing_device_task_keymap(mouse_report);
|
2021-12-15 04:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool process_record_pointing(uint16_t keycode, keyrecord_t* record) {
|
|
|
|
switch (keycode) {
|
|
|
|
case TT(_MOUSE):
|
|
|
|
if (record->event.pressed) {
|
|
|
|
mouse_keycode_tracker++;
|
|
|
|
} else {
|
|
|
|
#if TAPPING_TOGGLE != 0
|
|
|
|
if (record->tap.count == TAPPING_TOGGLE) {
|
|
|
|
tap_toggling ^= 1;
|
|
|
|
# if TAPPING_TOGGLE == 1
|
|
|
|
if (!tap_toggling) mouse_keycode_tracker -= record->tap.count + 1;
|
|
|
|
# else
|
|
|
|
if (!tap_toggling) mouse_keycode_tracker -= record->tap.count;
|
|
|
|
# endif
|
|
|
|
} else {
|
|
|
|
mouse_keycode_tracker--;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
mouse_timer = timer_read();
|
|
|
|
break;
|
|
|
|
case TG(_MOUSE):
|
|
|
|
if (record->event.pressed) {
|
|
|
|
tap_toggling ^= 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MO(_MOUSE):
|
2022-01-30 21:29:43 +00:00
|
|
|
#if defined(KEYBOARD_ploopy)
|
2021-12-15 04:53:36 +00:00
|
|
|
case DPI_CONFIG:
|
2022-01-30 21:29:43 +00:00
|
|
|
#elif (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && !defined(NO_CHARYBDIS_KEYCODES)
|
2021-12-15 04:53:36 +00:00
|
|
|
case SAFE_RANGE ... (CHARYBDIS_SAFE_RANGE-1):
|
|
|
|
#endif
|
|
|
|
case KC_MS_UP ... KC_MS_WH_RIGHT:
|
|
|
|
record->event.pressed ? mouse_keycode_tracker++ : mouse_keycode_tracker--;
|
|
|
|
mouse_timer = timer_read();
|
|
|
|
break;
|
|
|
|
case KC_ACCEL:
|
|
|
|
enable_acceleration = record->event.pressed;
|
|
|
|
record->event.pressed ? mouse_keycode_tracker++ : mouse_keycode_tracker--;
|
|
|
|
mouse_timer = timer_read();
|
|
|
|
break;
|
2022-05-31 05:02:55 +00:00
|
|
|
#if 0
|
2022-01-30 21:20:33 +00:00
|
|
|
case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:
|
|
|
|
break;
|
2022-05-31 05:02:55 +00:00
|
|
|
#endif
|
2022-01-30 21:20:33 +00:00
|
|
|
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
|
|
|
|
if (record->event.pressed || !record->tap.count) {
|
|
|
|
break;
|
|
|
|
}
|
2021-12-15 04:53:36 +00:00
|
|
|
default:
|
|
|
|
if (IS_NOEVENT(record->event)) break;
|
|
|
|
if ((keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX) && (((keycode >> 0x8) & 0xF) == _MOUSE)) {
|
|
|
|
record->event.pressed ? mouse_keycode_tracker++ : mouse_keycode_tracker--;
|
|
|
|
mouse_timer = timer_read();
|
|
|
|
break;
|
|
|
|
}
|
2022-01-22 03:36:52 +00:00
|
|
|
if (layer_state_is(_MOUSE) && !mouse_keycode_tracker && !tap_toggling) {
|
2021-12-15 04:53:36 +00:00
|
|
|
layer_off(_MOUSE);
|
|
|
|
}
|
|
|
|
mouse_keycode_tracker = 0;
|
|
|
|
mouse_debounce_timer = timer_read();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
layer_state_t layer_state_set_pointing(layer_state_t state) {
|
2022-03-07 06:12:17 +00:00
|
|
|
if (layer_state_cmp(state, _GAMEPAD) || layer_state_cmp(state, _DIABLO) || layer_state_cmp(state, _DIABLOII)) {
|
2021-12-15 04:53:36 +00:00
|
|
|
state |= ((layer_state_t)1 << _MOUSE);
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|