From 7b854112edf7b2b3a487251ef24c1b1106669232 Mon Sep 17 00:00:00 2001 From: Pol Rivero <65060696+pol-rivero@users.noreply.github.com> Date: Fri, 24 Jan 2025 20:48:45 +0100 Subject: [PATCH] workspace taskbars: Allow custom command on window click --- include/modules/hyprland/workspaces.hpp | 2 ++ src/modules/hyprland/workspace.cpp | 14 +++++++++++--- src/modules/hyprland/workspaces.cpp | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index b31909ce..9c0a60ab 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -49,6 +49,7 @@ class Workspaces : public AModule, public EventHandler { auto taskbarFormatAfter() const -> std::string { return m_taskbarFormatAfter; } auto taskbarIconSize() const -> int { return m_taskbarIconSize; } 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& getWindowSeparator() { return m_formatWindowSeparator; } @@ -166,6 +167,7 @@ class Workspaces : public AModule, public EventHandler { std::string m_taskbarFormatAfter; int m_taskbarIconSize = 16; Gtk::Orientation m_taskbarOrientation = Gtk::ORIENTATION_HORIZONTAL; + std::string m_onClickWindow; std::vector m_ignoreWorkspaces; diff --git a/src/modules/hyprland/workspace.cpp b/src/modules/hyprland/workspace.cpp index 515ed18f..79075f21 100644 --- a/src/modules/hyprland/workspace.cpp +++ b/src/modules/hyprland/workspace.cpp @@ -6,6 +6,7 @@ #include #include "modules/hyprland/workspaces.hpp" +#include "util/command.hpp" #include "util/icon_loader.hpp" 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"); auto event_box = Gtk::manage(new Gtk::EventBox()); event_box->add(*window_box); - event_box->signal_button_press_event().connect( - sigc::bind(sigc::mem_fun(*this, &Workspace::handleClick), window_repr.address)); + if (m_workspaceManager.onClickWindow() != "") { + 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()), 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 { 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; } diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 0bee8446..2b4eda54 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -705,6 +705,10 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo toLower(workspaceTaskbar["orientation"].asString()) == "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) {