2022-03-17 15:53:45 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
#include <hyprutils/animation/AnimationConfig.hpp>
|
2022-04-23 14:16:02 +02:00
|
|
|
#define CONFIG_MANAGER_H
|
|
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
#include <map>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include "../defines.hpp"
|
2024-08-19 12:46:36 +00:00
|
|
|
#include <variant>
|
2022-03-17 15:53:45 +01:00
|
|
|
#include <vector>
|
2023-05-01 23:28:27 +02:00
|
|
|
#include <optional>
|
2023-10-29 16:59:50 +00:00
|
|
|
#include <functional>
|
2023-05-09 15:01:45 +02:00
|
|
|
#include <xf86drmMode.h>
|
2023-08-11 17:37:52 +02:00
|
|
|
#include "../helpers/Monitor.hpp"
|
2024-04-11 02:12:29 +01:00
|
|
|
#include "../desktop/Window.hpp"
|
2025-01-17 15:21:35 +00:00
|
|
|
#include "../desktop/LayerRule.hpp"
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2022-11-26 17:56:43 +00:00
|
|
|
#include "ConfigDataValues.hpp"
|
2025-01-17 19:14:55 +01:00
|
|
|
#include "../SharedDefs.hpp"
|
|
|
|
|
#include "../helpers/Color.hpp"
|
|
|
|
|
#include "../desktop/DesktopTypes.hpp"
|
|
|
|
|
#include "../helpers/memory/Memory.hpp"
|
|
|
|
|
#include "../desktop/WindowRule.hpp"
|
|
|
|
|
#include "../managers/XWaylandManager.hpp"
|
2022-04-08 22:07:40 +02:00
|
|
|
|
2024-02-18 15:00:34 +00:00
|
|
|
#include <hyprlang.hpp>
|
|
|
|
|
|
2023-02-27 12:32:38 +00:00
|
|
|
#define HANDLE void*
|
|
|
|
|
|
2023-05-01 23:28:27 +02:00
|
|
|
struct SWorkspaceRule {
|
2023-12-11 22:58:40 +00:00
|
|
|
std::string monitor = "";
|
|
|
|
|
std::string workspaceString = "";
|
|
|
|
|
std::string workspaceName = "";
|
2024-08-08 21:01:50 +02:00
|
|
|
WORKSPACEID workspaceId = -1;
|
2023-12-11 22:58:40 +00:00
|
|
|
bool isDefault = false;
|
|
|
|
|
bool isPersistent = false;
|
2024-02-21 12:07:39 +01:00
|
|
|
std::optional<CCssGapData> gapsIn;
|
|
|
|
|
std::optional<CCssGapData> gapsOut;
|
2023-12-11 22:58:40 +00:00
|
|
|
std::optional<int64_t> borderSize;
|
2024-07-11 14:10:42 +00:00
|
|
|
std::optional<bool> decorate;
|
|
|
|
|
std::optional<bool> noRounding;
|
|
|
|
|
std::optional<bool> noBorder;
|
|
|
|
|
std::optional<bool> noShadow;
|
2023-12-11 22:58:40 +00:00
|
|
|
std::optional<std::string> onCreatedEmptyRunCmd;
|
2024-02-27 22:44:42 +00:00
|
|
|
std::optional<std::string> defaultName;
|
2023-12-11 22:58:40 +00:00
|
|
|
std::map<std::string, std::string> layoutopts;
|
2023-05-01 23:28:27 +02:00
|
|
|
};
|
|
|
|
|
|
2022-04-27 17:46:07 +02:00
|
|
|
struct SMonitorAdditionalReservedArea {
|
2022-12-16 17:17:31 +00:00
|
|
|
int top = 0;
|
|
|
|
|
int bottom = 0;
|
|
|
|
|
int left = 0;
|
|
|
|
|
int right = 0;
|
2022-04-27 17:46:07 +02:00
|
|
|
};
|
|
|
|
|
|
2023-10-29 16:59:50 +00:00
|
|
|
struct SPluginKeyword {
|
2024-12-07 18:51:18 +01:00
|
|
|
HANDLE handle = nullptr;
|
2024-02-18 15:00:34 +00:00
|
|
|
std::string name = "";
|
|
|
|
|
Hyprlang::PCONFIGHANDLERFUNC fn = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SPluginVariable {
|
2024-12-07 18:51:18 +01:00
|
|
|
HANDLE handle = nullptr;
|
2024-02-18 15:00:34 +00:00
|
|
|
std::string name = "";
|
2023-10-29 16:59:50 +00:00
|
|
|
};
|
|
|
|
|
|
2022-11-10 13:39:23 +00:00
|
|
|
struct SExecRequestedRule {
|
2022-12-16 17:17:31 +00:00
|
|
|
std::string szRule = "";
|
|
|
|
|
uint64_t iPid = 0;
|
2022-11-10 13:39:23 +00:00
|
|
|
};
|
|
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
enum eConfigOptionType : uint8_t {
|
2024-08-17 17:33:16 +01:00
|
|
|
CONFIG_OPTION_BOOL = 0,
|
|
|
|
|
CONFIG_OPTION_INT = 1, /* e.g. 0/1/2*/
|
|
|
|
|
CONFIG_OPTION_FLOAT = 2,
|
|
|
|
|
CONFIG_OPTION_STRING_SHORT = 3, /* e.g. "auto" */
|
|
|
|
|
CONFIG_OPTION_STRING_LONG = 4, /* e.g. a command */
|
|
|
|
|
CONFIG_OPTION_COLOR = 5,
|
|
|
|
|
CONFIG_OPTION_CHOICE = 6, /* e.g. "one", "two", "three" */
|
|
|
|
|
CONFIG_OPTION_GRADIENT = 7,
|
|
|
|
|
CONFIG_OPTION_VECTOR = 8,
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
enum eConfigOptionFlags : uint8_t {
|
2024-08-17 17:33:16 +01:00
|
|
|
CONFIG_OPTION_FLAG_PERCENTAGE = (1 << 0),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SConfigOptionDescription {
|
|
|
|
|
|
|
|
|
|
struct SBoolData {
|
|
|
|
|
bool value = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SRangeData {
|
|
|
|
|
int value = 0, min = 0, max = 2;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SFloatData {
|
|
|
|
|
float value = 0, min = 0, max = 100;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SStringData {
|
|
|
|
|
std::string value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SColorData {
|
2024-12-03 18:58:24 +00:00
|
|
|
CHyprColor color;
|
2024-08-17 17:33:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SChoiceData {
|
|
|
|
|
int firstIndex = 0;
|
|
|
|
|
std::string choices; // comma-separated
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SGradientData {
|
|
|
|
|
std::string gradient;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SVectorData {
|
|
|
|
|
Vector2D vec, min, max;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::string value; // e.g. general:gaps_in
|
|
|
|
|
std::string description;
|
|
|
|
|
std::string specialCategory; // if value is special (e.g. device:abc) value will be abc and special device
|
|
|
|
|
bool specialKey = false;
|
|
|
|
|
eConfigOptionType type = CONFIG_OPTION_BOOL;
|
|
|
|
|
uint32_t flags = 0; // eConfigOptionFlags
|
|
|
|
|
|
|
|
|
|
std::string jsonify() const;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
std::variant<SBoolData, SRangeData, SFloatData, SStringData, SColorData, SChoiceData, SGradientData, SVectorData> data;
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-11 23:58:05 +08:00
|
|
|
struct SFirstExecRequest {
|
|
|
|
|
std::string exec = "";
|
|
|
|
|
bool withRules = false;
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-07 20:12:02 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
class CConfigManager {
|
2022-12-16 17:17:31 +00:00
|
|
|
public:
|
2022-03-17 15:53:45 +01:00
|
|
|
CConfigManager();
|
|
|
|
|
|
2022-12-16 17:17:31 +00:00
|
|
|
void init();
|
2025-01-19 15:39:19 +01:00
|
|
|
void reload();
|
2025-01-24 20:30:12 +00:00
|
|
|
std::string verify();
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2023-09-06 16:14:18 +02:00
|
|
|
int getDeviceInt(const std::string&, const std::string&, const std::string& fallback = "");
|
|
|
|
|
float getDeviceFloat(const std::string&, const std::string&, const std::string& fallback = "");
|
2023-09-28 02:49:30 +08:00
|
|
|
Vector2D getDeviceVec(const std::string&, const std::string&, const std::string& fallback = "");
|
2023-09-06 16:14:18 +02:00
|
|
|
std::string getDeviceString(const std::string&, const std::string&, const std::string& fallback = "");
|
2022-12-16 17:17:31 +00:00
|
|
|
bool deviceConfigExists(const std::string&);
|
2024-02-18 15:00:34 +00:00
|
|
|
Hyprlang::CConfigValue* getConfigValueSafeDevice(const std::string& dev, const std::string& val, const std::string& fallback);
|
2022-12-16 17:17:31 +00:00
|
|
|
bool shouldBlurLS(const std::string&);
|
2022-06-30 21:26:00 +02:00
|
|
|
|
2024-02-18 15:00:34 +00:00
|
|
|
void* const* getConfigValuePtr(const std::string&);
|
|
|
|
|
Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string& name, const std::string& specialCat = "");
|
2025-01-02 18:29:10 +01:00
|
|
|
std::string getMainConfigPath();
|
2024-12-16 19:05:24 +01:00
|
|
|
std::string getConfigString();
|
2022-04-23 14:16:02 +02:00
|
|
|
|
2024-10-26 02:06:13 +01:00
|
|
|
SMonitorRule getMonitorRuleFor(const PHLMONITOR);
|
2024-04-05 08:54:30 -07:00
|
|
|
SWorkspaceRule getWorkspaceRuleFor(PHLWORKSPACE workspace);
|
2023-03-18 16:12:43 +00:00
|
|
|
std::string getDefaultWorkspaceFor(const std::string&);
|
2022-03-17 16:56:33 +01:00
|
|
|
|
2024-10-19 23:03:29 +01:00
|
|
|
PHLMONITOR getBoundMonitorForWS(const std::string&);
|
2022-12-16 17:17:31 +00:00
|
|
|
std::string getBoundMonitorStringForWS(const std::string&);
|
2024-12-16 15:58:19 +00:00
|
|
|
const std::vector<SWorkspaceRule>& getAllWorkspaceRules();
|
2022-09-12 21:05:52 +02:00
|
|
|
|
2024-12-16 19:05:24 +01:00
|
|
|
std::vector<SP<CWindowRule>> getMatchingRules(PHLWINDOW, bool dynamic = true, bool shadowExec = false);
|
|
|
|
|
std::vector<SP<CLayerRule>> getMatchingRules(PHLLS);
|
2025-01-26 14:40:42 +00:00
|
|
|
void ensurePersistentWorkspacesPresent();
|
2022-03-24 18:22:01 +01:00
|
|
|
|
2024-08-17 17:33:16 +01:00
|
|
|
const std::vector<SConfigOptionDescription>& getAllDescriptions();
|
|
|
|
|
|
2022-04-27 17:46:07 +02:00
|
|
|
std::unordered_map<std::string, SMonitorAdditionalReservedArea> m_mAdditionalReservedAreas;
|
|
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
const std::unordered_map<std::string, SP<Hyprutils::Animation::SAnimationPropertyConfig>>& getAnimationConfig();
|
2023-01-25 15:16:28 +00:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
void addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value);
|
2024-02-18 15:00:34 +00:00
|
|
|
void addPluginKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fun, Hyprlang::SHandlerOptions opts = {});
|
2023-10-29 16:59:50 +00:00
|
|
|
void removePluginConfig(HANDLE handle);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
2022-04-12 20:02:57 +02:00
|
|
|
// no-op when done.
|
2025-01-07 17:55:14 +00:00
|
|
|
void dispatchExecOnce();
|
|
|
|
|
void dispatchExecShutdown();
|
2022-04-12 20:02:57 +02:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
void performMonitorReload();
|
|
|
|
|
void ensureMonitorStatus();
|
|
|
|
|
void ensureVRR(PHLMONITOR pMonitor = nullptr);
|
2022-04-19 19:01:23 +02:00
|
|
|
|
2025-02-15 00:21:50 +00:00
|
|
|
bool shouldUseSoftwareCursors(PHLMONITOR pMonitor);
|
2025-01-29 10:50:39 +00:00
|
|
|
void updateWatcher();
|
2024-10-26 02:12:43 +01:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
std::string parseKeyword(const std::string&, const std::string&);
|
2022-04-21 16:56:27 +02:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
void addParseError(const std::string&);
|
2022-08-09 18:13:13 +02:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
SP<Hyprutils::Animation::SAnimationPropertyConfig> getAnimationPropertyConfig(const std::string&);
|
2022-07-28 13:28:43 +02:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
void addExecRule(const SExecRequestedRule&);
|
2022-11-10 13:39:23 +00:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
void handlePluginLoads();
|
|
|
|
|
std::string getErrors();
|
2023-05-01 07:10:53 -07:00
|
|
|
|
2024-02-18 15:00:34 +00:00
|
|
|
// keywords
|
2025-03-02 02:13:31 +00:00
|
|
|
std::optional<std::string> handleRawExec(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleExec(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleExecOnce(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleExecRawOnce(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleExecShutdown(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleMonitor(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleBind(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleUnbind(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleWindowRule(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleLayerRule(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleWorkspaceRules(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleBezier(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleAnimation(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleSource(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleSubmap(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleBlurLS(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleBindWS(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handleEnv(const std::string&, const std::string&);
|
|
|
|
|
std::optional<std::string> handlePlugin(const std::string&, const std::string&);
|
|
|
|
|
|
|
|
|
|
std::string configCurrentPath;
|
|
|
|
|
|
|
|
|
|
bool m_bWantsMonitorReload = false;
|
|
|
|
|
bool m_bNoMonitorReload = false;
|
|
|
|
|
bool isLaunchingExecOnce = false; // For exec-once to skip initial ws tracking
|
|
|
|
|
bool m_bLastConfigVerificationWasSuccessful = true;
|
2024-07-25 15:29:39 +02:00
|
|
|
|
2025-03-07 20:12:02 -05:00
|
|
|
void storeFloatingSize(PHLWINDOW window, const Vector2D& size);
|
|
|
|
|
std::optional<Vector2D> getStoredFloatingSize(PHLWINDOW window);
|
|
|
|
|
|
2022-12-16 17:17:31 +00:00
|
|
|
private:
|
2025-01-23 21:55:41 +01:00
|
|
|
UP<Hyprlang::CConfig> m_pConfig;
|
2022-07-28 13:28:43 +02:00
|
|
|
|
2025-01-19 15:39:19 +01:00
|
|
|
std::vector<std::string> m_configPaths;
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
Hyprutils::Animation::CAnimationConfigTree m_AnimationTree;
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
std::string m_szCurrentSubmap = ""; // For storing the current keybind submap
|
2022-09-12 21:05:52 +02:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
std::vector<SExecRequestedRule> execRequestedRules; // rules requested with exec, e.g. [workspace 2] kitty
|
2022-11-10 13:39:23 +00:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
std::vector<std::string> m_vDeclaredPlugins;
|
|
|
|
|
std::vector<SPluginKeyword> pluginKeywords;
|
|
|
|
|
std::vector<SPluginVariable> pluginVariables;
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
bool isFirstLaunch = true; // For exec-once
|
2022-03-17 16:56:33 +01:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
std::vector<SMonitorRule> m_vMonitorRules;
|
|
|
|
|
std::vector<SWorkspaceRule> m_vWorkspaceRules;
|
|
|
|
|
std::vector<SP<CWindowRule>> m_vWindowRules;
|
|
|
|
|
std::vector<SP<CLayerRule>> m_vLayerRules;
|
|
|
|
|
std::vector<std::string> m_dBlurLSNamespaces;
|
2022-04-12 20:02:57 +02:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
bool firstExecDispatched = false;
|
|
|
|
|
bool m_bManualCrashInitiated = false;
|
2025-01-11 23:58:05 +08:00
|
|
|
|
|
|
|
|
std::vector<SFirstExecRequest> firstExecRequests; // bool is for if with rules
|
2025-01-07 17:55:14 +00:00
|
|
|
std::vector<std::string> finalExecRequests;
|
2023-03-05 14:54:26 +00:00
|
|
|
|
2025-01-07 17:55:14 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> m_vFailedPluginConfigValues; // for plugin values of unloaded plugins
|
|
|
|
|
std::string m_szConfigErrors = "";
|
2023-07-10 14:13:23 +02:00
|
|
|
|
2025-02-25 13:49:07 +00:00
|
|
|
uint32_t m_configValueNumber = 0;
|
|
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
// internal methods
|
2025-03-07 20:12:02 -05:00
|
|
|
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;
|
2025-02-25 13:49:07 +00:00
|
|
|
|
|
|
|
|
friend struct SConfigOptionDescription;
|
2022-03-17 15:53:45 +01:00
|
|
|
};
|
|
|
|
|
|
2025-01-23 21:55:41 +01:00
|
|
|
inline UP<CConfigManager> g_pConfigManager;
|