diff options
| author | nyx <nnyyxxxx@protonmail.com> | 2025-03-07 20:12:02 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-08 02:12:02 +0100 |
| commit | b80b64cd6c913f8c8ac820a1e4ca615a62ff958f (patch) | |
| tree | e6a6eda202efc6e5995245b3d6b8d0fa2650f7ca /src/config | |
| parent | 4082e876d522dc6ed7118d62cdaa729f84c1b755 (diff) | |
windowrules: add option to allow size persistence between app launches (#9422)
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/ConfigManager.cpp | 15 | ||||
| -rw-r--r-- | src/config/ConfigManager.hpp | 52 |
2 files changed, 54 insertions, 13 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 12b43b37..f0383d50 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -2954,3 +2954,18 @@ std::string SConfigOptionDescription::jsonify() const { void CConfigManager::ensurePersistentWorkspacesPresent() { g_pCompositor->ensurePersistentWorkspacesPresent(m_vWorkspaceRules); } + +void CConfigManager::storeFloatingSize(PHLWINDOW window, const Vector2D& size) { + Debug::log(LOG, "storing floating size {}x{} for window {}::{}", size.x, size.y, window->m_szClass, window->m_szTitle); + SFloatCache id{window}; + m_mStoredFloatingSizes[id] = size; +} + +std::optional<Vector2D> CConfigManager::getStoredFloatingSize(PHLWINDOW window) { + SFloatCache id{window}; + if (m_mStoredFloatingSizes.contains(id)) { + Debug::log(LOG, "got stored size {}x{} for window {}::{}", m_mStoredFloatingSizes[id].x, m_mStoredFloatingSizes[id].y, window->m_szClass, window->m_szTitle); + return m_mStoredFloatingSizes[id]; + } + return std::nullopt; +} diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index d9ea413e..7ce378b1 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -138,6 +138,27 @@ struct SFirstExecRequest { bool withRules = false; }; +struct SFloatCache { + size_t hash; + + SFloatCache(PHLWINDOW window) { + hash = std::hash<std::string>{}(window->m_szClass) ^ (std::hash<std::string>{}(window->m_szTitle) << 1); + } + + bool operator==(const SFloatCache& other) const { + return hash == other.hash; + } +}; + +namespace std { + template <> + struct hash<SFloatCache> { + size_t operator()(const SFloatCache& id) const { + return id.hash; + } + }; +} + class CConfigManager { public: CConfigManager(); @@ -232,6 +253,9 @@ class CConfigManager { bool isLaunchingExecOnce = false; // For exec-once to skip initial ws tracking bool m_bLastConfigVerificationWasSuccessful = true; + void storeFloatingSize(PHLWINDOW window, const Vector2D& size); + std::optional<Vector2D> getStoredFloatingSize(PHLWINDOW window); + private: UP<Hyprlang::CConfig> m_pConfig; @@ -267,19 +291,21 @@ class CConfigManager { uint32_t m_configValueNumber = 0; // internal methods - void updateBlurredLS(const std::string&, const bool); - void setDefaultAnimationVars(); - std::optional<std::string> resetHLConfig(); - std::optional<std::string> generateConfig(std::string configPath); - std::optional<std::string> verifyConfigExists(); - void postConfigReload(const Hyprlang::CParseResult& result); - SWorkspaceRule mergeWorkspaceRules(const SWorkspaceRule&, const SWorkspaceRule&); - - void registerConfigVar(const char* name, const Hyprlang::INT& val); - void registerConfigVar(const char* name, const Hyprlang::FLOAT& val); - void registerConfigVar(const char* name, const Hyprlang::VEC2& val); - void registerConfigVar(const char* name, const Hyprlang::STRING& val); - void registerConfigVar(const char* name, Hyprlang::CUSTOMTYPE&& val); + void updateBlurredLS(const std::string&, const bool); + void setDefaultAnimationVars(); + std::optional<std::string> resetHLConfig(); + std::optional<std::string> generateConfig(std::string configPath); + std::optional<std::string> verifyConfigExists(); + void postConfigReload(const Hyprlang::CParseResult& result); + SWorkspaceRule mergeWorkspaceRules(const SWorkspaceRule&, const SWorkspaceRule&); + + void registerConfigVar(const char* name, const Hyprlang::INT& val); + void registerConfigVar(const char* name, const Hyprlang::FLOAT& val); + void registerConfigVar(const char* name, const Hyprlang::VEC2& val); + void registerConfigVar(const char* name, const Hyprlang::STRING& val); + void registerConfigVar(const char* name, Hyprlang::CUSTOMTYPE&& val); + + std::unordered_map<SFloatCache, Vector2D> m_mStoredFloatingSizes; friend struct SConfigOptionDescription; }; |
