fix: length_error thrown in handleOutputDescription

This commit is contained in:
peelz
2025-06-13 22:51:03 -04:00
parent 2c482a2917
commit f4496c9648

View File

@ -106,11 +106,11 @@ void waybar::Client::handleOutputDescription(void *data, struct zxdg_output_v1 *
auto *client = waybar::Client::inst(); auto *client = waybar::Client::inst();
try { try {
auto &output = client->getOutput(data); auto &output = client->getOutput(data);
const char *open_paren = strrchr(description, '(');
// Description format: "identifier (name)" // Description format: "identifier (name)"
size_t identifier_length = open_paren - description; auto s = std::string(description);
output.identifier = std::string(description, identifier_length - 1); auto pos = s.find(" (");
output.identifier = pos != std::string::npos ? s.substr(0, pos) : s;
} catch (const std::exception &e) { } catch (const std::exception &e) {
std::cerr << e.what() << '\n'; std::cerr << e.what() << '\n';
} }