mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-20 19:45:00 +00:00
Added and utilized screen_on_only
field to BACK_OR_SCREEN_ON
control message.
This commit is contained in:
parent
ea63e7c279
commit
f61ef531f6
8 changed files with 40 additions and 5 deletions
|
@ -78,6 +78,8 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
|||
buf[1] = msg->set_screen_power_mode.mode;
|
||||
return 2;
|
||||
case CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
||||
buf[1] = !!msg->back_or_screen_on.screen_on_only;
|
||||
return 2;
|
||||
case CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
case CONTROL_MSG_TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||
case CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
||||
|
|
|
@ -63,6 +63,9 @@ struct control_msg {
|
|||
int32_t hscroll;
|
||||
int32_t vscroll;
|
||||
} inject_scroll_event;
|
||||
struct {
|
||||
bool screen_on_only;
|
||||
} back_or_screen_on;
|
||||
struct {
|
||||
char *text; // owned, to be freed by SDL_free()
|
||||
bool paste;
|
||||
|
|
|
@ -194,8 +194,8 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
|
|||
case SDL_ACTIVEEVENT:
|
||||
if (options->auto_turn_on && event->gain == 1) {
|
||||
struct control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
|
||||
msg.set_screen_power_mode.mode = SCREEN_POWER_MODE_NORMAL;
|
||||
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
||||
msg.back_or_screen_on.screen_on_only = true;
|
||||
|
||||
if (!controller_push_msg(&controller, &msg)) {
|
||||
LOGW("Could not request 'set screen power mode'");
|
||||
|
|
|
@ -144,14 +144,16 @@ static void test_serialize_inject_scroll_event(void) {
|
|||
static void test_serialize_back_or_screen_on(void) {
|
||||
struct control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||
.back_or_screen_on.screen_on_only = true,
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
int size = control_msg_serialize(&msg, buf);
|
||||
assert(size == 1);
|
||||
assert(size == 2);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||
1
|
||||
};
|
||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public final class ControlMessage {
|
|||
private int vScroll;
|
||||
private boolean paste;
|
||||
private int repeat;
|
||||
private boolean screenOnOnly;
|
||||
|
||||
private ControlMessage() {
|
||||
}
|
||||
|
@ -71,6 +72,13 @@ public final class ControlMessage {
|
|||
return msg;
|
||||
}
|
||||
|
||||
public static ControlMessage createBackOrScreenOn(boolean screenOnOnly) {
|
||||
ControlMessage msg = new ControlMessage();
|
||||
msg.type = TYPE_BACK_OR_SCREEN_ON;
|
||||
msg.screenOnOnly = screenOnOnly;
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static ControlMessage createSetClipboard(String text, boolean paste) {
|
||||
ControlMessage msg = new ControlMessage();
|
||||
msg.type = TYPE_SET_CLIPBOARD;
|
||||
|
@ -146,4 +154,8 @@ public final class ControlMessage {
|
|||
public int getRepeat() {
|
||||
return repeat;
|
||||
}
|
||||
|
||||
public boolean getScreenOnOnly() {
|
||||
return screenOnOnly;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ public class ControlMessageReader {
|
|||
static final int INJECT_KEYCODE_PAYLOAD_LENGTH = 13;
|
||||
static final int INJECT_TOUCH_EVENT_PAYLOAD_LENGTH = 27;
|
||||
static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
|
||||
static final int BACK_OR_SCREEN_ON_PAYLOAD_LENGTH = 1;
|
||||
static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;
|
||||
static final int SET_CLIPBOARD_FIXED_PAYLOAD_LENGTH = 1;
|
||||
|
||||
|
@ -73,6 +74,8 @@ public class ControlMessageReader {
|
|||
msg = parseSetScreenPowerMode();
|
||||
break;
|
||||
case ControlMessage.TYPE_BACK_OR_SCREEN_ON:
|
||||
msg = parseBackOrScreenOn();
|
||||
break;
|
||||
case ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
case ControlMessage.TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||
case ControlMessage.TYPE_GET_CLIPBOARD:
|
||||
|
@ -170,6 +173,14 @@ public class ControlMessageReader {
|
|||
return ControlMessage.createSetScreenPowerMode(mode);
|
||||
}
|
||||
|
||||
private ControlMessage parseBackOrScreenOn() {
|
||||
if (buffer.remaining() != BACK_OR_SCREEN_ON_PAYLOAD_LENGTH) {
|
||||
return null;
|
||||
}
|
||||
boolean screenOnOnly = buffer.get() != 0;
|
||||
return ControlMessage.createBackOrScreenOn(screenOnOnly);
|
||||
}
|
||||
|
||||
private static Position readPosition(ByteBuffer buffer) {
|
||||
int x = buffer.getInt();
|
||||
int y = buffer.getInt();
|
||||
|
|
|
@ -101,7 +101,7 @@ public class Controller {
|
|||
break;
|
||||
case ControlMessage.TYPE_BACK_OR_SCREEN_ON:
|
||||
if (device.supportsInputEvents()) {
|
||||
pressBackOrTurnScreenOn();
|
||||
pressBackOrTurnScreenOn(msg.getScreenOnOnly());
|
||||
}
|
||||
break;
|
||||
case ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
|
@ -247,7 +247,10 @@ public class Controller {
|
|||
}, 200, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private boolean pressBackOrTurnScreenOn() {
|
||||
private boolean pressBackOrTurnScreenOn(boolean screenOnOnly) {
|
||||
if (screenOnOnly && device.isScreenOn()) {
|
||||
return true;
|
||||
}
|
||||
int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER;
|
||||
if (keepPowerModeOff && keycode == KeyEvent.KEYCODE_POWER) {
|
||||
schedulePowerModeOff();
|
||||
|
|
|
@ -154,6 +154,7 @@ public class ControlMessageReaderTest {
|
|||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
dos.writeByte(ControlMessage.TYPE_BACK_OR_SCREEN_ON);
|
||||
dos.writeByte(1);
|
||||
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
|
@ -161,6 +162,7 @@ public class ControlMessageReaderTest {
|
|||
ControlMessage event = reader.next();
|
||||
|
||||
Assert.assertEquals(ControlMessage.TYPE_BACK_OR_SCREEN_ON, event.getType());
|
||||
Assert.assertEquals(true, event.getScreenOnOnly());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Reference in a new issue