Skip to content

Commit

Permalink
Merge pull request #179 from eltariel/macos-screen-switch
Browse files Browse the repository at this point in the history
Tweak macos screen switch helper
  • Loading branch information
hrvach authored Nov 27, 2024
2 parents 92baf1a + 9939903 commit cbb98e4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand All @@ -137,17 +140,21 @@ 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) {
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:
Expand Down Expand Up @@ -199,7 +206,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
Expand Down

0 comments on commit cbb98e4

Please sign in to comment.