Add setting to automatically connect to CC

This commit is contained in:
Lorenzooone 2026-01-24 16:45:59 +01:00
parent a83ba0f79f
commit cb820ac204
6 changed files with 75 additions and 16 deletions

View File

@ -16,13 +16,14 @@ enum ExtraSettingsMenuOutAction{
EXTRA_SETTINGS_MENU_SPLIT,
EXTRA_SETTINGS_MENU_USB_CONFLICT_RESOLUTION,
EXTRA_SETTINGS_MENU_RESET_SETTINGS,
EXTRA_SETTINGS_MENU_CHANGE_PERIODIC_CONNECTION_TRY,
};
class ExtraSettingsMenu : public OptionSelectionMenu {
public:
ExtraSettingsMenu(TextRectanglePool* text_pool);
~ExtraSettingsMenu();
void prepare(float scaling_factor, int view_size_x, int view_size_y);
void prepare(float scaling_factor, int view_size_x, int view_size_y, bool periodic_connection_try);
static int get_total_possible_selectable_inserted(ScreenType s_type, bool is_fullscreen, bool is_mono_app);
void insert_data(ScreenType s_type, bool is_fullscreen, bool is_mono_app);
ExtraSettingsMenuOutAction selected_index = ExtraSettingsMenuOutAction::EXTRA_SETTINGS_MENU_NO_ACTION;

View File

@ -109,6 +109,7 @@ struct InputData {
struct SharedData {
InputData input_data;
volatile bool periodic_connection_try = false;
};
#pragma pack(push, 1)

View File

@ -5,6 +5,7 @@
struct ExtraSettingsMenuOptionInfo {
const std::string base_name;
const std::string false_name;
const bool is_selectable;
const bool active_fullscreen;
const bool active_windowed_screen;
@ -17,63 +18,71 @@ struct ExtraSettingsMenuOptionInfo {
};
static const ExtraSettingsMenuOptionInfo warning_option = {
.base_name = "Advanced users only!", .is_selectable = false,
.base_name = "Advanced users only!", .false_name = "", .is_selectable = false,
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.active_regular = true, .active_mono_app = true,
.out_action = EXTRA_SETTINGS_MENU_NO_ACTION};
static const ExtraSettingsMenuOptionInfo reset_to_default_option = {
.base_name = "Reset Settings", .is_selectable = true,
.base_name = "Reset Settings", .false_name = "", .is_selectable = true,
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.active_regular = true, .active_mono_app = true,
.out_action = EXTRA_SETTINGS_MENU_RESET_SETTINGS};
static const ExtraSettingsMenuOptionInfo windowed_option = {
.base_name = "Windowed Mode", .is_selectable = true,
.base_name = "Windowed Mode", .false_name = "", .is_selectable = true,
.active_fullscreen = true, .active_windowed_screen = false,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.active_regular = false, .active_mono_app = true,
.out_action = EXTRA_SETTINGS_MENU_FULLSCREEN};
static const ExtraSettingsMenuOptionInfo fullscreen_option = {
.base_name = "Fullscreen Mode", .is_selectable = true,
.base_name = "Fullscreen Mode", .false_name = "", .is_selectable = true,
.active_fullscreen = false, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.active_regular = false, .active_mono_app = true,
.out_action = EXTRA_SETTINGS_MENU_FULLSCREEN};
static const ExtraSettingsMenuOptionInfo join_screens_option = {
.base_name = "Join Screens", .is_selectable = true,
.base_name = "Join Screens", .false_name = "", .is_selectable = true,
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = false, .active_top_screen = true, .active_bottom_screen = true,
.active_regular = false, .active_mono_app = true,
.out_action = EXTRA_SETTINGS_MENU_SPLIT};
static const ExtraSettingsMenuOptionInfo split_screens_option = {
.base_name = "Split Screens", .is_selectable = true,
.base_name = "Split Screens", .false_name = "", .is_selectable = true,
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
.active_regular = false, .active_mono_app = true,
.out_action = EXTRA_SETTINGS_MENU_SPLIT};
static const ExtraSettingsMenuOptionInfo quit_option = {
.base_name = "Quit Application", .is_selectable = true,
.base_name = "Quit Application", .false_name = "", .is_selectable = true,
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.active_regular = false, .active_mono_app = true,
.out_action = EXTRA_SETTINGS_MENU_QUIT_APPLICATION};
static const ExtraSettingsMenuOptionInfo usb_conflict_resolution_menu_option = {
.base_name = "USB Conflict Resolution", .is_selectable = true,
.base_name = "USB Conflict Resolution", .false_name = "", .is_selectable = true,
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.active_regular = true, .active_mono_app = true,
.out_action = EXTRA_SETTINGS_MENU_USB_CONFLICT_RESOLUTION};
static const ExtraSettingsMenuOptionInfo periodic_connection_try_menu_option = {
.base_name = "Set Manual Connection", .false_name = "Set Automatic Connection", .is_selectable = true,
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.active_regular = true, .active_mono_app = true,
.out_action = EXTRA_SETTINGS_MENU_CHANGE_PERIODIC_CONNECTION_TRY};
static const ExtraSettingsMenuOptionInfo* pollable_options[] = {
&warning_option,
&periodic_connection_try_menu_option,
&reset_to_default_option,
&windowed_option,
&fullscreen_option,
@ -170,9 +179,30 @@ size_t ExtraSettingsMenu::get_num_options() {
}
std::string ExtraSettingsMenu::get_string_option(int index, int action) {
if(action == FALSE_ACTION)
return pollable_options[this->options_indexes[index]]->false_name;
return pollable_options[this->options_indexes[index]]->base_name;
}
void ExtraSettingsMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y) {
void ExtraSettingsMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, bool periodic_connection_try) {
int num_pages = this->get_num_pages();
if(this->future_data.page >= num_pages)
this->future_data.page = num_pages - 1;
int start = this->future_data.page * this->num_options_per_screen;
for(int i = 0; i < this->num_options_per_screen + 1; i++) {
int index = (i * this->single_option_multiplier) + this->elements_start_id;
if(!this->future_enabled_labels[index])
continue;
int real_index = start + i;
int option_index = this->options_indexes[real_index];
switch(pollable_options[option_index]->out_action) {
case EXTRA_SETTINGS_MENU_CHANGE_PERIODIC_CONNECTION_TRY:
this->labels[index]->setText(this->setTextOptionBool(real_index, periodic_connection_try));
break;
default:
break;
}
}
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
}

View File

@ -2055,6 +2055,9 @@ void WindowScreen::poll(bool do_everything) {
this->setup_usb_conflict_resolution_menu();
done = true;
break;
case EXTRA_SETTINGS_MENU_CHANGE_PERIODIC_CONNECTION_TRY:
this->shared_data->periodic_connection_try = !this->shared_data->periodic_connection_try;
break;
default:
break;
}
@ -2735,7 +2738,7 @@ void WindowScreen::prepare_menu_draws(int view_size_x, int view_size_y) {
this->fileconfig_menu->prepare(menu_scaling_factor, view_size_x, view_size_y);
break;
case EXTRA_MENU_TYPE:
this->extra_menu->prepare(menu_scaling_factor, view_size_x, view_size_y);
this->extra_menu->prepare(menu_scaling_factor, view_size_x, view_size_y, this->shared_data->periodic_connection_try);
break;
case SHORTCUTS_MENU_TYPE:
this->shortcut_menu->prepare(menu_scaling_factor, view_size_x, view_size_y);

View File

@ -30,6 +30,8 @@
#define ANDROID_FIRST_CONNECTION_TIMEOUT 0.5
#define PERIOD_CONNECTION_TRY_TIMEOUT 0.5
struct override_all_data {
override_win_data override_top_bot_data;
override_win_data override_top_data;
@ -114,6 +116,11 @@ static bool load_shared(const std::string path, const std::string name, SharedDa
shared_data->input_data.enable_buttons_input = std::stoi(value);
continue;
}
if(key == "periodic_connection_try") {
shared_data->periodic_connection_try = std::stoi(value);
continue;
}
}
}
}
@ -334,6 +341,7 @@ static bool save_shared(const std::string path, const std::string name, SharedDa
file << "enable_controller_input=" << shared_data->input_data.enable_controller_input << std::endl;
file << "enable_mouse_input=" << shared_data->input_data.enable_mouse_input << std::endl;
file << "enable_buttons_input=" << shared_data->input_data.enable_buttons_input << std::endl;
file << "periodic_connection_try=" << shared_data->periodic_connection_try << std::endl;
file.close();
return true;
@ -600,7 +608,7 @@ static void populate_force_disable_ccs(bool* force_cc_disables, override_all_dat
force_cc_disables[CC_OPTIMIZE_O3DS] = override_data.force_disable_optimize_old_3ds;
}
static void check_for_first_connection(bool &did_first_connection, std::chrono::time_point<std::chrono::high_resolution_clock> &start_time, CaptureData* capture_data, FrontendData *frontend_data, bool* force_cc_disables, override_all_data &override_data, OutTextData &out_text_data, int &ret_val) {
static void check_for_first_connection(bool &did_first_connection, std::chrono::time_point<std::chrono::high_resolution_clock> &start_time, CaptureData* capture_data, FrontendData *frontend_data, bool* force_cc_disables, override_all_data &override_data, OutTextData &out_text_data, int &ret_val, std::chrono::time_point<std::chrono::high_resolution_clock> &last_connection_time) {
if(did_first_connection)
return;
@ -618,6 +626,16 @@ static void check_for_first_connection(bool &did_first_connection, std::chrono::
}
SuccessConnectionOutTextGenerator(out_text_data, capture_data);
did_first_connection = true;
last_connection_time = std::chrono::high_resolution_clock::now();
}
static bool should_do_periodic_connection_try(SharedData* shared_data, bool connected, std::chrono::time_point<std::chrono::high_resolution_clock> &last_connection_time) {
if(connected || (!shared_data->periodic_connection_try))
return false;
auto curr_time = std::chrono::high_resolution_clock::now();
const std::chrono::duration<double> diff = curr_time - last_connection_time;
return diff.count() >= PERIOD_CONNECTION_TRY_TIMEOUT;
}
static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data, override_all_data &override_data, volatile bool* can_do_output) {
@ -636,6 +654,7 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data,
std::chrono::time_point<std::chrono::high_resolution_clock> start_time = std::chrono::high_resolution_clock::now();
std::chrono::time_point<std::chrono::high_resolution_clock> last_valid_frame_time = start_time;
OutTextData out_text_data;
std::chrono::time_point<std::chrono::high_resolution_clock> last_connection_time = std::chrono::high_resolution_clock::now();
int ret_val = 0;
int poll_timeout = 0;
const bool endianness = is_big_endian();
@ -681,7 +700,7 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data,
joystick_print_all();
while(capture_data->status.running) {
check_for_first_connection(did_first_connection, start_time, capture_data, &frontend_data, force_cc_disables, override_data, out_text_data, ret_val);
check_for_first_connection(did_first_connection, start_time, capture_data, &frontend_data, force_cc_disables, override_data, out_text_data, ret_val, last_connection_time);
if(!capture_data->status.running)
break;
@ -738,6 +757,7 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data,
blank_out = true;
no_data_consecutive++;
}
last_connection_time = std::chrono::high_resolution_clock::now();
}
else {
default_sleep();
@ -774,10 +794,13 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data,
joint_screen->m_info.window_enabled = false;
}
if(top_screen->open_capture() || bot_screen->open_capture() || joint_screen->open_capture()) {
bool asked_for_connect = top_screen->open_capture() || bot_screen->open_capture() || joint_screen->open_capture();
if(asked_for_connect || should_do_periodic_connection_try(&frontend_data.shared_data, capture_data->status.connected, last_connection_time)) {
if(did_first_connection) {
capture_data->status.connected = connect(true, capture_data, &frontend_data, force_cc_disables);
SuccessConnectionOutTextGenerator(out_text_data, capture_data);
capture_data->status.connected = connect(asked_for_connect, capture_data, &frontend_data, force_cc_disables);
if(capture_data->status.connected || asked_for_connect)
SuccessConnectionOutTextGenerator(out_text_data, capture_data);
last_connection_time = std::chrono::high_resolution_clock::now();
}
}

View File

@ -540,6 +540,7 @@ void reset_input_data(InputData* input_data) {
void reset_shared_data(SharedData* shared_data) {
reset_input_data(&shared_data->input_data);
shared_data->periodic_connection_try = false;
}
void reset_fullscreen_info(ScreenInfo &info) {