Hyprland/src/config/ConfigManager.hpp

93 lines
2.8 KiB
C++
Raw Normal View History

2022-03-17 15:53:45 +01:00
#pragma once
#include <map>
#include "../debug/Log.hpp"
#include <unordered_map>
#include "../defines.hpp"
#include <vector>
2022-03-17 16:56:33 +01:00
#include <deque>
2022-03-24 18:22:01 +01:00
#include <algorithm>
#include <regex>
#include "../Window.hpp"
2022-03-17 15:53:45 +01:00
#include "defaultConfig.hpp"
2022-03-17 15:53:45 +01:00
struct SConfigValue {
int64_t intValue = -1;
float floatValue = -1;
std::string strValue = "";
};
2022-03-17 16:56:33 +01:00
struct SMonitorRule {
std::string name = "";
Vector2D resolution = Vector2D(1280,720);
Vector2D offset = Vector2D(0,0);
float scale = 1;
2022-03-19 21:46:29 +01:00
float refreshRate = 60;
2022-03-20 16:01:47 +01:00
int defaultWorkspaceID = -1;
2022-04-17 10:19:46 +02:00
bool disabled = false;
2022-03-17 16:56:33 +01:00
};
2022-03-24 18:22:01 +01:00
struct SWindowRule {
std::string szRule;
std::string szValue;
};
2022-03-17 15:53:45 +01:00
class CConfigManager {
public:
CConfigManager();
void tick();
2022-03-17 17:08:54 +01:00
void init();
2022-03-17 15:53:45 +01:00
int getInt(std::string);
float getFloat(std::string);
std::string getString(std::string);
void setFloat(std::string, float);
void setInt(std::string, int);
void setString(std::string, std::string);
2022-03-17 15:53:45 +01:00
2022-03-17 16:56:33 +01:00
SMonitorRule getMonitorRuleFor(std::string);
2022-03-24 18:22:01 +01:00
std::vector<SWindowRule> getMatchingRules(CWindow*);
2022-04-12 20:02:57 +02:00
// no-op when done.
void dispatchExecOnce();
2022-04-19 19:01:23 +02:00
void performMonitorReload();
bool m_bWantsMonitorReload = false;
2022-04-21 16:56:27 +02:00
std::string parseKeyword(const std::string&, const std::string&, bool dynamic = false);
2022-03-17 15:53:45 +01:00
private:
std::unordered_map<std::string, SConfigValue> configValues;
time_t lastModifyTime = 0; // for reloading the config if changed
std::string currentCategory = ""; // For storing the category of the current item
std::string parseError = ""; // For storing a parse error to display later
bool isFirstLaunch = true; // For exec-once
2022-03-17 16:56:33 +01:00
std::deque<SMonitorRule> m_dMonitorRules;
2022-03-24 18:22:01 +01:00
std::deque<SWindowRule> m_dWindowRules;
2022-03-17 16:56:33 +01:00
2022-04-12 20:02:57 +02:00
bool firstExecDispatched = false;
std::deque<std::string> firstExecRequests;
2022-03-17 15:53:45 +01:00
// internal methods
void setDefaultVars();
2022-03-17 15:53:45 +01:00
void loadConfigLoadVars();
SConfigValue getConfigValueSafe(std::string);
void parseLine(std::string&);
void configSetValueSafe(const std::string&, const std::string&);
void handleRawExec(const std::string&, const std::string&);
2022-03-17 16:56:33 +01:00
void handleMonitor(const std::string&, const std::string&);
2022-03-19 17:48:18 +01:00
void handleBind(const std::string&, const std::string&);
2022-04-21 17:06:43 +02:00
void handleUnbind(const std::string&, const std::string&);
2022-03-24 18:22:01 +01:00
void handleWindowRule(const std::string&, const std::string&);
2022-03-20 16:01:47 +01:00
void handleDefaultWorkspace(const std::string&, const std::string&);
2022-03-17 15:53:45 +01:00
};
inline std::unique_ptr<CConfigManager> g_pConfigManager;