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..8770412 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); @@ -147,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) { @@ -200,6 +213,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 */