Skip to content

Commit

Permalink
workspace taskbars: Focus window on click
Browse files Browse the repository at this point in the history
  • Loading branch information
pol-rivero committed Jan 4, 2025
1 parent 411f3ec commit 22fc31e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/modules/hyprland/workspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 22 additions & 2 deletions src/modules/hyprland/workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::Box>(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));
Expand All @@ -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();
Expand All @@ -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

0 comments on commit 22fc31e

Please sign in to comment.