Compare commits
16 Commits
logical_si
...
window-par
Author | SHA1 | Date | |
---|---|---|---|
ad6b8847d4 | |||
fba89e6f73 | |||
4bf2b80c75 | |||
f983ec67fa | |||
120f08ee96 | |||
0415672a75 | |||
3ea4742321 | |||
95fd64b5de | |||
ab205084dc | |||
4696878a97 | |||
3da95b52bd | |||
c72f677435 | |||
1380f6e00f | |||
d841718956 | |||
17d53be3ef | |||
f9938dbf88 |
14
BUILD.md
14
BUILD.md
@ -195,8 +195,7 @@ Then, build:
|
||||
|
||||
```bash
|
||||
meson x --buildtype release --strip -Db_lto=true
|
||||
cd x
|
||||
ninja
|
||||
ninja -Cx
|
||||
```
|
||||
|
||||
_Note: `ninja` [must][ninja-user] be run as a non-root user (only `ninja
|
||||
@ -219,13 +218,13 @@ To run without installing:
|
||||
After a successful build, you can install _scrcpy_ on the system:
|
||||
|
||||
```bash
|
||||
sudo ninja install # without sudo on Windows
|
||||
sudo ninja -Cx install # without sudo on Windows
|
||||
```
|
||||
|
||||
This installs two files:
|
||||
|
||||
- `/usr/local/bin/scrcpy`
|
||||
- `/usr/local/share/scrcpy/scrcpy-server.jar`
|
||||
- `/usr/local/share/scrcpy/scrcpy-server`
|
||||
|
||||
Just remove them to "uninstall" the application.
|
||||
|
||||
@ -244,8 +243,7 @@ configuration:
|
||||
|
||||
```bash
|
||||
meson x --buildtype release --strip -Db_lto=true \
|
||||
-Dprebuilt_server=/path/to/scrcpy-server.jar
|
||||
cd x
|
||||
ninja
|
||||
sudo ninja install
|
||||
-Dprebuilt_server=/path/to/scrcpy-server
|
||||
ninja -Cx
|
||||
sudo ninja -Cx install
|
||||
```
|
||||
|
@ -3,7 +3,7 @@
|
||||
## Overview
|
||||
|
||||
This application is composed of two parts:
|
||||
- the server (`scrcpy-server.jar`), to be executed on the device,
|
||||
- the server (`scrcpy-server`), to be executed on the device,
|
||||
- the client (the `scrcpy` binary), executed on the host computer.
|
||||
|
||||
The client is responsible to push the server to the device and start its
|
||||
@ -49,7 +49,7 @@ application may not replace the server just before the client executes it._
|
||||
Instead of a raw _dex_ file, `app_process` accepts a _jar_ containing
|
||||
`classes.dex` (e.g. an [APK]). For simplicity, and to benefit from the gradle
|
||||
build system, the server is built to an (unsigned) APK (renamed to
|
||||
`scrcpy-server.jar`).
|
||||
`scrcpy-server`).
|
||||
|
||||
[dex]: https://en.wikipedia.org/wiki/Dalvik_(software)
|
||||
[apk]: https://en.wikipedia.org/wiki/Android_application_package
|
||||
|
@ -3,7 +3,7 @@
|
||||
#
|
||||
# Here, "portable" means that the client and server binaries are expected to be
|
||||
# anywhere, but in the same directory, instead of well-defined separate
|
||||
# locations (e.g. /usr/bin/scrcpy and /usr/share/scrcpy/scrcpy-server.jar).
|
||||
# locations (e.g. /usr/bin/scrcpy and /usr/share/scrcpy/scrcpy-server).
|
||||
#
|
||||
# In particular, this implies to change the location from where the client push
|
||||
# the server to the device.
|
||||
@ -97,7 +97,7 @@ build-win64-noconsole: prepare-deps-win64
|
||||
|
||||
dist-win32: build-server build-win32 build-win32-noconsole
|
||||
mkdir -p "$(DIST)/$(WIN32_TARGET_DIR)"
|
||||
cp "$(SERVER_BUILD_DIR)"/server/scrcpy-server.jar "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp "$(SERVER_BUILD_DIR)"/server/scrcpy-server "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp "$(WIN32_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
cp "$(WIN32_NOCONSOLE_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN32_TARGET_DIR)/scrcpy-noconsole.exe"
|
||||
cp prebuilt-deps/ffmpeg-4.1.4-win32-shared/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
|
||||
@ -112,7 +112,7 @@ dist-win32: build-server build-win32 build-win32-noconsole
|
||||
|
||||
dist-win64: build-server build-win64 build-win64-noconsole
|
||||
mkdir -p "$(DIST)/$(WIN64_TARGET_DIR)"
|
||||
cp "$(SERVER_BUILD_DIR)"/server/scrcpy-server.jar "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp "$(SERVER_BUILD_DIR)"/server/scrcpy-server "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp "$(WIN64_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
cp "$(WIN64_NOCONSOLE_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN64_TARGET_DIR)/scrcpy-noconsole.exe"
|
||||
cp prebuilt-deps/ffmpeg-4.1.4-win64-shared/bin/avutil-56.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
|
@ -358,7 +358,7 @@ To use a specific _adb_ binary, configure its path in the environment variable
|
||||
|
||||
ADB=/path/to/adb scrcpy
|
||||
|
||||
To override the path of the `scrcpy-server.jar` file, configure its path in
|
||||
To override the path of the `scrcpy-server` file, configure its path in
|
||||
`SCRCPY_SERVER_PATH`.
|
||||
|
||||
[useful]: https://github.com/Genymobile/scrcpy/issues/278#issuecomment-429330345
|
||||
|
@ -93,7 +93,7 @@ conf.set_quoted('SCRCPY_VERSION', meson.project_version())
|
||||
# the prefix used during configuration (meson --prefix=PREFIX)
|
||||
conf.set_quoted('PREFIX', get_option('prefix'))
|
||||
|
||||
# build a "portable" version (with scrcpy-server.jar accessible from the same
|
||||
# build a "portable" version (with scrcpy-server accessible from the same
|
||||
# directory as the executable)
|
||||
conf.set('PORTABLE', get_option('portable'))
|
||||
|
||||
@ -134,6 +134,8 @@ executable('scrcpy', src,
|
||||
c_args: c_args,
|
||||
link_args: link_args)
|
||||
|
||||
install_man('scrcpy.1')
|
||||
|
||||
|
||||
### TESTS
|
||||
|
||||
|
254
app/scrcpy.1
Normal file
254
app/scrcpy.1
Normal file
@ -0,0 +1,254 @@
|
||||
.TH "scrcpy" "1"
|
||||
.SH NAME
|
||||
scrcpy \- Display and control your Android device
|
||||
|
||||
|
||||
.SH SYNOPSIS
|
||||
.B scrcpy
|
||||
.RI [ options ]
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
.B scrcpy
|
||||
provides display and control of Android devices connected on USB (or over TCP/IP). It does not require any root access.
|
||||
|
||||
|
||||
.SH OPTIONS
|
||||
|
||||
.TP
|
||||
.BI "\-b, \-\-bit\-rate " value
|
||||
Encode the video at the given bit\-rate, expressed in bits/s. Unit suffixes are supported: '\fBK\fR' (x1000) and '\fBM\fR' (x1000000).
|
||||
|
||||
Default is 8000000.
|
||||
|
||||
.TP
|
||||
.BI "\-c, \-\-crop " width\fR:\fIheight\fR:\fIx\fR:\fIy
|
||||
Crop the device screen on the server.
|
||||
|
||||
The values are expressed in the device natural orientation (typically, portrait for a phone, landscape for a tablet). Any
|
||||
.B \-\-max\-size
|
||||
value is computed on the cropped size.
|
||||
|
||||
.TP
|
||||
.B \-f, \-\-fullscreen
|
||||
Start in fullscreen.
|
||||
|
||||
.TP
|
||||
.BI "\-F, \-\-record\-format " format
|
||||
Force recording format (either mp4 or mkv).
|
||||
|
||||
.TP
|
||||
.B \-h, \-\-help
|
||||
Print this help.
|
||||
|
||||
.TP
|
||||
.BI "\-m, \-\-max\-size " value
|
||||
Limit both the width and height of the video to \fIvalue\fR. The other dimension is computed so that the device aspect\-ratio is preserved.
|
||||
|
||||
Default is 0 (unlimited).
|
||||
|
||||
.TP
|
||||
.B \-n, \-\-no\-control
|
||||
Disable device control (mirror the device in read\-only).
|
||||
|
||||
.TP
|
||||
.B \-N, \-\-no\-display
|
||||
Do not display device (only when screen recording is enabled).
|
||||
|
||||
.TP
|
||||
.BI "\-p, \-\-port " port
|
||||
Set the TCP port the client listens on.
|
||||
|
||||
Default is 27183.
|
||||
|
||||
.TP
|
||||
.BI "\-\-push\-target " path
|
||||
Set the target directory for pushing files to the device by drag & drop. It is passed as\-is to "adb push".
|
||||
|
||||
Default is "/sdcard/".
|
||||
|
||||
.TP
|
||||
.BI "\-r, \-\-record " file
|
||||
Record screen to
|
||||
.IR file .
|
||||
|
||||
The format is determined by the
|
||||
.B \-F/\-\-record\-format
|
||||
option if set, or by the file extension (.mp4 or .mkv).
|
||||
|
||||
.TP
|
||||
.B \-\-render\-expired\-frames
|
||||
By default, to minimize latency, scrcpy always renders the last available decoded frame, and drops any previous ones. This flag forces to render all frames, at a cost of a possible increased latency.
|
||||
|
||||
.TP
|
||||
.BI "\-s, \-\-serial " number
|
||||
The device serial number. Mandatory only if several devices are connected to adb.
|
||||
|
||||
.TP
|
||||
.B \-S, \-\-turn\-screen\-off
|
||||
Turn the device screen off immediately.
|
||||
|
||||
.TP
|
||||
.B \-t, \-\-show\-touches
|
||||
Enable "show touches" on start, disable on quit.
|
||||
|
||||
It only shows physical touches (not clicks from scrcpy).
|
||||
|
||||
.TP
|
||||
.B \-T, \-\-always\-on\-top
|
||||
Make scrcpy window always on top (above other windows).
|
||||
|
||||
.TP
|
||||
.B \-v, \-\-version
|
||||
Print the version of scrcpy.
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-title " text
|
||||
Set a custom window title.
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-x " value
|
||||
Set the initial window horizontal position.
|
||||
|
||||
Default is -1 (automatic).\n
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-y " value
|
||||
Set the initial window vertical position.
|
||||
|
||||
Default is -1 (automatic).\n
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-width " value
|
||||
Set the initial window width.
|
||||
|
||||
Default is 0 (automatic).\n
|
||||
|
||||
.TP
|
||||
.BI \-\-window\-height " value
|
||||
Set the initial window height.
|
||||
|
||||
Default is 0 (automatic).\n
|
||||
|
||||
.SH SHORTCUTS
|
||||
|
||||
.TP
|
||||
.B Ctrl+f
|
||||
switch fullscreen mode
|
||||
|
||||
.TP
|
||||
.B Ctrl+g
|
||||
resize window to 1:1 (pixel\-perfect)
|
||||
|
||||
.TP
|
||||
.B Ctrl+x, Double\-click on black borders
|
||||
resize window to remove black borders
|
||||
|
||||
.TP
|
||||
.B Ctrl+h, Home, Middle\-click
|
||||
Click on HOME
|
||||
|
||||
.TP
|
||||
.B Ctrl+b, Ctrl+Backspace, Right\-click (when screen is on)
|
||||
Click on BACK
|
||||
|
||||
.TP
|
||||
.B Ctrl+s
|
||||
Click on APP_SWITCH
|
||||
|
||||
.TP
|
||||
.B Ctrl+m
|
||||
Click on MENU
|
||||
|
||||
.TP
|
||||
.B Ctrl+Up
|
||||
Click on VOLUME_UP
|
||||
|
||||
.TP
|
||||
.B Ctrl+Down
|
||||
Click on VOLUME_DOWN
|
||||
|
||||
.TP
|
||||
.B Ctrl+p
|
||||
Click on POWER (turn screen on/off)
|
||||
|
||||
.TP
|
||||
.B Right\-click (when screen is off)
|
||||
turn screen on
|
||||
|
||||
.TP
|
||||
.B Ctrl+o
|
||||
turn device screen off (keep mirroring)
|
||||
|
||||
.TP
|
||||
.B Ctrl+n
|
||||
expand notification panel
|
||||
|
||||
.TP
|
||||
.B Ctrl+Shift+n
|
||||
collapse notification panel
|
||||
|
||||
.TP
|
||||
.B Ctrl+c
|
||||
copy device clipboard to computer
|
||||
|
||||
.TP
|
||||
.B Ctrl+v
|
||||
paste computer clipboard to device
|
||||
|
||||
.TP
|
||||
.B Ctrl+Shift+v
|
||||
copy computer clipboard to device
|
||||
|
||||
.TP
|
||||
.B Ctrl+i
|
||||
enable/disable FPS counter (print frames/second in logs)
|
||||
|
||||
.TP
|
||||
.B Drag & drop APK file
|
||||
install APK from computer
|
||||
|
||||
|
||||
.SH Environment variables
|
||||
|
||||
.TP
|
||||
.B ADB
|
||||
Specify the path to adb.
|
||||
|
||||
.TP
|
||||
.B SCRCPY_SERVER_PATH
|
||||
Specify the path to server binary.
|
||||
|
||||
|
||||
.SH AUTHORS
|
||||
.B scrcpy
|
||||
is written by Romain Vimont.
|
||||
|
||||
This manual page was written by
|
||||
.MT mmyangfl@gmail.com
|
||||
Yangfl
|
||||
.ME
|
||||
for the Debian Project (and may be used by others).
|
||||
|
||||
|
||||
.SH "REPORTING BUGS"
|
||||
Report bugs to
|
||||
.UR https://github.com/Genymobile/scrcpy/issues
|
||||
.UE .
|
||||
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2018 Genymobile
|
||||
.UR https://www.genymobile.com
|
||||
Genymobile
|
||||
.UE
|
||||
|
||||
Copyright \(co 2018\-2019
|
||||
.MT rom@rom1v.com
|
||||
Romain Vimont
|
||||
.ME
|
||||
|
||||
Licensed under the Apache License, Version 2.0.
|
||||
|
||||
.SH WWW
|
||||
.UR https://github.com/Genymobile/scrcpy
|
||||
.UE
|
@ -5,7 +5,7 @@
|
||||
#define MAP(FROM, TO) case FROM: *to = TO; return true
|
||||
#define FAIL default: return false
|
||||
|
||||
bool
|
||||
static bool
|
||||
convert_keycode_action(SDL_EventType from, enum android_keyevent_action *to) {
|
||||
switch (from) {
|
||||
MAP(SDL_KEYDOWN, AKEY_EVENT_ACTION_DOWN);
|
||||
@ -33,7 +33,7 @@ autocomplete_metastate(enum android_metastate metastate) {
|
||||
return metastate;
|
||||
}
|
||||
|
||||
enum android_metastate
|
||||
static enum android_metastate
|
||||
convert_meta_state(SDL_Keymod mod) {
|
||||
enum android_metastate metastate = 0;
|
||||
if (mod & KMOD_LSHIFT) {
|
||||
@ -74,7 +74,7 @@ convert_meta_state(SDL_Keymod mod) {
|
||||
return autocomplete_metastate(metastate);
|
||||
}
|
||||
|
||||
bool
|
||||
static bool
|
||||
convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod) {
|
||||
switch (from) {
|
||||
MAP(SDLK_RETURN, AKEYCODE_ENTER);
|
||||
@ -128,7 +128,7 @@ convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod) {
|
||||
}
|
||||
}
|
||||
|
||||
enum android_motionevent_buttons
|
||||
static enum android_motionevent_buttons
|
||||
convert_mouse_buttons(uint32_t state) {
|
||||
enum android_motionevent_buttons buttons = 0;
|
||||
if (state & SDL_BUTTON_LMASK) {
|
||||
@ -140,16 +140,34 @@ convert_mouse_buttons(uint32_t state) {
|
||||
if (state & SDL_BUTTON_MMASK) {
|
||||
buttons |= AMOTION_EVENT_BUTTON_TERTIARY;
|
||||
}
|
||||
if (state & SDL_BUTTON_X1) {
|
||||
if (state & SDL_BUTTON_X1MASK) {
|
||||
buttons |= AMOTION_EVENT_BUTTON_BACK;
|
||||
}
|
||||
if (state & SDL_BUTTON_X2) {
|
||||
if (state & SDL_BUTTON_X2MASK) {
|
||||
buttons |= AMOTION_EVENT_BUTTON_FORWARD;
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
|
||||
bool
|
||||
convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
||||
|
||||
if (!convert_keycode_action(from->type, &to->inject_keycode.action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t mod = from->keysym.mod;
|
||||
if (!convert_keycode(from->keysym.sym, &to->inject_keycode.keycode, mod)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
to->inject_keycode.metastate = convert_meta_state(mod);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
convert_mouse_action(SDL_EventType from, enum android_motionevent_action *to) {
|
||||
switch (from) {
|
||||
MAP(SDL_MOUSEBUTTONDOWN, AMOTION_EVENT_ACTION_DOWN);
|
||||
@ -159,6 +177,41 @@ convert_mouse_action(SDL_EventType from, enum android_motionevent_action *to) {
|
||||
}
|
||||
|
||||
bool
|
||||
convert_mouse_button(const SDL_MouseButtonEvent *from, struct size screen_size,
|
||||
struct control_msg *to) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
||||
|
||||
if (!convert_mouse_action(from->type, &to->inject_touch_event.action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
to->inject_touch_event.pointer_id = POINTER_ID_MOUSE;
|
||||
to->inject_touch_event.position.screen_size = screen_size;
|
||||
to->inject_touch_event.position.point.x = from->x;
|
||||
to->inject_touch_event.position.point.y = from->y;
|
||||
to->inject_touch_event.pressure = 1.f;
|
||||
to->inject_touch_event.buttons =
|
||||
convert_mouse_buttons(SDL_BUTTON(from->button));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
convert_mouse_motion(const SDL_MouseMotionEvent *from, struct size screen_size,
|
||||
struct control_msg *to) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
||||
to->inject_touch_event.action = AMOTION_EVENT_ACTION_MOVE;
|
||||
to->inject_touch_event.pointer_id = POINTER_ID_MOUSE;
|
||||
to->inject_touch_event.position.screen_size = screen_size;
|
||||
to->inject_touch_event.position.point.x = from->x;
|
||||
to->inject_touch_event.position.point.y = from->y;
|
||||
to->inject_touch_event.pressure = 1.f;
|
||||
to->inject_touch_event.buttons = convert_mouse_buttons(from->state);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
convert_touch_action(SDL_EventType from, enum android_motionevent_action *to) {
|
||||
switch (from) {
|
||||
MAP(SDL_FINGERMOTION, AMOTION_EVENT_ACTION_MOVE);
|
||||
@ -167,3 +220,39 @@ convert_touch_action(SDL_EventType from, enum android_motionevent_action *to) {
|
||||
FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
convert_touch(const SDL_TouchFingerEvent *from, struct size screen_size,
|
||||
struct control_msg *to) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
||||
|
||||
if (!convert_touch_action(from->type, &to->inject_touch_event.action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
to->inject_touch_event.pointer_id = from->fingerId;
|
||||
to->inject_touch_event.position.screen_size = screen_size;
|
||||
// SDL touch event coordinates are normalized in the range [0; 1]
|
||||
to->inject_touch_event.position.point.x = from->x * screen_size.width;
|
||||
to->inject_touch_event.position.point.y = from->y * screen_size.height;
|
||||
to->inject_touch_event.pressure = from->pressure;
|
||||
to->inject_touch_event.buttons = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct position position,
|
||||
struct control_msg *to) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT;
|
||||
|
||||
to->inject_scroll_event.position = position;
|
||||
|
||||
int mul = from->direction == SDL_MOUSEWHEEL_NORMAL ? 1 : -1;
|
||||
// SDL behavior seems inconsistent between horizontal and vertical scrolling
|
||||
// so reverse the horizontal
|
||||
// <https://wiki.libsdl.org/SDL_MouseWheelEvent#Remarks>
|
||||
to->inject_scroll_event.hscroll = -mul * from->x;
|
||||
to->inject_scroll_event.vscroll = mul * from->y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -7,22 +7,36 @@
|
||||
#include "config.h"
|
||||
#include "control_msg.h"
|
||||
|
||||
bool
|
||||
convert_keycode_action(SDL_EventType from, enum android_keyevent_action *to);
|
||||
struct complete_mouse_motion_event {
|
||||
SDL_MouseMotionEvent *mouse_motion_event;
|
||||
struct size screen_size;
|
||||
};
|
||||
|
||||
enum android_metastate
|
||||
convert_meta_state(SDL_Keymod mod);
|
||||
struct complete_mouse_wheel_event {
|
||||
SDL_MouseWheelEvent *mouse_wheel_event;
|
||||
struct point position;
|
||||
};
|
||||
|
||||
bool
|
||||
convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod);
|
||||
|
||||
enum android_motionevent_buttons
|
||||
convert_mouse_buttons(uint32_t state);
|
||||
convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to);
|
||||
|
||||
bool
|
||||
convert_mouse_action(SDL_EventType from, enum android_motionevent_action *to);
|
||||
convert_mouse_button(const SDL_MouseButtonEvent *from, struct size screen_size,
|
||||
struct control_msg *to);
|
||||
|
||||
// the video size may be different from the real device size, so we need the
|
||||
// size to which the absolute position apply, to scale it accordingly
|
||||
bool
|
||||
convert_mouse_motion(const SDL_MouseMotionEvent *from, struct size screen_size,
|
||||
struct control_msg *to);
|
||||
|
||||
bool
|
||||
convert_touch_action(SDL_EventType from, enum android_motionevent_action *to);
|
||||
convert_touch(const SDL_TouchFingerEvent *from, struct size screen_size,
|
||||
struct control_msg *to);
|
||||
|
||||
// on Android, a scroll event requires the current mouse position
|
||||
bool
|
||||
convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct position position,
|
||||
struct control_msg *to);
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,33 @@
|
||||
#include "lock_util.h"
|
||||
#include "log.h"
|
||||
|
||||
// Convert window coordinates (as provided by SDL_GetMouseState() to renderer
|
||||
// coordinates (as provided in SDL mouse events)
|
||||
//
|
||||
// See my question:
|
||||
// <https://stackoverflow.com/questions/49111054/how-to-get-mouse-position-on-mouse-wheel-event>
|
||||
static void
|
||||
convert_to_renderer_coordinates(SDL_Renderer *renderer, int *x, int *y) {
|
||||
SDL_Rect viewport;
|
||||
float scale_x, scale_y;
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
||||
*x = (int) (*x / scale_x) - viewport.x;
|
||||
*y = (int) (*y / scale_y) - viewport.y;
|
||||
}
|
||||
|
||||
static struct point
|
||||
get_mouse_point(struct screen *screen) {
|
||||
int x;
|
||||
int y;
|
||||
SDL_GetMouseState(&x, &y);
|
||||
convert_to_renderer_coordinates(screen->renderer, &x, &y);
|
||||
return (struct point) {
|
||||
.x = x,
|
||||
.y = y,
|
||||
};
|
||||
}
|
||||
|
||||
static const int ACTION_DOWN = 1;
|
||||
static const int ACTION_UP = 1 << 1;
|
||||
|
||||
@ -185,7 +212,7 @@ clipboard_paste(struct controller *controller) {
|
||||
}
|
||||
|
||||
void
|
||||
input_manager_process_text_input(struct input_manager *im,
|
||||
input_manager_process_text_input(struct input_manager *input_manager,
|
||||
const SDL_TextInputEvent *event) {
|
||||
char c = event->text[0];
|
||||
if (isalpha(c) || c == ' ') {
|
||||
@ -200,32 +227,14 @@ input_manager_process_text_input(struct input_manager *im,
|
||||
LOGW("Could not strdup input text");
|
||||
return;
|
||||
}
|
||||
if (!controller_push_msg(im->controller, &msg)) {
|
||||
if (!controller_push_msg(input_manager->controller, &msg)) {
|
||||
SDL_free(msg.inject_text.text);
|
||||
LOGW("Could not request 'inject text'");
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
||||
|
||||
if (!convert_keycode_action(from->type, &to->inject_keycode.action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t mod = from->keysym.mod;
|
||||
if (!convert_keycode(from->keysym.sym, &to->inject_keycode.keycode, mod)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
to->inject_keycode.metastate = convert_meta_state(mod);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
input_manager_process_key(struct input_manager *im,
|
||||
input_manager_process_key(struct input_manager *input_manager,
|
||||
const SDL_KeyboardEvent *event,
|
||||
bool control) {
|
||||
// control: indicates the state of the command-line option --no-control
|
||||
@ -252,7 +261,7 @@ input_manager_process_key(struct input_manager *im,
|
||||
return;
|
||||
}
|
||||
|
||||
struct controller *controller = im->controller;
|
||||
struct controller *controller = input_manager->controller;
|
||||
|
||||
// capture all Ctrl events
|
||||
if (ctrl || cmd) {
|
||||
@ -327,23 +336,23 @@ input_manager_process_key(struct input_manager *im,
|
||||
return;
|
||||
case SDLK_f:
|
||||
if (!shift && cmd && !repeat && down) {
|
||||
screen_switch_fullscreen(im->screen);
|
||||
screen_switch_fullscreen(input_manager->screen);
|
||||
}
|
||||
return;
|
||||
case SDLK_x:
|
||||
if (!shift && cmd && !repeat && down) {
|
||||
screen_resize_to_fit(im->screen);
|
||||
screen_resize_to_fit(input_manager->screen);
|
||||
}
|
||||
return;
|
||||
case SDLK_g:
|
||||
if (!shift && cmd && !repeat && down) {
|
||||
screen_resize_to_pixel_perfect(im->screen);
|
||||
screen_resize_to_pixel_perfect(input_manager->screen);
|
||||
}
|
||||
return;
|
||||
case SDLK_i:
|
||||
if (!shift && cmd && !repeat && down) {
|
||||
struct fps_counter *fps_counter =
|
||||
im->video_buffer->fps_counter;
|
||||
input_manager->video_buffer->fps_counter;
|
||||
switch_fps_counter_state(fps_counter);
|
||||
}
|
||||
return;
|
||||
@ -373,23 +382,8 @@ input_manager_process_key(struct input_manager *im,
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
convert_mouse_motion(const SDL_MouseMotionEvent *from, struct screen *screen,
|
||||
struct control_msg *to) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
||||
to->inject_touch_event.action = AMOTION_EVENT_ACTION_MOVE;
|
||||
to->inject_touch_event.pointer_id = POINTER_ID_MOUSE;
|
||||
to->inject_touch_event.position.screen_size = screen->frame_size;
|
||||
to->inject_touch_event.position.point =
|
||||
screen_convert_to_frame_coords(screen, from->x, from->y);
|
||||
to->inject_touch_event.pressure = 1.f;
|
||||
to->inject_touch_event.buttons = convert_mouse_buttons(from->state);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
input_manager_process_mouse_motion(struct input_manager *im,
|
||||
input_manager_process_mouse_motion(struct input_manager *input_manager,
|
||||
const SDL_MouseMotionEvent *event) {
|
||||
if (!event->state) {
|
||||
// do not send motion events when no button is pressed
|
||||
@ -400,76 +394,33 @@ input_manager_process_mouse_motion(struct input_manager *im,
|
||||
return;
|
||||
}
|
||||
struct control_msg msg;
|
||||
if (convert_mouse_motion(event, im->screen, &msg)) {
|
||||
if (!controller_push_msg(im->controller, &msg)) {
|
||||
if (convert_mouse_motion(event, input_manager->screen->frame_size, &msg)) {
|
||||
if (!controller_push_msg(input_manager->controller, &msg)) {
|
||||
LOGW("Could not request 'inject mouse motion event'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
convert_touch(const SDL_TouchFingerEvent *from, struct screen *screen,
|
||||
struct control_msg *to) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
||||
|
||||
if (!convert_touch_action(from->type, &to->inject_touch_event.action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct size frame_size = screen->frame_size;
|
||||
// SDL touch event coordinates are normalized in the range [0; 1]
|
||||
float x = from->x * frame_size.width;
|
||||
float y = from->y * frame_size.height;
|
||||
|
||||
to->inject_touch_event.pointer_id = from->fingerId;
|
||||
to->inject_touch_event.position.screen_size = frame_size;
|
||||
to->inject_touch_event.position.point =
|
||||
screen_convert_to_frame_coords(screen, x, y);
|
||||
to->inject_touch_event.pressure = from->pressure;
|
||||
to->inject_touch_event.buttons = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
input_manager_process_touch(struct input_manager *im,
|
||||
input_manager_process_touch(struct input_manager *input_manager,
|
||||
const SDL_TouchFingerEvent *event) {
|
||||
struct control_msg msg;
|
||||
if (convert_touch(event, im->screen, &msg)) {
|
||||
if (!controller_push_msg(im->controller, &msg)) {
|
||||
if (convert_touch(event, input_manager->screen->frame_size, &msg)) {
|
||||
if (!controller_push_msg(input_manager->controller, &msg)) {
|
||||
LOGW("Could not request 'inject touch event'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
is_outside_device_screen(struct input_manager *im, int x, int y)
|
||||
is_outside_device_screen(struct input_manager *input_manager, int x, int y)
|
||||
{
|
||||
return x < 0 || x >= im->screen->frame_size.width ||
|
||||
y < 0 || y >= im->screen->frame_size.height;
|
||||
}
|
||||
|
||||
static bool
|
||||
convert_mouse_button(const SDL_MouseButtonEvent *from, struct screen *screen,
|
||||
struct control_msg *to) {
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
||||
|
||||
if (!convert_mouse_action(from->type, &to->inject_touch_event.action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
to->inject_touch_event.pointer_id = POINTER_ID_MOUSE;
|
||||
to->inject_touch_event.position.screen_size = screen->frame_size;
|
||||
to->inject_touch_event.position.point =
|
||||
screen_convert_to_frame_coords(screen, from->x, from->y);
|
||||
to->inject_touch_event.pressure = 1.f;
|
||||
to->inject_touch_event.buttons =
|
||||
convert_mouse_buttons(SDL_BUTTON(from->button));
|
||||
|
||||
return true;
|
||||
return x < 0 || x >= input_manager->screen->frame_size.width ||
|
||||
y < 0 || y >= input_manager->screen->frame_size.height;
|
||||
}
|
||||
|
||||
void
|
||||
input_manager_process_mouse_button(struct input_manager *im,
|
||||
input_manager_process_mouse_button(struct input_manager *input_manager,
|
||||
const SDL_MouseButtonEvent *event,
|
||||
bool control) {
|
||||
if (event->which == SDL_TOUCH_MOUSEID) {
|
||||
@ -478,19 +429,19 @@ input_manager_process_mouse_button(struct input_manager *im,
|
||||
}
|
||||
if (event->type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (control && event->button == SDL_BUTTON_RIGHT) {
|
||||
press_back_or_turn_screen_on(im->controller);
|
||||
press_back_or_turn_screen_on(input_manager->controller);
|
||||
return;
|
||||
}
|
||||
if (control && event->button == SDL_BUTTON_MIDDLE) {
|
||||
action_home(im->controller, ACTION_DOWN | ACTION_UP);
|
||||
action_home(input_manager->controller, ACTION_DOWN | ACTION_UP);
|
||||
return;
|
||||
}
|
||||
// double-click on black borders resize to fit the device screen
|
||||
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
|
||||
bool outside =
|
||||
is_outside_device_screen(im, event->x, event->y);
|
||||
is_outside_device_screen(input_manager, event->x, event->y);
|
||||
if (outside) {
|
||||
screen_resize_to_fit(im->screen);
|
||||
screen_resize_to_fit(input_manager->screen);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -502,47 +453,23 @@ input_manager_process_mouse_button(struct input_manager *im,
|
||||
}
|
||||
|
||||
struct control_msg msg;
|
||||
if (convert_mouse_button(event, im->screen, &msg)) {
|
||||
if (!controller_push_msg(im->controller, &msg)) {
|
||||
if (convert_mouse_button(event, input_manager->screen->frame_size, &msg)) {
|
||||
if (!controller_push_msg(input_manager->controller, &msg)) {
|
||||
LOGW("Could not request 'inject mouse button event'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct screen *screen,
|
||||
struct control_msg *to) {
|
||||
|
||||
// mouse_x and mouse_y are expressed in pixels relatice to the window
|
||||
int mouse_x;
|
||||
int mouse_y;
|
||||
SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
|
||||
struct position position = {
|
||||
.screen_size = screen->frame_size,
|
||||
.point = screen_convert_to_frame_coords(screen, mouse_x, mouse_y),
|
||||
};
|
||||
|
||||
to->type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT;
|
||||
|
||||
to->inject_scroll_event.position = position;
|
||||
|
||||
int mul = from->direction == SDL_MOUSEWHEEL_NORMAL ? 1 : -1;
|
||||
// SDL behavior seems inconsistent between horizontal and vertical scrolling
|
||||
// so reverse the horizontal
|
||||
// <https://wiki.libsdl.org/SDL_MouseWheelEvent#Remarks>
|
||||
to->inject_scroll_event.hscroll = -mul * from->x;
|
||||
to->inject_scroll_event.vscroll = mul * from->y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
input_manager_process_mouse_wheel(struct input_manager *im,
|
||||
input_manager_process_mouse_wheel(struct input_manager *input_manager,
|
||||
const SDL_MouseWheelEvent *event) {
|
||||
struct position position = {
|
||||
.screen_size = input_manager->screen->frame_size,
|
||||
.point = get_mouse_point(input_manager->screen),
|
||||
};
|
||||
struct control_msg msg;
|
||||
if (convert_mouse_wheel(event, im->screen, &msg)) {
|
||||
if (!controller_push_msg(im->controller, &msg)) {
|
||||
if (convert_mouse_wheel(event, position, &msg)) {
|
||||
if (!controller_push_msg(input_manager->controller, &msg)) {
|
||||
LOGW("Could not request 'inject mouse wheel event'");
|
||||
}
|
||||
}
|
||||
|
@ -17,29 +17,29 @@ struct input_manager {
|
||||
};
|
||||
|
||||
void
|
||||
input_manager_process_text_input(struct input_manager *im,
|
||||
input_manager_process_text_input(struct input_manager *input_manager,
|
||||
const SDL_TextInputEvent *event);
|
||||
|
||||
void
|
||||
input_manager_process_key(struct input_manager *im,
|
||||
input_manager_process_key(struct input_manager *input_manager,
|
||||
const SDL_KeyboardEvent *event,
|
||||
bool control);
|
||||
|
||||
void
|
||||
input_manager_process_mouse_motion(struct input_manager *im,
|
||||
input_manager_process_mouse_motion(struct input_manager *input_manager,
|
||||
const SDL_MouseMotionEvent *event);
|
||||
|
||||
void
|
||||
input_manager_process_touch(struct input_manager *im,
|
||||
input_manager_process_touch(struct input_manager *input_manager,
|
||||
const SDL_TouchFingerEvent *event);
|
||||
|
||||
void
|
||||
input_manager_process_mouse_button(struct input_manager *im,
|
||||
input_manager_process_mouse_button(struct input_manager *input_manager,
|
||||
const SDL_MouseButtonEvent *event,
|
||||
bool control);
|
||||
|
||||
void
|
||||
input_manager_process_mouse_wheel(struct input_manager *im,
|
||||
input_manager_process_mouse_wheel(struct input_manager *input_manager,
|
||||
const SDL_MouseWheelEvent *event);
|
||||
|
||||
#endif
|
||||
|
119
app/src/main.c
119
app/src/main.c
@ -29,9 +29,14 @@ struct args {
|
||||
uint16_t port;
|
||||
uint16_t max_size;
|
||||
uint32_t bit_rate;
|
||||
int16_t window_x;
|
||||
int16_t window_y;
|
||||
uint16_t window_width;
|
||||
uint16_t window_height;
|
||||
bool always_on_top;
|
||||
bool turn_screen_off;
|
||||
bool render_expired_frames;
|
||||
bool window_borderless;
|
||||
};
|
||||
|
||||
static void usage(const char *arg0) {
|
||||
@ -59,7 +64,7 @@ static void usage(const char *arg0) {
|
||||
" -f, --fullscreen\n"
|
||||
" Start in fullscreen.\n"
|
||||
"\n"
|
||||
" -F, --record-format\n"
|
||||
" -F, --record-format format\n"
|
||||
" Force recording format (either mp4 or mkv).\n"
|
||||
"\n"
|
||||
" -h, --help\n"
|
||||
@ -115,9 +120,28 @@ static void usage(const char *arg0) {
|
||||
" -v, --version\n"
|
||||
" Print the version of scrcpy.\n"
|
||||
"\n"
|
||||
" --window_borderless\n"
|
||||
" Disable window decorations (display borderless window).\n"
|
||||
"\n"
|
||||
" --window-title text\n"
|
||||
" Set a custom window title.\n"
|
||||
"\n"
|
||||
" --window-x value\n"
|
||||
" Set the initial window horizontal position.\n"
|
||||
" Default is -1 (automatic).\n"
|
||||
"\n"
|
||||
" --window-y value\n"
|
||||
" Set the initial window vertical position.\n"
|
||||
" Default is -1 (automatic).\n"
|
||||
"\n"
|
||||
" --window-width value\n"
|
||||
" Set the initial window width.\n"
|
||||
" Default is -1 (automatic).\n"
|
||||
"\n"
|
||||
" --window-height value\n"
|
||||
" Set the initial window width.\n"
|
||||
" Default is -1 (automatic).\n"
|
||||
"\n"
|
||||
"Shortcuts:\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+f\n"
|
||||
@ -258,6 +282,48 @@ parse_max_size(char *optarg, uint16_t *max_size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_window_position(char *optarg, int16_t *position) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Window position parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*endptr != '\0') {
|
||||
LOGE("Invalid window position: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if (value < -1 || value > 0x7fff) {
|
||||
LOGE("Window position must be between -1 and 32767: %ld", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
*position = (int16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_window_dimension(char *optarg, uint16_t *dimension) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Window dimension parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*endptr != '\0') {
|
||||
LOGE("Invalid window dimension: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
LOGE("Window position must be between 0 and 65535: %ld", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
*dimension = (uint16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_port(char *optarg, uint16_t *port) {
|
||||
char *endptr;
|
||||
@ -310,8 +376,13 @@ guess_record_format(const char *filename) {
|
||||
}
|
||||
|
||||
#define OPT_RENDER_EXPIRED_FRAMES 1000
|
||||
#define OPT_WINDOW_TITLE 1001
|
||||
#define OPT_PUSH_TARGET 1002
|
||||
#define OPT_PUSH_TARGET 1001
|
||||
#define OPT_WINDOW_TITLE 1002
|
||||
#define OPT_WINDOW_X 1003
|
||||
#define OPT_WINDOW_Y 1004
|
||||
#define OPT_WINDOW_WIDTH 1005
|
||||
#define OPT_WINDOW_HEIGHT 1006
|
||||
#define OPT_WINDOW_BORDERLESS 1007
|
||||
|
||||
static bool
|
||||
parse_args(struct args *args, int argc, char *argv[]) {
|
||||
@ -324,6 +395,8 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
||||
{"max-size", required_argument, NULL, 'm'},
|
||||
{"no-control", no_argument, NULL, 'n'},
|
||||
{"no-display", no_argument, NULL, 'N'},
|
||||
{"window-borderless", no_argument, NULL,
|
||||
OPT_WINDOW_BORDERLESS},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
{"push-target", required_argument, NULL,
|
||||
OPT_PUSH_TARGET},
|
||||
@ -335,8 +408,11 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
||||
{"show-touches", no_argument, NULL, 't'},
|
||||
{"turn-screen-off", no_argument, NULL, 'S'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"window-title", required_argument, NULL,
|
||||
OPT_WINDOW_TITLE},
|
||||
{"window-title", required_argument, NULL, OPT_WINDOW_TITLE},
|
||||
{"window-x", required_argument, NULL, OPT_WINDOW_X},
|
||||
{"window-y", required_argument, NULL, OPT_WINDOW_Y},
|
||||
{"window-width", required_argument, NULL, OPT_WINDOW_WIDTH},
|
||||
{"window-height", required_argument, NULL, OPT_WINDOW_HEIGHT},
|
||||
{NULL, 0, NULL, 0 },
|
||||
};
|
||||
int c;
|
||||
@ -402,6 +478,29 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
||||
case OPT_WINDOW_TITLE:
|
||||
args->window_title = optarg;
|
||||
break;
|
||||
case OPT_WINDOW_X:
|
||||
if (!parse_window_position(optarg, &args->window_x)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_Y:
|
||||
if (!parse_window_position(optarg, &args->window_y)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_WIDTH:
|
||||
if (!parse_window_dimension(optarg, &args->window_width)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_HEIGHT:
|
||||
if (!parse_window_dimension(optarg, &args->window_height)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_BORDERLESS:
|
||||
args->window_borderless = true;
|
||||
break;
|
||||
case OPT_PUSH_TARGET:
|
||||
args->push_target = optarg;
|
||||
break;
|
||||
@ -470,11 +569,16 @@ main(int argc, char *argv[]) {
|
||||
.port = DEFAULT_LOCAL_PORT,
|
||||
.max_size = DEFAULT_MAX_SIZE,
|
||||
.bit_rate = DEFAULT_BIT_RATE,
|
||||
.window_x = -1,
|
||||
.window_y = -1,
|
||||
.window_width = 0,
|
||||
.window_height = 0,
|
||||
.always_on_top = false,
|
||||
.no_control = false,
|
||||
.no_display = false,
|
||||
.turn_screen_off = false,
|
||||
.render_expired_frames = false,
|
||||
.window_borderless = false,
|
||||
};
|
||||
if (!parse_args(&args, argc, argv)) {
|
||||
return 1;
|
||||
@ -514,6 +618,10 @@ main(int argc, char *argv[]) {
|
||||
.record_format = args.record_format,
|
||||
.max_size = args.max_size,
|
||||
.bit_rate = args.bit_rate,
|
||||
.window_x = args.window_x,
|
||||
.window_y = args.window_y,
|
||||
.window_width = args.window_width,
|
||||
.window_height = args.window_height,
|
||||
.show_touches = args.show_touches,
|
||||
.fullscreen = args.fullscreen,
|
||||
.always_on_top = args.always_on_top,
|
||||
@ -521,6 +629,7 @@ main(int argc, char *argv[]) {
|
||||
.display = !args.no_display,
|
||||
.turn_screen_off = args.turn_screen_off,
|
||||
.render_expired_frames = args.render_expired_frames,
|
||||
.window_borderless = args.window_borderless,
|
||||
};
|
||||
int res = scrcpy(&options) ? 0 : 1;
|
||||
|
||||
|
@ -135,6 +135,9 @@ recorder_open(struct recorder *recorder, const AVCodec *input_codec) {
|
||||
// <https://github.com/FFmpeg/FFmpeg/commit/0694d8702421e7aff1340038559c438b61bb30dd>
|
||||
recorder->ctx->oformat = (AVOutputFormat *) format;
|
||||
|
||||
av_dict_set(&recorder->ctx->metadata, "comment",
|
||||
"Recorded by scrcpy " SCRCPY_VERSION, 0);
|
||||
|
||||
AVStream *ostream = avformat_new_stream(recorder->ctx, input_codec);
|
||||
if (!ostream) {
|
||||
avformat_free_context(recorder->ctx);
|
||||
|
@ -145,10 +145,8 @@ handle_event(SDL_Event *event, bool control) {
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event->window.event) {
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
screen_render(&screen);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
screen_window_resized(&screen);
|
||||
screen_render(&screen);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -392,7 +390,10 @@ scrcpy(const struct scrcpy_options *options) {
|
||||
options->window_title ? options->window_title : device_name;
|
||||
|
||||
if (!screen_init_rendering(&screen, window_title, frame_size,
|
||||
options->always_on_top)) {
|
||||
options->always_on_top, options->window_x,
|
||||
options->window_y, options->window_width,
|
||||
options->window_height,
|
||||
options->window_borderless)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,10 @@ struct scrcpy_options {
|
||||
uint16_t port;
|
||||
uint16_t max_size;
|
||||
uint32_t bit_rate;
|
||||
int16_t window_x;
|
||||
int16_t window_y;
|
||||
uint16_t window_width;
|
||||
uint16_t window_height;
|
||||
bool show_touches;
|
||||
bool fullscreen;
|
||||
bool always_on_top;
|
||||
@ -24,6 +28,7 @@ struct scrcpy_options {
|
||||
bool display;
|
||||
bool turn_screen_off;
|
||||
bool render_expired_frames;
|
||||
bool window_borderless;
|
||||
};
|
||||
|
||||
bool
|
||||
|
@ -117,35 +117,30 @@ get_optimal_window_size(const struct screen *screen, struct size frame_size) {
|
||||
}
|
||||
|
||||
// initially, there is no current size, so use the frame size as current size
|
||||
// req_width and req_height, if not 0, are the sizes requested by the user
|
||||
static inline struct size
|
||||
get_initial_optimal_size(struct size frame_size) {
|
||||
return get_optimal_size(frame_size, frame_size);
|
||||
}
|
||||
|
||||
static void
|
||||
update_frame_rect(struct screen *screen) {
|
||||
int ww;
|
||||
int wh;
|
||||
SDL_GL_GetDrawableSize(screen->window, &ww, &wh);
|
||||
|
||||
// 32 bits because we need to multiply two 16 bits values
|
||||
uint32_t fw = screen->frame_size.width;
|
||||
uint32_t fh = screen->frame_size.height;
|
||||
|
||||
SDL_Rect *rect = &screen->rect;
|
||||
|
||||
bool keep_width = fw * wh > fh * ww;
|
||||
if (keep_width) {
|
||||
rect->x = 0;
|
||||
rect->w = ww;
|
||||
rect->h = ww * fh / fw;
|
||||
rect->y = (wh - rect->h) / 2;
|
||||
get_initial_optimal_size(struct size frame_size, uint16_t req_width,
|
||||
uint16_t req_height) {
|
||||
struct size window_size;
|
||||
if (!req_width && !req_height) {
|
||||
window_size = get_optimal_size(frame_size, frame_size);
|
||||
} else {
|
||||
rect->y = 0;
|
||||
rect->h = wh;
|
||||
rect->w = wh * fw / fh;
|
||||
rect->x = (ww - rect->w) / 2;
|
||||
if (req_width) {
|
||||
window_size.width = req_width;
|
||||
} else {
|
||||
// compute from the requested height
|
||||
window_size.width = (uint32_t) req_height * frame_size.width
|
||||
/ frame_size.height;
|
||||
}
|
||||
if (req_height) {
|
||||
window_size.height = req_height;
|
||||
} else {
|
||||
// compute from the requested width
|
||||
window_size.height = (uint32_t) req_width * frame_size.height
|
||||
/ frame_size.width;
|
||||
}
|
||||
}
|
||||
return window_size;
|
||||
}
|
||||
|
||||
void
|
||||
@ -162,10 +157,13 @@ create_texture(SDL_Renderer *renderer, struct size frame_size) {
|
||||
|
||||
bool
|
||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
struct size frame_size, bool always_on_top) {
|
||||
struct size frame_size, bool always_on_top,
|
||||
int16_t window_x, int16_t window_y, uint16_t window_width,
|
||||
uint16_t window_height, bool window_borderless) {
|
||||
screen->frame_size = frame_size;
|
||||
|
||||
struct size window_size = get_initial_optimal_size(frame_size);
|
||||
struct size window_size =
|
||||
get_initial_optimal_size(frame_size, window_width, window_height);
|
||||
uint32_t window_flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;
|
||||
#ifdef HIDPI_SUPPORT
|
||||
window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
@ -178,9 +176,13 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
"(compile with SDL >= 2.0.5 to enable it)");
|
||||
#endif
|
||||
}
|
||||
if (window_borderless) {
|
||||
window_flags |= SDL_WINDOW_BORDERLESS;
|
||||
}
|
||||
|
||||
screen->window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
int x = window_x != -1 ? window_x : SDL_WINDOWPOS_UNDEFINED;
|
||||
int y = window_y != -1 ? window_y : SDL_WINDOWPOS_UNDEFINED;
|
||||
screen->window = SDL_CreateWindow(window_title, x, y,
|
||||
window_size.width, window_size.height,
|
||||
window_flags);
|
||||
if (!screen->window) {
|
||||
@ -196,6 +198,13 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SDL_RenderSetLogicalSize(screen->renderer, frame_size.width,
|
||||
frame_size.height)) {
|
||||
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
||||
screen_destroy(screen);
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_Surface *icon = read_xpm(icon_xpm);
|
||||
if (icon) {
|
||||
SDL_SetWindowIcon(screen->window, icon);
|
||||
@ -239,6 +248,12 @@ static bool
|
||||
prepare_for_frame(struct screen *screen, struct size new_frame_size) {
|
||||
if (screen->frame_size.width != new_frame_size.width
|
||||
|| screen->frame_size.height != new_frame_size.height) {
|
||||
if (SDL_RenderSetLogicalSize(screen->renderer, new_frame_size.width,
|
||||
new_frame_size.height)) {
|
||||
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// frame dimension changed, destroy texture
|
||||
SDL_DestroyTexture(screen->texture);
|
||||
|
||||
@ -284,7 +299,6 @@ screen_update_frame(struct screen *screen, struct video_buffer *vb) {
|
||||
mutex_unlock(vb->mutex);
|
||||
return false;
|
||||
}
|
||||
update_frame_rect(screen);
|
||||
update_texture(screen, frame);
|
||||
mutex_unlock(vb->mutex);
|
||||
|
||||
@ -292,16 +306,10 @@ screen_update_frame(struct screen *screen, struct video_buffer *vb) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
screen_window_resized(struct screen *screen) {
|
||||
update_frame_rect(screen);
|
||||
screen_render(screen);
|
||||
}
|
||||
|
||||
void
|
||||
screen_render(struct screen *screen) {
|
||||
SDL_RenderClear(screen->renderer);
|
||||
SDL_RenderCopy(screen->renderer, screen->texture, NULL, &screen->rect);
|
||||
SDL_RenderCopy(screen->renderer, screen->texture, NULL, NULL);
|
||||
SDL_RenderPresent(screen->renderer);
|
||||
}
|
||||
|
||||
@ -347,11 +355,3 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
|
||||
LOGD("Resized to pixel-perfect");
|
||||
}
|
||||
}
|
||||
|
||||
struct point
|
||||
screen_convert_to_frame_coords(struct screen *screen, float x, float y) {
|
||||
struct point out;
|
||||
out.x = (x - screen->rect.x) * screen->frame_size.width / screen->rect.w;
|
||||
out.y = (y - screen->rect.y) * screen->frame_size.height / screen->rect.h;
|
||||
return out;
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ struct screen {
|
||||
struct size frame_size;
|
||||
//used only in fullscreen mode to know the windowed window size
|
||||
struct size windowed_window_size;
|
||||
struct SDL_Rect rect;
|
||||
bool has_frame;
|
||||
bool fullscreen;
|
||||
bool no_window;
|
||||
@ -35,15 +34,9 @@ struct screen {
|
||||
.width = 0, \
|
||||
.height = 0, \
|
||||
}, \
|
||||
.rect = { \
|
||||
.x = 0, \
|
||||
.y = 0, \
|
||||
.w = 0, \
|
||||
.h = 0, \
|
||||
}, \
|
||||
.has_frame = false, \
|
||||
.fullscreen = false, \
|
||||
.no_window = false, \
|
||||
.has_frame = false, \
|
||||
.fullscreen = false, \
|
||||
.no_window = false, \
|
||||
}
|
||||
|
||||
// initialize default values
|
||||
@ -53,7 +46,9 @@ screen_init(struct screen *screen);
|
||||
// initialize screen, create window, renderer and texture (window is hidden)
|
||||
bool
|
||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
struct size frame_size, bool always_on_top);
|
||||
struct size frame_size, bool always_on_top,
|
||||
int16_t window_x, int16_t window_y, uint16_t window_width,
|
||||
uint16_t window_height, bool window_borderless);
|
||||
|
||||
// show the window
|
||||
void
|
||||
@ -67,10 +62,6 @@ screen_destroy(struct screen *screen);
|
||||
bool
|
||||
screen_update_frame(struct screen *screen, struct video_buffer *vb);
|
||||
|
||||
// update content after window resizing
|
||||
void
|
||||
screen_window_resized(struct screen *screen);
|
||||
|
||||
// render the texture to the renderer
|
||||
void
|
||||
screen_render(struct screen *screen);
|
||||
@ -87,9 +78,4 @@ screen_resize_to_fit(struct screen *screen);
|
||||
void
|
||||
screen_resize_to_pixel_perfect(struct screen *screen);
|
||||
|
||||
// convert point from window coordinates to frame coordinates
|
||||
// x and y are expressed in pixels (float to allow partial pixels)
|
||||
struct point
|
||||
screen_convert_to_frame_coords(struct screen *screen, float x, float y);
|
||||
|
||||
#endif
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "net.h"
|
||||
|
||||
#define SOCKET_NAME "scrcpy"
|
||||
#define SERVER_FILENAME "scrcpy-server.jar"
|
||||
#define SERVER_FILENAME "scrcpy-server"
|
||||
|
||||
#define DEFAULT_SERVER_PATH PREFIX "/share/scrcpy/" SERVER_FILENAME
|
||||
#define DEVICE_SERVER_PATH "/data/local/tmp/" SERVER_FILENAME
|
||||
@ -32,7 +32,7 @@ get_server_path(void) {
|
||||
// the absolute path is hardcoded
|
||||
return DEFAULT_SERVER_PATH;
|
||||
#else
|
||||
// use scrcpy-server.jar in the same directory as the executable
|
||||
// use scrcpy-server in the same directory as the executable
|
||||
char *executable_path = get_executable_path();
|
||||
if (!executable_path) {
|
||||
LOGE("Could not get executable path, "
|
||||
|
@ -3,5 +3,5 @@ option('compile_server', type: 'boolean', value: true, description: 'Build the s
|
||||
option('crossbuild_windows', type: 'boolean', value: false, description: 'Build for Windows from Linux')
|
||||
option('windows_noconsole', type: 'boolean', value: false, description: 'Disable console on Windows (pass -mwindows flag)')
|
||||
option('prebuilt_server', type: 'string', description: 'Path of the prebuilt server')
|
||||
option('portable', type: 'boolean', value: false, description: 'Use scrcpy-server.jar from the same directory as the scrcpy executable')
|
||||
option('portable', type: 'boolean', value: false, description: 'Use scrcpy-server from the same directory as the scrcpy executable')
|
||||
option('hidpi_support', type: 'boolean', value: true, description: 'Enable High DPI support')
|
||||
|
@ -23,21 +23,21 @@ cd -
|
||||
make -f Makefile.CrossWindows
|
||||
|
||||
# the generated server must be the same everywhere
|
||||
cmp "$BUILDDIR/server/scrcpy-server.jar" dist/scrcpy-win32/scrcpy-server.jar
|
||||
cmp "$BUILDDIR/server/scrcpy-server.jar" dist/scrcpy-win64/scrcpy-server.jar
|
||||
cmp "$BUILDDIR/server/scrcpy-server" dist/scrcpy-win32/scrcpy-server
|
||||
cmp "$BUILDDIR/server/scrcpy-server" dist/scrcpy-win64/scrcpy-server
|
||||
|
||||
# get version name
|
||||
TAG=$(git describe --tags --always)
|
||||
|
||||
# create release directory
|
||||
mkdir -p "release-$TAG"
|
||||
cp "$BUILDDIR/server/scrcpy-server.jar" "release-$TAG/scrcpy-server-$TAG.jar"
|
||||
cp "$BUILDDIR/server/scrcpy-server" "release-$TAG/scrcpy-server-$TAG"
|
||||
cp "dist/scrcpy-win32-$TAG.zip" "release-$TAG/"
|
||||
cp "dist/scrcpy-win64-$TAG.zip" "release-$TAG/"
|
||||
|
||||
# generate checksums
|
||||
cd "release-$TAG"
|
||||
sha256sum "scrcpy-server-$TAG.jar" \
|
||||
sha256sum "scrcpy-server-$TAG" \
|
||||
"scrcpy-win32-$TAG.zip" \
|
||||
"scrcpy-win64-$TAG.zip" > SHA256SUMS.txt
|
||||
|
||||
|
2
run
2
run
@ -20,4 +20,4 @@ then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRCPY_SERVER_PATH="$BUILDDIR/server/scrcpy-server.jar" "$BUILDDIR/app/scrcpy" "$@"
|
||||
SCRCPY_SERVER_PATH="$BUILDDIR/server/scrcpy-server" "$BUILDDIR/app/scrcpy" "$@"
|
||||
|
@ -1,2 +1,2 @@
|
||||
#!/bin/bash
|
||||
SCRCPY_SERVER_PATH="$MESON_BUILD_ROOT/server/scrcpy-server.jar" "$MESON_BUILD_ROOT/app/scrcpy"
|
||||
SCRCPY_SERVER_PATH="$MESON_BUILD_ROOT/server/scrcpy-server" "$MESON_BUILD_ROOT/app/scrcpy"
|
||||
|
62
server/build_without_gradle.sh
Executable file
62
server/build_without_gradle.sh
Executable file
@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# This script generates the scrcpy binary "manually" (without gradle).
|
||||
#
|
||||
# Adapt Android platform and build tools versions (via ANDROID_PLATFORM and
|
||||
# ANDROID_BUILD_TOOLS environment variables).
|
||||
#
|
||||
# Then execute:
|
||||
#
|
||||
# BUILD_DIR=my_build_dir ./build_without_gradle.sh
|
||||
|
||||
set -e
|
||||
|
||||
PLATFORM=${ANDROID_PLATFORM:-29}
|
||||
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-29.0.2}
|
||||
|
||||
BUILD_DIR="$(realpath ${BUILD_DIR:-build_manual})"
|
||||
CLASSES_DIR="$BUILD_DIR/classes"
|
||||
SERVER_DIR=$(dirname "$0")
|
||||
SERVER_BINARY=scrcpy-server
|
||||
|
||||
echo "Platform: android-$PLATFORM"
|
||||
echo "Build-tools: $BUILD_TOOLS"
|
||||
echo "Build dir: $BUILD_DIR"
|
||||
|
||||
rm -rf "$CLASSES_DIR" "$BUILD_DIR/$SERVER_BINARY" classes.dex
|
||||
mkdir -p "$CLASSES_DIR/com/genymobile/scrcpy"
|
||||
|
||||
<< EOF cat > "$CLASSES_DIR/com/genymobile/scrcpy/BuildConfig.java"
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
public final class BuildConfig {
|
||||
public static final boolean DEBUG = false;
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "Generating java from aidl..."
|
||||
cd "$SERVER_DIR/src/main/aidl"
|
||||
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/aidl" -o "$CLASSES_DIR" \
|
||||
android/view/IRotationWatcher.aidl
|
||||
|
||||
echo "Compiling java sources..."
|
||||
cd ../java
|
||||
javac -bootclasspath "$ANDROID_HOME/platforms/android-$PLATFORM/android.jar" \
|
||||
-cp "$CLASSES_DIR" -d "$CLASSES_DIR" -source 1.8 -target 1.8 \
|
||||
com/genymobile/scrcpy/*.java \
|
||||
com/genymobile/scrcpy/wrappers/*.java
|
||||
|
||||
echo "Dexing..."
|
||||
cd "$CLASSES_DIR"
|
||||
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/dx" --dex \
|
||||
--output "$BUILD_DIR/classes.dex" \
|
||||
android/view/*.class \
|
||||
com/genymobile/scrcpy/*.class \
|
||||
com/genymobile/scrcpy/wrappers/*.class
|
||||
|
||||
echo "Archiving..."
|
||||
cd "$BUILD_DIR"
|
||||
jar cvf "$SERVER_BINARY" classes.dex
|
||||
rm -rf classes.dex classes
|
||||
|
||||
echo "Server generated in $BUILD_DIR/$SERVER_BINARY"
|
@ -4,7 +4,7 @@ prebuilt_server = get_option('prebuilt_server')
|
||||
if prebuilt_server == ''
|
||||
custom_target('scrcpy-server',
|
||||
build_always: true, # gradle is responsible for tracking source changes
|
||||
output: 'scrcpy-server.jar',
|
||||
output: 'scrcpy-server',
|
||||
command: [find_program('./scripts/build-wrapper.sh'), meson.current_source_dir(), '@OUTPUT@', get_option('buildtype')],
|
||||
console: true,
|
||||
install: true,
|
||||
@ -16,7 +16,7 @@ else
|
||||
endif
|
||||
custom_target('scrcpy-server-prebuilt',
|
||||
input: prebuilt_server,
|
||||
output: 'scrcpy-server.jar',
|
||||
output: 'scrcpy-server',
|
||||
command: ['cp', '@INPUT@', '@OUTPUT@'],
|
||||
install: true,
|
||||
install_dir: 'share/scrcpy')
|
||||
|
@ -82,7 +82,7 @@ public class Controller {
|
||||
injectText(msg.getText());
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_TOUCH_EVENT:
|
||||
injectTouch(msg.getAction(), msg.getPointerId(), msg.getPosition(), msg.getPressure(), 0);
|
||||
injectTouch(msg.getAction(), msg.getPointerId(), msg.getPosition(), msg.getPressure(), msg.getButtons());
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_SCROLL_EVENT:
|
||||
injectScroll(msg.getPosition(), msg.getHScroll(), msg.getVScroll());
|
||||
@ -177,7 +177,7 @@ public class Controller {
|
||||
}
|
||||
|
||||
MotionEvent event = MotionEvent.obtain(lastTouchDown, now, action, pointerCount, pointerProperties,
|
||||
pointerCoords, 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
|
||||
pointerCoords, 0, buttons, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
|
||||
return injectEvent(event);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import java.io.IOException;
|
||||
|
||||
public final class Server {
|
||||
|
||||
private static final String SERVER_PATH = "/data/local/tmp/scrcpy-server.jar";
|
||||
private static final String SERVER_PATH = "/data/local/tmp/scrcpy-server";
|
||||
|
||||
private Server() {
|
||||
// not instantiable
|
||||
|
Reference in New Issue
Block a user