-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(macos/input): incorrect mouse input for non-main display #2461
Changes from 24 commits
a161573
59c3978
81cf98f
4d079a4
ecc86b8
79326e1
50f47d5
1bc0b2c
6a377ec
7286502
22762e7
a3c3f01
e9dd2aa
70447d6
a23b491
ee4014b
32f5c1c
8a6b0bb
a755c7e
dcbaae6
111e6de
75f48f5
9f44d3e
98d0dea
4d89d73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before we support change the display we need to capture in macOS, the location we get here according to Apple Document should be |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,15 +328,19 @@ | |
auto display = macos_input->display; | ||
auto event = macos_input->mouse_event; | ||
|
||
if (location.x < 0) | ||
location.x = 0; | ||
if (location.x >= (double) CGDisplayPixelsWide(display)) | ||
location.x = (double) CGDisplayPixelsWide(display) - 1; | ||
// get display bounds for current display | ||
CGRect display_bounds = CGDisplayBounds(display); | ||
|
||
if (location.y < 0) | ||
location.y = 0; | ||
if (location.y >= (double) CGDisplayPixelsHigh(display)) | ||
location.y = (double) CGDisplayPixelsHigh(display) - 1; | ||
// limit mouse to current display bounds | ||
if (location.x < display_bounds.origin.x) | ||
location.x = display_bounds.origin.x; | ||
if (location.x >= display_bounds.origin.x + display_bounds.size.width) | ||
location.x = display_bounds.origin.x + display_bounds.size.width - 1; | ||
TimmyOVO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (location.y < display_bounds.origin.y) | ||
location.y = display_bounds.origin.y; | ||
if (location.y >= display_bounds.origin.y + display_bounds.size.height) | ||
location.y = display_bounds.origin.y + display_bounds.size.height - 1; | ||
|
||
CGEventSetType(event, type); | ||
CGEventSetLocation(event, location); | ||
|
@@ -379,10 +383,15 @@ | |
|
||
void | ||
abs_mouse(input_t &input, const touch_port_t &touch_port, float x, float y) { | ||
auto scaling = ((macos_input_t *) input.get())->displayScaling; | ||
auto macos_input = static_cast<macos_input_t *>(input.get()); | ||
auto scaling = macos_input->displayScaling; | ||
auto display = macos_input->display; | ||
|
||
CGPoint location = CGPointMake(x * scaling, y * scaling); | ||
|
||
CGRect display_bounds = CGDisplayBounds(display); | ||
// in order to get the correct mouse location for capturing display , we need to add the display bounds to the location | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The location we received are relative to the display we are capturing ,so we get the display bounds using CGDisplayBounds then add them up to get the right input coordinates. |
||
location.x += display_bounds.origin.x; | ||
location.y += display_bounds.origin.y; | ||
post_mouse(input, kCGMouseButtonLeft, event_type_mouse(input), location, 0); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this commit, there is a change that would require both env_width and env_height to have non-zero values, but these values are not properly set in that commit, which could break absolute mouse input on macOS.