mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-09-01 15:15:44 +00:00
Merge commands with other control events
Several commands were grouped under the same event type "command", with a separate field to indicate the actual command. Move these commands at the same level as other control events. It will allow to implement commands with arguments.
This commit is contained in:
parent
3b4366e5bf
commit
63909fd10d
6 changed files with 29 additions and 60 deletions
|
@ -9,16 +9,14 @@ public final class ControlEvent {
|
|||
public static final int TYPE_TEXT = 1;
|
||||
public static final int TYPE_MOUSE = 2;
|
||||
public static final int TYPE_SCROLL = 3;
|
||||
public static final int TYPE_COMMAND = 4;
|
||||
|
||||
public static final int COMMAND_BACK_OR_SCREEN_ON = 0;
|
||||
public static final int COMMAND_EXPAND_NOTIFICATION_PANEL = 1;
|
||||
public static final int COMMAND_COLLAPSE_NOTIFICATION_PANEL = 2;
|
||||
public static final int TYPE_BACK_OR_SCREEN_ON = 4;
|
||||
public static final int TYPE_EXPAND_NOTIFICATION_PANEL = 5;
|
||||
public static final int TYPE_COLLAPSE_NOTIFICATION_PANEL = 6;
|
||||
|
||||
private int type;
|
||||
private String text;
|
||||
private int metaState; // KeyEvent.META_*
|
||||
private int action; // KeyEvent.ACTION_* or MotionEvent.ACTION_* or COMMAND_*
|
||||
private int action; // KeyEvent.ACTION_* or MotionEvent.ACTION_*
|
||||
private int keycode; // KeyEvent.KEYCODE_*
|
||||
private int buttons; // MotionEvent.BUTTON_*
|
||||
private Position position;
|
||||
|
@ -62,10 +60,9 @@ public final class ControlEvent {
|
|||
return event;
|
||||
}
|
||||
|
||||
public static ControlEvent createCommandControlEvent(int action) {
|
||||
public static ControlEvent createSimpleControlEvent(int type) {
|
||||
ControlEvent event = new ControlEvent();
|
||||
event.type = TYPE_COMMAND;
|
||||
event.action = action;
|
||||
event.type = type;
|
||||
return event;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ public class ControlEventReader {
|
|||
private static final int KEYCODE_PAYLOAD_LENGTH = 9;
|
||||
private static final int MOUSE_PAYLOAD_LENGTH = 17;
|
||||
private static final int SCROLL_PAYLOAD_LENGTH = 20;
|
||||
private static final int COMMAND_PAYLOAD_LENGTH = 1;
|
||||
|
||||
public static final int TEXT_MAX_LENGTH = 300;
|
||||
private static final int RAW_BUFFER_SIZE = 1024;
|
||||
|
@ -64,8 +63,10 @@ public class ControlEventReader {
|
|||
case ControlEvent.TYPE_SCROLL:
|
||||
controlEvent = parseScrollControlEvent();
|
||||
break;
|
||||
case ControlEvent.TYPE_COMMAND:
|
||||
controlEvent = parseCommandControlEvent();
|
||||
case ControlEvent.TYPE_BACK_OR_SCREEN_ON:
|
||||
case ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
case ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||
controlEvent = ControlEvent.createSimpleControlEvent(type);
|
||||
break;
|
||||
default:
|
||||
Ln.w("Unknown event type: " + type);
|
||||
|
@ -123,14 +124,6 @@ public class ControlEventReader {
|
|||
return ControlEvent.createScrollControlEvent(position, hScroll, vScroll);
|
||||
}
|
||||
|
||||
private ControlEvent parseCommandControlEvent() {
|
||||
if (buffer.remaining() < COMMAND_PAYLOAD_LENGTH) {
|
||||
return null;
|
||||
}
|
||||
int action = toUnsigned(buffer.get());
|
||||
return ControlEvent.createCommandControlEvent(action);
|
||||
}
|
||||
|
||||
private static Position readPosition(ByteBuffer buffer) {
|
||||
int x = buffer.getInt();
|
||||
int y = buffer.getInt();
|
||||
|
|
|
@ -77,8 +77,14 @@ public class EventController {
|
|||
case ControlEvent.TYPE_SCROLL:
|
||||
injectScroll(controlEvent.getPosition(), controlEvent.getHScroll(), controlEvent.getVScroll());
|
||||
break;
|
||||
case ControlEvent.TYPE_COMMAND:
|
||||
executeCommand(controlEvent.getAction());
|
||||
case ControlEvent.TYPE_BACK_OR_SCREEN_ON:
|
||||
pressBackOrTurnScreenOn();
|
||||
break;
|
||||
case ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
device.expandNotificationPanel();
|
||||
break;
|
||||
case ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||
device.collapsePanels();
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
|
@ -170,20 +176,4 @@ public class EventController {
|
|||
int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER;
|
||||
return injectKeycode(keycode);
|
||||
}
|
||||
|
||||
private boolean executeCommand(int action) {
|
||||
switch (action) {
|
||||
case ControlEvent.COMMAND_BACK_OR_SCREEN_ON:
|
||||
return pressBackOrTurnScreenOn();
|
||||
case ControlEvent.COMMAND_EXPAND_NOTIFICATION_PANEL:
|
||||
device.expandNotificationPanel();
|
||||
return true;
|
||||
case ControlEvent.COMMAND_COLLAPSE_NOTIFICATION_PANEL:
|
||||
device.collapsePanels();
|
||||
return true;
|
||||
default:
|
||||
Ln.w("Unsupported command: " + action);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue