From af4c88e53118b7de94ab477675ef179adb2a3fd9 Mon Sep 17 00:00:00 2001 From: Serhii Hadzhilov <71632867+SerhiiGadzhilov@users.noreply.github.com> Date: Wed, 26 Jan 2022 14:07:28 +0200 Subject: [PATCH] SYNERGY-1454 Scroll direction (#7140) * SYNERGY-1454 Add a new checkbox into the setting dialog * SYNERGY-1454 Save the new option * SYNERGY-1454 Pass the new option to client * SYNERGY-1454 Parse the new param on client side * SYNERGY-1454 Invert scroll direction for macOS * SYNERGY-1454 Scroll direction on Windows * SYNERGY-1454 Remove unused code * SYNERGY-1454 Scroll direction for Linux * SYNERGY-1454 Simplify scroll direction for Mac * SYNERGY-1454 Simplify scroll direction for Linux * SYNERGY-1454 Simplify scroll direction for Windows * SYNERGY-1454 ChangeLog * SYNERGY-1454 Fix code smell * SYNERGY-1434 Lower case for the first char of the option * SYNERGY-1454 Fix indentations Co-authored-by: Serhii Hadzhilov Co-authored-by: Serhii Hadzhilov --- ChangeLog | 1 + src/gui/src/AppConfig.cpp | 13 +++- src/gui/src/AppConfig.h | 6 +- src/gui/src/MainWindow.cpp | 3 + src/gui/src/SettingsDialog.cpp | 8 ++- src/gui/src/SettingsDialogBase.ui | 64 +++++++++--------- src/lib/arch/unix/ArchSystemUnix.cpp | 22 ------- src/lib/arch/unix/ArchSystemUnix.h | 2 - src/lib/platform/MSWindowsScreen.cpp | 65 +------------------ src/lib/platform/MSWindowsScreen.h | 10 +-- src/lib/platform/OSXScreen.h | 4 -- src/lib/platform/OSXScreen.mm | 16 +---- src/lib/platform/XWindowsScreen.cpp | 40 ++---------- src/lib/platform/XWindowsScreen.h | 6 -- src/lib/synergy/ArgParser.cpp | 3 + src/lib/synergy/ClientApp.cpp | 2 + src/lib/synergy/ClientArgs.h | 15 ++++- src/lib/synergy/IPlatformScreen.h | 14 ---- src/lib/synergy/PlatformScreen.h | 4 -- src/lib/synergy/Screen.cpp | 20 +----- src/lib/synergy/Screen.h | 2 +- .../synergy/ClientArgsParsingTests.cpp | 11 ++++ 22 files changed, 104 insertions(+), 227 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8668ef0c5..c67ac9009 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ v1.14.3-snapshot =========== Bug fixes: - #7135 Fix issue with function keys on macOS +- #7140 Configure scroll direction on a per-computer basis =========== v1.14.2-stable diff --git a/src/gui/src/AppConfig.cpp b/src/gui/src/AppConfig.cpp index 499240218..8529a6124 100644 --- a/src/gui/src/AppConfig.cpp +++ b/src/gui/src/AppConfig.cpp @@ -78,7 +78,8 @@ const char* AppConfig::m_SynergySettingsName[] = { "tlsCertPath", "tlsKeyLength", "preventSleep", - "languageSync" + "languageSync", + "invertScrollDirection" }; static const char* logLevelNames[] = @@ -243,6 +244,7 @@ void AppConfig::loadSettings() m_ServerHostname = loadSetting(kServerHostname).toString(); m_PreventSleep = loadSetting(kPreventSleep, false).toBool(); m_LanguageSync = loadSetting(kLanguageSync, false).toBool(); + m_InvertScrollDirection = loadSetting(kInvertScrollDirection, false).toBool(); //only change the serial key if the settings being loaded contains a key bool updateSerial = ConfigWriter::make() @@ -305,6 +307,7 @@ void AppConfig::saveSettings() setSetting(kServerHostname, m_ServerHostname); setSetting(kPreventSleep, m_PreventSleep); setSetting(kLanguageSync, m_LanguageSync); + setSetting(kInvertScrollDirection, m_InvertScrollDirection); } m_unsavedChanges = false; @@ -454,8 +457,16 @@ void AppConfig::setMinimizeToTray(bool newValue) { setSettingModified(m_MinimizeToTray, newValue); } +bool AppConfig::getInvertScrollDirection() const { + return m_InvertScrollDirection; +} + bool AppConfig::getLanguageSync() const { return m_LanguageSync; } +void AppConfig::setInvertScrollDirection(bool newValue) { + setSettingModified(m_InvertScrollDirection, newValue); +} + void AppConfig::setLanguageSync(bool newValue) { setSettingModified(m_LanguageSync, newValue); } diff --git a/src/gui/src/AppConfig.h b/src/gui/src/AppConfig.h index c936ec0ff..49e0f8576 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -112,6 +112,8 @@ class AppConfig: public QObject, public GUI::Config::ConfigBase void setAutoHide(bool b); bool getAutoHide(); + void setInvertScrollDirection(bool b); + bool getInvertScrollDirection() const; void setLanguageSync(bool b); bool getLanguageSync() const; void setPreventSleep(bool b); @@ -205,7 +207,8 @@ protected: kTLSCertPath, kTLSKeyLength, kPreventSleep, - kLanguageSync + kLanguageSync, + kInvertScrollDirection }; void setScreenName(const QString& s); @@ -248,6 +251,7 @@ protected: int m_LastExpiringWarningTime; bool m_ActivationHasRun; bool m_MinimizeToTray; + bool m_InvertScrollDirection = false; bool m_LanguageSync = true; bool m_PreventSleep = false; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 992df46a4..b3bb9f089 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -811,6 +811,9 @@ bool MainWindow::clientArgs(QStringList& args, QString& app) args << "--sync-language"; } + if (appConfig().getInvertScrollDirection()) { + args <<"--invert-scroll"; + } #if !defined(SYNERGY_ENTERPRISE) && defined(SYNERGY_AUTOCONFIG) // check auto config first, if it is disabled or no server detected, diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index 347d4f88f..55932d046 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -53,6 +53,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : enableControls(appConfig().isWritable()); m_pCheckBoxLanguageSync->setVisible(m_pMainWindow->synergyType() == MainWindow::synergyClient); + m_pCheckBoxScrollDirection->setVisible(m_pMainWindow->synergyType() == MainWindow::synergyClient); const auto& serveConfig = m_pMainWindow->serverConfig(); m_pLineEditScreenName->setValidator(new validators::ScreenNameValidator(m_pLineEditScreenName, m_pLabelNameError, (&serveConfig.screens()))); @@ -69,6 +70,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : connect(m_pLineEditScreenName, SIGNAL(textEdited(QString)), this, SLOT(onChange())); connect(m_pComboElevate, SIGNAL(currentIndexChanged(int)), this, SLOT(onChange())); connect(m_pCheckBoxLanguageSync, SIGNAL(clicked()), this, SLOT(onChange())); + connect(m_pCheckBoxScrollDirection, SIGNAL(clicked()), this, SLOT(onChange())); adjustSize(); } @@ -92,6 +94,7 @@ void SettingsDialog::accept() appConfig().setTLSKeyLength(m_pComboBoxKeyLength->currentText()); appConfig().setCryptoEnabled(m_pCheckBoxEnableCrypto->isChecked()); appConfig().setLanguageSync(m_pCheckBoxLanguageSync->isChecked()); + appConfig().setInvertScrollDirection(m_pCheckBoxScrollDirection->isChecked()); appConfig().saveSettings(); QDialog::accept(); @@ -150,6 +153,7 @@ void SettingsDialog::loadFromConfig() { m_pLineEditCertificatePath->setText(appConfig().getTLSCertPath()); m_pCheckBoxEnableCrypto->setChecked(m_appConfig.getCryptoEnabled()); m_pCheckBoxLanguageSync->setChecked(m_appConfig.getLanguageSync()); + m_pCheckBoxScrollDirection->setChecked(m_appConfig.getInvertScrollDirection()); //If the tls file exists test its key length if (QFile(appConfig().getTLSCertPath()).exists()) { @@ -341,7 +345,8 @@ bool SettingsDialog::isModified() || appConfig().getTLSKeyLength() != m_pComboBoxKeyLength->currentText() || appConfig().getCryptoEnabled() != m_pCheckBoxEnableCrypto->isChecked() || appConfig().isSystemScoped() != m_isSystemAtStart - || appConfig().getLanguageSync() != m_pCheckBoxLanguageSync->isChecked()) + || appConfig().getLanguageSync() != m_pCheckBoxLanguageSync->isChecked() + || appConfig().getInvertScrollDirection() != m_pCheckBoxScrollDirection->isChecked()) ); } @@ -363,6 +368,7 @@ void SettingsDialog::enableControls(bool enable) { m_pCheckBoxEnableCrypto->setEnabled(enable); m_labelAdminRightsMessage->setVisible(!enable); m_pCheckBoxLanguageSync->setEnabled(enable); + m_pCheckBoxScrollDirection->setEnabled(enable); if (enable) { m_pLabelLogPath->setEnabled(m_pCheckBoxLogToFile->isChecked()); diff --git a/src/gui/src/SettingsDialogBase.ui b/src/gui/src/SettingsDialogBase.ui index 8ad704945..973c7889c 100644 --- a/src/gui/src/SettingsDialogBase.ui +++ b/src/gui/src/SettingsDialogBase.ui @@ -337,10 +337,33 @@ background-color: rgba(192,192,192, 0.1); QFrame::Raised - - + + + + + 0 + 0 + + + + Elevate privileges + + - + + + + Qt::Vertical + + + + 20 + 40 + + + + + &Use server's keyboard language on this machine @@ -369,20 +392,7 @@ background-color: rgba(192,192,192, 0.1); - - - - - 0 - 0 - - - - Elevate privileges - - - - + Specify when the Synergy service should run at an elevated privilege level @@ -407,18 +417,15 @@ background-color: rgba(192,192,192, 0.1); - - - - Qt::Vertical + + + + + + + Invert scroll direction on this computer - - - 20 - 40 - - - + @@ -1008,7 +1015,6 @@ font-weight: bold; - diff --git a/src/lib/arch/unix/ArchSystemUnix.cpp b/src/lib/arch/unix/ArchSystemUnix.cpp index 2a21b1bda..4f394ff21 100644 --- a/src/lib/arch/unix/ArchSystemUnix.cpp +++ b/src/lib/arch/unix/ArchSystemUnix.cpp @@ -19,10 +19,6 @@ #include "arch/unix/ArchSystemUnix.h" #include -#include -#include -#include -#include #ifndef __APPLE__ #include #endif @@ -86,24 +82,6 @@ ArchSystemUnix::getLibsUsed(void) const return "not implemented.\nuse lsof on shell"; } -std::string -ArchSystemUnix::runCommand(const std::string& cmd) -{ - std::array buffer; - std::string result; - std::unique_ptr pipe(popen(cmd.c_str(), "r"), &pclose); - if (!pipe) - { - return ""; - } - - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) - { - result += buffer.data(); - } - return result; -} - #ifndef __APPLE__ bool ArchSystemUnix::DBusInhibitScreenCall(InhibitScreenServices serviceID, bool state, std::string& error) diff --git a/src/lib/arch/unix/ArchSystemUnix.h b/src/lib/arch/unix/ArchSystemUnix.h index e4e6724e3..734213952 100644 --- a/src/lib/arch/unix/ArchSystemUnix.h +++ b/src/lib/arch/unix/ArchSystemUnix.h @@ -35,8 +35,6 @@ public: virtual void setting(const std::string&, const std::string&) const; virtual std::string getLibsUsed(void) const; - static std::string runCommand(const std::string& cmd); - #ifndef __APPLE__ enum class InhibitScreenServices { kScreenSaver, diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp index 42577aa9e..2682839b4 100644 --- a/src/lib/platform/MSWindowsScreen.cpp +++ b/src/lib/platform/MSWindowsScreen.cpp @@ -46,7 +46,6 @@ #include #include #include -#include // suppress warning about GetVersionEx, which is used indirectly in this compilation unit. #pragma warning(disable: 4996) @@ -341,11 +340,6 @@ MSWindowsScreen::leave() // tell desk that we're leaving and tell it the keyboard layout m_desks->leave(m_keyLayout); - // Forcefully update scrolling direction - // Will keep server updated when moving cursor - allowScrollDirectionUpdate(); - updateScrollDirection(); - if (m_isPrimary) { // warp to center @@ -831,8 +825,8 @@ MSWindowsScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const void MSWindowsScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const { - xDelta = mapScrollFromSynergy(xDelta); - yDelta = mapScrollFromSynergy(yDelta); + xDelta *= ClientApp::instance().args().m_clientScrollDirection; + yDelta *= ClientApp::instance().args().m_clientScrollDirection; m_desks->fakeMouseWheel(xDelta, yDelta); } @@ -1485,8 +1479,6 @@ MSWindowsScreen::onMouseWheel(SInt32 xDelta, SInt32 yDelta) // ignore message if posted prior to last mark change if (!ignore()) { LOG((CLOG_DEBUG1 "event: button wheel delta=%+d,%+d", xDelta, yDelta)); - xDelta = mapScrollToSynergy(xDelta); - yDelta = mapScrollToSynergy(yDelta); sendEvent(m_events->forIPrimaryScreen().wheel(), WheelInfo::alloc(xDelta, yDelta)); } return true; @@ -2036,56 +2028,3 @@ MSWindowsScreen::isModifierRepeat(KeyModifierMask oldState, KeyModifierMask stat return result; } - -SInt32 -MSWindowsScreen::mapScrollToSynergy(SInt32 delta) const -{ - // for mouse wheel the delta will be a multiple of WHEEL_DELTA - if (delta % WHEEL_DELTA == 0) - { - return delta * m_scrollDirectionMouse; - } - else - { - return delta * m_scrollDirectionTouchpad; - } -} - -SInt32 -MSWindowsScreen::mapScrollFromSynergy(SInt32 delta) const -{ - // use mouse scrolling direction to invert - if (m_scrollDirectionMouse < 0) - return -delta; - return delta; -} - -void -MSWindowsScreen::updateScrollDirection() -{ - static const TCHAR* const touchpadScrollDirectionNames[] = { - _T("SOFTWARE"), - _T("Microsoft"), - _T("Windows"), - _T("CurrentVersion"), - _T("PrecisionTouchPad"), - NULL - }; - - if (m_shouldUpdateScrollDirection) - { - m_shouldUpdateScrollDirection = false; - - std::thread scrollDirectionUpdateThread([&] { - HKEY key = ArchMiscWindows::openKey(HKEY_CURRENT_USER, touchpadScrollDirectionNames); - if (key) - { - DWORD scroll = ArchMiscWindows::readValueInt(key, _T("ScrollDirection")); - ArchMiscWindows::closeKey(key); - if (scroll == 0) m_scrollDirectionTouchpad = 1; - else m_scrollDirectionTouchpad = -1; - } - }); - scrollDirectionUpdateThread.detach(); - } -} diff --git a/src/lib/platform/MSWindowsScreen.h b/src/lib/platform/MSWindowsScreen.h index 22c161c18..bef2f71cf 100644 --- a/src/lib/platform/MSWindowsScreen.h +++ b/src/lib/platform/MSWindowsScreen.h @@ -141,7 +141,6 @@ public: virtual const String& getDropTarget() const; String getSecureInputApp() const override; - void updateScrollDirection() override; protected: // IPlatformScreen overrides @@ -249,9 +248,6 @@ private: // HACK // send drag info and data back to server void sendDragThread(void*); - SInt32 mapScrollToSynergy(SInt32 delta) const; - SInt32 mapScrollFromSynergy(SInt32 delta) const; - private: struct HotKeyItem { public: @@ -371,9 +367,5 @@ private: Thread* m_sendDragThread; PrimaryKeyDownList m_primaryKeyDownList; - - // -1 for natural scrolling direction, 1 otherwise - SInt32 m_scrollDirectionMouse = 1; - SInt32 m_scrollDirectionTouchpad = 1; - MSWindowsPowerManager m_powerManager; + MSWindowsPowerManager m_powerManager; }; diff --git a/src/lib/platform/OSXScreen.h b/src/lib/platform/OSXScreen.h index 6756cfb85..8ba118d30 100644 --- a/src/lib/platform/OSXScreen.h +++ b/src/lib/platform/OSXScreen.h @@ -338,10 +338,6 @@ private: Thread* m_getDropTargetThread; String m_dropTarget; - void updateScrollDirection() override; - // -1 for natural scrolling direction, 1 otherwise - SInt32 m_scrollDirection = 1; - #if defined(MAC_OS_X_VERSION_10_7) Mutex* m_carbonLoopMutex; CondVar* m_carbonLoopReady; diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index d5d6e83ae..acf3207a6 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -1460,7 +1460,7 @@ OSXScreen::mapScrollWheelToSynergy(SInt32 x) const { // return accelerated scrolling double d = (1.0 + getScrollSpeed()) * x; - return static_cast(m_scrollDirection * 120.0 * d); + return static_cast(120.0 * d); } SInt32 @@ -1468,7 +1468,8 @@ OSXScreen::mapScrollWheelFromSynergy(SInt32 x) const { // use server's acceleration with a little boost since other platforms // take one wheel step as a larger step than the mac does. - return static_cast(m_scrollDirection * 3.0 * x / 120.0); + auto result = static_cast(3.0 * x / 120.0); + return (result * ClientApp::instance().args().m_clientScrollDirection); } double @@ -2214,17 +2215,6 @@ getProcessName(int pid) return buf; } -void -OSXScreen::updateScrollDirection() -{ - if(m_shouldUpdateScrollDirection) - { - LOG((CLOG_DEBUG "updated scrolling direction")); - m_scrollDirection = [[[NSUserDefaults standardUserDefaults] objectForKey:@"com.apple.swipescrolldirection"] boolValue] ? -1 : 1; - m_shouldUpdateScrollDirection = false; - } -} - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" void diff --git a/src/lib/platform/XWindowsScreen.cpp b/src/lib/platform/XWindowsScreen.cpp index a6d1f04e7..1feedbe5f 100644 --- a/src/lib/platform/XWindowsScreen.cpp +++ b/src/lib/platform/XWindowsScreen.cpp @@ -25,6 +25,8 @@ #include "platform/XWindowsUtil.h" #include "synergy/Clipboard.h" #include "synergy/KeyMap.h" +#include "synergy/ClientApp.h" +#include "synergy/ClientArgs.h" #include "synergy/XScreen.h" #include "synergy/ArgsBase.h" #include "synergy/App.h" @@ -39,7 +41,6 @@ #include #include #include -#include #if X_DISPLAY_MISSING # error X11 is required to build synergy #else @@ -875,11 +876,7 @@ XWindowsScreen::fakeMouseWheel(SInt32, SInt32 yDelta) const return; } - // use mouse scroll direction for inversion - if( m_scrollDirectionMouse < 0 ) - { - yDelta = -yDelta; - } + yDelta *= ClientApp::instance().args().m_clientScrollDirection; // choose button depending on rotation direction const unsigned int xButton = mapButtonToX(static_cast( @@ -1638,13 +1635,11 @@ XWindowsScreen::onMouseRelease(const XButtonEvent& xbutton) } else if (xbutton.button == 4) { // wheel forward (away from user) - // invert for natural scroll setting - sendEvent(m_events->forIPrimaryScreen().wheel(), WheelInfo::alloc(0, 120 * m_scrollDirectionMouse)); + sendEvent(m_events->forIPrimaryScreen().wheel(), WheelInfo::alloc(0, 120)); } else if (xbutton.button == 5) { // wheel backward (toward user) - // invert for natural scroll setting - sendEvent(m_events->forIPrimaryScreen().wheel(), WheelInfo::alloc(0, -120 * m_scrollDirectionMouse)); + sendEvent(m_events->forIPrimaryScreen().wheel(), WheelInfo::alloc(0, -120)); } // XXX -- support x-axis scrolling } @@ -2169,28 +2164,3 @@ XWindowsScreen::selectXIRawMotion() free(mask.mask); } #endif - -void -XWindowsScreen::updateScrollDirection() -{ - if (m_shouldUpdateScrollDirection) - { - m_shouldUpdateScrollDirection = false; - - std::thread scrollDirectionUpdateThread([this]{ - std::string mouseScroll = ArchSystemUnix::runCommand("gsettings get org.gnome.desktop.peripherals.mouse natural-scroll"); - if(mouseScroll == "false\n") - m_scrollDirectionMouse = 1; - else if(mouseScroll == "true\n") - m_scrollDirectionMouse = -1; - - std::string touchpadScroll = ArchSystemUnix::runCommand("gsettings get org.gnome.desktop.peripherals.touchpad natural-scroll"); - if(touchpadScroll == "false\n") - m_scrollDirectionTouchpad = 1; - else if(touchpadScroll == "true\n") - m_scrollDirectionTouchpad = -1; - }); - scrollDirectionUpdateThread.detach(); - } -} - diff --git a/src/lib/platform/XWindowsScreen.h b/src/lib/platform/XWindowsScreen.h index b674b708d..427c6fd0f 100644 --- a/src/lib/platform/XWindowsScreen.h +++ b/src/lib/platform/XWindowsScreen.h @@ -88,8 +88,6 @@ public: virtual bool isPrimary() const; String getSecureInputApp() const override; - void updateScrollDirection() override; - protected: // IPlatformScreen overrides virtual void handleSystemEvent(const Event&, void*); @@ -255,9 +253,5 @@ private: // pointer to (singleton) screen. this is only needed by // ioErrorHandler(). static XWindowsScreen* s_screen; - - // -1 for natural scrolling direction, 1 otherwise - SInt32 m_scrollDirectionMouse = 1; - SInt32 m_scrollDirectionTouchpad = 1; XWindowsPowerManager m_powerManager; }; diff --git a/src/lib/synergy/ArgParser.cpp b/src/lib/synergy/ArgParser.cpp index 4d8dd5e34..526429d98 100644 --- a/src/lib/synergy/ArgParser.cpp +++ b/src/lib/synergy/ArgParser.cpp @@ -114,6 +114,9 @@ ArgParser::parseClientArgs(lib::synergy::ClientArgs& args, int argc, const char* else if (isArg(i, argc, argv, nullptr, "--sync-language")) { args.m_enableLangSync = true; } + else if (isArg(i, argc, argv, nullptr, "--invert-scroll")) { + args.m_clientScrollDirection = lib::synergy::ClientScrollDirection::INVERT_SERVER; + } else { if (i + 1 == argc) { args.m_synergyAddress = argv[i]; diff --git a/src/lib/synergy/ClientApp.cpp b/src/lib/synergy/ClientApp.cpp index f11bac721..8785744fa 100644 --- a/src/lib/synergy/ClientApp.cpp +++ b/src/lib/synergy/ClientApp.cpp @@ -127,6 +127,7 @@ ClientApp::help() "Usage: %s" " [--yscroll ]" " [--sync-language]" + " [--invert-scroll]" WINAPI_ARG HELP_SYS_ARGS HELP_COMMON_ARGS @@ -140,6 +141,7 @@ ClientApp::help() " --yscroll defines the vertical scrolling delta, which is\n" " 120 by default.\n" " --sync-language set this parameter to enable language synchronization.\n" + " --invert-scroll invert scroll direction on this computer.\n" HELP_COMMON_INFO_2 "\n" "* marks defaults.\n" diff --git a/src/lib/synergy/ClientArgs.h b/src/lib/synergy/ClientArgs.h index 444ae4767..d445d9368 100644 --- a/src/lib/synergy/ClientArgs.h +++ b/src/lib/synergy/ClientArgs.h @@ -23,6 +23,11 @@ namespace lib { namespace synergy { + enum ClientScrollDirection { + SERVER = 1, + INVERT_SERVER = -1 + }; + class ClientArgs : public ArgsBase { /// Public functions @@ -32,10 +37,14 @@ namespace lib { ~ClientArgs() override; public: - int m_yscroll = 0; - bool m_enableLangSync = false; /// @brief Should keyboard input be in same language as on server + int m_yscroll = 0; + bool m_enableLangSync = false; /// @brief Should keyboard input be in same language as on server - private: + /** + * @brief m_clientScrollDirection + * This option is responcible for scroll direction on client side. + */ + ClientScrollDirection m_clientScrollDirection = ClientScrollDirection::SERVER; }; } diff --git a/src/lib/synergy/IPlatformScreen.h b/src/lib/synergy/IPlatformScreen.h index 2d95903a7..c436e09b4 100644 --- a/src/lib/synergy/IPlatformScreen.h +++ b/src/lib/synergy/IPlatformScreen.h @@ -139,20 +139,6 @@ public: */ virtual String getSecureInputApp() const = 0; - //! Allow updating wheel scrolling direction - /*! - Sets a flag to allow updating the scrolling direction automatically - when scrolling - */ - virtual void allowScrollDirectionUpdate() = 0; - - //! Update the scrolling direction if allowed - /*! - If relevant flag is set should read a system settings to apply a - correct scrolling direction - */ - virtual void updateScrollDirection() = 0; - //@} //! @name accessors //@{ diff --git a/src/lib/synergy/PlatformScreen.h b/src/lib/synergy/PlatformScreen.h index 2a24a56bd..7079df138 100644 --- a/src/lib/synergy/PlatformScreen.h +++ b/src/lib/synergy/PlatformScreen.h @@ -102,9 +102,6 @@ public: virtual const String& getDropTarget() const { throw std::runtime_error("getDropTarget not implemented"); } - void allowScrollDirectionUpdate() override { m_shouldUpdateScrollDirection = true; } - void updateScrollDirection() override = 0; - protected: //! Update mouse buttons /*! @@ -127,5 +124,4 @@ protected: String m_draggingFilename; bool m_draggingStarted; bool m_fakeDraggingStarted; - bool m_shouldUpdateScrollDirection = false; }; diff --git a/src/lib/synergy/Screen.cpp b/src/lib/synergy/Screen.cpp index b9fe223ec..b2ce9ef22 100644 --- a/src/lib/synergy/Screen.cpp +++ b/src/lib/synergy/Screen.cpp @@ -114,11 +114,6 @@ Screen::enter(KeyModifierMask toggleMask) // now on screen m_entered = true; - // Forcefully update scrolling direction - // Will keep clients updated when moving cursor - m_screen->allowScrollDirectionUpdate(); - m_screen->updateScrollDirection(); - m_screen->enter(); if (m_isPrimary) { enterPrimary(); @@ -134,11 +129,6 @@ Screen::leave() assert(m_entered == true); LOG((CLOG_INFO "leaving screen")); - // Forcefully update scrolling direction - // Will keep server updated when moving cursor - m_screen->allowScrollDirectionUpdate(); - m_screen->updateScrollDirection(); - if (!m_screen->leave()) { return false; } @@ -222,11 +212,6 @@ Screen::keyUp(KeyID, KeyModifierMask, KeyButton button) void Screen::mouseDown(ButtonID button) { - // No other convinient way to check if scroll direction was changed - // If mouse button is pressed is good enough indication to allow checking - // for scroll direction - m_screen->allowScrollDirectionUpdate(); - m_screen->fakeMouseButton(button, true); } @@ -251,12 +236,9 @@ Screen::mouseRelativeMove(SInt32 dx, SInt32 dy) } void -Screen::mouseWheel(SInt32 xDelta, SInt32 yDelta) +Screen::mouseWheel(SInt32 xDelta, SInt32 yDelta) const { assert(!m_isPrimary); - // update scroll direction if necessary - m_screen->updateScrollDirection(); - m_screen->fakeMouseWheel(xDelta, yDelta); } diff --git a/src/lib/synergy/Screen.h b/src/lib/synergy/Screen.h index f79a50db8..6ca5073c7 100644 --- a/src/lib/synergy/Screen.h +++ b/src/lib/synergy/Screen.h @@ -177,7 +177,7 @@ public: to the right and negative for motion towards the user or to the left. Each wheel click should generate a delta of +/-120. */ - void mouseWheel(SInt32 xDelta, SInt32 yDelta); + void mouseWheel(SInt32 xDelta, SInt32 yDelta) const; //! Notify of options changes /*! diff --git a/src/test/unittests/synergy/ClientArgsParsingTests.cpp b/src/test/unittests/synergy/ClientArgsParsingTests.cpp index 21df6c602..9c9a725fc 100644 --- a/src/test/unittests/synergy/ClientArgsParsingTests.cpp +++ b/src/test/unittests/synergy/ClientArgsParsingTests.cpp @@ -68,6 +68,17 @@ TEST(ClientArgsParsingTests, parseClientArgs_setLangSync) EXPECT_TRUE(clientArgs.m_enableLangSync); } +TEST(ClientArgsParsingTests, parseClientArgs_setInvertScroll) +{ + NiceMock argParser; + lib::synergy::ClientArgs clientArgs; + const int argc = 2; + std::array kLangCmd = { "stub", "--invert-scroll" }; + + argParser.parseClientArgs(clientArgs, argc, kLangCmd.data()); + EXPECT_EQ(clientArgs.m_clientScrollDirection, lib::synergy::ClientScrollDirection::INVERT_SERVER); +} + TEST(ClientArgsParsingTests, parseClientArgs_setCommonArgs) { NiceMock argParser;