Skip to content

Commit

Permalink
Merge pull request #2268 from zjeffer/hyprland/workspaces
Browse files Browse the repository at this point in the history
Fixes for hyprland/workspaces
  • Loading branch information
Alexays authored Jul 2, 2023
2 parents b9cd028 + f6a62e2 commit 0bfb297
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
25 changes: 11 additions & 14 deletions src/modules/hyprland/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,27 @@ auto Window::update() -> void {
}

auto Window::getActiveWorkspace() -> Workspace {
const auto workspace = gIPC->getSocket1Reply("j/activeworkspace");
Json::Value json = parser_.parse(workspace);
assert(json.isObject());
return Workspace::parse(json);
const auto workspace = gIPC->getSocket1JsonReply("activeworkspace");
assert(workspace.isObject());
return Workspace::parse(workspace);
}

auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace {
const auto monitors = gIPC->getSocket1Reply("j/monitors");
Json::Value json = parser_.parse(monitors);
assert(json.isArray());
auto monitor = std::find_if(json.begin(), json.end(),
const auto monitors = gIPC->getSocket1JsonReply("monitors");
assert(monitors.isArray());
auto monitor = std::find_if(monitors.begin(), monitors.end(),
[&](Json::Value monitor) { return monitor["name"] == monitorName; });
if (monitor == std::end(json)) {
if (monitor == std::end(monitors)) {
spdlog::warn("Monitor not found: {}", monitorName);
return Workspace{-1, 0, "", ""};
}
const int id = (*monitor)["activeWorkspace"]["id"].asInt();

const auto workspaces = gIPC->getSocket1Reply("j/workspaces");
json = parser_.parse(workspaces);
assert(json.isArray());
auto workspace = std::find_if(json.begin(), json.end(),
const auto workspaces = gIPC->getSocket1JsonReply("workspaces");
assert(workspaces.isArray());
auto workspace = std::find_if(monitors.begin(), monitors.end(),
[&](Json::Value workspace) { return workspace["id"] == id; });
if (workspace == std::end(json)) {
if (workspace == std::end(monitors)) {
spdlog::warn("No workspace with id {}", id);
return Workspace{-1, 0, "", ""};
}
Expand Down
6 changes: 4 additions & 2 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ void Workspaces::onEvent(const std::string &ev) {
} else if (eventName == "destroyworkspace") {
int deleted_workspace_id;
std::from_chars(payload.data(), payload.data() + payload.size(), deleted_workspace_id);
workspaces_.erase(std::remove_if(workspaces_.begin(), workspaces_.end(),
[&](Workspace &x) { return x.id() == deleted_workspace_id; }));
auto workspace = std::find_if(workspaces_.begin(), workspaces_.end(),
[&](Workspace &x) { return x.id() == deleted_workspace_id; });
box_.remove(workspace->button());
workspaces_.erase(workspace);
} else if (eventName == "createworkspace") {
int new_workspace_id;
std::from_chars(payload.data(), payload.data() + payload.size(), new_workspace_id);
Expand Down

0 comments on commit 0bfb297

Please sign in to comment.