Share button state from mousekey to pointing_device (#10179)

* Branch point for 2020 November 28 Breaking Change

Update readme.md

* Share button state from mousekey to pointing_device

Co-authored-by: Nick Brassel <nick@tzarc.org>

Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com>
Co-authored-by: Nick Brassel <nick@tzarc.org>
This commit is contained in:
Manna Harbour 2020-10-04 06:12:20 +11:00 committed by James Young
parent 310662fce9
commit eecedf0db5
No known key found for this signature in database
GPG key ID: 8E1085BF6FCFBD74
2 changed files with 45 additions and 8 deletions

View file

@ -140,3 +140,7 @@ To use constant speed mode, you must at least define `MK_COMBINED` in your keyma
```c ```c
#define MK_COMBINED #define MK_COMBINED
``` ```
## Use with PS/2 Mouse and Pointing Device
Mouse keys button state is shared with [PS/2 mouse](feature_ps2_mouse.md) and [pointing device](feature_pointing_device.md) so mouse keys button presses can be used for clicks and drags.

View file

@ -37,6 +37,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "nodebug.h" # include "nodebug.h"
#endif #endif
#ifdef POINTING_DEVICE_ENABLE
# include "pointing_device.h"
#endif
int tp_buttons; int tp_buttons;
#ifdef RETRO_TAPPING #ifdef RETRO_TAPPING
@ -220,6 +224,19 @@ void process_record_handler(keyrecord_t *record) {
process_action(record, action); 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. /** \brief Take an action and processes it.
* *
* FIXME: Needs documentation. * FIXME: Needs documentation.
@ -404,15 +421,23 @@ void process_action(keyrecord_t *record, action_t action) {
if (event.pressed) { if (event.pressed) {
mousekey_on(action.key.code); mousekey_on(action.key.code);
switch (action.key.code) { switch (action.key.code) {
# ifdef PS2_MOUSE_ENABLE # if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
case KC_MS_BTN1: case KC_MS_BTN1:
tp_buttons |= (1 << 0); register_button(true, MOUSE_BTN1);
break; break;
case KC_MS_BTN2: case KC_MS_BTN2:
tp_buttons |= (1 << 1); register_button(true, MOUSE_BTN2);
break; break;
case KC_MS_BTN3: 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; break;
# endif # endif
default: default:
@ -422,15 +447,23 @@ void process_action(keyrecord_t *record, action_t action) {
} else { } else {
mousekey_off(action.key.code); mousekey_off(action.key.code);
switch (action.key.code) { switch (action.key.code) {
# ifdef PS2_MOUSE_ENABLE # if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
case KC_MS_BTN1: case KC_MS_BTN1:
tp_buttons &= ~(1 << 0); register_button(false, MOUSE_BTN1);
break; break;
case KC_MS_BTN2: case KC_MS_BTN2:
tp_buttons &= ~(1 << 1); register_button(false, MOUSE_BTN2);
break; break;
case KC_MS_BTN3: 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; break;
# endif # endif
default: default: