Merge pull request #3440 from khaneliman/hyprland-fix

hyprland/window: fix crash when no return from socket
This commit is contained in:
Alexis Rouillard 2024-07-15 19:16:06 +02:00 committed by GitHub
commit 5f3a9d9423
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 78 additions and 70 deletions

View File

@ -18,11 +18,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1719506693,
"narHash": "sha256-C8e9S7RzshSdHB7L+v9I51af1gDM5unhJ2xO1ywxNH8=",
"lastModified": 1720957393,
"narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b2852eb9365c6de48ffb0dc2c9562591f652242a",
"rev": "693bc46d169f5af9c992095736e82c3488bf7dbb",
"type": "github"
},
"original": {

View File

@ -123,7 +123,8 @@ void waybar::Client::handleMonitorAdded(Glib::RefPtr<Gdk::Monitor> monitor) {
}
void waybar::Client::handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor) {
spdlog::debug("Output removed: {} {}", monitor->get_manufacturer().c_str(), monitor->get_model().c_str());
spdlog::debug("Output removed: {} {}", monitor->get_manufacturer().c_str(),
monitor->get_model().c_str());
/* This event can be triggered from wl_display_roundtrip called by GTK or our code.
* Defer destruction of bars for the output to the next iteration of the event loop to avoid
* deleting objects referenced by currently executed code.

View File

@ -92,15 +92,20 @@ auto Window::update() -> void {
auto Window::getActiveWorkspace() -> Workspace {
const auto workspace = gIPC->getSocket1JsonReply("activeworkspace");
assert(workspace.isObject());
if (workspace.isObject()) {
return Workspace::parse(workspace);
}
return {};
}
auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace {
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 (monitors.isArray()) {
auto monitor = std::find_if(monitors.begin(), monitors.end(), [&](Json::Value monitor) {
return monitor["name"] == monitorName;
});
if (monitor == std::end(monitors)) {
spdlog::warn("Monitor not found: {}", monitorName);
return Workspace{-1, 0, "", ""};
@ -108,7 +113,7 @@ auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace {
const int id = (*monitor)["activeWorkspace"]["id"].asInt();
const auto workspaces = gIPC->getSocket1JsonReply("workspaces");
assert(workspaces.isArray());
if (workspaces.isArray()) {
auto workspace = std::find_if(workspaces.begin(), workspaces.end(),
[&](Json::Value workspace) { return workspace["id"] == id; });
if (workspace == std::end(workspaces)) {
@ -116,6 +121,10 @@ auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace {
return Workspace{-1, 0, "", ""};
}
return Workspace::parse(*workspace);
};
};
return {};
}
auto Window::Workspace::parse(const Json::Value& value) -> Window::Workspace {
@ -146,7 +155,7 @@ void Window::queryActiveWorkspace() {
focused_ = true;
if (workspace_.windows > 0) {
const auto clients = gIPC->getSocket1JsonReply("clients");
assert(clients.isArray());
if (clients.isArray()) {
auto activeWindow = std::find_if(clients.begin(), clients.end(), [&](Json::Value window) {
return window["address"] == workspace_.last_window;
});
@ -193,6 +202,7 @@ void Window::queryActiveWorkspace() {
} else {
soloClass_ = "";
}
};
} else {
focused_ = false;
windowData_ = WindowData{};

View File

@ -845,11 +845,8 @@ void waybar::modules::Network::parseBssid(struct nlattr **bss) {
auto bssid = static_cast<uint8_t *>(nla_data(bss[NL80211_BSS_BSSID]));
auto bssid_len = nla_len(bss[NL80211_BSS_BSSID]);
if (bssid_len == 6) {
bssid_ = std::format(
"{:x}:{:x}:{:x}:{:x}:{:x}:{:x}",
bssid[0], bssid[1], bssid[2],
bssid[3], bssid[4], bssid[5]
);
bssid_ = fmt::format("{:x}:{:x}:{:x}:{:x}:{:x}:{:x}", bssid[0], bssid[1], bssid[2], bssid[3],
bssid[4], bssid[5]);
}
}
}