Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion workspace/all/common/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3957,6 +3957,18 @@ static struct VIB_Context
int queued_strength;
int strength;
} vib = {0};
// User-facing "Rumble strength" setting, applied to every request right before it
// reaches the platform. vib.strength stays in core units (0..0xFFFF) so
// VIB_getStrength() and the change detection above are unaffected.
static int VIB_applyScale(int strength)
{
int percent = CFG_getRumbleStrength();
if (percent >= 100)
return strength;
if (percent <= 0)
return 0;
return (int)(((long long)strength * percent) / 100);
}
static void *VIB_thread(void *arg)
{
#define DEFER_FRAMES 3
Expand All @@ -3974,7 +3986,7 @@ static void *VIB_thread(void *arg)
vib.strength = vib.queued_strength;
defer = 0;

PLAT_setRumble(vib.strength);
PLAT_setRumble(VIB_applyScale(vib.strength));
}
}
return 0;
Expand All @@ -3993,6 +4005,11 @@ void VIB_quit(void)
VIB_setStrength(0);
pthread_cancel(vib.pt);
pthread_join(vib.pt, NULL);
// the queued 0 above is usually lost (the thread is cancelled inside its
// SDL_Delay or still deferring the drop), so stop the motor ourselves
vib.strength = vib.queued_strength = 0;
PLAT_setRumble(0);
vib.initialized = 0;
Comment on lines +4008 to +4012

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be a PR on its own, since it fixes an issue with the current logic here (we could probably also drop the VIB_setStrength(0); above too)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I only included it in this PR since the change is rather small, but we could definitely move it into a separate PR. What do you prefer?

}
void VIB_setStrength(int strength)
{
Expand Down Expand Up @@ -4291,6 +4308,10 @@ void PWR_disablePowerOff(void)
}
void PWR_powerOff(int reboot)
{
// the core is blocked in PWR_update, so its last rumble request would stay
// queued and the motor would run through the power-off screen
VIB_setStrength(0);

if (pwr.can_poweroff)
{

Expand Down Expand Up @@ -4341,6 +4362,9 @@ void PWR_powerOff(int reboot)

static void PWR_enterSleep(void)
{
// a core may be mid-rumble when the lid closes; without haptics the sleep
// pulse below never runs, and the motor would stay on through suspend
VIB_setStrength(0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user holds the power button (going into the "Quicksave created, powering off" screen) wouldn't the vibrate continue to happen through that screen?

I think we probably need VIB_setStrength(0); in PWR_powerOff() to avoid that scenario while a device is going to sleep.

@puchupala puchupala Nov 23, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, added in e8d8c0f for now. Depending on #899 (comment), we may want to move this to a new PR.

#if defined(SND_CLOSE_ON_SLEEP) && SND_CLOSE_ON_SLEEP
// On H700, fully close the audio device before sleeping: a PCM left open
// across suspend-to-RAM ends up in a state SDL takes ~10s to close on
Expand Down
23 changes: 23 additions & 0 deletions workspace/all/common/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void CFG_defaults(NextUISettings *cfg)
.keepAwakeWhenUSB = CFG_DEFAULT_KEEPAWAKEWHENUSB,

.haptics = CFG_DEFAULT_HAPTICS,
.rumbleStrength = CFG_DEFAULT_RUMBLESTRENGTH,
.romsUseFolderBackground = CFG_DEFAULT_ROMSUSEFOLDERBACKGROUND,
.saveFormat = CFG_DEFAULT_SAVEFORMAT,
.stateFormat = CFG_DEFAULT_STATEFORMAT,
Expand Down Expand Up @@ -321,6 +322,11 @@ void CFG_init(FontLoad_callback_t cb, ColorSet_callback_t ccb)
CFG_setHaptics((bool)temp_value);
continue;
}
if (sscanf(line, "rumbleStrength=%i", &temp_value) == 1)
{
CFG_setRumbleStrength(temp_value);
continue;
}
if (sscanf(line, "romfolderbg=%i", &temp_value) == 1)
{
CFG_setRomsUseFolderBackground((bool)temp_value);
Expand Down Expand Up @@ -892,6 +898,17 @@ void CFG_setHaptics(bool enable)
CFG_sync();
}

int CFG_getRumbleStrength(void)
{
return settings.rumbleStrength;
}

void CFG_setRumbleStrength(int percent)
{
settings.rumbleStrength = clamp(percent, 0, 100);
CFG_sync();
}
Comment on lines +906 to +910

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing this manually instead of using clamp()?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to avoid relying on C++17 unnecessarily and didn't notice that clamp is already available in https://github.com/LoveRetro/NextUI/blob/main/workspace/all/common/utils.h#L47

Let's use clamp() as suggested since it's already there and is much cleaner.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a6635eb, thanks.


int CFG_getSaveFormat(void)
{
return settings.saveFormat;
Expand Down Expand Up @@ -1458,6 +1475,10 @@ void CFG_get(const char *key, char *value)
{
sprintf(value, "%i", CFG_getMuteLEDs());
}
else if (strcmp(key, "rumbleStrength") == 0)
{
sprintf(value, "%i", CFG_getRumbleStrength());
}
else if (strcmp(key, "fn1action") == 0)
{
sprintf(value, "%s", CFG_getFnAction(0));
Expand Down Expand Up @@ -1650,6 +1671,7 @@ void CFG_sync(void)
fprintf(file, "keepAwakeWhenUSB=%i\n", settings.keepAwakeWhenUSB);
fprintf(file, "switcherscale=%i\n", settings.gameSwitcherScaling);
fprintf(file, "haptics=%i\n", settings.haptics);
fprintf(file, "rumbleStrength=%i\n", settings.rumbleStrength);
fprintf(file, "romfolderbg=%i\n", settings.romsUseFolderBackground);
fprintf(file, "saveFormat=%i\n", settings.saveFormat);
fprintf(file, "stateFormat=%i\n", settings.stateFormat);
Expand Down Expand Up @@ -1725,6 +1747,7 @@ void CFG_print(void)
printf("\t\"keepAwakeWhenUSB\": %i,\n", settings.keepAwakeWhenUSB);
printf("\t\"switcherscale\": %i,\n", settings.gameSwitcherScaling);
printf("\t\"haptics\": %i,\n", settings.haptics);
printf("\t\"rumbleStrength\": %i,\n", settings.rumbleStrength);
printf("\t\"romfolderbg\": %i,\n", settings.romsUseFolderBackground);
printf("\t\"saveFormat\": %i,\n", settings.saveFormat);
printf("\t\"stateFormat\": %i,\n", settings.stateFormat);
Expand Down
5 changes: 5 additions & 0 deletions workspace/all/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ typedef struct

// Haptic
bool haptics;
int rumbleStrength; // percent, 0 = off, 100 = full

// Networking
bool ntp;
Expand Down Expand Up @@ -232,6 +233,7 @@ typedef struct
#define CFG_DEFAULT_POWEROFFPROTECTION true
#define CFG_DEFAULT_KEEPAWAKEWHENUSB false
#define CFG_DEFAULT_HAPTICS false
#define CFG_DEFAULT_RUMBLESTRENGTH 100
#define CFG_DEFAULT_ROMSUSEFOLDERBACKGROUND true
#define CFG_DEFAULT_SAVEFORMAT SAVE_FORMAT_SAV
#define CFG_DEFAULT_STATEFORMAT STATE_FORMAT_SAV
Expand Down Expand Up @@ -370,6 +372,9 @@ void CFG_setGameSwitcherScaling(int enumValue);
// Enable/disable haptics.
bool CFG_getHaptics(void);
void CFG_setHaptics(bool enable);
// Scale applied to every rumble/haptic request, in percent (0 = off, 100 = full).
int CFG_getRumbleStrength(void);
void CFG_setRumbleStrength(int percent);
// Save format to use for libretro cores
// 0 - .sav
// 1 - .srm (compressed rzip)
Expand Down
9 changes: 9 additions & 0 deletions workspace/all/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ static const std::vector<std::string> transition_mode_labels = {"Off", "Snappy",
static const std::vector<std::any> curtain_opacity_values = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
static const std::vector<std::string> curtain_opacity_labels = {"Off", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"};

// Rumble strength options (percent, 0 = off)
static const std::vector<std::any> rumble_strength_values = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
static const std::vector<std::string> rumble_strength_labels = {"Off", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"};

// Input prompt style options
static const std::vector<std::any> input_prompt_style_values = {(int)INPUT_STYLE_TEXT, (int)INPUT_STYLE_ABXY, (int)INPUT_STYLE_CARDINALS, (int)INPUT_STYLE_SHAPES};
static const std::vector<std::string> input_prompt_style_labels = {"Text", "ABXY", "Cardinals", "Shapes"};
Expand Down Expand Up @@ -657,6 +661,11 @@ int main(int argc, char *argv[])
{ return CFG_getHaptics(); }, [](const std::any &value)
{ CFG_setHaptics(std::any_cast<bool>(value)); },
[]() { CFG_setHaptics(CFG_DEFAULT_HAPTICS);}},
new MenuItem{ListItemType::Generic, "Rumble strength", "Strength of game rumble and haptic pulses (Off disables rumble)", rumble_strength_values, rumble_strength_labels, []() -> std::any
{ // snap to the 10% grid so a hand-edited value still matches a list entry
return (CFG_getRumbleStrength() + 5) / 10 * 10; }, [](const std::any &value)
{ CFG_setRumbleStrength(std::any_cast<int>(value)); },
[]() { CFG_setRumbleStrength(CFG_DEFAULT_RUMBLESTRENGTH);}},
new MenuItem{ListItemType::Generic, "Default view", "The initial view to show on boot",
{(int)SCREEN_GAMELIST, (int)SCREEN_GAMESWITCHER, (int)SCREEN_QUICKMENU},
{"Content List","Game Switcher","Quick Menu"},
Expand Down