diff --git a/src/managers/SeatManager.cpp b/src/managers/SeatManager.cpp index 2f93c42fc..81bb1b9ed 100644 --- a/src/managers/SeatManager.cpp +++ b/src/managers/SeatManager.cpp @@ -13,6 +13,7 @@ #include "../desktop/view/LayerSurface.hpp" #include "../managers/input/InputManager.hpp" #include "../state/MonitorState.hpp" +#include "devices/IHID.hpp" #include "wlr-layer-shell-unstable-v1.hpp" #include #include @@ -183,8 +184,8 @@ void CSeatManager::setKeyboardFocus(SP surf) { if (m_state.keyboardFocus == surf) return; - if (!m_keyboard) { - Log::logger->log(Log::ERR, "BUG THIS: setKeyboardFocus without a valid keyboard set"); + if (!g_pInputManager->anyHidHasCap(HID_INPUT_CAPABILITY_KEYBOARD)) { + Log::logger->log(Log::ERR, "BUG THIS: setKeyboardFocus without a valid keyboard capability"); return; } @@ -301,8 +302,8 @@ void CSeatManager::setPointerFocus(SP surf, const Vector2D& return; } - if (!m_mouse) { - Log::logger->log(Log::ERR, "BUG THIS: setPointerFocus without a valid mouse set"); + if (!g_pInputManager->anyHidHasCap(HID_INPUT_CAPABILITY_POINTER)) { + Log::logger->log(Log::ERR, "BUG THIS: setPointerFocus without a valid pointer input"); return; } diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index fbb626a0c..6cd97ee99 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1543,6 +1543,10 @@ static void removeFromHIDs(WP hid) { g_pInputManager->updateCapabilities(); } +bool CInputManager::anyHidHasCap(eHIDCapabilityType type) { + return std::ranges::any_of(m_hids, [&type](const auto& hid) { return hid && (hid->getCapabilities() & type) != 0; }); +} + void CInputManager::destroyKeyboard(SP pKeyboard) { Log::logger->log(Log::DEBUG, "Keyboard at {:x} removed", rc(pKeyboard.get())); diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 7c16d16e9..bc955338d 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -118,6 +118,8 @@ class CInputManager { bool isLocked(); bool hasHeldButtons(); + bool anyHidHasCap(eHIDCapabilityType type); + Vector2D getMouseCoordsInternal(); void refocus(std::optional overridePos = std::nullopt); bool refocusLastWindow(PHLMONITOR pMonitor);