mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 16:46:31 +00:00
merged, because I was an idiot who didn't pull before working
This commit is contained in:
commit
5e9fe3c736
61
input.cpp
61
input.cpp
@ -8,10 +8,6 @@
|
||||
|
||||
#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) {
|
||||
switch (ppButton) {
|
||||
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
|
||||
@ -31,38 +27,23 @@ void MoonlightInstance::DidLockMouse(int32_t result) {
|
||||
|
||||
void MoonlightInstance::MouseLockLost() {
|
||||
m_MouseLocked = false;
|
||||
m_KeyModifiers = 0;
|
||||
}
|
||||
|
||||
void MoonlightInstance::UpdateModifiers(PP_InputEvent_Type eventType, short keyCode) {
|
||||
switch (keyCode) {
|
||||
case KEY_CODE_ALT:
|
||||
if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) {
|
||||
m_KeyModifiers |= MODIFIER_ALT;
|
||||
}
|
||||
else {
|
||||
m_KeyModifiers &= ~MODIFIER_ALT;
|
||||
}
|
||||
break;
|
||||
static char GetModifierFlags(const pp::InputEvent& event) {
|
||||
uint32_t modifiers = event.GetModifiers();
|
||||
char flags = 0;
|
||||
|
||||
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_SHIFTKEY) {
|
||||
flags |= MODIFIER_SHIFT;
|
||||
}
|
||||
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) {
|
||||
@ -135,11 +116,9 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
||||
}
|
||||
|
||||
pp::KeyboardInputEvent keyboardEvent(event);
|
||||
char modifiers = GetModifierFlags(event);
|
||||
|
||||
// Update modifier state before sending the key event
|
||||
UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode());
|
||||
|
||||
if (m_KeyModifiers == (MODIFIER_ALT | MODIFIER_CTRL | MODIFIER_SHIFT)) {
|
||||
if (modifiers == (MODIFIER_ALT | MODIFIER_CTRL | MODIFIER_SHIFT)) {
|
||||
if (keyboardEvent.GetKeyCode() == 0x51) { // Q key
|
||||
// Terminate the connection
|
||||
StopConnection();
|
||||
@ -152,7 +131,7 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
||||
}
|
||||
|
||||
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
|
||||
KEY_ACTION_DOWN, m_KeyModifiers);
|
||||
KEY_ACTION_DOWN, modifiers);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -162,19 +141,17 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
||||
}
|
||||
|
||||
pp::KeyboardInputEvent keyboardEvent(event);
|
||||
|
||||
// Update modifier state before sending the key event
|
||||
UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode());
|
||||
char modifiers = GetModifierFlags(event);
|
||||
|
||||
// Check if all modifiers are up now
|
||||
if (m_WaitingForAllModifiersUp && m_KeyModifiers == 0) {
|
||||
if (m_WaitingForAllModifiersUp && modifiers == 0) {
|
||||
UnlockMouse();
|
||||
m_MouseLocked = false;
|
||||
m_WaitingForAllModifiersUp = false;
|
||||
}
|
||||
|
||||
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
|
||||
KEY_ACTION_UP, m_KeyModifiers);
|
||||
KEY_ACTION_UP, modifiers);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
15
main.cpp
15
main.cpp
@ -38,8 +38,12 @@ void MoonlightInstance::OnConnectionStarted(uint32_t unused) {
|
||||
PostMessage(response);
|
||||
|
||||
// Start receiving input events
|
||||
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
|
||||
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
|
||||
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
|
||||
|
||||
// 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) {
|
||||
@ -177,10 +181,15 @@ void MoonlightInstance::HandleStartStream(int32_t callbackId, pp::VarArray args)
|
||||
m_StreamConfig.height = stoi(height);
|
||||
m_StreamConfig.fps = stoi(fps);
|
||||
m_StreamConfig.bitrate = stoi(bitrate); // kilobits per second
|
||||
m_StreamConfig.packetSize = 1024;
|
||||
m_StreamConfig.streamingRemotely = 0;
|
||||
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);
|
||||
|
||||
// Initialize the rendering surface before starting the connection
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Moonlight",
|
||||
"version": "0.02",
|
||||
"version": "0.03",
|
||||
"description": "A Moonlight streaming plugin for Google Chrome",
|
||||
"icons": {
|
||||
"128": "icons/icon128.png",
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit f69ab5dd5eb8ca79bb59bcb9e87587a819c9bd4d
|
||||
Subproject commit dddcba217b315281364bca92e7e409b449fff000
|
@ -46,7 +46,6 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
||||
m_OpusDecoder(NULL),
|
||||
m_CallbackFactory(this),
|
||||
m_MouseLocked(false),
|
||||
m_KeyModifiers(0),
|
||||
m_WaitingForAllModifiersUp(false),
|
||||
m_AccumulatedTicks(0),
|
||||
openHttpThread(this) {
|
||||
@ -74,7 +73,6 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
||||
void HandleOpenURL(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);
|
||||
|
||||
void PollGamepads();
|
||||
@ -150,7 +148,6 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
||||
const PPB_Gamepad* m_GamepadApi;
|
||||
pp::CompletionCallbackFactory<MoonlightInstance> m_CallbackFactory;
|
||||
bool m_MouseLocked;
|
||||
char m_KeyModifiers;
|
||||
bool m_WaitingForAllModifiersUp;
|
||||
float m_AccumulatedTicks;
|
||||
|
||||
|
@ -66,9 +66,9 @@ main {
|
||||
margin: 3px;
|
||||
}
|
||||
#listener {
|
||||
overflow: hidden;
|
||||
margin-top: 20px;
|
||||
border: 1px solid;
|
||||
overflow: hidden;
|
||||
margin-top: 0px;
|
||||
height: 0px;
|
||||
}
|
||||
.fullscreen {
|
||||
height: 100vh !important;
|
||||
|
@ -1,6 +1,8 @@
|
||||
// just start the app in fullscreen
|
||||
chrome.app.runtime.onLaunched.addListener(function() {
|
||||
chrome.app.window.create('index.html', {
|
||||
state: "normal",
|
||||
bounds: {
|
||||
width: 850, height: 500
|
||||
}
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user