Skip to content

Commit

Permalink
Use virtual device id to avoid NPE
Browse files Browse the repository at this point in the history
Inject mouse events using id -1 (virtual device) instead of 0 which
does not exist (and causes the InputDevice to be null).

Fixes <#962>
  • Loading branch information
rom1v committed Nov 29, 2019
1 parent 15a206b commit 26529d3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions server/src/main/java/com/genymobile/scrcpy/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

public class Controller {

private static final int DEVICE_ID_VIRTUAL = -1;

private final Device device;
private final DesktopConnection connection;
private final DeviceMessageSender sender;
Expand Down Expand Up @@ -174,8 +176,9 @@ private boolean injectTouch(int action, long pointerId, Position position, float
}
}

MotionEvent event = MotionEvent.obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, 0, 0,
InputDevice.SOURCE_TOUCHSCREEN, 0);
MotionEvent event = MotionEvent
.obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, DEVICE_ID_VIRTUAL, 0,
InputDevice.SOURCE_TOUCHSCREEN, 0);
return injectEvent(event);
}

Expand All @@ -196,8 +199,9 @@ private boolean injectScroll(Position position, int hScroll, int vScroll) {
coords.setAxisValue(MotionEvent.AXIS_HSCROLL, hScroll);
coords.setAxisValue(MotionEvent.AXIS_VSCROLL, vScroll);

MotionEvent event = MotionEvent.obtain(lastTouchDown, now, MotionEvent.ACTION_SCROLL, 1, pointerProperties, pointerCoords, 0, 0, 1f, 1f, 0, 0,
InputDevice.SOURCE_MOUSE, 0);
MotionEvent event = MotionEvent
.obtain(lastTouchDown, now, MotionEvent.ACTION_SCROLL, 1, pointerProperties, pointerCoords, 0, 0, 1f, 1f, DEVICE_ID_VIRTUAL, 0,
InputDevice.SOURCE_MOUSE, 0);
return injectEvent(event);
}

Expand Down

0 comments on commit 26529d3

Please sign in to comment.