Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share button state from mousekey to pointing_device #10179

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/feature_mouse_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,7 @@ To use constant speed mode, you must at least define `MK_COMBINED` in your keyma
```c
#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.
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
[![GitHub contributors](https://img.shields.io/github/contributors/qmk/qmk_firmware.svg)](https://github.com/qmk/qmk_firmware/pulse/monthly)
[![GitHub forks](https://img.shields.io/github/forks/qmk/qmk_firmware.svg?style=social&label=Fork)](https://github.com/qmk/qmk_firmware/)

# THIS IS THE DEVELOP BRANCH

Warning- This is the `develop` branch of QMK Firmware. You may encounter broken code here. Please see [Breaking Changes](https://docs.qmk.fm/#/breaking_changes) for more information.

# Original readme continues

This is a keyboard firmware based on the [tmk\_keyboard firmware](https://github.com/tmk/tmk_keyboard) with some useful features for Atmel AVR and ARM controllers, and more specifically, the [OLKB product line](https://olkb.com), the [ErgoDox EZ](https://ergodox-ez.com) keyboard, and the [Clueboard product line](https://clueboard.co).

## Documentation
Expand Down
49 changes: 41 additions & 8 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ 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
Expand Down Expand Up @@ -220,6 +224,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.
Expand Down Expand Up @@ -404,15 +421,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:
Expand All @@ -422,15 +447,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:
Expand Down