This commit is contained in:
bartsaintgermain 2025-04-16 06:27:56 +02:00 committed by GitHub
commit 4e67916410
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 15 deletions

View file

@ -165,7 +165,7 @@ sdl_configure(bool video_playback, bool disable_screensaver) {
}
static enum scrcpy_exit_code
event_loop(struct scrcpy *s) {
event_loop(struct scrcpy *s, bool has_screen) {
SDL_Event event;
while (SDL_WaitEvent(&event)) {
switch (event.type) {
@ -197,7 +197,7 @@ event_loop(struct scrcpy *s) {
break;
}
default:
if (!sc_screen_handle_event(&s->screen, &event)) {
if (has_screen && !sc_screen_handle_event(&s->screen, &event)) {
return SCRCPY_EXIT_FAILURE;
}
break;
@ -933,7 +933,7 @@ aoa_complete:
}
}
ret = event_loop(s);
ret = event_loop(s, options->window);
terminate_event_loop();
LOGD("quit...");

View file

@ -40,6 +40,7 @@ public class Options {
private Rect crop;
private boolean control = true;
private int displayId;
private int injectMode = Device.INJECT_MODE_ASYNC;
private String cameraId;
private Size cameraSize;
private CameraFacing cameraFacing;
@ -152,6 +153,10 @@ public class Options {
return displayId;
}
public int getInjectMode() {
return injectMode;
}
public String getCameraId() {
return cameraId;
}
@ -387,6 +392,9 @@ public class Options {
case "display_id":
options.displayId = Integer.parseInt(value);
break;
case "inject_mode":
options.injectMode = Integer.parseInt(value);
break;
case "show_touches":
options.showTouches = Boolean.parseBoolean(value);
break;

View file

@ -82,6 +82,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
private final DeviceMessageSender sender;
private final boolean clipboardAutosync;
private final boolean powerOn;
private int injectMode = Device.INJECT_MODE_ASYNC;
private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
@ -102,6 +103,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
public Controller(ControlChannel controlChannel, CleanUp cleanUp, Options options) {
this.displayId = options.getDisplayId();
this.injectMode = options.getInjectMode();
this.controlChannel = controlChannel;
this.cleanUp = cleanUp;
this.clipboardAutosync = options.getClipboardAutosync();
@ -178,7 +180,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
private void control() throws IOException {
// on start, power on the device
if (powerOn && displayId == 0 && !Device.isScreenOn(displayId)) {
Device.pressReleaseKeycode(KeyEvent.KEYCODE_POWER, displayId, Device.INJECT_MODE_ASYNC);
Device.pressReleaseKeycode(KeyEvent.KEYCODE_POWER, displayId, this.injectMode);
// dirty hack
// After POWER is injected, the device is powered on asynchronously.
@ -319,7 +321,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
assert displayId != Device.DISPLAY_ID_NONE;
scheduleDisplayPowerOff(displayId);
}
return injectKeyEvent(action, keycode, repeat, metaState, Device.INJECT_MODE_ASYNC);
return injectKeyEvent(action, keycode, repeat, metaState, this.injectMode);
}
private boolean injectChar(char c) {
@ -332,7 +334,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
int actionDisplayId = getActionDisplayId();
for (KeyEvent event : events) {
if (!Device.injectEvent(event, actionDisplayId, Device.INJECT_MODE_ASYNC)) {
if (!Device.injectEvent(event, actionDisplayId, this.injectMode)) {
return false;
}
}
@ -445,7 +447,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
// First button pressed: ACTION_DOWN
MotionEvent downEvent = MotionEvent.obtain(lastTouchDown, now, MotionEvent.ACTION_DOWN, pointerCount, pointerProperties,
pointerCoords, 0, buttons, 1f, 1f, DEFAULT_DEVICE_ID, 0, source, 0);
if (!Device.injectEvent(downEvent, targetDisplayId, Device.INJECT_MODE_ASYNC)) {
if (!Device.injectEvent(downEvent, targetDisplayId, this.injectMode)) {
return false;
}
}
@ -456,7 +458,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
if (!InputManager.setActionButton(pressEvent, actionButton)) {
return false;
}
if (!Device.injectEvent(pressEvent, targetDisplayId, Device.INJECT_MODE_ASYNC)) {
if (!Device.injectEvent(pressEvent, targetDisplayId, this.injectMode)) {
return false;
}
@ -470,7 +472,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
if (!InputManager.setActionButton(releaseEvent, actionButton)) {
return false;
}
if (!Device.injectEvent(releaseEvent, targetDisplayId, Device.INJECT_MODE_ASYNC)) {
if (!Device.injectEvent(releaseEvent, targetDisplayId, this.injectMode)) {
return false;
}
@ -478,7 +480,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
// Last button released: ACTION_UP
MotionEvent upEvent = MotionEvent.obtain(lastTouchDown, now, MotionEvent.ACTION_UP, pointerCount, pointerProperties,
pointerCoords, 0, buttons, 1f, 1f, DEFAULT_DEVICE_ID, 0, source, 0);
if (!Device.injectEvent(upEvent, targetDisplayId, Device.INJECT_MODE_ASYNC)) {
if (!Device.injectEvent(upEvent, targetDisplayId, this.injectMode)) {
return false;
}
}
@ -489,7 +491,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
MotionEvent event = MotionEvent.obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f,
DEFAULT_DEVICE_ID, 0, source, 0);
return Device.injectEvent(event, targetDisplayId, Device.INJECT_MODE_ASYNC);
return Device.injectEvent(event, targetDisplayId, this.injectMode);
}
private boolean injectScroll(Position position, float hScroll, float vScroll, int buttons) {
@ -514,7 +516,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
MotionEvent event = MotionEvent.obtain(lastTouchDown, now, MotionEvent.ACTION_SCROLL, 1, pointerProperties, pointerCoords, 0, buttons, 1f, 1f,
DEFAULT_DEVICE_ID, 0, InputDevice.SOURCE_MOUSE, 0);
return Device.injectEvent(event, targetDisplayId, Device.INJECT_MODE_ASYNC);
return Device.injectEvent(event, targetDisplayId, this.injectMode);
}
/**
@ -529,7 +531,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
private boolean pressBackOrTurnScreenOn(int action) {
if (displayId == Device.DISPLAY_ID_NONE || Device.isScreenOn(displayId)) {
return injectKeyEvent(action, KeyEvent.KEYCODE_BACK, 0, 0, Device.INJECT_MODE_ASYNC);
return injectKeyEvent(action, KeyEvent.KEYCODE_BACK, 0, 0, this.injectMode);
}
// Screen is off
@ -543,7 +545,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
assert displayId != Device.DISPLAY_ID_NONE;
scheduleDisplayPowerOff(displayId);
}
return pressReleaseKeycode(KeyEvent.KEYCODE_POWER, Device.INJECT_MODE_ASYNC);
return pressReleaseKeycode(KeyEvent.KEYCODE_POWER, this.injectMode);
}
private void getClipboard(int copyKey) {
@ -576,7 +578,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
// On Android >= 7, also press the PASTE key if requested
if (paste && Build.VERSION.SDK_INT >= AndroidVersions.API_24_ANDROID_7_0 && supportsInputEvents) {
pressReleaseKeycode(KeyEvent.KEYCODE_PASTE, Device.INJECT_MODE_ASYNC);
pressReleaseKeycode(KeyEvent.KEYCODE_PASTE, this.injectMode);
}
if (sequence != ControlMessage.SEQUENCE_INVALID) {