Merge pull request #2268 from zjeffer/hyprland/workspaces

Fixes for hyprland/workspaces
This commit is contained in:
Alexis Rouillard 2023-07-02 11:45:09 +02:00 committed by GitHub
commit 0bfb29789c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 16 deletions

View File

@ -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, "", ""};
}

View File

@ -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);