Skip to content

Commit

Permalink
src/config: add misc:watch_symlinks option
Browse files Browse the repository at this point in the history
  • Loading branch information
fufexan committed Jan 29, 2025
1 parent aaa5573 commit 661c842
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/config/ConfigDescriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,12 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{false},
},
SConfigOptionDescription{
.value = "misc:watch_symlinks",
.description = "If true and the config is a symlink, it will be reloaded when the symlink changes, not when the pointed file changes.",
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{false},
},
SConfigOptionDescription{
.value = "misc:enable_swallow",
.description = "Enable window swallowing",
Expand Down
4 changes: 3 additions & 1 deletion src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ CConfigManager::CConfigManager() {
m_pConfig->addConfigValue("misc:animate_manual_resizes", Hyprlang::INT{0});
m_pConfig->addConfigValue("misc:animate_mouse_windowdragging", Hyprlang::INT{0});
m_pConfig->addConfigValue("misc:disable_autoreload", Hyprlang::INT{0});
m_pConfig->addConfigValue("misc:watch_symlinks", Hyprlang::INT{0});
m_pConfig->addConfigValue("misc:enable_swallow", Hyprlang::INT{0});
m_pConfig->addConfigValue("misc:swallow_regex", {STRVAL_EMPTY});
m_pConfig->addConfigValue("misc:swallow_exception_regex", {STRVAL_EMPTY});
Expand Down Expand Up @@ -914,7 +915,8 @@ std::optional<std::string> CConfigManager::resetHLConfig() {

void CConfigManager::updateWatcher() {
static const auto PDISABLEAUTORELOAD = CConfigValue<Hyprlang::INT>("misc:disable_autoreload");
g_pConfigWatcher->setWatchList(*PDISABLEAUTORELOAD ? std::vector<std::string>{} : m_configPaths);
static const auto WATCHSYMLINKS = CConfigValue<Hyprlang::INT>("misc:watch_symlinks");
g_pConfigWatcher->setWatchList(*PDISABLEAUTORELOAD ? std::vector<std::string>{} : m_configPaths, *WATCHSYMLINKS);
}

void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
Expand Down
4 changes: 2 additions & 2 deletions src/config/ConfigWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int CConfigWatcher::getInotifyFD() {
return m_inotifyFd;
}

void CConfigWatcher::setWatchList(const std::vector<std::string>& paths) {
void CConfigWatcher::setWatchList(const std::vector<std::string>& paths, const bool watchSymlinks) {

// we clear all watches first, because whichever fired is now invalid
// or that is at least what it seems to be.
Expand All @@ -46,7 +46,7 @@ void CConfigWatcher::setWatchList(const std::vector<std::string>& paths) {
// add new paths
for (const auto& path : paths) {
m_watches.emplace_back(SInotifyWatch{
.wd = inotify_add_watch(m_inotifyFd, path.c_str(), IN_MODIFY),
.wd = inotify_add_watch(m_inotifyFd, path.c_str(), IN_MODIFY | (watchSymlinks ? IN_DONT_FOLLOW : 0)),
.file = path,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/config/ConfigWatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CConfigWatcher {
};

int getInotifyFD();
void setWatchList(const std::vector<std::string>& paths);
void setWatchList(const std::vector<std::string>& paths, const bool watchSymlinks);
void setOnChange(const std::function<void(const SConfigWatchEvent&)>& fn);
void onInotifyEvent();

Expand All @@ -29,4 +29,4 @@ class CConfigWatcher {
int m_inotifyFd = -1;
};

inline UP<CConfigWatcher> g_pConfigWatcher = makeUnique<CConfigWatcher>();
inline UP<CConfigWatcher> g_pConfigWatcher = makeUnique<CConfigWatcher>();
2 changes: 1 addition & 1 deletion src/debug/HyprCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ static std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in)
}
}

if (COMMAND.contains("misc:disable_autoreload"))
if (COMMAND.contains("misc:disable_autoreload") || COMMAND.contains("misc:watch_symlinks"))
g_pConfigManager->updateWatcher();

// decorations will probably need a repaint
Expand Down

0 comments on commit 661c842

Please sign in to comment.