Skip to content

Commit

Permalink
seatmgr: fix missing nullcheck in updateActiveKeyboardData
Browse files Browse the repository at this point in the history
sometimes we may set a keyboard that's about-to-be-deleted, we might as well check for that

additionally avoid setting null keyboards altogether
  • Loading branch information
vaxerski committed Jun 12, 2024
1 parent c7e85e2 commit 9d7d5ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/managers/SeatManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void CSeatManager::setKeyboard(SP<IKeyboard> KEEB) {
}

void CSeatManager::updateActiveKeyboardData() {
if (keyboard)
if (keyboard && keyboard->wlr())
PROTO::seat->updateRepeatInfo(keyboard->wlr()->repeat_info.rate, keyboard->wlr()->repeat_info.delay);
PROTO::seat->updateKeymap();
}
Expand Down
18 changes: 13 additions & 5 deletions src/managers/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,12 +1226,20 @@ void CInputManager::destroyKeyboard(SP<IKeyboard> pKeyboard) {
std::erase_if(m_vKeyboards, [pKeyboard](const auto& other) { return other == pKeyboard; });

if (m_vKeyboards.size() > 0) {
const auto PNEWKEYBOARD = m_vKeyboards.back();
g_pSeatManager->setKeyboard(PNEWKEYBOARD);
PNEWKEYBOARD->active = true;
} else {
bool found = false;
for (auto& k : m_vKeyboards | std::views::reverse) {
if (!k->wlr())
continue;

g_pSeatManager->setKeyboard(k);
found = true;
break;
}

if (!found)
g_pSeatManager->setKeyboard(nullptr);
} else
g_pSeatManager->setKeyboard(nullptr);
}

removeFromHIDs(pKeyboard);
}
Expand Down

0 comments on commit 9d7d5ec

Please sign in to comment.