Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -947,6 +951,10 @@ void apply_config(std::unordered_map<std::string, std::string> &&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;
Expand Down
4 changes: 4 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ struct input_t {
std::chrono::duration<double> key_repeat_period;

std::string gamepad;

bool keyboard;
bool mouse;
bool controller;
};

namespace flag {
Expand Down
32 changes: 32 additions & 0 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,19 @@ void print(void *payload) {
}

void passthrough(std::shared_ptr<input_t> &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_t> &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;
}
Expand Down Expand Up @@ -313,6 +321,10 @@ void passthrough(std::shared_ptr<input_t> &input, PNV_ABS_MOUSE_MOVE_PACKET pack
}

void passthrough(std::shared_ptr<input_t> &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()) {
Expand Down Expand Up @@ -430,6 +442,10 @@ void repeat_key(short key_code) {
}

void passthrough(std::shared_ptr<input_t> &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;

Expand Down Expand Up @@ -467,14 +483,26 @@ void passthrough(std::shared_ptr<input_t> &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);
}
Expand Down Expand Up @@ -521,6 +549,10 @@ int updateGamepads(std::vector<gamepad_t> &gamepads, std::int16_t old_state, std
}

void passthrough(std::shared_ptr<input_t> &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;
}
Expand Down
54 changes: 54 additions & 0 deletions src_assets/common/assets/web/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,57 @@ <h1 class="my-4">Configuration</h1>
If back_button_timeout &lt; 0, then the Home/Guide button will not be emulated<br />
</div>
</div>
<!--Enable Mouse Input-->
<div class="mb-3">
<label for="mouse" class="form-label"
>Enable Mouse Input</label
>
<select
id="mouse"
class="form-select"
v-model="config.mouse"
>
<option value="disabled">Disabled</option>
<option value="enabled">Enabled</option>
</select>
<div class="form-text">
Allows guests to control the host system with the mouse
</div>
</div>
<!--Enable Keyboard Input-->
<div class="mb-3">
<label for="keyboard" class="form-label"
>Enable Keyboard Input</label
>
<select
id="keyboard"
class="form-select"
v-model="config.keyboard"
>
<option value="disabled">Disabled</option>
<option value="enabled">Enabled</option>
</select>
<div class="form-text">
Allows guests to control the host system with the keyboard
</div>
</div>
<!--Enable Gamepad Input-->
<div class="mb-3">
<label for="gamepad" class="form-label"
>Enable Gamepad Input</label
>
<select
id="gamepad"
class="form-select"
v-model="config.controller"
>
<option value="disabled">Disabled</option>
<option value="enabled">Enabled</option>
</select>
<div class="form-text">
Allows guests to control the host system with a gamepad / controller
</div>
</div>
<!-- Key Repeat Delay-->
<div class="mb-3" v-if="platform === 'windows'">
<label for="key_repeat_delay" class="form-label"
Expand Down Expand Up @@ -952,6 +1003,9 @@ <h1 class="my-4">Configuration</h1>
this.config.origin_pin_allowed || "pc";
this.config.origin_web_ui_allowed =
this.config.origin_web_ui_allowed || "lan";
this.config.mouse = this.config.mouse || "enabled";
this.config.keyboard = this.config.keyboard || "enabled";
this.config.controller = this.config.controller || "enabled";
this.config.hevc_mode = this.config.hevc_mode || 0;
this.config.encoder = this.config.encoder || "";
this.config.nv_preset = this.config.nv_preset || "p4";
Expand Down