Skip to content

Commit

Permalink
[HID] Fixed spam caused by incorrect controller visibility
Browse files Browse the repository at this point in the history
- Little cleanup in HID related code
  • Loading branch information
Gliniak authored and JeBobs committed Jan 5, 2025
1 parent def1ff1 commit 87f63d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
19 changes: 12 additions & 7 deletions src/xenia/hid/input_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ void InputSystem::AddDriver(std::unique_ptr<InputDriver> driver) {
drivers_.push_back(std::move(driver));
}

void InputSystem::UpdateUsedSlot(uint8_t slot, bool connected) {
void InputSystem::UpdateUsedSlot(InputDriver* driver, uint8_t slot,
bool connected) {
if (slot == 0xFF) {
slot = 0;
XELOGW("{} received requrest for slot any! Unsupported", __func__);
return;
}

if (connected) {
Expand Down Expand Up @@ -120,24 +122,27 @@ X_RESULT InputSystem::GetKeystroke(uint32_t user_index, uint32_t flags,

bool any_connected = false;
for (auto& driver : drivers_) {
// connected_slots
X_RESULT result = driver->GetKeystroke(user_index, flags, out_keystroke);
if (result == X_ERROR_INVALID_PARAMETER) {
if (result == X_ERROR_INVALID_PARAMETER ||
result == X_ERROR_DEVICE_NOT_CONNECTED) {
continue;
}

if (result != X_ERROR_DEVICE_NOT_CONNECTED) {
any_connected = true;
}
any_connected = true;

if (result == X_ERROR_SUCCESS || result == X_ERROR_EMPTY) {
UpdateUsedSlot(user_index, any_connected);
if (result == X_ERROR_SUCCESS) {
last_used_slot = user_index;
}
return result;
}

if (result == X_ERROR_EMPTY) {
continue;
}
}
UpdateUsedSlot(user_index, any_connected);
return any_connected ? X_ERROR_EMPTY : X_ERROR_DEVICE_NOT_CONNECTED;
}

Expand Down
26 changes: 13 additions & 13 deletions src/xenia/hid/winkey/winkey_input_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace xe {
namespace hid {
namespace winkey {

bool static IsPassthroughEnabled(uint32_t user_index) {
bool static IsPassthroughEnabled() {
return static_cast<KeyboardMode>(cvars::keyboard_mode) ==
KeyboardMode::Passthrough;
}
Expand Down Expand Up @@ -277,6 +277,14 @@ X_RESULT WinKeyInputDriver::SetState(uint32_t user_index,

X_RESULT WinKeyInputDriver::GetKeystroke(uint32_t user_index, uint32_t flags,
X_INPUT_KEYSTROKE* out_keystroke) {
if (!is_active()) {
return X_ERROR_DEVICE_NOT_CONNECTED;
}

if (!IsKeyboardForUserEnabled(user_index) && !IsPassthroughEnabled()) {
return X_ERROR_DEVICE_NOT_CONNECTED;
}

// Pop from the queue.
KeyEvent evt;
{
Expand All @@ -289,15 +297,6 @@ X_RESULT WinKeyInputDriver::GetKeystroke(uint32_t user_index, uint32_t flags,
key_events_.pop();
}

if (!IsKeyboardForUserEnabled(user_index) &&
!IsPassthroughEnabled(user_index)) {
return X_ERROR_DEVICE_NOT_CONNECTED;
}

if (!is_active()) {
return X_ERROR_EMPTY;
}

X_RESULT result = X_ERROR_EMPTY;

ui::VirtualKey xinput_virtual_key = ui::VirtualKey::kNone;
Expand All @@ -307,7 +306,7 @@ X_RESULT WinKeyInputDriver::GetKeystroke(uint32_t user_index, uint32_t flags,

bool capital = IsKeyToggled(VK_CAPITAL) || IsKeyDown(VK_SHIFT);

if (!IsPassthroughEnabled(user_index)) {
if (!IsPassthroughEnabled()) {
if (IsKeyboardForUserEnabled(user_index)) {
for (const KeyBinding& b : key_bindings_) {
if (b.input_key == evt.virtual_key &&
Expand Down Expand Up @@ -343,7 +342,7 @@ X_RESULT WinKeyInputDriver::GetKeystroke(uint32_t user_index, uint32_t flags,
keystroke_flags |= 0x0002; // XINPUT_KEYSTROKE_KEYUP
}

if (IsPassthroughEnabled(user_index)) {
if (IsPassthroughEnabled()) {
if (GetKeyboardState(key_map_)) {
WCHAR buf;
if (ToUnicode(uint8_t(xinput_virtual_key), 0, key_map_, &buf, 1, 0) ==
Expand Down Expand Up @@ -378,7 +377,8 @@ void WinKeyInputDriver::WinKeyWindowInputListener::OnKeyUp(ui::KeyEvent& e) {
}

void WinKeyInputDriver::OnKey(ui::KeyEvent& e, bool is_down) {
if (!is_active()) {
if (!is_active() || static_cast<KeyboardMode>(cvars::keyboard_mode) ==
KeyboardMode::Disabled) {
return;
}

Expand Down

0 comments on commit 87f63d0

Please sign in to comment.