Skip to content

Display and control your Android device

Define default options as const struct

Romain Vimont27fa23846d5e
diff --git a/app/meson.build b/app/meson.build
index f82d37b3..2ced151b 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -16,6 +16,7 @@ src = [
'src/keyboard_inject.c',
'src/mouse_inject.c',
'src/opengl.c',
+ 'src/options.c',
'src/receiver.c',
'src/recorder.c',
'src/scrcpy.c',
@@ -184,6 +185,7 @@ if get_option('buildtype') == 'debug'
['test_cli', [
'tests/test_cli.c',
'src/cli.c',
+ 'src/options.c',
'src/util/str_util.c',
]],
['test_clock', [
diff --git a/app/src/main.c b/app/src/main.c
index 51c13fd5..831b98fa 100644
--- a/app/src/main.c
+++ b/app/src/main.c
@@ -48,7 +48,7 @@ main(int argc, char *argv[]) {
#endif
struct scrcpy_cli_args args = {
- .opts = SCRCPY_OPTIONS_DEFAULT,
+ .opts = scrcpy_options_default,
.help = false,
.version = false,
};
diff --git a/app/src/options.c b/app/src/options.c
new file mode 100644
index 00000000..a1722158
--- /dev/null
+++ b/app/src/options.c
@@ -0,0 +1,52 @@
+#include "options.h"
+
+const struct scrcpy_options scrcpy_options_default = {
+ .serial = NULL,
+ .crop = NULL,
+ .record_filename = NULL,
+ .window_title = NULL,
+ .push_target = NULL,
+ .render_driver = NULL,
+ .codec_options = NULL,
+ .encoder_name = NULL,
+ .v4l2_device = NULL,
+ .log_level = SC_LOG_LEVEL_INFO,
+ .record_format = SC_RECORD_FORMAT_AUTO,
+ .keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_INJECT,
+ .port_range = {
+ .first = DEFAULT_LOCAL_PORT_RANGE_FIRST,
+ .last = DEFAULT_LOCAL_PORT_RANGE_LAST,
+ },
+ .shortcut_mods = {
+ .data = {SC_MOD_LALT, SC_MOD_LSUPER},
+ .count = 2,
+ },
+ .max_size = 0,
+ .bit_rate = DEFAULT_BIT_RATE,
+ .max_fps = 0,
+ .lock_video_orientation = SC_LOCK_VIDEO_ORIENTATION_UNLOCKED,
+ .rotation = 0,
+ .window_x = SC_WINDOW_POSITION_UNDEFINED,
+ .window_y = SC_WINDOW_POSITION_UNDEFINED,
+ .window_width = 0,
+ .window_height = 0,
+ .display_id = 0,
+ .display_buffer = 0,
+ .v4l2_buffer = 0,
+ .show_touches = false,
+ .fullscreen = false,
+ .always_on_top = false,
+ .control = true,
+ .display = true,
+ .turn_screen_off = false,
+ .prefer_text = false,
+ .window_borderless = false,
+ .mipmaps = true,
+ .stay_awake = false,
+ .force_adb_forward = false,
+ .disable_screensaver = false,
+ .forward_key_repeat = true,
+ .forward_all_clicks = false,
+ .legacy_paste = false,
+ .power_off_on_close = false,
+};
diff --git a/app/src/options.h b/app/src/options.h
index 04b8f6d2..23583f37 100644
--- a/app/src/options.h
+++ b/app/src/options.h
@@ -106,55 +106,6 @@ struct scrcpy_options {
bool power_off_on_close;
};
-#define SCRCPY_OPTIONS_DEFAULT { \
- .serial = NULL, \
- .crop = NULL, \
- .record_filename = NULL, \
- .window_title = NULL, \
- .push_target = NULL, \
- .render_driver = NULL, \
- .codec_options = NULL, \
- .encoder_name = NULL, \
- .v4l2_device = NULL, \
- .log_level = SC_LOG_LEVEL_INFO, \
- .record_format = SC_RECORD_FORMAT_AUTO, \
- .keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_INJECT, \
- .port_range = { \
- .first = DEFAULT_LOCAL_PORT_RANGE_FIRST, \
- .last = DEFAULT_LOCAL_PORT_RANGE_LAST, \
- }, \
- .shortcut_mods = { \
- .data = {SC_MOD_LALT, SC_MOD_LSUPER}, \
- .count = 2, \
- }, \
- .max_size = 0, \
- .bit_rate = DEFAULT_BIT_RATE, \
- .max_fps = 0, \
- .lock_video_orientation = SC_LOCK_VIDEO_ORIENTATION_UNLOCKED, \
- .rotation = 0, \
- .window_x = SC_WINDOW_POSITION_UNDEFINED, \
- .window_y = SC_WINDOW_POSITION_UNDEFINED, \
- .window_width = 0, \
- .window_height = 0, \
- .display_id = 0, \
- .display_buffer = 0, \
- .v4l2_buffer = 0, \
- .show_touches = false, \
- .fullscreen = false, \
- .always_on_top = false, \
- .control = true, \
- .display = true, \
- .turn_screen_off = false, \
- .prefer_text = false, \
- .window_borderless = false, \
- .mipmaps = true, \
- .stay_awake = false, \
- .force_adb_forward = false, \
- .disable_screensaver = false, \
- .forward_key_repeat = true, \
- .forward_all_clicks = false, \
- .legacy_paste = false, \
- .power_off_on_close = false, \
-}
+extern const struct scrcpy_options scrcpy_options_default;
#endif
diff --git a/app/tests/test_cli.c b/app/tests/test_cli.c
index 1682a72d..05bacbf8 100644
--- a/app/tests/test_cli.c
+++ b/app/tests/test_cli.c
@@ -8,7 +8,7 @@
static void test_flag_version(void) {
struct scrcpy_cli_args args = {
- .opts = SCRCPY_OPTIONS_DEFAULT,
+ .opts = scrcpy_options_default,
.help = false,
.version = false,
};
@@ -23,7 +23,7 @@ static void test_flag_version(void) {
static void test_flag_help(void) {
struct scrcpy_cli_args args = {
- .opts = SCRCPY_OPTIONS_DEFAULT,
+ .opts = scrcpy_options_default,
.help = false,
.version = false,
};
@@ -38,7 +38,7 @@ static void test_flag_help(void) {
static void test_options(void) {
struct scrcpy_cli_args args = {
- .opts = SCRCPY_OPTIONS_DEFAULT,
+ .opts = scrcpy_options_default,
.help = false,
.version = false,
};
@@ -100,7 +100,7 @@ static void test_options(void) {
static void test_options2(void) {
struct scrcpy_cli_args args = {
- .opts = SCRCPY_OPTIONS_DEFAULT,
+ .opts = scrcpy_options_default,
.help = false,
.version = false,
};