diff --git a/include/modules/hyprland/workspace.hpp b/include/modules/hyprland/workspace.hpp index 2dc9239b7..b5ff3b412 100644 --- a/include/modules/hyprland/workspace.hpp +++ b/include/modules/hyprland/workspace.hpp @@ -88,6 +88,7 @@ class Workspace { Gtk::Label m_labelAfter; void updateTaskbar(const std::string& workspace_icon); + static void focusWindow(WindowAddress const& addr); }; } // namespace waybar::modules::hyprland diff --git a/src/modules/hyprland/workspace.cpp b/src/modules/hyprland/workspace.cpp index 0baa67a80..0e33f6007 100644 --- a/src/modules/hyprland/workspace.cpp +++ b/src/modules/hyprland/workspace.cpp @@ -248,6 +248,18 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) { for (const auto &window_repr : m_windowMap) { auto window_box = Gtk::make_managed(Gtk::ORIENTATION_HORIZONTAL); window_box->set_tooltip_text(window_repr.window_title); + 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( + [window_repr](GdkEventButton const *bt) { + if (bt->type == GDK_BUTTON_PRESS) { + focusWindow(window_repr.address); + return true; + } + return false; + }, + false); auto text_before = fmt::format(fmt::runtime(m_workspaceManager.taskbarFormatBefore()), fmt::arg("title", window_repr.window_title)); @@ -271,8 +283,8 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) { window_box->pack_start(*window_label_after, true, true); } - m_content.pack_start(*window_box, true, false); - window_box->show_all(); + m_content.pack_start(*event_box, true, false); + event_box->show_all(); } auto formatAfter = m_workspaceManager.formatAfter(); @@ -285,4 +297,12 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) { } } +void Workspace::focusWindow(WindowAddress const &addr) { + try { + IPC::getSocket1Reply("dispatch focuswindow address:0x" + addr); + } catch (const std::exception &e) { + spdlog::error("Failed to dispatch window: {}", e.what()); + } +} + } // namespace waybar::modules::hyprland