feat(taskbar): `order-list` option

pull/1396/head
Jake Stanger 2022-01-16 20:35:39 +00:00
parent 81f0bcb3a3
commit 4c172ae924
3 changed files with 28 additions and 2 deletions

View File

@ -46,6 +46,8 @@ class Task
INVALID = (1 << 4)
};
Gtk::Button button_;
private:
static uint32_t global_id;
@ -58,7 +60,7 @@ class Task
uint32_t id_;
Gtk::Button button_;
Gtk::Box content_;
Gtk::Image icon_;
Gtk::Label text_before_;
@ -143,6 +145,7 @@ class Taskbar : public waybar::AModule
std::vector<Glib::RefPtr<Gtk::IconTheme>> icon_themes_;
std::unordered_set<std::string> ignore_list_;
std::vector<std::string> order_list_;
std::map<std::string, std::string> app_ids_replace_map_;
struct zwlr_foreign_toplevel_manager_v1 *manager_;

View File

@ -72,6 +72,10 @@ Addressed by *wlr/taskbar*
typeof: array ++
List of app_id/titles to be invisible.
*ignore-list*: ++
typeof: array ++
List of app_ids in the order they should appear.
*app_ids-mapping*: ++
typeof: object ++
Dictionary of app_id to be replaced with

View File

@ -764,6 +764,13 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu
}
}
// Load order-list
if (config_["order-list"].isArray()) {
for (auto& app_name : config_["order-list"]) {
order_list_.push_back(app_name.asString());
}
}
// Load app_id remappings
if (config_["app_ids-mapping"].isObject()) {
const Json::Value& mapping = config_["app_ids-mapping"];
@ -798,6 +805,18 @@ Taskbar::~Taskbar()
void Taskbar::update()
{
if (!order_list_.empty()) {
for (auto& task : tasks_) {
auto begin = order_list_.begin();
auto itr = std::find(begin, order_list_.end(), task->app_id());
if (itr != std::end(order_list_)) {
auto index = std::distance(begin, itr);
move_button(task->button_, index);
}
}
}
for (auto& t : tasks_) {
t->update();
}