Skip to content

Commit

Permalink
Merge pull request #2540 from Syndelis/fix/hyprland-special-workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexays committed Sep 25, 2023
2 parents 16f6d9d + 9a3238c commit 4c0347d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/modules/hyprland/workspaces.cpp
Expand Up @@ -134,6 +134,14 @@ auto Workspaces::update() -> void {
AModule::update();
}

bool isDoubleSpecial(std::string &workspace_name) {
// Hyprland's IPC sometimes reports the creation of workspaces strangely named
// `special:special:<some_name>`. This function checks for that and is used
// to avoid creating (and then removing) such workspaces.
// See hyprwm/Hyprland#3424 for more info.
return workspace_name.find("special:special:") != std::string::npos;
}

void Workspaces::onEvent(const std::string &ev) {
std::lock_guard<std::mutex> lock(mutex_);
std::string eventName(begin(ev), begin(ev) + ev.find_first_of('>'));
Expand All @@ -143,15 +151,16 @@ void Workspaces::onEvent(const std::string &ev) {
active_workspace_name_ = payload;

} else if (eventName == "destroyworkspace") {
workspaces_to_remove_.push_back(payload);

if (!isDoubleSpecial(payload)) {
workspaces_to_remove_.push_back(payload);
}
} else if (eventName == "createworkspace") {
const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces");
for (Json::Value workspace_json : workspaces_json) {
std::string name = workspace_json["name"].asString();
if (name == payload &&
(all_outputs() || bar_.output->name == workspace_json["monitor"].asString()) &&
(show_special() || !name.starts_with("special"))) {
(show_special() || !name.starts_with("special")) && !isDoubleSpecial(payload)) {
workspaces_to_create_.push_back(workspace_json);
break;
}
Expand Down Expand Up @@ -238,8 +247,10 @@ void Workspaces::create_workspace(Json::Value &value) {
}

void Workspaces::remove_workspace(std::string name) {
auto workspace = std::find_if(workspaces_.begin(), workspaces_.end(),
[&](std::unique_ptr<Workspace> &x) { return x->name() == name; });
auto workspace =
std::find_if(workspaces_.begin(), workspaces_.end(), [&](std::unique_ptr<Workspace> &x) {
return (name.starts_with("special:") && name.substr(8) == x->name()) || name == x->name();
});

if (workspace == workspaces_.end()) {
// happens when a workspace on another monitor is destroyed
Expand Down

0 comments on commit 4c0347d

Please sign in to comment.