From f90578882d01734f8731c62ea82e24334529b191 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 16 Feb 2016 20:27:22 -0500 Subject: [PATCH] Implement Ctrl+Alt+Shift+Q to terminate the stream --- connectionlistener.cpp | 6 +++--- input.cpp | 19 ++++++++++++++++--- main.cpp | 3 +++ moonlight.hpp | 4 +++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/connectionlistener.cpp b/connectionlistener.cpp index 4a7c797..c003d15 100644 --- a/connectionlistener.cpp +++ b/connectionlistener.cpp @@ -21,11 +21,11 @@ void MoonlightInstance::ClConnectionStarted(void) { } void MoonlightInstance::ClConnectionTerminated(long errorCode) { + // Teardown the connection + LiStopConnection(); + pp::Module::Get()->core()->CallOnMainThread(0, g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::OnConnectionStopped), (uint32_t)errorCode); - - pp::Var response("Connection terminated"); - g_Instance->PostMessage(response); } void MoonlightInstance::ClDisplayMessage(char* message) { diff --git a/input.cpp b/input.cpp index bb50ce7..50bbbac 100644 --- a/input.cpp +++ b/input.cpp @@ -129,9 +129,15 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode()); if (m_KeyModifiers == (MODIFIER_ALT | MODIFIER_CTRL | MODIFIER_SHIFT)) { - g_Instance->UnlockMouse(); - m_MouseLocked = false; - return true; + if (keyboardEvent.GetKeyCode() == 0x51) { // Q key + // Call our connection listener to do the cleanup for us + MoonlightInstance::ClConnectionTerminated(0); + return true; + } + else { + // Wait until these keys come up to unlock the mouse + m_WaitingForAllModifiersUp = true; + } } LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(), @@ -148,6 +154,13 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { // Update modifier state before sending the key event 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(), KEY_ACTION_UP, m_KeyModifiers); diff --git a/main.cpp b/main.cpp index 62077e5..78ce30a 100644 --- a/main.cpp +++ b/main.cpp @@ -43,6 +43,9 @@ void MoonlightInstance::OnConnectionStopped(uint32_t error) { // Unlock the mouse g_Instance->UnlockMouse(); + + pp::Var response("Connection terminated"); + g_Instance->PostMessage(response); } void* MoonlightInstance::ConnectionThreadFunc(void* context) { diff --git a/moonlight.hpp b/moonlight.hpp index 36c168f..47e30e0 100644 --- a/moonlight.hpp +++ b/moonlight.hpp @@ -42,7 +42,8 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { m_OpusDecoder(NULL), m_CallbackFactory(this), 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!) 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 m_CallbackFactory; bool m_MouseLocked; char m_KeyModifiers; + bool m_WaitingForAllModifiersUp; }; extern MoonlightInstance* g_Instance;