summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2022-09-29 10:50:47 -0700
committerGitHub <noreply@github.com>2022-09-29 10:50:47 -0700
commitdbe214c3268d9a316a137471a7679f7e45046e49 (patch)
tree97b065e2c3e1690c33fba2febd4498d40bb640ab /quantum
parentb53918fbe9122ef7995dce194951717ac65f7817 (diff)
Handle mouse keys more consistently (#18513)
Diffstat (limited to 'quantum')
-rw-r--r--quantum/action.c100
-rw-r--r--quantum/keymap_common.c2
2 files changed, 51 insertions, 51 deletions
diff --git a/quantum/action.c b/quantum/action.c
index 4f01acb96e..259c4349c3 100644
--- a/quantum/action.c
+++ b/quantum/action.c
@@ -293,19 +293,56 @@ 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);
+/**
+ * @brief handles all the messy mouse stuff
+ *
+ * Handles all the edgecases and special stuff that is needed for coexistense
+ * of the multiple mouse subsystems.
+ *
+ * @param mouse_keycode[in] uint8_t mouse keycode
+ * @param pressed[in] bool
+ */
+
+void register_mouse(uint8_t mouse_keycode, bool pressed) {
+#ifdef MOUSEKEY_ENABLE
+ // if mousekeys is enabled, let it do the brunt of the work
+ if (pressed) {
+ mousekey_on(mouse_keycode);
+ } else {
+ mousekey_off(mouse_keycode);
+ }
+ // should mousekeys send report, or does something else handle this?
+ switch (mouse_keycode) {
+# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
+ case KC_MS_BTN1 ... KC_MS_BTN8:
+ // let pointing device handle the buttons
+ // expand if/when it handles more of the code
+# if defined(POINTING_DEVICE_ENABLE)
+ pointing_device_keycode_handler(mouse_keycode, pressed);
+# endif
+ break;
# endif
-}
+ default:
+ mousekey_send();
+ break;
+ }
+#elif defined(POINTING_DEVICE_ENABLE)
+ // if mousekeys isn't enabled, and pointing device is enabled, then
+ // let pointing device do all the heavy lifting, then
+ if IS_MOUSEKEY (mouse_keycode) {
+ pointing_device_keycode_handler(mouse_keycode, pressed);
+ }
#endif
+#ifdef PS2_MOUSE_ENABLE
+ // make sure that ps2 mouse has button report synced
+ if (KC_MS_BTN1 <= mouse_keycode && mouse_keycode <= KC_MS_BTN3) {
+ uint8_t tmp_button_msk = MOUSE_BTN_MASK(mouse_keycode - KC_MS_BTN1);
+ tp_buttons = pressed ? tp_buttons | tmp_button_msk : tp_buttons & ~tmp_button_msk;
+ }
+#endif
+}
+
/** \brief Take an action and processes it.
*
* FIXME: Needs documentation.
@@ -506,30 +543,10 @@ void process_action(keyrecord_t *record, action_t action) {
}
break;
#endif
-#ifdef MOUSEKEY_ENABLE
/* Mouse key */
case ACT_MOUSEKEY:
- if (event.pressed) {
- mousekey_on(action.key.code);
- } else {
- mousekey_off(action.key.code);
- }
- switch (action.key.code) {
-# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
-# ifdef POINTING_DEVICE_ENABLE
- case KC_MS_BTN1 ... KC_MS_BTN8:
-# else
- case KC_MS_BTN1 ... KC_MS_BTN3:
-# endif
- register_button(event.pressed, MOUSE_BTN_MASK(action.key.code - KC_MS_BTN1));
- break;
-# endif
- default:
- mousekey_send();
- break;
- }
+ register_mouse(action.key.code, event.pressed);
break;
-#endif
#ifndef NO_ACTION_LAYER
case ACT_LAYER:
if (action.layer_bitop.on == 0) {
@@ -913,16 +930,9 @@ __attribute__((weak)) void register_code(uint8_t code) {
host_consumer_send(KEYCODE2CONSUMER(code));
}
#endif
-#ifdef MOUSEKEY_ENABLE
else if IS_MOUSEKEY (code) {
- mousekey_on(code);
- mousekey_send();
+ register_mouse(code, true);
}
-#elif defined(POINTING_DEVICE_ENABLE)
- else if IS_MOUSEKEY (code) {
- pointing_device_keycode_handler(code, true);
- }
-#endif
}
/** \brief Utilities for actions. (FIXME: Needs better description)
@@ -976,17 +986,9 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
host_system_send(0);
} else if IS_CONSUMER (code) {
host_consumer_send(0);
+ } else if IS_MOUSEKEY (code) {
+ register_mouse(code, false);
}
-#ifdef MOUSEKEY_ENABLE
- else if IS_MOUSEKEY (code) {
- mousekey_off(code);
- mousekey_send();
- }
-#elif defined(POINTING_DEVICE_ENABLE)
- else if IS_MOUSEKEY (code) {
- pointing_device_keycode_handler(code, false);
- }
-#endif
}
/** \brief Tap a keycode with a delay.
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 5e8a043470..50e581cd87 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -65,11 +65,9 @@ action_t action_for_keycode(uint16_t keycode) {
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
break;
#endif
-#ifdef MOUSEKEY_ENABLE
case KC_MS_UP ... KC_MS_ACCEL2:
action.code = ACTION_MOUSEKEY(keycode);
break;
-#endif
case KC_TRANSPARENT:
action.code = ACTION_TRANSPARENT;
break;