From a7bd3208a5aed38a896661710990ebc65eb8a8d7 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Mon, 9 Sep 2024 00:44:48 +0200 Subject: [PATCH] Declutter main rosalina menu & reorder "Change screen brightness" (due to limitations), "Power Off", "Reboot" moved to sysconfig menu --- sysmodules/rosalina/include/menus.h | 3 - sysmodules/rosalina/include/menus/sysconfig.h | 3 + sysmodules/rosalina/source/menus.c | 165 +----------------- sysmodules/rosalina/source/menus/sysconfig.c | 160 +++++++++++++++++ 4 files changed, 165 insertions(+), 166 deletions(-) diff --git a/sysmodules/rosalina/include/menus.h b/sysmodules/rosalina/include/menus.h index 336f4ccb..8e870fb1 100644 --- a/sysmodules/rosalina/include/menus.h +++ b/sysmodules/rosalina/include/menus.h @@ -33,12 +33,9 @@ extern Menu rosalinaMenu; void RosalinaMenu_TakeScreenshot(void); -void RosalinaMenu_ChangeScreenBrightness(void); void RosalinaMenu_ShowCredits(void); void RosalinaMenu_ProcessList(void); void RosalinaMenu_SaveSettings(void); -void RosalinaMenu_PowerOff(void); -void RosalinaMenu_Reboot(void); void RosalinaMenu_Cheats(void); void RosalinaMenu_ShowSystemInfo(); diff --git a/sysmodules/rosalina/include/menus/sysconfig.h b/sysmodules/rosalina/include/menus/sysconfig.h index 63c08592..0fe1107a 100644 --- a/sysmodules/rosalina/include/menus/sysconfig.h +++ b/sysmodules/rosalina/include/menus/sysconfig.h @@ -43,3 +43,6 @@ void SysConfigMenu_DisableForcedWifiConnection(void); void SysConfigMenu_ToggleCardIfPower(void); void SysConfigMenu_LoadConfig(void); void SysConfigMenu_AdjustVolume(void); +void SysConfigMenu_ChangeScreenBrightness(void); +void SysConfigMenu_PowerOff(void); +void SysConfigMenu_Reboot(void); diff --git a/sysmodules/rosalina/source/menus.c b/sysmodules/rosalina/source/menus.c index f4d43443..f107bf97 100644 --- a/sysmodules/rosalina/source/menus.c +++ b/sysmodules/rosalina/source/menus.c @@ -40,25 +40,21 @@ #include "memory.h" #include "fmt.h" #include "process_patches.h" -#include "luminance.h" #include "luma_config.h" Menu rosalinaMenu = { "Rosalina menu", { { "Take screenshot", METHOD, .method = &RosalinaMenu_TakeScreenshot }, - { "Change screen brightness", METHOD, .method = &RosalinaMenu_ChangeScreenBrightness }, + { "Screen filters...", MENU, .menu = &screenFiltersMenu }, { "Cheats...", METHOD, .method = &RosalinaMenu_Cheats }, { "", METHOD, .method = PluginLoader__MenuCallback}, + { "New 3DS menu...", MENU, .menu = &N3DSMenu, .visibility = &menuCheckN3ds }, { "Process list", METHOD, .method = &RosalinaMenu_ProcessList }, { "Debugger options...", MENU, .menu = &debuggerMenu }, { "System configuration...", MENU, .menu = &sysconfigMenu }, - { "Screen filters...", MENU, .menu = &screenFiltersMenu }, - { "New 3DS menu...", MENU, .menu = &N3DSMenu, .visibility = &menuCheckN3ds }, { "Miscellaneous options...", MENU, .menu = &miscellaneousMenu }, { "Save settings", METHOD, .method = &RosalinaMenu_SaveSettings }, - { "Power off", METHOD, .method = &RosalinaMenu_PowerOff }, - { "Reboot", METHOD, .method = &RosalinaMenu_Reboot }, { "System info", METHOD, .method = &RosalinaMenu_ShowSystemInfo }, { "Credits", METHOD, .method = &RosalinaMenu_ShowCredits }, { "Debug info", METHOD, .method = &RosalinaMenu_ShowDebugInfo, .visibility = &rosalinaMenuShouldShowDebugInfo }, @@ -216,163 +212,6 @@ void RosalinaMenu_ShowCredits(void) while(!(waitInput() & KEY_B) && !menuShouldExit); } -void RosalinaMenu_Reboot(void) -{ - Draw_Lock(); - Draw_ClearFramebuffer(); - Draw_FlushFramebuffer(); - Draw_Unlock(); - - do - { - Draw_Lock(); - Draw_DrawString(10, 10, COLOR_TITLE, "Reboot"); - Draw_DrawString(10, 30, COLOR_WHITE, "Press A to reboot, press B to go back."); - Draw_FlushFramebuffer(); - Draw_Unlock(); - - u32 pressed = waitInputWithTimeout(1000); - - if(pressed & KEY_A) - { - menuLeave(); - APT_HardwareResetAsync(); - return; - } else if(pressed & KEY_B) - return; - } - while(!menuShouldExit); -} - -void RosalinaMenu_ChangeScreenBrightness(void) -{ - Draw_Lock(); - Draw_ClearFramebuffer(); - Draw_FlushFramebuffer(); - Draw_Unlock(); - - // gsp:LCD GetLuminance is stubbed on O3DS so we have to implement it ourselves... damn it. - // Assume top and bottom screen luminances are the same (should be; if not, we'll set them to the same values). - u32 luminance = getCurrentLuminance(false); - u32 minLum = getMinLuminancePreset(); - u32 maxLum = getMaxLuminancePreset(); - - do - { - Draw_Lock(); - Draw_DrawString(10, 10, COLOR_TITLE, "Screen brightness"); - u32 posY = 30; - posY = Draw_DrawFormattedString( - 10, - posY, - COLOR_WHITE, - "Current luminance: %lu (min. %lu, max. %lu)\n\n", - luminance, - minLum, - maxLum - ); - posY = Draw_DrawString(10, posY, COLOR_WHITE, "Controls: Up/Down for +-1, Right/Left for +-10.\n"); - posY = Draw_DrawString(10, posY, COLOR_WHITE, "Press A to start, B to exit.\n\n"); - - posY = Draw_DrawString(10, posY, COLOR_RED, "WARNING: \n"); - posY = Draw_DrawString(10, posY, COLOR_WHITE, " * value will be limited by the presets.\n"); - posY = Draw_DrawString(10, posY, COLOR_WHITE, " * bottom framebuffer will be restored until\nyou exit."); - Draw_FlushFramebuffer(); - Draw_Unlock(); - - u32 pressed = waitInputWithTimeout(1000); - - if (pressed & KEY_A) - break; - - if (pressed & KEY_B) - return; - } - while (!menuShouldExit); - - Draw_Lock(); - - Draw_RestoreFramebuffer(); - Draw_FreeFramebufferCache(); - - svcKernelSetState(0x10000, 2); // unblock gsp - gspLcdInit(); // assume it doesn't fail. If it does, brightness won't change, anyway. - - // gsp:LCD will normalize the brightness between top/bottom screen, handle PWM, etc. - - s32 lum = (s32)luminance; - - do - { - u32 pressed = waitInputWithTimeout(1000); - if (pressed & DIRECTIONAL_KEYS) - { - if (pressed & KEY_UP) - lum += 1; - else if (pressed & KEY_DOWN) - lum -= 1; - else if (pressed & KEY_RIGHT) - lum += 10; - else if (pressed & KEY_LEFT) - lum -= 10; - - lum = lum < (s32)minLum ? (s32)minLum : lum; - lum = lum > (s32)maxLum ? (s32)maxLum : lum; - - // We need to call gsp here because updating the active duty LUT is a bit tedious (plus, GSP has internal state). - // This is actually SetLuminance: - GSPLCD_SetBrightnessRaw(BIT(GSP_SCREEN_TOP) | BIT(GSP_SCREEN_BOTTOM), lum); - } - - if (pressed & KEY_B) - break; - } - while (!menuShouldExit); - - gspLcdExit(); - svcKernelSetState(0x10000, 2); // block gsp again - - if (R_FAILED(Draw_AllocateFramebufferCache(FB_BOTTOM_SIZE))) - { - // Shouldn't happen - __builtin_trap(); - } - else - Draw_SetupFramebuffer(); - - Draw_Unlock(); -} - -void RosalinaMenu_PowerOff(void) // Soft shutdown. -{ - Draw_Lock(); - Draw_ClearFramebuffer(); - Draw_FlushFramebuffer(); - Draw_Unlock(); - - do - { - Draw_Lock(); - Draw_DrawString(10, 10, COLOR_TITLE, "Power off"); - Draw_DrawString(10, 30, COLOR_WHITE, "Press A to power off, press B to go back."); - Draw_FlushFramebuffer(); - Draw_Unlock(); - - u32 pressed = waitInputWithTimeout(1000); - - if(pressed & KEY_A) - { - menuLeave(); - srvPublishToSubscriber(0x203, 0); - return; - } - else if(pressed & KEY_B) - return; - } - while(!menuShouldExit); -} - - #define TRY(expr) if(R_FAILED(res = (expr))) goto end; static s64 timeSpentConvertingScreenshot = 0; diff --git a/sysmodules/rosalina/source/menus/sysconfig.c b/sysmodules/rosalina/source/menus/sysconfig.c index c067ecfc..3baa4f9a 100644 --- a/sysmodules/rosalina/source/menus/sysconfig.c +++ b/sysmodules/rosalina/source/menus/sysconfig.c @@ -32,6 +32,7 @@ #include "fmt.h" #include "utils.h" #include "ifile.h" +#include "luminance.h" Menu sysconfigMenu = { "System configuration menu", @@ -42,6 +43,9 @@ Menu sysconfigMenu = { { "Toggle Wireless", METHOD, .method = &SysConfigMenu_ToggleWireless }, { "Toggle Power Button", METHOD, .method=&SysConfigMenu_TogglePowerButton }, { "Toggle power to card slot", METHOD, .method=&SysConfigMenu_ToggleCardIfPower}, + { "Change screen brightness", METHOD, .method = &SysConfigMenu_ChangeScreenBrightness }, + { "Power off", METHOD, .method = &SysConfigMenu_PowerOff }, + { "Reboot", METHOD, .method = &SysConfigMenu_Reboot }, {}, } }; @@ -488,3 +492,159 @@ void SysConfigMenu_AdjustVolume(void) } } while(!menuShouldExit); } + +void SysConfigMenu_ChangeScreenBrightness(void) +{ + Draw_Lock(); + Draw_ClearFramebuffer(); + Draw_FlushFramebuffer(); + Draw_Unlock(); + + // gsp:LCD GetLuminance is stubbed on O3DS so we have to implement it ourselves... damn it. + // Assume top and bottom screen luminances are the same (should be; if not, we'll set them to the same values). + u32 luminance = getCurrentLuminance(false); + u32 minLum = getMinLuminancePreset(); + u32 maxLum = getMaxLuminancePreset(); + + do + { + Draw_Lock(); + Draw_DrawString(10, 10, COLOR_TITLE, "Screen brightness"); + u32 posY = 30; + posY = Draw_DrawFormattedString( + 10, + posY, + COLOR_WHITE, + "Current luminance: %lu (min. %lu, max. %lu)\n\n", + luminance, + minLum, + maxLum + ); + posY = Draw_DrawString(10, posY, COLOR_WHITE, "Controls: Up/Down for +-1, Right/Left for +-10.\n"); + posY = Draw_DrawString(10, posY, COLOR_WHITE, "Press A to start, B to exit.\n\n"); + + posY = Draw_DrawString(10, posY, COLOR_RED, "WARNING: \n"); + posY = Draw_DrawString(10, posY, COLOR_WHITE, " * value will be limited by the presets.\n"); + posY = Draw_DrawString(10, posY, COLOR_WHITE, " * bottom framebuffer will be restored until\nyou exit."); + Draw_FlushFramebuffer(); + Draw_Unlock(); + + u32 pressed = waitInputWithTimeout(1000); + + if (pressed & KEY_A) + break; + + if (pressed & KEY_B) + return; + } + while (!menuShouldExit); + + Draw_Lock(); + + Draw_RestoreFramebuffer(); + Draw_FreeFramebufferCache(); + + svcKernelSetState(0x10000, 2); // unblock gsp + gspLcdInit(); // assume it doesn't fail. If it does, brightness won't change, anyway. + + // gsp:LCD will normalize the brightness between top/bottom screen, handle PWM, etc. + + s32 lum = (s32)luminance; + + do + { + u32 pressed = waitInputWithTimeout(1000); + if (pressed & DIRECTIONAL_KEYS) + { + if (pressed & KEY_UP) + lum += 1; + else if (pressed & KEY_DOWN) + lum -= 1; + else if (pressed & KEY_RIGHT) + lum += 10; + else if (pressed & KEY_LEFT) + lum -= 10; + + lum = lum < (s32)minLum ? (s32)minLum : lum; + lum = lum > (s32)maxLum ? (s32)maxLum : lum; + + // We need to call gsp here because updating the active duty LUT is a bit tedious (plus, GSP has internal state). + // This is actually SetLuminance: + GSPLCD_SetBrightnessRaw(BIT(GSP_SCREEN_TOP) | BIT(GSP_SCREEN_BOTTOM), lum); + } + + if (pressed & KEY_B) + break; + } + while (!menuShouldExit); + + gspLcdExit(); + svcKernelSetState(0x10000, 2); // block gsp again + + if (R_FAILED(Draw_AllocateFramebufferCache(FB_BOTTOM_SIZE))) + { + // Shouldn't happen + __builtin_trap(); + } + else + Draw_SetupFramebuffer(); + + Draw_Unlock(); +} + +void SysConfigMenu_PowerOff(void) // Soft shutdown. +{ + Draw_Lock(); + Draw_ClearFramebuffer(); + Draw_FlushFramebuffer(); + Draw_Unlock(); + + do + { + Draw_Lock(); + Draw_DrawString(10, 10, COLOR_TITLE, "Power off"); + Draw_DrawString(10, 30, COLOR_WHITE, "Press A to power off, press B to go back."); + Draw_FlushFramebuffer(); + Draw_Unlock(); + + u32 pressed = waitInputWithTimeout(1000); + + if(pressed & KEY_A) + { + menuLeave(); + srvPublishToSubscriber(0x203, 0); + return; + } + else if(pressed & KEY_B) + return; + } + while(!menuShouldExit); +} + +void SysConfigMenu_Reboot(void) +{ + Draw_Lock(); + Draw_ClearFramebuffer(); + Draw_FlushFramebuffer(); + Draw_Unlock(); + + do + { + Draw_Lock(); + Draw_DrawString(10, 10, COLOR_TITLE, "Reboot"); + Draw_DrawString(10, 30, COLOR_WHITE, "Press A to reboot, press B to go back."); + Draw_FlushFramebuffer(); + Draw_Unlock(); + + u32 pressed = waitInputWithTimeout(1000); + + if(pressed & KEY_A) + { + menuLeave(); + APT_HardwareResetAsync(); + return; + } else if(pressed & KEY_B) + return; + } + while(!menuShouldExit); +}