Compare commits

...

3 Commits

Author SHA1 Message Date
¥IGA 2fb6da7ca7
Merge fd64846aab into 11f14e8488 2024-12-21 22:03:46 +01:00
Gliniak 11f14e8488 [HID] Fixed spam caused by incorrect controller visibility
- Little cleanup in HID related code
2024-12-21 19:51:01 +01:00
¥IGA fd64846aab
[Misc] Support for upcoming Python releases 2024-12-18 15:27:31 +01:00
3 changed files with 34 additions and 30 deletions

View File

@ -41,7 +41,8 @@ void InputSystem::AddDriver(std::unique_ptr<InputDriver> driver) {
void InputSystem::UpdateUsedSlot(InputDriver* driver, uint8_t slot,
bool connected) {
if (slot == XUserIndexAny) {
slot = 0;
XELOGW("{} received requrest for slot any! Unsupported", __func__);
return;
}
if (connected_slots.test(slot) == connected) {
@ -136,18 +137,16 @@ 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;
}
if (result == X_ERROR_SUCCESS || result == X_ERROR_EMPTY) {
UpdateUsedSlot(driver.get(), user_index, any_connected);
if (result == X_ERROR_SUCCESS) {
last_used_slot = user_index;
}
@ -158,7 +157,6 @@ X_RESULT InputSystem::GetKeystroke(uint32_t user_index, uint32_t flags,
continue;
}
}
UpdateUsedSlot(nullptr, user_index, any_connected);
return any_connected ? X_ERROR_EMPTY : X_ERROR_DEVICE_NOT_CONNECTED;
}

View File

@ -39,7 +39,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;
}
@ -272,6 +272,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;
{
@ -284,15 +292,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;
@ -302,7 +301,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 &&
@ -338,7 +337,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) ==
@ -373,7 +372,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;
}

24
xb.bat
View File

@ -1,5 +1,5 @@
@ECHO OFF
REM Copyright 2022 Ben Vanik. All Rights Reserved.
REM Copyright 2024 Ben Vanik. All Rights Reserved.
SET "DIR=%~dp0"
@ -35,14 +35,20 @@ SETLOCAL ENABLEDELAYEDEXPANSION
SET FOUND_PATH=""
SET "CANDIDATE_PATHS[0]=C:\python313\python.exe"
SET "CANDIDATE_PATHS[1]=C:\python312\python.exe"
SET "CANDIDATE_PATHS[2]=C:\python311\python.exe"
SET "CANDIDATE_PATHS[3]=C:\python310\python.exe"
SET "CANDIDATE_PATHS[4]=C:\python39\python.exe"
SET "CANDIDATE_PATHS[5]=C:\python%PYTHON_MINIMUM_VERSION[0]%%PYTHON_MINIMUM_VERSION[1]%\python.exe"
SET "CANDIDATE_PATHS[6]=C:\Windows\py.exe"
SET OUTPUT_INDEX=7
SET "CANDIDATE_PATHS[0]=C:\python320\python.exe"
SET "CANDIDATE_PATHS[1]=C:\python319\python.exe"
SET "CANDIDATE_PATHS[2]=C:\python318\python.exe"
SET "CANDIDATE_PATHS[3]=C:\python317\python.exe"
SET "CANDIDATE_PATHS[4]=C:\python316\python.exe"
SET "CANDIDATE_PATHS[5]=C:\python315\python.exe"
SET "CANDIDATE_PATHS[6]=C:\python314\python.exe"
SET "CANDIDATE_PATHS[7]=C:\python313\python.exe"
SET "CANDIDATE_PATHS[8]=C:\python312\python.exe"
SET "CANDIDATE_PATHS[9]=C:\python311\python.exe"
SET "CANDIDATE_PATHS[10]=C:\python310\python.exe"
SET "CANDIDATE_PATHS[11]=C:\python%PYTHON_MINIMUM_VERSION[0]%%PYTHON_MINIMUM_VERSION[1]%\python.exe"
SET "CANDIDATE_PATHS[12]=C:\Windows\py.exe"
SET OUTPUT_INDEX=13
FOR /F "usebackq delims=" %%L IN (`2^>NUL where python3`) DO (
IF %%~zL NEQ 0 (