-
-
Notifications
You must be signed in to change notification settings - Fork 35
Add config #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add config #41
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9fcd7ef
add schedule logic
salfel f5de593
added configmanager
salfel 52f97fd
automatically apply the appropriate profile
salfel c1bb790
fix imports
salfel 9fe24de
add some logging
salfel c20c75e
adding identity config option
salfel eae06c8
add some error handling for time parsing
salfel a9677de
override profile when args are passed via the cli
salfel e74fe22
add max-gamma config option
salfel a06193e
minor fixes
salfel b46789b
remove error on missing config
salfel 512cc1d
make schedule thread safe
salfel 9ce504b
fix error in profile selection
salfel 3bdd78d
fix unsafe thread
salfel 1bb9fe0
remove braces
salfel 21bd3f5
fix: current profile not applying
salfel 9fec5b8
add link to hyprsunset wiki
salfel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #include "ConfigManager.hpp" | ||
| #include <cstdlib> | ||
| #include <hyprlang.hpp> | ||
| #include <hyprutils/path/Path.hpp> | ||
| #include <string> | ||
| #include <sys/ucontext.h> | ||
| #include "helpers/Log.hpp" | ||
|
|
||
| static std::string getMainConfigPath() { | ||
| static const auto paths = Hyprutils::Path::findConfig("hyprsunset"); | ||
| if (paths.first.has_value()) | ||
| return paths.first.value(); | ||
| else | ||
| throw std::runtime_error("Could not find config in HOME, XDG_CONFIG_HOME, XDG_CONFIG_DIRS or /etc/hypr."); | ||
| } | ||
|
|
||
| CConfigManager::CConfigManager(std::string configPath) : | ||
| m_config(configPath.empty() ? getMainConfigPath().c_str() : configPath.c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = configPath.empty()}) { | ||
| currentConfigPath = configPath.empty() ? getMainConfigPath() : configPath; | ||
| } | ||
|
|
||
| void CConfigManager::init() { | ||
| m_config.addConfigValue("max-gamma", Hyprlang::INT{100}); | ||
|
|
||
| m_config.addSpecialCategory("profile", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true}); | ||
| m_config.addSpecialConfigValue("profile", "time", Hyprlang::STRING{"00:00"}); | ||
| m_config.addSpecialConfigValue("profile", "temperature", Hyprlang::INT{6500}); | ||
| m_config.addSpecialConfigValue("profile", "gamma", Hyprlang::FLOAT{1.0f}); | ||
| m_config.addSpecialConfigValue("profile", "identity", Hyprlang::INT{0}); | ||
|
|
||
| m_config.commence(); | ||
|
|
||
| auto result = m_config.parse(); | ||
|
|
||
| if (result.error) | ||
| Debug::log(ERR, "Config has errors:\n{}\nProceeding ignoring faulty entries", result.getError()); | ||
| } | ||
|
|
||
| std::vector<SSunsetProfile> CConfigManager::getSunsetProfiles() { | ||
| std::vector<SSunsetProfile> result; | ||
|
|
||
| auto keys = m_config.listKeysForSpecialCategory("profile"); | ||
| result.reserve(keys.size()); | ||
|
|
||
| for (auto& key : keys) { | ||
| std::string time; | ||
| unsigned long temperature; | ||
| float gamma; | ||
| bool identity; | ||
|
|
||
| try { | ||
| time = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("profile", "time", key.c_str())); | ||
| temperature = std::any_cast<Hyprlang::INT>(m_config.getSpecialConfigValue("profile", "temperature", key.c_str())); | ||
| gamma = std::any_cast<Hyprlang::FLOAT>(m_config.getSpecialConfigValue("profile", "gamma", key.c_str())); | ||
| identity = std::any_cast<Hyprlang::INT>(m_config.getSpecialConfigValue("profile", "identity", key.c_str())); | ||
| } catch (const std::bad_any_cast& e) { | ||
| RASSERT(false, "Failed to construct Profile: {}", e.what()); // | ||
| } catch (const std::out_of_range& e) { | ||
| RASSERT(false, "Missing property for Profile: {}", e.what()); // | ||
| } | ||
|
|
||
| int separator = time.find_first_of(':'); | ||
salfel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (separator == -1) { | ||
salfel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| RASSERT(false, "Invalid time format for profile {}", key); | ||
| } | ||
|
|
||
| int hour, minute; | ||
salfel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| hour = std::stoi(time.substr(0, separator)); | ||
| minute = std::stoi(time.substr(separator + 1).c_str()); | ||
| } catch (const std::exception& e) { | ||
| Debug::log(ERR, "Invalid time format: {}, skipping this profile", time); | ||
| continue; | ||
| } | ||
|
|
||
| // clang-format off | ||
| result.push_back(SSunsetProfile{ | ||
| .time = { | ||
| .hour = std::chrono::hours(hour), | ||
| .minute = std::chrono::minutes(minute), | ||
| }, | ||
| .temperature = temperature, | ||
| .gamma = gamma, | ||
| .identity = identity, | ||
| }); | ||
| // clang-format on | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| float CConfigManager::getMaxGamma() { | ||
| try { | ||
| return std::any_cast<Hyprlang::INT>(m_config.getConfigValue("max-gamma")) / 100.f; | ||
| } catch (const std::bad_any_cast& e) { | ||
| RASSERT(false, "Failed to construct max-gamma: {}", e.what()); // | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #pragma once | ||
|
|
||
| #include "Hyprsunset.hpp" | ||
| #include <hyprlang.hpp> | ||
| #include <vector> | ||
|
|
||
| class CConfigManager { | ||
| public: | ||
| CConfigManager(std::string configPath); | ||
|
|
||
| std::vector<SSunsetProfile> getSunsetProfiles(); | ||
| float getMaxGamma(); | ||
|
|
||
| void init(); | ||
|
|
||
| private: | ||
| Hyprlang::CConfig m_config; | ||
|
|
||
| std::string currentConfigPath; | ||
| }; | ||
|
|
||
| inline UP<CConfigManager> g_pConfigManager; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.