mirror of
https://github.com/hyprwm/Hyprland
synced 2025-02-17 09:42:09 +01:00
src/config/ConfigWatcher.cpp: watch both symlinks and canonical paths
This commit is contained in:
parent
1e8102b82e
commit
784779eb3b
5 changed files with 10 additions and 13 deletions
|
@ -1040,12 +1040,6 @@ 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",
|
||||
|
|
|
@ -411,7 +411,6 @@ 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});
|
||||
|
@ -915,8 +914,7 @@ std::optional<std::string> CConfigManager::resetHLConfig() {
|
|||
|
||||
void CConfigManager::updateWatcher() {
|
||||
static const auto PDISABLEAUTORELOAD = CConfigValue<Hyprlang::INT>("misc:disable_autoreload");
|
||||
static const auto WATCHSYMLINKS = CConfigValue<Hyprlang::INT>("misc:watch_symlinks");
|
||||
g_pConfigWatcher->setWatchList(*PDISABLEAUTORELOAD ? std::vector<std::string>{} : m_configPaths, *WATCHSYMLINKS);
|
||||
g_pConfigWatcher->setWatchList(*PDISABLEAUTORELOAD ? std::vector<std::string>{} : m_configPaths);
|
||||
}
|
||||
|
||||
void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <ranges>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <filesystem>
|
||||
|
||||
CConfigWatcher::CConfigWatcher() : m_inotifyFd(inotify_init()) {
|
||||
if (m_inotifyFd < 0) {
|
||||
|
@ -29,7 +30,7 @@ int CConfigWatcher::getInotifyFD() {
|
|||
return m_inotifyFd;
|
||||
}
|
||||
|
||||
void CConfigWatcher::setWatchList(const std::vector<std::string>& paths, const bool watchSymlinks) {
|
||||
void CConfigWatcher::setWatchList(const std::vector<std::string>& paths) {
|
||||
|
||||
// we clear all watches first, because whichever fired is now invalid
|
||||
// or that is at least what it seems to be.
|
||||
|
@ -46,7 +47,11 @@ void CConfigWatcher::setWatchList(const std::vector<std::string>& paths, const b
|
|||
// add new paths
|
||||
for (const auto& path : paths) {
|
||||
m_watches.emplace_back(SInotifyWatch{
|
||||
.wd = inotify_add_watch(m_inotifyFd, path.c_str(), IN_MODIFY | (watchSymlinks ? IN_DONT_FOLLOW : 0)),
|
||||
.wd = inotify_add_watch(m_inotifyFd, path.c_str(), IN_MODIFY | IN_DONT_FOLLOW),
|
||||
.file = path,
|
||||
});
|
||||
m_watches.emplace_back(SInotifyWatch{
|
||||
.wd = inotify_add_watch(m_inotifyFd, (std::filesystem::canonical(path)).c_str(), IN_MODIFY),
|
||||
.file = path,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class CConfigWatcher {
|
|||
};
|
||||
|
||||
int getInotifyFD();
|
||||
void setWatchList(const std::vector<std::string>& paths, const bool watchSymlinks);
|
||||
void setWatchList(const std::vector<std::string>& paths);
|
||||
void setOnChange(const std::function<void(const SConfigWatchEvent&)>& fn);
|
||||
void onInotifyEvent();
|
||||
|
||||
|
|
|
@ -1100,7 +1100,7 @@ static std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in)
|
|||
}
|
||||
}
|
||||
|
||||
if (COMMAND.contains("misc:disable_autoreload") || COMMAND.contains("misc:watch_symlinks"))
|
||||
if (COMMAND.contains("misc:disable_autoreload"))
|
||||
g_pConfigManager->updateWatcher();
|
||||
|
||||
// decorations will probably need a repaint
|
||||
|
|
Loading…
Add table
Reference in a new issue