From 4c172ae924fbf9ae8aa9b6e18f7b01f2389e3975 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 16 Jan 2022 20:35:39 +0000 Subject: [PATCH] feat(taskbar): `order-list` option --- include/modules/wlr/taskbar.hpp | 5 ++++- man/waybar-wlr-taskbar.5.scd | 4 ++++ src/modules/wlr/taskbar.cpp | 21 ++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/modules/wlr/taskbar.hpp b/include/modules/wlr/taskbar.hpp index 973d15db..658e0b20 100644 --- a/include/modules/wlr/taskbar.hpp +++ b/include/modules/wlr/taskbar.hpp @@ -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> icon_themes_; std::unordered_set ignore_list_; + std::vector order_list_; std::map app_ids_replace_map_; struct zwlr_foreign_toplevel_manager_v1 *manager_; diff --git a/man/waybar-wlr-taskbar.5.scd b/man/waybar-wlr-taskbar.5.scd index b2946ac5..1fba397c 100644 --- a/man/waybar-wlr-taskbar.5.scd +++ b/man/waybar-wlr-taskbar.5.scd @@ -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 diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index ddc360bb..d38646e5 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -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,7 +805,19 @@ Taskbar::~Taskbar() void Taskbar::update() { - for (auto& t : tasks_) { + 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(); }