2024-04-14 14:09:51 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-07-24 06:12:53 +00:00
|
|
|
#include <string>
|
2024-04-14 14:09:51 +00:00
|
|
|
#include "common/types.h"
|
|
|
|
|
|
|
|
struct SDL_Window;
|
2024-08-13 09:54:08 +00:00
|
|
|
struct SDL_Gamepad;
|
2024-04-14 14:09:51 +00:00
|
|
|
union SDL_Event;
|
|
|
|
|
|
|
|
namespace Input {
|
|
|
|
class GameController;
|
2024-09-11 09:56:27 +00:00
|
|
|
}
|
2024-04-14 14:09:51 +00:00
|
|
|
|
|
|
|
namespace Frontend {
|
|
|
|
|
|
|
|
enum class WindowSystemType : u8 {
|
|
|
|
Headless,
|
|
|
|
Windows,
|
|
|
|
X11,
|
|
|
|
Wayland,
|
2024-07-09 09:18:34 +00:00
|
|
|
Metal,
|
2024-04-14 14:09:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct WindowSystemInfo {
|
|
|
|
// Connection to a display server. This is used on X11 and Wayland platforms.
|
|
|
|
void* display_connection = nullptr;
|
|
|
|
|
|
|
|
// Render surface. This is a pointer to the native window handle, which depends
|
|
|
|
// on the platform. e.g. HWND for Windows, Window for X11. If the surface is
|
|
|
|
// set to nullptr, the video backend will run in headless mode.
|
|
|
|
void* render_surface = nullptr;
|
|
|
|
|
|
|
|
// Scale of the render surface. For hidpi systems, this will be >1.
|
|
|
|
float render_surface_scale = 1.0f;
|
2024-08-24 13:18:12 +00:00
|
|
|
|
|
|
|
// Window system type. Determines which GL context or Vulkan WSI is used.
|
|
|
|
WindowSystemType type = WindowSystemType::Headless;
|
2024-04-14 14:09:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class WindowSDL {
|
2024-12-09 20:11:11 +00:00
|
|
|
int keyboard_grab = 0;
|
|
|
|
|
2024-04-14 14:09:51 +00:00
|
|
|
public:
|
2024-07-24 06:12:53 +00:00
|
|
|
explicit WindowSDL(s32 width, s32 height, Input::GameController* controller,
|
2024-07-31 21:56:10 +00:00
|
|
|
std::string_view window_title);
|
2024-04-14 14:09:51 +00:00
|
|
|
~WindowSDL();
|
|
|
|
|
2024-11-30 20:37:36 +00:00
|
|
|
s32 GetWidth() const {
|
2024-04-14 14:09:51 +00:00
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
2024-11-30 20:37:36 +00:00
|
|
|
s32 GetHeight() const {
|
2024-04-14 14:09:51 +00:00
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
2024-11-30 20:37:36 +00:00
|
|
|
bool IsOpen() const {
|
2024-04-14 14:09:51 +00:00
|
|
|
return is_open;
|
|
|
|
}
|
|
|
|
|
2024-11-30 20:37:36 +00:00
|
|
|
[[nodiscard]] SDL_Window* GetSDLWindow() const {
|
2024-09-08 19:50:32 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2024-11-30 20:37:36 +00:00
|
|
|
WindowSystemInfo GetWindowInfo() const {
|
2024-04-14 14:09:51 +00:00
|
|
|
return window_info;
|
|
|
|
}
|
|
|
|
|
2024-11-30 20:37:36 +00:00
|
|
|
void WaitEvent();
|
|
|
|
void InitTimers();
|
2024-10-19 12:57:01 +00:00
|
|
|
|
2024-12-09 20:11:11 +00:00
|
|
|
void RequestKeyboard();
|
|
|
|
void ReleaseKeyboard();
|
|
|
|
|
2024-04-14 14:09:51 +00:00
|
|
|
private:
|
2024-11-30 20:37:36 +00:00
|
|
|
void OnResize();
|
|
|
|
void OnKeyPress(const SDL_Event* event);
|
|
|
|
void OnGamepadEvent(const SDL_Event* event);
|
2024-04-14 14:09:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
s32 width;
|
|
|
|
s32 height;
|
|
|
|
Input::GameController* controller;
|
|
|
|
WindowSystemInfo window_info{};
|
|
|
|
SDL_Window* window{};
|
|
|
|
bool is_shown{};
|
|
|
|
bool is_open{true};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Frontend
|