diff --git a/src/config.cpp b/src/config.cpp index 27e70657043..4ddecf42551 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -408,6 +408,10 @@ input_t input { platf::supported_gamepads().front().data(), platf::supported_gamepads().front().size(), }, // Default gamepad + + false, + false, + false, }; sunshine_t sunshine { @@ -947,6 +951,10 @@ void apply_config(std::unordered_map &&vars) { string_restricted_f(vars, "gamepad"s, input.gamepad, platf::supported_gamepads()); + bool_f(vars, "mouse", input.mouse); + bool_f(vars, "keyboard", input.keyboard); + bool_f(vars, "controller", input.controller); + int port = sunshine.port; int_f(vars, "port"s, port); sunshine.port = (std::uint16_t)port; diff --git a/src/config.h b/src/config.h index b27a10206c0..2a4a638ad93 100644 --- a/src/config.h +++ b/src/config.h @@ -100,6 +100,10 @@ struct input_t { std::chrono::duration key_repeat_period; std::string gamepad; + + bool keyboard; + bool mouse; + bool controller; }; namespace flag { diff --git a/src/input.cpp b/src/input.cpp index c360a6f3d10..54d887e70b7 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -263,11 +263,19 @@ void print(void *payload) { } void passthrough(std::shared_ptr &input, PNV_REL_MOUSE_MOVE_PACKET packet) { + if(!config::input.mouse) { + return; + } + input->mouse_left_button_timeout = DISABLE_LEFT_BUTTON_DELAY; platf::move_mouse(platf_input, util::endian::big(packet->deltaX), util::endian::big(packet->deltaY)); } void passthrough(std::shared_ptr &input, PNV_ABS_MOUSE_MOVE_PACKET packet) { + if(!config::input.mouse) { + return; + } + if(input->mouse_left_button_timeout == DISABLE_LEFT_BUTTON_DELAY) { input->mouse_left_button_timeout = ENABLE_LEFT_BUTTON_DELAY; } @@ -313,6 +321,10 @@ void passthrough(std::shared_ptr &input, PNV_ABS_MOUSE_MOVE_PACKET pack } void passthrough(std::shared_ptr &input, PNV_MOUSE_BUTTON_PACKET packet) { + if(!config::input.mouse) { + return; + } + auto release = util::endian::little(packet->header.magic) == MOUSE_BUTTON_UP_EVENT_MAGIC_GEN5; auto button = util::endian::big(packet->button); if(button > 0 && button < mouse_press.size()) { @@ -430,6 +442,10 @@ void repeat_key(short key_code) { } void passthrough(std::shared_ptr &input, PNV_KEYBOARD_PACKET packet) { + if(!config::input.keyboard) { + return; + } + auto release = util::endian::little(packet->header.magic) == KEY_UP_EVENT_MAGIC; auto keyCode = packet->keyCode & 0x00FF; @@ -467,14 +483,26 @@ void passthrough(std::shared_ptr &input, PNV_KEYBOARD_PACKET packet) { } void passthrough(PNV_SCROLL_PACKET packet) { + if(!config::input.mouse) { + return; + } + platf::scroll(platf_input, util::endian::big(packet->scrollAmt1)); } void passthrough(PSS_HSCROLL_PACKET packet) { + if(!config::input.mouse) { + return; + } + platf::hscroll(platf_input, util::endian::big(packet->scrollAmount)); } void passthrough(PNV_UNICODE_PACKET packet) { + if(!config::input.keyboard) { + return; + } + auto size = util::endian::big(packet->header.size) - sizeof(packet->header.magic); platf::unicode(platf_input, packet->text, size); } @@ -521,6 +549,10 @@ int updateGamepads(std::vector &gamepads, std::int16_t old_state, std } void passthrough(std::shared_ptr &input, PNV_MULTI_CONTROLLER_PACKET packet) { + if(!config::input.controller) { + return; + } + if(updateGamepads(input->gamepads, input->active_gamepad_state, packet->activeGamepadMask, input->rumble_queue)) { return; } diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index 6f555e364ea..d5c8dabaae4 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -297,6 +297,57 @@

Configuration

If back_button_timeout < 0, then the Home/Guide button will not be emulated
+ +
+ + +
+ Allows guests to control the host system with the mouse +
+
+ +
+ + +
+ Allows guests to control the host system with the keyboard +
+
+ +
+ + +
+ Allows guests to control the host system with a gamepad / controller +
+