summaryrefslogtreecommitdiff
path: root/quantum/pointing_device
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@drashna.net>2023-03-30 18:27:39 -0700
committerGitHub <noreply@github.com>2023-03-30 18:27:39 -0700
commit297779385fd53e93c33861e2d3107cb88efbde81 (patch)
tree21b10a2cc50505ba31a634045f00df40b2196a50 /quantum/pointing_device
parent8686c527f76ff794c51ff55377c029ac3c38f683 (diff)
Add last activity functions for pointing device (#20079)
Diffstat (limited to 'quantum/pointing_device')
-rw-r--r--quantum/pointing_device/pointing_device.c28
-rw-r--r--quantum/pointing_device/pointing_device.h4
2 files changed, 20 insertions, 12 deletions
diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c
index 75bb5f81fc..abb3817b5f 100644
--- a/quantum/pointing_device/pointing_device.c
+++ b/quantum/pointing_device/pointing_device.c
@@ -74,7 +74,8 @@ uint16_t pointing_device_get_shared_cpi(void) {
#endif // defined(SPLIT_POINTING_ENABLE)
-static report_mouse_t local_mouse_report = {};
+static report_mouse_t local_mouse_report = {};
+static bool pointing_device_force_send = false;
extern const pointing_device_driver_t pointing_device_driver;
@@ -163,11 +164,11 @@ __attribute__((weak)) void pointing_device_init(void) {
* This sends the mouse report generated by pointing_device_task if changed since the last report. Once send zeros mouse report except buttons.
*
*/
-__attribute__((weak)) void pointing_device_send(void) {
- static report_mouse_t old_report = {};
+__attribute__((weak)) bool pointing_device_send(void) {
+ static report_mouse_t old_report = {};
+ bool should_send_report = has_mouse_report_changed(&local_mouse_report, &old_report);
- // If you need to do other things, like debugging, this is the place to do it.
- if (has_mouse_report_changed(&local_mouse_report, &old_report)) {
+ if (should_send_report) {
host_mouse_send(&local_mouse_report);
}
// send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
@@ -175,6 +176,8 @@ __attribute__((weak)) void pointing_device_send(void) {
memset(&local_mouse_report, 0, sizeof(local_mouse_report));
local_mouse_report.buttons = buttons;
memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report));
+
+ return should_send_report || buttons;
}
/**
@@ -220,18 +223,18 @@ report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report) {
* It applies any optional configuration e.g. rotation or axis inversion and then initiates a send.
*
*/
-__attribute__((weak)) void pointing_device_task(void) {
+__attribute__((weak)) bool pointing_device_task(void) {
#if defined(SPLIT_POINTING_ENABLE)
// Don't poll the target side pointing device.
if (!is_keyboard_master()) {
- return;
+ return false;
};
#endif
#if (POINTING_DEVICE_TASK_THROTTLE_MS > 0)
static uint32_t last_exec = 0;
if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) {
- return;
+ return false;
}
last_exec = timer_read32();
#endif
@@ -286,7 +289,11 @@ __attribute__((weak)) void pointing_device_task(void) {
report_mouse_t mousekey_report = mousekey_get_report();
local_mouse_report.buttons = local_mouse_report.buttons | mousekey_report.buttons;
#endif
- pointing_device_send();
+
+ const bool send_report = pointing_device_send() || pointing_device_force_send;
+ pointing_device_force_send = false;
+
+ return send_report;
}
/**
@@ -304,7 +311,8 @@ report_mouse_t pointing_device_get_report(void) {
* @param[in] mouse_report
*/
void pointing_device_set_report(report_mouse_t mouse_report) {
- local_mouse_report = mouse_report;
+ pointing_device_force_send = has_mouse_report_changed(&local_mouse_report, &mouse_report);
+ memcpy(&local_mouse_report, &mouse_report, sizeof(local_mouse_report));
}
/**
diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h
index d430e6cfa4..eacc6418dd 100644
--- a/quantum/pointing_device/pointing_device.h
+++ b/quantum/pointing_device/pointing_device.h
@@ -97,8 +97,8 @@ typedef int16_t clamp_range_t;
#endif
void pointing_device_init(void);
-void pointing_device_task(void);
-void pointing_device_send(void);
+bool pointing_device_task(void);
+bool pointing_device_send(void);
report_mouse_t pointing_device_get_report(void);
void pointing_device_set_report(report_mouse_t mouse_report);
uint16_t pointing_device_get_cpi(void);