From 45e71a14a627928c96c418b7e39adcfbca04d7e9 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Wed, 7 Oct 2026 21:15:49 -0400 Subject: [PATCH] feat: experiment with two local touch controllers beside the Deck pad --- app/src/main/cpp/fakeinput_steam.cpp | 57 ++++++++++------ .../launcher/session/SteamDeckPad.kt | 66 ++++++++++--------- docs/development/steam-touch-controller.md | 20 ++++++ 3 files changed, 94 insertions(+), 49 deletions(-) diff --git a/app/src/main/cpp/fakeinput_steam.cpp b/app/src/main/cpp/fakeinput_steam.cpp index 167e32c237..36d109b11a 100644 --- a/app/src/main/cpp/fakeinput_steam.cpp +++ b/app/src/main/cpp/fakeinput_steam.cpp @@ -1217,6 +1217,7 @@ struct DeckHidraw { size_t mapping_size = 0; uint8_t pending_feature = 0; bool touch = false; // the Mobile Touch experiment below, not the Deck + int touch_index = 0; }; // ---- EXPERIMENT: Steam's Mobile Touch controller as a local device ---- @@ -1227,13 +1228,21 @@ struct DeckHidraw { // ids as a local hidraw node, to see whether it builds the touch controller with no stream. The // 40-byte input report is read from TOUCHCTL_REPORT_FILE (written by hand while experimenting); every // output and feature report the client sends is logged and appended to TOUCHCTL_OUT_FILE. -static constexpr const char *TOUCH_HIDRAW_PATH = "/dev/hidraw17"; +// FAKE_EVDEV_TOUCHCTL= offers n of them: /dev/hidraw17, 18, ... with serials MT-DROIDDECK0001, 0002, +// ..., each reading its own report file (touchctl.report, touchctl1.report, ...). static constexpr unsigned int TOUCH_HIDRAW_MINOR = 17; +static constexpr int TOUCH_MAX = 4; static constexpr int TOUCH_REPORT_BYTES = 40; static constexpr int TOUCH_REPORT_INTERVAL_US = 8000; static constexpr const char *TOUCH_NAME = "Mobile Touch Control"; -static constexpr const char *TOUCH_SERIAL = "MT-DROIDDECK0001"; -static constexpr const char *TOUCHCTL_REPORT_FILE = "/tmp/touchctl.report"; +static std::string touch_serial(int index) { + char serial[32]; + snprintf(serial, sizeof(serial), "MT-DROIDDECK%04d", index + 1); + return serial; +} +static std::string touch_report_file(int index) { + return index == 0 ? std::string("/tmp/touchctl.report") : "/tmp/touchctl" + std::to_string(index) + ".report"; +} static constexpr const char *TOUCHCTL_OUT_FILE = "/tmp/touchctl.out"; // While this file exists the device is unplugged: the open stream ends and new opens fail. static constexpr const char *TOUCHCTL_OFF_FILE = "/tmp/touchctl.off"; @@ -1244,11 +1253,12 @@ static const uint8_t kTouchReportDescriptor[] = { 0x09, 0x03, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x40, 0x91, 0x02, 0x09, 0x04, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x40, 0xb1, 0x02, 0xc0}; -static bool fake_touchctl_enabled() { - static int enabled = -1; - if (enabled < 0) enabled = getenv("FAKE_EVDEV_TOUCHCTL") && atoi(getenv("FAKE_EVDEV_TOUCHCTL")) ? 1 : 0; - return enabled == 1; +static int touchctl_count() { + static int count = -1; + if (count < 0) count = getenv("FAKE_EVDEV_TOUCHCTL") ? std::max(0, std::min(TOUCH_MAX, atoi(getenv("FAKE_EVDEV_TOUCHCTL")))) : 0; + return count; } +static bool fake_touchctl_enabled() { return touchctl_count() > 0; } __attribute__((visibility("hidden"))) static void touchctl_note(const char *what, const uint8_t *data, size_t size) { static std::atomic count{0}; @@ -1548,13 +1558,13 @@ __attribute__((visibility("hidden"))) static void *touch_report_thread(void *arg break; } uint8_t report[TOUCH_REPORT_BYTES] = {}; - int fd = my_open(TOUCHCTL_REPORT_FILE, O_RDONLY | O_CLOEXEC); + int fd = my_open(touch_report_file(self->touch_index).c_str(), O_RDONLY | O_CLOEXEC); if (fd >= 0) { syscall(SYS_read, fd, report, sizeof(report)); syscall(SYS_close, fd); } if (memcmp(report, last, sizeof(report))) { - touchctl_note("input", report, sizeof(report)); + touchctl_note(self->touch_index ? "input#1+" : "input", report, sizeof(report)); memcpy(last, report, sizeof(report)); } if (send(self->peer, report, sizeof(report), MSG_DONTWAIT | MSG_NOSIGNAL) < 0 && @@ -1583,7 +1593,7 @@ __attribute__((visibility("hidden"))) static void touchctl_trace(int dirfd, cons path += '/'; path += pathname; } - if (path.find("usb2") == std::string::npos && path.find("hidraw17") == std::string::npos && + if (path.find("usb2") == std::string::npos && path.find("usb3") == std::string::npos && path.find("hidraw17") == std::string::npos && path.find("11FB") == std::string::npos && path.find("240:17") == std::string::npos) return; static std::mutex mutex; @@ -1596,11 +1606,19 @@ __attribute__((visibility("hidden"))) static void touchctl_trace(int dirfd, cons Logger::log("touchctl: client read %s\n", path.c_str()); } +// The index of the experiment's node at pathname, or -1. +__attribute__((visibility("hidden"))) static int touch_hidraw_index(const char *pathname) { + if (!pathname || !fake_touchctl_enabled() || strncmp(pathname, "/dev/hidraw", 11)) return -1; + char *end = nullptr; + long minor = strtol(pathname + 11, &end, 10); + if (!end || *end || minor < TOUCH_HIDRAW_MINOR || minor >= TOUCH_HIDRAW_MINOR + touchctl_count()) return -1; + return static_cast(minor - TOUCH_HIDRAW_MINOR); +} __attribute__((visibility("hidden"))) static bool is_touch_hidraw_path(const char *pathname) { - return pathname && fake_touchctl_enabled() && !strcmp(pathname, TOUCH_HIDRAW_PATH); + return touch_hidraw_index(pathname) >= 0; } -__attribute__((visibility("hidden"))) static int open_touch_hidraw(int flags) { +__attribute__((visibility("hidden"))) static int open_touch_hidraw(int flags, int index) { if (access(TOUCHCTL_OFF_FILE, F_OK) == 0) { Logger::log("touchctl: open refused while unplugged\n"); errno = ENOENT; @@ -1619,6 +1637,7 @@ __attribute__((visibility("hidden"))) static int open_touch_hidraw(int flags) { auto touch = std::make_shared(); touch->peer = pair[1]; touch->touch = true; + touch->touch_index = index; { std::lock_guard guard(controller_mutex()); deck_map()[pair[0]] = touch; @@ -1635,7 +1654,7 @@ __attribute__((visibility("hidden"))) static int open_touch_hidraw(int flags) { return -1; } pthread_detach(thread); - Logger::log("touchctl: %s opened as fd %d\n", TOUCH_HIDRAW_PATH, pair[0]); + Logger::log("touchctl: /dev/hidraw%u opened as fd %d\n", TOUCH_HIDRAW_MINOR + index, pair[0]); return pair[0]; } @@ -1668,8 +1687,8 @@ __attribute__((visibility("hidden"))) static int ioctl_touch(DeckHidraw &touch, return 0; } case 0x04: return copy_ioctl_string(op, argp, TOUCH_NAME); - case 0x05: return copy_ioctl_string(op, argp, "usb-droiddeck-2/input0"); - case 0x08: return copy_ioctl_string(op, argp, TOUCH_SERIAL); + case 0x05: return copy_ioctl_string(op, argp, ("usb-droiddeck-" + std::to_string(2 + touch.touch_index) + "/input0").c_str()); + case 0x08: return copy_ioctl_string(op, argp, touch_serial(touch.touch_index).c_str()); case 0x06: // HIDIOCSFEATURE touchctl_note("set-feature", static_cast(argp), size); touch.pending_feature = size > 1 ? static_cast(argp)[1] : 0; @@ -2034,7 +2053,7 @@ EXPORT int open(const char *pathname, int flags, ...) { if (fake_uinput_enabled() && is_uinput_path(pathname)) return open_uinput(flags); if (is_deck_hidraw_path(pathname)) return open_deck_hidraw(flags); touchctl_trace(AT_FDCWD, pathname); - if (is_touch_hidraw_path(pathname)) return open_touch_hidraw(flags); + if (is_touch_hidraw_path(pathname)) return open_touch_hidraw(flags, touch_hidraw_index(pathname)); if (is_withdrawn_pad_path(pathname)) { errno = ENOENT; return -1; @@ -2110,7 +2129,7 @@ EXPORT int openat(int dirfd, const char *pathname, int flags, ...) { if (fake_uinput_enabled() && is_uinput_path(pathname)) return open_uinput(flags); if (is_deck_hidraw_path(pathname)) return open_deck_hidraw(flags); touchctl_trace(dirfd, pathname); - if (is_touch_hidraw_path(pathname)) return open_touch_hidraw(flags); + if (is_touch_hidraw_path(pathname)) return open_touch_hidraw(flags, touch_hidraw_index(pathname)); if (is_withdrawn_pad_path(pathname)) { errno = ENOENT; return -1; @@ -2174,7 +2193,7 @@ static int fake_stat_path(const char *pathname, S *statbuf, Real real) { if (is_touch_hidraw_path(pathname) && process_is_steam_client()) { memset(statbuf, 0, sizeof(*statbuf)); statbuf->st_mode = S_IFCHR | 0666; - statbuf->st_rdev = makedev(DECK_HIDRAW_MAJOR, TOUCH_HIDRAW_MINOR); + statbuf->st_rdev = makedev(DECK_HIDRAW_MAJOR, TOUCH_HIDRAW_MINOR + touch_hidraw_index(pathname)); return 0; } if (is_deck_hidraw_path(pathname)) { @@ -2228,7 +2247,7 @@ static int fake_stat_fd(int fd, S *buf, Real real) { std::lock_guard guard(controller_mutex()); if (ret == 0 && deck_map().count(fd)) { buf->st_mode = (buf->st_mode & ~S_IFMT) | S_IFCHR; - buf->st_rdev = makedev(DECK_HIDRAW_MAJOR, deck_map()[fd]->touch ? TOUCH_HIDRAW_MINOR : DECK_HIDRAW_MINOR); + buf->st_rdev = makedev(DECK_HIDRAW_MAJOR, deck_map()[fd]->touch ? TOUCH_HIDRAW_MINOR + deck_map()[fd]->touch_index : DECK_HIDRAW_MINOR); return ret; } auto controller = controller_map().find(fd); diff --git a/app/src/main/java/com/droiddeck/launcher/session/SteamDeckPad.kt b/app/src/main/java/com/droiddeck/launcher/session/SteamDeckPad.kt index 34797e7d11..a8622a76a6 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SteamDeckPad.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SteamDeckPad.kt @@ -48,11 +48,7 @@ object SteamDeckPad { // 0000:11fb, as a second local device. libfakeinput serves the node only with // FAKE_EVDEV_TOUCHCTL=1 (fakeinput_steam.cpp: TOUCH_HIDRAW_*). private const val TOUCH_MINOR = 17 - private const val TOUCH_NODE = "hidraw$TOUCH_MINOR" - private const val TOUCH_USB = "$GUEST_DEVICES/usb2" - private const val TOUCH_INTERFACE = "$TOUCH_USB/2-1:1.0" - private const val TOUCH_HID = "$TOUCH_INTERFACE/0003:0000:11FB.0002" - private const val TOUCH_HIDRAW = "$TOUCH_HID/hidraw/$TOUCH_NODE" + private const val TOUCH_DEVICES = 2 /** InputPlumber's CONTROLLER_DESCRIPTOR, as libfakeinput answers HIDIOCGRDESC. */ private val REPORT_DESCRIPTOR = intArrayOf( @@ -125,31 +121,41 @@ object SteamDeckPad { val udevData = File(LinuxRuntime.rootDir(context), "run/udev/data").apply { mkdirs() } File(udevData, "c$MAJOR:$MINOR").writeText("I:1\nE:ID_INPUT=1\nE:ID_INPUT_JOYSTICK=1\n") - // EXPERIMENT: the Mobile Touch controller beside the Deck. - write(TOUCH_USB, "uevent", "DEVTYPE=usb_device\nPRODUCT=0/11fb/0\nTYPE=0/0/0\nBUSNUM=002\nDEVNUM=002\n") - write(TOUCH_USB, "idVendor", "0000\n") - write(TOUCH_USB, "idProduct", "11fb\n") - write(TOUCH_USB, "bcdDevice", "0000\n") - write(TOUCH_USB, "manufacturer", "Valve Software\n") - write(TOUCH_USB, "product", "Mobile Touch Control\n") - write(TOUCH_USB, "serial", "MT-DROIDDECK0001\n") - link(File(dir(TOUCH_USB), "subsystem"), "/sys/bus/usb") - write(TOUCH_INTERFACE, "uevent", "DEVTYPE=usb_interface\nPRODUCT=0/11fb/0\nINTERFACE=3/0/0\n") - write(TOUCH_INTERFACE, "bInterfaceNumber", "00\n") - write(TOUCH_INTERFACE, "bInterfaceClass", "03\n") - link(File(dir(TOUCH_INTERFACE), "subsystem"), "/sys/bus/usb") - write(TOUCH_HID, "uevent", "DRIVER=hid-generic\nHID_ID=0003:00000000:000011FB\n" + - "HID_NAME=Mobile Touch Control\nHID_PHYS=usb-droiddeck-2/input0\n" + - "HID_UNIQ=MT-DROIDDECK0001\nMODALIAS=hid:b0003g0001v00000000p000011FB\n") - File(dir(TOUCH_HID), "report_descriptor").writeBytes(TOUCH_REPORT_DESCRIPTOR) - link(File(dir(TOUCH_HID), "subsystem"), "/sys/bus/hid") - write(TOUCH_HIDRAW, "uevent", "MAJOR=$MAJOR\nMINOR=$TOUCH_MINOR\nDEVNAME=$TOUCH_NODE\n") - write(TOUCH_HIDRAW, "dev", "$MAJOR:$TOUCH_MINOR\n") - link(File(dir(TOUCH_HIDRAW), "subsystem"), "/sys/class/hidraw") - link(File(dir(TOUCH_HIDRAW), "device"), TOUCH_HID) - link(File(hidrawClass, TOUCH_NODE), TOUCH_HIDRAW) - link(File(context.cacheDir, "drm/sys/$MAJOR:$TOUCH_MINOR"), TOUCH_HIDRAW) - File(udevData, "c$MAJOR:$TOUCH_MINOR").writeText("I:1\nE:ID_INPUT=1\nE:ID_INPUT_JOYSTICK=1\n") + // EXPERIMENT: Mobile Touch controllers beside the Deck, two of them (hidraw17, 18). + for (index in 0 until TOUCH_DEVICES) { + val minor = TOUCH_MINOR + index + val node = "hidraw$minor" + val bus = 2 + index + val usb = "$GUEST_DEVICES/usb$bus" + val iface = "$usb/$bus-1:1.0" + val hid = "$iface/0003:0000:11FB.000${2 + index}" + val hidraw = "$hid/hidraw/$node" + val serial = "MT-DROIDDECK%04d".format(index + 1) + write(usb, "uevent", "DEVTYPE=usb_device\nPRODUCT=0/11fb/0\nTYPE=0/0/0\nBUSNUM=00$bus\nDEVNUM=002\n") + write(usb, "idVendor", "0000\n") + write(usb, "idProduct", "11fb\n") + write(usb, "bcdDevice", "0000\n") + write(usb, "manufacturer", "Valve Software\n") + write(usb, "product", "Mobile Touch Control\n") + write(usb, "serial", "$serial\n") + link(File(dir(usb), "subsystem"), "/sys/bus/usb") + write(iface, "uevent", "DEVTYPE=usb_interface\nPRODUCT=0/11fb/0\nINTERFACE=3/0/0\n") + write(iface, "bInterfaceNumber", "00\n") + write(iface, "bInterfaceClass", "03\n") + link(File(dir(iface), "subsystem"), "/sys/bus/usb") + write(hid, "uevent", "DRIVER=hid-generic\nHID_ID=0003:00000000:000011FB\n" + + "HID_NAME=Mobile Touch Control\nHID_PHYS=usb-droiddeck-$bus/input0\n" + + "HID_UNIQ=$serial\nMODALIAS=hid:b0003g0001v00000000p000011FB\n") + File(dir(hid), "report_descriptor").writeBytes(TOUCH_REPORT_DESCRIPTOR) + link(File(dir(hid), "subsystem"), "/sys/bus/hid") + write(hidraw, "uevent", "MAJOR=$MAJOR\nMINOR=$minor\nDEVNAME=$node\n") + write(hidraw, "dev", "$MAJOR:$minor\n") + link(File(dir(hidraw), "subsystem"), "/sys/class/hidraw") + link(File(dir(hidraw), "device"), hid) + link(File(hidrawClass, node), hidraw) + link(File(context.cacheDir, "drm/sys/$MAJOR:$minor"), hidraw) + File(udevData, "c$MAJOR:$minor").writeText("I:1\nE:ID_INPUT=1\nE:ID_INPUT_JOYSTICK=1\n") + } Log.i(TAG, "deck pad: /dev/$NODE described as a Steam Deck controller (28de:1205)") listOf(devices.path + ":" + GUEST_DEVICES, hidrawClass.path + ":/sys/class/hidraw") diff --git a/docs/development/steam-touch-controller.md b/docs/development/steam-touch-controller.md index 1b2a364f33..2662c17248 100644 --- a/docs/development/steam-touch-controller.md +++ b/docs/development/steam-touch-controller.md @@ -380,3 +380,23 @@ Sticks, triggers, bumpers and macros are not in the table; they appear when the The experimental pieces on this branch (`FAKE_EVDEV_TOUCHCTL`, `/tmp/touchctl.*`, `/tmp/udev-inject`) are research scaffolding to be replaced, not shipped. + +### 7. Several controllers + +`FAKE_EVDEV_TOUCHCTL=2` serves two touch devices (`/dev/hidraw17` and `18`, serials +`MT-DROIDDECK0001` and `0002`, each with its own sysfs `usb2`/`usb3` and report file). With the +Deck pad that is three controllers, and Steam takes all three: + +``` +Controller 15 Type 4 (Deck pad, /dev/hidraw16) +Controller 0 Type 43 Serial MT-MT-DROIDDECK0001 +Controller 1 Type 43 Serial MT-MT-DROIDDECK0002 +Created virtual controller at slot 0 / 1 / 2 +uinput: "Microsoft X-Box 360 pad 0" / "pad 1" / "pad 2" is /dev/input/event16 / 17 / 18 +``` + +Each gets its own Steam Input config and its own virtual pad, so a game sees three players; a +Steam press on the second device alone opened the Steam menu (Steam answered it with report 4 for +the menu's action set). Several touch controllers would allow, say, a second player on the Thor's +bottom screen. The other physical pads DroidDeck passes through (ring slots 1-3 as evdev pads) sit +beside these as ordinary gamepads; no external pad was connected for this test.