Skip to content

Commit

Permalink
switch: update for release-2.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Cpasjuste authored and WinterMute committed Jan 20, 2024
1 parent 29752cd commit 007fc27
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -27573,9 +27573,9 @@ $as_echo "#define SDL_JOYSTICK_SWITCH 1" >>confdefs.h
# Set up files for the timer library
if test x$enable_timers = xyes; then

$as_echo "#define SDL_TIMER_UNIX 1" >>confdefs.h
$as_echo "#define SDL_TIMER_SWITCH 1" >>confdefs.h

SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
SOURCES="$SOURCES $srcdir/src/timer/switch/*.c"
have_timers=yes
fi
# Set up files for the thread library
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4704,8 +4704,8 @@ dnl BeOS support removed after SDL 2.0.1. Haiku still works. --ryan.
fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
AC_DEFINE(SDL_TIMER_UNIX, 1, [ ])
SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
AC_DEFINE(SDL_TIMER_SWITCH, 1, [ ])
SOURCES="$SOURCES $srcdir/src/timer/switch/*.c"
have_timers=yes
fi
# Set up files for the thread library
Expand Down
4 changes: 2 additions & 2 deletions src/joystick/switch/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ SWITCH_JoystickOpen(SDL_Joystick *joystick, int device_index)
}

static int
SWITCH_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
SWITCH_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
// TODO
return SDL_Unsupported();
Expand Down Expand Up @@ -215,7 +215,7 @@ SDL_JoystickDriver SDL_SWITCH_JoystickDriver =
SWITCH_JoystickDetect,
SWITCH_JoystickGetDeviceName,
SWITCH_JoystickGetDevicePlayerIndex,
//SWITCH_JoystickSetDevicePlayerIndex,
SWITCH_JoystickSetDevicePlayerIndex,
SWITCH_JoystickGetDeviceGUID,
SWITCH_JoystickGetDeviceInstanceID,
SWITCH_JoystickOpen,
Expand Down
13 changes: 9 additions & 4 deletions src/video/switch/SDL_switchtouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <switch.h>

#include "SDL_events.h"
#include "SDL_switchtouch.h"
#include "../../events/SDL_touch_c.h"
#include "../../video/SDL_sysvideo.h"

#define MAX_TOUCH 16

Expand Down Expand Up @@ -61,6 +61,11 @@ SWITCH_QuitTouch(void)
void
SWITCH_PollTouch(void)
{
SDL_Window *window = SDL_GetFocusWindow();
if (window == NULL) {
return;
}

memcpy(&touchState_old, &touchState, sizeof(touchState));

touchState.count = hidTouchCount();
Expand All @@ -75,12 +80,12 @@ SWITCH_PollTouch(void)
hidTouchRead(&touchState.touch[i].position, i);

// Send an initial touch
SDL_SendTouch(0, (SDL_FingerID) i, SDL_TRUE,
SDL_SendTouch(0, (SDL_FingerID) i, window, SDL_TRUE,
(float) touchState.touch[i].position.px / 1280.0f,
(float) touchState.touch[i].position.py / 720.0f, 1);

// Always send the motion
SDL_SendTouchMotion(0, (SDL_FingerID) i,
SDL_SendTouchMotion(0, (SDL_FingerID) i, window,
(float) touchState.touch[i].position.px / 1280.0f,
(float) touchState.touch[i].position.py / 720.0f, 1);
}
Expand All @@ -102,7 +107,7 @@ SWITCH_PollTouch(void)

if (finger_up == 1) {
// Finger released from screen
SDL_SendTouch((SDL_TouchID) 0, (SDL_FingerID) touchState_old.touch[i].id, SDL_FALSE,
SDL_SendTouch((SDL_TouchID) 0, (SDL_FingerID) touchState_old.touch[i].id, window, SDL_FALSE,
(float) touchState_old.touch[i].position.px / 1280.0f,
(float) touchState_old.touch[i].position.py / 720.0f, 1);
}
Expand Down
16 changes: 11 additions & 5 deletions src/video/switch/SDL_switchvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ SWITCH_Available(void)
static void
SWITCH_Destroy(SDL_VideoDevice *device)
{
if (device) {
SDL_free(device->driverdata);
if (device != NULL) {
if(device->driverdata != NULL) {
SDL_free(device->driverdata);
}
SDL_free(device);
}
}
Expand Down Expand Up @@ -110,7 +112,7 @@ SWITCH_CreateDevice(int devindex)

VideoBootStrap SWITCH_bootstrap = {
"Switch",
"OpenGL ES2 video driver for Nintendo Switch",
"SDL2 video driver for Nintendo Switch",
SWITCH_Available,
SWITCH_CreateDevice
};
Expand All @@ -129,10 +131,12 @@ SWITCH_VideoInit(_THIS)
current_mode.h = 1080;
current_mode.refresh_rate = 60;
current_mode.format = SDL_PIXELFORMAT_RGBA8888;
current_mode.driverdata = NULL;

SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
display.driverdata = NULL;
SDL_AddVideoDisplay(&display);

// init touch
Expand Down Expand Up @@ -244,8 +248,10 @@ SWITCH_DestroyWindow(_THIS, SDL_Window *window)
if (data->egl_surface != EGL_NO_SURFACE) {
SDL_EGL_DestroySurface(_this, data->egl_surface);
}
SDL_free(window->driverdata);
window->driverdata = NULL;
if(window->driverdata != NULL) {
SDL_free(window->driverdata);
window->driverdata = NULL;
}
}
switch_window = NULL;
}
Expand Down

0 comments on commit 007fc27

Please sign in to comment.