Fix screensaver issue with rapid movement.

This commit is contained in:
Hrvoje Cavrak 2024-12-04 20:00:13 +01:00
parent fa4ccdfeae
commit d78bcd4638
4 changed files with 22 additions and 14 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.6)
## Version Configuration ## Version Configuration
set(VERSION_MAJOR 00) set(VERSION_MAJOR 00)
set(VERSION_MINOR 161) set(VERSION_MINOR 162)
## Release Type Selection ## Release Type Selection
option(DH_DEBUG "Build a debug version" OFF) option(DH_DEBUG "Build a debug version" OFF)

View File

@ -39,7 +39,7 @@ void _get_border_position(device_t *state, border_size_t *border) {
border->top = state->pointer_y; border->top = state->pointer_y;
} }
void _screensaver_set(device_t *state, bool value) { void _screensaver_set(device_t *state, uint8_t value) {
if (CURRENT_BOARD_IS_ACTIVE_OUTPUT) if (CURRENT_BOARD_IS_ACTIVE_OUTPUT)
state->config.output[BOARD_ROLE].screensaver.mode = value; state->config.output[BOARD_ROLE].screensaver.mode = value;
else else
@ -123,12 +123,18 @@ void mouse_zoom_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
/* When pressed, enables the screensaver on active output */ /* When pressed, enables the screensaver on active output */
void enable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) { void enable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
_screensaver_set(state, true); uint8_t desired_mode = state->config.output[BOARD_ROLE].screensaver.mode;
/* If the user explicitly asks for screensaver to be active, ignore config and turn it on */
if (desired_mode == DISABLED)
desired_mode = PONG;
_screensaver_set(state, desired_mode);
} }
/* When pressed, disables the screensaver on active output */ /* When pressed, disables the screensaver on active output */
void disable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) { void disable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
_screensaver_set(state, false); _screensaver_set(state, DISABLED);
} }
/* Put the device into a special configuration mode */ /* Put the device into a special configuration mode */

View File

@ -206,9 +206,10 @@ enum screen_pos_e {
}; };
enum screensaver_mode_e { enum screensaver_mode_e {
DISABLED = 0, DISABLED = 0,
PONG = 1, PONG = 1,
JITTER = 2, JITTER = 2,
MAX_SS_VAL = JITTER,
}; };
#define ITF_NUM_HID 0 #define ITF_NUM_HID 0

View File

@ -79,12 +79,9 @@ mouse_report_t *screensaver_pong(device_t *state) {
mouse_report_t *screensaver_jitter(device_t *state) { mouse_report_t *screensaver_jitter(device_t *state) {
const int16_t jitter_distance = 2; const int16_t jitter_distance = 2;
static mouse_report_t report = { static mouse_report_t report = {
.x = jitter_distance,
.y = jitter_distance, .y = jitter_distance,
.mode = RELATIVE, .mode = RELATIVE,
}; };
report.x = -report.x;
report.y = -report.y; report.y = -report.y;
return &report; return &report;
@ -92,7 +89,11 @@ mouse_report_t *screensaver_jitter(device_t *state) {
/* Have something fun and entertaining when idle. */ /* Have something fun and entertaining when idle. */
void screensaver_task(device_t *state) { void screensaver_task(device_t *state) {
const int mouse_move_delay = 5000; const uint32_t delays[] = {
0, /* DISABLED, unused index 0 */
5000, /* PONG, move mouse every 5 ms for a high framerate */
10000000, /* JITTER, once every 10 sec is more than enough */
};
static int last_pointer_move = 0; static int last_pointer_move = 0;
screensaver_t *screensaver = &state->config.output[BOARD_ROLE].screensaver; screensaver_t *screensaver = &state->config.output[BOARD_ROLE].screensaver;
uint64_t inactivity_period = time_us_64() - state->last_activity[BOARD_ROLE]; uint64_t inactivity_period = time_us_64() - state->last_activity[BOARD_ROLE];
@ -101,8 +102,8 @@ void screensaver_task(device_t *state) {
if (screensaver->mode == DISABLED) if (screensaver->mode == DISABLED)
return; return;
/* System is still not idle for long enough to activate or we've been running for too long */ /* System is still not idle for long enough to activate or screensaver mode is not supported */
if (inactivity_period < screensaver->idle_time_us) if (inactivity_period < screensaver->idle_time_us || screensaver->mode > MAX_SS_VAL)
return; return;
/* We exceeded the maximum permitted screensaver runtime */ /* We exceeded the maximum permitted screensaver runtime */
@ -115,7 +116,7 @@ void screensaver_task(device_t *state) {
return; return;
/* We're active! Now check if it's time to move the cursor yet. */ /* We're active! Now check if it's time to move the cursor yet. */
if ((time_us_32()) - last_pointer_move < mouse_move_delay) if (time_us_32() - last_pointer_move < delays[screensaver->mode])
return; return;
mouse_report_t *report; mouse_report_t *report;