diff --git a/include/modules/wlr/taskbar.hpp b/include/modules/wlr/taskbar.hpp index 4465dd06e5..e55e5c7da5 100644 --- a/include/modules/wlr/taskbar.hpp +++ b/include/modules/wlr/taskbar.hpp @@ -140,6 +140,7 @@ class Taskbar : public waybar::AModule { Taskbar(const std::string &, const waybar::Bar &, const Json::Value &); ~Taskbar(); void update(); + auto doAction(const std::string &) -> void override; private: const waybar::Bar &bar_; @@ -170,6 +171,7 @@ class Taskbar : public waybar::AModule { bool show_output(struct wl_output *) const; bool all_outputs() const; + bool legacy_event_config = false; const std::vector> &icon_themes() const; const std::unordered_set &ignore_list() const; diff --git a/man/waybar-wlr-taskbar.5.scd b/man/waybar-wlr-taskbar.5.scd index af1ba97f76..a2ebb95b1c 100644 --- a/man/waybar-wlr-taskbar.5.scd +++ b/man/waybar-wlr-taskbar.5.scd @@ -59,15 +59,15 @@ Addressed by *wlr/taskbar* *on-click*: ++ typeof: string ++ - The action which should be triggered when clicking on the application button with the left mouse button. + The action which should be triggered when clicking on the application button with the left mouse button. Needs to be defined in actions object. *on-click-middle*: ++ typeof: string ++ - The action which should be triggered when clicking on the application button with the middle mouse button. + The action which should be triggered when clicking on the application button with the middle mouse button. Needs to be defined in actions object. *on-click-right*: ++ typeof: string ++ - The action which should be triggered when clicking on the application button with the right mouse button. + The action which should be triggered when clicking on the application button with the right mouse button. Needs to be defined in actions object. *on-update*: ++ typeof: string ++ @@ -133,8 +133,10 @@ Invalid expressions (e.g., mismatched parentheses) are skipped. "icon-size": 14, "icon-theme": "Numix-Circle", "tooltip-format": "{title}", - "on-click": "activate", - "on-click-middle": "close", + "actions" : { + "on-click": "activate", + "on-click-middle": "close", + }, "ignore-list": [ "Alacritty" ], diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index e6c8e536c7..ef95ba9824 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -328,11 +328,6 @@ Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar, format_tooltip_ = "{title}"; } - /* Handle click events if configured */ - if (config_["on-click"].isString() || config_["on-click-middle"].isString() || - config_["on-click-right"].isString()) { - } - button.add_events(Gdk::BUTTON_PRESS_MASK); button.signal_button_release_event().connect(sigc::mem_fun(*this, &Task::handle_clicked), false); @@ -542,12 +537,20 @@ bool Task::handle_clicked(GdkEventButton *bt) { } std::string action; - if (config_["on-click"].isString() && bt->button == 1) - action = config_["on-click"].asString(); - else if (config_["on-click-middle"].isString() && bt->button == 2) - action = config_["on-click-middle"].asString(); - else if (config_["on-click-right"].isString() && bt->button == 3) - action = config_["on-click-right"].asString(); + auto cr = config_["actions"]; + if (!cr.isObject()) { + if (tbar_->legacy_event_config) { + cr = config_; + } else { + return false; + } + } + if (cr["on-click"].isString() && bt->button == 1) + action = cr["on-click"].asString(); + else if (cr["on-click-middle"].isString() && bt->button == 2) + action = cr["on-click-middle"].asString(); + else if (cr["on-click-right"].isString() && bt->button == 3) + action = cr["on-click-right"].asString(); if (action.empty()) return true; @@ -787,6 +790,19 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu } } + if (config_["on-click"]) { + legacy_event_config = true; + spdlog::warn("wlr/taskbar: on-click should be within actions object"); + } + if (config_["on-click-right"]) { + legacy_event_config = true; + spdlog::warn("wlr/taskbar: on-click-right should be within actions object"); + } + if (config_["on-click-middle"]) { + legacy_event_config = true; + spdlog::warn("wlr/taskbar: on-click-middle should be within actions object"); + } + icon_themes_.push_back(Gtk::IconTheme::get_default()); for (auto &t : tasks_) { @@ -846,6 +862,8 @@ static const struct zwlr_foreign_toplevel_manager_v1_listener toplevel_manager_i .finished = tm_handle_finished, }; +auto Taskbar::doAction(const std::string &name) -> void {} + void Taskbar::register_manager(struct wl_registry *registry, uint32_t name, uint32_t version) { if (manager_) { spdlog::warn("Register foreign toplevel manager again although already existing!");