summaryrefslogtreecommitdiff
path: root/src/config
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-17 16:56:33 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-17 16:56:33 +0100
commitd6c2553af2fc42b3ea61a1bd5f6e2cc395deccbe (patch)
treee690297fd4f953824129dd148bcec66a63a86957 /src/config
parentcf51ab71a25cbb60ebcf13edd4b7413c23264128 (diff)
start handling monitors
Diffstat (limited to 'src/config')
-rw-r--r--src/config/ConfigManager.cpp77
-rw-r--r--src/config/ConfigManager.hpp14
2 files changed, 91 insertions, 0 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index eccad341..47255651 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -66,6 +66,52 @@ void CConfigManager::handleRawExec(const std::string& command, const std::string
}
}
+void CConfigManager::handleMonitor(const std::string& command, const std::string& args) {
+
+ // get the monitor config
+ SMonitorRule newrule;
+
+ std::string curitem = "";
+
+ std::string argZ = args;
+
+ auto nextItem = [&]() {
+ auto idx = argZ.find_first_of(',');
+
+ if (idx != std::string::npos) {
+ curitem = argZ.substr(0, idx);
+ argZ = argZ.substr(idx + 1);
+ } else {
+ argZ = "";
+ curitem = argZ;
+ }
+ };
+
+ nextItem();
+
+ newrule.name = curitem;
+
+ nextItem();
+
+ newrule.resolution.x = stoi(curitem.substr(0, curitem.find_first_of('x')));
+ newrule.resolution.y = stoi(curitem.substr(curitem.find_first_of('x') + 1));
+
+ nextItem();
+
+ newrule.offset.x = stoi(curitem.substr(0, curitem.find_first_of('x')));
+ newrule.offset.y = stoi(curitem.substr(curitem.find_first_of('x') + 1));
+
+ nextItem();
+
+ newrule.mfact = stof(curitem);
+
+ nextItem();
+
+ newrule.scale = stof(curitem);
+
+ m_dMonitorRules.push_back(newrule);
+}
+
void CConfigManager::parseLine(std::string& line) {
// first check if its not a comment
const auto COMMENTSTART = line.find_first_of('#');
@@ -111,6 +157,9 @@ void CConfigManager::parseLine(std::string& line) {
handleRawExec(COMMAND, VALUE);
return;
}
+ } else if (COMMAND == "monitor") {
+ handleMonitor(COMMAND, VALUE);
+ return;
}
configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE);
@@ -121,6 +170,8 @@ void CConfigManager::loadConfigLoadVars() {
parseError = ""; // reset the error
currentCategory = ""; // reset the category
+ m_dMonitorRules.clear();
+
const char* const ENVHOME = getenv("HOME");
const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf");
@@ -199,3 +250,29 @@ float CConfigManager::getFloat(std::string v) {
std::string CConfigManager::getString(std::string v) {
return getConfigValueSafe(v).strValue;
}
+
+SMonitorRule CConfigManager::getMonitorRuleFor(std::string name) {
+ SMonitorRule* found = nullptr;
+
+ for (auto& r : m_dMonitorRules) {
+ if (r.name == name) {
+ found = &r;
+ break;
+ }
+ }
+
+ if (found)
+ return *found;
+
+ for (auto& r : m_dMonitorRules) {
+ if (r.name == "") {
+ found = &r;
+ break;
+ }
+ }
+
+ if (found)
+ return *found;
+
+ return SMonitorRule{.name = "", .resolution = Vector2D(1280, 720), .offset = Vector2D(0, 0), .mfact = 0.5f, .scale = 1};
+} \ No newline at end of file
diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp
index 5e58173a..eda06044 100644
--- a/src/config/ConfigManager.hpp
+++ b/src/config/ConfigManager.hpp
@@ -5,6 +5,7 @@
#include <unordered_map>
#include "../defines.hpp"
#include <vector>
+#include <deque>
struct SConfigValue {
int64_t intValue = -1;
@@ -12,6 +13,14 @@ struct SConfigValue {
std::string strValue = "";
};
+struct SMonitorRule {
+ std::string name = "";
+ Vector2D resolution = Vector2D(1280,720);
+ Vector2D offset = Vector2D(0,0);
+ float mfact = 0.5;
+ float scale = 1;
+};
+
class CConfigManager {
public:
CConfigManager();
@@ -22,6 +31,8 @@ public:
float getFloat(std::string);
std::string getString(std::string);
+ SMonitorRule getMonitorRuleFor(std::string);
+
private:
std::unordered_map<std::string, SConfigValue> configValues;
time_t lastModifyTime = 0; // for reloading the config if changed
@@ -32,12 +43,15 @@ private:
bool isFirstLaunch = true; // For exec-once
+ std::deque<SMonitorRule> m_dMonitorRules;
+
// internal methods
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&);
+ void handleMonitor(const std::string&, const std::string&);
};
inline std::unique_ptr<CConfigManager> g_pConfigManager; \ No newline at end of file