Merge pull request #1809 from herlev/hyprland-named-workspace-crash

pull/1810/head
Alex 2022-11-24 07:46:17 +01:00 committed by GitHub
commit 74fa131ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -18,8 +18,8 @@ class Window : public waybar::ALabel,
auto update() -> void; auto update() -> void;
private: private:
uint getActiveWorkspaceID(std::string); int getActiveWorkspaceID(std::string);
std::string getLastWindowTitle(uint); std::string getLastWindowTitle(int);
void onEvent(const std::string&); void onEvent(const std::string&);
bool separate_outputs; bool separate_outputs;

View File

@ -49,7 +49,7 @@ auto Window::update() -> void {
ALabel::update(); ALabel::update();
} }
uint Window::getActiveWorkspaceID(std::string monitorName) { int Window::getActiveWorkspaceID(std::string monitorName) {
auto cmd = waybar::util::command::exec("hyprctl monitors -j"); auto cmd = waybar::util::command::exec("hyprctl monitors -j");
assert(cmd.exit_code == 0); assert(cmd.exit_code == 0);
Json::Value json = parser_.parse(cmd.out); Json::Value json = parser_.parse(cmd.out);
@ -59,16 +59,16 @@ uint Window::getActiveWorkspaceID(std::string monitorName) {
if (monitor == std::end(json)) { if (monitor == std::end(json)) {
return 0; return 0;
} }
return (*monitor)["activeWorkspace"]["id"].as<uint>(); return (*monitor)["activeWorkspace"]["id"].as<int>();
} }
std::string Window::getLastWindowTitle(uint workspaceID) { std::string Window::getLastWindowTitle(int workspaceID) {
auto cmd = waybar::util::command::exec("hyprctl workspaces -j"); auto cmd = waybar::util::command::exec("hyprctl workspaces -j");
assert(cmd.exit_code == 0); assert(cmd.exit_code == 0);
Json::Value json = parser_.parse(cmd.out); Json::Value json = parser_.parse(cmd.out);
assert(json.isArray()); assert(json.isArray());
auto workspace = std::find_if(json.begin(), json.end(), [&](Json::Value workspace) { auto workspace = std::find_if(json.begin(), json.end(), [&](Json::Value workspace) {
return workspace["id"].as<uint>() == workspaceID; return workspace["id"].as<int>() == workspaceID;
}); });
if (workspace == std::end(json)) { if (workspace == std::end(json)) {

View File

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include <stdexcept>
#include <vector> #include <vector>
#include "gtkmm/widget.h" #include "gtkmm/widget.h"
@ -66,10 +67,13 @@ auto WorkspaceManager::workspace_comparator() const
auto is_name_less = lhs->get_name() < rhs->get_name(); auto is_name_less = lhs->get_name() < rhs->get_name();
auto is_name_eq = lhs->get_name() == rhs->get_name(); auto is_name_eq = lhs->get_name() == rhs->get_name();
auto is_coords_less = lhs->get_coords() < rhs->get_coords(); auto is_coords_less = lhs->get_coords() < rhs->get_coords();
auto is_number_less = std::stoi(lhs->get_name()) < std::stoi(rhs->get_name());
if (sort_by_number_) { if (sort_by_number_) {
try {
auto is_number_less = std::stoi(lhs->get_name()) < std::stoi(rhs->get_name());
return is_number_less; return is_number_less;
} catch (std::invalid_argument) {
}
} }
if (sort_by_name_) { if (sort_by_name_) {