2021-12-29 20:17:34 -08:00
|
|
|
// Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-12-14 20:53:36 -08:00
|
|
|
|
|
|
|
#include "pointing.h"
|
2023-02-28 11:14:48 -08:00
|
|
|
#include "math.h"
|
2021-12-14 20:53:36 -08:00
|
|
|
|
2022-09-25 13:04:00 -07:00
|
|
|
static uint16_t mouse_debounce_timer = 0;
|
|
|
|
bool enable_acceleration = false;
|
2021-12-14 20:53:36 -08:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2022-09-25 13:04:00 -07:00
|
|
|
__attribute__((weak)) void pointing_device_init_keymap(void) {}
|
|
|
|
|
|
|
|
void pointing_device_init_user(void) {
|
|
|
|
set_auto_mouse_layer(_MOUSE);
|
|
|
|
set_auto_mouse_enable(true);
|
|
|
|
|
|
|
|
pointing_device_init_keymap();
|
|
|
|
}
|
|
|
|
|
2021-12-14 20:53:36 -08:00
|
|
|
__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 12:55:19 -07:00
|
|
|
mouse_xy_report_t x = mouse_report.x, y = mouse_report.y;
|
2021-12-14 20:53:36 -08:00
|
|
|
mouse_report.x = 0;
|
|
|
|
mouse_report.y = 0;
|
|
|
|
|
2022-09-25 13:04:00 -07:00
|
|
|
if (x != 0 && y != 0 && (timer_elapsed(mouse_debounce_timer) > TAP_CHECK)) {
|
|
|
|
if (enable_acceleration) {
|
2023-05-31 11:44:06 -07:00
|
|
|
float magnitude = sqrtf( mouse_report.x * mouse_report.x + mouse_report.y * mouse_report.y );
|
|
|
|
float adjusted_magnitude = powf(magnitude, 1.2f);
|
|
|
|
x = (mouse_xy_report_t)(x * adjusted_magnitude);
|
|
|
|
y = (mouse_xy_report_t)(y * adjusted_magnitude);
|
2023-02-28 11:14:48 -08: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-14 20:53:36 -08:00
|
|
|
}
|
2022-09-25 13:04:00 -07:00
|
|
|
mouse_report.x = x;
|
|
|
|
mouse_report.y = y;
|
2021-12-14 20:53:36 -08:00
|
|
|
}
|
2022-01-30 13:20:33 -08:00
|
|
|
|
|
|
|
return pointing_device_task_keymap(mouse_report);
|
2021-12-14 20:53:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool process_record_pointing(uint16_t keycode, keyrecord_t* record) {
|
|
|
|
switch (keycode) {
|
|
|
|
case KC_ACCEL:
|
|
|
|
enable_acceleration = record->event.pressed;
|
2022-01-30 13:20:33 -08:00
|
|
|
break;
|
2023-05-31 11:44:06 -07:00
|
|
|
#if defined(POINTING_DEVICE_MOUSE_JIGGLER_ENABLE)
|
|
|
|
case PD_JIGGLER:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
pointing_device_mouse_jiggler_toggle();
|
|
|
|
}
|
|
|
|
#endif
|
2021-12-14 20:53:36 -08:00
|
|
|
default:
|
|
|
|
mouse_debounce_timer = timer_read();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
layer_state_t layer_state_set_pointing(layer_state_t state) {
|
2022-03-06 22:12:17 -08:00
|
|
|
if (layer_state_cmp(state, _GAMEPAD) || layer_state_cmp(state, _DIABLO) || layer_state_cmp(state, _DIABLOII)) {
|
2021-12-14 20:53:36 -08:00
|
|
|
state |= ((layer_state_t)1 << _MOUSE);
|
2022-09-25 13:04:00 -07:00
|
|
|
set_auto_mouse_enable(false); // auto mouse can be disabled any time during run time
|
|
|
|
} else {
|
|
|
|
set_auto_mouse_enable(true);
|
2021-12-14 20:53:36 -08:00
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
2022-09-25 13:04:00 -07:00
|
|
|
|
2023-05-31 11:44:06 -07:00
|
|
|
#if defined(POINTING_DEVICE_MOUSE_JIGGLER_ENABLE)
|
|
|
|
static uint16_t mouse_jiggler_timer;
|
|
|
|
|
|
|
|
bool has_mouse_report_changed(report_mouse_t* new_report, report_mouse_t* old_report) {
|
|
|
|
// Only report every 5 seconds.
|
|
|
|
if (userspace_config.mouse_jiggler && timer_elapsed(mouse_jiggler_timer) > 5000) {
|
|
|
|
mouse_jiggler_timer = timer_read();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return memcmp(new_report, old_report, sizeof(report_mouse_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
void pointing_device_mouse_jiggler_toggle(void) {
|
|
|
|
mouse_jiggler_timer = timer_read();
|
|
|
|
userspace_config.mouse_jiggler = !userspace_config.mouse_jiggler;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2022-09-25 13:04:00 -07:00
|
|
|
|
|
|
|
#if defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
|
|
|
|
__attribute__((weak)) bool is_mouse_record_keymap(uint16_t keycode, keyrecord_t *record) { return false; }
|
|
|
|
|
|
|
|
bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record) {
|
|
|
|
if (is_mouse_record_keymap(keycode, record)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
switch (keycode) {
|
|
|
|
# if defined(KEYBOARD_ploopy)
|
|
|
|
case DPI_CONFIG:
|
2023-02-28 11:14:48 -08:00
|
|
|
# elif (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && !defined(NO_CHARYBDIS_KEYCODES) || (defined(KEYBOARD_bastardkb_dilemma) && !defined(NO_DILEMMA_KEYCODES))
|
2023-02-22 14:49:07 -08:00
|
|
|
case QK_KB ... QK_KB_MAX:
|
2022-09-25 13:04:00 -07:00
|
|
|
# endif
|
|
|
|
case KC_ACCEL:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|