2022-03-17 15:53:45 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
#define CONFIG_MANAGER_H
|
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
#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
|
|
|
|
2022-04-08 22:07:40 +02:00
|
|
|
#include "defaultConfig.hpp"
|
|
|
|
|
2022-05-06 14:30:35 +02:00
|
|
|
#define STRVAL_EMPTY "[[EMPTY]]"
|
|
|
|
|
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-04-27 17:46:07 +02:00
|
|
|
struct SMonitorAdditionalReservedArea {
|
|
|
|
int top = 0;
|
|
|
|
int bottom = 0;
|
|
|
|
int left = 0;
|
|
|
|
int right = 0;
|
|
|
|
};
|
|
|
|
|
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);
|
2022-04-10 18:25:45 +02:00
|
|
|
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-04-23 14:16:02 +02:00
|
|
|
SConfigValue* getConfigValuePtr(std::string);
|
|
|
|
|
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-27 17:46:07 +02:00
|
|
|
std::unordered_map<std::string, SMonitorAdditionalReservedArea> m_mAdditionalReservedAreas;
|
|
|
|
|
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-05-08 15:28:45 +02:00
|
|
|
bool m_bForceReload = false;
|
2022-04-19 19:01:23 +02:00
|
|
|
|
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:
|
2022-05-16 09:38:42 +02:00
|
|
|
std::unordered_map<std::string, std::string> configDynamicVars; // stores dynamic vars declared by the user
|
2022-03-17 15:53:45 +01:00
|
|
|
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
|
2022-04-18 13:27:54 +02:00
|
|
|
void setDefaultVars();
|
|
|
|
|
2022-05-16 09:38:42 +02:00
|
|
|
void applyUserDefinedVars(std::string&, const size_t);
|
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-04-23 21:47:16 +02:00
|
|
|
void handleBezier(const std::string&, const std::string&);
|
2022-05-14 15:56:01 +02:00
|
|
|
void handleAnimation(const std::string&, const std::string&);
|
2022-03-17 15:53:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
inline std::unique_ptr<CConfigManager> g_pConfigManager;
|