mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 08:36:42 +00:00
Modifiers are passed with every input event so we don't need to track them ourselves
This commit is contained in:
parent
ea80c6e3ef
commit
97052591ba
57
input.cpp
57
input.cpp
@ -8,10 +8,6 @@
|
|||||||
|
|
||||||
#define KEY_PREFIX 0x80
|
#define KEY_PREFIX 0x80
|
||||||
|
|
||||||
#define KEY_CODE_ALT 18
|
|
||||||
#define KEY_CODE_CTRL 17
|
|
||||||
#define KEY_CODE_SHIFT 16
|
|
||||||
|
|
||||||
static int ConvertPPButtonToLiButton(PP_InputEvent_MouseButton ppButton) {
|
static int ConvertPPButtonToLiButton(PP_InputEvent_MouseButton ppButton) {
|
||||||
switch (ppButton) {
|
switch (ppButton) {
|
||||||
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
|
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
|
||||||
@ -31,38 +27,23 @@ void MoonlightInstance::DidLockMouse(int32_t result) {
|
|||||||
|
|
||||||
void MoonlightInstance::MouseLockLost() {
|
void MoonlightInstance::MouseLockLost() {
|
||||||
m_MouseLocked = false;
|
m_MouseLocked = false;
|
||||||
m_KeyModifiers = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoonlightInstance::UpdateModifiers(PP_InputEvent_Type eventType, short keyCode) {
|
static char GetModifierFlags(const pp::InputEvent& event) {
|
||||||
switch (keyCode) {
|
uint32_t modifiers = event.GetModifiers();
|
||||||
case KEY_CODE_ALT:
|
char flags = 0;
|
||||||
if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) {
|
|
||||||
m_KeyModifiers |= MODIFIER_ALT;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_KeyModifiers &= ~MODIFIER_ALT;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KEY_CODE_CTRL:
|
if (modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY) {
|
||||||
if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) {
|
flags |= MODIFIER_SHIFT;
|
||||||
m_KeyModifiers |= MODIFIER_CTRL;
|
|
||||||
}
|
}
|
||||||
else {
|
if (modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY) {
|
||||||
m_KeyModifiers &= ~MODIFIER_CTRL;
|
flags |= MODIFIER_CTRL;
|
||||||
|
}
|
||||||
|
if (modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY) {
|
||||||
|
flags |= MODIFIER_ALT;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case KEY_CODE_SHIFT:
|
return flags;
|
||||||
if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) {
|
|
||||||
m_KeyModifiers |= MODIFIER_SHIFT;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_KeyModifiers &= ~MODIFIER_SHIFT;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
||||||
@ -135,11 +116,9 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pp::KeyboardInputEvent keyboardEvent(event);
|
pp::KeyboardInputEvent keyboardEvent(event);
|
||||||
|
char modifiers = GetModifierFlags(event);
|
||||||
|
|
||||||
// Update modifier state before sending the key event
|
if (modifiers == (MODIFIER_ALT | MODIFIER_CTRL | MODIFIER_SHIFT)) {
|
||||||
UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode());
|
|
||||||
|
|
||||||
if (m_KeyModifiers == (MODIFIER_ALT | MODIFIER_CTRL | MODIFIER_SHIFT)) {
|
|
||||||
if (keyboardEvent.GetKeyCode() == 0x51) { // Q key
|
if (keyboardEvent.GetKeyCode() == 0x51) { // Q key
|
||||||
// Terminate the connection
|
// Terminate the connection
|
||||||
StopConnection();
|
StopConnection();
|
||||||
@ -152,7 +131,7 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
|
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
|
||||||
KEY_ACTION_DOWN, m_KeyModifiers);
|
KEY_ACTION_DOWN, modifiers);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,19 +141,17 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pp::KeyboardInputEvent keyboardEvent(event);
|
pp::KeyboardInputEvent keyboardEvent(event);
|
||||||
|
char modifiers = GetModifierFlags(event);
|
||||||
// Update modifier state before sending the key event
|
|
||||||
UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode());
|
|
||||||
|
|
||||||
// Check if all modifiers are up now
|
// Check if all modifiers are up now
|
||||||
if (m_WaitingForAllModifiersUp && m_KeyModifiers == 0) {
|
if (m_WaitingForAllModifiersUp && modifiers == 0) {
|
||||||
UnlockMouse();
|
UnlockMouse();
|
||||||
m_MouseLocked = false;
|
m_MouseLocked = false;
|
||||||
m_WaitingForAllModifiersUp = false;
|
m_WaitingForAllModifiersUp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
|
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
|
||||||
KEY_ACTION_UP, m_KeyModifiers);
|
KEY_ACTION_UP, modifiers);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
|||||||
m_OpusDecoder(NULL),
|
m_OpusDecoder(NULL),
|
||||||
m_CallbackFactory(this),
|
m_CallbackFactory(this),
|
||||||
m_MouseLocked(false),
|
m_MouseLocked(false),
|
||||||
m_KeyModifiers(0),
|
|
||||||
m_WaitingForAllModifiersUp(false),
|
m_WaitingForAllModifiersUp(false),
|
||||||
m_AccumulatedTicks(0),
|
m_AccumulatedTicks(0),
|
||||||
openHttpThread(this) {
|
openHttpThread(this) {
|
||||||
@ -74,7 +73,6 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
|||||||
void HandleOpenURL(int32_t callbackId, pp::VarArray args);
|
void HandleOpenURL(int32_t callbackId, pp::VarArray args);
|
||||||
void PairCallback(int32_t /*result*/, int32_t callbackId, pp::VarArray args);
|
void PairCallback(int32_t /*result*/, int32_t callbackId, pp::VarArray args);
|
||||||
|
|
||||||
void UpdateModifiers(PP_InputEvent_Type eventType, short keyCode);
|
|
||||||
bool HandleInputEvent(const pp::InputEvent& event);
|
bool HandleInputEvent(const pp::InputEvent& event);
|
||||||
|
|
||||||
void PollGamepads();
|
void PollGamepads();
|
||||||
@ -150,7 +148,6 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
|||||||
const PPB_Gamepad* m_GamepadApi;
|
const PPB_Gamepad* m_GamepadApi;
|
||||||
pp::CompletionCallbackFactory<MoonlightInstance> m_CallbackFactory;
|
pp::CompletionCallbackFactory<MoonlightInstance> m_CallbackFactory;
|
||||||
bool m_MouseLocked;
|
bool m_MouseLocked;
|
||||||
char m_KeyModifiers;
|
|
||||||
bool m_WaitingForAllModifiersUp;
|
bool m_WaitingForAllModifiersUp;
|
||||||
float m_AccumulatedTicks;
|
float m_AccumulatedTicks;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user