From 831f583f89c087a5ea1bec4b717e06496217f260 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 21 May 2025 22:57:55 +0200 Subject: Add support for rumble streaming by default --- src/Config.cpp | 1 + src/GlobalHotkeys/GlobalHotkeysJoystick.cpp | 64 +++++++++++++++++++++++++++++ src/gui/SettingsPage.cpp | 9 ++++ 3 files changed, 74 insertions(+) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index ced9375..9e10534 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -201,6 +201,7 @@ namespace gsr { {"streaming.service", &config.streaming_config.streaming_service}, {"streaming.youtube.key", &config.streaming_config.youtube.stream_key}, {"streaming.twitch.key", &config.streaming_config.twitch.stream_key}, + {"streaming.rumble.key", &config.streaming_config.rumble.stream_key}, {"streaming.custom.url", &config.streaming_config.custom.url}, {"streaming.custom.container", &config.streaming_config.custom.container}, {"streaming.start_stop_hotkey", &config.streaming_config.start_stop_hotkey}, diff --git a/src/GlobalHotkeys/GlobalHotkeysJoystick.cpp b/src/GlobalHotkeys/GlobalHotkeysJoystick.cpp index b3b21c8..23f8a20 100644 --- a/src/GlobalHotkeys/GlobalHotkeysJoystick.cpp +++ b/src/GlobalHotkeys/GlobalHotkeysJoystick.cpp @@ -14,6 +14,68 @@ namespace gsr { static constexpr int axis_up_down = 7; static constexpr int axis_left_right = 6; + struct DeviceId { + uint16_t vendor; + uint16_t product; + }; + + static bool read_file_hex_number(const char *path, unsigned int *value) { + *value = 0; + FILE *f = fopen(path, "rb"); + if(!f) + return false; + + fscanf(f, "%x", value); + fclose(f); + return true; + } + + static DeviceId joystick_get_device_id(const char *path) { + DeviceId device_id; + device_id.vendor = 0; + device_id.product = 0; + + const char *js_path_id = nullptr; + const int len = strlen(path); + for(int i = len - 1; i >= 0; --i) { + if(path[i] == '/') { + js_path_id = path + i + 1; + break; + } + } + + if(!js_path_id) + return device_id; + + unsigned int vendor = 0; + unsigned int product = 0; + char path_buf[1024]; + + snprintf(path_buf, sizeof(path_buf), "/sys/class/input/%s/device/id/vendor", js_path_id); + if(!read_file_hex_number(path_buf, &vendor)) + return device_id; + + snprintf(path_buf, sizeof(path_buf), "/sys/class/input/%s/device/id/product", js_path_id); + if(!read_file_hex_number(path_buf, &product)) + return device_id; + + device_id.vendor = vendor; + device_id.product = product; + return device_id; + } + + static bool is_ps4_controller(DeviceId device_id) { + return device_id.vendor == 0x054C && (device_id.product == 0x09CC || device_id.product == 0x0BA0 || device_id.product == 0x05C4); + } + + static bool is_ps5_controller(DeviceId device_id) { + return device_id.vendor == 0x054C && (device_id.product == 0x0DF2 || device_id.product == 0x0CE6); + } + + static bool is_stadia_controller(DeviceId device_id) { + return device_id.vendor == 0x18D1 && (device_id.product == 0x9400); + } + // Returns -1 on error static int get_js_dev_input_id_from_filepath(const char *dev_input_filepath) { if(strncmp(dev_input_filepath, "/dev/input/js", 13) != 0) @@ -276,6 +338,8 @@ namespace gsr { dev_input_id }; + //const DeviceId device_id = joystick_get_device_id(dev_input_filepath); + ++num_poll_fd; fprintf(stderr, "Info: added joystick: %s\n", dev_input_filepath); return true; diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index 78c6e91..1230290 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -964,6 +964,7 @@ namespace gsr { auto streaming_service_box = std::make_unique(&get_theme().body_font); streaming_service_box->add_item("Twitch", "twitch"); streaming_service_box->add_item("YouTube", "youtube"); + streaming_service_box->add_item("Rumble", "rumble"); streaming_service_box->add_item("Custom", "custom"); streaming_service_box_ptr = streaming_service_box.get(); return streaming_service_box; @@ -988,6 +989,10 @@ namespace gsr { youtube_stream_key_entry_ptr = youtube_stream_key_entry.get(); stream_key_list->add_widget(std::move(youtube_stream_key_entry)); + auto rumble_stream_key_entry = std::make_unique(&get_theme().body_font, "", get_theme().body_font.get_character_size() * 20); + rumble_stream_key_entry_ptr = rumble_stream_key_entry.get(); + stream_key_list->add_widget(std::move(rumble_stream_key_entry)); + stream_key_list_ptr = stream_key_list.get(); return stream_key_list; } @@ -1049,12 +1054,14 @@ namespace gsr { streaming_service_box_ptr->on_selection_changed = [this](const std::string&, const std::string &id) { const bool twitch_option = id == "twitch"; const bool youtube_option = id == "youtube"; + const bool rumble_option = id == "rumble"; const bool custom_option = id == "custom"; stream_key_list_ptr->set_visible(!custom_option); stream_url_list_ptr->set_visible(custom_option); container_list_ptr->set_visible(custom_option); twitch_stream_key_entry_ptr->set_visible(twitch_option); youtube_stream_key_entry_ptr->set_visible(youtube_option); + rumble_stream_key_entry_ptr->set_visible(rumble_option); return true; }; streaming_service_box_ptr->on_selection_changed("Twitch", "twitch"); @@ -1256,6 +1263,7 @@ namespace gsr { streaming_service_box_ptr->set_selected_item(config.streaming_config.streaming_service); youtube_stream_key_entry_ptr->set_text(config.streaming_config.youtube.stream_key); twitch_stream_key_entry_ptr->set_text(config.streaming_config.twitch.stream_key); + rumble_stream_key_entry_ptr->set_text(config.streaming_config.rumble.stream_key); stream_url_entry_ptr->set_text(config.streaming_config.custom.url); container_box_ptr->set_selected_item(config.streaming_config.custom.container); } @@ -1397,6 +1405,7 @@ namespace gsr { config.streaming_config.streaming_service = streaming_service_box_ptr->get_selected_id(); config.streaming_config.youtube.stream_key = youtube_stream_key_entry_ptr->get_text(); config.streaming_config.twitch.stream_key = twitch_stream_key_entry_ptr->get_text(); + config.streaming_config.rumble.stream_key = rumble_stream_key_entry_ptr->get_text(); config.streaming_config.custom.url = stream_url_entry_ptr->get_text(); config.streaming_config.custom.container = container_box_ptr->get_selected_id(); } -- cgit v1.2.3-70-g09d2