fix(input): honor extended keyboard modifier (#5821)

This commit is contained in:
Dave Lane authored and GitHub committed 2026-09-28 21:43:24 -04:00
1 parent 052b413216
commit 2435fb421d
8 files changed
+79 -25

No files matched your search

+30 -16
View File
@@ -163,7 +163,16 @@ namespace input {
}
static task_pool_util::TaskPool::task_id_t key_press_repeat_id {};
static std::unordered_map<key_press_id_t, bool> key_press {};
/**
* @brief Press state retained so releases and repeats use the key's original identity.
*/
struct key_press_state_t {
bool pressed = false; ///< Whether the key is held.
bool extended = false; ///< Whether its press identified an extended key.
};
static std::unordered_map<key_press_id_t, key_press_state_t> key_press {};
static std::array<std::uint8_t, 5> mouse_press {};
static platf::input_t platf_input;
@@ -1093,15 +1102,16 @@ namespace input {
* @param key_code Platform keycode to emit.
* @param release Whether the key event is a release.
* @param flags Bit flags that modify the requested operation.
* @param extended Whether the client identified an extended key.
*/
void emit_keyboard_update(uint16_t key_code, bool release, uint8_t flags) {
void emit_keyboard_update(uint16_t key_code, bool release, uint8_t flags, bool extended = false) {
#ifdef SUNSHINE_TESTS
if (keyboard_sink()) {
keyboard_sink()(testing::keyboard_event_t {key_code, release, flags});
keyboard_sink()(testing::keyboard_event_t {key_code, release, flags, extended});
return;
}
#endif
platf::keyboard_update(platf_input, key_code, release, flags);
platf::keyboard_update(platf_input, key_code, release, flags, extended);
}
/**
@@ -1111,8 +1121,9 @@ namespace input {
* @param release Whether the key or button event is a release.
* @param flags Bit flags that modify the requested operation.
* @param synthetic_modifiers Synthetic modifiers.
* @param extended Whether the client identified an extended key.
*/
void send_key_and_modifiers(uint16_t key_code, bool release, uint8_t flags, uint8_t synthetic_modifiers) {
void send_key_and_modifiers(uint16_t key_code, bool release, uint8_t flags, uint8_t synthetic_modifiers, bool extended) {
if (!release) {
// Press any synthetic modifiers required for this key
if (synthetic_modifiers & MODIFIER_SHIFT) {
@@ -1126,7 +1137,7 @@ namespace input {
}
}
emit_keyboard_update(map_keycode(key_code), release, flags);
emit_keyboard_update(map_keycode(key_code), release, flags, extended);
if (!release) {
// Raise any synthetic modifier keys we pressed
@@ -1151,12 +1162,13 @@ namespace input {
*/
void repeat_key(uint16_t key_code, uint8_t flags, uint8_t synthetic_modifiers) {
// If key no longer pressed, stop repeating
if (!key_press[make_kpid(key_code, flags)]) {
const auto state = key_press[make_kpid(key_code, flags)];
if (!state.pressed) {
key_press_repeat_id = nullptr;
return;
}
send_key_and_modifiers(key_code, false, flags, synthetic_modifiers);
send_key_and_modifiers(key_code, false, flags, synthetic_modifiers, state.extended);
key_press_repeat_id = task_pool.pushDelayed(repeat_key, config::input.key_repeat_period, key_code, flags, synthetic_modifiers).task_id;
}
@@ -1198,8 +1210,8 @@ namespace input {
}
}
auto &pressed = key_press[make_kpid(keyCode, packet->flags)];
if (!pressed) {
auto &state = key_press[make_kpid(keyCode, packet->flags)];
if (!state.pressed) {
if (!release) {
// A new key has been pressed down, we need to check for key combo's
// If a key-combo has been pressed down, don't pass it through
@@ -1207,6 +1219,8 @@ namespace input {
return;
}
state.extended = (modifiers & MODIFIER_EXTENDED) != 0;
if (key_press_repeat_id) {
task_pool.cancel(key_press_repeat_id);
}
@@ -1223,9 +1237,9 @@ namespace input {
return;
}
pressed = !release;
state.pressed = !release;
send_key_and_modifiers(keyCode, release, packet->flags, synthetic_modifiers);
send_key_and_modifiers(keyCode, release, packet->flags, synthetic_modifiers, state.extended);
// Track the modifier state the client is holding, not the remapped host key.
// This is compared against packet->modifiers above, which is client-side, so a
@@ -2243,13 +2257,13 @@ namespace input {
* @brief Release every pressed keyboard key tracked by Sunshine.
*/
void reset_keyboard_keys() {
for (auto &[key, pressed] : key_press) {
if (pressed) {
for (auto &[key, state] : key_press) {
if (state.pressed) {
// key_press is keyed on the client's unmapped virtual-key code, but the press was
// emitted through map_keycode(). Release the host key that actually went down,
// otherwise a remapped modifier stays latched after the client disconnects.
emit_keyboard_update(map_keycode(vk_from_kpid(key) & 0x00FF), true, flags_from_kpid(key));
pressed = false;
emit_keyboard_update(map_keycode(vk_from_kpid(key) & 0x00FF), true, flags_from_kpid(key), state.extended);
state.pressed = false;
}
}
}