mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 18:46:00 +01:00
parent
00ee1cf98e
commit
d105c7403c
1 changed files with 63 additions and 32 deletions
|
@ -1141,15 +1141,9 @@ std::string switchXKBLayoutRequest(eHyprCtlOutputFormat format, std::string requ
|
|||
const auto KB = vars[1];
|
||||
const auto CMD = vars[2];
|
||||
|
||||
// get kb
|
||||
const auto PKEYBOARD = std::find_if(g_pInputManager->m_vKeyboards.begin(), g_pInputManager->m_vKeyboards.end(),
|
||||
[&](const auto& other) { return other->hlName == g_pInputManager->deviceNameToInternalString(KB); });
|
||||
|
||||
if (PKEYBOARD == g_pInputManager->m_vKeyboards.end())
|
||||
return "device not found";
|
||||
|
||||
const auto KEEB = *PKEYBOARD;
|
||||
SP<IKeyboard> pKeyboard;
|
||||
|
||||
auto updateKeyboard = [](const SP<IKeyboard> KEEB, const std::string& CMD) -> std::optional<std::string> {
|
||||
const auto LAYOUTS = xkb_keymap_num_layouts(KEEB->xkbKeymap);
|
||||
xkb_layout_index_t activeLayout = 0;
|
||||
while (activeLayout < LAYOUTS) {
|
||||
|
@ -1176,6 +1170,43 @@ std::string switchXKBLayoutRequest(eHyprCtlOutputFormat format, std::string requ
|
|||
KEEB->updateModifiers(KEEB->modifiersState.depressed, KEEB->modifiersState.latched, KEEB->modifiersState.locked, requestedLayout);
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
};
|
||||
|
||||
if (KB == "main" || KB == "active" || KB == "current") {
|
||||
for (auto const& k : g_pInputManager->m_vKeyboards) {
|
||||
if (!k->active)
|
||||
continue;
|
||||
|
||||
pKeyboard = k;
|
||||
break;
|
||||
}
|
||||
} else if (KB == "all") {
|
||||
std::string result = "";
|
||||
for (auto const& k : g_pInputManager->m_vKeyboards) {
|
||||
auto res = updateKeyboard(k, CMD);
|
||||
if (res.has_value())
|
||||
result += *res + "\n";
|
||||
}
|
||||
return result.empty() ? "ok" : result;
|
||||
} else {
|
||||
auto k = std::find_if(g_pInputManager->m_vKeyboards.begin(), g_pInputManager->m_vKeyboards.end(),
|
||||
[&](const auto& other) { return other->hlName == g_pInputManager->deviceNameToInternalString(KB); });
|
||||
|
||||
if (k == g_pInputManager->m_vKeyboards.end())
|
||||
return "device not found";
|
||||
|
||||
pKeyboard = *k;
|
||||
}
|
||||
|
||||
if (!pKeyboard)
|
||||
return "no device";
|
||||
|
||||
auto result = updateKeyboard(pKeyboard, CMD);
|
||||
|
||||
if (result.has_value())
|
||||
return *result;
|
||||
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue