Skip to content

Commit

Permalink
Fix screensaver issue with rapid movement.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrvoje Cavrak committed Dec 4, 2024
1 parent fa4ccdf commit d78bcd4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.6)

## Version Configuration
set(VERSION_MAJOR 00)
set(VERSION_MINOR 161)
set(VERSION_MINOR 162)

## Release Type Selection
option(DH_DEBUG "Build a debug version" OFF)
Expand Down
12 changes: 9 additions & 3 deletions src/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void _get_border_position(device_t *state, border_size_t *border) {
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)
state->config.output[BOARD_ROLE].screensaver.mode = value;
else
Expand Down Expand Up @@ -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 */
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 */
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 */
Expand Down
7 changes: 4 additions & 3 deletions src/include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ enum screen_pos_e {
};

enum screensaver_mode_e {
DISABLED = 0,
PONG = 1,
JITTER = 2,
DISABLED = 0,
PONG = 1,
JITTER = 2,
MAX_SS_VAL = JITTER,
};

#define ITF_NUM_HID 0
Expand Down
15 changes: 8 additions & 7 deletions src/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,21 @@ mouse_report_t *screensaver_pong(device_t *state) {
mouse_report_t *screensaver_jitter(device_t *state) {
const int16_t jitter_distance = 2;
static mouse_report_t report = {
.x = jitter_distance,
.y = jitter_distance,
.mode = RELATIVE,
};

report.x = -report.x;
report.y = -report.y;

return &report;
}

/* Have something fun and entertaining when idle. */
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;
screensaver_t *screensaver = &state->config.output[BOARD_ROLE].screensaver;
uint64_t inactivity_period = time_us_64() - state->last_activity[BOARD_ROLE];
Expand All @@ -101,8 +102,8 @@ void screensaver_task(device_t *state) {
if (screensaver->mode == DISABLED)
return;

/* System is still not idle for long enough to activate or we've been running for too long */
if (inactivity_period < screensaver->idle_time_us)
/* System is still not idle for long enough to activate or screensaver mode is not supported */
if (inactivity_period < screensaver->idle_time_us || screensaver->mode > MAX_SS_VAL)
return;

/* We exceeded the maximum permitted screensaver runtime */
Expand All @@ -115,7 +116,7 @@ void screensaver_task(device_t *state) {
return;

/* 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;

mouse_report_t *report;
Expand Down

0 comments on commit d78bcd4

Please sign in to comment.