Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Rehan committed Oct 29, 2023
1 parent e46f66b commit a5a0e6f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ class Workspaces : public AModule, public EventHandler {
std::vector<WindowCreationPayload> windows_to_create_;

std::vector<std::regex> ignore_workspaces_;
std::vector<int> exclude_persistence_point_;
std::vector<int> prune_past_persistence_point_;

std::mutex mutex_;
const Bar& bar_;
Expand Down
37 changes: 37 additions & 0 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ auto Workspaces::parse_config(const Json::Value &config) -> void {
window_rewrite, window_rewrite_default, [this](std::string &window_rule) {
return this->window_rewrite_priority_function(window_rule);
});

Json::Value exclude_persistence_point = config["exclude-persistence-point"];
if (exclude_persistence_point.isArray()) {
for (Json::Value &ws_id : exclude_persistence_point) {
if (ws_id.isInt()) exclude_persistence_point_.emplace_back(ws_id.asInt());
}
}

Json::Value prune_past_persistence_point = config["prune-past-persistence-point"];
if (prune_past_persistence_point.isArray()) {
for (Json::Value &ws_id : prune_past_persistence_point) {
if (ws_id.isInt()) prune_past_persistence_point_.emplace_back(ws_id.asInt());
}
}
}

auto Workspaces::register_ipc() -> void {
Expand Down Expand Up @@ -182,7 +196,19 @@ auto Workspaces::update() -> void {
visible_workspaces.push_back(ws["name"].asString());
}
}
int persist_point = -1;
if (!prune_past_persistence_point_.empty()) {
for (int i = workspaces_.size() - 1; i >= 0; i--) {
if ((!workspaces_[i]->is_empty() || workspaces_[i]->active() || workspaces_[i]->is_visible()) &&
!workspaces_[i]->name().starts_with("special") &&
std::find(exclude_persistence_point_.begin(), exclude_persistence_point_.end(), workspaces_[i]->id()) == exclude_persistence_point_.end()) {
persist_point = i;
break;
}
}
}

int i = 0;
for (auto &workspace : workspaces_) {
// active
workspace->set_active(workspace->name() == active_workspace_name_);
Expand All @@ -201,6 +227,15 @@ auto Workspaces::update() -> void {
workspace_icon = workspace->select_icon(icons_map_);
}
workspace->update(format_, workspace_icon);

if (!prune_past_persistence_point_.empty() &&
workspace->is_persistent() &&
i > persist_point &&
std::find(prune_past_persistence_point_.begin(), prune_past_persistence_point_.end(), workspaces_[i]->id()) != prune_past_persistence_point_.end()) {
workspace->button().hide();
}

i++;
}

bool any_window_created = false;
Expand Down Expand Up @@ -640,6 +675,8 @@ void Workspaces::init() {

sort_workspaces();

update();

dp.emit();
}

Expand Down

0 comments on commit a5a0e6f

Please sign in to comment.