@@ -124,35 +124,17 @@ public void start(Surface surface) throws IOException {
124
124
inputSize = videoSize ;
125
125
}
126
126
127
- int virtualDisplayId ;
128
- PositionMapper positionMapper ;
129
127
try {
130
128
virtualDisplay = ServiceManager .getDisplayManager ()
131
129
.createVirtualDisplay ("scrcpy" , inputSize .getWidth (), inputSize .getHeight (), displayId , surface );
132
-
133
-
134
- if (displayId == 0 ) {
135
- // Main display: send all events to the original display, relative to the device size
136
- Size deviceSize = displayInfo .getSize ();
137
- positionMapper = PositionMapper .create (videoSize , transform , deviceSize );
138
- virtualDisplayId = 0 ;
139
- } else {
140
- // The positions are relative to the virtual display, not the original display (so use inputSize, not deviceSize!)
141
- positionMapper = PositionMapper .create (videoSize , transform , inputSize );
142
- virtualDisplayId = virtualDisplay .getDisplay ().getDisplayId ();
143
- }
144
130
Ln .d ("Display: using DisplayManager API" );
145
131
} catch (Exception displayManagerException ) {
146
132
try {
147
133
display = createDisplay ();
148
134
149
135
Size deviceSize = displayInfo .getSize ();
150
136
int layerStack = displayInfo .getLayerStack ();
151
-
152
137
setDisplaySurface (display , surface , deviceSize .toRect (), inputSize .toRect (), layerStack );
153
- virtualDisplayId = displayId ;
154
-
155
- positionMapper = PositionMapper .create (videoSize , transform , deviceSize );
156
138
Ln .d ("Display: using SurfaceControl API" );
157
139
} catch (Exception surfaceControlException ) {
158
140
Ln .e ("Could not create display using DisplayManager" , displayManagerException );
@@ -162,6 +144,18 @@ public void start(Surface surface) throws IOException {
162
144
}
163
145
164
146
if (vdListener != null ) {
147
+ int virtualDisplayId ;
148
+ PositionMapper positionMapper ;
149
+ if (virtualDisplay == null || displayId == 0 ) {
150
+ // Surface control or main display: send all events to the original display, relative to the device size
151
+ Size deviceSize = displayInfo .getSize ();
152
+ positionMapper = PositionMapper .create (videoSize , transform , deviceSize );
153
+ virtualDisplayId = displayId ;
154
+ } else {
155
+ // The positions are relative to the virtual display, not the original display (so use inputSize, not deviceSize!)
156
+ positionMapper = PositionMapper .create (videoSize , transform , inputSize );
157
+ virtualDisplayId = virtualDisplay .getDisplay ().getDisplayId ();
158
+ }
165
159
vdListener .onNewVirtualDisplay (virtualDisplayId , positionMapper );
166
160
}
167
161
}
0 commit comments