mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-03-27 14:37:24 +00:00
simulate release of keyboard/gamepad/mouse buttons when stopping session
This commit is contained in:
parent
daaec4ba46
commit
b5fe713848
@ -120,18 +120,24 @@ void passthrough(platf::input_t &input, PNV_MOUSE_MOVE_PACKET packet) {
|
||||
platf::move_mouse(input, util::endian::big(packet->deltaX), util::endian::big(packet->deltaY));
|
||||
}
|
||||
|
||||
void passthrough(platf::input_t &input, PNV_MOUSE_BUTTON_PACKET packet) {
|
||||
void passthrough(std::shared_ptr<input_t> &input, PNV_MOUSE_BUTTON_PACKET packet) {
|
||||
auto constexpr BUTTON_RELEASED = 0x09;
|
||||
|
||||
display_cursor = true;
|
||||
|
||||
platf::button_mouse(input, util::endian::big(packet->button), packet->action == BUTTON_RELEASED);
|
||||
auto button = util::endian::big(packet->button);
|
||||
if(button > 0 && button < 4) {
|
||||
input->mouse_press[button] = packet->action != BUTTON_RELEASED;
|
||||
}
|
||||
|
||||
platf::button_mouse(input->input, button, packet->action == BUTTON_RELEASED);
|
||||
}
|
||||
|
||||
void passthrough(platf::input_t &input, PNV_KEYBOARD_PACKET packet) {
|
||||
void passthrough(std::shared_ptr<input_t> &input, PNV_KEYBOARD_PACKET packet) {
|
||||
auto constexpr BUTTON_RELEASED = 0x04;
|
||||
|
||||
platf::keyboard(input, packet->keyCode & 0x00FF, packet->keyAction == BUTTON_RELEASED);
|
||||
input->key_press[packet->keyCode] = packet->keyAction != BUTTON_RELEASED;
|
||||
platf::keyboard(input->input, packet->keyCode & 0x00FF, packet->keyAction == BUTTON_RELEASED);
|
||||
}
|
||||
|
||||
void passthrough(platf::input_t &input, PNV_SCROLL_PACKET packet) {
|
||||
@ -242,7 +248,7 @@ void passthrough_helper(std::shared_ptr<input_t> input, std::vector<std::uint8_t
|
||||
passthrough(input->input, (PNV_MOUSE_MOVE_PACKET)payload);
|
||||
break;
|
||||
case PACKET_TYPE_MOUSE_BUTTON:
|
||||
passthrough(input->input, (PNV_MOUSE_BUTTON_PACKET)payload);
|
||||
passthrough(input, (PNV_MOUSE_BUTTON_PACKET)payload);
|
||||
break;
|
||||
case PACKET_TYPE_SCROLL_OR_KEYBOARD:
|
||||
{
|
||||
@ -251,7 +257,7 @@ void passthrough_helper(std::shared_ptr<input_t> input, std::vector<std::uint8_t
|
||||
passthrough(input->input, (PNV_SCROLL_PACKET)payload);
|
||||
}
|
||||
else {
|
||||
passthrough(input->input, (PNV_KEYBOARD_PACKET)payload);
|
||||
passthrough(input, (PNV_KEYBOARD_PACKET)payload);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -262,9 +268,42 @@ void passthrough_helper(std::shared_ptr<input_t> input, std::vector<std::uint8_t
|
||||
}
|
||||
}
|
||||
|
||||
void reset_helper(std::shared_ptr<input_t> input) {
|
||||
for(auto &[key_press, key_down] : input->key_press) {
|
||||
if(key_down) {
|
||||
key_down = false;
|
||||
platf::keyboard(input->input, key_press & 0x00FF, true);
|
||||
}
|
||||
}
|
||||
|
||||
auto &mouse_press = input->mouse_press;
|
||||
for(int x = 0; x < mouse_press.size(); ++x) {
|
||||
if(mouse_press[x]) {
|
||||
mouse_press[x] = false;
|
||||
|
||||
platf::button_mouse(input->input, x + 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
NV_MULTI_CONTROLLER_PACKET fake_packet;
|
||||
fake_packet.buttonFlags = 0;
|
||||
fake_packet.leftStickX = 0;
|
||||
fake_packet.leftStickY = 0;
|
||||
fake_packet.rightStickX = 0;
|
||||
fake_packet.rightStickY = 0;
|
||||
fake_packet.leftTrigger = 0;
|
||||
fake_packet.rightTrigger = 0;
|
||||
|
||||
passthrough(input, &fake_packet);
|
||||
}
|
||||
|
||||
void passthrough(std::shared_ptr<input_t> &input, std::vector<std::uint8_t> &&input_data) {
|
||||
task_pool.push(passthrough_helper, input, util::cmove(input_data));
|
||||
}
|
||||
|
||||
void reset(std::shared_ptr<input_t> &input) {
|
||||
task_pool.push(reset_helper, input);
|
||||
}
|
||||
|
||||
input_t::input_t() : gamepad_state { 0 }, back_timeout_id { nullptr }, input { platf::input() } {}
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ struct input_t {
|
||||
input_t();
|
||||
|
||||
gamepad_state_t gamepad_state;
|
||||
std::unordered_map<short, bool> key_press;
|
||||
std::array<std::uint8_t, 3> mouse_press;
|
||||
|
||||
util::ThreadPool::task_id_t back_timeout_id;
|
||||
|
||||
platf::input_t input;
|
||||
@ -30,6 +33,7 @@ struct input_t {
|
||||
|
||||
void print(void *input);
|
||||
void passthrough(std::shared_ptr<input_t> &input, std::vector<std::uint8_t> &&input_data);
|
||||
void reset(std::shared_ptr<input_t> &input);
|
||||
}
|
||||
|
||||
#endif //SUNSHINE_INPUT_H
|
||||
|
@ -161,6 +161,7 @@ void stop(session_t &session) {
|
||||
session.video_packets->stop();
|
||||
session.audio_packets->stop();
|
||||
|
||||
input::reset(input);
|
||||
has_session.store(false);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user