Commit Graph

1580 Commits (53c6eb66ea8fc07433ffe686e9994c8d7c104b7a)

Author SHA1 Message Date
Romain Vimont c57a0512ba Add assertions
Passing an unknown enum value to convert them to string would return
NULL without any error, possibly causing undefined behavior later.

Add assertions to catch such programming errors early.
2 months ago
Romain Vimont 9989668226 Add mouse secondary bindings
Add secondary bindings (Shift+click) for mouse buttons.

In addition to:

    --mouse-bind=xxxx

It is now possible to pass a sequence of secondary bindings:

    --mouse-bind=xxxx:xxxx
                 <--> <-->
             primary   secondary
            bindings   bindings

If the second sequence is omitted, then it is the same as the first one.

By default, for SDK mouse, primary bindings trigger shortcuts and
secondary bindings forward all clicks.

For AOA and UHID, the default bindings are reversed: all clicks are
forwarded by default, whereas pressing Shift+click trigger shortcuts.

    --mouse-bind=bhsn:++++  # default for SDK
    --mouse-bind=++++:bhsn  # default for AOA and UHID

Refs 035d60cf5d
Refs f5e6b8092a
Fixes #5055 <https://github.com/Genymobile/scrcpy/issues/5055>
PR #5076 <https://github.com/Genymobile/scrcpy/pull/5076>
2 months ago
Romain Vimont 6baea57987 Track mouse buttons state manually
The buttons state was tracked by SDL_GetMouseState(), and scrcpy applied
a mask to ignore buttons used for shortcuts.

Instead, track the buttons actually pressed (ignoring shortcuts)
manually, to prepare the introduction of more dynamic mouse shortcuts.

PR #5076 <https://github.com/Genymobile/scrcpy/pull/5076>
2 months ago
Romain Vimont 86b8286217 Remove unused virtual mouse
PR #5076 <https://github.com/Genymobile/scrcpy/pull/5076>
2 months ago
Romain Vimont 51fee79bf5 Use finger source when a pointer is simulated
For pinch-to-zoom, rotation and tilt simulation, always use a finger
source (instead of a mouse) for both pointers (the real one and the
simulated one).

A "virtual" mouse does not work on all devices (e.g. on Pixel 8).

PR #5076 <https://github.com/Genymobile/scrcpy/pull/5076>
2 months ago
Romain Vimont 6808288823 Make pointer id independent of mouse bindings
The device source (MOUSE or FINGER) to use depended on whether a
secondary click was possible via mouse bindings.

As a first step, always use a mouse source to break this dependency.
Note that this change might cause regressions in some (unknown) cases
(refs f70359f14f), but hopefully not.

Further commits will restore a finger source in some specific use cases,
but independent of secondary clicks.

Refs #5055 <https://github.com/Genymobile/scrcpy/issues/5055>
Fixes #5067 <https://github.com/Genymobile/scrcpy/issues/5067>
PR #5076 <https://github.com/Genymobile/scrcpy/pull/5076>
2 months ago
Romain Vimont 0bce4d7f56 Add missing SC_ prefix for pointer id constants
PR #5076 <https://github.com/Genymobile/scrcpy/pull/5076>
2 months ago
Romain Vimont 6d98766cd5 Simplify boolean condition using XOR
(A && !B) || (!A && B) <==> A ^ B

PR #5076 <https://github.com/Genymobile/scrcpy/pull/5076>
2 months ago
Romain Vimont 487a6b9cf4 Remove top-level const
For consistency, never use top-level const for local variables.

PR #5076 <https://github.com/Genymobile/scrcpy/pull/5076>
2 months ago
Yan 46041e0cc0 Always initialize display->gl_context on macOS
Otherwise SDL_GL_DeleteContext() tried to access an uninitialized
pointer upon exit when not using the OpenGL renderer.

SDL_GL_DeleteContext() doesn't try to delete a NULL pointer, so no need
to check for that.

Fixes #5057 <https://github.com/Genymobile/scrcpy/issues/5057>
PR #5058 <https://github.com/Genymobile/scrcpy/pull/5058>

Signed-off-by: Romain Vimont <rom@rom1v.com>
3 months ago
Romain Vimont b419eef55e Do not report error on device disconnected
A device disconnection (when the adb connection is closed) makes the
read() on the "receiver" socket fail.

Since commit 063a8339ed, this is reported
as an error. As a consequence, scrcpy fails with:

    ERROR: Controller error

instead of:

    WARN: Device disconnected

To fix the issue, report a device disconnection in that case.

PR #5044 <https://github.com/Genymobile/scrcpy/pull/5044>
3 months ago
Romain Vimont a4f8c02502 Reorder initialization to simplify
This also avoids a warning with some compilers which do not understand
that the condition to initialize the variable is the same as the
condition to use it:

    ../app/src/scrcpy.c: In function ‘scrcpy’:
    ../app/src/scrcpy.c:750:13: warning: ‘src’ may be used uninitialized in this function [-Wmaybe-uninitialized]
      750 |             sc_frame_source_add_sink(src, &s->screen.frame_sink);
          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Refs 45fe6b602b
Refs <https://github.com/Genymobile/scrcpy/issues/5045#issuecomment-2201589757>
3 months ago
Romain Vimont 89df38f641 Bump version to 2.5 3 months ago
Romain Vimont 343f715323 Upgrade platform-tools (35.0.0) for Windows 3 months ago
Romain Vimont f13f00021f Upgrade SDL (2.30.4) for Windows 3 months ago
Romain Vimont 48c2c03093 Upgrade FFmpeg (7.0.1) for Windows 3 months ago
Romain Vimont 1e3deabd6c Do not call avcodec_close()
The documentation of avcodec_close() says:

> Do not use this function. Use avcodec_free_context() to destroy a
> codec context (either open or closed).

It was deprecated in FFmpeg 7 by commit
1cc24d749569a42510399a29b034f7a77bdec34e:

<1cc24d7495>

> Its use has been discouraged since 2016, but now is no longer used in
> avformat, so there is no reason to keep it public.
3 months ago
Romain Vimont 7633228278 Forward mouse hover events
Also add an option --no-mouse-hover to get the old behavior.

Fixes #2743 <https://github.com/Genymobile/scrcpy/issues/2743>
Fixes #3070 <https://github.com/Genymobile/scrcpy/issues/3070>
PR #5039 <https://github.com/Genymobile/scrcpy/pull/5039>
3 months ago
Romain Vimont f5e6b8092a Forward all clicks by default for UHID/AOA
By default, only the left click is forwarded to the device, and
secondary clicks trigger shortcuts (the behavior can be configured by
--mouse-bind=xxxx).

But when the mouse mode is relative (AOA and UHID modes), forward all
clicks by default. This makes more sense since the cursor is handled on
the device side, the user expects all mouse buttons to be forwarded.

Refs <https://github.com/Genymobile/scrcpy/issues/4727#issuecomment-2069869750>
PR #5022 <https://github.com/Genymobile/scrcpy/pull/5022>
3 months ago
Romain Vimont 035d60cf5d Add option to configure mouse bindings
Add a new option --mouse-bind=xxxx.

The argument must be exactly 4 characters, one for each secondary click:

    --mouse-bind=xxxx
                 ^^^^
                 ||||
                 ||| `- 5th click
                 || `-- 4th click
                 | `--- middle click
                  `---- right click

Each character must be one of the following:
 - `+`: forward the click to the device
 - `-`: ignore the click
 - `b`: trigger shortcut BACK (or turn screen on if off)
 - `h`: trigger shortcut HOME
 - `s`: trigger shortcut APP_SWITCH
 - `n`: trigger shortcut "expand notification panel"

This deprecates --forward-all-clicks (use --mouse-bind=++++ instead).

Refs <https://github.com/Genymobile/scrcpy/pull/2258#issuecomment-2182394460>
PR #5022 <https://github.com/Genymobile/scrcpy/pull/5022>
3 months ago
Romain Vimont 40493dff60 Fix "resize to fit" when all clicks are forwarded
To resize the window to fit the device screen, it is possible to
double-click in the "black bars".

This feature was mistakenly disabled when --forward-all-clicks was set.

Instead, disable it only if mouse relative mode is enabled (AOA or
UHID), because in that case the mouse cursor is on the device.
3 months ago
Romain Vimont 09ce0307fe Fix zsh completion script
An '=' was missing for some options with an argument.
3 months ago
Romain Vimont 9fa30ab1ae Fix error message parameter
Use the local argument value, not the global optarg variable (even if it
has the same value in practice, as it's passed as argument).
3 months ago
Romain Vimont 0b926922bc Ignore shortcut keycodes
Never inject keycodes used as shortcut modifiers.

Refs #4732 <https://github.com/Genymobile/scrcpy/issues/4732>
PR #4741 <https://github.com/Genymobile/scrcpy/pull/4741>
3 months ago
Romain Vimont 24bcc3fa2b Simplify shortcut modifiers
Restrict shortcut modifiers to be composed of only one item each.

Before, it was possible to select a list of multiple combinations of
modifier keys, like --shortcut-mod='lctrl+lalt,rctrl+rsuper', meaning
that shortcuts would be triggered either by LCtrl+LAlt+key or
RCtrl+RSuper+key.

This was overly generic, probably not used very much, and it prevents to
solve inconsistencies between UP and DOWN events of modifier keys sent
to the device.

Refs #4732 <https://github.com/Genymobile/scrcpy/issues/4732>
PR #4741 <https://github.com/Genymobile/scrcpy/pull/4741>
3 months ago
Romain Vimont 24b9e0a970 Retrieve icon decoder directly
The call to av_find_best_stream() gives the decoder directly, this
avoids to retrieve it afterwards in a separate step.
3 months ago
Romain Vimont 9ea4446369 Release the audio lock early
The final write from the writer thread does not require a lock: it is
guaranteed that enough space is available since the reader thread never
writes.
4 months ago
Romain Vimont 5d1d5bdc16 Fix thread leak on Windows
Fixes #4973 <https://github.com/Genymobile/scrcpy/issues/4973>
4 months ago
Romain Vimont fd9498e07c Avoid zero-length copies
Return early if there is nothing to read/write.
4 months ago
Romain Vimont da484b7ab9 Reject recording with control only
If video and audio are disabled, there is nothing to record.
4 months ago
Romain Vimont 063a8339ed Terminate on controller error
This is particularly important to react to server socket disconnection
since video and audio may be disabled.

PR #4868 <https://github.com/Genymobile/scrcpy/pull/4868>
4 months ago
Romain Vimont 45fe6b602b Add scrcpy window without video playback
Add the possibility to solely control the device without screen
mirroring:

    scrcpy --no-video --no-audio

This is different from OTG mode, which does not require USB debugging at
all. Here, the standard mode is used but with the possibility to disable
video playback.

By default, always open a window (even without video playback), and add
an option --no-window.

Fixes #4727 <https://github.com/Genymobile/scrcpy/issues/4727>
Fixes #4793 <https://github.com/Genymobile/scrcpy/issues/4793>
PR #4868 <https://github.com/Genymobile/scrcpy/pull/4868>
4 months ago
Romain Vimont cca2c9ffb7 Disable FPS counter when no video playback
There is no frame rate to count.
5 months ago
Romain Vimont 22d78e8a82 Fix boolean condition
Use the short-circuit operator && between booleans.
5 months ago
Romain Vimont 9aa6cc71be Forbid --no-control in OTG mode
The whole purpose of OTG is to only control the device.
5 months ago
Romain Vimont 54e08b4eae Fix code style
Limit to 80 columns.
5 months ago
Romain Vimont aa34d63171 Fix segfault on close with --no-video
Do not call sc_screen_hide_window() if screen is not initialized.

To reproduce:

    scrcpy --no-video --record=file.mp4

This only segfaults in debug mode since commit
fd0f432e87.
6 months ago
Romain Vimont db55edb196 Fix YUV conversion for full color range
Take the color range (full vs limited) into account to render the
picture.

Note that with the current version of SDL, it has no impact with the SDL
opengl render driver.

Fixes #4756 <https://github.com/Genymobile/scrcpy/issues/4756>
Refs <https://github.com/Genymobile/scrcpy/issues/4756#issuecomment-2003228916>
Refs libusb/#9311 <https://github.com/libsdl-org/SDL/issues/9311>

Suggested-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
6 months ago
Romain Vimont 1c3801a0b1 Add a shortcut to pause/unpause display
Pause/unpause display on MOD+z and MOD+Shift+z.

It only impacts rendering, the device is still captured, the video
stream continues to be transmitted to the device and recorded (if
recording is enabled).

Fixes #1632 <https://github.com/Genymobile/scrcpy/issues/1632>
PR #4748 <https://github.com/Genymobile/scrcpy/pull/4748>
6 months ago
Romain Vimont be3d357a6d Use source repo tarball for libusb
Legitimate or not, we should not use sources that do not match the
repository.

Refs <https://github.com/libusb/libusb/issues/1468#issuecomment-1974787595>
Refs <https://news.ycombinator.com/item?id=39866309>
Refs #4713 <https://github.com/Genymobile/scrcpy/pull/4713>
6 months ago
Romain Vimont af57309074 Bump version to 2.4 7 months ago
Romain Vimont a720c946a6 Merge branch 'master' into release 7 months ago
Romain Vimont 8d87b91f69 Build dependencies from sources
The project has 3 build dependencies:
 - SDL
 - FFmpeg
 - libusb

For Windows, the release script downloaded pre-built build dependencies
(either from upstream, or from the scrcpy-deps repository).

Instead, download the source releases and build locally. This offers
more flexibility.

The official adb release is still downloaded and included as is in the
release archive (it is not a build dependency).

Also upgrade FFmpeg to 6.1.1 and libusb to 1.0.27.

PR #4713 <https://github.com/Genymobile/scrcpy/pull/4713>
7 months ago
inson1 125b1103e1 Happy new year 2024!
PR #4716 <https://github.com/Genymobile/scrcpy/pull/4716>

Signed-off-by: Romain Vimont <rom@rom1v.com>
7 months ago
Romain Vimont 36189b90ea Remove spurious line 7 months ago
Romain Vimont 4dca08cfe3 Set SDL hints before creating any thread
To avoid race conditions in SDL (reported by TSAN).
7 months ago
Romain Vimont fd0f432e87 Detect missing initializations
Write invalid data in memory to easily detect missing initializations in
debug mode.
7 months ago
Romain Vimont cdf09805c0 Add missing initialization 7 months ago
Romain Vimont dd479ed176 Check options specific to SDK keyboard
Fail if an option specific to --keyboard=sdk is passed with another
keyboard input mode.

PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
7 months ago
Romain Vimont 5f12132c47 Do not fallback keyboard mode if AOA fails
Initially, if AOA initialization failed, default injection method was
used, in order to use the same command/shortcut when the device is
connected via USB or via TCP/IP, without changing the arguments.

Now that there are 3 keyboard modes, it seems unexpected to switch to
another specific mode if AOA fails (and it is inconsistent). If the user
explicitly requests AOA, then use AOA or fail.

Refs #2632 comment <https://github.com/Genymobile/scrcpy/pull/2632#issuecomment-945190859>
PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
7 months ago