From 9e2fd674873e33c9f10c865274647f98e9163533 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 9 Sep 2018 13:21:11 -0700 Subject: [PATCH] Add option to enable mouse acceleration for remote desktop usage --- app/gui/SettingsView.qml | 18 +++++++++++++++--- app/gui/main.qml | 2 +- app/settings/streamingpreferences.cpp | 3 +++ app/settings/streamingpreferences.h | 3 +++ app/streaming/input.cpp | 11 +++++++++-- app/streaming/input.hpp | 4 +++- app/streaming/session.cpp | 2 +- 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/gui/SettingsView.qml b/app/gui/SettingsView.qml index e5e6222d..488ca9c6 100644 --- a/app/gui/SettingsView.qml +++ b/app/gui/SettingsView.qml @@ -423,10 +423,10 @@ ScrollView { id: gamepadSettingsGroupBox width: (parent.width - parent.padding) padding: 12 - title: "Gamepad Settings" + title: "Input Settings" font.pointSize: 12 - Column { + Row { anchors.fill: parent spacing: 5 @@ -439,6 +439,16 @@ ScrollView { prefs.multiController = checked } } + + CheckBox { + id: mouseAccelerationCheck + text: "Enable mouse acceleration" + font.pointSize: 12 + checked: prefs.mouseAcceleration + onCheckedChanged: { + prefs.mouseAcceleration = checked + } + } } } @@ -449,13 +459,15 @@ ScrollView { title: "Host Settings" font.pointSize: 12 - Column { + Row { anchors.fill: parent spacing: 5 CheckBox { id: optimizeGameSettingsCheck text: "Optimize game settings" + // HACK: Match width of the other checkbox to make the UI not look bad + width: multiControllerCheck.width font.pointSize: 12 checked: prefs.gameOptimizations onCheckedChanged: { diff --git a/app/gui/main.qml b/app/gui/main.qml index d20099f4..bd227ad6 100644 --- a/app/gui/main.qml +++ b/app/gui/main.qml @@ -14,7 +14,7 @@ ApplicationWindow { id: window visible: true width: 1280 - height: 700 + height: 600 Material.theme: Material.Dark Material.accent: Material.Purple diff --git a/app/settings/streamingpreferences.cpp b/app/settings/streamingpreferences.cpp index 526e5235..016ece44 100644 --- a/app/settings/streamingpreferences.cpp +++ b/app/settings/streamingpreferences.cpp @@ -20,6 +20,7 @@ #define SER_WINDOWMODE "windowmode" #define SER_UNSUPPORTEDFPS "unsupportedfps" #define SER_MDNS "mdns" +#define SER_MOUSEACCELERATION "mouseacceleration" StreamingPreferences::StreamingPreferences() { @@ -40,6 +41,7 @@ void StreamingPreferences::reload() multiController = settings.value(SER_MULTICONT, true).toBool(); unsupportedFps = settings.value(SER_UNSUPPORTEDFPS, false).toBool(); enableMdns = settings.value(SER_MDNS, true).toBool(); + mouseAcceleration = settings.value(SER_MOUSEACCELERATION, false).toBool(); audioConfig = static_cast(settings.value(SER_AUDIOCFG, static_cast(AudioConfig::AC_FORCE_STEREO)).toInt()); videoCodecConfig = static_cast(settings.value(SER_VIDEOCFG, @@ -66,6 +68,7 @@ void StreamingPreferences::save() settings.setValue(SER_MULTICONT, multiController); settings.setValue(SER_UNSUPPORTEDFPS, unsupportedFps); settings.setValue(SER_MDNS, enableMdns); + settings.setValue(SER_MOUSEACCELERATION, mouseAcceleration); settings.setValue(SER_AUDIOCFG, static_cast(audioConfig)); settings.setValue(SER_VIDEOCFG, static_cast(videoCodecConfig)); settings.setValue(SER_VIDEODEC, static_cast(videoDecoderSelection)); diff --git a/app/settings/streamingpreferences.h b/app/settings/streamingpreferences.h index e23f91d7..673fc738 100644 --- a/app/settings/streamingpreferences.h +++ b/app/settings/streamingpreferences.h @@ -70,6 +70,7 @@ public: Q_PROPERTY(bool multiController MEMBER multiController NOTIFY multiControllerChanged) Q_PROPERTY(bool unsupportedFps MEMBER unsupportedFps NOTIFY unsupportedFpsChanged) Q_PROPERTY(bool enableMdns MEMBER enableMdns NOTIFY enableMdnsChanged) + Q_PROPERTY(bool mouseAcceleration MEMBER mouseAcceleration NOTIFY mouseAccelerationChanged) Q_PROPERTY(AudioConfig audioConfig MEMBER audioConfig NOTIFY audioConfigChanged) Q_PROPERTY(VideoCodecConfig videoCodecConfig MEMBER videoCodecConfig NOTIFY videoCodecConfigChanged) Q_PROPERTY(VideoDecoderSelection videoDecoderSelection MEMBER videoDecoderSelection NOTIFY videoDecoderSelectionChanged) @@ -86,6 +87,7 @@ public: bool multiController; bool unsupportedFps; bool enableMdns; + bool mouseAcceleration; AudioConfig audioConfig; VideoCodecConfig videoCodecConfig; VideoDecoderSelection videoDecoderSelection; @@ -100,6 +102,7 @@ signals: void multiControllerChanged(); void unsupportedFpsChanged(); void enableMdnsChanged(); + void mouseAccelerationChanged(); void audioConfigChanged(); void videoCodecConfigChanged(); void videoDecoderSelectionChanged(); diff --git a/app/streaming/input.cpp b/app/streaming/input.cpp index 3480bed1..90fda02b 100644 --- a/app/streaming/input.cpp +++ b/app/streaming/input.cpp @@ -22,13 +22,20 @@ const int SdlInputHandler::k_ButtonMap[] = { UP_FLAG, DOWN_FLAG, LEFT_FLAG, RIGHT_FLAG }; -SdlInputHandler::SdlInputHandler(bool multiController) +SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs) : m_LastMouseMotionTime(0), - m_MultiController(multiController) + m_MultiController(prefs.multiController) { // Allow gamepad input when the app doesn't have focus SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); + // If mouse acceleration is enabled, use relative mode warp (which + // is via normal motion events that are influenced by mouse acceleration). + // Otherwise, we'll use raw input capture which is straight from the device + // without modification by the OS. + SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, + prefs.mouseAcceleration ? "1" : "0"); + // We need to reinit this each time, since you only get // an initial set of gamepad arrival events once per init. SDL_assert(!SDL_WasInit(SDL_INIT_GAMECONTROLLER)); diff --git a/app/streaming/input.hpp b/app/streaming/input.hpp index db040a02..10383fd0 100644 --- a/app/streaming/input.hpp +++ b/app/streaming/input.hpp @@ -1,5 +1,7 @@ #pragma once +#include "settings/streamingpreferences.h" + #include struct GamepadState { @@ -18,7 +20,7 @@ struct GamepadState { class SdlInputHandler { public: - explicit SdlInputHandler(bool multiController); + explicit SdlInputHandler(StreamingPreferences& prefs); ~SdlInputHandler(); diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 3cb77dd6..462102c5 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -728,7 +728,7 @@ void Session::exec(int displayOriginX, int displayOriginY) // Initialize the gamepad code with our preferences StreamingPreferences prefs; - SdlInputHandler inputHandler(prefs.multiController); + SdlInputHandler inputHandler(prefs); // The UI should have ensured the old game was already quit // if we decide to stream a different game.