Compare commits

..

1 Commits

Author SHA1 Message Date
e1e0
ef24690eee Fix reference to FAQ in README
PR #3065 <https://github.com/Genymobile/scrcpy/pull/3065>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2022-03-06 22:44:26 +01:00
10 changed files with 35 additions and 63 deletions

View File

@@ -1105,7 +1105,7 @@ See [BUILD].
## Common issues ## Common issues
See the [FAQ].md). See the [FAQ].
[FAQ]: FAQ.md [FAQ]: FAQ.md

View File

@@ -355,12 +355,6 @@ Set the initial window height.
Default is 0 (automatic). Default is 0 (automatic).
.SH EXIT STATUS
.B scrcpy
will exit with code 0 on normal program termination. If an initial
connection cannot be established, the exit code 1 will be returned. If the
device disconnects while a session is active, exit code 2 will be returned.
.SH SHORTCUTS .SH SHORTCUTS
In the following list, MOD is the shortcut modifier. By default, it's (left) In the following list, MOD is the shortcut modifier. By default, it's (left)

View File

@@ -40,19 +40,19 @@ main(int argc, char *argv[]) {
#endif #endif
if (!scrcpy_parse_args(&args, argc, argv)) { if (!scrcpy_parse_args(&args, argc, argv)) {
return SCRCPY_EXIT_FAILURE; return 1;
} }
sc_set_log_level(args.opts.log_level); sc_set_log_level(args.opts.log_level);
if (args.help) { if (args.help) {
scrcpy_print_usage(argv[0]); scrcpy_print_usage(argv[0]);
return SCRCPY_EXIT_SUCCESS; return 0;
} }
if (args.version) { if (args.version) {
scrcpy_print_version(); scrcpy_print_version();
return SCRCPY_EXIT_SUCCESS; return 0;
} }
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL #ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
@@ -66,17 +66,17 @@ main(int argc, char *argv[]) {
#endif #endif
if (avformat_network_init()) { if (avformat_network_init()) {
return SCRCPY_EXIT_FAILURE; return 1;
} }
#ifdef HAVE_USB #ifdef HAVE_USB
enum scrcpy_exit_code ret = args.opts.otg ? scrcpy_otg(&args.opts) bool ok = args.opts.otg ? scrcpy_otg(&args.opts)
: scrcpy(&args.opts); : scrcpy(&args.opts);
#else #else
enum scrcpy_exit_code ret = scrcpy(&args.opts); bool ok = scrcpy(&args.opts);
#endif #endif
avformat_network_deinit(); // ignore failure avformat_network_deinit(); // ignore failure
return ret; return ok ? 0 : 1;
} }

View File

@@ -149,41 +149,38 @@ sdl_configure(bool display, bool disable_screensaver) {
} }
} }
static enum scrcpy_exit_code static bool
event_loop(struct scrcpy *s) { event_loop(struct scrcpy *s) {
SDL_Event event; SDL_Event event;
while (SDL_WaitEvent(&event)) { while (SDL_WaitEvent(&event)) {
switch (event.type) { switch (event.type) {
case EVENT_STREAM_STOPPED: case EVENT_STREAM_STOPPED:
LOGW("Device disconnected"); LOGW("Device disconnected");
return SCRCPY_EXIT_DISCONNECTED; return false;
case SDL_QUIT: case SDL_QUIT:
LOGD("User requested to quit"); LOGD("User requested to quit");
return SCRCPY_EXIT_SUCCESS; return true;
default: default:
sc_screen_handle_event(&s->screen, &event); sc_screen_handle_event(&s->screen, &event);
break; break;
} }
} }
return SCRCPY_EXIT_FAILURE; return false;
} }
// Return true on success, false on error
static bool static bool
await_for_server(bool *connected) { await_for_server(void) {
SDL_Event event; SDL_Event event;
while (SDL_WaitEvent(&event)) { while (SDL_WaitEvent(&event)) {
switch (event.type) { switch (event.type) {
case SDL_QUIT: case SDL_QUIT:
LOGD("User requested to quit"); LOGD("User requested to quit");
*connected = false; return false;
return true;
case EVENT_SERVER_CONNECTION_FAILED: case EVENT_SERVER_CONNECTION_FAILED:
LOGE("Server connection failed"); LOGE("Server connection failed");
return false; return false;
case EVENT_SERVER_CONNECTED: case EVENT_SERVER_CONNECTED:
LOGD("Server connected"); LOGD("Server connected");
*connected = true;
return true; return true;
default: default:
break; break;
@@ -265,7 +262,7 @@ sc_server_on_disconnected(struct sc_server *server, void *userdata) {
// event // event
} }
enum scrcpy_exit_code bool
scrcpy(struct scrcpy_options *options) { scrcpy(struct scrcpy_options *options) {
static struct scrcpy scrcpy; static struct scrcpy scrcpy;
struct scrcpy *s = &scrcpy; struct scrcpy *s = &scrcpy;
@@ -273,12 +270,12 @@ scrcpy(struct scrcpy_options *options) {
// Minimal SDL initialization // Minimal SDL initialization
if (SDL_Init(SDL_INIT_EVENTS)) { if (SDL_Init(SDL_INIT_EVENTS)) {
LOGE("Could not initialize SDL: %s", SDL_GetError()); LOGE("Could not initialize SDL: %s", SDL_GetError());
return SCRCPY_EXIT_FAILURE; return false;
} }
atexit(SDL_Quit); atexit(SDL_Quit);
enum scrcpy_exit_code ret = SCRCPY_EXIT_FAILURE; bool ret = false;
bool server_started = false; bool server_started = false;
bool file_pusher_initialized = false; bool file_pusher_initialized = false;
@@ -332,7 +329,7 @@ scrcpy(struct scrcpy_options *options) {
.on_disconnected = sc_server_on_disconnected, .on_disconnected = sc_server_on_disconnected,
}; };
if (!sc_server_init(&s->server, &params, &cbs, NULL)) { if (!sc_server_init(&s->server, &params, &cbs, NULL)) {
return SCRCPY_EXIT_FAILURE; return false;
} }
if (!sc_server_start(&s->server)) { if (!sc_server_start(&s->server)) {
@@ -354,14 +351,7 @@ scrcpy(struct scrcpy_options *options) {
sdl_configure(options->display, options->disable_screensaver); sdl_configure(options->display, options->disable_screensaver);
// Await for server without blocking Ctrl+C handling // Await for server without blocking Ctrl+C handling
bool connected; if (!await_for_server()) {
if (!await_for_server(&connected)) {
goto end;
}
if (!connected) {
// This is not an error, user requested to quit
ret = SCRCPY_EXIT_SUCCESS;
goto end; goto end;
} }

View File

@@ -6,18 +6,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "options.h" #include "options.h"
enum scrcpy_exit_code { bool
// Normal program termination
SCRCPY_EXIT_SUCCESS,
// No connection could be established
SCRCPY_EXIT_FAILURE,
// Device was disconnected while running
SCRCPY_EXIT_DISCONNECTED,
};
enum scrcpy_exit_code
scrcpy(struct scrcpy_options *options); scrcpy(struct scrcpy_options *options);
#endif #endif

View File

@@ -340,7 +340,7 @@ push_mod_lock_state(struct sc_hid_keyboard *kb, uint16_t mods_state) {
if (!sc_aoa_push_hid_event(kb->aoa, &hid_event)) { if (!sc_aoa_push_hid_event(kb->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event); sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (mod lock state)"); LOGW("Could request HID event");
return false; return false;
} }
@@ -382,7 +382,7 @@ sc_key_processor_process_key(struct sc_key_processor *kp,
if (!sc_aoa_push_hid_event(kb->aoa, &hid_event)) { if (!sc_aoa_push_hid_event(kb->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event); sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (key)"); LOGW("Could request HID event");
} }
} }
} }

View File

@@ -181,7 +181,7 @@ sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) { if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event); sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (mouse motion)"); LOGW("Could request HID event");
} }
} }
@@ -203,7 +203,7 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) { if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event); sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (mouse click)"); LOGW("Could request HID event");
} }
} }
@@ -228,7 +228,7 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) { if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event); sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (mouse scroll)"); LOGW("Could request HID event");
} }
} }

View File

@@ -29,26 +29,26 @@ sc_usb_on_disconnected(struct sc_usb *usb, void *userdata) {
} }
} }
static enum scrcpy_exit_code static bool
event_loop(struct scrcpy_otg *s) { event_loop(struct scrcpy_otg *s) {
SDL_Event event; SDL_Event event;
while (SDL_WaitEvent(&event)) { while (SDL_WaitEvent(&event)) {
switch (event.type) { switch (event.type) {
case EVENT_USB_DEVICE_DISCONNECTED: case EVENT_USB_DEVICE_DISCONNECTED:
LOGW("Device disconnected"); LOGW("Device disconnected");
return SCRCPY_EXIT_DISCONNECTED; return false;
case SDL_QUIT: case SDL_QUIT:
LOGD("User requested to quit"); LOGD("User requested to quit");
return SCRCPY_EXIT_SUCCESS; return true;
default: default:
sc_screen_otg_handle_event(&s->screen_otg, &event); sc_screen_otg_handle_event(&s->screen_otg, &event);
break; break;
} }
} }
return SCRCPY_EXIT_FAILURE; return false;
} }
enum scrcpy_exit_code bool
scrcpy_otg(struct scrcpy_options *options) { scrcpy_otg(struct scrcpy_options *options) {
static struct scrcpy_otg scrcpy_otg; static struct scrcpy_otg scrcpy_otg;
struct scrcpy_otg *s = &scrcpy_otg; struct scrcpy_otg *s = &scrcpy_otg;
@@ -67,7 +67,7 @@ scrcpy_otg(struct scrcpy_options *options) {
LOGW("Could not enable mouse focus clickthrough"); LOGW("Could not enable mouse focus clickthrough");
} }
enum scrcpy_exit_code ret = SCRCPY_EXIT_FAILURE; bool ret = false;
struct sc_hid_keyboard *keyboard = NULL; struct sc_hid_keyboard *keyboard = NULL;
struct sc_hid_mouse *mouse = NULL; struct sc_hid_mouse *mouse = NULL;
@@ -90,7 +90,7 @@ scrcpy_otg(struct scrcpy_options *options) {
}; };
bool ok = sc_usb_init(&s->usb); bool ok = sc_usb_init(&s->usb);
if (!ok) { if (!ok) {
return SCRCPY_EXIT_FAILURE; return false;
} }
struct sc_usb_device usb_device; struct sc_usb_device usb_device;

View File

@@ -3,10 +3,10 @@
#include "common.h" #include "common.h"
#include <stdbool.h>
#include "options.h" #include "options.h"
#include "scrcpy.h"
enum scrcpy_exit_code bool
scrcpy_otg(struct scrcpy_options *options); scrcpy_otg(struct scrcpy_options *options);
#endif #endif

View File

@@ -15,7 +15,6 @@ read_string(libusb_device_handle *handle, uint8_t desc_index) {
(unsigned char *) buffer, (unsigned char *) buffer,
sizeof(buffer)); sizeof(buffer));
if (result < 0) { if (result < 0) {
LOGD("Read string: libusb error: %s", libusb_strerror(result));
return NULL; return NULL;
} }