Merge pull request #179 from eltariel/macos-screen-switch

Tweak macos screen switch helper
This commit is contained in:
Hrvoje Čavrak 2024-11-27 20:08:08 +01:00 committed by GitHub
commit cbb98e4a88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 8 deletions

View File

@ -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 */
@ -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 */
@ -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:
@ -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