mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-04-21 01:33:36 +00:00
Inject display-related events to virtual display
Mouse and touch events must be sent to the virtual display id (used for mirroring), other events (like key events) must be sent to the original display id. Fixes #4598 <https://github.com/Genymobile/scrcpy/issues/4598> Fixes #5137 <https://github.com/Genymobile/scrcpy/issues/5137> PR #5370 <https://github.com/Genymobile/scrcpy/pull/5370> Co-authored-by: nightmare <mengyanshou@gmail.com>
This commit is contained in:
parent
7024d38199
commit
d19396718e
3 changed files with 56 additions and 31 deletions
|
|
@ -106,10 +106,16 @@ public class ScreenCapture extends SurfaceCapture {
|
|||
virtualDisplay = null;
|
||||
}
|
||||
|
||||
int virtualDisplayId;
|
||||
PositionMapper positionMapper;
|
||||
try {
|
||||
Size videoSize = screenInfo.getVideoSize();
|
||||
virtualDisplay = ServiceManager.getDisplayManager()
|
||||
.createVirtualDisplay("scrcpy", videoSize.getWidth(), videoSize.getHeight(), displayId, surface);
|
||||
virtualDisplayId = virtualDisplay.getDisplay().getDisplayId();
|
||||
Rect contentRect = new Rect(0, 0, videoSize.getWidth(), videoSize.getHeight());
|
||||
// The position are relative to the virtual display, not the original display
|
||||
positionMapper = new PositionMapper(videoSize, contentRect, 0);
|
||||
Ln.d("Display: using DisplayManager API");
|
||||
} catch (Exception displayManagerException) {
|
||||
try {
|
||||
|
|
@ -123,6 +129,8 @@ public class ScreenCapture extends SurfaceCapture {
|
|||
int layerStack = displayInfo.getLayerStack();
|
||||
|
||||
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
|
||||
virtualDisplayId = displayId;
|
||||
positionMapper = PositionMapper.from(screenInfo);
|
||||
Ln.d("Display: using SurfaceControl API");
|
||||
} catch (Exception surfaceControlException) {
|
||||
Ln.e("Could not create display using DisplayManager", displayManagerException);
|
||||
|
|
@ -132,8 +140,7 @@ public class ScreenCapture extends SurfaceCapture {
|
|||
}
|
||||
|
||||
if (vdListener != null) {
|
||||
PositionMapper positionMapper = PositionMapper.from(screenInfo);
|
||||
vdListener.onNewVirtualDisplay(positionMapper);
|
||||
vdListener.onNewVirtualDisplay(virtualDisplayId, positionMapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue