2021-12-30 05:17:34 +01:00
|
|
|
// Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-12-15 05:53:36 +01:00
|
|
|
|
|
|
|
#include "pointing.h"
|
2023-02-28 20:14:48 +01:00
|
|
|
#include "math.h"
|
2021-12-15 05:53:36 +01:00
|
|
|
|
2022-09-25 22:04:00 +02:00
|
|
|
static uint16_t mouse_debounce_timer = 0;
|
|
|
|
bool enable_acceleration = false;
|
2021-12-15 05:53:36 +01: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 22:04:00 +02: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-15 05:53:36 +01: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 21:55:19 +02:00
|
|
|
mouse_xy_report_t x = mouse_report.x, y = mouse_report.y;
|
2021-12-15 05:53:36 +01:00
|
|
|
mouse_report.x = 0;
|
|
|
|
mouse_report.y = 0;
|
|
|
|
|
2022-09-25 22:04:00 +02:00
|
|
|
if (x != 0 && y != 0 && (timer_elapsed(mouse_debounce_timer) > TAP_CHECK)) {
|
2021-12-15 05:53:36 +01:00
|
|
|
#ifdef OLED_ENABLE
|
2022-05-31 07:02:55 +02:00
|
|
|
oled_timer_reset();
|
2021-12-15 05:53:36 +01:00
|
|
|
#endif
|
2022-09-25 22:04:00 +02:00
|
|
|
if (enable_acceleration) {
|
2023-02-28 20:14:48 +01:00
|
|
|
x = (mouse_xy_report_t)(x > 0 ? pow(4, x) / 2 + x : -pow(4, abs(x)) / 2 + x);
|
|
|
|
y = (mouse_xy_report_t)(y > 0 ? pow(5, y) / 2 + y : -pow(5, abs(y)) / 2 + y);
|
|
|
|
// 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 05:53:36 +01:00
|
|
|
}
|
2022-09-25 22:04:00 +02:00
|
|
|
mouse_report.x = x;
|
|
|
|
mouse_report.y = y;
|
2021-12-15 05:53:36 +01:00
|
|
|
}
|
2022-01-30 22:20:33 +01:00
|
|
|
|
|
|
|
return pointing_device_task_keymap(mouse_report);
|
2021-12-15 05:53:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool process_record_pointing(uint16_t keycode, keyrecord_t* record) {
|
|
|
|
switch (keycode) {
|
|
|
|
case KC_ACCEL:
|
|
|
|
enable_acceleration = record->event.pressed;
|
2022-01-30 22:20:33 +01:00
|
|
|
break;
|
2021-12-15 05:53:36 +01:00
|
|
|
default:
|
|
|
|
mouse_debounce_timer = timer_read();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
layer_state_t layer_state_set_pointing(layer_state_t state) {
|
2022-03-07 07:12:17 +01:00
|
|
|
if (layer_state_cmp(state, _GAMEPAD) || layer_state_cmp(state, _DIABLO) || layer_state_cmp(state, _DIABLOII)) {
|
2021-12-15 05:53:36 +01:00
|
|
|
state |= ((layer_state_t)1 << _MOUSE);
|
2022-09-25 22:04:00 +02:00
|
|
|
set_auto_mouse_enable(false); // auto mouse can be disabled any time during run time
|
|
|
|
} else {
|
|
|
|
set_auto_mouse_enable(true);
|
2021-12-15 05:53:36 +01:00
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
2022-09-25 22:04:00 +02: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 20:14:48 +01: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 23:49:07 +01:00
|
|
|
case QK_KB ... QK_KB_MAX:
|
2022-09-25 22:04:00 +02:00
|
|
|
# endif
|
|
|
|
case KC_ACCEL:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|