diff --git a/CMakeLists.txt b/CMakeLists.txt index bfd4016..5c602e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/handlers.c b/src/handlers.c index 838ea6a..edfd91f 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -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 @@ -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 */ diff --git a/src/include/main.h b/src/include/main.h index bb72223..9849709 100644 --- a/src/include/main.h +++ b/src/include/main.h @@ -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 diff --git a/src/tasks.c b/src/tasks.c index 49d1ad7..2726bd5 100644 --- a/src/tasks.c +++ b/src/tasks.c @@ -79,12 +79,9 @@ 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; @@ -92,7 +89,11 @@ mouse_report_t *screensaver_jitter(device_t *state) { /* 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]; @@ -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 */ @@ -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;