Skip to content

Display and control your Android device

Do not init SDL video subsystem if no display

Romain Vimont6baed8a06fc0
diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c
index 26bde219..c2428c61 100644
--- a/app/src/scrcpy.c
+++ b/app/src/scrcpy.c
@@ -42,6 +42,40 @@ static struct input_manager input_manager = {
.control = true,
};
+// init SDL and set appropriate hints
+static bool
+sdl_init_and_configure(bool display) {
+ uint32_t flags = display ? SDL_INIT_VIDEO : SDL_INIT_EVENTS;
+ if (SDL_Init(flags)) {
+ LOGC("Could not initialize SDL: %s", SDL_GetError());
+ return false;
+ }
+
+ atexit(SDL_Quit);
+
+ if (!display) {
+ return true;
+ }
+
+ // Use the best available scale quality
+ if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2")) {
+ LOGW("Could not enable bilinear filtering");
+ }
+
+#ifdef SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH
+ // Handle a click to gain focus as any other click
+ if (!SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1")) {
+ LOGW("Could not enable mouse focus clickthrough");
+ }
+#endif
+
+ // Do not disable the screensaver when scrcpy is running
+ SDL_EnableScreenSaver();
+
+ return true;
+}
+
+
#if defined(__APPLE__) || defined(__WINDOWS__)
# define CONTINUOUS_RESIZING_WORKAROUND
#endif
@@ -240,7 +274,10 @@ scrcpy(const struct scrcpy_options *options) {
bool ret = true;
- if (!sdl_init_and_configure()) {
+ bool display = !options->no_display;
+ bool control = !options->no_control;
+
+ if (!sdl_init_and_configure(display)) {
ret = false;
goto finally_destroy_server;
}
@@ -264,9 +301,6 @@ scrcpy(const struct scrcpy_options *options) {
goto finally_destroy_server;
}
- bool display = !options->no_display;
- bool control = !options->no_control;
-
input_manager.control = control;
struct decoder *dec = NULL;
diff --git a/app/src/screen.c b/app/src/screen.c
index 962d5b70..f6e917a9 100644
--- a/app/src/screen.c
+++ b/app/src/screen.c
@@ -13,33 +13,6 @@
#define DISPLAY_MARGINS 96
-bool
-sdl_init_and_configure(void) {
- if (SDL_Init(SDL_INIT_VIDEO)) {
- LOGC("Could not initialize SDL: %s", SDL_GetError());
- return false;
- }
-
- atexit(SDL_Quit);
-
- // Use the best available scale quality
- if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2")) {
- LOGW("Could not enable bilinear filtering");
- }
-
-#ifdef SCRCPY_SDL_HAS_HINT_MOUSE_FOCUS_CLICKTHROUGH
- // Handle a click to gain focus as any other click
- if (!SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1")) {
- LOGW("Could not enable mouse focus clickthrough");
- }
-#endif
-
- // Do not disable the screensaver when scrcpy is running
- SDL_EnableScreenSaver();
-
- return true;
-}
-
// get the window size in a struct size
static struct size
get_native_window_size(SDL_Window *window) {
diff --git a/app/src/screen.h b/app/src/screen.h
index b3e3ecaa..5734fdc2 100644
--- a/app/src/screen.h
+++ b/app/src/screen.h
@@ -38,10 +38,6 @@ struct screen {
.no_window = false, \
}
-// init SDL and set appropriate hints
-bool
-sdl_init_and_configure(void);
-
// initialize default values
void
screen_init(struct screen *screen);