/* ES40 emulator.
 * Copyright (C) 2007-2008 by the ES40 Emulator Project
 * Copyright (C) 2020-2025 by gdwnldsKSC
 *
 * WWW    : https://github.com/gdwnldsKSC/es40
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

/**
 * \file
 * SDL main thread support for macOS.
 *
 * On macOS, SDL3 requires that SDL_Init(SDL_INIT_VIDEO), window creation,
 * and event pumping happen on the main thread (the thread that called main()).
 * This file provides helpers to manage SDL on the main thread while running
 * the emulator in a background thread.
 */

#ifndef __SDL_MAIN_THREAD_H__
#define __SDL_MAIN_THREAD_H__

#include "../Configurator.h"

#if defined(HAVE_SDL)

class CSystem;

// Check if the configuration specifies SDL as the GUI
bool sdl_is_configured_gui(CConfigurator* cfg);

// Initialize SDL on the main thread (macOS only)
// Returns true if SDL was initialized, false otherwise
bool sdl_init_on_main_thread_if_needed(CConfigurator* cfg);

// Create the SDL window on the main thread (macOS only)
// This must be called AFTER sdl_init_on_main_thread_if_needed
// and BEFORE worker threads are spawned
void sdl_create_window_on_main_thread_if_needed();

// Run the emulator with proper SDL main thread handling
// On macOS: spawns CSystem::Run() in a background thread, uses main thread for SDL
// On other platforms: just calls CSystem::Run() directly
void sdl_aware_run(CSystem* sys);

// Cleanup SDL on main thread
void sdl_cleanup_main_thread();

#endif // HAVE_SDL

#endif // __SDL_MAIN_THREAD_H__
