Change mute on minimize to mute on focus loss

Minimization doesn't always happen on focus loss in full-screen mode,
so it could lead to unpredictable behavior.
This commit is contained in:
Cameron Gutman
2021-01-09 17:56:23 -06:00
parent 2d62d090df
commit 7020749987
5 changed files with 26 additions and 24 deletions
+3 -3
View File
@@ -303,7 +303,7 @@ void StreamCommandLineParser::parse(const QStringList &args, StreamingPreference
parser.addToggleOption("game-optimization", "game optimizations"); parser.addToggleOption("game-optimization", "game optimizations");
parser.addToggleOption("audio-on-host", "audio on host PC"); parser.addToggleOption("audio-on-host", "audio on host PC");
parser.addToggleOption("frame-pacing", "frame pacing"); parser.addToggleOption("frame-pacing", "frame pacing");
parser.addToggleOption("mute-on-minimize", "mute audio when minimized"); parser.addToggleOption("mute-on-focus-loss", "mute audio when Moonlight window loses focus");
parser.addToggleOption("background-gamepad", "background gamepad input"); parser.addToggleOption("background-gamepad", "background gamepad input");
parser.addToggleOption("reverse-scroll-direction", "inverted scroll direction"); parser.addToggleOption("reverse-scroll-direction", "inverted scroll direction");
parser.addToggleOption("swap-gamepad-buttons", "swap A/B and X/Y gamepad buttons (Nintendo-style)"); parser.addToggleOption("swap-gamepad-buttons", "swap A/B and X/Y gamepad buttons (Nintendo-style)");
@@ -409,8 +409,8 @@ void StreamCommandLineParser::parse(const QStringList &args, StreamingPreference
// Resolve --frame-pacing and --no-frame-pacing options // Resolve --frame-pacing and --no-frame-pacing options
preferences->framePacing = parser.getToggleOptionValue("frame-pacing", preferences->framePacing); preferences->framePacing = parser.getToggleOptionValue("frame-pacing", preferences->framePacing);
// Resolve --mute-on-minimize and --no-mute-on-minimize options // Resolve --mute-on-focus-loss and --no-mute-on-focus-loss options
preferences->muteOnMinimize = parser.getToggleOptionValue("mute-on-minimize", preferences->muteOnMinimize); preferences->muteOnFocusLoss = parser.getToggleOptionValue("mute-on-focus-loss", preferences->muteOnFocusLoss);
// Resolve --background-gamepad and --no-background-gamepad options // Resolve --background-gamepad and --no-background-gamepad options
preferences->backgroundGamepad = parser.getToggleOptionValue("background-gamepad", preferences->backgroundGamepad); preferences->backgroundGamepad = parser.getToggleOptionValue("background-gamepad", preferences->backgroundGamepad);
+9 -4
View File
@@ -685,14 +685,19 @@ Flickable {
} }
CheckBox { CheckBox {
id: muteOnMinimizeCheck id: muteOnFocusLossCheck
width: parent.width width: parent.width
text: qsTr("Mute audio stream when Moonlight is minimized") text: qsTr("Mute audio stream when Moonlight is not the active window")
font.pointSize: 12 font.pointSize: 12
checked: StreamingPreferences.muteOnMinimize checked: StreamingPreferences.muteOnFocusLoss
onCheckedChanged: { onCheckedChanged: {
StreamingPreferences.muteOnMinimize = checked StreamingPreferences.muteOnFocusLoss = checked
} }
ToolTip.delay: 1000
ToolTip.timeout: 5000
ToolTip.visible: hovered
ToolTip.text: qsTr("Mutes Moonlight's audio when you Alt+Tab out of the stream or click on a different window.")
} }
} }
} }
+3 -3
View File
@@ -30,7 +30,7 @@
#define SER_PACKETSIZE "packetsize" #define SER_PACKETSIZE "packetsize"
#define SER_DETECTNETBLOCKING "detectnetblocking" #define SER_DETECTNETBLOCKING "detectnetblocking"
#define SER_SWAPMOUSEBUTTONS "swapmousebuttons" #define SER_SWAPMOUSEBUTTONS "swapmousebuttons"
#define SER_MUTEONMINIMIZE "muteonminimize" #define SER_MUTEONFOCUSLOSS "muteonfocusloss"
#define SER_BACKGROUNDGAMEPAD "backgroundgamepad" #define SER_BACKGROUNDGAMEPAD "backgroundgamepad"
#define SER_REVERSESCROLL "reversescroll" #define SER_REVERSESCROLL "reversescroll"
#define SER_SWAPFACEBUTTONS "swapfacebuttons" #define SER_SWAPFACEBUTTONS "swapfacebuttons"
@@ -76,7 +76,7 @@ void StreamingPreferences::reload()
detectNetworkBlocking = settings.value(SER_DETECTNETBLOCKING, true).toBool(); detectNetworkBlocking = settings.value(SER_DETECTNETBLOCKING, true).toBool();
packetSize = settings.value(SER_PACKETSIZE, 0).toInt(); packetSize = settings.value(SER_PACKETSIZE, 0).toInt();
swapMouseButtons = settings.value(SER_SWAPMOUSEBUTTONS, false).toBool(); swapMouseButtons = settings.value(SER_SWAPMOUSEBUTTONS, false).toBool();
muteOnMinimize = settings.value(SER_MUTEONMINIMIZE, false).toBool(); muteOnFocusLoss = settings.value(SER_MUTEONFOCUSLOSS, false).toBool();
backgroundGamepad = settings.value(SER_BACKGROUNDGAMEPAD, false).toBool(); backgroundGamepad = settings.value(SER_BACKGROUNDGAMEPAD, false).toBool();
reverseScrollDirection = settings.value(SER_REVERSESCROLL, false).toBool(); reverseScrollDirection = settings.value(SER_REVERSESCROLL, false).toBool();
swapFaceButtons = settings.value(SER_SWAPFACEBUTTONS, false).toBool(); swapFaceButtons = settings.value(SER_SWAPFACEBUTTONS, false).toBool();
@@ -132,7 +132,7 @@ void StreamingPreferences::save()
settings.setValue(SER_WINDOWMODE, static_cast<int>(windowMode)); settings.setValue(SER_WINDOWMODE, static_cast<int>(windowMode));
settings.setValue(SER_DEFAULTVER, CURRENT_DEFAULT_VER); settings.setValue(SER_DEFAULTVER, CURRENT_DEFAULT_VER);
settings.setValue(SER_SWAPMOUSEBUTTONS, swapMouseButtons); settings.setValue(SER_SWAPMOUSEBUTTONS, swapMouseButtons);
settings.setValue(SER_MUTEONMINIMIZE, muteOnMinimize); settings.setValue(SER_MUTEONFOCUSLOSS, muteOnFocusLoss);
settings.setValue(SER_BACKGROUNDGAMEPAD, backgroundGamepad); settings.setValue(SER_BACKGROUNDGAMEPAD, backgroundGamepad);
settings.setValue(SER_REVERSESCROLL, reverseScrollDirection); settings.setValue(SER_REVERSESCROLL, reverseScrollDirection);
settings.setValue(SER_SWAPFACEBUTTONS, swapFaceButtons); settings.setValue(SER_SWAPFACEBUTTONS, swapFaceButtons);
+3 -3
View File
@@ -75,7 +75,7 @@ public:
Q_PROPERTY(WindowMode windowMode MEMBER windowMode NOTIFY windowModeChanged) Q_PROPERTY(WindowMode windowMode MEMBER windowMode NOTIFY windowModeChanged)
Q_PROPERTY(WindowMode recommendedFullScreenMode MEMBER recommendedFullScreenMode CONSTANT) Q_PROPERTY(WindowMode recommendedFullScreenMode MEMBER recommendedFullScreenMode CONSTANT)
Q_PROPERTY(bool swapMouseButtons MEMBER swapMouseButtons NOTIFY mouseButtonsChanged) Q_PROPERTY(bool swapMouseButtons MEMBER swapMouseButtons NOTIFY mouseButtonsChanged)
Q_PROPERTY(bool muteOnMinimize MEMBER muteOnMinimize NOTIFY muteOnMinimizeChanged) Q_PROPERTY(bool muteOnFocusLoss MEMBER muteOnFocusLoss NOTIFY muteOnFocusLossChanged)
Q_PROPERTY(bool backgroundGamepad MEMBER backgroundGamepad NOTIFY backgroundGamepadChanged) Q_PROPERTY(bool backgroundGamepad MEMBER backgroundGamepad NOTIFY backgroundGamepadChanged)
Q_PROPERTY(bool reverseScrollDirection MEMBER reverseScrollDirection NOTIFY reverseScrollDirectionChanged) Q_PROPERTY(bool reverseScrollDirection MEMBER reverseScrollDirection NOTIFY reverseScrollDirectionChanged)
Q_PROPERTY(bool swapFaceButtons MEMBER swapFaceButtons NOTIFY swapFaceButtonsChanged) Q_PROPERTY(bool swapFaceButtons MEMBER swapFaceButtons NOTIFY swapFaceButtonsChanged)
@@ -101,7 +101,7 @@ public:
bool gamepadMouse; bool gamepadMouse;
bool detectNetworkBlocking; bool detectNetworkBlocking;
bool swapMouseButtons; bool swapMouseButtons;
bool muteOnMinimize; bool muteOnFocusLoss;
bool backgroundGamepad; bool backgroundGamepad;
bool reverseScrollDirection; bool reverseScrollDirection;
bool swapFaceButtons; bool swapFaceButtons;
@@ -135,7 +135,7 @@ signals:
void gamepadMouseChanged(); void gamepadMouseChanged();
void detectNetworkBlockingChanged(); void detectNetworkBlockingChanged();
void mouseButtonsChanged(); void mouseButtonsChanged();
void muteOnMinimizeChanged(); void muteOnFocusLossChanged();
void backgroundGamepadChanged(); void backgroundGamepadChanged();
void reverseScrollDirectionChanged(); void reverseScrollDirectionChanged();
void swapFaceButtonsChanged(); void swapFaceButtonsChanged();
+8 -11
View File
@@ -1345,22 +1345,19 @@ void Session::exec(int displayOriginX, int displayOriginY)
// Early handling of some events // Early handling of some events
switch (event.window.event) { switch (event.window.event) {
case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_FOCUS_LOST:
if (m_Preferences->muteOnFocusLoss) {
m_AudioMuted = true;
}
m_InputHandler->notifyFocusLost(); m_InputHandler->notifyFocusLost();
break; break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
if (m_Preferences->muteOnFocusLoss) {
m_AudioMuted = false;
}
break;
case SDL_WINDOWEVENT_LEAVE: case SDL_WINDOWEVENT_LEAVE:
m_InputHandler->notifyMouseLeave(); m_InputHandler->notifyMouseLeave();
break; break;
case SDL_WINDOWEVENT_MINIMIZED:
if (m_Preferences->muteOnMinimize) {
m_AudioMuted = true;
}
break;
case SDL_WINDOWEVENT_MAXIMIZED:
case SDL_WINDOWEVENT_RESTORED:
if (m_Preferences->muteOnMinimize) {
m_AudioMuted = false;
}
break;
} }
// Capture the mouse on SDL_WINDOWEVENT_ENTER if needed // Capture the mouse on SDL_WINDOWEVENT_ENTER if needed