From b1224032a1da6aba6580f4a28d30e2d3b7d0fc9e Mon Sep 17 00:00:00 2001 From: Christian Rupp Date: Wed, 8 Sep 2021 17:18:27 +0200 Subject: [PATCH 1/9] Add non US Backslash for international keyboards on Linux --- sunshine/platform/linux/input.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sunshine/platform/linux/input.cpp b/sunshine/platform/linux/input.cpp index e1d86a67..b96266d5 100644 --- a/sunshine/platform/linux/input.cpp +++ b/sunshine/platform/linux/input.cpp @@ -51,8 +51,8 @@ struct keycode_t { constexpr auto UNKNOWN = 0; -static constexpr std::array init_keycodes() { - std::array keycodes {}; +static constexpr std::array init_keycodes() { + std::array keycodes {}; #define __CONVERT(wincode, linuxcode, scancode) \ static_assert(wincode < keycodes.size(), "Keycode doesn't fit into keycode array"); \ @@ -182,6 +182,7 @@ static constexpr std::array init_keycodes() { __CONVERT(0xDC /* VKEY_OEM_5 */, KEY_BACKSLASH, 0x70031); __CONVERT(0xDD /* VKEY_OEM_6 */, KEY_RIGHTBRACE, 0x70030); __CONVERT(0xDE /* VKEY_OEM_7 */, KEY_APOSTROPHE, 0x70034); + __CONVERT(0xE2 /* VKEY_NON_US_BACKSLASH */, KEY_102ND, 0x70064); #undef __CONVERT return keycodes; From d8df57130a80f14d64ff6681726a5e8f697147ea Mon Sep 17 00:00:00 2001 From: WisdomCode Date: Thu, 9 Sep 2021 14:57:04 +0200 Subject: [PATCH 2/9] Apply key rewrite also when keeping key pressed --- sunshine/input.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sunshine/input.cpp b/sunshine/input.cpp index 6568ad7c..9d2b3962 100644 --- a/sunshine/input.cpp +++ b/sunshine/input.cpp @@ -396,18 +396,6 @@ void passthrough(std::shared_ptr &input, PNV_MOUSE_BUTTON_PACKET packet platf::button_mouse(platf_input, button, release); } -void repeat_key(short key_code) { - // If key no longer pressed, stop repeating - if(!key_press[key_code]) { - key_press_repeat_id = nullptr; - return; - } - - platf::keyboard(platf_input, key_code, false); - - key_press_repeat_id = task_pool.pushDelayed(repeat_key, config::input.key_repeat_period, key_code).task_id; -} - short map_keycode(short keycode) { auto it = config::input.keybindings.find(keycode); if(it != std::end(config::input.keybindings)) { @@ -416,6 +404,18 @@ short map_keycode(short keycode) { return keycode; } + +void repeat_key(short key_code) { + // If key no longer pressed, stop repeating + if(!key_press[key_code]) { + key_press_repeat_id = nullptr; + return; + } + + platf::keyboard(platf_input, map_keycode(keyCode), false); + + key_press_repeat_id = task_pool.pushDelayed(repeat_key, config::input.key_repeat_period, key_code).task_id; +} void passthrough(std::shared_ptr &input, PNV_KEYBOARD_PACKET packet) { auto constexpr BUTTON_RELEASED = 0x04; From 640f2b1c5561f520cc0f26dac0f53dd41a1af695 Mon Sep 17 00:00:00 2001 From: WisdomCode Date: Thu, 9 Sep 2021 15:05:04 +0200 Subject: [PATCH 3/9] Syntax --- sunshine/input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunshine/input.cpp b/sunshine/input.cpp index 9d2b3962..cba58602 100644 --- a/sunshine/input.cpp +++ b/sunshine/input.cpp @@ -412,7 +412,7 @@ void repeat_key(short key_code) { return; } - platf::keyboard(platf_input, map_keycode(keyCode), false); + platf::keyboard(platf_input, map_keycode(key_code), false); key_press_repeat_id = task_pool.pushDelayed(repeat_key, config::input.key_repeat_period, key_code).task_id; } From 9be80c103ea3d1c158598a463b89dcca167cfdc0 Mon Sep 17 00:00:00 2001 From: WisdomCode Date: Thu, 9 Sep 2021 21:15:35 +0200 Subject: [PATCH 4/9] Shortcut Flags need to be adjusted as well --- sunshine/input.cpp | 78 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/sunshine/input.cpp b/sunshine/input.cpp index cba58602..d0f40224 100644 --- a/sunshine/input.cpp +++ b/sunshine/input.cpp @@ -155,44 +155,6 @@ inline int apply_shortcut(short keyCode) { return 0; } -/** - * Update flags for keyboard shortcut combo's - */ -inline void update_shortcutFlags(int *flags, short keyCode, bool release) { - switch(keyCode) { - case VKEY_SHIFT: - case VKEY_LSHIFT: - case VKEY_RSHIFT: - if(release) { - *flags &= ~input_t::SHIFT; - } - else { - *flags |= input_t::SHIFT; - } - break; - case VKEY_CONTROL: - case VKEY_LCONTROL: - case VKEY_RCONTROL: - if(release) { - *flags &= ~input_t::CTRL; - } - else { - *flags |= input_t::CTRL; - } - break; - case VKEY_MENU: - case VKEY_LMENU: - case VKEY_RMENU: - if(release) { - *flags &= ~input_t::ALT; - } - else { - *flags |= input_t::ALT; - } - break; - } -} - void print(PNV_REL_MOUSE_MOVE_PACKET packet) { BOOST_LOG(debug) << "--begin relative mouse move packet--"sv << std::endl @@ -404,7 +366,45 @@ short map_keycode(short keycode) { return keycode; } - + +/** + * Update flags for keyboard shortcut combo's + */ +inline void update_shortcutFlags(int *flags, short keyCode, bool release) { + switch(map_keycode(keyCode)) { + case VKEY_SHIFT: + case VKEY_LSHIFT: + case VKEY_RSHIFT: + if(release) { + *flags &= ~input_t::SHIFT; + } + else { + *flags |= input_t::SHIFT; + } + break; + case VKEY_CONTROL: + case VKEY_LCONTROL: + case VKEY_RCONTROL: + if(release) { + *flags &= ~input_t::CTRL; + } + else { + *flags |= input_t::CTRL; + } + break; + case VKEY_MENU: + case VKEY_LMENU: + case VKEY_RMENU: + if(release) { + *flags &= ~input_t::ALT; + } + else { + *flags |= input_t::ALT; + } + break; + } +} + void repeat_key(short key_code) { // If key no longer pressed, stop repeating if(!key_press[key_code]) { From 35e0497f86af0f9640e7374f123af19499503696 Mon Sep 17 00:00:00 2001 From: Tobias Nordahl Kristensen Date: Sat, 11 Sep 2021 16:07:52 +0200 Subject: [PATCH 5/9] Adding note about `sink` in pipewire Also, splitting it up to two points, so it's a bit easier to read. --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b1da90c3..0c4bd7c5 100644 --- a/README.md +++ b/README.md @@ -79,9 +79,11 @@ It's necessary to allow Sunshine to use KMS - `groups $USER` - If Sunshine sends audio from the microphone instead of the speaker, try the following steps: - 1. `$ pacmd list-sources | grep "name:"` or `$ pactl info | grep Source` if running pipewire. + 1. Check whether you're using Pulseaudio or Pipewire + - Pulseaudio: Use `pacmd list-sources | grep "name:"` + - ipewire: Use `pactl info | grep Source`. In some causes you'd need to use the `sink` device. Try `pactl info | grep Sink`, if _Source_ doesn't work. 2. Copy the name to the configuration option "audio_sink" - 3. restart sunshine + 3. Restart sunshine - If you get "Error: Failed to create client: Daemon not running", ensure that your avahi-daemon is running: - `systemctl status avahi-daemon` From fea650fbe45e6b9ef09da2d044073b938447b046 Mon Sep 17 00:00:00 2001 From: Tobias Nordahl Kristensen Date: Mon, 13 Sep 2021 17:17:32 +0200 Subject: [PATCH 6/9] Typo ipewire --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c4bd7c5..69bf2c47 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ It's necessary to allow Sunshine to use KMS - If Sunshine sends audio from the microphone instead of the speaker, try the following steps: 1. Check whether you're using Pulseaudio or Pipewire - Pulseaudio: Use `pacmd list-sources | grep "name:"` - - ipewire: Use `pactl info | grep Source`. In some causes you'd need to use the `sink` device. Try `pactl info | grep Sink`, if _Source_ doesn't work. + - Pipewire: Use `pactl info | grep Source`. In some causes you'd need to use the `sink` device. Try `pactl info | grep Sink`, if _Source_ doesn't work. 2. Copy the name to the configuration option "audio_sink" 3. Restart sunshine From 91a6e55f7487509168960ac960e637739a7182bb Mon Sep 17 00:00:00 2001 From: loki Date: Mon, 13 Sep 2021 20:24:04 +0200 Subject: [PATCH 7/9] Fix segfault when connecting multiple controllers at the same ttime --- sunshine/input.cpp | 4 ++-- sunshine/platform/common.h | 2 +- sunshine/platform/windows/input.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sunshine/input.cpp b/sunshine/input.cpp index d0f40224..9652b2bf 100644 --- a/sunshine/input.cpp +++ b/sunshine/input.cpp @@ -460,7 +460,7 @@ void passthrough(PNV_SCROLL_PACKET packet) { platf::scroll(platf_input, util::endian::big(packet->scrollAmt1)); } -int updateGamepads(std::vector &gamepads, std::int16_t old_state, std::int16_t new_state, platf::rumble_queue_t rumble_queue) { +int updateGamepads(std::vector &gamepads, std::int16_t old_state, std::int16_t new_state, const platf::rumble_queue_t &rumble_queue) { auto xorGamepadMask = old_state ^ new_state; if(!xorGamepadMask) { return 0; @@ -486,7 +486,7 @@ int updateGamepads(std::vector &gamepads, std::int16_t old_state, std return -1; } - if(platf::alloc_gamepad(platf_input, id, std::move(rumble_queue))) { + if(platf::alloc_gamepad(platf_input, id, rumble_queue)) { free_id(gamepadMask, id); // allocating a gamepad failed: solution: ignore gamepads // The implementations of platf::alloc_gamepad already has logging diff --git a/sunshine/platform/common.h b/sunshine/platform/common.h index 4fe87b7c..7482f0ea 100644 --- a/sunshine/platform/common.h +++ b/sunshine/platform/common.h @@ -290,7 +290,7 @@ void scroll(input_t &input, int distance); void keyboard(input_t &input, uint16_t modcode, bool release); void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state); -int alloc_gamepad(input_t &input, int nr, rumble_queue_t &&rumble_queue); +int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue); void free_gamepad(input_t &input, int nr); #define SERVICE_NAME "Sunshine" diff --git a/sunshine/platform/windows/input.cpp b/sunshine/platform/windows/input.cpp index b637b0d6..88183f4b 100755 --- a/sunshine/platform/windows/input.cpp +++ b/sunshine/platform/windows/input.cpp @@ -326,7 +326,7 @@ void keyboard(input_t &input, uint16_t modcode, bool release) { send_input(i); } -int alloc_gamepad(input_t &input, int nr, rumble_queue_t &&rumble_queue) { +int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) { if(!input) { return 0; } From 9c0ea17ada0334055ac16ad33f157baebeedf11c Mon Sep 17 00:00:00 2001 From: loki Date: Mon, 13 Sep 2021 20:33:17 +0200 Subject: [PATCH 8/9] Update Linux specific code for fix in previous commit --- sunshine/platform/linux/input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunshine/platform/linux/input.cpp b/sunshine/platform/linux/input.cpp index b96266d5..a0d18578 100644 --- a/sunshine/platform/linux/input.cpp +++ b/sunshine/platform/linux/input.cpp @@ -986,7 +986,7 @@ void keyboard(input_t &input, uint16_t modcode, bool release) { keycode.pressed = 1; } -int alloc_gamepad(input_t &input, int nr, rumble_queue_t &&rumble_queue) { +int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) { return ((input_raw_t *)input.get())->alloc_gamepad(nr, std::move(rumble_queue)); } From 7f4b9cf36c29687b7c8c4d4e8d231c25975b08fe Mon Sep 17 00:00:00 2001 From: loki Date: Mon, 13 Sep 2021 20:34:45 +0200 Subject: [PATCH 9/9] Change where keycode is mapped --- sunshine/input.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sunshine/input.cpp b/sunshine/input.cpp index 9652b2bf..2a7e4486 100644 --- a/sunshine/input.cpp +++ b/sunshine/input.cpp @@ -371,7 +371,7 @@ short map_keycode(short keycode) { * Update flags for keyboard shortcut combo's */ inline void update_shortcutFlags(int *flags, short keyCode, bool release) { - switch(map_keycode(keyCode)) { + switch(keyCode) { case VKEY_SHIFT: case VKEY_LSHIFT: case VKEY_RSHIFT: @@ -452,7 +452,7 @@ void passthrough(std::shared_ptr &input, PNV_KEYBOARD_PACKET packet) { pressed = !release; - update_shortcutFlags(&input->shortcutFlags, keyCode, release); + update_shortcutFlags(&input->shortcutFlags, map_keycode(keyCode), release); platf::keyboard(platf_input, map_keycode(keyCode), release); }