From ff70bdafb57f3f60878d93654c49c4f9e7e7ddce Mon Sep 17 00:00:00 2001 From: Ellie T Date: Wed, 27 Nov 2024 21:40:30 +1100 Subject: [PATCH] Tweak macos screen switch helper - Increase relative mouse movement to over one screen pixel in most resolutions - Extract MacOS desktop switch helper to its own function - Clean up unused parameters in top-level desktop switch --- src/mouse.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index 7e8e30e..e49850a 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -17,6 +17,9 @@ #include "main.h" +#define MACOS_SWITCH_MOVE_X 10 +#define MACOS_SWITCH_MOVE_COUNT 5 + /* Move mouse coordinate 'position' by 'offset', but don't fall off the screen */ int32_t move_and_keep_on_screen(int position, int offset) { /* Lowest we can go is 0 */ @@ -122,7 +125,7 @@ int16_t scale_y_coordinate(int screen_from, int screen_to, device_t *state) { } void switch_screen( - device_t *state, output_t *output, int new_x, int output_from, int output_to, int direction) { + device_t *state, output_t *output, int output_to, int direction) { uint8_t *mouse_park_pos = &state->config.output[state->active_output].mouse_park_pos; int16_t mouse_y = (*mouse_park_pos == 0) ? MIN_SCREEN_COORD : /* Top */ @@ -137,17 +140,24 @@ void switch_screen( state->pointer_y = scale_y_coordinate(output->number, 1 - output->number, state); } -void switch_desktop(device_t *state, output_t *output, int new_index, int direction) { +#define MACOS_SWITCH_MOVE_X 10 +#define MACOS_SWITCH_MOVE_COUNT 5 + +void switch_desktop_macos(device_t *state, int direction) { /* Fix for MACOS: Send relative mouse movement here, one or two pixels in the direction of movement, BEFORE absolute report sets X to 0 */ - mouse_report_t move_relative_one - = {.x = (direction == LEFT) ? -5 : 5, .mode = RELATIVE}; + uint16_t move = (direction == LEFT) ? -MACOS_SWITCH_MOVE_X : MACOS_SWITCH_MOVE_X; + mouse_report_t move_relative_one = {.x = move, .mode = RELATIVE}; + /* Once doesn't seem reliable enough, do it a few times */ + for (int i = 0; i < MACOS_SWITCH_MOVE_COUNT; i++) + output_mouse_report(&move_relative_one, state); +} + +void switch_desktop(device_t *state, output_t *output, int new_index, int direction) { switch (output->os) { case MACOS: - /* Once doesn't seem reliable enough, do it a few times */ - for (int i = 0; i < 5; i++) - output_mouse_report(&move_relative_one, state); + switch_desktop_macos(state, direction); break; case WINDOWS: @@ -199,7 +209,7 @@ void check_screen_switch(const mouse_values_t *values, device_t *state) { if (state->mouse_buttons) return; - switch_screen(state, output, new_x, state->active_output, 1 - state->active_output, direction); + switch_screen(state, output, 1 - state->active_output, direction); } /* If here, this output has multiple desktops and we are not on the main one */ else