mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-09-20 08:18:34 +00:00
Swap position/point names
A point is a 2D vector. A position represent a point relative to the screen size.
This commit is contained in:
parent
f70359f14f
commit
879941355d
15 changed files with 109 additions and 109 deletions
|
@ -27,7 +27,7 @@ SRC := com/genymobile/scrcpy/ScrCpyServer.java \
|
|||
com/genymobile/scrcpy/EventController.java \
|
||||
com/genymobile/scrcpy/Ln.java \
|
||||
com/genymobile/scrcpy/Point.java \
|
||||
com/genymobile/scrcpy/RawPoint.java \
|
||||
com/genymobile/scrcpy/Position.java \
|
||||
com/genymobile/scrcpy/ScreenInfo.java \
|
||||
com/genymobile/scrcpy/ScreenStreamer.java \
|
||||
com/genymobile/scrcpy/ScreenStreamerSession.java \
|
||||
|
|
|
@ -16,7 +16,7 @@ public class ControlEvent {
|
|||
private int action; // KeyEvent.ACTION_* or MotionEvent.ACTION_*
|
||||
private int keycode; // KeyEvent.KEYCODE_*
|
||||
private int buttons; // MotionEvent.BUTTON_*
|
||||
private Point point;
|
||||
private Position position;
|
||||
private int hScroll;
|
||||
private int vScroll;
|
||||
|
||||
|
@ -39,19 +39,19 @@ public class ControlEvent {
|
|||
return event;
|
||||
}
|
||||
|
||||
public static ControlEvent createMotionControlEvent(int action, int buttons, Point point) {
|
||||
public static ControlEvent createMotionControlEvent(int action, int buttons, Position position) {
|
||||
ControlEvent event = new ControlEvent();
|
||||
event.type = TYPE_MOUSE;
|
||||
event.action = action;
|
||||
event.buttons = buttons;
|
||||
event.point = point;
|
||||
event.position = position;
|
||||
return event;
|
||||
}
|
||||
|
||||
public static ControlEvent createScrollControlEvent(Point point, int hScroll, int vScroll) {
|
||||
public static ControlEvent createScrollControlEvent(Position position, int hScroll, int vScroll) {
|
||||
ControlEvent event = new ControlEvent();
|
||||
event.type = TYPE_SCROLL;
|
||||
event.point = point;
|
||||
event.position = position;
|
||||
event.hScroll = hScroll;
|
||||
event.vScroll = vScroll;
|
||||
return event;
|
||||
|
@ -81,8 +81,8 @@ public class ControlEvent {
|
|||
return buttons;
|
||||
}
|
||||
|
||||
public Point getPoint() {
|
||||
return point;
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public int getHScroll() {
|
||||
|
|
|
@ -74,17 +74,17 @@ public class ControlEventReader {
|
|||
}
|
||||
int action = toUnsigned(buffer.get());
|
||||
int buttons = buffer.getInt();
|
||||
Point point = readPoint(buffer);
|
||||
return ControlEvent.createMotionControlEvent(action, buttons, point);
|
||||
Position position = readPosition(buffer);
|
||||
return ControlEvent.createMotionControlEvent(action, buttons, position);
|
||||
}
|
||||
case ControlEvent.TYPE_SCROLL: {
|
||||
if (buffer.remaining() < SCROLL_PAYLOAD_LENGTH) {
|
||||
break;
|
||||
}
|
||||
Point point = readPoint(buffer);
|
||||
int hscroll = buffer.getInt();
|
||||
int vscroll = buffer.getInt();
|
||||
return ControlEvent.createScrollControlEvent(point, hscroll, vscroll);
|
||||
Position position = readPosition(buffer);
|
||||
int hScroll = buffer.getInt();
|
||||
int vScroll = buffer.getInt();
|
||||
return ControlEvent.createScrollControlEvent(position, hScroll, vScroll);
|
||||
}
|
||||
default:
|
||||
Ln.w("Unknown event type: " + type);
|
||||
|
@ -95,12 +95,12 @@ public class ControlEventReader {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static Point readPoint(ByteBuffer buffer) {
|
||||
private static Position readPosition(ByteBuffer buffer) {
|
||||
int x = toUnsigned(buffer.getShort());
|
||||
int y = toUnsigned(buffer.getShort());
|
||||
int screenWidth = toUnsigned(buffer.getShort());
|
||||
int screenHeight = toUnsigned(buffer.getShort());
|
||||
return new Point(x, y, screenWidth, screenHeight);
|
||||
return new Position(x, y, screenWidth, screenHeight);
|
||||
}
|
||||
|
||||
private static int toUnsigned(short value) {
|
||||
|
|
|
@ -48,13 +48,13 @@ public class Device {
|
|||
return screenInfo;
|
||||
}
|
||||
|
||||
public RawPoint getPhysicalPoint(Point point) {
|
||||
public Point getPhysicalPoint(Position position) {
|
||||
ScreenInfo screenInfo = getScreenInfo();
|
||||
int deviceWidth = screenInfo.getLogicalWidth();
|
||||
int deviceHeight = screenInfo.getLogicalHeight();
|
||||
int scaledX = point.getX() * deviceWidth / point.getScreenWidth();
|
||||
int scaledY = point.getY() * deviceHeight / point.getScreenHeight();
|
||||
return new RawPoint(scaledX, scaledY);
|
||||
int scaledX = position.getX() * deviceWidth / position.getScreenWidth();
|
||||
int scaledY = position.getY() * deviceHeight / position.getScreenHeight();
|
||||
return new Point(scaledX, scaledY);
|
||||
}
|
||||
|
||||
private ScreenInfo readScreenInfo() {
|
||||
|
|
|
@ -43,10 +43,10 @@ public class EventController {
|
|||
coords.touchMinor = 1;
|
||||
}
|
||||
|
||||
private void setPointerCoords(RawPoint rawPoint) {
|
||||
private void setPointerCoords(Point point) {
|
||||
MotionEvent.PointerCoords coords = pointerCoords[0];
|
||||
coords.x = rawPoint.getX();
|
||||
coords.y = rawPoint.getY();
|
||||
coords.x = point.getX();
|
||||
coords.y = point.getY();
|
||||
}
|
||||
|
||||
private void setScroll(int hScroll, int vScroll) {
|
||||
|
@ -72,10 +72,10 @@ public class EventController {
|
|||
injectText(controlEvent.getText());
|
||||
break;
|
||||
case ControlEvent.TYPE_MOUSE:
|
||||
injectMouse(controlEvent.getAction(), controlEvent.getButtons(), controlEvent.getPoint());
|
||||
injectMouse(controlEvent.getAction(), controlEvent.getButtons(), controlEvent.getPosition());
|
||||
break;
|
||||
case ControlEvent.TYPE_SCROLL:
|
||||
injectScroll(controlEvent.getPoint(), controlEvent.getHScroll(), controlEvent.getVScroll());
|
||||
injectScroll(controlEvent.getPosition(), controlEvent.getHScroll(), controlEvent.getVScroll());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -97,29 +97,29 @@ public class EventController {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean injectMouse(int action, int buttons, Point point) {
|
||||
private boolean injectMouse(int action, int buttons, Position position) {
|
||||
long now = SystemClock.uptimeMillis();
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
lastMouseDown = now;
|
||||
}
|
||||
RawPoint rawPoint = Device.getInstance().getPhysicalPoint(point);
|
||||
if (rawPoint == null) {
|
||||
Point point = Device.getInstance().getPhysicalPoint(position);
|
||||
if (point == null) {
|
||||
// ignore event
|
||||
return false;
|
||||
}
|
||||
setPointerCoords(rawPoint);
|
||||
setPointerCoords(point);
|
||||
MotionEvent event = MotionEvent.obtain(lastMouseDown, now, action, 1, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
|
||||
return injectEvent(event);
|
||||
}
|
||||
|
||||
private boolean injectScroll(Point point, int hScroll, int vScroll) {
|
||||
private boolean injectScroll(Position position, int hScroll, int vScroll) {
|
||||
long now = SystemClock.uptimeMillis();
|
||||
RawPoint rawPoint = Device.getInstance().getPhysicalPoint(point);
|
||||
if (rawPoint == null) {
|
||||
Point point = Device.getInstance().getPhysicalPoint(position);
|
||||
if (point == null) {
|
||||
// ignore event
|
||||
return false;
|
||||
}
|
||||
setPointerCoords(rawPoint);
|
||||
setPointerCoords(point);
|
||||
setScroll(hScroll, vScroll);
|
||||
MotionEvent event = MotionEvent.obtain(lastMouseDown, now, MotionEvent.ACTION_SCROLL, 1, pointerProperties, pointerCoords, 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_MOUSE, 0);
|
||||
return injectEvent(event);
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
package com.genymobile.scrcpy;
|
||||
|
||||
public class Point {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int screenWidth;
|
||||
private int screenHeight;
|
||||
|
||||
public Point(int x, int y, int screenWidth, int screenHeight) {
|
||||
public Point(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.screenWidth = screenWidth;
|
||||
this.screenHeight = screenHeight;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
|
@ -22,21 +17,11 @@ public class Point {
|
|||
return y;
|
||||
}
|
||||
|
||||
public int getScreenWidth() {
|
||||
return screenWidth;
|
||||
}
|
||||
|
||||
public int getScreenHeight() {
|
||||
return screenHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Point{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", screenWidth=" + screenWidth +
|
||||
", screenHeight=" + screenHeight +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
42
server/src/com/genymobile/scrcpy/Position.java
Normal file
42
server/src/com/genymobile/scrcpy/Position.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
package com.genymobile.scrcpy;
|
||||
|
||||
public class Position {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int screenWidth;
|
||||
private int screenHeight;
|
||||
|
||||
public Position(int x, int y, int screenWidth, int screenHeight) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.screenWidth = screenWidth;
|
||||
this.screenHeight = screenHeight;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getScreenWidth() {
|
||||
return screenWidth;
|
||||
}
|
||||
|
||||
public int getScreenHeight() {
|
||||
return screenHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Point{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", screenWidth=" + screenWidth +
|
||||
", screenHeight=" + screenHeight +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.genymobile.scrcpy;
|
||||
|
||||
public class RawPoint {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public RawPoint(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RawPoint{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
'}';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue