mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 15:05:59 +01:00
Handle keyboards better
Also fixes some crashes of apps on reload
This commit is contained in:
parent
10c2bd0686
commit
1a93b2a756
3 changed files with 40 additions and 20 deletions
|
@ -69,6 +69,8 @@ struct SKeyboard {
|
||||||
DYNLISTENER(keyboardKey);
|
DYNLISTENER(keyboardKey);
|
||||||
DYNLISTENER(keyboardDestroy);
|
DYNLISTENER(keyboardDestroy);
|
||||||
|
|
||||||
|
bool active = false;
|
||||||
|
|
||||||
// For the list lookup
|
// For the list lookup
|
||||||
bool operator==(const SKeyboard& rhs) {
|
bool operator==(const SKeyboard& rhs) {
|
||||||
return keyboard == rhs.keyboard;
|
return keyboard == rhs.keyboard;
|
||||||
|
|
|
@ -253,6 +253,10 @@ void CInputManager::newKeyboard(wlr_input_device* keyboard) {
|
||||||
PNEWKEYBOARD->hyprListener_keyboardKey.initCallback(&keyboard->keyboard->events.key, &Events::listener_keyboardKey, PNEWKEYBOARD, "Keyboard");
|
PNEWKEYBOARD->hyprListener_keyboardKey.initCallback(&keyboard->keyboard->events.key, &Events::listener_keyboardKey, PNEWKEYBOARD, "Keyboard");
|
||||||
PNEWKEYBOARD->hyprListener_keyboardDestroy.initCallback(&keyboard->events.destroy, &Events::listener_keyboardDestroy, PNEWKEYBOARD, "Keyboard");
|
PNEWKEYBOARD->hyprListener_keyboardDestroy.initCallback(&keyboard->events.destroy, &Events::listener_keyboardDestroy, PNEWKEYBOARD, "Keyboard");
|
||||||
|
|
||||||
|
if (m_pActiveKeyboard)
|
||||||
|
m_pActiveKeyboard->active = false;
|
||||||
|
m_pActiveKeyboard = PNEWKEYBOARD;
|
||||||
|
|
||||||
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, keyboard->keyboard);
|
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, keyboard->keyboard);
|
||||||
|
|
||||||
Debug::log(LOG, "New keyboard created, pointers Hypr: %x and WLR: %x", PNEWKEYBOARD, keyboard);
|
Debug::log(LOG, "New keyboard created, pointers Hypr: %x and WLR: %x", PNEWKEYBOARD, keyboard);
|
||||||
|
@ -287,28 +291,29 @@ void CInputManager::setKeyboardLayout() {
|
||||||
|
|
||||||
const auto PLASTKEEB = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat);
|
const auto PLASTKEEB = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat);
|
||||||
|
|
||||||
// TODO: configure devices one by one
|
if (!PLASTKEEB) {
|
||||||
for (auto& k : m_lKeyboards) {
|
xkb_keymap_unref(KEYMAP);
|
||||||
wlr_keyboard_set_keymap(k.keyboard->keyboard, KEYMAP);
|
xkb_context_unref(CONTEXT);
|
||||||
|
|
||||||
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, k.keyboard->keyboard);
|
Debug::log(ERR, "No Seat Keyboard???");
|
||||||
|
return;
|
||||||
wlr_keyboard_modifiers wlrMods = {0};
|
|
||||||
|
|
||||||
if (g_pConfigManager->getInt("input:numlock_by_default") == 1) {
|
|
||||||
// lock numlock
|
|
||||||
const auto IDX = xkb_map_mod_get_index(KEYMAP, XKB_MOD_NAME_NUM);
|
|
||||||
|
|
||||||
if (IDX != XKB_MOD_INVALID)
|
|
||||||
wlrMods.locked |= (uint32_t)1 << IDX;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wlrMods.locked != 0) {
|
|
||||||
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &wlrMods);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, PLASTKEEB);
|
wlr_keyboard_set_keymap(PLASTKEEB, KEYMAP);
|
||||||
|
|
||||||
|
wlr_keyboard_modifiers wlrMods = {0};
|
||||||
|
|
||||||
|
if (g_pConfigManager->getInt("input:numlock_by_default") == 1) {
|
||||||
|
// lock numlock
|
||||||
|
const auto IDX = xkb_map_mod_get_index(KEYMAP, XKB_MOD_NAME_NUM);
|
||||||
|
|
||||||
|
if (IDX != XKB_MOD_INVALID)
|
||||||
|
wlrMods.locked |= (uint32_t)1 << IDX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wlrMods.locked != 0) {
|
||||||
|
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &wlrMods);
|
||||||
|
}
|
||||||
|
|
||||||
xkb_keymap_unref(KEYMAP);
|
xkb_keymap_unref(KEYMAP);
|
||||||
xkb_context_unref(CONTEXT);
|
xkb_context_unref(CONTEXT);
|
||||||
|
@ -351,6 +356,17 @@ void CInputManager::destroyKeyboard(SKeyboard* pKeyboard) {
|
||||||
pKeyboard->hyprListener_keyboardMod.removeCallback();
|
pKeyboard->hyprListener_keyboardMod.removeCallback();
|
||||||
pKeyboard->hyprListener_keyboardKey.removeCallback();
|
pKeyboard->hyprListener_keyboardKey.removeCallback();
|
||||||
|
|
||||||
|
if (pKeyboard->active) {
|
||||||
|
m_lKeyboards.remove(*pKeyboard);
|
||||||
|
|
||||||
|
if (m_lKeyboards.size() > 0) {
|
||||||
|
m_pActiveKeyboard = &m_lKeyboards.back();
|
||||||
|
m_pActiveKeyboard->active = true;
|
||||||
|
} else {
|
||||||
|
m_pActiveKeyboard = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_lKeyboards.remove(*pKeyboard);
|
m_lKeyboards.remove(*pKeyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ public:
|
||||||
std::list<SKeyboard> m_lKeyboards;
|
std::list<SKeyboard> m_lKeyboards;
|
||||||
std::list<SMouse> m_lMice;
|
std::list<SMouse> m_lMice;
|
||||||
|
|
||||||
|
SKeyboard* m_pActiveKeyboard = nullptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void mouseMoveUnified(uint32_t, bool refocus = false);
|
void mouseMoveUnified(uint32_t, bool refocus = false);
|
||||||
|
|
Loading…
Reference in a new issue