start: init start-hyprland and safe mode (#12484)

This commit is contained in:
Vaxry 2025-12-05 15:40:03 +00:00 committed by GitHub
parent ec6756f961
commit 016eb7a23d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 550 additions and 28 deletions

View file

@ -1321,6 +1321,12 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{false},
},
SConfigOptionDescription{
.value = "misc:disable_watchdog_warning",
.description = "whether to disable the warning about not using start-hyprland.",
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{false},
},
SConfigOptionDescription{
.value = "misc:lockdead_screen_delay",
.description = "the delay in ms after the lockdead screen appears if the lock screen did not appear after a lock event occurred.",

View file

@ -498,6 +498,7 @@ CConfigManager::CConfigManager() {
registerConfigVar("misc:render_unfocused_fps", Hyprlang::INT{15});
registerConfigVar("misc:disable_xdg_env_checks", Hyprlang::INT{0});
registerConfigVar("misc:disable_hyprland_guiutils_check", Hyprlang::INT{0});
registerConfigVar("misc:disable_watchdog_warning", Hyprlang::INT{0});
registerConfigVar("misc:lockdead_screen_delay", Hyprlang::INT{1000});
registerConfigVar("misc:enable_anr_dialog", Hyprlang::INT{1});
registerConfigVar("misc:anr_missed_pings", Hyprlang::INT{5});
@ -914,7 +915,7 @@ void CConfigManager::reloadRuleConfigs() {
}
}
std::optional<std::string> CConfigManager::generateConfig(std::string configPath) {
std::optional<std::string> CConfigManager::generateConfig(std::string configPath, bool safeMode) {
std::string parentPath = std::filesystem::path(configPath).parent_path();
if (!parentPath.empty()) {
@ -931,7 +932,14 @@ std::optional<std::string> CConfigManager::generateConfig(std::string configPath
Debug::log(WARN, "No config file found; attempting to generate.");
std::ofstream ofs;
ofs.open(configPath, std::ios::trunc);
ofs << AUTOGENERATED_PREFIX << EXAMPLE_CONFIG;
if (!safeMode) {
ofs << AUTOGENERATED_PREFIX;
ofs << EXAMPLE_CONFIG;
} else {
std::string n = std::string{EXAMPLE_CONFIG};
replaceInString(n, "\n$menu = hyprlauncher\n", "\n$menu = hyprland-run\n");
ofs << n;
}
ofs.close();
if (ofs.fail())
@ -941,7 +949,16 @@ std::optional<std::string> CConfigManager::generateConfig(std::string configPath
}
std::string CConfigManager::getMainConfigPath() {
static std::string CONFIG_PATH = [this]() -> std::string {
static bool lastSafeMode = g_pCompositor->m_safeMode;
static auto getCfgPath = [this]() -> std::string {
lastSafeMode = g_pCompositor->m_safeMode;
m_firstExecDispatched = false;
if (g_pCompositor->m_safeMode) {
const auto CONFIGPATH = g_pCompositor->m_instancePath + "/recoverycfg.conf";
return generateConfig(CONFIGPATH, false).value();
}
if (!g_pCompositor->m_explicitConfigPath.empty())
return g_pCompositor->m_explicitConfigPath;
@ -956,7 +973,13 @@ std::string CConfigManager::getMainConfigPath() {
return generateConfig(CONFIGPATH).value();
} else
throw std::runtime_error("Neither HOME nor XDG_CONFIG_HOME are set in the environment. Could not find config in XDG_CONFIG_DIRS or /etc/xdg.");
}();
};
static std::string CONFIG_PATH = getCfgPath();
if (lastSafeMode != g_pCompositor->m_safeMode) {
CONFIG_PATH = getCfgPath();
m_config->changeRootPath(CONFIG_PATH.c_str());
}
return CONFIG_PATH;
}
@ -1415,7 +1438,6 @@ void CConfigManager::init() {
reload();
});
const std::string CONFIGPATH = getMainConfigPath();
reload();
m_isFirstLaunch = false;
@ -1637,7 +1659,12 @@ void CConfigManager::dispatchExecOnce() {
g_pInputManager->setTabletConfigs();
// check for user's possible errors with their setup and notify them if needed
g_pCompositor->performUserChecks();
// this is additionally guarded because exiting safe mode will re-run this.
static bool once = true;
if (once) {
g_pCompositor->performUserChecks();
once = false;
}
}
void CConfigManager::dispatchExecShutdown() {

View file

@ -317,7 +317,7 @@ class CConfigManager {
// internal methods
void setDefaultAnimationVars();
std::optional<std::string> resetHLConfig();
std::optional<std::string> generateConfig(std::string configPath);
std::optional<std::string> generateConfig(std::string configPath, bool safeMode = false);
std::optional<std::string> verifyConfigExists();
void reloadRuleConfigs();