Files
vanilla/gui/main.c
T
Joshua Brest (杰成)andMattKC 78b923719c Add iOS support with build scripts, toolchain, and assets (#302)
* feat: add iOS support

* ios: clean up icon

* ci: add ios build

* fix(gui): revert asset lookups to use "%s/assets/%s/%s" for macOS

* refactor(gui): remove extra `iconv` linkage for iOS

* chore(gitignore): remove unused `xcuserdata` and `DerivedData` entries

* fix(gui): use provided `LibXML2` in non-vendored builds

* fix(ci): add Xcode setup step for iOS build

* fix(pipe): prevent relay threads from using freed stack memory

* fix(input): replace bitfields with explicit wire packing for touch and gyro data

* fix merge issues

* fix cmake merge bug

* cmake: attempt iOS SDL fix

* older ios

* feat: add iOS support

* ios: clean up icon

* ci: add ios build

* refactor(gui): remove extra `iconv` linkage for iOS

* chore(gitignore): remove unused `xcuserdata` and `DerivedData` entries

* fix(ci): add Xcode setup step for iOS build

* cmake: attempt iOS SDL fix

* older ios

* cleanup

* build signed macOS app alongside iOS app

* cmake: detect ios version and include liquid glass icon if available

* ci: upload continuous release

* cmake: move more ios code to toolchain

* remove ios simulator target

* improvements

* remove CMakePresets.json

* Update ios-toolchain.cmake

* move ios folder to gui folder

* converge Info.plist templates

* update comments and readme

* cmake: remove redundant code

* remove redundant ios folder

* cmake: add comments to cache strings

* cmake/ci: maybe fix new apple builds

* cmake: fix new ios build

* cmake: fix macOS build?

---------

Co-authored-by: MattKC <34096995+itsmattkc@users.noreply.github.com>
2026-09-09 02:25:50 -07:00

147 lines
4.1 KiB
C

#include <errno.h>
#include <SDL.h>
#include <stdio.h>
#include <string.h>
#include <vanilla.h>
#include "config.h"
#include "menu/menu.h"
#include "platform.h"
#include "ui/ui.h"
#include "ui/ui_sdl.h"
#if defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_IOS
// SDL_main will be linked incorrectly on iOS unless we include this
#include <SDL.h>
#endif
#endif
#define SCREEN_WIDTH 854
#define SCREEN_HEIGHT 480
#include "pipemgmt.h"
void display_cli_help(char **argv);
int main(int argc, char **argv)
{
int ret = 1;
// Determine whether we're overriding the fullscreen setting in the config
int override_fs = -1;
int force_swdec = 0;
long autoconnect = -1;
for (int i = 1, consumed; i < argc; i += consumed) {
consumed = -1;
if (!strcmp(argv[i], "-w") || !strcmp(argv[i], "--window")) {
override_fs = 0;
consumed = 1;
} else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--fullscreen")) {
override_fs = 1;
consumed = 1;
} else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--swdec")) {
force_swdec = 1;
consumed = 1;
} else if (!strcmp(argv[i], "-a") || !strcmp(argv[i], "--autoconnect")) {
if (i + 1 >= argc) {
vpilog("%s requires an argument\n", argv[i]);
return 1;
}
const char *s_acId = argv[i+1];
char *endptr;
autoconnect = strtol(s_acId, &endptr, 10);
if (errno == ERANGE || endptr == s_acId || *endptr != '\0' || autoconnect < 0) {
vpilog("\"%s\" was not a valid argument for %s\n", s_acId, argv[i]);
return 1;
}
consumed = 2;
} else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
display_cli_help(argv);
return 0;
}
if (consumed <= 0) {
vpilog("Invalid argument(s): %s\n\n", argv[i]);
display_cli_help(argv);
return 1;
}
}
vanilla_install_logger(vpilog_va);
// Load config
vpi_config_init();
if (autoconnect >= vpi_config.connected_console_count) {
vpilog("Console %li does not exist for auto-connection\n", autoconnect);
goto exit_config;
}
vpi_config.autoconnect = autoconnect;
vpi_config.force_software_decode |= force_swdec;
#ifndef VANILLA_GUI_ENABLE_WINDOWED
// Window mode is disabled, so we'll just enable fullscreen
override_fs = 1;
#endif
// Check if override fullscreen, if so set it in the config, but don't save
if (override_fs != -1) {
vpi_config.fullscreen = override_fs;
}
// Initialize UI system
vui_context_t *vui = vui_alloc(SCREEN_WIDTH, SCREEN_HEIGHT);
// Initialize SDL2
if (vui_init_sdl(vui, vpi_config.fullscreen)) {
vpilog("Failed to initialize VUI\n");
goto exit;
}
#ifndef ANDROID
// On Linux/Buildroot platforms like Raspberry Pi and Nintendo Switch, it
// is desirable for the brightness to be restored from config. On Android
// though, the brightness will be set externally so changing it here is
// probably not desirable.
vui_brightness_set(vui, vpi_config.screen_brightness);
#endif
vpi_menu_init(vui);
while (vui_update_sdl(vui)) {
vpi_update_pipe();
}
ret = 0;
vpi_stop_pipe();
exit:
vui_close_sdl(vui);
vui_free(vui);
exit_config:
vpi_config_free();
return ret;
}
void display_cli_help(char **argv) {
vpilog("Usage: %s [options]\n\n", argv[0]);
vpilog("Options:\n");
vpilog(" -w, --window Run Vanilla in a window (overrides config)\n");
vpilog(" -f, --fullscreen Run Vanilla full screen (overrides config)\n");
vpilog(" -s, --swdec Force software decoding (overrides config)\n");
vpilog(" -a <id>,\n");
vpilog(" --autoconnect <id> Auto-connect to a console on startup\n");
vpilog(" (<id> is the index of the console in the\n");
vpilog(" menu, e.g. 0 is the first console, 1 is\n");
vpilog(" the second, etc.)\n");
vpilog(" -h, --help Show this help message\n");
}