merged, because I was an idiot who didn't pull before working

This commit is contained in:
R. Aidan Campbell 2016-05-09 09:12:08 -04:00
commit 5e9fe3c736
7 changed files with 40 additions and 55 deletions

View File

@ -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; if (modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY) {
} flags |= MODIFIER_SHIFT;
else {
m_KeyModifiers &= ~MODIFIER_ALT;
}
break;
case KEY_CODE_CTRL:
if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) {
m_KeyModifiers |= MODIFIER_CTRL;
}
else {
m_KeyModifiers &= ~MODIFIER_CTRL;
}
break;
case KEY_CODE_SHIFT:
if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) {
m_KeyModifiers |= MODIFIER_SHIFT;
}
else {
m_KeyModifiers &= ~MODIFIER_SHIFT;
}
break;
} }
if (modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY) {
flags |= MODIFIER_CTRL;
}
if (modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY) {
flags |= MODIFIER_ALT;
}
return flags;
} }
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;
} }

View File

@ -38,8 +38,12 @@ void MoonlightInstance::OnConnectionStarted(uint32_t unused) {
PostMessage(response); PostMessage(response);
// Start receiving input events // Start receiving input events
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
// Filtering is suboptimal but it ensures that we can pass keyboard events
// to the browser when mouse lock is disabled. This is neccessary for Esc
// to kick the app out of full-screen.
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
} }
void MoonlightInstance::OnConnectionStopped(uint32_t error) { void MoonlightInstance::OnConnectionStopped(uint32_t error) {
@ -177,10 +181,15 @@ void MoonlightInstance::HandleStartStream(int32_t callbackId, pp::VarArray args)
m_StreamConfig.height = stoi(height); m_StreamConfig.height = stoi(height);
m_StreamConfig.fps = stoi(fps); m_StreamConfig.fps = stoi(fps);
m_StreamConfig.bitrate = stoi(bitrate); // kilobits per second m_StreamConfig.bitrate = stoi(bitrate); // kilobits per second
m_StreamConfig.packetSize = 1024;
m_StreamConfig.streamingRemotely = 0; m_StreamConfig.streamingRemotely = 0;
m_StreamConfig.audioConfiguration = AUDIO_CONFIGURATION_STEREO; m_StreamConfig.audioConfiguration = AUDIO_CONFIGURATION_STEREO;
// The overhead of receiving a packet is much higher in NaCl because we must
// pass through various layers of abstraction on each recv() call. We're using a
// higher than normal default video packet size here to reduce CPU cycles wasted
// receiving packets. The possible cost is greater network losses.
m_StreamConfig.packetSize = 1392;
m_ServerMajorVersion = stoi(serverMajorVersion); m_ServerMajorVersion = stoi(serverMajorVersion);
// Initialize the rendering surface before starting the connection // Initialize the rendering surface before starting the connection

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Moonlight", "name": "Moonlight",
"version": "0.02", "version": "0.03",
"description": "A Moonlight streaming plugin for Google Chrome", "description": "A Moonlight streaming plugin for Google Chrome",
"icons": { "icons": {
"128": "icons/icon128.png", "128": "icons/icon128.png",

@ -1 +1 @@
Subproject commit f69ab5dd5eb8ca79bb59bcb9e87587a819c9bd4d Subproject commit dddcba217b315281364bca92e7e409b449fff000

View File

@ -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;

View File

@ -66,9 +66,9 @@ main {
margin: 3px; margin: 3px;
} }
#listener { #listener {
overflow: hidden; overflow: hidden;
margin-top: 20px; margin-top: 0px;
border: 1px solid; height: 0px;
} }
.fullscreen { .fullscreen {
height: 100vh !important; height: 100vh !important;

View File

@ -1,6 +1,8 @@
// just start the app in fullscreen
chrome.app.runtime.onLaunched.addListener(function() { chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('index.html', { chrome.app.window.create('index.html', {
state: "normal", state: "normal",
bounds: {
width: 850, height: 500
}
}); });
}); });