2022-03-17 15:53:45 +01:00
|
|
|
#include "ConfigManager.hpp"
|
2022-03-19 17:48:18 +01:00
|
|
|
#include "../managers/KeybindManager.hpp"
|
2022-03-17 15:53:45 +01:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
CConfigManager::CConfigManager() {
|
|
|
|
configValues["general:max_fps"].intValue = 240;
|
2022-03-19 20:30:21 +01:00
|
|
|
configValues["general:sensitivity"].floatValue = 0.25f;
|
2022-03-20 19:58:12 +01:00
|
|
|
configValues["general:main_mod"].strValue = "SUPER"; // exposed to the user for easier configuring
|
|
|
|
configValues["general:main_mod_internal"].intValue = g_pKeybindManager->stringToModMask("SUPER"); // actually used and automatically calculated
|
2022-03-17 15:53:45 +01:00
|
|
|
|
|
|
|
configValues["general:border_size"].intValue = 1;
|
|
|
|
configValues["general:gaps_in"].intValue = 5;
|
|
|
|
configValues["general:gaps_out"].intValue = 20;
|
2022-03-19 16:13:19 +01:00
|
|
|
configValues["general:col.active_border"].intValue = 0xffffffff;
|
|
|
|
configValues["general:col.inactive_border"].intValue = 0xff444444;
|
2022-03-23 22:01:59 +01:00
|
|
|
|
2022-04-05 15:50:47 +02:00
|
|
|
configValues["decoration:rounding"].intValue = 1;
|
2022-04-09 16:51:08 +02:00
|
|
|
configValues["decoration:blur"].intValue = 1;
|
|
|
|
configValues["decoration:blur_size"].intValue = 8;
|
2022-04-09 17:06:09 +02:00
|
|
|
configValues["decoration:blur_passes"].intValue = 1;
|
2022-04-05 15:50:47 +02:00
|
|
|
|
2022-04-02 20:04:32 +02:00
|
|
|
configValues["dwindle:pseudotile"].intValue = 0;
|
|
|
|
|
2022-03-23 22:01:59 +01:00
|
|
|
configValues["animations:enabled"].intValue = 1;
|
|
|
|
configValues["animations:speed"].floatValue = 7.f;
|
2022-03-31 17:53:28 +02:00
|
|
|
configValues["animations:windows_speed"].floatValue = 0.f;
|
2022-03-23 22:01:59 +01:00
|
|
|
configValues["animations:windows"].intValue = 1;
|
2022-03-31 17:53:28 +02:00
|
|
|
configValues["animations:borders_speed"].floatValue = 0.f;
|
2022-03-23 22:01:59 +01:00
|
|
|
configValues["animations:borders"].intValue = 1;
|
2022-03-31 17:53:28 +02:00
|
|
|
configValues["animations:fadein_speed"].floatValue = 0.f;
|
2022-03-23 22:01:59 +01:00
|
|
|
configValues["animations:fadein"].intValue = 1;
|
2022-03-24 21:05:34 +01:00
|
|
|
|
|
|
|
configValues["input:kb_layout"].strValue = "en";
|
|
|
|
configValues["input:kb_variant"].strValue = "";
|
|
|
|
configValues["input:kb_options"].strValue = "";
|
|
|
|
configValues["input:kb_rules"].strValue = "";
|
|
|
|
configValues["input:kb_model"].strValue = "";
|
2022-04-08 22:07:40 +02:00
|
|
|
|
|
|
|
configValues["autogenerated"].intValue = 0;
|
2022-03-17 17:08:54 +01:00
|
|
|
}
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2022-03-17 17:08:54 +01:00
|
|
|
void CConfigManager::init() {
|
2022-03-20 19:58:12 +01:00
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
loadConfigLoadVars();
|
|
|
|
|
2022-03-19 17:00:52 +01:00
|
|
|
const char* const ENVHOME = getenv("HOME");
|
|
|
|
|
|
|
|
const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf");
|
|
|
|
|
|
|
|
struct stat fileStat;
|
|
|
|
int err = stat(CONFIGPATH.c_str(), &fileStat);
|
|
|
|
if (err != 0) {
|
|
|
|
Debug::log(WARN, "Error at statting config, error %i", errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
lastModifyTime = fileStat.st_mtime;
|
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
isFirstLaunch = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::string& VALUE) {
|
|
|
|
if (configValues.find(COMMAND) == configValues.end()) {
|
|
|
|
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">: No such field.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& CONFIGENTRY = configValues.at(COMMAND);
|
|
|
|
if (CONFIGENTRY.intValue != -1) {
|
|
|
|
try {
|
|
|
|
if (VALUE.find("0x") == 0) {
|
|
|
|
// Values with 0x are hex
|
|
|
|
const auto VALUEWITHOUTHEX = VALUE.substr(2);
|
|
|
|
CONFIGENTRY.intValue = stol(VALUEWITHOUTHEX, nullptr, 16);
|
|
|
|
} else
|
|
|
|
CONFIGENTRY.intValue = stol(VALUE);
|
|
|
|
} catch (...) {
|
|
|
|
Debug::log(WARN, "Error reading value of %s", COMMAND.c_str());
|
|
|
|
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
|
|
|
|
}
|
|
|
|
} else if (CONFIGENTRY.floatValue != -1) {
|
|
|
|
try {
|
|
|
|
CONFIGENTRY.floatValue = stof(VALUE);
|
|
|
|
} catch (...) {
|
|
|
|
Debug::log(WARN, "Error reading value of %s", COMMAND.c_str());
|
|
|
|
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
|
|
|
|
}
|
|
|
|
} else if (CONFIGENTRY.strValue != "") {
|
|
|
|
try {
|
|
|
|
CONFIGENTRY.strValue = VALUE;
|
|
|
|
} catch (...) {
|
|
|
|
Debug::log(WARN, "Error reading value of %s", COMMAND.c_str());
|
|
|
|
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CConfigManager::handleRawExec(const std::string& command, const std::string& args) {
|
|
|
|
// Exec in the background dont wait for it.
|
|
|
|
if (fork() == 0) {
|
|
|
|
execl("/bin/sh", "/bin/sh", "-c", args.c_str(), nullptr);
|
|
|
|
|
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:56:33 +01:00
|
|
|
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 {
|
|
|
|
curitem = argZ;
|
2022-03-19 17:00:52 +01:00
|
|
|
argZ = "";
|
2022-03-17 16:56:33 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
nextItem();
|
|
|
|
|
|
|
|
newrule.name = curitem;
|
|
|
|
|
|
|
|
nextItem();
|
|
|
|
|
|
|
|
newrule.resolution.x = stoi(curitem.substr(0, curitem.find_first_of('x')));
|
2022-03-19 21:46:29 +01:00
|
|
|
newrule.resolution.y = stoi(curitem.substr(curitem.find_first_of('x') + 1, curitem.find_first_of('@')));
|
|
|
|
|
|
|
|
if (curitem.find_first_of('@') != std::string::npos)
|
|
|
|
newrule.refreshRate = stof(curitem.substr(curitem.find_first_of('@') + 1));
|
2022-03-17 16:56:33 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-03-19 17:48:18 +01:00
|
|
|
void CConfigManager::handleBind(const std::string& command, const std::string& value) {
|
|
|
|
// example:
|
|
|
|
// bind=SUPER,G,exec,dmenu_run <args>
|
|
|
|
|
|
|
|
auto valueCopy = value;
|
|
|
|
|
|
|
|
const auto MOD = g_pKeybindManager->stringToModMask(valueCopy.substr(0, valueCopy.find_first_of(",")));
|
|
|
|
valueCopy = valueCopy.substr(valueCopy.find_first_of(",") + 1);
|
|
|
|
|
|
|
|
const auto KEY = valueCopy.substr(0, valueCopy.find_first_of(","));
|
|
|
|
valueCopy = valueCopy.substr(valueCopy.find_first_of(",") + 1);
|
|
|
|
|
|
|
|
const auto HANDLER = valueCopy.substr(0, valueCopy.find_first_of(","));
|
|
|
|
valueCopy = valueCopy.substr(valueCopy.find_first_of(",") + 1);
|
|
|
|
|
|
|
|
const auto COMMAND = valueCopy;
|
|
|
|
|
|
|
|
if (KEY != "")
|
|
|
|
g_pKeybindManager->addKeybind(SKeybind{KEY, MOD, HANDLER, COMMAND});
|
|
|
|
}
|
|
|
|
|
2022-03-24 18:22:01 +01:00
|
|
|
void CConfigManager::handleWindowRule(const std::string& command, const std::string& value) {
|
|
|
|
const auto RULE = value.substr(0, value.find_first_of(","));
|
|
|
|
const auto VALUE = value.substr(value.find_first_of(",") + 1);
|
|
|
|
|
|
|
|
// check rule and value
|
|
|
|
if (RULE == "" || VALUE == "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify we support a rule
|
|
|
|
if (RULE != "float"
|
|
|
|
&& RULE != "tile"
|
|
|
|
&& RULE.find("move") != 0
|
|
|
|
&& RULE.find("size") != 0
|
2022-04-02 20:04:32 +02:00
|
|
|
&& RULE.find("pseudo") != 0
|
2022-03-24 18:22:01 +01:00
|
|
|
&& RULE.find("monitor") != 0) {
|
|
|
|
Debug::log(ERR, "Invalid rule found: %s", RULE.c_str());
|
|
|
|
parseError = "Invalid rule found: " + RULE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dWindowRules.push_back({RULE, VALUE});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-20 16:01:47 +01:00
|
|
|
void CConfigManager::handleDefaultWorkspace(const std::string& command, const std::string& value) {
|
|
|
|
|
|
|
|
const auto DISPLAY = value.substr(0, value.find_first_of(','));
|
|
|
|
const auto WORKSPACEID = stoi(value.substr(value.find_first_of(',') + 1));
|
|
|
|
|
|
|
|
for (auto& mr : m_dMonitorRules) {
|
|
|
|
if (mr.name == DISPLAY) {
|
|
|
|
mr.defaultWorkspaceID = WORKSPACEID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
void CConfigManager::parseLine(std::string& line) {
|
|
|
|
// first check if its not a comment
|
|
|
|
const auto COMMENTSTART = line.find_first_of('#');
|
|
|
|
if (COMMENTSTART == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// now, cut the comment off
|
|
|
|
if (COMMENTSTART != std::string::npos)
|
|
|
|
line = line.substr(0, COMMENTSTART);
|
|
|
|
|
|
|
|
// remove shit at the beginning
|
|
|
|
while (line[0] == ' ' || line[0] == '\t') {
|
|
|
|
line = line.substr(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line.find(" {") != std::string::npos) {
|
|
|
|
auto cat = line.substr(0, line.find(" {"));
|
|
|
|
transform(cat.begin(), cat.end(), cat.begin(), ::tolower);
|
|
|
|
currentCategory = cat;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line.find("}") != std::string::npos && currentCategory != "") {
|
|
|
|
currentCategory = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// And parse
|
|
|
|
// check if command
|
|
|
|
const auto EQUALSPLACE = line.find_first_of('=');
|
|
|
|
|
|
|
|
if (EQUALSPLACE == std::string::npos)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto COMMAND = line.substr(0, EQUALSPLACE);
|
|
|
|
const auto VALUE = line.substr(EQUALSPLACE + 1);
|
|
|
|
|
|
|
|
if (COMMAND == "exec") {
|
|
|
|
handleRawExec(COMMAND, VALUE);
|
|
|
|
return;
|
|
|
|
} else if (COMMAND == "exec-once") {
|
|
|
|
if (isFirstLaunch) {
|
|
|
|
handleRawExec(COMMAND, VALUE);
|
|
|
|
}
|
2022-04-09 22:49:07 +02:00
|
|
|
return;
|
2022-03-17 16:56:33 +01:00
|
|
|
} else if (COMMAND == "monitor") {
|
|
|
|
handleMonitor(COMMAND, VALUE);
|
|
|
|
return;
|
2022-03-19 17:48:18 +01:00
|
|
|
} else if (COMMAND == "bind") {
|
|
|
|
handleBind(COMMAND, VALUE);
|
|
|
|
return;
|
2022-03-20 16:01:47 +01:00
|
|
|
} else if (COMMAND == "workspace") {
|
|
|
|
handleDefaultWorkspace(COMMAND, VALUE);
|
|
|
|
return;
|
2022-03-24 18:22:01 +01:00
|
|
|
} else if (COMMAND == "windowrule") {
|
|
|
|
handleWindowRule(COMMAND, VALUE);
|
|
|
|
return;
|
2022-03-17 15:53:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CConfigManager::loadConfigLoadVars() {
|
|
|
|
Debug::log(LOG, "Reloading the config!");
|
|
|
|
parseError = ""; // reset the error
|
|
|
|
currentCategory = ""; // reset the category
|
2022-04-09 16:52:05 +02:00
|
|
|
configValues["autogenerated"].intValue = 0; // reset autogenerated status
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2022-03-17 16:56:33 +01:00
|
|
|
m_dMonitorRules.clear();
|
2022-03-24 18:22:01 +01:00
|
|
|
m_dWindowRules.clear();
|
2022-03-19 21:48:24 +01:00
|
|
|
g_pKeybindManager->clearKeybinds();
|
2022-03-17 16:56:33 +01:00
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
const char* const ENVHOME = getenv("HOME");
|
|
|
|
const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf");
|
|
|
|
|
|
|
|
std::ifstream ifs;
|
2022-04-08 22:07:40 +02:00
|
|
|
ifs.open(CONFIGPATH);
|
2022-03-17 15:53:45 +01:00
|
|
|
|
|
|
|
if (!ifs.good()) {
|
2022-04-08 22:07:40 +02:00
|
|
|
Debug::log(WARN, "Config reading error. (No file? Attempting to generate, backing up old one if exists)");
|
|
|
|
try {
|
|
|
|
std::filesystem::rename(CONFIGPATH, CONFIGPATH + ".backup");
|
|
|
|
} catch(...) { /* Probably doesn't exist */}
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2022-04-08 22:07:40 +02:00
|
|
|
std::ofstream ofs;
|
|
|
|
ofs.open(CONFIGPATH, std::ios::trunc);
|
|
|
|
|
|
|
|
ofs << AUTOCONFIG;
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
|
|
|
|
ifs.open(CONFIGPATH);
|
|
|
|
|
|
|
|
if (!ifs.good()) {
|
|
|
|
parseError = "Broken config file! (Could not open)";
|
|
|
|
return;
|
|
|
|
}
|
2022-03-17 15:53:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string line = "";
|
|
|
|
int linenum = 1;
|
|
|
|
if (ifs.is_open()) {
|
|
|
|
while (std::getline(ifs, line)) {
|
|
|
|
// Read line by line.
|
|
|
|
try {
|
|
|
|
parseLine(line);
|
|
|
|
} catch (...) {
|
|
|
|
Debug::log(ERR, "Error reading line from config. Line:");
|
|
|
|
Debug::log(NONE, "%s", line.c_str());
|
|
|
|
|
2022-04-08 21:40:41 +02:00
|
|
|
parseError += "Config error at line " + std::to_string(linenum) + ": Line parsing error.";
|
2022-03-17 15:53:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parseError != "" && parseError.find("Config error at line") != 0) {
|
|
|
|
parseError = "Config error at line " + std::to_string(linenum) + ": " + parseError;
|
|
|
|
}
|
|
|
|
|
|
|
|
++linenum;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifs.close();
|
|
|
|
}
|
2022-03-19 21:48:24 +01:00
|
|
|
|
|
|
|
for (auto& m : g_pCompositor->m_lMonitors)
|
|
|
|
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m.ID);
|
2022-03-20 11:14:24 +01:00
|
|
|
|
2022-04-10 16:19:49 +02:00
|
|
|
// Update the keyboard layout to the cfg'd one if this is not the first launch
|
|
|
|
if (!isFirstLaunch)
|
|
|
|
g_pInputManager->setKeyboardLayout();
|
2022-03-24 21:05:34 +01:00
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
// Calculate the mod mask for main_mod
|
|
|
|
configValues["general:main_mod_internal"].intValue = g_pKeybindManager->stringToModMask(configValues["general:main_mod"].strValue);
|
2022-04-08 21:40:41 +02:00
|
|
|
|
|
|
|
// parseError will be displayed next frame
|
|
|
|
if (parseError != "")
|
|
|
|
g_pHyprError->queueCreate(parseError + "\nHyprland may not work correctly.", CColor(255, 50, 50, 255));
|
2022-04-08 22:07:40 +02:00
|
|
|
else if (configValues["autogenerated"].intValue == 1)
|
|
|
|
g_pHyprError->queueCreate("Warning: You're using an autogenerated config! (config file: " + CONFIGPATH + " )\nSUPER+Enter -> kitty\nSUPER+T -> Alacritty\nSUPER+M -> exit Hyprland", CColor(255, 255, 70, 255));
|
2022-04-08 21:40:41 +02:00
|
|
|
else
|
|
|
|
g_pHyprError->destroy();
|
2022-03-17 15:53:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CConfigManager::tick() {
|
|
|
|
const char* const ENVHOME = getenv("HOME");
|
|
|
|
|
2022-03-19 16:13:19 +01:00
|
|
|
const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf");
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2022-04-08 22:07:40 +02:00
|
|
|
if (!std::filesystem::exists(CONFIGPATH)) {
|
|
|
|
loadConfigLoadVars();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
struct stat fileStat;
|
|
|
|
int err = stat(CONFIGPATH.c_str(), &fileStat);
|
|
|
|
if (err != 0) {
|
2022-03-20 19:58:12 +01:00
|
|
|
Debug::log(WARN, "Error at ticking config at %s, error %i: %s", CONFIGPATH.c_str(), err, strerror(err));
|
|
|
|
return;
|
2022-03-17 15:53:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if we need to reload cfg
|
|
|
|
if (fileStat.st_mtime != lastModifyTime) {
|
|
|
|
lastModifyTime = fileStat.st_mtime;
|
|
|
|
|
|
|
|
loadConfigLoadVars();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::mutex configmtx;
|
|
|
|
SConfigValue CConfigManager::getConfigValueSafe(std::string val) {
|
|
|
|
std::lock_guard<std::mutex> lg(configmtx);
|
|
|
|
|
|
|
|
SConfigValue copy = configValues[val];
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CConfigManager::getInt(std::string v) {
|
|
|
|
return getConfigValueSafe(v).intValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float CConfigManager::getFloat(std::string v) {
|
|
|
|
return getConfigValueSafe(v).floatValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CConfigManager::getString(std::string v) {
|
|
|
|
return getConfigValueSafe(v).strValue;
|
|
|
|
}
|
2022-03-17 16:56:33 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-03-19 17:00:52 +01:00
|
|
|
Debug::log(WARN, "No rule found for %s, trying to use the first.", name.c_str());
|
|
|
|
|
2022-03-17 16:56:33 +01:00
|
|
|
for (auto& r : m_dMonitorRules) {
|
|
|
|
if (r.name == "") {
|
|
|
|
found = &r;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return *found;
|
|
|
|
|
2022-03-19 17:00:52 +01:00
|
|
|
Debug::log(WARN, "No rules configured. Using the default hardcoded one.");
|
|
|
|
|
2022-03-17 16:56:33 +01:00
|
|
|
return SMonitorRule{.name = "", .resolution = Vector2D(1280, 720), .offset = Vector2D(0, 0), .mfact = 0.5f, .scale = 1};
|
2022-03-24 18:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow) {
|
|
|
|
if (!g_pCompositor->windowValidMapped(pWindow))
|
|
|
|
return std::vector<SWindowRule>();
|
|
|
|
|
|
|
|
std::vector<SWindowRule> returns;
|
|
|
|
|
|
|
|
std::string title = g_pXWaylandManager->getTitle(pWindow);
|
|
|
|
std::string appidclass = g_pXWaylandManager->getAppIDClass(pWindow);
|
|
|
|
|
|
|
|
for (auto& rule : m_dWindowRules) {
|
|
|
|
// check if we have a matching rule
|
|
|
|
try {
|
|
|
|
std::regex classCheck(rule.szValue);
|
|
|
|
|
|
|
|
if (!std::regex_search(title, classCheck) && !std::regex_search(appidclass, classCheck))
|
|
|
|
continue;
|
|
|
|
} catch (...) {
|
|
|
|
Debug::log(ERR, "Regex error at %s", rule.szValue.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// applies. Read the rule and behave accordingly
|
|
|
|
Debug::log(LOG, "Window rule %s -> %s matched %x [%s]", rule.szRule.c_str(), rule.szValue.c_str(), pWindow, pWindow->m_szTitle.c_str());
|
|
|
|
|
|
|
|
returns.push_back(rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
return returns;
|
2022-03-17 16:56:33 +01:00
|
|
|
}
|