Files
eden/src/yuzu_cmd/emu_window/emu_window_sdl3.h
T
lizzie e7a931d06b [eden-cli] rework loop to use new SDL3 event dispatch system (#4108)
modernized into the new SDL3 API for event dispatching.

also stopped using the periodic comparison and just added a SDL timer like it wants us to do
is it better than before? well it's certainly more portable now. docs say this improves battery usage on busywaits for event polling.

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4108
Reviewed-by: Maufeat <sahyno1996@gmail.com>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
2026-08-12 18:10:24 +02:00

104 lines
3.2 KiB
C++

// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <tuple>
#include <utility>
#include <SDL3/SDL.h>
#include <SDL3/SDL_timer.h>
#include "core/frontend/emu_window.h"
#include "core/frontend/graphics_context.h"
namespace Core {
class System;
}
namespace InputCommon {
class InputSubsystem;
enum class MouseButton;
} // namespace InputCommon
class EmuWindow_SDL3 : public Core::Frontend::EmuWindow {
public:
explicit EmuWindow_SDL3(InputCommon::InputSubsystem* input_subsystem_, Core::System& system_);
~EmuWindow_SDL3();
/// Whether the window is still open, and a close request hasn't yet been sent
bool IsOpen() const;
/// Returns if window is shown (not minimized)
bool IsShown() const override;
/// Wait for the next event on the main thread.
void OnEvent(SDL_Event& event);
// Sets the window icon from yuzu.bmp
void SetWindowIcon();
protected:
/// Called by WaitEvent when a key is pressed or released.
void OnKeyEvent(int key, u8 state);
/// Converts a SDL mouse button into MouseInput mouse button
InputCommon::MouseButton SDLButtonToMouseButton(u32 button) const;
// Using std::pair<float,float> will invoke HFA miscompilation bug on g++10
// on newer versions it emits an annoying warning, so just not use an HFA
// https://stackoverflow.com/questions/77729813/parameter-passing-for-argument-when-c17-is-enabled-changed-to-match-c14
using FloatPairNonHFA = std::tuple<float, float, char>;
FloatPairNonHFA MouseToTouchPos(s32 touch_x, s32 touch_y) const;
/// Called by WaitEvent when a mouse button is pressed or released
void OnMouseButton(u32 button, u8 state, s32 x, s32 y);
/// Called by WaitEvent when the mouse moves.
void OnMouseMotion(s32 x, s32 y);
/// Called by WaitEvent when a finger starts touching the touchscreen
void OnFingerDown(float x, float y, std::size_t id);
/// Called by WaitEvent when a finger moves while touching the touchscreen
void OnFingerMotion(float x, float y, std::size_t id);
/// Called by WaitEvent when a finger stops touching the touchscreen
void OnFingerUp();
/// Called by WaitEvent when any event that may cause the window to be resized occurs
void OnResize();
/// Called when users want to hide the mouse cursor
void ShowCursor(bool show_cursor);
/// Called when user passes the fullscreen parameter flag
void Fullscreen();
/// Called when a configuration change affects the minimal size of the window
void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override;
/// Periodic changer of titlebar (independent of event loop)
SDL_TimerID titlebar_timer;
/// Is the window still open?
bool is_open = true;
/// Is the window being shown?
bool is_shown = true;
/// Internal SDL3 render window
SDL_Window* render_window{};
/// Input subsystem to use with this window.
InputCommon::InputSubsystem* input_subsystem;
/// yuzu core instance
Core::System& system;
};
class DummyContext : public Core::Frontend::GraphicsContext {};