diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu_cmd/config.cpp | 3 | ||||
| -rw-r--r-- | src/yuzu_cmd/default_ini.h | 13 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 48 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.h | 10 |
4 files changed, 39 insertions, 35 deletions
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 527017282..9c34cdc6e 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -176,6 +176,9 @@ void Config::ReadValues() { | |||
| 176 | Settings::values.debug_pad_analogs[i] = default_param; | 176 | Settings::values.debug_pad_analogs[i] = default_param; |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | ReadSetting("ControlsGeneral", Settings::values.enable_raw_input); | ||
| 180 | ReadSetting("ControlsGeneral", Settings::values.enable_joycon_driver); | ||
| 181 | ReadSetting("ControlsGeneral", Settings::values.emulate_analog_keyboard); | ||
| 179 | ReadSetting("ControlsGeneral", Settings::values.vibration_enabled); | 182 | ReadSetting("ControlsGeneral", Settings::values.vibration_enabled); |
| 180 | ReadSetting("ControlsGeneral", Settings::values.enable_accurate_vibrations); | 183 | ReadSetting("ControlsGeneral", Settings::values.enable_accurate_vibrations); |
| 181 | ReadSetting("ControlsGeneral", Settings::values.motion_enabled); | 184 | ReadSetting("ControlsGeneral", Settings::values.motion_enabled); |
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index 67d230462..3f3651dbe 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h | |||
| @@ -14,6 +14,7 @@ const char* sdl2_config_file = | |||
| 14 | # Escape characters $0 (for ':'), $1 (for ',') and $2 (for '$') can be used in values | 14 | # Escape characters $0 (for ':'), $1 (for ',') and $2 (for '$') can be used in values |
| 15 | 15 | ||
| 16 | # Indicates if this player should be connected at boot | 16 | # Indicates if this player should be connected at boot |
| 17 | # 0 (default): Disabled, 1: Enabled | ||
| 17 | connected= | 18 | connected= |
| 18 | 19 | ||
| 19 | # for button input, the following devices are available: | 20 | # for button input, the following devices are available: |
| @@ -94,6 +95,18 @@ motionright= | |||
| 94 | # 0 (default): Disabled, 1: Enabled | 95 | # 0 (default): Disabled, 1: Enabled |
| 95 | debug_pad_enabled = | 96 | debug_pad_enabled = |
| 96 | 97 | ||
| 98 | # Enable sdl raw input. Allows to configure up to 8 xinput controllers. | ||
| 99 | # 0 (default): Disabled, 1: Enabled | ||
| 100 | enable_raw_input = | ||
| 101 | |||
| 102 | # Enable yuzu joycon driver instead of SDL drive. | ||
| 103 | # 0: Disabled, 1 (default): Enabled | ||
| 104 | enable_joycon_driver = | ||
| 105 | |||
| 106 | # Emulates an analog input from buttons. Allowing to dial any angle. | ||
| 107 | # 0 (default): Disabled, 1: Enabled | ||
| 108 | emulate_analog_keyboard = | ||
| 109 | |||
| 97 | # Whether to enable or disable vibration | 110 | # Whether to enable or disable vibration |
| 98 | # 0: Disabled, 1 (default): Enabled | 111 | # 0: Disabled, 1 (default): Enabled |
| 99 | vibration_enabled= | 112 | vibration_enabled= |
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 31f28a507..5450b8c38 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | |||
| @@ -18,11 +18,11 @@ | |||
| 18 | 18 | ||
| 19 | EmuWindow_SDL2::EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem_, Core::System& system_) | 19 | EmuWindow_SDL2::EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem_, Core::System& system_) |
| 20 | : input_subsystem{input_subsystem_}, system{system_} { | 20 | : input_subsystem{input_subsystem_}, system{system_} { |
| 21 | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { | 21 | input_subsystem->Initialize(); |
| 22 | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) { | ||
| 22 | LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting..."); | 23 | LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting..."); |
| 23 | exit(1); | 24 | exit(1); |
| 24 | } | 25 | } |
| 25 | input_subsystem->Initialize(); | ||
| 26 | SDL_SetMainReady(); | 26 | SDL_SetMainReady(); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| @@ -32,10 +32,6 @@ EmuWindow_SDL2::~EmuWindow_SDL2() { | |||
| 32 | SDL_Quit(); | 32 | SDL_Quit(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { | ||
| 36 | input_subsystem->GetMouse()->MouseMove(x, y, 0, 0, 0, 0); | ||
| 37 | } | ||
| 38 | |||
| 39 | InputCommon::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const { | 35 | InputCommon::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const { |
| 40 | switch (button) { | 36 | switch (button) { |
| 41 | case SDL_BUTTON_LEFT: | 37 | case SDL_BUTTON_LEFT: |
| @@ -53,44 +49,36 @@ InputCommon::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) cons | |||
| 53 | } | 49 | } |
| 54 | } | 50 | } |
| 55 | 51 | ||
| 52 | std::pair<float, float> EmuWindow_SDL2::MouseToTouchPos(s32 touch_x, s32 touch_y) const { | ||
| 53 | int w, h; | ||
| 54 | SDL_GetWindowSize(render_window, &w, &h); | ||
| 55 | const float fx = static_cast<float>(touch_x) / w; | ||
| 56 | const float fy = static_cast<float>(touch_y) / h; | ||
| 57 | |||
| 58 | return {std::clamp<float>(fx, 0.0f, 1.0f), std::clamp<float>(fy, 0.0f, 1.0f)}; | ||
| 59 | } | ||
| 60 | |||
| 56 | void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { | 61 | void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { |
| 57 | const auto mouse_button = SDLButtonToMouseButton(button); | 62 | const auto mouse_button = SDLButtonToMouseButton(button); |
| 58 | if (state == SDL_PRESSED) { | 63 | if (state == SDL_PRESSED) { |
| 59 | input_subsystem->GetMouse()->PressButton(x, y, 0, 0, mouse_button); | 64 | const auto [touch_x, touch_y] = MouseToTouchPos(x, y); |
| 65 | input_subsystem->GetMouse()->PressButton(x, y, touch_x, touch_y, mouse_button); | ||
| 60 | } else { | 66 | } else { |
| 61 | input_subsystem->GetMouse()->ReleaseButton(mouse_button); | 67 | input_subsystem->GetMouse()->ReleaseButton(mouse_button); |
| 62 | } | 68 | } |
| 63 | } | 69 | } |
| 64 | 70 | ||
| 65 | std::pair<unsigned, unsigned> EmuWindow_SDL2::TouchToPixelPos(float touch_x, float touch_y) const { | 71 | void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { |
| 66 | int w, h; | 72 | const auto [touch_x, touch_y] = MouseToTouchPos(x, y); |
| 67 | SDL_GetWindowSize(render_window, &w, &h); | 73 | input_subsystem->GetMouse()->MouseMove(x, y, touch_x, touch_y, 0, 0); |
| 68 | |||
| 69 | touch_x *= w; | ||
| 70 | touch_y *= h; | ||
| 71 | |||
| 72 | return {static_cast<unsigned>(std::max(std::round(touch_x), 0.0f)), | ||
| 73 | static_cast<unsigned>(std::max(std::round(touch_y), 0.0f))}; | ||
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | void EmuWindow_SDL2::OnFingerDown(float x, float y, std::size_t id) { | 76 | void EmuWindow_SDL2::OnFingerDown(float x, float y, std::size_t id) { |
| 77 | int width, height; | 77 | input_subsystem->GetTouchScreen()->TouchPressed(x, y, id); |
| 78 | SDL_GetWindowSize(render_window, &width, &height); | ||
| 79 | const auto [px, py] = TouchToPixelPos(x, y); | ||
| 80 | const float fx = px * 1.0f / width; | ||
| 81 | const float fy = py * 1.0f / height; | ||
| 82 | |||
| 83 | input_subsystem->GetTouchScreen()->TouchPressed(fx, fy, id); | ||
| 84 | } | 78 | } |
| 85 | 79 | ||
| 86 | void EmuWindow_SDL2::OnFingerMotion(float x, float y, std::size_t id) { | 80 | void EmuWindow_SDL2::OnFingerMotion(float x, float y, std::size_t id) { |
| 87 | int width, height; | 81 | input_subsystem->GetTouchScreen()->TouchMoved(x, y, id); |
| 88 | SDL_GetWindowSize(render_window, &width, &height); | ||
| 89 | const auto [px, py] = TouchToPixelPos(x, y); | ||
| 90 | const float fx = px * 1.0f / width; | ||
| 91 | const float fy = py * 1.0f / height; | ||
| 92 | |||
| 93 | input_subsystem->GetTouchScreen()->TouchMoved(fx, fy, id); | ||
| 94 | } | 82 | } |
| 95 | 83 | ||
| 96 | void EmuWindow_SDL2::OnFingerUp() { | 84 | void EmuWindow_SDL2::OnFingerUp() { |
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h index 25c23e2a5..d9b453dee 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h | |||
| @@ -38,17 +38,17 @@ protected: | |||
| 38 | /// Called by WaitEvent when a key is pressed or released. | 38 | /// Called by WaitEvent when a key is pressed or released. |
| 39 | void OnKeyEvent(int key, u8 state); | 39 | void OnKeyEvent(int key, u8 state); |
| 40 | 40 | ||
| 41 | /// Called by WaitEvent when the mouse moves. | ||
| 42 | void OnMouseMotion(s32 x, s32 y); | ||
| 43 | |||
| 44 | /// Converts a SDL mouse button into MouseInput mouse button | 41 | /// Converts a SDL mouse button into MouseInput mouse button |
| 45 | InputCommon::MouseButton SDLButtonToMouseButton(u32 button) const; | 42 | InputCommon::MouseButton SDLButtonToMouseButton(u32 button) const; |
| 46 | 43 | ||
| 44 | /// Translates pixel position to float position | ||
| 45 | std::pair<float, float> MouseToTouchPos(s32 touch_x, s32 touch_y) const; | ||
| 46 | |||
| 47 | /// Called by WaitEvent when a mouse button is pressed or released | 47 | /// Called by WaitEvent when a mouse button is pressed or released |
| 48 | void OnMouseButton(u32 button, u8 state, s32 x, s32 y); | 48 | void OnMouseButton(u32 button, u8 state, s32 x, s32 y); |
| 49 | 49 | ||
| 50 | /// Translates pixel position (0..1) to pixel positions | 50 | /// Called by WaitEvent when the mouse moves. |
| 51 | std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const; | 51 | void OnMouseMotion(s32 x, s32 y); |
| 52 | 52 | ||
| 53 | /// Called by WaitEvent when a finger starts touching the touchscreen | 53 | /// Called by WaitEvent when a finger starts touching the touchscreen |
| 54 | void OnFingerDown(float x, float y, std::size_t id); | 54 | void OnFingerDown(float x, float y, std::size_t id); |