Merge pull request #2268 from zjeffer/hyprland/workspaces
Fixes for hyprland/workspacespull/2274/head
commit
0bfb29789c
|
@ -84,30 +84,27 @@ auto Window::update() -> void {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Window::getActiveWorkspace() -> Workspace {
|
auto Window::getActiveWorkspace() -> Workspace {
|
||||||
const auto workspace = gIPC->getSocket1Reply("j/activeworkspace");
|
const auto workspace = gIPC->getSocket1JsonReply("activeworkspace");
|
||||||
Json::Value json = parser_.parse(workspace);
|
assert(workspace.isObject());
|
||||||
assert(json.isObject());
|
return Workspace::parse(workspace);
|
||||||
return Workspace::parse(json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace {
|
auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace {
|
||||||
const auto monitors = gIPC->getSocket1Reply("j/monitors");
|
const auto monitors = gIPC->getSocket1JsonReply("monitors");
|
||||||
Json::Value json = parser_.parse(monitors);
|
assert(monitors.isArray());
|
||||||
assert(json.isArray());
|
auto monitor = std::find_if(monitors.begin(), monitors.end(),
|
||||||
auto monitor = std::find_if(json.begin(), json.end(),
|
|
||||||
[&](Json::Value monitor) { return monitor["name"] == monitorName; });
|
[&](Json::Value monitor) { return monitor["name"] == monitorName; });
|
||||||
if (monitor == std::end(json)) {
|
if (monitor == std::end(monitors)) {
|
||||||
spdlog::warn("Monitor not found: {}", monitorName);
|
spdlog::warn("Monitor not found: {}", monitorName);
|
||||||
return Workspace{-1, 0, "", ""};
|
return Workspace{-1, 0, "", ""};
|
||||||
}
|
}
|
||||||
const int id = (*monitor)["activeWorkspace"]["id"].asInt();
|
const int id = (*monitor)["activeWorkspace"]["id"].asInt();
|
||||||
|
|
||||||
const auto workspaces = gIPC->getSocket1Reply("j/workspaces");
|
const auto workspaces = gIPC->getSocket1JsonReply("workspaces");
|
||||||
json = parser_.parse(workspaces);
|
assert(workspaces.isArray());
|
||||||
assert(json.isArray());
|
auto workspace = std::find_if(monitors.begin(), monitors.end(),
|
||||||
auto workspace = std::find_if(json.begin(), json.end(),
|
|
||||||
[&](Json::Value workspace) { return workspace["id"] == id; });
|
[&](Json::Value workspace) { return workspace["id"] == id; });
|
||||||
if (workspace == std::end(json)) {
|
if (workspace == std::end(monitors)) {
|
||||||
spdlog::warn("No workspace with id {}", id);
|
spdlog::warn("No workspace with id {}", id);
|
||||||
return Workspace{-1, 0, "", ""};
|
return Workspace{-1, 0, "", ""};
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,10 @@ void Workspaces::onEvent(const std::string &ev) {
|
||||||
} else if (eventName == "destroyworkspace") {
|
} else if (eventName == "destroyworkspace") {
|
||||||
int deleted_workspace_id;
|
int deleted_workspace_id;
|
||||||
std::from_chars(payload.data(), payload.data() + payload.size(), deleted_workspace_id);
|
std::from_chars(payload.data(), payload.data() + payload.size(), deleted_workspace_id);
|
||||||
workspaces_.erase(std::remove_if(workspaces_.begin(), workspaces_.end(),
|
auto workspace = std::find_if(workspaces_.begin(), workspaces_.end(),
|
||||||
[&](Workspace &x) { return x.id() == deleted_workspace_id; }));
|
[&](Workspace &x) { return x.id() == deleted_workspace_id; });
|
||||||
|
box_.remove(workspace->button());
|
||||||
|
workspaces_.erase(workspace);
|
||||||
} else if (eventName == "createworkspace") {
|
} else if (eventName == "createworkspace") {
|
||||||
int new_workspace_id;
|
int new_workspace_id;
|
||||||
std::from_chars(payload.data(), payload.data() + payload.size(), new_workspace_id);
|
std::from_chars(payload.data(), payload.data() + payload.size(), new_workspace_id);
|
||||||
|
|
Loading…
Reference in New Issue