Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/include/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ enum screen_pos_e {
LEFT = 1,
RIGHT = 2,
MIDDLE = 3,
TOP = 4,
BOTTOM = 5,
};

enum screensaver_mode_e {
Expand Down
29 changes: 23 additions & 6 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 */
Expand Down