refactor: sort-by enum hyprland

This commit is contained in:
Austin Horstman
2023-09-09 09:32:55 -05:00
parent 65ba449460
commit 8ea2626de8
3 changed files with 85 additions and 39 deletions

View File

@ -11,6 +11,7 @@
#include "AModule.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
#include "util/enum.hpp"
namespace waybar::modules::hyprland {
@ -86,7 +87,8 @@ class Workspaces : public AModule, public EventHandler {
bool all_outputs_ = false;
bool show_special_ = false;
bool active_only_ = false;
std::string sort_by = "default";
util::EnumParser enum_parser_;
util::EnumParser::SORT_METHOD sort_by_ = util::EnumParser::SORT_METHOD::DEFAULT;
void fill_persistent_workspaces();
void create_persistent_workspaces();

28
include/util/enum.hpp Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#include <iostream>
#include <map>
#include <string>
namespace waybar::util {
struct EnumParser {
EnumParser() {}
enum SORT_METHOD { ID, NAME, NUMBER, DEFAULT };
SORT_METHOD sortStringToEnum(const std::string& str) {
static const std::map<std::string, SORT_METHOD> enumMap = {
{"ID", ID}, {"NAME", NAME}, {"NUMBER", NUMBER}, {"DEFAULT", DEFAULT}};
auto it = enumMap.find(str);
if (it != enumMap.end()) {
return it->second;
} else {
throw std::invalid_argument("Invalid string representation for enum");
}
}
~EnumParser() = default;
};
} // namespace waybar::util