aboutsummaryrefslogtreecommitdiff
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 ee9aa0df7..77da0139f 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/>.
37# include "nodebug.h" 37# include "nodebug.h"
38#endif 38#endif
39 39
40#ifdef POINTING_DEVICE_ENABLE
41# include "pointing_device.h"
42#endif
43
40int tp_buttons; 44int tp_buttons;
41 45
42#ifdef RETRO_TAPPING 46#if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY)
43int retro_tapping_counter = 0; 47int retro_tapping_counter = 0;
44#endif 48#endif
45 49
@@ -51,6 +55,10 @@ int retro_tapping_counter = 0;
51__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { return false; } 55__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { return false; }
52#endif 56#endif
53 57
58#ifdef RETRO_TAPPING_PER_KEY
59__attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { return false; }
60#endif
61
54#ifndef TAP_CODE_DELAY 62#ifndef TAP_CODE_DELAY
55# define TAP_CODE_DELAY 0 63# define TAP_CODE_DELAY 0
56#endif 64#endif
@@ -67,7 +75,7 @@ void action_exec(keyevent_t event) {
67 dprint("EVENT: "); 75 dprint("EVENT: ");
68 debug_event(event); 76 debug_event(event);
69 dprintln(); 77 dprintln();
70#ifdef RETRO_TAPPING 78#if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY)
71 retro_tapping_counter++; 79 retro_tapping_counter++;
72#endif 80#endif
73 } 81 }
@@ -220,6 +228,19 @@ void process_record_handler(keyrecord_t *record) {
220 process_action(record, action); 228 process_action(record, action);
221} 229}
222 230
231#if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
232void register_button(bool pressed, enum mouse_buttons button) {
233# ifdef PS2_MOUSE_ENABLE
234 tp_buttons = pressed ? tp_buttons | button : tp_buttons & ~button;
235# endif
236# ifdef POINTING_DEVICE_ENABLE
237 report_mouse_t currentReport = pointing_device_get_report();
238 currentReport.buttons = pressed ? currentReport.buttons | button : currentReport.buttons & ~button;
239 pointing_device_set_report(currentReport);
240# endif
241}
242#endif
243
223/** \brief Take an action and processes it. 244/** \brief Take an action and processes it.
224 * 245 *
225 * FIXME: Needs documentation. 246 * FIXME: Needs documentation.
@@ -404,15 +425,23 @@ void process_action(keyrecord_t *record, action_t action) {
404 if (event.pressed) { 425 if (event.pressed) {
405 mousekey_on(action.key.code); 426 mousekey_on(action.key.code);
406 switch (action.key.code) { 427 switch (action.key.code) {
407# ifdef PS2_MOUSE_ENABLE 428# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
408 case KC_MS_BTN1: 429 case KC_MS_BTN1:
409 tp_buttons |= (1 << 0); 430 register_button(true, MOUSE_BTN1);
410 break; 431 break;
411 case KC_MS_BTN2: 432 case KC_MS_BTN2:
412 tp_buttons |= (1 << 1); 433 register_button(true, MOUSE_BTN2);
413 break; 434 break;
414 case KC_MS_BTN3: 435 case KC_MS_BTN3:
415 tp_buttons |= (1 << 2); 436 register_button(true, MOUSE_BTN3);
437 break;
438# endif
439# ifdef POINTING_DEVICE_ENABLE
440 case KC_MS_BTN4:
441 register_button(true, MOUSE_BTN4);
442 break;
443 case KC_MS_BTN5:
444 register_button(true, MOUSE_BTN5);
416 break; 445 break;
417# endif 446# endif
418 default: 447 default:
@@ -422,15 +451,23 @@ void process_action(keyrecord_t *record, action_t action) {
422 } else { 451 } else {
423 mousekey_off(action.key.code); 452 mousekey_off(action.key.code);
424 switch (action.key.code) { 453 switch (action.key.code) {
425# ifdef PS2_MOUSE_ENABLE 454# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
426 case KC_MS_BTN1: 455 case KC_MS_BTN1:
427 tp_buttons &= ~(1 << 0); 456 register_button(false, MOUSE_BTN1);
428 break; 457 break;
429 case KC_MS_BTN2: 458 case KC_MS_BTN2:
430 tp_buttons &= ~(1 << 1); 459 register_button(false, MOUSE_BTN2);
431 break; 460 break;
432 case KC_MS_BTN3: 461 case KC_MS_BTN3:
433 tp_buttons &= ~(1 << 2); 462 register_button(false, MOUSE_BTN3);
463 break;
464# endif
465# ifdef POINTING_DEVICE_ENABLE
466 case KC_MS_BTN4:
467 register_button(false, MOUSE_BTN4);
468 break;
469 case KC_MS_BTN5:
470 register_button(false, MOUSE_BTN5);
434 break; 471 break;
435# endif 472# endif
436 default: 473 default:
@@ -692,20 +729,23 @@ void process_action(keyrecord_t *record, action_t action) {
692#endif 729#endif
693 730
694#ifndef NO_ACTION_TAPPING 731#ifndef NO_ACTION_TAPPING
695# ifdef RETRO_TAPPING 732# if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY)
696 if (!is_tap_action(action)) { 733 if (!is_tap_action(action)) {
697 retro_tapping_counter = 0; 734 retro_tapping_counter = 0;
698 } else { 735 } else {
699 if (event.pressed) { 736 if (event.pressed) {
700 if (tap_count > 0) { 737 if (tap_count > 0) {
701 retro_tapping_counter = 0; 738 retro_tapping_counter = 0;
702 } else {
703 } 739 }
704 } else { 740 } else {
705 if (tap_count > 0) { 741 if (tap_count > 0) {
706 retro_tapping_counter = 0; 742 retro_tapping_counter = 0;
707 } else { 743 } else {
708 if (retro_tapping_counter == 2) { 744 if (
745# ifdef RETRO_TAPPING_PER_KEY
746 get_retro_tapping(get_event_keycode(record->event, false), record) &&
747# endif
748 retro_tapping_counter == 2) {
709 tap_code(action.layer_tap.code); 749 tap_code(action.layer_tap.code);
710 } 750 }
711 retro_tapping_counter = 0; 751 retro_tapping_counter = 0;