Commit graph

1537 commits

Author SHA1 Message Date
Romain Vimont
9ac57d6e71 hid_mouse_initialization 2022-01-01 20:05:17 +01:00
Romain Vimont
82ac944d23 refactor_hid_keyboard_init 2022-01-01 20:00:33 +01:00
Romain Vimont
b33e9ca3a7 hidmousecli 2022-01-01 19:48:44 +01:00
Romain Vimont
d140537e93 hid_mouse 2022-01-01 19:48:44 +01:00
Romain Vimont
9f80b91d72 Add CLAMP() macro 2022-01-01 19:48:44 +01:00
Romain Vimont
7dba4a9e98 relative-mouse-mode 2022-01-01 19:48:44 +01:00
Romain Vimont
9ec4017910 relative_mode 2022-01-01 19:48:44 +01:00
Romain Vimont
a97151707e Add relative mouse motion in event
This will allow the mouse processor to handle relative motion easily.
2022-01-01 19:48:44 +01:00
Romain Vimont
e84cdf963c Destroy acksync immediately on error
If AOA or HID keyboard may not be initialized for some reason, acksync
is useless.
2022-01-01 19:47:47 +01:00
Romain Vimont
4fcace8ab0 Remove duplicate boolean
The AOA initialization state is already tracked by aoa_hid_initialized.
2022-01-01 19:45:50 +01:00
Romain Vimont
e9bef7e880 Reorder controller and HID initialization
This allows to merge two "#ifdef HAVE_AOA_HID" blocks to simplify.
2022-01-01 19:38:27 +01:00
Romain Vimont
eb23a2afc8 Move input_manager into screen
The input_manager is strongly tied to the screen, it could not work
independently of the specific screen implementation.

To implement a user-friendly HID mouse behavior, some SDL events
will need to be handled both by the screen and by the input manager. For
example, a click must typically be handled by the input_manager so that
it is forwarded to the device, but in HID mouse mode, the first click
should be handled by the screen to capture the mouse (enable relative
mouse mode).

Make the input_manager a descendant of the screen, so that the screen
decides what to do on SDL events.

Concretely, replace this structure hierarchy:

     +- struct scrcpy
        +- struct input_manager
        +- struct screen

by this one:

     +- struct scrcpy
        +- struct screen
           +- struct input_manager
2022-01-01 19:01:27 +01:00
Romain Vimont
c7038da147 Use separate struct for input manager params
This avoids to directly pass the options instance (which contains more
data than strictly necessary), and limit the number of parameters for
the init function.
2022-01-01 19:01:27 +01:00
Romain Vimont
9e4773fd24 Pass buttons state in scroll events
A scroll event might be produced when a mouse button is pressed (for
example when scrolling while selecting a text). For consistency, pass
the actual buttons state (instead of 0).

In practice, it seems that this use case does not work properly with
Android event injection, but it will work with HID mouse.
2022-01-01 19:01:27 +01:00
Romain Vimont
dada6883d6 Make some mouse processors ops optional
Do not force all mouse processors implementations to implement scroll
events or touch events.
2022-01-01 19:01:27 +01:00
Romain Vimont
65087fcf57 Make process_text() optional
Not all key processors support text injection (HID keyboard does not
support it).

Instead of providing a dummy op function, set it to NULL and check on
the caller side before calling it.
2022-01-01 19:01:27 +01:00
Romain Vimont
71c2af1aed Apply buttons mask if not --forward-all-clicks
If --forward-all-clicks is not set, then only left clicks are forwarded.
For consistency, also mask the buttons state in other events.
2022-01-01 19:01:27 +01:00
Romain Vimont
4ab8775ed0 Reorder mouse processor ops
Group the mouse events callbacks before the touch event callback.
2022-01-01 19:01:27 +01:00
Romain Vimont
396bbc1a84 Simplify mouse injection implementation
The static functions are now so simple they become unnecessary: the
control message may be initialized directly instead.
2022-01-01 19:01:27 +01:00
Romain Vimont
f92e9edd1d Make some event conversions infallible
When the implementation handles all possible input values, it may never
fail.
2022-01-01 19:01:27 +01:00
Romain Vimont
07e46dabe4 Use scrcpy input events for mouse processors
Pass scrcpy input events instead of SDL input events to mouse
processors.

These events represent exactly what mouse processors need, abstracted
from any visual orientation and scaling applied on the SDL window.

This makes the mouse processors independent of the "screen" instance,
and the implementation source code independent of the SDL API.
2022-01-01 19:01:27 +01:00
Romain Vimont
abc5bcc6df Use scrcpy input events for key processors
Pass scrcpy input events instead of SDL input events to key processors.

This makes the source code of key processors independent of the SDL API.
2022-01-01 19:01:27 +01:00
Romain Vimont
2ba699902e Use common sc_action in input manager
Now that the scrcpy input events API exposes a sc_action enum, use the
same from the input manager.
2022-01-01 19:01:27 +01:00
Romain Vimont
191339987f Add intermediate input events layer
This aims to make the key/mouse processors independent of the "screen",
instead of processing SDL events themselves.

In particular, these scrcpy events are not impacted by any UI window
scaling or rotation (contrary to SDL events).
2022-01-01 19:01:27 +01:00
Romain Vimont
8cd245214d Rename SC_MOD_* to SC_SHORTCUT_MOD_*
This will avoid conflicts with new SC_MOD_* constants.
2022-01-01 19:01:27 +01:00
Romain Vimont
cc59906a38 Remove actions bitset
The input manager exposed functions taking an "actions" parameter,
containing a bitmask-OR of ACTION_UP and ACTION_DOWN.

But they are never called with both actions simultaneously anymore, so
simplify.

Refs 964b6d2243
Refs d0739911a3
2022-01-01 19:01:27 +01:00
Romain Vimont
7bd3da79b6 Expose V4L2 option on all platforms
This allows to report a meaningful error message if an unsupported
feature is used on another platform. This is consistent with the
behavior of -K/--hid-keyboard.
2022-01-01 19:01:27 +01:00
Romain Vimont
d76bf4c50c Fail on unsupported HID option
If the feature is not supported on the platform, fail during command
line parsing instead of using a fallback.
2022-01-01 19:01:26 +01:00
Romain Vimont
6b9f397733 Happy new year 2022! 2022-01-01 17:20:36 +01:00
Romain Vimont
1fbc590b26 Fix memory leaks in tests
Tests were failing when run with ASAN enabled.
2021-12-31 10:49:22 +01:00
Romain Vimont
826ddf1a6e Document HID keyboard events 2021-12-28 12:23:03 +01:00
Romain Vimont
6261bb0b5a Ignore display bounds on resize-to-fit
The "resize to fit" feature (MOD+w or double-click on black borders)
computed the "optimal size" using the same function computing the
initial window size on start.

However, on "resize to fit", only the black borders must be removed (the
content size must be preserved), so the display bounds must not be
considered.
2021-12-20 19:24:28 +01:00
Romain Vimont
2f091beeaa Simplify sc_size assignment
Assign the whole struct instead of each field separately.
2021-12-20 19:24:28 +01:00
Romain Vimont
720c3064df Upgrade SDL (2.0.18) for Windows
Include the latest version of SDL in Windows releases.
2021-12-20 19:16:28 +01:00
Romain Vimont
ad11c5babb Set DPI awareness for Windows
Add a windows manifest to set the DPI awareness by default:
<https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process>

Refs #40 <https://github.com/Genymobile/scrcpy/issues/40>
Fixes #2865 <https://github.com/Genymobile/scrcpy/issues/2865>
2021-12-20 19:13:02 +01:00
Romain Vimont
feb250a973 Fix typos reported by codespell 2021-12-15 18:27:45 +01:00
Chih-Hsuan Yen
d049671908 Fix adb server hang
Since commit 0426708544, the server is run
in a dedicated thread. For SDL, many signals, including SIGINT and
SIGTERM, are masked for new threads. As a result, if the adb server is
not already running, adb commands invoked by scrcpy will start an adb
server that ignores those signals and cannot be terminated at system
shutdown.

Fixes #2873 <https://github.com/Genymobile/scrcpy/issues/2873>
PR #2870 <https://github.com/Genymobile/scrcpy/pull/2870>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2021-12-11 19:09:11 +01:00
Romain Vimont
0685c491cd Improve crossbuild configuration
Use meson native features to detect crossbuild, and remove the
user-provided option crossbuild_windows.
2021-12-10 19:50:58 +01:00
Romain Vimont
892cfe943e Add script to bump version
The version must now be bumped at 4 different places. Add a script to
bump automatically:

    ./bump_version 1.23.4
2021-12-10 19:50:17 +01:00
Romain Vimont
29570ee819 Add metadata to scrcpy.exe for Windows
Refs <https://stackoverflow.com/a/708382/1987178>
2021-12-09 23:38:13 +01:00
Romain Vimont
cfcbc2ac21 Add icon to scrcpy.exe
The icon will be associated to scrcpy.exe in the Windows explorer.

The .ico was created using imagemagick:

    convert icon.png icon.ico

It is included as a binary for simplicity.

Refs #2815 <https://github.com/Genymobile/scrcpy/issues/2815>
2021-12-09 23:38:13 +01:00
Romain Vimont
2cb4e04209 Update copyright date to 2021 in manpage
December, it's time to update to 2021!
2021-12-09 23:37:40 +01:00
Romain Vimont
878ffffc36 Update environment variables section in manpage
Use the same content as the section printed with --help.
2021-12-09 21:47:05 +01:00
Romain Vimont
f0361fc8b3 Add environment variables in help
Print the list of environment variables used by scrcpy in --help.
2021-12-09 21:45:39 +01:00
Romain Vimont
b5d4ec61fc Move newline generation in help
If we removed the shortcuts intro, we would not need the additional '\n'
of the section title, so it should be printed along with the shortcuts
intro.
2021-12-09 21:43:54 +01:00
Romain Vimont
3ada5c51bc Rename scrcpy threads
Prefix the name of threads by "scrcpy-". This improves readability in
the output of `top -H` for example.

Limit the thread names to 16 bytes, because it is limited on some
platforms.
2021-12-09 21:32:11 +01:00
Romain Vimont
09c55b0f93 Set "low delay" decoder flag
I don't really know the concrete benefits, but scrcpy definitely wants
low delay decoding.

Suggested-by: François Cartegnie <fcvlcdev@free.fr>
2021-12-08 23:53:54 +01:00
Romain Vimont
682a691173 Use timers with microsecond precision
SDL only provides millisecond precision. Use system timers to get a
better precision.
2021-12-08 23:45:45 +01:00
Romain Vimont
ddb9396743 Interrupt and close sockets on server stop
The sockets were never interrupted or closed by the client since recent
changes to run the server from a dedicated thread (see commit
0426708544).

As a side effect, the server could never terminate properly (it was
waiting on socket blocking calls), so it was always killed by the client
after the WATCHDOG_DELAY.

Interrupt the sockets on stop to give the servera chance to terminate
property, then close them.
2021-12-08 23:44:23 +01:00
Romain Vimont
cabcbc2b15 Do not create control socket if no control
If --no-control is enabled, then it is not necessary to create a second
communication socket between the client and the server.

This also facilitates the use of the server alone (without the client)
to receive only the raw video stream.
2021-12-08 23:41:38 +01:00