Skip to content

Commit

Permalink
fixed bug; when the shown task is removed it promotes another one
Browse files Browse the repository at this point in the history
  • Loading branch information
NoakPalander committed Nov 4, 2024
1 parent a45c59b commit a587715
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/modules/wlr/taskbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <map>
#include <memory>
#include <ranges>
#include <string>
#include <unordered_set>
#include <vector>
Expand Down Expand Up @@ -187,6 +188,10 @@ class Taskbar : public waybar::AModule {
const std::map<std::string, std::string> &app_ids_replace_map() const;
std::size_t task_id_count(std::string_view id) const;
std::size_t task_title_count(std::string_view title) const;

auto tasks() {
return tasks_ | std::views::transform([](auto &task) -> Task & { return *task; });
}
};

} /* namespace waybar::modules::wlr */
22 changes: 22 additions & 0 deletions src/modules/wlr/taskbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,28 @@ void Task::handle_closed() {
tbar_->remove_button(button);
button_visible_ = false;
}

const auto &squash_list = tbar_->squash_list();
const bool in_squash_list =
squash_list.contains("*") || squash_list.contains(title_) || squash_list.contains(app_id_);
if (in_squash_list && !squashed_ &&
(tbar_->task_id_count(app_id_) > 1 || tbar_->task_title_count(title_) > 1)) {
// Find next squashed task with same title or id (excluding ourselves)
auto tasks = tbar_->tasks();
const auto it = std::ranges::find_if(tasks, [this](auto &&task) {
return &task != this && task.squashed_ &&
(task.app_id() == app_id_ || task.title() == title_);
});

if (it != tasks.end() && !(*it).ignored_) {
Task &task = *it;
task.squashed_ = false;
tbar_->add_button(task.button);
task.button.show();
task.button_visible_ = true;
}
}

tbar_->remove_task(id_);
}

Expand Down

0 comments on commit a587715

Please sign in to comment.