martin f. krafft
b3f5dfe1de
Add specific exit code for device disconnection
...
Modify the return logic such that exit code 1 is used when the initial
connection fails, but if a session is established, and then the device
disconnects, exit code 2 is emitted.
Fixes #3083 <https://github.com/Genymobile/scrcpy/issues/3083 >
PR #3085 <https://github.com/Genymobile/scrcpy/pull/3085 >
Signed-off-by: martin f. krafft <madduck@madduck.net>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2022-03-06 22:19:46 +01:00
Romain Vimont
8d91cda4f6
Improve HID event push error message
...
On HID event push failure, add the event type in the error message.
2022-02-24 23:28:20 +01:00
Romain Vimont
59656fe649
Fix typo in error message
2022-02-24 23:26:12 +01:00
Romain Vimont
e4bb2b8728
Add libusb error log
...
Log libusb_get_string_descriptor_ascii() errors.
Refs #3050 <https://github.com/Genymobile/scrcpy/issues/3050 >
2022-02-24 23:25:02 +01:00
Romain Vimont
1790e88278
Use vector for listing USB devices
...
This avoids the hardcoded maximum number of USB devices detected (16).
Refs #3029 <https://github.com/Genymobile/scrcpy/pull/3029 >
PR #3035 <https://github.com/Genymobile/scrcpy/pull/3035 >
2022-02-20 23:59:35 +01:00
Romain Vimont
25296ae167
Kill adb daemon in OTG mode on Windows
...
On Windows, it is not possible to open a USB device from several
process, so HID events may only work if no adb daemon is running.
PR #3011 <https://github.com/Genymobile/scrcpy/pull/3011 >
2022-02-20 17:39:39 +01:00
Romain Vimont
ff3cb31cb4
Fix libusb callback for Windows
...
Add LIBUSB_CALL so that the callback has the correct signature on
Windows (including __attribute__((stdcall))).
PR #3011 <https://github.com/Genymobile/scrcpy/pull/3011 >
2022-02-20 17:39:09 +01:00
Romain Vimont
06243e7c3c
Avoid PRIx16 printf format on Windows
...
Convert uint16_t to unsigned to avoid using PRIx16, which may not exist
on Windows.
PR #3011 <https://github.com/Genymobile/scrcpy/pull/3011 >
2022-02-20 17:39:04 +01:00
Romain Vimont
b9b2879789
Remove USB hotplug callback error log
...
If it fails, the error is already logged by sc_usb_register_callback().
PR #3011 <https://github.com/Genymobile/scrcpy/pull/3011 >
2022-02-20 17:38:51 +01:00
Romain Vimont
be1936bb85
Report USB device disconnection when detected
...
USB device disconnection is detected via a hotplug callback when it is
supported.
In addition, report disconnection on libusb calls returning
LIBUSB_ERROR_NO_DEVICE or LIBUSB_ERROR_NOT_FOUND. This allows to detect
disconnection after a libusb call when hotplug is not available.
PR #3011 <https://github.com/Genymobile/scrcpy/pull/3011 >
2022-02-20 17:38:14 +01:00
Romain Vimont
3ee3f8dc02
Work around mouse capture SDL bug on macOS
...
On macOS, SDL relative mouse mode does not work correctly when the
cursor is outside the window.
As a workaround, move the cursor inside the window before setting the
relative mouse mode.
Refs SDL/#5340 <https://github.com/libsdl-org/SDL/issues/5340 >
PR #3031 <https://github.com/Genymobile/scrcpy/pull/3031 >
2022-02-20 17:28:02 +01:00
Romain Vimont
9db42341e4
Pass screen instance to mouse capture functions
...
Using the screen instance or not in these functions is an implementation
detail. Further changes will require the screen instance.
Refs 7848a387c8
PR #3031 <https://github.com/Genymobile/scrcpy/pull/3031 >
2022-02-20 17:27:53 +01:00
Romain Vimont
4a95c08d56
Improve error message for unsupported usb hotplug
2022-02-10 08:54:43 +01:00
Romain Vimont
7848a387c8
Do not duplicate relative mouse mode state
...
The relative mouse mode is tracked by SDL, and accessible via
SDL_GetRelativeMouseMode().
This is more robust in case SDL changes the relative mouse mode on its
own.
2022-02-10 08:50:18 +01:00
Romain Vimont
43ae418752
Fix USB device leak on connection error
...
If sc_usb_connect() failed, then the sc_usb_device was never destroyed.
The assignment was mistakenly removed by commit
61969aeb80
.
2022-02-10 08:47:39 +01:00
Romain Vimont
29828aa330
Log device opening errors during listing
...
Without this log, the user would have no way to know that a USB device
is rejected because it could not be opened (typically due to
insufficient permissions).
2022-02-09 10:04:09 +01:00
Romain Vimont
4692d13179
Expose simple API to select a single adb device
...
Select an adb device from the output of `adb device -l`.
PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005 >
2022-02-09 09:56:26 +01:00
Romain Vimont
700503df6c
List and select USB devices separately
...
List all USB devices in a first step, then select the matching one(s).
This allows to report a user-friendly log message containing the list of
devices, with the matching one(s) highlighted.
PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005 >
2022-02-09 09:55:25 +01:00
Romain Vimont
61969aeb80
Expose simple API to select a single USB device
...
The caller just wants a single device. Handle all cases and error
messages internally.
PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005 >
2022-02-09 09:55:25 +01:00
Romain Vimont
b88c4aa75e
Add move-function for sc_usb_device
...
Add a function to "move" a sc_usb_device into another instance.
This will avoid unnecessary copies.
PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005 >
2022-02-09 09:55:23 +01:00
Romain Vimont
0eadf95a3e
Rename function to destroy a list of USB devices
...
Rename from "usb_device_" to "usb_devices_".
PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005 >
2022-02-09 09:53:19 +01:00
Romain Vimont
61b6324ee9
Remove LOGC()
...
It is not clear when to use LOGC() rather than LOGE(). Always use
LOGE().
Moreover, enum sc_log_level has no "critical" log level.
2022-02-09 09:52:15 +01:00
Romain Vimont
f20137d2ac
Improve USB device open log
...
For consistency with "List USB devices", log "Open USB device".
2022-02-07 13:10:53 +01:00
Romain Vimont
b60809a4da
Inline USB device opening
...
Such a separate function was useless.
2022-02-07 13:03:23 +01:00
Romain Vimont
b0e04aa327
Remove log_libusb_error()
...
This helper did not help a lot, and prevented the client to choose the
log level and the prefix error message.
2022-02-07 12:56:25 +01:00
Romain Vimont
5508c635cb
Enable mouse focus clickthrough in OTG mode
...
A single click on the window must both give focus and capture the mouse.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:30 +01:00
Romain Vimont
ea68a003a2
Make HID keyboard and mouse optional in OTG mode
...
Allow to only enable HID keyboard or HID mouse:
scrcpy --otg -K # keyboard only
scrcpy --otg -M # mouse only
scrcpy --otg -KM # keyboard and mouse
scrcpy --otg # keyboard and mouse
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:27 +01:00
Romain Vimont
91418c79ab
Add OTG mode
...
Add an option --otg to run scrcpy with only physical keyboard and mouse
simulation (HID over AOA), without mirroring and without requiring adb.
To avoid adding complexity into the scrcpy initialization and screen
implementation, OTG mode is implemented totally separately, with a
separate window.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:23 +01:00
Romain Vimont
1a03206e36
Detect USB device disconnection
...
The device disconnection is detected when the video socket closes.
In order to introduce an OTG mode (HID events) without mirroring (and
without server), we must be able to detect USB device disconnection.
This feature will only be used in OTG mode.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:18 +01:00
Romain Vimont
37987b822e
Make acksync optional for AOA initialization
...
Acksync is used to delay HID events until some request (in practice,
device clipboard synchronization) is acknowledged by the device.
This mechanism will not be necessary for OTG mode.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:16 +01:00
Romain Vimont
8fc9dca8cb
Make serial optional to find USB devices
...
If no serial is provided, then list all available USB devices (which can
be open and having a serial).
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:15 +01:00
Romain Vimont
1c17f57c10
Find a list of devices instead of a single one
...
Several devices may match the requested serial, but above all, this
paves the way to list all devices (when no serial is provided).
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:13 +01:00
Romain Vimont
d8b37fe189
Wrap libusb_device
...
Introduce a structure to wrap a libusb_device and expose its descriptor
data read during discovery.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:11 +01:00
Romain Vimont
0ee9e2ff51
Expose function to find a USB device
...
The device was automatically found by sc_usb_connect(). Instead, expose
a function to find a device from a serial, and let the caller connect to
the device found (if any).
This will allow to list all devices first, then select one device to
connect to.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:08 +01:00
Romain Vimont
1ab3692f3d
Add util function to read USB descriptor string
...
Use it from accept_device() to simplify (at the cost an additional
allocation for each serial, but it is not important).
It will also be useful in other functions in further commits.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:06 +01:00
Romain Vimont
bbef426a4b
Split USB initialization and connection
...
This will allow to execute other USB calls (retrieving the device list
for example) before connecting to the selected device.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:04 +01:00
Romain Vimont
2114f48185
Find device with USB context
...
An explicit context was used everywhere except for listing the devices.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:02 +01:00
Romain Vimont
b779eca8d3
Remove libusb_device field
...
It is possible to retrieve the device instance from the handle via
libusb_get_device(), so we don't need to reference the device one more
time.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:00 +01:00
Romain Vimont
adda47b0f7
Move sc_usb out of sc_aoa
...
This will allow to initialize a USB device separately and pass it to
sc_aoa.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:35:59 +01:00
Romain Vimont
48e3ff284f
Make serial mandatory for sc_usb
...
In practice, it is already mandatory.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:35:57 +01:00
Romain Vimont
1d6f9952ee
Extract USB handling from AOA
...
The AOA code handled both USB initialization and AOA commands/events.
Extract USB-related code to a separate file and structure.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:35:55 +01:00
Romain Vimont
2762f5d183
Move AOA/HID code to usb/
...
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:35:34 +01:00