Skip to content

Commit 6ef3d7b

Browse files
authored
Merge pull request #227 from rygwdn/macos-screen-switch
fix transition between screens of different sizes on macos.
2 parents 00e109c + 3198ed7 commit 6ef3d7b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/mouse.c

+20-3
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,27 @@ void switch_to_another_pc(
179179
}
180180

181181
void switch_virtual_desktop_macos(device_t *state, int direction) {
182-
/* Fix for MACOS: Send relative mouse movement here, one or two pixels in the
183-
direction of movement, BEFORE absolute report sets X to 0 */
182+
/*
183+
* Fix for MACOS: Before sending new absolute report setting X to 0:
184+
* 1. Move the cursor to the edge of the screen directly in the middle to handle screens
185+
* of different heights
186+
* 2. Send relative mouse movement one or two pixels in the direction of movement to get
187+
* the cursor onto the next screen
188+
*/
189+
mouse_report_t edge_position = {
190+
.x = (direction == LEFT) ? MIN_SCREEN_COORD : MAX_SCREEN_COORD,
191+
.y = MAX_SCREEN_COORD / 2,
192+
.mode = ABSOLUTE,
193+
.buttons = state->mouse_buttons,
194+
};
195+
184196
uint16_t move = (direction == LEFT) ? -MACOS_SWITCH_MOVE_X : MACOS_SWITCH_MOVE_X;
185-
mouse_report_t move_relative_one = {.x = move, .mode = RELATIVE};
197+
mouse_report_t move_relative_one = {
198+
.x = move,
199+
.mode = RELATIVE,
200+
};
201+
202+
output_mouse_report(&edge_position, state);
186203

187204
/* Once doesn't seem reliable enough, do it a few times */
188205
for (int i = 0; i < MACOS_SWITCH_MOVE_COUNT; i++)

0 commit comments

Comments
 (0)