Added simple window rules

This commit is contained in:
vaxerski 2021-12-20 20:50:35 +01:00
parent 22983f40f3
commit c679f327d6
5 changed files with 76 additions and 5 deletions

View file

@ -53,6 +53,11 @@ Animations {
borders=0 borders=0
} }
# window rules
windowrule=float,class:krunner
windowrule=float,role:pop-up
windowrule=float,role:task_dialog
# keybinds # keybinds
bind=SUPER,R,exec,dmenu_run bind=SUPER,R,exec,dmenu_run
bind=SUPER,Q,exec,kitty bind=SUPER,Q,exec,kitty

View file

@ -249,6 +249,26 @@ void parseAnimLine(const std::string& line) {
configSetValueSafe("anim:" + COMMAND, VALUE); configSetValueSafe("anim:" + COMMAND, VALUE);
} }
void 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") {
Debug::log(ERR, "Invalid rule found: " + RULE);
ConfigManager::parseError = "Invalid rule found: " + RULE;
return;
}
ConfigManager::windowRules.push_back({RULE, VALUE});
}
void parseLine(std::string& line) { void parseLine(std::string& line) {
// first check if its not a comment // first check if its not a comment
const auto COMMENTSTART = line.find_first_of('#'); const auto COMMENTSTART = line.find_first_of('#');
@ -312,6 +332,9 @@ void parseLine(std::string& line) {
} else if (COMMAND == "status_command") { } else if (COMMAND == "status_command") {
handleStatusCommand(COMMAND, VALUE); handleStatusCommand(COMMAND, VALUE);
return; return;
} else if (COMMAND == "windowrule") {
handleWindowRule(COMMAND, VALUE);
return;
} }
configSetValueSafe(COMMAND, VALUE); configSetValueSafe(COMMAND, VALUE);
@ -322,6 +345,7 @@ void ConfigManager::loadConfigLoadVars() {
Debug::log(LOG, "Reloading the config!"); Debug::log(LOG, "Reloading the config!");
ConfigManager::parseError = ""; // reset the error ConfigManager::parseError = ""; // reset the error
ConfigManager::currentCategory = ""; // reset the category ConfigManager::currentCategory = ""; // reset the category
ConfigManager::windowRules.clear(); // Clear rules
if (loadBar && g_pWindowManager->statusBar) { if (loadBar && g_pWindowManager->statusBar) {
// clear modules as we overwrite them // clear modules as we overwrite them

View file

@ -3,6 +3,7 @@
#include <map> #include <map>
#include "../utilities/Debug.hpp" #include "../utilities/Debug.hpp"
#include <unordered_map> #include <unordered_map>
#include <vector>
enum ELayouts { enum ELayouts {
LAYOUT_DWINDLE = 0, LAYOUT_DWINDLE = 0,
@ -15,6 +16,11 @@ struct SConfigValue {
std::string strValue = ""; std::string strValue = "";
}; };
struct SWindowRule {
std::string szRule;
std::string szValue;
};
namespace ConfigManager { namespace ConfigManager {
inline std::unordered_map<std::string, SConfigValue> configValues; inline std::unordered_map<std::string, SConfigValue> configValues;
inline time_t lastModifyTime = 0; inline time_t lastModifyTime = 0;
@ -27,6 +33,8 @@ namespace ConfigManager {
inline std::string parseError = ""; // For storing a parse error to display later inline std::string parseError = ""; // For storing a parse error to display later
inline std::vector<SWindowRule> windowRules;
void init(); void init();
void loadConfigLoadVars(); void loadConfigLoadVars();
void tick(); void tick();

View file

@ -28,6 +28,8 @@
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include <unordered_map> #include <unordered_map>
#include <regex>
#include <vector>
#include "./helpers/Vector.hpp" #include "./helpers/Vector.hpp"
#include "./utilities/Debug.hpp" #include "./utilities/Debug.hpp"

View file

@ -1579,8 +1579,25 @@ bool CWindowManager::shouldBeFloatedOnInit(int64_t window) {
xcb_change_property(DisplayConnection, XCB_PROP_MODE_REPLACE, window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen("hypr"), "hypr"); xcb_change_property(DisplayConnection, XCB_PROP_MODE_REPLACE, window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen("hypr"), "hypr");
if (((std::string)CLASSNAME).find("krunner") != std::string::npos) { // Verify the class (rules)
return true; for (auto& rule : ConfigManager::windowRules) {
// check if we have a class rule
if (rule.szValue.find("class:") != 0)
continue;
// regex check the arg
std::regex classCheck(rule.szValue.substr(strlen("class:")));
if (!std::regex_search(CLASSNAME, classCheck))
continue;
// applies. Read the rule and behave accordingly
Debug::log(LOG, "Window rule " + rule.szRule + "," + rule.szValue + " matched.");
if (rule.szRule == "tile")
return false;
else if (rule.szRule == "float")
return true;
} }
@ -1589,10 +1606,25 @@ bool CWindowManager::shouldBeFloatedOnInit(int64_t window) {
Debug::log(LOG, "Window opened with a role of " + WINROLE); Debug::log(LOG, "Window opened with a role of " + WINROLE);
if (WINROLE.find("pop-up") != std::string::npos || WINROLE.find("task_dialog") != std::string::npos) { for (auto& rule : ConfigManager::windowRules) {
return true; // check if we have a role rule
} if (rule.szValue.find("role:") != 0)
continue;
// regex check the arg
std::regex roleCheck(rule.szValue.substr(strlen("role:")));
if (!std::regex_search(WINROLE, roleCheck))
continue;
// applies. Read the rule and behave accordingly
Debug::log(LOG, "Window rule " + rule.szRule + "," + rule.szValue + " matched.");
if (rule.szRule == "tile")
return false;
else if (rule.szRule == "float")
return true;
}
// //
// Type stuff // Type stuff