summaryrefslogtreecommitdiff
path: root/tmk_core/common/action.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/action.c')
-rw-r--r--tmk_core/common/action.c66
1 files changed, 53 insertions, 13 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index ee9aa0df77..77da0139f2 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -37,9 +37,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "nodebug.h"
#endif
+#ifdef POINTING_DEVICE_ENABLE
+# include "pointing_device.h"
+#endif
+
int tp_buttons;
-#ifdef RETRO_TAPPING
+#if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY)
int retro_tapping_counter = 0;
#endif
@@ -51,6 +55,10 @@ int retro_tapping_counter = 0;
__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { return false; }
#endif
+#ifdef RETRO_TAPPING_PER_KEY
+__attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { return false; }
+#endif
+
#ifndef TAP_CODE_DELAY
# define TAP_CODE_DELAY 0
#endif
@@ -67,7 +75,7 @@ void action_exec(keyevent_t event) {
dprint("EVENT: ");
debug_event(event);
dprintln();
-#ifdef RETRO_TAPPING
+#if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY)
retro_tapping_counter++;
#endif
}
@@ -220,6 +228,19 @@ void process_record_handler(keyrecord_t *record) {
process_action(record, action);
}
+#if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
+void register_button(bool pressed, enum mouse_buttons button) {
+# ifdef PS2_MOUSE_ENABLE
+ tp_buttons = pressed ? tp_buttons | button : tp_buttons & ~button;
+# endif
+# ifdef POINTING_DEVICE_ENABLE
+ report_mouse_t currentReport = pointing_device_get_report();
+ currentReport.buttons = pressed ? currentReport.buttons | button : currentReport.buttons & ~button;
+ pointing_device_set_report(currentReport);
+# endif
+}
+#endif
+
/** \brief Take an action and processes it.
*
* FIXME: Needs documentation.
@@ -404,15 +425,23 @@ void process_action(keyrecord_t *record, action_t action) {
if (event.pressed) {
mousekey_on(action.key.code);
switch (action.key.code) {
-# ifdef PS2_MOUSE_ENABLE
+# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
case KC_MS_BTN1:
- tp_buttons |= (1 << 0);
+ register_button(true, MOUSE_BTN1);
break;
case KC_MS_BTN2:
- tp_buttons |= (1 << 1);
+ register_button(true, MOUSE_BTN2);
break;
case KC_MS_BTN3:
- tp_buttons |= (1 << 2);
+ register_button(true, MOUSE_BTN3);
+ break;
+# endif
+# ifdef POINTING_DEVICE_ENABLE
+ case KC_MS_BTN4:
+ register_button(true, MOUSE_BTN4);
+ break;
+ case KC_MS_BTN5:
+ register_button(true, MOUSE_BTN5);
break;
# endif
default:
@@ -422,15 +451,23 @@ void process_action(keyrecord_t *record, action_t action) {
} else {
mousekey_off(action.key.code);
switch (action.key.code) {
-# ifdef PS2_MOUSE_ENABLE
+# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
case KC_MS_BTN1:
- tp_buttons &= ~(1 << 0);
+ register_button(false, MOUSE_BTN1);
break;
case KC_MS_BTN2:
- tp_buttons &= ~(1 << 1);
+ register_button(false, MOUSE_BTN2);
break;
case KC_MS_BTN3:
- tp_buttons &= ~(1 << 2);
+ register_button(false, MOUSE_BTN3);
+ break;
+# endif
+# ifdef POINTING_DEVICE_ENABLE
+ case KC_MS_BTN4:
+ register_button(false, MOUSE_BTN4);
+ break;
+ case KC_MS_BTN5:
+ register_button(false, MOUSE_BTN5);
break;
# endif
default:
@@ -692,20 +729,23 @@ void process_action(keyrecord_t *record, action_t action) {
#endif
#ifndef NO_ACTION_TAPPING
-# ifdef RETRO_TAPPING
+# if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY)
if (!is_tap_action(action)) {
retro_tapping_counter = 0;
} else {
if (event.pressed) {
if (tap_count > 0) {
retro_tapping_counter = 0;
- } else {
}
} else {
if (tap_count > 0) {
retro_tapping_counter = 0;
} else {
- if (retro_tapping_counter == 2) {
+ if (
+# ifdef RETRO_TAPPING_PER_KEY
+ get_retro_tapping(get_event_keycode(record->event, false), record) &&
+# endif
+ retro_tapping_counter == 2) {
tap_code(action.layer_tap.code);
}
retro_tapping_counter = 0;