Implement Ctrl+Alt+Shift+Q to terminate the stream

This commit is contained in:
Cameron Gutman 2016-02-16 20:27:22 -05:00
parent 02a9e80e76
commit f90578882d
4 changed files with 25 additions and 7 deletions

View File

@ -21,11 +21,11 @@ void MoonlightInstance::ClConnectionStarted(void) {
} }
void MoonlightInstance::ClConnectionTerminated(long errorCode) { void MoonlightInstance::ClConnectionTerminated(long errorCode) {
// Teardown the connection
LiStopConnection();
pp::Module::Get()->core()->CallOnMainThread(0, pp::Module::Get()->core()->CallOnMainThread(0,
g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::OnConnectionStopped), (uint32_t)errorCode); g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::OnConnectionStopped), (uint32_t)errorCode);
pp::Var response("Connection terminated");
g_Instance->PostMessage(response);
} }
void MoonlightInstance::ClDisplayMessage(char* message) { void MoonlightInstance::ClDisplayMessage(char* message) {

View File

@ -129,10 +129,16 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode()); UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode());
if (m_KeyModifiers == (MODIFIER_ALT | MODIFIER_CTRL | MODIFIER_SHIFT)) { if (m_KeyModifiers == (MODIFIER_ALT | MODIFIER_CTRL | MODIFIER_SHIFT)) {
g_Instance->UnlockMouse(); if (keyboardEvent.GetKeyCode() == 0x51) { // Q key
m_MouseLocked = false; // Call our connection listener to do the cleanup for us
MoonlightInstance::ClConnectionTerminated(0);
return true; return true;
} }
else {
// Wait until these keys come up to unlock the mouse
m_WaitingForAllModifiersUp = true;
}
}
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(), LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
KEY_ACTION_DOWN, m_KeyModifiers); KEY_ACTION_DOWN, m_KeyModifiers);
@ -149,6 +155,13 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
// Update modifier state before sending the key event // Update modifier state before sending the key event
UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode()); UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode());
// Check if all modifiers are up now
if (m_WaitingForAllModifiersUp && m_KeyModifiers == 0) {
g_Instance->UnlockMouse();
m_MouseLocked = false;
m_WaitingForAllModifiersUp = false;
}
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(), LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
KEY_ACTION_UP, m_KeyModifiers); KEY_ACTION_UP, m_KeyModifiers);
return true; return true;

View File

@ -43,6 +43,9 @@ void MoonlightInstance::OnConnectionStopped(uint32_t error) {
// Unlock the mouse // Unlock the mouse
g_Instance->UnlockMouse(); g_Instance->UnlockMouse();
pp::Var response("Connection terminated");
g_Instance->PostMessage(response);
} }
void* MoonlightInstance::ConnectionThreadFunc(void* context) { void* MoonlightInstance::ConnectionThreadFunc(void* context) {

View File

@ -42,7 +42,8 @@ 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_KeyModifiers(0),
m_WaitingForAllModifiersUp(false) {
// This function MUST be used otherwise sockets don't work (nacl_io_init() doesn't work!) // This function MUST be used otherwise sockets don't work (nacl_io_init() doesn't work!)
nacl_io_init_ppapi(pp_instance(), pp::Module::Get()->get_browser_interface()); nacl_io_init_ppapi(pp_instance(), pp::Module::Get()->get_browser_interface());
@ -120,6 +121,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
pp::CompletionCallbackFactory<MoonlightInstance> m_CallbackFactory; pp::CompletionCallbackFactory<MoonlightInstance> m_CallbackFactory;
bool m_MouseLocked; bool m_MouseLocked;
char m_KeyModifiers; char m_KeyModifiers;
bool m_WaitingForAllModifiersUp;
}; };
extern MoonlightInstance* g_Instance; extern MoonlightInstance* g_Instance;