mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #2268 from zjeffer/hyprland/workspaces
Fixes for hyprland/workspaces
This commit is contained in:
commit
0bfb29789c
@ -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, "", ""};
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user