workspace taskbars: Allow custom command on window click
This commit is contained in:
@ -49,6 +49,7 @@ class Workspaces : public AModule, public EventHandler {
|
|||||||
auto taskbarFormatAfter() const -> std::string { return m_taskbarFormatAfter; }
|
auto taskbarFormatAfter() const -> std::string { return m_taskbarFormatAfter; }
|
||||||
auto taskbarIconSize() const -> int { return m_taskbarIconSize; }
|
auto taskbarIconSize() const -> int { return m_taskbarIconSize; }
|
||||||
auto taskbarOrientation() const -> Gtk::Orientation { return m_taskbarOrientation; }
|
auto taskbarOrientation() const -> Gtk::Orientation { return m_taskbarOrientation; }
|
||||||
|
auto onClickWindow() const -> std::string { return m_onClickWindow; }
|
||||||
|
|
||||||
std::string getRewrite(std::string window_class, std::string window_title);
|
std::string getRewrite(std::string window_class, std::string window_title);
|
||||||
std::string& getWindowSeparator() { return m_formatWindowSeparator; }
|
std::string& getWindowSeparator() { return m_formatWindowSeparator; }
|
||||||
@ -166,6 +167,7 @@ class Workspaces : public AModule, public EventHandler {
|
|||||||
std::string m_taskbarFormatAfter;
|
std::string m_taskbarFormatAfter;
|
||||||
int m_taskbarIconSize = 16;
|
int m_taskbarIconSize = 16;
|
||||||
Gtk::Orientation m_taskbarOrientation = Gtk::ORIENTATION_HORIZONTAL;
|
Gtk::Orientation m_taskbarOrientation = Gtk::ORIENTATION_HORIZONTAL;
|
||||||
|
std::string m_onClickWindow;
|
||||||
|
|
||||||
std::vector<std::regex> m_ignoreWorkspaces;
|
std::vector<std::regex> m_ignoreWorkspaces;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "modules/hyprland/workspaces.hpp"
|
#include "modules/hyprland/workspaces.hpp"
|
||||||
|
#include "util/command.hpp"
|
||||||
#include "util/icon_loader.hpp"
|
#include "util/icon_loader.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::hyprland {
|
namespace waybar::modules::hyprland {
|
||||||
@ -251,8 +252,10 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
|||||||
window_box->get_style_context()->add_class("taskbar-window");
|
window_box->get_style_context()->add_class("taskbar-window");
|
||||||
auto event_box = Gtk::manage(new Gtk::EventBox());
|
auto event_box = Gtk::manage(new Gtk::EventBox());
|
||||||
event_box->add(*window_box);
|
event_box->add(*window_box);
|
||||||
event_box->signal_button_press_event().connect(
|
if (m_workspaceManager.onClickWindow() != "") {
|
||||||
sigc::bind(sigc::mem_fun(*this, &Workspace::handleClick), window_repr.address));
|
event_box->signal_button_press_event().connect(
|
||||||
|
sigc::bind(sigc::mem_fun(*this, &Workspace::handleClick), window_repr.address));
|
||||||
|
}
|
||||||
|
|
||||||
auto text_before = fmt::format(fmt::runtime(m_workspaceManager.taskbarFormatBefore()),
|
auto text_before = fmt::format(fmt::runtime(m_workspaceManager.taskbarFormatBefore()),
|
||||||
fmt::arg("title", window_repr.window_title));
|
fmt::arg("title", window_repr.window_title));
|
||||||
@ -292,7 +295,12 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
|||||||
|
|
||||||
bool Workspace::handleClick(const GdkEventButton *event_button, WindowAddress const &addr) const {
|
bool Workspace::handleClick(const GdkEventButton *event_button, WindowAddress const &addr) const {
|
||||||
if (event_button->type == GDK_BUTTON_PRESS) {
|
if (event_button->type == GDK_BUTTON_PRESS) {
|
||||||
IPC::getSocket1Reply("dispatch focuswindow address:0x" + addr);
|
std::string command = std::regex_replace(m_workspaceManager.onClickWindow(),
|
||||||
|
std::regex("\\{address\\}"), "0x" + addr);
|
||||||
|
auto res = util::command::execNoRead(command);
|
||||||
|
if (res.exit_code != 0) {
|
||||||
|
spdlog::error("Failed to execute {}: {}", command, res.out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -705,6 +705,10 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo
|
|||||||
toLower(workspaceTaskbar["orientation"].asString()) == "vertical") {
|
toLower(workspaceTaskbar["orientation"].asString()) == "vertical") {
|
||||||
m_taskbarOrientation = Gtk::ORIENTATION_VERTICAL;
|
m_taskbarOrientation = Gtk::ORIENTATION_VERTICAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (workspaceTaskbar["on-click-window"].isString()) {
|
||||||
|
m_onClickWindow = workspaceTaskbar["on-click-window"].asString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Workspaces::registerOrphanWindow(WindowCreationPayload create_window_payload) {
|
void Workspaces::registerOrphanWindow(WindowCreationPayload create_window_payload) {
|
||||||
|
Reference in New Issue
Block a user