Skip to content

Commit

Permalink
Inject main display events to the original display
Browse files Browse the repository at this point in the history
When mirroring a secondary display, touch and scroll events must be sent
to the mirroring virtual display id (with coordinates relative to the
virtual display size), rather than to the original display (with
coordinates relative to the original display size).

This behavior, introduced by d193967,
was also applied for the main display for consistency. However, it
causes some UI elements to become unclickable.

To minimize inconveniences, restore the previous behavior when mirroring
the main display: send all events to the original display id (0) with
coordinates relative to the original display size.

Fixes #5545 <#5545>
Fixes #5605 <#5605>
Fixes #5616 <#5616>
Refs #4598 <#4598>
Refs #5137 <#5137>
Refs #5370 <#5370>
PR #5614 <#5614>
  • Loading branch information
rom1v committed Dec 7, 2024
1 parent baa10ed commit 97fa77c
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,18 @@ public void start(Surface surface) throws IOException {
try {
virtualDisplay = ServiceManager.getDisplayManager()
.createVirtualDisplay("scrcpy", inputSize.getWidth(), inputSize.getHeight(), displayId, surface);
virtualDisplayId = virtualDisplay.getDisplay().getDisplayId();

// The positions are relative to the virtual display, not the original display (so use inputSize, not deviceSize!)
positionMapper = PositionMapper.create(videoSize, transform, inputSize);

if (displayId == 0) {
// Main display: send all events to the original display, relative to the device size
Size deviceSize = displayInfo.getSize();
positionMapper = PositionMapper.create(videoSize, transform, deviceSize);
virtualDisplayId = 0;
} else {
// The positions are relative to the virtual display, not the original display (so use inputSize, not deviceSize!)
positionMapper = PositionMapper.create(videoSize, transform, inputSize);
virtualDisplayId = virtualDisplay.getDisplay().getDisplayId();
}
Ln.d("Display: using DisplayManager API");
} catch (Exception displayManagerException) {
try {
Expand Down

0 comments on commit 97fa77c

Please sign in to comment.