From 6cfccd93b6ca49f76f22fbf19883fcc39fff9896 Mon Sep 17 00:00:00 2001 From: kotleni Date: Wed, 11 Jan 2023 19:57:17 +0200 Subject: [PATCH 01/18] Implemented gamepad support for macOS --- CMakeLists.txt | 1 + src/platform/macos/input.cpp | 134 +++++++++++++++++++++++++++++++++-- 2 files changed, 131 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e672839c482..f95ce678840 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -652,6 +652,7 @@ if(NOT DEFINED CMAKE_CUDA_STANDARD) endif() if(APPLE) + target_link_libraries(sunshine "-framework IOKit") target_link_options(sunshine PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,${APPLE_PLIST_FILE}) # Tell linker to dynamically load these symbols at runtime, in case they're unavailable: target_link_options(sunshine PRIVATE -Wl,-U,_CGPreflightScreenCaptureAccess -Wl,-U,_CGRequestScreenCaptureAccess) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index ff59f4fb293..963779fe2ca 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -2,6 +2,10 @@ #include #include +// For gamepad emulation +#include +#include + #include "src/main.h" #include "src/platform/common.h" #include "src/utility.h" @@ -10,6 +14,66 @@ // FIXME: we probably want to make this configurable #define MULTICLICK_DELAY_NS 500000000 +// For gamepad emulation +#define VIRTGAMEPAD_NAME "Sunshine Gamepad" +#define VIRTGAMEPAD_SN "SG 0001" // serial number +#define SERVICE_NAME "it_kotleni_virthid" // virthid service id +#define VIRTGAMEPAD_INPU_COUNT 8 +#define FOOHID_CREATE 0 // create selector +#define FOOHID_SEND 2 // send selector + +// http://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/ +// Used HIDTool to generate the data +unsigned char gamepad_report_descriptor[] = { + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x05, // USAGE (Game Pad) + 0xa1, 0x01, // COLLECTION (Application) + 0xa1, 0x00, // COLLECTION (Physical) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x09, 0x33, // USAGE (Rx) + 0x09, 0x34, // USAGE (Ry) + 0x16, 0x00, 0x80, // LOGICAL_MINIMUM (-32768) + 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767) + 0x75, 0x10, // REPORT_SIZE (16) + 0x95, 0x04, // REPORT_COUNT (4) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x32, // USAGE (Z) + 0x09, 0x35, // USAGE (Rz) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x46, 0xff, 0x00, // PHYSICAL_MAXIMUM (255) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x02, // REPORT_COUNT (2) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x10, // USAGE_MAXIMUM (Button 16) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x10, // REPORT_COUNT (16) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0xc0, // END_COLLECTION + 0xc0 // END_COLLECTION +}; + +struct gamepad_report_t { + int16_t x; + int16_t y; + int16_t rx; + int16_t ry; + uint8_t z; + uint8_t rz; + uint16_t buttons; +}; + +io_iterator_t virtgamepad_iterator; +io_service_t virtgamepad_service; +io_connect_t virtgamepad_connect; +uint64_t virtgamepad_input[VIRTGAMEPAD_INPU_COUNT]; + namespace platf { using namespace std::literals; @@ -282,16 +346,78 @@ void unicode(input_t &input, char *utf8, int size) { } int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) { - BOOST_LOG(info) << "alloc_gamepad: Gamepad not yet implemented for MacOS."sv; - return -1; + // Get a reference to the IOService + kern_return_t ret = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(SERVICE_NAME), &virtgamepad_iterator); + + if (ret != KERN_SUCCESS) { + BOOST_LOG(info) << "Gamepad: Unable to access IOService."sv; + return 1; + } + + // Iterate till success + int found = 0; + while ((virtgamepad_service = IOIteratorNext(virtgamepad_iterator)) != IO_OBJECT_NULL) { + ret = IOServiceOpen(virtgamepad_service, mach_task_self(), 0, &virtgamepad_connect); + if (ret == KERN_SUCCESS) { + found = 1; + break; + } + + IOObjectRelease(virtgamepad_service); + } + + IOObjectRelease(virtgamepad_iterator); + + if(!found) { + BOOST_LOG(info) << "Gamepad: Unable to open IOService."sv; + return 1; + } + + // Fill up the input arguments. + virtgamepad_input[0] = (uint64_t) strdup(VIRTGAMEPAD_NAME); // device name + virtgamepad_input[1] = strlen((char *)virtgamepad_input[0]); // name length + virtgamepad_input[2] = (uint64_t) gamepad_report_descriptor; // report descriptor + virtgamepad_input[3] = sizeof(gamepad_report_descriptor); // report descriptor len + virtgamepad_input[4] = (uint64_t) strdup(VIRTGAMEPAD_SN); // serial number + virtgamepad_input[5] = strlen((char *)virtgamepad_input[4]); // serial number len + virtgamepad_input[6] = (uint64_t) 2; // vendor ID + virtgamepad_input[7] = (uint64_t) 3; // device ID + + ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_CREATE, virtgamepad_input, VIRTGAMEPAD_INPU_COUNT, NULL, 0); + if (ret != KERN_SUCCESS) { + BOOST_LOG(info) << "Gamepad: Unable to create HID device. May be fine if created previously."sv; + } + return 0; } void free_gamepad(input_t &input, int nr) { - BOOST_LOG(info) << "free_gamepad: Gamepad not yet implemented for MacOS."sv; + IOObjectRelease(virtgamepad_connect); } void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { - BOOST_LOG(info) << "gamepad: Gamepad not yet implemented for MacOS."sv; + auto bf = gamepad_state.buttonFlags; + + // Arguments to be passed through the HID message. + struct gamepad_report_t gamepad; + uint32_t send_count = 4; + uint64_t send[send_count]; + send[0] = (uint64_t)virtgamepad_input[0]; // device name + send[1] = strlen((char *)virtgamepad_input[0]); // name length + send[2] = (uint64_t) &gamepad; // mouse struct + send[3] = sizeof(struct gamepad_report_t); // mouse struct len + + gamepad.buttons = gamepad_state.buttonFlags; + gamepad.x = gamepad_state.lsX; + gamepad.y = -gamepad_state.lsY; // inversed + gamepad.rx = gamepad_state.rsX; + gamepad.ry = -gamepad_state.rsY; // inversed + gamepad.z = gamepad_state.lt; + gamepad.rz = gamepad_state.rt; + + kern_return_t ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_SEND, send, send_count, NULL, 0); + if(ret != KERN_SUCCESS) { + BOOST_LOG(info) << "Gamepad: Unable to send message to HID device."sv; + } } // returns current mouse location: From 92efec42b5555aa69deb27fc4ae75423aeaa766a Mon Sep 17 00:00:00 2001 From: kotleni Date: Wed, 11 Jan 2023 22:54:46 +0200 Subject: [PATCH 02/18] Fixed gamepad buttons mapping on macOS --- src/platform/macos/input.cpp | 55 +++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index 963779fe2ca..32d185cd1f5 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -15,13 +15,32 @@ #define MULTICLICK_DELAY_NS 500000000 // For gamepad emulation +// https://github.com/kotleni/virthid-macos #define VIRTGAMEPAD_NAME "Sunshine Gamepad" #define VIRTGAMEPAD_SN "SG 0001" // serial number #define SERVICE_NAME "it_kotleni_virthid" // virthid service id -#define VIRTGAMEPAD_INPU_COUNT 8 +#define VIRTGAMEPAD_INPUT_COUNT 16 // gamepad buttons count #define FOOHID_CREATE 0 // create selector #define FOOHID_SEND 2 // send selector +// Gamepad buttons +#define GAMEPAD_BTN_A 0b0000000000000001 +#define GAMEPAD_BTN_B 0b0000000000000010 +#define GAMEPAD_BTN_X 0b0000000000000100 +#define GAMEPAD_BTN_Y 0b0000000000001000 +#define GAMEPAD_BTN_L 0b0000000000010000 +#define GAMEPAD_BTN_R 0b0000000000100000 +#define GAMEPAD_BTN_LT 0b0000000001000000 +#define GAMEPAD_BTN_RT 0b0000000010000000 +#define GAMEPAD_BTN_BACK 0b0000000100000000 +#define GAMEPAD_BTN_START 0b0000001000000000 +#define GAMEPAD_BTN_LS 0b0000010000000000 +#define GAMEPAD_BTN_RS 0b0000100000000000 +#define GAMEPAD_BTN_UP 0b0001000000000000 +#define GAMEPAD_BTN_DOWN 0b0010000000000000 +#define GAMEPAD_BTN_LEFT 0b0100000000000000 +#define GAMEPAD_BTN_RIGHT 0b1000000000000000 + // http://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/ // Used HIDTool to generate the data unsigned char gamepad_report_descriptor[] = { @@ -72,7 +91,7 @@ struct gamepad_report_t { io_iterator_t virtgamepad_iterator; io_service_t virtgamepad_service; io_connect_t virtgamepad_connect; -uint64_t virtgamepad_input[VIRTGAMEPAD_INPU_COUNT]; +uint64_t virtgamepad_input[VIRTGAMEPAD_INPUT_COUNT]; namespace platf { using namespace std::literals; @@ -383,7 +402,7 @@ int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) { virtgamepad_input[6] = (uint64_t) 2; // vendor ID virtgamepad_input[7] = (uint64_t) 3; // device ID - ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_CREATE, virtgamepad_input, VIRTGAMEPAD_INPU_COUNT, NULL, 0); + ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_CREATE, virtgamepad_input, VIRTGAMEPAD_INPUT_COUNT, NULL, 0); if (ret != KERN_SUCCESS) { BOOST_LOG(info) << "Gamepad: Unable to create HID device. May be fine if created previously."sv; } @@ -395,8 +414,6 @@ void free_gamepad(input_t &input, int nr) { } void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { - auto bf = gamepad_state.buttonFlags; - // Arguments to be passed through the HID message. struct gamepad_report_t gamepad; uint32_t send_count = 4; @@ -406,13 +423,31 @@ void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { send[2] = (uint64_t) &gamepad; // mouse struct send[3] = sizeof(struct gamepad_report_t); // mouse struct len - gamepad.buttons = gamepad_state.buttonFlags; + auto flags = gamepad_state.buttonFlags; + + gamepad.buttons = 0b00000000; // fill zeroes + if(flags & LEFT_STICK) gamepad.buttons |= GAMEPAD_BTN_LS; + if(flags & RIGHT_STICK) gamepad.buttons |= GAMEPAD_BTN_RS; + if(flags & LEFT_BUTTON) gamepad.buttons |= GAMEPAD_BTN_L; + if(flags & RIGHT_BUTTON) gamepad.buttons |= GAMEPAD_BTN_R; + if(flags & START) gamepad.buttons |= GAMEPAD_BTN_START; + if(flags & BACK) gamepad.buttons |= GAMEPAD_BTN_BACK; + if(flags & A) gamepad.buttons |= GAMEPAD_BTN_A; + if(flags & B) gamepad.buttons |= GAMEPAD_BTN_B; + if(flags & X) gamepad.buttons |= GAMEPAD_BTN_X; + if(flags & Y) gamepad.buttons |= GAMEPAD_BTN_Y; + if(flags & DPAD_UP) gamepad.buttons |= GAMEPAD_BTN_UP; + if(flags & DPAD_DOWN) gamepad.buttons |= GAMEPAD_BTN_DOWN; + if(flags & DPAD_LEFT) gamepad.buttons |= GAMEPAD_BTN_LEFT; + if(flags & DPAD_RIGHT) gamepad.buttons |= GAMEPAD_BTN_RIGHT; + + if(gamepad_state.lt > 0) gamepad.buttons |= GAMEPAD_BTN_LT; + if(gamepad_state.rt > 0) gamepad.buttons |= GAMEPAD_BTN_RT; + gamepad.x = gamepad_state.lsX; - gamepad.y = -gamepad_state.lsY; // inversed + gamepad.y = -gamepad_state.lsY; // inversed gamepad.rx = gamepad_state.rsX; - gamepad.ry = -gamepad_state.rsY; // inversed - gamepad.z = gamepad_state.lt; - gamepad.rz = gamepad_state.rt; + gamepad.ry = -gamepad_state.rsY; // inversed kern_return_t ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_SEND, send, send_count, NULL, 0); if(ret != KERN_SUCCESS) { From 649ac4eab46532394eff39fd62ba06fb17bc5fef Mon Sep 17 00:00:00 2001 From: kotleni Date: Wed, 11 Jan 2023 22:58:50 +0200 Subject: [PATCH 03/18] Changed link to VirtualHID repo --- src/platform/macos/input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index 32d185cd1f5..b3bdffc43b3 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -15,7 +15,7 @@ #define MULTICLICK_DELAY_NS 500000000 // For gamepad emulation -// https://github.com/kotleni/virthid-macos +// https://github.com/kotleni/VirtualHID-macOS #define VIRTGAMEPAD_NAME "Sunshine Gamepad" #define VIRTGAMEPAD_SN "SG 0001" // serial number #define SERVICE_NAME "it_kotleni_virthid" // virthid service id From 2fe38fd7c7461c1eb21bc07b0011718395fe4863 Mon Sep 17 00:00:00 2001 From: kotleni Date: Wed, 11 Jan 2023 23:32:09 +0200 Subject: [PATCH 04/18] Refactoring macOS gamepad code --- src/platform/macos/input.cpp | 60 ++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index b3bdffc43b3..78c60060521 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -16,30 +16,31 @@ // For gamepad emulation // https://github.com/kotleni/VirtualHID-macOS -#define VIRTGAMEPAD_NAME "Sunshine Gamepad" -#define VIRTGAMEPAD_SN "SG 0001" // serial number -#define SERVICE_NAME "it_kotleni_virthid" // virthid service id -#define VIRTGAMEPAD_INPUT_COUNT 16 // gamepad buttons count -#define FOOHID_CREATE 0 // create selector -#define FOOHID_SEND 2 // send selector +#define VIRTGAMEPAD_NAME "Sunshine Gamepad" +#define VIRTGAMEPAD_SN "SG 0001" // serial number +#define VIRTGAMEPAD_INPUT_COUNT 16 // gamepad buttons count +#define SERVICE_NAME "it_kotleni_virthid" // virthid service id +#define FOOHID_CREATE 0 // create selector +#define FOOHID_SEND 2 // send selector // Gamepad buttons -#define GAMEPAD_BTN_A 0b0000000000000001 -#define GAMEPAD_BTN_B 0b0000000000000010 -#define GAMEPAD_BTN_X 0b0000000000000100 -#define GAMEPAD_BTN_Y 0b0000000000001000 -#define GAMEPAD_BTN_L 0b0000000000010000 -#define GAMEPAD_BTN_R 0b0000000000100000 -#define GAMEPAD_BTN_LT 0b0000000001000000 -#define GAMEPAD_BTN_RT 0b0000000010000000 -#define GAMEPAD_BTN_BACK 0b0000000100000000 -#define GAMEPAD_BTN_START 0b0000001000000000 -#define GAMEPAD_BTN_LS 0b0000010000000000 -#define GAMEPAD_BTN_RS 0b0000100000000000 -#define GAMEPAD_BTN_UP 0b0001000000000000 -#define GAMEPAD_BTN_DOWN 0b0010000000000000 -#define GAMEPAD_BTN_LEFT 0b0100000000000000 -#define GAMEPAD_BTN_RIGHT 0b1000000000000000 +#define GAMEPAD_ZEROBTNS 0 +#define GAMEPAD_BTN_A (1 << 0) +#define GAMEPAD_BTN_B (1 << 1) +#define GAMEPAD_BTN_X (1 << 2) +#define GAMEPAD_BTN_Y (1 << 3) +#define GAMEPAD_BTN_L (1 << 4) +#define GAMEPAD_BTN_R (1 << 5) +#define GAMEPAD_BTN_LT (1 << 6) +#define GAMEPAD_BTN_RT (1 << 7) +#define GAMEPAD_BTN_BACK (1 << 8) +#define GAMEPAD_BTN_START (1 << 9) +#define GAMEPAD_BTN_LS (1 << 10) +#define GAMEPAD_BTN_RS (1 << 11) +#define GAMEPAD_BTN_UP (1 << 12) +#define GAMEPAD_BTN_DOWN (1 << 13) +#define GAMEPAD_BTN_LEFT (1 << 14) +#define GAMEPAD_BTN_RIGHT (1 << 15) // http://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/ // Used HIDTool to generate the data @@ -399,8 +400,8 @@ int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) { virtgamepad_input[3] = sizeof(gamepad_report_descriptor); // report descriptor len virtgamepad_input[4] = (uint64_t) strdup(VIRTGAMEPAD_SN); // serial number virtgamepad_input[5] = strlen((char *)virtgamepad_input[4]); // serial number len - virtgamepad_input[6] = (uint64_t) 2; // vendor ID - virtgamepad_input[7] = (uint64_t) 3; // device ID + virtgamepad_input[6] = (uint64_t) 0xdead; // vendor ID + virtgamepad_input[7] = (uint64_t) 0xbeef; // device ID ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_CREATE, virtgamepad_input, VIRTGAMEPAD_INPUT_COUNT, NULL, 0); if (ret != KERN_SUCCESS) { @@ -425,7 +426,10 @@ void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { auto flags = gamepad_state.buttonFlags; - gamepad.buttons = 0b00000000; // fill zeroes + // reset buttons + gamepad.buttons = GAMEPAD_ZEROBTNS; + + // Map buttons if(flags & LEFT_STICK) gamepad.buttons |= GAMEPAD_BTN_LS; if(flags & RIGHT_STICK) gamepad.buttons |= GAMEPAD_BTN_RS; if(flags & LEFT_BUTTON) gamepad.buttons |= GAMEPAD_BTN_L; @@ -441,13 +445,15 @@ void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { if(flags & DPAD_LEFT) gamepad.buttons |= GAMEPAD_BTN_LEFT; if(flags & DPAD_RIGHT) gamepad.buttons |= GAMEPAD_BTN_RIGHT; + // Map triggers if(gamepad_state.lt > 0) gamepad.buttons |= GAMEPAD_BTN_LT; if(gamepad_state.rt > 0) gamepad.buttons |= GAMEPAD_BTN_RT; + // Map sticks gamepad.x = gamepad_state.lsX; - gamepad.y = -gamepad_state.lsY; // inversed + gamepad.y = -gamepad_state.lsY; gamepad.rx = gamepad_state.rsX; - gamepad.ry = -gamepad_state.rsY; // inversed + gamepad.ry = -gamepad_state.rsY; kern_return_t ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_SEND, send, send_count, NULL, 0); if(ret != KERN_SUCCESS) { From 74b9e136898d88b350bd68529225499a49150df3 Mon Sep 17 00:00:00 2001 From: kotleni Date: Thu, 12 Jan 2023 00:18:53 +0200 Subject: [PATCH 05/18] Refactoring --- src/platform/macos/input.cpp | 176 +++++++++++++++++------------------ 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index 78c60060521..435aaccfd25 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -16,77 +16,77 @@ // For gamepad emulation // https://github.com/kotleni/VirtualHID-macOS -#define VIRTGAMEPAD_NAME "Sunshine Gamepad" -#define VIRTGAMEPAD_SN "SG 0001" // serial number -#define VIRTGAMEPAD_INPUT_COUNT 16 // gamepad buttons count -#define SERVICE_NAME "it_kotleni_virthid" // virthid service id -#define FOOHID_CREATE 0 // create selector -#define FOOHID_SEND 2 // send selector +#define VIRTGAMEPAD_NAME "Sunshine Gamepad" +#define VIRTGAMEPAD_SN "SG 0001" // serial number +#define VIRTGAMEPAD_INPUT_COUNT 16 // gamepad buttons count +#define SERVICE_NAME "it_kotleni_virthid" // virthid service id +#define FOOHID_CREATE 0 // create selector +#define FOOHID_SEND 2 // send selector // Gamepad buttons #define GAMEPAD_ZEROBTNS 0 -#define GAMEPAD_BTN_A (1 << 0) -#define GAMEPAD_BTN_B (1 << 1) -#define GAMEPAD_BTN_X (1 << 2) -#define GAMEPAD_BTN_Y (1 << 3) -#define GAMEPAD_BTN_L (1 << 4) -#define GAMEPAD_BTN_R (1 << 5) -#define GAMEPAD_BTN_LT (1 << 6) -#define GAMEPAD_BTN_RT (1 << 7) -#define GAMEPAD_BTN_BACK (1 << 8) +#define GAMEPAD_BTN_A (1 << 0) +#define GAMEPAD_BTN_B (1 << 1) +#define GAMEPAD_BTN_X (1 << 2) +#define GAMEPAD_BTN_Y (1 << 3) +#define GAMEPAD_BTN_L (1 << 4) +#define GAMEPAD_BTN_R (1 << 5) +#define GAMEPAD_BTN_LT (1 << 6) +#define GAMEPAD_BTN_RT (1 << 7) +#define GAMEPAD_BTN_BACK (1 << 8) #define GAMEPAD_BTN_START (1 << 9) -#define GAMEPAD_BTN_LS (1 << 10) -#define GAMEPAD_BTN_RS (1 << 11) -#define GAMEPAD_BTN_UP (1 << 12) -#define GAMEPAD_BTN_DOWN (1 << 13) -#define GAMEPAD_BTN_LEFT (1 << 14) +#define GAMEPAD_BTN_LS (1 << 10) +#define GAMEPAD_BTN_RS (1 << 11) +#define GAMEPAD_BTN_UP (1 << 12) +#define GAMEPAD_BTN_DOWN (1 << 13) +#define GAMEPAD_BTN_LEFT (1 << 14) #define GAMEPAD_BTN_RIGHT (1 << 15) // http://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/ // Used HIDTool to generate the data unsigned char gamepad_report_descriptor[] = { - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x05, // USAGE (Game Pad) - 0xa1, 0x01, // COLLECTION (Application) - 0xa1, 0x00, // COLLECTION (Physical) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x09, 0x33, // USAGE (Rx) - 0x09, 0x34, // USAGE (Ry) - 0x16, 0x00, 0x80, // LOGICAL_MINIMUM (-32768) - 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767) - 0x75, 0x10, // REPORT_SIZE (16) - 0x95, 0x04, // REPORT_COUNT (4) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x32, // USAGE (Z) - 0x09, 0x35, // USAGE (Rz) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x46, 0xff, 0x00, // PHYSICAL_MAXIMUM (255) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x02, // REPORT_COUNT (2) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x10, // USAGE_MAXIMUM (Button 16) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x10, // REPORT_COUNT (16) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0xc0, // END_COLLECTION - 0xc0 // END_COLLECTION + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x05, // USAGE (Game Pad) + 0xa1, 0x01, // COLLECTION (Application) + 0xa1, 0x00, // COLLECTION (Physical) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x09, 0x33, // USAGE (Rx) + 0x09, 0x34, // USAGE (Ry) + 0x16, 0x00, 0x80, // LOGICAL_MINIMUM (-32768) + 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767) + 0x75, 0x10, // REPORT_SIZE (16) + 0x95, 0x04, // REPORT_COUNT (4) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x32, // USAGE (Z) + 0x09, 0x35, // USAGE (Rz) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x46, 0xff, 0x00, // PHYSICAL_MAXIMUM (255) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x02, // REPORT_COUNT (2) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x10, // USAGE_MAXIMUM (Button 16) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x10, // REPORT_COUNT (16) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0xc0, // END_COLLECTION + 0xc0 // END_COLLECTION }; struct gamepad_report_t { - int16_t x; - int16_t y; - int16_t rx; - int16_t ry; - uint8_t z; - uint8_t rz; - uint16_t buttons; + int16_t x; + int16_t y; + int16_t rx; + int16_t ry; + uint8_t z; + uint8_t rz; + uint16_t buttons; }; io_iterator_t virtgamepad_iterator; @@ -369,23 +369,23 @@ int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) { // Get a reference to the IOService kern_return_t ret = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(SERVICE_NAME), &virtgamepad_iterator); - if (ret != KERN_SUCCESS) { + if(ret != KERN_SUCCESS) { BOOST_LOG(info) << "Gamepad: Unable to access IOService."sv; return 1; } // Iterate till success int found = 0; - while ((virtgamepad_service = IOIteratorNext(virtgamepad_iterator)) != IO_OBJECT_NULL) { + while((virtgamepad_service = IOIteratorNext(virtgamepad_iterator)) != IO_OBJECT_NULL) { ret = IOServiceOpen(virtgamepad_service, mach_task_self(), 0, &virtgamepad_connect); - if (ret == KERN_SUCCESS) { + if(ret == KERN_SUCCESS) { found = 1; break; } IOObjectRelease(virtgamepad_service); } - + IOObjectRelease(virtgamepad_iterator); if(!found) { @@ -394,17 +394,17 @@ int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) { } // Fill up the input arguments. - virtgamepad_input[0] = (uint64_t) strdup(VIRTGAMEPAD_NAME); // device name - virtgamepad_input[1] = strlen((char *)virtgamepad_input[0]); // name length - virtgamepad_input[2] = (uint64_t) gamepad_report_descriptor; // report descriptor - virtgamepad_input[3] = sizeof(gamepad_report_descriptor); // report descriptor len - virtgamepad_input[4] = (uint64_t) strdup(VIRTGAMEPAD_SN); // serial number - virtgamepad_input[5] = strlen((char *)virtgamepad_input[4]); // serial number len - virtgamepad_input[6] = (uint64_t) 0xdead; // vendor ID - virtgamepad_input[7] = (uint64_t) 0xbeef; // device ID + virtgamepad_input[0] = (uint64_t)strdup(VIRTGAMEPAD_NAME); // device name + virtgamepad_input[1] = strlen((char *)virtgamepad_input[0]); // name length + virtgamepad_input[2] = (uint64_t)gamepad_report_descriptor; // report descriptor + virtgamepad_input[3] = sizeof(gamepad_report_descriptor); // report descriptor len + virtgamepad_input[4] = (uint64_t)strdup(VIRTGAMEPAD_SN); // serial number + virtgamepad_input[5] = strlen((char *)virtgamepad_input[4]); // serial number len + virtgamepad_input[6] = (uint64_t)0xdead; // vendor ID + virtgamepad_input[7] = (uint64_t)0xbeef; // device ID ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_CREATE, virtgamepad_input, VIRTGAMEPAD_INPUT_COUNT, NULL, 0); - if (ret != KERN_SUCCESS) { + if(ret != KERN_SUCCESS) { BOOST_LOG(info) << "Gamepad: Unable to create HID device. May be fine if created previously."sv; } return 0; @@ -421,7 +421,7 @@ void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { uint64_t send[send_count]; send[0] = (uint64_t)virtgamepad_input[0]; // device name send[1] = strlen((char *)virtgamepad_input[0]); // name length - send[2] = (uint64_t) &gamepad; // mouse struct + send[2] = (uint64_t)&gamepad; // mouse struct send[3] = sizeof(struct gamepad_report_t); // mouse struct len auto flags = gamepad_state.buttonFlags; @@ -430,28 +430,28 @@ void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { gamepad.buttons = GAMEPAD_ZEROBTNS; // Map buttons - if(flags & LEFT_STICK) gamepad.buttons |= GAMEPAD_BTN_LS; - if(flags & RIGHT_STICK) gamepad.buttons |= GAMEPAD_BTN_RS; - if(flags & LEFT_BUTTON) gamepad.buttons |= GAMEPAD_BTN_L; + if(flags & LEFT_STICK) gamepad.buttons |= GAMEPAD_BTN_LS; + if(flags & RIGHT_STICK) gamepad.buttons |= GAMEPAD_BTN_RS; + if(flags & LEFT_BUTTON) gamepad.buttons |= GAMEPAD_BTN_L; if(flags & RIGHT_BUTTON) gamepad.buttons |= GAMEPAD_BTN_R; - if(flags & START) gamepad.buttons |= GAMEPAD_BTN_START; - if(flags & BACK) gamepad.buttons |= GAMEPAD_BTN_BACK; - if(flags & A) gamepad.buttons |= GAMEPAD_BTN_A; - if(flags & B) gamepad.buttons |= GAMEPAD_BTN_B; - if(flags & X) gamepad.buttons |= GAMEPAD_BTN_X; - if(flags & Y) gamepad.buttons |= GAMEPAD_BTN_Y; - if(flags & DPAD_UP) gamepad.buttons |= GAMEPAD_BTN_UP; - if(flags & DPAD_DOWN) gamepad.buttons |= GAMEPAD_BTN_DOWN; - if(flags & DPAD_LEFT) gamepad.buttons |= GAMEPAD_BTN_LEFT; - if(flags & DPAD_RIGHT) gamepad.buttons |= GAMEPAD_BTN_RIGHT; + if(flags & START) gamepad.buttons |= GAMEPAD_BTN_START; + if(flags & BACK) gamepad.buttons |= GAMEPAD_BTN_BACK; + if(flags & A) gamepad.buttons |= GAMEPAD_BTN_A; + if(flags & B) gamepad.buttons |= GAMEPAD_BTN_B; + if(flags & X) gamepad.buttons |= GAMEPAD_BTN_X; + if(flags & Y) gamepad.buttons |= GAMEPAD_BTN_Y; + if(flags & DPAD_UP) gamepad.buttons |= GAMEPAD_BTN_UP; + if(flags & DPAD_DOWN) gamepad.buttons |= GAMEPAD_BTN_DOWN; + if(flags & DPAD_LEFT) gamepad.buttons |= GAMEPAD_BTN_LEFT; + if(flags & DPAD_RIGHT) gamepad.buttons |= GAMEPAD_BTN_RIGHT; // Map triggers if(gamepad_state.lt > 0) gamepad.buttons |= GAMEPAD_BTN_LT; if(gamepad_state.rt > 0) gamepad.buttons |= GAMEPAD_BTN_RT; // Map sticks - gamepad.x = gamepad_state.lsX; - gamepad.y = -gamepad_state.lsY; + gamepad.x = gamepad_state.lsX; + gamepad.y = -gamepad_state.lsY; gamepad.rx = gamepad_state.rsX; gamepad.ry = -gamepad_state.rsY; From 71252bb30b1abf70c0dfc89e64954e83e5f78458 Mon Sep 17 00:00:00 2001 From: Victor Varenik <38311102+kotleni@users.noreply.github.com> Date: Thu, 12 Jan 2023 01:16:43 +0200 Subject: [PATCH 06/18] Refactoring --- src/platform/macos/input.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index 435aaccfd25..0dd47a06e79 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -24,7 +24,7 @@ #define FOOHID_SEND 2 // send selector // Gamepad buttons -#define GAMEPAD_ZEROBTNS 0 +#define GAMEPAD_ZEROBTNS 0 #define GAMEPAD_BTN_A (1 << 0) #define GAMEPAD_BTN_B (1 << 1) #define GAMEPAD_BTN_X (1 << 2) @@ -419,10 +419,10 @@ void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { struct gamepad_report_t gamepad; uint32_t send_count = 4; uint64_t send[send_count]; - send[0] = (uint64_t)virtgamepad_input[0]; // device name - send[1] = strlen((char *)virtgamepad_input[0]); // name length - send[2] = (uint64_t)&gamepad; // mouse struct - send[3] = sizeof(struct gamepad_report_t); // mouse struct len + send[0] = (uint64_t)virtgamepad_input[0]; // device name + send[1] = strlen((char *)virtgamepad_input[0]); // name length + send[2] = (uint64_t)&gamepad; // mouse struct + send[3] = sizeof(struct gamepad_report_t); // mouse struct len auto flags = gamepad_state.buttonFlags; From 9675eebf0ec929076f4d80688e8db6ba2dfa50e8 Mon Sep 17 00:00:00 2001 From: Victor Varenik <38311102+kotleni@users.noreply.github.com> Date: Thu, 12 Jan 2023 10:37:39 +0200 Subject: [PATCH 07/18] Update input.cpp --- src/platform/macos/input.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index 0dd47a06e79..ef3c58601f7 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -31,8 +31,6 @@ #define GAMEPAD_BTN_Y (1 << 3) #define GAMEPAD_BTN_L (1 << 4) #define GAMEPAD_BTN_R (1 << 5) -#define GAMEPAD_BTN_LT (1 << 6) -#define GAMEPAD_BTN_RT (1 << 7) #define GAMEPAD_BTN_BACK (1 << 8) #define GAMEPAD_BTN_START (1 << 9) #define GAMEPAD_BTN_LS (1 << 10) @@ -445,15 +443,13 @@ void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { if(flags & DPAD_LEFT) gamepad.buttons |= GAMEPAD_BTN_LEFT; if(flags & DPAD_RIGHT) gamepad.buttons |= GAMEPAD_BTN_RIGHT; - // Map triggers - if(gamepad_state.lt > 0) gamepad.buttons |= GAMEPAD_BTN_LT; - if(gamepad_state.rt > 0) gamepad.buttons |= GAMEPAD_BTN_RT; - // Map sticks gamepad.x = gamepad_state.lsX; gamepad.y = -gamepad_state.lsY; gamepad.rx = gamepad_state.rsX; gamepad.ry = -gamepad_state.rsY; + gamepad.z = gamepad_state.lt; + gamepad.rz = gamepad_state.rt; kern_return_t ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_SEND, send, send_count, NULL, 0); if(ret != KERN_SUCCESS) { From 151c788f299c464d1eb47731f86f0901d8e3f93c Mon Sep 17 00:00:00 2001 From: Victor Varenik <38311102+kotleni@users.noreply.github.com> Date: Thu, 12 Jan 2023 11:41:56 +0200 Subject: [PATCH 08/18] Reverted digital gamepad triggers for macOS --- src/platform/macos/input.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index ef3c58601f7..0dd47a06e79 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -31,6 +31,8 @@ #define GAMEPAD_BTN_Y (1 << 3) #define GAMEPAD_BTN_L (1 << 4) #define GAMEPAD_BTN_R (1 << 5) +#define GAMEPAD_BTN_LT (1 << 6) +#define GAMEPAD_BTN_RT (1 << 7) #define GAMEPAD_BTN_BACK (1 << 8) #define GAMEPAD_BTN_START (1 << 9) #define GAMEPAD_BTN_LS (1 << 10) @@ -443,13 +445,15 @@ void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state) { if(flags & DPAD_LEFT) gamepad.buttons |= GAMEPAD_BTN_LEFT; if(flags & DPAD_RIGHT) gamepad.buttons |= GAMEPAD_BTN_RIGHT; + // Map triggers + if(gamepad_state.lt > 0) gamepad.buttons |= GAMEPAD_BTN_LT; + if(gamepad_state.rt > 0) gamepad.buttons |= GAMEPAD_BTN_RT; + // Map sticks gamepad.x = gamepad_state.lsX; gamepad.y = -gamepad_state.lsY; gamepad.rx = gamepad_state.rsX; gamepad.ry = -gamepad_state.rsY; - gamepad.z = gamepad_state.lt; - gamepad.rz = gamepad_state.rt; kern_return_t ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_SEND, send, send_count, NULL, 0); if(ret != KERN_SUCCESS) { From c640b0f7fffa5458f7fe94a80493b6e75f36d733 Mon Sep 17 00:00:00 2001 From: kotleni Date: Fri, 13 Jan 2023 16:11:20 +0200 Subject: [PATCH 09/18] Updated docs for macOS --- docs/source/about/installation.rst | 2 +- docs/source/about/usage.rst | 2 ++ docs/source/troubleshooting/macos.rst | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/source/about/installation.rst b/docs/source/about/installation.rst index dede1f22d0c..444c98c3851 100644 --- a/docs/source/about/installation.rst +++ b/docs/source/about/installation.rst @@ -188,7 +188,7 @@ Uninstall: macOS ----- -Sunshine on macOS is experimental. Gamepads do not work. Other features may not work as expected. +Sunshine on macOS is experimental. Other features may not work as expected. pkg ^^^ diff --git a/docs/source/about/usage.rst b/docs/source/about/usage.rst index db7af09ea7e..1ad78fe23f9 100644 --- a/docs/source/about/usage.rst +++ b/docs/source/about/usage.rst @@ -144,6 +144,8 @@ Sunshine needs access to `uinput` to create mouse and gamepad events. macOS ^^^^^ +For gamepad support, install `VirtualHID `_ + Sunshine can only access microphones on macOS due to system limitations. To stream system audio use `Soundflower `_ or `BlackHole `_. diff --git a/docs/source/troubleshooting/macos.rst b/docs/source/troubleshooting/macos.rst index 551f6945f4a..cdca0785f7f 100644 --- a/docs/source/troubleshooting/macos.rst +++ b/docs/source/troubleshooting/macos.rst @@ -11,3 +11,14 @@ If you get this error: .. code-block:: bash launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist + +No gamepad detected +------------------- +#. Verify that you've installed `VirtualHID `_. + +Unable to create HID device +--------------------------- +If you get this error: + `Gamepad: Unable to create HID device. May be fine if created previously.` + + It's okay. It's just a warning. From 1364baa93dc5218b2b04052facff5c1d98b2f95a Mon Sep 17 00:00:00 2001 From: kotleni Date: Sat, 14 Jan 2023 09:10:06 +0200 Subject: [PATCH 10/18] Updated docs --- docs/source/about/installation.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/source/about/installation.rst b/docs/source/about/installation.rst index 444c98c3851..bdafbdd88b1 100644 --- a/docs/source/about/installation.rst +++ b/docs/source/about/installation.rst @@ -188,8 +188,6 @@ Uninstall: macOS ----- -Sunshine on macOS is experimental. Other features may not work as expected. - pkg ^^^ .. Warning:: The `pkg` does not include runtime dependencies. From c1f5a66a0dda4e6777b6023c4f3e3be4b502e2c6 Mon Sep 17 00:00:00 2001 From: kotleni Date: Sat, 14 Jan 2023 09:10:23 +0200 Subject: [PATCH 11/18] Updated notes in Portfile --- packaging/macos/Portfile | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/macos/Portfile b/packaging/macos/Portfile index fb5fb13a8f0..bc939e1042d 100644 --- a/packaging/macos/Portfile +++ b/packaging/macos/Portfile @@ -63,3 +63,4 @@ notes-append "Run @PROJECT_NAME@ by executing 'sunshine ', notes-append "The config file will be created if it doesn't exist." notes-append "It is recommended to set a location for the apps file in the config." notes-append "See our documentation at 'https://docs.lizardbyte.dev/projects/sunshine/en/v@PROJECT_VERSION@/' for further info." +notes-append "For gamepad support, install VirtualHID from 'https://github.com/kotleni/VirtualHID-macOS/releases/latest' \ No newline at end of file From f5c62464cb73e6d903cdd6649a08e364d4049951 Mon Sep 17 00:00:00 2001 From: kotleni Date: Mon, 16 Jan 2023 08:47:37 +0200 Subject: [PATCH 12/18] Updated docs for macOS --- docs/source/about/installation.rst | 1 + packaging/macos/Portfile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/about/installation.rst b/docs/source/about/installation.rst index bdafbdd88b1..9cf81352eb3 100644 --- a/docs/source/about/installation.rst +++ b/docs/source/about/installation.rst @@ -188,6 +188,7 @@ Uninstall: macOS ----- + pkg ^^^ .. Warning:: The `pkg` does not include runtime dependencies. diff --git a/packaging/macos/Portfile b/packaging/macos/Portfile index bc939e1042d..d34be7a919c 100644 --- a/packaging/macos/Portfile +++ b/packaging/macos/Portfile @@ -62,5 +62,5 @@ pre-build { notes-append "Run @PROJECT_NAME@ by executing 'sunshine ', e.g. 'sunshine ~/sunshine.conf' " notes-append "The config file will be created if it doesn't exist." notes-append "It is recommended to set a location for the apps file in the config." +notes-append "For gamepad support, install VirtualHID from 'https://github.com/kotleni/VirtualHID-macOS/releases/latest'." notes-append "See our documentation at 'https://docs.lizardbyte.dev/projects/sunshine/en/v@PROJECT_VERSION@/' for further info." -notes-append "For gamepad support, install VirtualHID from 'https://github.com/kotleni/VirtualHID-macOS/releases/latest' \ No newline at end of file From 92db0b7842eef53d85c219caa35c67373916bb73 Mon Sep 17 00:00:00 2001 From: Victor Varenik <38311102+kotleni@users.noreply.github.com> Date: Wed, 18 Jan 2023 00:39:20 +0200 Subject: [PATCH 13/18] Updated docs for macOS --- docs/source/about/usage.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/source/about/usage.rst b/docs/source/about/usage.rst index 1ad78fe23f9..262385cd6b5 100644 --- a/docs/source/about/usage.rst +++ b/docs/source/about/usage.rst @@ -152,8 +152,6 @@ Sunshine can only access microphones on macOS due to system limitations. To stre .. Note:: Command Keys are not forwarded by Moonlight. Right Option-Key is mapped to CMD-Key. -.. Caution:: Gamepads are not currently supported. - Configure autostart service **MacPorts** .. code-block:: bash From 2512eea61909d6de3a6f8d115c4e15cffc717c9f Mon Sep 17 00:00:00 2001 From: Victor Varenik <38311102+kotleni@users.noreply.github.com> Date: Wed, 18 Jan 2023 00:56:01 +0200 Subject: [PATCH 14/18] Updated docs for macOS --- docs/source/troubleshooting/macos.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/troubleshooting/macos.rst b/docs/source/troubleshooting/macos.rst index cdca0785f7f..f9492a22e5d 100644 --- a/docs/source/troubleshooting/macos.rst +++ b/docs/source/troubleshooting/macos.rst @@ -7,10 +7,10 @@ If you get this error: `Dynamic session lookup supported but failed: launchd did not provide a socket path, verify that org.freedesktop.dbus-session.plist is loaded!` - Try this. - .. code-block:: bash +Try this. + .. code-block:: bash - launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist + launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist No gamepad detected ------------------- From df324745340fa2c640af269c21f7b2f5872c9868 Mon Sep 17 00:00:00 2001 From: Victor Varenik <38311102+kotleni@users.noreply.github.com> Date: Wed, 18 Jan 2023 01:22:21 +0200 Subject: [PATCH 15/18] Revert changes by 8b9d5a7 Commit 0457407e4c971b41b2ddf08092de283a7d9566ad --- docs/source/troubleshooting/macos.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/troubleshooting/macos.rst b/docs/source/troubleshooting/macos.rst index f9492a22e5d..cdca0785f7f 100644 --- a/docs/source/troubleshooting/macos.rst +++ b/docs/source/troubleshooting/macos.rst @@ -7,10 +7,10 @@ If you get this error: `Dynamic session lookup supported but failed: launchd did not provide a socket path, verify that org.freedesktop.dbus-session.plist is loaded!` -Try this. - .. code-block:: bash + Try this. + .. code-block:: bash - launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist + launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist No gamepad detected ------------------- From 92ff1c980cf4861ad4c33443a4cd6010b5e3e7a8 Mon Sep 17 00:00:00 2001 From: Victor Varenik <38311102+kotleni@users.noreply.github.com> Date: Wed, 18 Jan 2023 01:23:36 +0200 Subject: [PATCH 16/18] Updated docs for macOS --- docs/source/troubleshooting/macos.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/troubleshooting/macos.rst b/docs/source/troubleshooting/macos.rst index cdca0785f7f..8bfe17ce916 100644 --- a/docs/source/troubleshooting/macos.rst +++ b/docs/source/troubleshooting/macos.rst @@ -19,6 +19,6 @@ No gamepad detected Unable to create HID device --------------------------- If you get this error: - `Gamepad: Unable to create HID device. May be fine if created previously.` + `Gamepad: Unable to create HID device. May be fine if created previously.` It's okay. It's just a warning. From 554da261253c80cf0dc9b10b4f75fc781e7c81de Mon Sep 17 00:00:00 2001 From: kotleni Date: Mon, 27 Mar 2023 18:30:23 +0300 Subject: [PATCH 17/18] Fixed gamepad init * Changed service provider to foohid * Changed gamepad data to DualShock4 * Fixed wrong allocation size --- src/platform/macos/input.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index 0dd47a06e79..d2103f317fc 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -15,11 +15,11 @@ #define MULTICLICK_DELAY_NS 500000000 // For gamepad emulation -// https://github.com/kotleni/VirtualHID-macOS -#define VIRTGAMEPAD_NAME "Sunshine Gamepad" -#define VIRTGAMEPAD_SN "SG 0001" // serial number -#define VIRTGAMEPAD_INPUT_COUNT 16 // gamepad buttons count -#define SERVICE_NAME "it_kotleni_virthid" // virthid service id +// https://github.com/kotleni/foohid +#define VIRTGAMEPAD_NAME "DualShock 4" // gamepad name (only device names supported by macos) +#define VIRTGAMEPAD_SN "CUH-ZCT1x" // serial number +#define VIRTGAMEPAD_INPUT_COUNT 8 // device arguments count +#define SERVICE_NAME "it_unbit_foohid" // virthid service id #define FOOHID_CREATE 0 // create selector #define FOOHID_SEND 2 // send selector @@ -400,8 +400,8 @@ int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) { virtgamepad_input[3] = sizeof(gamepad_report_descriptor); // report descriptor len virtgamepad_input[4] = (uint64_t)strdup(VIRTGAMEPAD_SN); // serial number virtgamepad_input[5] = strlen((char *)virtgamepad_input[4]); // serial number len - virtgamepad_input[6] = (uint64_t)0xdead; // vendor ID - virtgamepad_input[7] = (uint64_t)0xbeef; // device ID + virtgamepad_input[6] = (uint64_t)0x054c; // vendor ID + virtgamepad_input[7] = (uint64_t)0x05c4; // device ID ret = IOConnectCallScalarMethod(virtgamepad_connect, FOOHID_CREATE, virtgamepad_input, VIRTGAMEPAD_INPUT_COUNT, NULL, 0); if(ret != KERN_SUCCESS) { From af72fac980ed91d1c4882a037aec5a5e267f2b26 Mon Sep 17 00:00:00 2001 From: kotleni Date: Mon, 27 Mar 2023 18:48:30 +0300 Subject: [PATCH 18/18] Removed wrong commentary --- src/platform/macos/input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index d2103f317fc..5edc3f35e76 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -16,7 +16,7 @@ // For gamepad emulation // https://github.com/kotleni/foohid -#define VIRTGAMEPAD_NAME "DualShock 4" // gamepad name (only device names supported by macos) +#define VIRTGAMEPAD_NAME "DualShock 4" // gamepad name #define VIRTGAMEPAD_SN "CUH-ZCT1x" // serial number #define VIRTGAMEPAD_INPUT_COUNT 8 // device arguments count #define SERVICE_NAME "it_unbit_foohid" // virthid service id