From 6c039255a32970ac77b16ae5d8ef52d44464ede5 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Mon, 21 Sep 2026 03:35:13 +0200 Subject: [PATCH] Improve screen experience on Android --- android/app/src/main/AndroidManifest.xml | 1 + android/app/src/main/res/values/styles.xml | 5 ++ docker-scripts/docker_build_android | 4 +- .../docker_config_android_sfml_single_arch | 2 +- include/event_structs.hpp | 5 +- include/frontend.hpp | 1 + source/Menus/ResolutionMenu.cpp | 3 ++ source/WindowScreen.cpp | 18 +++++++ source/WindowScreen_Menu.cpp | 50 +++++++++++++++++-- source/cc3dsfs.cpp | 6 ++- 10 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 android/app/src/main/res/values/styles.xml diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 705d75f..67acc29 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ + + + diff --git a/docker-scripts/docker_build_android b/docker-scripts/docker_build_android index 7b3c833..69c2718 100644 --- a/docker-scripts/docker_build_android +++ b/docker-scripts/docker_build_android @@ -2,8 +2,8 @@ SFML_EXTRACTED_TO_FOLDER=~ LIBUSB_EXTRACTED_TO_FOLDER=~ -SFML_BRANCH_NAME=master -SFML_AUTHOR=SFML +SFML_BRANCH_NAME=android_fix_fs_weird +SFML_AUTHOR=Lorenzooone LIBUSB_BRANCH_NAME=android-rebase-2022-07 LIBUSB_AUTHOR=jagheterfredrik SFML_EXTRACTED_FOLDER=${SFML_EXTRACTED_TO_FOLDER}/SFML-${SFML_BRANCH_NAME} diff --git a/docker-scripts/docker_config_android_sfml_single_arch b/docker-scripts/docker_config_android_sfml_single_arch index 4a9c6c1..88e0274 100644 --- a/docker-scripts/docker_config_android_sfml_single_arch +++ b/docker-scripts/docker_config_android_sfml_single_arch @@ -6,4 +6,4 @@ STL_CHOSEN=$3 RELEASE_TYPE=$4 BUILD_FOLDER=${SFML_FOLDER}/build/${ARCH_CHOSEN} -(mkdir -p ${BUILD_FOLDER} ; cd ${BUILD_FOLDER} ; cmake -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK=${ANDROID_NDK_HOME} -DCMAKE_ANDROID_ARCH_ABI=${ARCH_CHOSEN} -DCMAKE_ANDROID_STL_TYPE=${STL_CHOSEN} -DCMAKE_BUILD_TYPE=${RELEASE_TYPE} ../.. ) +(mkdir -p ${BUILD_FOLDER} ; cd ${BUILD_FOLDER} ; cmake -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK=${ANDROID_NDK_HOME} -DCMAKE_ANDROID_ARCH_ABI=${ARCH_CHOSEN} -DCMAKE_SYSTEM_VERSION=${ANDROID_SDK_VERSION} -DCMAKE_ANDROID_STL_TYPE=${STL_CHOSEN} -DCMAKE_BUILD_TYPE=${RELEASE_TYPE} -DBUILD_SHARED_LIBS=ON ../.. ) diff --git a/include/event_structs.hpp b/include/event_structs.hpp index 91079e2..78c3416 100644 --- a/include/event_structs.hpp +++ b/include/event_structs.hpp @@ -7,7 +7,7 @@ enum JoystickDirection {JOY_DIR_NONE, JOY_DIR_UP, JOY_DIR_DOWN, JOY_DIR_LEFT, JOY_DIR_RIGHT}; enum JoystickAction {JOY_ACTION_NONE, JOY_ACTION_CONFIRM, JOY_ACTION_NEGATE, JOY_ACTION_MENU}; -enum EventType {EVENT_NONE, EVENT_JOYSTICK_BTN_PRESSED, EVENT_JOYSTICK_BTN_RELEASED, EVENT_JOYSTICK_MOVED, EVENT_MOUSE_BTN_PRESSED, EVENT_MOUSE_MOVED, EVENT_KEY_PRESSED, EVENT_TEXT_ENTERED, EVENT_CLOSED, EVENT_KEY_RELEASED, EVENT_MOUSE_BTN_RELEASED}; +enum EventType {EVENT_NONE, EVENT_JOYSTICK_BTN_PRESSED, EVENT_JOYSTICK_BTN_RELEASED, EVENT_JOYSTICK_MOVED, EVENT_MOUSE_BTN_PRESSED, EVENT_MOUSE_MOVED, EVENT_KEY_PRESSED, EVENT_TEXT_ENTERED, EVENT_CLOSED, EVENT_KEY_RELEASED, EVENT_MOUSE_BTN_RELEASED, EVENT_RESIZED}; struct SFEvent { SFEvent(bool pressed, sf::Keyboard::Key code, bool alt, bool control, bool shift, bool system, bool poweroff_cmd = false, bool is_extra = false) : type(pressed ? EVENT_KEY_PRESSED : EVENT_KEY_RELEASED), code(code), alt(alt), control(control), shift(shift), system(system), poweroff_cmd(poweroff_cmd), is_extra(is_extra) {} @@ -16,6 +16,7 @@ struct SFEvent { SFEvent(uint32_t joystickId, sf::Joystick::Axis axis, float position) : type(EVENT_JOYSTICK_MOVED), joystickId(joystickId), axis(axis), position(position) {} SFEvent(bool pressed, sf::Mouse::Button mouse_button, sf::Vector2i mouse_position) : type(pressed ? EVENT_MOUSE_BTN_PRESSED : EVENT_MOUSE_BTN_RELEASED), mouse_button(mouse_button), mouse_x(mouse_position.x), mouse_y(mouse_position.y) {} SFEvent(sf::Vector2i mouse_position) : type(EVENT_MOUSE_MOVED), mouse_x(mouse_position.x), mouse_y(mouse_position.y) {} + SFEvent(sf::Vector2u resized_size) : type(EVENT_RESIZED), width(resized_size.x), height(resized_size.y) {} SFEvent(EventType type) : type(type) {} EventType type; @@ -34,6 +35,8 @@ struct SFEvent { int mouse_y; bool poweroff_cmd; bool is_extra; + unsigned int width; + unsigned int height; }; void joystick_axis_poll(std::queue &events_queue); diff --git a/include/frontend.hpp b/include/frontend.hpp index 218b2f2..ad671ea 100755 --- a/include/frontend.hpp +++ b/include/frontend.hpp @@ -170,6 +170,7 @@ private: HeldTime right_click_action; HeldTime controller_button_action; bool consumed_touch_long_press; + bool can_create_small_touches = true; bool is_touch_currently_active[NUM_FINGERS_SUPPORTED]; sf::Vector2i touch_position[NUM_FINGERS_SUPPORTED]; const float touch_short_press_timer = 0.2f; diff --git a/source/Menus/ResolutionMenu.cpp b/source/Menus/ResolutionMenu.cpp index f578fb3..b4ad933 100755 --- a/source/Menus/ResolutionMenu.cpp +++ b/source/Menus/ResolutionMenu.cpp @@ -51,6 +51,9 @@ sf::VideoMode ResolutionMenu::get_resolution(int index) { std::string ResolutionMenu::get_string_option(int index, int action) { sf::VideoMode mode = this->get_resolution(index); if((mode.size.x == 0) && (mode.size.y == 0)) { + #if defined(ANDROID_COMPILATION) + return "System Preference (Auto Rotate)"; + #endif return "System Preference (" + std::to_string(this->desktop_resolution.size.x) + " x " + std::to_string(this->desktop_resolution.size.y) + ")"; } return std::to_string(mode.size.x) + " x " + std::to_string(mode.size.y); diff --git a/source/WindowScreen.cpp b/source/WindowScreen.cpp index 05d6ea1..be43968 100755 --- a/source/WindowScreen.cpp +++ b/source/WindowScreen.cpp @@ -1718,10 +1718,28 @@ void WindowScreen::create_window(bool re_prepare_size, bool reset_text) { this->curr_desk_mode = mode_created; success = true; } + /* + // Test stuff for SFML PR + #if defined(ANDROID_COMPILATION) + else if(mode_created == sf::VideoMode::getDesktopMode()) { + this->curr_desk_mode = sf::VideoMode::getDesktopMode(); + success = true; + this->m_info.failed_fullscreen = true; + } + #endif + */ } if(!success) { this->curr_desk_mode = sf::VideoMode::getDesktopMode(); success = this->curr_desk_mode.isValid(); + /* + // Test stuff for SFML PR + #if defined(ANDROID_COMPILATION) + this->curr_desk_mode = sf::VideoMode::getDesktopMode(); + success = true; + this->m_info.failed_fullscreen = true; + #endif + */ } #ifdef __APPLE__ if(!success) { diff --git a/source/WindowScreen_Menu.cpp b/source/WindowScreen_Menu.cpp index aa47703..daf809c 100755 --- a/source/WindowScreen_Menu.cpp +++ b/source/WindowScreen_Menu.cpp @@ -937,6 +937,32 @@ bool WindowScreen::common_poll(SFEvent &event_data) { case EVENT_JOYSTICK_MOVED: consumed = false; break; + case EVENT_RESIZED: + if((this->m_info.is_fullscreen) && (this->curr_desk_mode.size.x != event_data.width) && (this->curr_desk_mode.size.y != event_data.height)) { + #if defined(ANDROID_COMPILATION) + bool was_old_automatic = (this->m_info.fullscreen_mode_width <= 0) || (this->m_info.fullscreen_mode_height <= 0) || (this->m_info.fullscreen_mode_bpp <= 0); + this->m_info.fullscreen_mode_width = event_data.width; + this->m_info.fullscreen_mode_height = event_data.height; + this->m_info.fullscreen_mode_bpp = this->curr_desk_mode.bitsPerPixel; + /* + // Test stuff for SFML PR + this->m_info.fullscreen_mode_width = 0; + this->m_info.fullscreen_mode_height = 0; + this->m_info.fullscreen_mode_bpp = 0; + */ + this->create_window(true); + if(was_old_automatic) { + this->m_info.fullscreen_mode_width = 0; + this->m_info.fullscreen_mode_height = 0; + this->m_info.fullscreen_mode_bpp = 0; + } + #else + consumed = false; + #endif + } + else + consumed = false; + break; default: consumed = false; break; @@ -1128,6 +1154,11 @@ void WindowScreen::setup_resolution_menu(bool reset_data) { return; if(this->curr_menu != RESOLUTION_MENU_TYPE) { this->possible_resolutions.clear(); + /* + #if defined(ANDROID_COMPILATION) + this->possible_resolutions.push_back(sf::VideoMode::getDesktopMode()); + #endif + */ std::vector modes = sf::VideoMode::getFullscreenModes(); if(modes.size() > 0) { this->possible_resolutions.push_back(sf::VideoMode({0, 0}, 0)); @@ -2828,6 +2859,9 @@ void WindowScreen::poll_window(bool do_everything) { if(touch_ended->finger < NUM_FINGERS_SUPPORTED) this->is_touch_currently_active[touch_ended->finger] = false; } + else if(const auto* resized = event->getIf()) { + events_queue.emplace(resized->size); + } } } if(this->m_win.hasFocus()) { @@ -2855,13 +2889,19 @@ void WindowScreen::poll_window(bool do_everything) { if(diff.count() > this->touch_long_press_timer) { events_queue.emplace(true, sf::Mouse::Button::Right, touch_pos); this->touch_right_click_action.start_time = std::chrono::high_resolution_clock::now(); + if(this->curr_menu == DEFAULT_MENU_TYPE) + this->can_create_small_touches = false; } - const std::chrono::duration difftouch = curr_time - this->last_touch_left_time; - if(difftouch.count() > this->touch_short_press_timer) { - events_queue.emplace(true, sf::Mouse::Button::Left, touch_pos); - this->last_touch_left_time = std::chrono::high_resolution_clock::now(); + if(this->can_create_small_touches) { + const std::chrono::duration difftouch = curr_time - this->last_touch_left_time; + if(difftouch.count() > this->touch_short_press_timer) { + events_queue.emplace(true, sf::Mouse::Button::Left, touch_pos); + this->last_touch_left_time = std::chrono::high_resolution_clock::now(); + } } } + else + this->can_create_small_touches = true; if(this->shared_data->input_data.enable_controller_input) joystick_axis_poll(this->events_queue); } @@ -2869,6 +2909,7 @@ void WindowScreen::poll_window(bool do_everything) { extra_buttons_poll(this->events_queue); } else { + this->can_create_small_touches = true; this->reset_held_times(); check_held_reset(false, this->touch_right_click_action); } @@ -2876,6 +2917,7 @@ void WindowScreen::poll_window(bool do_everything) { else { for(int i = 0; i < NUM_FINGERS_SUPPORTED; i++) this->is_touch_currently_active[i] = false; + this->can_create_small_touches = true; this->reset_held_times(); check_held_reset(false, this->touch_right_click_action); } diff --git a/source/cc3dsfs.cpp b/source/cc3dsfs.cpp index 403d741..1f3b9f8 100755 --- a/source/cc3dsfs.cpp +++ b/source/cc3dsfs.cpp @@ -30,7 +30,11 @@ #define ANDROID_FIRST_CONNECTION_TIMEOUT 0.5 +#ifdef ANDROID_COMPILATION +#define PERIOD_CONNECTION_TRY_TIMEOUT 2.0 +#else #define PERIOD_CONNECTION_TRY_TIMEOUT 0.5 +#endif struct override_all_data { override_win_data override_top_bot_data; @@ -882,7 +886,7 @@ static int mainVideoOutputCall(AudioData* audio_data, CaptureData* capture_data, 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) { + if(did_first_connection && (*can_do_output)) { 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);