Skip to content

Commit

Permalink
Merge pull request #2429 from khaneliman/hyprland-urgent
Browse files Browse the repository at this point in the history
Hyprland urgent class support
  • Loading branch information
Alexays authored Aug 24, 2023
2 parents b7a527b + ee4fbc5 commit b665843
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 36 deletions.
76 changes: 47 additions & 29 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,12 @@
let pkgs = import nixpkgs {
inherit system;

overlays = [ devshell.overlay ];
overlays = [ devshell.overlays.default ];
};
in
pkgs.devshell.mkShell {
imports = [ "${pkgs.devshell.extraModulesDir}/language/c.nix" ];
commands = [
{
package = pkgs.devshell.cli;
help = "Per project developer environments";
}
];

devshell.packages = with pkgs; [
clang-tools
gdb
Expand All @@ -79,6 +74,7 @@
at-spi2-atk atkmm cairo cairomm catch2 fmt_8 fontconfig
gdk-pixbuf glibmm gtk3 harfbuzz pango pangomm wayland-protocols
]);

env = with pkgs; [
{ name = "CPLUS_INCLUDE_PATH"; prefix = "$DEVSHELL_DIR/include"; }
{ name = "PKG_CONFIG_PATH"; prefix = "$DEVSHELL_DIR/lib/pkgconfig"; }
Expand Down
4 changes: 4 additions & 0 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ class Workspace {
bool is_special() const { return is_special_; };
bool is_persistent() const { return is_persistent_; };
bool is_empty() const { return windows_ == 0; };
bool is_urgent() const { return is_urgent_; };

auto handle_clicked(GdkEventButton* bt) -> bool;
void set_active(bool value = true) { active_ = 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 update(const std::string& format, const std::string& icon);
Expand All @@ -38,6 +40,7 @@ class Workspace {
bool active_ = false;
bool is_special_ = false;
bool is_persistent_ = false;
bool is_urgent_ = false;

Gtk::Button button_;
Gtk::Box content_;
Expand All @@ -62,6 +65,7 @@ class Workspaces : public AModule, public EventHandler {
void sort_workspaces();
void create_workspace(Json::Value& value);
void remove_workspace(std::string name);
void set_urgent_workspace(std::string windowaddress);

bool all_outputs_ = false;
bool show_special_ = false;
Expand Down
1 change: 1 addition & 0 deletions man/waybar-hyprland-workspaces.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ Additional to workspace name matching, the following *format-icons* can be set.
- *#workspaces button.active*
- *#workspaces button.persistent*
- *#workspaces button.special*
- *#workspaces button.urgent*
26 changes: 26 additions & 0 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
gIPC->registerForIPC("openwindow", this);
gIPC->registerForIPC("closewindow", this);
gIPC->registerForIPC("movewindow", this);
gIPC->registerForIPC("urgent", this);
}

auto Workspaces::update() -> void {
Expand All @@ -75,6 +76,9 @@ auto Workspaces::update() -> void {

for (auto &workspace : workspaces_) {
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_[""];
if (with_icon_) {
workspace_icon = workspace->select_icon(icons_map_);
Expand Down Expand Up @@ -126,6 +130,8 @@ void Workspaces::onEvent(const std::string &ev) {
}
} else if (eventName == "openwindow" || eventName == "closewindow" || eventName == "movewindow") {
update_window_count();
} else if (eventName == "urgent") {
set_urgent_workspace(payload);
}

dp.emit();
Expand Down Expand Up @@ -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, is_special(), "special");
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()),
fmt::arg("name", name()), fmt::arg("icon", icon)));
Expand Down Expand Up @@ -419,4 +426,23 @@ auto Workspace::handle_clicked(GdkEventButton *bt) -> bool {
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

0 comments on commit b665843

Please sign in to comment.