Minor refactorings and formatting fixes for hyprland language module

This commit is contained in:
Enes Hecan 2022-12-16 10:01:58 +01:00
parent bd199e414b
commit 4136ffaecb
1 changed files with 16 additions and 14 deletions

View File

@ -50,17 +50,17 @@ auto Language::update() -> void {
void Language::onEvent(const std::string& ev) {
std::lock_guard<std::mutex> lg(mutex_);
auto layoutName = ev.substr(ev.find_last_of(',') + 1);
auto keebName = ev.substr(0, ev.find_last_of(','));
keebName = keebName.substr(keebName.find_first_of('>') + 2);
auto kbName = ev.substr(0, ev.find_last_of(','));
kbName = kbName.substr(kbName.find_first_of('>') + 2);
if (config_.isMember("keyboard-name") && keebName != config_["keyboard-name"].asString())
if (config_.isMember("keyboard-name") && kbName != config_["keyboard-name"].asString())
return; // ignore
const auto BRIEFNAME = getShortFrom(layoutName);
const auto briefName = getShortFrom(layoutName);
if (config_.isMember("format-" + BRIEFNAME)) {
const auto PROPNAME = "format-" + BRIEFNAME;
layoutName = fmt::format(format_, config_[PROPNAME].asString());
if (config_.isMember("format-" + briefName)) {
const auto propName = "format-" + briefName;
layoutName = fmt::format(format_, config_[propName].asString());
} else {
layoutName = fmt::format(format_, layoutName);
}
@ -77,21 +77,23 @@ void Language::onEvent(const std::string& ev) {
}
void Language::initLanguage() {
const auto INPUTDEVICES = gIPC->getSocket1Reply("devices");
const auto inputDevices = gIPC->getSocket1Reply("devices");
const auto KEEBNAME = config_["keyboard-name"].asString();
const auto kbName = config_["keyboard-name"].asString();
try {
auto searcher = KEEBNAME.empty() ? INPUTDEVICES : INPUTDEVICES.substr(INPUTDEVICES.find(KEEBNAME) + KEEBNAME.length());
auto searcher = kbName.empty()
? inputDevices
: inputDevices.substr(inputDevices.find(kbName) + kbName.length());
searcher = searcher.substr(searcher.find("keymap:") + 8);
searcher = searcher.substr(0, searcher.find_first_of("\n\t"));
auto layoutName = std::string{};
const auto BRIEFNAME = getShortFrom(searcher);
const auto briefName = getShortFrom(searcher);
if (config_.isMember("format-" + BRIEFNAME)) {
const auto PROPNAME = "format-" + BRIEFNAME;
layoutName = fmt::format(format_, config_[PROPNAME].asString());
if (config_.isMember("format-" + briefName)) {
const auto propName = "format-" + briefName;
layoutName = fmt::format(format_, config_[propName].asString());
} else {
layoutName = fmt::format(format_, searcher);
}