From 06692090898484cb5fd8ff6502a289b051e4763a Mon Sep 17 00:00:00 2001 From: AsocPro Date: Tue, 25 Feb 2025 13:09:59 -0700 Subject: [PATCH 1/3] Allow detection of switch needed on all four edges --- src/include/structs.h | 2 ++ src/mouse.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/include/structs.h b/src/include/structs.h index 82067ac..0797a34 100644 --- a/src/include/structs.h +++ b/src/include/structs.h @@ -167,6 +167,8 @@ enum screen_pos_e { LEFT = 1, RIGHT = 2, MIDDLE = 3, + TOP = 4, + BOTTOM = 5, }; enum screensaver_mode_e { diff --git a/src/mouse.c b/src/mouse.c index a46962a..0e9bef7 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -15,13 +15,19 @@ #define MACOS_SWITCH_MOVE_COUNT 5 /* Check if our upcoming mouse movement would result in having to switch outputs */ -enum screen_pos_e is_screen_switch_needed(int position, int offset) { - if (position + offset < MIN_SCREEN_COORD - global_state.config.jump_threshold) +enum screen_pos_e is_screen_switch_needed(int position_x, int offset_x, int position_y, int offset_y) { + if (position_x + offset_x < MIN_SCREEN_COORD - global_state.config.jump_threshold) return LEFT; - if (position + offset > MAX_SCREEN_COORD + global_state.config.jump_threshold) + if (position_x + offset_x > MAX_SCREEN_COORD + global_state.config.jump_threshold) return RIGHT; + if (position_y + offset_y < MIN_SCREEN_COORD - global_state.config.jump_threshold) + return TOP; + + if (position_y + offset_y > MAX_SCREEN_COORD + global_state.config.jump_threshold) + return BOTTOM; + return NONE; } @@ -82,7 +88,7 @@ enum screen_pos_e update_mouse_position(device_t *state, mouse_values_t *values) int offset_y = accelerate(values->move_y) * (current->speed_y >> reduce_speed); /* Determine if our upcoming movement would stay within the screen */ - enum screen_pos_e switch_direction = is_screen_switch_needed(state->pointer_x, offset_x); + enum screen_pos_e switch_direction = is_screen_switch_needed(state->pointer_x, offset_x, state->pointer_y, offset_y); /* Update movement */ state->pointer_x = move_and_keep_on_screen(state->pointer_x, offset_x); From 80752123e540ec0b6ce1eeae8d6bb10a7c442dfe Mon Sep 17 00:00:00 2001 From: AsocPro Date: Tue, 25 Feb 2025 22:17:29 -0700 Subject: [PATCH 2/3] Ignore top and bottom switches when switching screens --- src/mouse.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mouse.c b/src/mouse.c index 0e9bef7..1bb96a2 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -206,6 +206,10 @@ void do_screen_switch(device_t *state, int direction) { if (state->switch_lock || state->gaming_mode) return; + /* ignore top and bottem switches to match the default left/right linear configuration */ + if (direction == TOP || direction == BOTTOM) + return; + /* We want to jump in the direction of the other computer */ if (output->pos != direction) { if (output->screen_index == 1) { /* We are at the border -> switch outputs */ From 12677e7629b16d73c45280c6dfda92f58be6f0a2 Mon Sep 17 00:00:00 2001 From: AsocPro Date: Tue, 25 Feb 2025 23:08:35 -0700 Subject: [PATCH 3/3] More properly place the cursor when switching vertically --- src/mouse.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index 1bb96a2..8770412 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -153,8 +153,15 @@ void switch_to_another_pc( output_mouse_report(&hidden_pointer, state); set_active_output(state, output_to); - state->pointer_x = (direction == LEFT) ? MAX_SCREEN_COORD : MIN_SCREEN_COORD; - state->pointer_y = scale_y_coordinate(output->number, 1 - output->number, state); + + if (direction == LEFT || direction == RIGHT) { + state->pointer_x = (direction == LEFT) ? MAX_SCREEN_COORD : MIN_SCREEN_COORD; + state->pointer_y = scale_y_coordinate(output->number, 1 - output->number, state); + } + else { + state->pointer_y = (direction == TOP) ? MAX_SCREEN_COORD : MIN_SCREEN_COORD; + /* x scaling not currently supported */ + } } void switch_virtual_desktop_macos(device_t *state, int direction) {