Add an option to configure how the rendering fits the window.
The default, `--render-fit=letterbox`, preserves the aspect ratio
and fits the window as best as possible, adding black bars at
the top/bottom or left/right if needed. This has been the only behavior
scrcpy supported so far.
Another mode, `--render-fit=disabled`, renders the display at the
top-left corner without scaling. This mode will be useful for virtual
display resizing.
So far, scrcpy always resized the window whenever a frame with a new
size was received. However, with the upcoming "flex display" feature,
the size of the virtual display can change either on its own (e.g.,
due to app rotation) or as a result of a client window resize.
Track the cause of each resize and signal it in the session metadata.
Resize the window only if the change was not triggered by a client
request to prevent resize loops and stuttering.
The window aspect ratio was previously enforced by calling
`SDL_SetWindowAspectRatio()` before explicitly setting the window size,
using the width/height ratio of the new size.
However, this size may already be a scaled version of the actual content
size, subject to integer rounding. Using this derived size instead of
the actual content size could result in an inaccurate ratio, causing a
mismatch between the content and window aspect ratios, which may result
in a thin row or column of black pixels.
To avoid this issue, always set the aspect ratio based on the content
size.
Refs 1b4fd67286
Refs #6761 <https://github.com/Genymobile/scrcpy/pull/6761>
PR #6774 <https://github.com/Genymobile/scrcpy/pull/6774>
By default, the window aspect ratio is preserved when resizing.
Add `--no-window-aspect-ratio-lock` to disable this behavior.
PR #6761 <https://github.com/Genymobile/scrcpy/pull/6761>
Signed-off-by: Romain Vimont <rom@rom1v.com>
On Windows and macOS, resizing the window with the mouse blocks the
event loop until the click is released. To keep rendering during
resizing, an event watcher is registered to handle resize events.
Avoid handling resize events twice by ensuring
`SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED` is processed only once.
PR #6758 <https://github.com/Genymobile/scrcpy/pull/6758>
Previously, when the connection to the device was lost while mirroring,
the window closed immediately, suggesting scrcpy had crashed.
To make it clear that a disconnection occurred, display a disconnected
icon for 2 seconds before closing the window.
PR #6662 <https://github.com/Genymobile/scrcpy/pull/6662>
Replace scrcpy_icon_load(), which loaded the unique scrcpy app icon,
with sc_icon_load(filename), which can load any icon from the icons
directory.
PR #6662 <https://github.com/Genymobile/scrcpy/pull/6662>
Use a flag to indicate whether the window is currently shown.
This replaces the old has_video_window flag, which was true only when
the window was shown and video was enabled.
This will simplify performing actions only when the window is currently
shown.
PR #6694 <https://github.com/Genymobile/scrcpy/pull/6694>
In SDL3, texture rendering uses SDL_FRect, unlike SDL2 which used
SDL_Rect.
Compute content location using floating-point coordinates from the
start.
PR #6651 <https://github.com/Genymobile/scrcpy/pull/6651>
Replace SDL "logical rendering" with explicit computation of icon
location, and unify rendering of video frames and icons using the same
common code.
PR #6651 <https://github.com/Genymobile/scrcpy/pull/6651>
Three components are involved in displaying device content on screen:
- a window
- a renderer
- a texture
Originally, all three were handled by sc_screen.
Commit 051b74c883 later extracted the
renderer and texture into a separate component, sc_display.
However, the split was a bit awkward because the window size and
rendering location were managed by separate components.
Move rendering back to sc_screen, keeping only texture management
separated.
PR #6651 <https://github.com/Genymobile/scrcpy/pull/6651>
Make sc_screen the owner of both the SDL window and the SDL renderer.
This is the first step toward limiting the role of sc_display to texture
management.
PR #6651 <https://github.com/Genymobile/scrcpy/pull/6651>
When the scrcpy window is minimized on Windows with D3D9, texture
creation and updates fail.
As a workaround, a mechanism was implemented to reattempt applying the
requested changes.
Since SDL3 defaults to the D3D11 backend, remove this workaround,
which adds a lot of complexity for a backend that should almost never
be used.
However, do not close scrcpy when texture creation or updates fail; only
that specific rendering should fail.
Refs SDL/#7651 <https://github.com/libsdl-org/SDL/issues/7651>
Refs #3947 <https://github.com/Genymobile/scrcpy/issues/3947>
Refs 6298ef095f
PR #6651 <https://github.com/Genymobile/scrcpy/pull/6651>
Introduce a new packet type, a "session" packet, containing metadata
about the encoding session. It is used only for the video stream and
currently includes the video resolution.
For illustration, here is a sequence of packets on the video stream:
device rotation
v
CODEC | SESSION | MEDIA | MEDIA | … | SESSION | MEDIA | MEDIA | …
1920x1080 <-----------------> 1080x1920 <------------------
encoding session 1 encoding session 2
This metadata is not strictly necessary, since the video resolution can
be determined after decoding. However, it allows detection of cases
where the encoder does not respect the requested size (and logs a
warning), even without decoding (e.g., when there is no video playback).
Additional metadata could be added later if necessary, for example the
actual device rotation.
Refs #5918 <https://github.com/Genymobile/scrcpy/pull/5918>
Refs #5894 <https://github.com/Genymobile/scrcpy/pull/5894>
PR #6159 <https://github.com/Genymobile/scrcpy/pull/6159>
Co-authored-by: gz0119 <liyong2@4399.com>
The texture was created as soon as the initial video size was known,
even before the first frame arrived.
However, texture creation will require other data, such as the color
range, which is only available once the first frame is received.
Therefore, delay texture creation until the first frame.
PR #6216 <https://github.com/Genymobile/scrcpy/pull/6216>
Introduce a gamepad processor trait, similar to the keyboard processor
and mouse processor traits.
Handle gamepad events received from SDL, convert them to scrcpy-specific
gamepad events, and forward them to the gamepad processor.
Further commits will provide AOA and UHID implementations of the gamepad
processor trait.
PR #5270 <https://github.com/Genymobile/scrcpy/pull/5270>
Co-authored-by: Luiz Henrique Laurini <luizhenriquelaurini@gmail.com>
A video width or height of 0 triggered an assert.
Fail explicitly instead: the server may actually send this size in
practice (for example on cropping with small dimensions, even if the
requested crop size is not 0).
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>
On sway (a window manager), SDL_WINDOWEVENT_EXPOSED and
SDL_WINDOWEVENT_SIZE_CHANGED might not be called before a mouse event is
triggered. As a consequence, the "content rectangle" might not be
initialized when the mouse event is processed, causing a division by
zero.
To avoid the problem, initialize the content rect immediately when the
window is shown.
Fixes#4115 <https://github.com/Genymobile/scrcpy/issues/4115>
On some window managers (e.g. on Windows), performing a resize while the
window is minimized does nothing (the restored window keeps its old
size).
Therefore, like for maximized and fullscreen states, wait for the window
to be restored to apply a resize.
Refs #3947 <https://github.com/Genymobile/scrcpy/issues/3947>