Commit graph

1571 commits

Author SHA1 Message Date
Romain Vimont
30c79f2d25 Merge branch 'master' into dev 2021-11-29 22:08:43 +01:00
Romain Vimont
b25b674c45 Clarify TCP/IP mode in README 2021-11-29 22:03:58 +01:00
Romain Vimont
e2b3968c66 Always synchronize clipboard on explicit COPY/CUT
If --no-clipboard-autosync is enabled, the automatic clipboard
synchronization performed whenever the device clipboard changes is
disabled.

But on explicit COPY and CUT scrcpy shortcuts (MOD+c and MOD+x), the
clipboard should still be synchronized, so that it remains possible to
copy-paste from the device to the computer.

This is consistent with the behavior of MOD+v, which pastes the computer
clipboard to the device.

Refs #2228 <https://github.com/Genymobile/scrcpy/issues/2228>
Refs #2817 <https://github.com/Genymobile/scrcpy/pull/2817>
PR #2834 <https://github.com/Genymobile/scrcpy/pull/2834>
2021-11-29 22:00:55 +01:00
Romain Vimont
bfcb9d06c3 Expose sync mode for injecting events
Expose the inject input event mode so that it is possible to wait for
the events to be "finished". This will be necessary to read the
clipboard content only after the COPY or CUT key event is handled.

PR #2834 <https://github.com/Genymobile/scrcpy/pull/2834>
2021-11-29 22:00:21 +01:00
Romain Vimont
dc19ae334d Move acknowledgment handling
Handle all actions related to SET_CLIPBOARD from the dedicated method.

PR #2834 <https://github.com/Genymobile/scrcpy/pull/2834>
2021-11-29 21:58:30 +01:00
Romain Vimont
cbe73b0bc3 Fix set_clipboard message log
If paste is disabled on set_clipboard, then the PASTE key is not
injected, but COPY is unrelated.

PR #2834 <https://github.com/Genymobile/scrcpy/pull/2834>
2021-11-29 21:55:37 +01:00
Romain Vimont
bf97a46b0c Upgrade gradle build tools to 7.0.3 2021-11-29 21:55:12 +01:00
Romain Vimont
bd56d81f72 Add --raw-key-events
This option allows to inject all input keys as key events, and ignore
text events.

Fixes #2816 <https://github.com/Genymobile/scrcpy/issues/2816>
PR #2831 <https://github.com/Genymobile/scrcpy/pull/2831>
2021-11-29 21:15:41 +01:00
Romain Vimont
5e918ac0c3 Use enum for key injection mode
There was only two key injection modes:
 - the default one
 - the mode with --prefer-text enabled

To prepare the addition of another mode (--raw-key-events), use an enum
instead of a bool.

PR #2831 <https://github.com/Genymobile/scrcpy/pull/2831>
2021-11-29 21:15:32 +01:00
Romain Vimont
0c0f62e4ab Use static maps to convert input events
This improves readability (hopefully).

PR #2831 <https://github.com/Genymobile/scrcpy/pull/2831>
2021-11-29 21:15:07 +01:00
Romain Vimont
c96505200a Fix code style in keyboard_inject 2021-11-29 21:01:57 +01:00
Romain Vimont
82a053015d Improve HID keyboard documentation
Explain how to configure the keyboard layout.
2021-11-29 21:01:15 +01:00
Romain Vimont
1a6caeb18c Document --tcpip in README
PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
19858e6aeb Add --tcpip feature
Expose an option to automatically configure and reconnect the device
over TCP/IP, to simplify wireless connection without using adb
explicitly.

There are two variants:
 - If a destination address is provided, then scrcpy connects to this
   address before starting. The device must listen on the given TCP port
   (default is 5555).
 - If no destination address is provided, then scrcpy attempts to find
   the IP address of the current device (typically connected over USB),
   enables TCP/IP mode, then connects to this address before starting.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
3b310f8317 Extract interruptible sleep for server
This improves readability, and makes the function reusable.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
800ba33ff4 Add function to read an adb property
This will allow to read the property "service.adb.tcp.port" to know if
the TCP/IP mode is enabled on the device, and which listening port is
used.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
8543d842ea Add function to switch device to TCP/IP mode
Expose a function to execute "adb tcpip <port>".

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
f609b406c9 Add function to find the device IP address
Parse the result of "adb shell ip route" to find the device IP address.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
b7e631791c Add util function to remove trailing '\r'
Depending on the platform and adb versions, the lines output by adb
could end with "\r\r\n". This util function helps to remove all trailing
'\r'.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
b52f87a892 Add util function to locate a column in a string
This will help to parse the result of "adb shell ip route" to find the
device IP address.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
3bf6fd2894 Workaround "adb connect" error detection
"adb connect" always returns successfully (with exit code 0), even in
case of failure.

As a workaround, capture its output and check if it starts with
"connected".

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
bfce22414f Add adb connect and disconnect
PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
e6e6f865a0 Add adb flag to disable execution error logs
In addition to disable stdout and stderr of the child process, add a
flag to disable the error log printed by scrcpy if the command failed.

This will we useful for commands which are expected to fail in some
cases (like "adb disconnect" if the device is not connected).

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
e3d4aa8c5d Use flags for adb commands
Explicitly indicate, for each adb call, if stdout and stderr must be
inherited.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
f801d8b312 Expose flags for process execution
Let the caller decide if stdout and stderr must be inherited on process
creation, i.e. if stdout and stderr of the child process should be
printed in the scrcpy console.

This allows to get output and errors for specific adb commands depending
on the context.

PR #2827 <https://github.com/Genymobile/scrcpy/pull/2827>
2021-11-29 20:39:03 +01:00
Romain Vimont
01ab503c22 Remove obsolete precision in README
Scrcpy is available in Debian stable packages, and several Ubuntu
versions.
2021-11-29 00:36:09 +01:00
Romain Vimont
b9b8b6aab8 Simplify Windows process inheritance configuration
Merge if-blocks together.
2021-11-26 09:41:11 +01:00
Romain Vimont
3e54773c48 Remove intermediate static functions from adb.c
They can easily be inlined into the public functions.
2021-11-26 09:41:11 +01:00
Romain Vimont
b90c89766b Set CLOEXEC flag on sockets
If SOCK_CLOEXEC exists, then set the flag on socket creation.

Otherwise, use fcntl() (or SetHandleInformation() on Windows) to set the
flag afterwards.

This avoids the sockets to be inherited in child processes.

Refs #2783 <https://github.com/Genymobile/scrcpy/pull/2783>
2021-11-26 09:40:39 +01:00
Romain Vimont
904f0ae61e Check process success locally for adb commands
Remove sc_process_check_success() from the process API, it is too
specific.
2021-11-25 22:22:34 +01:00
Romain Vimont
680d2cc940 Extract command argv building
This simplifies adb_execute_p().
2021-11-25 22:22:34 +01:00
Romain Vimont
8ed3328055 Use unsigned for connection attempts count
There is no reason to use an explicit uint32_t.
2021-11-25 22:22:34 +01:00
Romain Vimont
d31725f077 Reorder cli sanity checks
Check unexpected additional arguments before other sanity checks.
2021-11-25 22:22:34 +01:00
Romain Vimont
b0eb1a55d6 Fix adb get-serialno error handling
If pipe read fails, return.
2021-11-25 22:22:34 +01:00
Romain Vimont
3653fb6b15 Add OutOfMemory log helper
Add a special LOG_OOM() function to log all OutOfMemory errors (i.e.
allocations returning NULL).
2021-11-24 22:06:49 +01:00
Romain Vimont
92a458e846 Remove unreachable return statements 2021-11-24 21:48:57 +01:00
Romain Vimont
73e0311d14 Add missing return on file_handler failure
Mistake introduced by 84334cf7db.
2021-11-24 21:46:02 +01:00
Romain Vimont
007f616302 Add missing includes
Include these headers explicitly instead of relying on transitivity.
2021-11-24 21:44:29 +01:00
Romain Vimont
4c47598865 Make lockVideoOrientation option name uniform
On the server, the option was named lockedVideoOrientation.
2021-11-24 21:33:58 +01:00
Romain Vimont
7b29f5fd2d Do not pass default values to the server
By default, only pass the version and the bit rate (the default bitrate
is a client compilation option).
2021-11-24 21:31:12 +01:00
Romain Vimont
04e5537f8c Pass server parameters as key=value pairs
The options values to configure the server were identified by their
command-line argument index. Now that there are a lot of arguments, many
of them being booleans, it became unreadable and error-prone.

Identify the arguments by a key string instead, and make them optional.

This will also simplify running the server manually for debugging.
2021-11-24 21:23:20 +01:00
Romain Vimont
2eb881c5f1 Allocate and format server command args
This simplifies formatting.
2021-11-24 21:10:18 +01:00
Romain Vimont
2c3099e2de Parse codec options early
For consistency with other options, parse the codec options on the
server before storing them in the Options instance.
2021-11-24 21:06:02 +01:00
Romain Vimont
5434ea543c Remove local "serial" variable
In execute_server(), the serial is used only once. Moreover, it can be
retrieved from the `params` argument directly.
2021-11-24 21:01:25 +01:00
Romain Vimont
d5f6697f3a Add (v)asprintf compatibility functions
In case they are not available on the platform.
2021-11-24 19:55:00 +01:00
Romain Vimont
d6c0054545 Move check_functions in meson script
Move the variable to the place it is actually used.
2021-11-24 19:38:33 +01:00
Romain Vimont
6f487a2892 Add missing includes in compat implementation
These includes are necessary for the strdup() compat implementation.
2021-11-24 19:37:33 +01:00
Romain Vimont
dc0ac01e00 Define common feature test macros for all systems
_POSIX_C_SOURCE, _XOPEN_SOURCE and _GNU_SOURCE are also used on Windows.

Fix regression introduced by ba547e3895.
2021-11-24 19:36:33 +01:00
Romain Vimont
6abff46c9f Add option to disable clipboard autosync
By default, scrcpy automatically synchronizes the computer clipboard to
the device clipboard before injecting Ctrl+v, and the device clipboard
to the computer clipboard whenever it changes.

This new option --no-clipboard-autosync disables this automatic
synchronization.

Fixes #2228 <https://github.com/Genymobile/scrcpy/issues/2228>
PR #2817 <https://github.com/Genymobile/scrcpy/pull/2817>
2021-11-24 09:44:39 +01:00
Romain Vimont
5d17bcf1bc Wait SET_CLIPBOARD ack before Ctrl+v via HID
To allow seamless copy-paste, on Ctrl+v, a SET_CLIPBOARD request is
performed before injecting Ctrl+v.

But when HID keyboard is enabled, the Ctrl+v injection is not sent on
the same channel as the clipboard request, so they are not serialized,
and may occur in any order. If Ctrl+v happens to be injected before the
new clipboard content is set, then the old content is pasted instead,
which is incorrect.

To minimize the probability of occurrence of the wrong order, a delay of
2 milliseconds was added before injecting Ctrl+v. Then 5ms. But even
with 5ms, the wrong behavior sometimes happens.

To handle it properly, add an acknowledgement mechanism, so that Ctrl+v
is injected over AOA only after the SET_CLIPBOARD request has been
performed and acknowledged by the server.

Refs e4163321f0
Refs 45b0f8123a

PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
2021-11-24 09:41:21 +01:00