autotile: different handling of except workspaces rule

This commit is contained in:
André Silva 2023-09-14 11:28:44 +01:00
parent b9e72a008a
commit 3737f8234b
No known key found for this signature in database
GPG key ID: 7C34FA12A023DC55
3 changed files with 13 additions and 10 deletions

View file

@ -1731,15 +1731,21 @@ void Hy3Layout::updateAtWorkspaces() {
return; return;
} }
this->at_workspaces_blacklist = this->at_raw_workspaces.rfind("not:", 0) == 0;
const auto at_raw_workspaces_filtered = (this->at_workspaces_blacklist)
? this->at_raw_workspaces.substr(4)
: this->at_raw_workspaces;
// split on space and comma // split on space and comma
const std::regex regex {R"([\s,]+)"}; const std::regex regex {R"([\s,]+)"};
const auto begin = std::regex_token_iterator( const auto begin = std::sregex_token_iterator(
this->at_raw_workspaces.begin(), at_raw_workspaces_filtered.begin(),
this->at_raw_workspaces.end(), at_raw_workspaces_filtered.end(),
regex, regex,
-1 -1
); );
const auto end = std::regex_token_iterator<std::string::iterator>(); const auto end = std::sregex_token_iterator();
for (auto s = begin; s != end; ++s) { for (auto s = begin; s != end; ++s) {
try { try {
@ -1751,11 +1757,8 @@ void Hy3Layout::updateAtWorkspaces() {
} }
bool Hy3Layout::shouldAtWorkspace(int workspace_id) { bool Hy3Layout::shouldAtWorkspace(int workspace_id) {
static const auto* at_workspaces_except if (this->at_workspaces_blacklist) {
= &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces.except")->intValue; return !this->at_workspaces.contains(workspace_id);
if (*at_workspaces_except) {
return !this->at_workspaces.empty() && !this->at_workspaces.contains(workspace_id);
} else { } else {
return this->at_workspaces.empty() || this->at_workspaces.contains(workspace_id); return this->at_workspaces.empty() || this->at_workspaces.contains(workspace_id);
} }

View file

@ -143,6 +143,7 @@ private:
bool shouldAtWorkspace(int); bool shouldAtWorkspace(int);
std::string at_raw_workspaces; std::string at_raw_workspaces;
bool at_workspaces_blacklist;
std::set<int> at_workspaces; std::set<int> at_workspaces;
friend struct Hy3Node; friend struct Hy3Node;

View file

@ -44,7 +44,6 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
CONF("autotile:trigger_height", int, 0); CONF("autotile:trigger_height", int, 0);
CONF("autotile:trigger_width", int, 0); CONF("autotile:trigger_width", int, 0);
CONF("autotile:workspaces", str, "all"); CONF("autotile:workspaces", str, "all");
CONF("autotile:workspaces.except", int, 0);
#undef CONF #undef CONF