hyprland add urgent ipc support

pull/2429/head
Austin Horstman 2023-08-23 12:18:35 -05:00
parent 3081b0c576
commit ee4fbc58f7
No known key found for this signature in database
3 changed files with 31 additions and 0 deletions

View File

@ -22,10 +22,12 @@ class Workspace {
bool is_special() const { return is_special_; }; bool is_special() const { return is_special_; };
bool is_persistent() const { return is_persistent_; }; bool is_persistent() const { return is_persistent_; };
bool is_empty() const { return windows_ == 0; }; bool is_empty() const { return windows_ == 0; };
bool is_urgent() const { return is_urgent_; };
auto handle_clicked(GdkEventButton* bt) -> bool; auto handle_clicked(GdkEventButton* bt) -> bool;
void set_active(bool value = true) { active_ = value; }; void set_active(bool value = true) { active_ = value; };
void set_persistent(bool value = true) { is_persistent_ = value; }; void set_persistent(bool value = true) { is_persistent_ = value; };
void set_urgent(bool value = true) { is_urgent_ = value; };
void set_windows(uint value) { windows_ = value; }; void set_windows(uint value) { windows_ = value; };
void update(const std::string& format, const std::string& icon); void update(const std::string& format, const std::string& icon);
@ -38,6 +40,7 @@ class Workspace {
bool active_ = false; bool active_ = false;
bool is_special_ = false; bool is_special_ = false;
bool is_persistent_ = false; bool is_persistent_ = false;
bool is_urgent_ = false;
Gtk::Button button_; Gtk::Button button_;
Gtk::Box content_; Gtk::Box content_;
@ -62,6 +65,7 @@ class Workspaces : public AModule, public EventHandler {
void sort_workspaces(); void sort_workspaces();
void create_workspace(Json::Value& value); void create_workspace(Json::Value& value);
void remove_workspace(std::string name); void remove_workspace(std::string name);
void set_urgent_workspace(std::string windowaddress);
bool all_outputs_ = false; bool all_outputs_ = false;
bool show_special_ = false; bool show_special_ = false;

View File

@ -76,3 +76,4 @@ Additional to workspace name matching, the following *format-icons* can be set.
- *#workspaces button.active* - *#workspaces button.active*
- *#workspaces button.persistent* - *#workspaces button.persistent*
- *#workspaces button.special* - *#workspaces button.special*
- *#workspaces button.urgent*

View File

@ -58,6 +58,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
gIPC->registerForIPC("openwindow", this); gIPC->registerForIPC("openwindow", this);
gIPC->registerForIPC("closewindow", this); gIPC->registerForIPC("closewindow", this);
gIPC->registerForIPC("movewindow", this); gIPC->registerForIPC("movewindow", this);
gIPC->registerForIPC("urgent", this);
} }
auto Workspaces::update() -> void { auto Workspaces::update() -> void {
@ -75,6 +76,9 @@ auto Workspaces::update() -> void {
for (auto &workspace : workspaces_) { for (auto &workspace : workspaces_) {
workspace->set_active(workspace->name() == active_workspace_name_); workspace->set_active(workspace->name() == active_workspace_name_);
if (workspace->name() == active_workspace_name_ && workspace.get()->is_urgent()) {
workspace->set_urgent(false);
}
std::string &workspace_icon = icons_map_[""]; std::string &workspace_icon = icons_map_[""];
if (with_icon_) { if (with_icon_) {
workspace_icon = workspace->select_icon(icons_map_); workspace_icon = workspace->select_icon(icons_map_);
@ -126,6 +130,8 @@ void Workspaces::onEvent(const std::string &ev) {
} }
} else if (eventName == "openwindow" || eventName == "closewindow" || eventName == "movewindow") { } else if (eventName == "openwindow" || eventName == "closewindow" || eventName == "movewindow") {
update_window_count(); update_window_count();
} else if (eventName == "urgent") {
set_urgent_workspace(payload);
} }
dp.emit(); dp.emit();
@ -323,6 +329,7 @@ void Workspace::update(const std::string &format, const std::string &icon) {
add_or_remove_class(style_context, active(), "active"); add_or_remove_class(style_context, active(), "active");
add_or_remove_class(style_context, is_special(), "special"); add_or_remove_class(style_context, is_special(), "special");
add_or_remove_class(style_context, is_empty(), "persistent"); add_or_remove_class(style_context, is_empty(), "persistent");
add_or_remove_class(style_context, is_urgent(), "urgent");
label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()), label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()),
fmt::arg("name", name()), fmt::arg("icon", icon))); fmt::arg("name", name()), fmt::arg("icon", icon)));
@ -419,4 +426,23 @@ auto Workspace::handle_clicked(GdkEventButton *bt) -> bool {
return false; return false;
} }
void Workspaces::set_urgent_workspace(std::string windowaddress) {
const Json::Value clients_json = gIPC->getSocket1JsonReply("clients");
int workspace_id;
for (Json::Value client_json : clients_json) {
if (client_json["address"].asString().ends_with(windowaddress)) {
workspace_id = client_json["workspace"]["id"].asInt();
break;
}
}
auto workspace =
std::find_if(workspaces_.begin(), workspaces_.end(),
[&](std::unique_ptr<Workspace> &x) { return x->id() == workspace_id; });
if (workspace->get() != nullptr) {
workspace->get()->set_urgent();
}
}
} // namespace waybar::modules::hyprland } // namespace waybar::modules::hyprland