summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-10-03 18:10:42 -0500
committerJordan Woyak <jordan.woyak@gmail.com>2025-10-04 14:43:28 -0500
commit4d53de5d847cefc4dc80c94daa1953c07e997a2f (patch)
tree86c8f97e39dbbb52aac826270d93dfd0bc7990db /Source
parent7609220e6176efa35fa647254d92278775512728 (diff)
WiimoteReal/IOhidapi: Log the currently attached hid driver on Linux.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/HW/WiimoteReal/IOhidapi.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/Source/Core/Core/HW/WiimoteReal/IOhidapi.cpp b/Source/Core/Core/HW/WiimoteReal/IOhidapi.cpp
index 95b8b6bdfa..7a70b09409 100644
--- a/Source/Core/Core/HW/WiimoteReal/IOhidapi.cpp
+++ b/Source/Core/Core/HW/WiimoteReal/IOhidapi.cpp
@@ -3,7 +3,9 @@
#include "Core/HW/WiimoteReal/IOhidapi.h"
-#include <algorithm>
+#if defined(__linux__)
+#include <filesystem>
+#endif
#include "Common/Assert.h"
#include "Common/Logging/Log.h"
@@ -12,6 +14,50 @@
using namespace WiimoteCommon;
using namespace WiimoteReal;
+#if defined(__linux__)
+// Here we check the currently attached Linux driver just for logging purposes.
+// Maybe in the future we'll be able to bind the desired HID driver somehow.
+static void LogLinuxDriverName(const char* device_path)
+{
+ namespace fs = std::filesystem;
+
+ const auto sys_device = "/sys/class/hidraw" / fs::path(device_path).filename() / "device";
+
+ // "driver" is a symlink to a path that contains the driver name.
+ // usually /sys/bus/hid/drivers/hid-generic (what we want)
+ // or this /sys/bus/hid/drivers/wiimote (what we don't want)
+ std::error_code err;
+ const auto sys_driver = fs::canonical(sys_device / "driver", err);
+
+ if (err)
+ {
+ WARN_LOG_FMT(WIIMOTE, "Could not determine current driver of {}. error: {}", device_path,
+ err.message());
+ return;
+ }
+
+ const auto driver_name = sys_driver.filename();
+ if (driver_name == "wiimote")
+ {
+ // If Linux's 'wiimote' driver is attached, we will be forever fighting with it.
+ // It's not going to work very well.
+
+ // One could write fs::canonical(sys_device).filename() to (sys_driver / "unbind")
+ // And then also write it to "/sys/bus/hid/drivers/hid-generic/bind"
+ // This should create a new hidraw device with the 'hid-generic' driver.
+
+ // But that requires elevated permissions.. Linux is annoying.
+
+ ERROR_LOG_FMT(WIIMOTE, "Wii remote at {} has the Linux 'wiimote' driver attached.",
+ device_path);
+ }
+ else
+ {
+ DEBUG_LOG_FMT(WIIMOTE, "Wii remote at {} has driver: {}", device_path, driver_name.string());
+ }
+}
+#endif
+
static bool IsDeviceUsable(const std::string& device_path)
{
hid_device* handle = hid_open_path(device_path.c_str());
@@ -73,6 +119,10 @@ void WiimoteScannerHidapi::FindWiimotes(std::vector<Wiimote*>& wiimotes, Wiimote
if (!is_wiimote || !IsNewWiimote(device->path) || !IsDeviceUsable(device->path))
continue;
+#if defined(__linux__)
+ LogLinuxDriverName(device->path);
+#endif
+
auto* wiimote = new WiimoteHidapi(device->path);
const bool is_balance_board = IsBalanceBoardName(name) || wiimote->IsBalanceBoard();
if (is_balance_board)