mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 02:25: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,11 +291,15 @@ 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_set_keymap(PLASTKEEB, KEYMAP);
|
||||||
|
|
||||||
wlr_keyboard_modifiers wlrMods = {0};
|
wlr_keyboard_modifiers wlrMods = {0};
|
||||||
|
|
||||||
|
@ -306,9 +314,6 @@ void CInputManager::setKeyboardLayout() {
|
||||||
if (wlrMods.locked != 0) {
|
if (wlrMods.locked != 0) {
|
||||||
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &wlrMods);
|
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &wlrMods);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, PLASTKEEB);
|
|
||||||
|
|
||||||
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