mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-01-30 03:32:43 +00:00
Add support for Unicode input messages on Windows
This commit is contained in:
parent
d912cce5ba
commit
e39d9bc662
@ -197,6 +197,14 @@ void print(PNV_KEYBOARD_PACKET packet) {
|
||||
<< "--end keyboard packet--"sv;
|
||||
}
|
||||
|
||||
void print(PNV_UNICODE_PACKET packet) {
|
||||
std::string text(packet->text, util::endian::big(packet->header.size) - sizeof(packet->header.magic));
|
||||
BOOST_LOG(debug)
|
||||
<< "--begin unicode packet--"sv << std::endl
|
||||
<< "text ["sv << text << ']' << std::endl
|
||||
<< "--end unicode packet--"sv;
|
||||
}
|
||||
|
||||
void print(PNV_MULTI_CONTROLLER_PACKET packet) {
|
||||
// Moonlight spams controller packet even when not necessary
|
||||
BOOST_LOG(verbose)
|
||||
@ -234,6 +242,9 @@ void print(void *payload) {
|
||||
case KEY_UP_EVENT_MAGIC:
|
||||
print((PNV_KEYBOARD_PACKET)payload);
|
||||
break;
|
||||
case UTF8_TEXT_EVENT_MAGIC:
|
||||
print((PNV_UNICODE_PACKET)payload);
|
||||
break;
|
||||
case MULTI_CONTROLLER_MAGIC_GEN5:
|
||||
print((PNV_MULTI_CONTROLLER_PACKET)payload);
|
||||
break;
|
||||
@ -448,6 +459,11 @@ void passthrough(PNV_SCROLL_PACKET packet) {
|
||||
platf::scroll(platf_input, util::endian::big(packet->scrollAmt1));
|
||||
}
|
||||
|
||||
void passthrough(PNV_UNICODE_PACKET packet) {
|
||||
auto size = util::endian::big(packet->header.size) - sizeof(packet->header.magic);
|
||||
platf::unicode(platf_input, packet->text, size);
|
||||
}
|
||||
|
||||
int updateGamepads(std::vector<gamepad_t> &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) {
|
||||
@ -609,6 +625,9 @@ void passthrough_helper(std::shared_ptr<input_t> input, std::vector<std::uint8_t
|
||||
case KEY_UP_EVENT_MAGIC:
|
||||
passthrough(input, (PNV_KEYBOARD_PACKET)payload);
|
||||
break;
|
||||
case UTF8_TEXT_EVENT_MAGIC:
|
||||
passthrough((PNV_UNICODE_PACKET)payload);
|
||||
break;
|
||||
case MULTI_CONTROLLER_MAGIC_GEN5:
|
||||
passthrough(input, (PNV_MULTI_CONTROLLER_PACKET)payload);
|
||||
break;
|
||||
|
@ -296,6 +296,7 @@ void button_mouse(input_t &input, int button, bool release);
|
||||
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);
|
||||
void unicode(input_t &input, char *utf8, int size);
|
||||
|
||||
int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue);
|
||||
void free_gamepad(input_t &input, int nr);
|
||||
|
@ -994,6 +994,10 @@ void keyboard(input_t &input, uint16_t modcode, bool release) {
|
||||
keycode.pressed = 1;
|
||||
}
|
||||
|
||||
void unicode(input_t &input, char *utf8, int size) {
|
||||
BOOST_LOG(info) << "unicode: Unicode input not yet implemented for Linux."sv;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
@ -277,6 +277,10 @@ void keyboard(input_t &input, uint16_t modcode, bool release) {
|
||||
CGEventPost(kCGHIDEventTap, event);
|
||||
}
|
||||
|
||||
void unicode(input_t &input, char *utf8, int size) {
|
||||
BOOST_LOG(info) << "unicode: Unicode input not yet implemented for MacOS."sv;
|
||||
}
|
||||
|
||||
int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) {
|
||||
BOOST_LOG(info) << "alloc_gamepad: Gamepad not yet implemented for MacOS."sv;
|
||||
return -1;
|
||||
|
@ -326,6 +326,34 @@ void keyboard(input_t &input, uint16_t modcode, bool release) {
|
||||
send_input(i);
|
||||
}
|
||||
|
||||
void unicode(input_t &input, char *utf8, int size) {
|
||||
// We can do no worse than one UTF-16 character per byte of UTF-8
|
||||
WCHAR wide[size];
|
||||
|
||||
int chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8, size, wide, size);
|
||||
if(chars <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send all key down events
|
||||
for(int i = 0; i < chars; i++) {
|
||||
INPUT input {};
|
||||
input.type = INPUT_KEYBOARD;
|
||||
input.ki.wScan = wide[i];
|
||||
input.ki.dwFlags = KEYEVENTF_UNICODE;
|
||||
send_input(input);
|
||||
}
|
||||
|
||||
// Send all key up events
|
||||
for(int i = 0; i < chars; i++) {
|
||||
INPUT input {};
|
||||
input.type = INPUT_KEYBOARD;
|
||||
input.ki.wScan = wide[i];
|
||||
input.ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
|
||||
send_input(input);
|
||||
}
|
||||
}
|
||||
|
||||
int alloc_gamepad(input_t &input, int nr, rumble_queue_t rumble_queue) {
|
||||
if(!input) {
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user