-
-
Notifications
You must be signed in to change notification settings - Fork 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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a161573
Complete output_name implementation in macos to select a different m…
TimmyOVO 59c3978
Update locale for both en.json and en_GB.json
TimmyOVO 81cf98f
Improved detected displays startup log format (now every display has …
TimmyOVO 4d079a4
Update macOS output_name doc
TimmyOVO ecc86b8
Update macOS output_name example doc
TimmyOVO 79326e1
Merge branch 'nightly' into nightly
TimmyOVO 50f47d5
Reordered some entries & locale cleanup.
TimmyOVO 1bc0b2c
Merge remote-tracking branch 'origin/nightly' into nightly
TimmyOVO 6a377ec
Unify startup display detection log format in macOS and Linux
TimmyOVO 7286502
Merge output_name doc Linux and macOS section into one.
TimmyOVO 22762e7
Update config.html to match the macOS & Linux display detection code.
TimmyOVO a3c3f01
Merge macOS and linux output_name config ui into one.
TimmyOVO e9dd2aa
Merge branch 'nightly' into nightly
TimmyOVO 70447d6
Separated output_name linux and macos in doc examples and config ui
TimmyOVO a23b491
Merge remote-tracking branch 'origin/nightly' into nightly
TimmyOVO ee4014b
Merge branch 'nightly' into nightly
TimmyOVO 32f5c1c
SUNSHINE_EXTERNAL_LIBRARIES in macos reordered.
TimmyOVO 8a6b0bb
Merge remote-tracking branch 'origin/nightly' into nightly
TimmyOVO a755c7e
doc spacing issue fixed.
TimmyOVO dcbaae6
Merge branch 'LizardByte:nightly' into nightly
TimmyOVO 111e6de
fix: abs mouse input not working in macOS
TimmyOVO 75f48f5
Merge remote-tracking branch 'origin/nightly' into nightly
TimmyOVO 9f44d3e
reformat using clang-format
TimmyOVO 98d0dea
Merge branch 'nightly' into nightly
TimmyOVO 4d89d73
use std::clamp instead of if statement.
TimmyOVO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,15 +328,12 @@ | |
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 | ||
location.x = std::clamp(location.x, display_bounds.origin.x, display_bounds.origin.x + display_bounds.size.width - 1); | ||
location.y = std::clamp(location.y, display_bounds.origin.y, display_bounds.origin.y + display_bounds.size.height - 1); | ||
|
||
CGEventSetType(event, type); | ||
CGEventSetLocation(event, location); | ||
|
@@ -379,10 +376,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); | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Before we support change the display we need to capture in macOS, the location we get here according to Apple Document should be
The current location of the specified mouse event in global display coordinates
, we can not just simply assuming the display's bounds to[0,display_width]
and[0,display_height]
. So we need to get the correspond display bounds for display we are capturing usingCGDisplayBounds
which returnThe bounds of the display, expressed as a rectangle in the global display coordinate space (relative to the upper-left corner of the main display).
.