diff --git a/ChangeLog b/ChangeLog index c67ac9009..e231679ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ v1.14.3-snapshot Bug fixes: - #7135 Fix issue with function keys on macOS - #7140 Configure scroll direction on a per-computer basis +- #7141 Code refactoring for the configure scroll direction task =========== v1.14.2-stable diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp index 2682839b4..8f8034acb 100644 --- a/src/lib/platform/MSWindowsScreen.cpp +++ b/src/lib/platform/MSWindowsScreen.cpp @@ -96,8 +96,10 @@ MSWindowsScreen::MSWindowsScreen( bool isPrimary, bool noHooks, bool stopOnDeskSwitch, - IEventQueue* events) : - PlatformScreen(events), + IEventQueue* events, + bool enableLangSync, + lib::synergy::ClientScrollDirection scrollDirection) : + PlatformScreen(events, scrollDirection), m_isPrimary(isPrimary), m_noHooks(noHooks), m_isOnScreen(m_isPrimary), @@ -146,7 +148,7 @@ MSWindowsScreen::MSWindowsScreen( stopOnDeskSwitch); m_keyState = new MSWindowsKeyState(m_desks, getEventTarget(), m_events, AppUtil::instance().getKeyboardLayoutList(), - ClientApp::instance().args().m_enableLangSync); + enableLangSync); updateScreenShape(); m_class = createWindowClass(); @@ -825,8 +827,8 @@ MSWindowsScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const void MSWindowsScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const { - xDelta *= ClientApp::instance().args().m_clientScrollDirection; - yDelta *= ClientApp::instance().args().m_clientScrollDirection; + xDelta = mapClientScrollDirection(xDelta); + yDelta = mapClientScrollDirection(yDelta); m_desks->fakeMouseWheel(xDelta, yDelta); } diff --git a/src/lib/platform/MSWindowsScreen.h b/src/lib/platform/MSWindowsScreen.h index bef2f71cf..450068e22 100644 --- a/src/lib/platform/MSWindowsScreen.h +++ b/src/lib/platform/MSWindowsScreen.h @@ -22,6 +22,7 @@ #include "platform/MSWindowsPowerManager.h" #include "synergy/PlatformScreen.h" #include "synergy/DragInformation.h" +#include "synergy/ClientArgs.h" #include "platform/synwinhk.h" #include "mt/CondVar.h" #include "mt/Mutex.h" @@ -44,7 +45,9 @@ public: bool isPrimary, bool noHooks, bool stopOnDeskSwitch, - IEventQueue* events); + IEventQueue* events, + bool enableLangSync = false, + lib::synergy::ClientScrollDirection scrollDirection = lib::synergy::ClientScrollDirection::SERVER); virtual ~MSWindowsScreen(); //! @name manipulators diff --git a/src/lib/platform/OSXScreen.h b/src/lib/platform/OSXScreen.h index 8ba118d30..ecfef6507 100644 --- a/src/lib/platform/OSXScreen.h +++ b/src/lib/platform/OSXScreen.h @@ -53,7 +53,11 @@ class Mutex; //! Implementation of IPlatformScreen for OS X class OSXScreen : public PlatformScreen { public: - OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCursor=true); + OSXScreen(IEventQueue* events, + bool isPrimary, + bool enableLangSync = false, + lib::synergy::ClientScrollDirection scrollDirection = lib::synergy::ClientScrollDirection::SERVER); + virtual ~OSXScreen(); IEventQueue* getEvents() const { return m_events; } @@ -330,9 +334,6 @@ private: SInt32 m_lastSingleClickXCursor; SInt32 m_lastSingleClickYCursor; - // cursor will hide and show on enable and disable if true. - bool m_autoShowHideCursor; - IEventQueue* m_events; Thread* m_getDropTargetThread; diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index acf3207a6..750830d1e 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -83,8 +83,11 @@ void avoidHesitatingCursor(); bool OSXScreen::s_testedForGHOM = false; bool OSXScreen::s_hasGHOM = false; -OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCursor) : - PlatformScreen(events), +OSXScreen::OSXScreen(IEventQueue* events, + bool isPrimary, + bool enableLangSync, + lib::synergy::ClientScrollDirection scrollDirection) : + PlatformScreen(events, scrollDirection), m_isPrimary(isPrimary), m_isOnScreen(m_isPrimary), m_cursorPosValid(false), @@ -113,7 +116,6 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso m_clickState(1), m_lastSingleClickXCursor(0), m_lastSingleClickYCursor(0), - m_autoShowHideCursor(autoShowHideCursor), m_events(events), m_getDropTargetThread(NULL), m_impl(NULL) @@ -127,7 +129,7 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso m_screensaver = new OSXScreenSaver(m_events, getEventTarget()); m_keyState = new OSXKeyState(m_events, AppUtil::instance().getKeyboardLayoutList(), - ClientApp::instance().args().m_enableLangSync); + enableLangSync); if (App::instance().argsBase().m_preventSleep) { m_powerManager.disableSleep(); @@ -786,9 +788,7 @@ OSXScreen::enable() else { // FIXME -- prevent system from entering power save mode - if (m_autoShowHideCursor) { - hideCursor(); - } + hideCursor(); // warp the mouse to the cursor center fakeMouseMove(m_xCenter, m_yCenter); @@ -819,10 +819,8 @@ OSXScreen::enable() void OSXScreen::disable() { - if (m_autoShowHideCursor) { - showCursor(); - } - + showCursor(); + // FIXME -- stop watching jump zones, stop capturing input if (m_eventTapRLSR) { @@ -1469,7 +1467,7 @@ 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. auto result = static_cast(3.0 * x / 120.0); - return (result * ClientApp::instance().args().m_clientScrollDirection); + return mapClientScrollDirection(result); } double diff --git a/src/lib/platform/XWindowsScreen.cpp b/src/lib/platform/XWindowsScreen.cpp index 1feedbe5f..a3225096f 100644 --- a/src/lib/platform/XWindowsScreen.cpp +++ b/src/lib/platform/XWindowsScreen.cpp @@ -100,7 +100,9 @@ XWindowsScreen::XWindowsScreen( bool isPrimary, bool disableXInitThreads, int mouseScrollDelta, - IEventQueue* events) : + IEventQueue* events, + lib::synergy::ClientScrollDirection scrollDirection) : + PlatformScreen(events, scrollDirection), m_isPrimary(isPrimary), m_mouseScrollDelta(mouseScrollDelta), m_display(NULL), @@ -125,8 +127,7 @@ XWindowsScreen::XWindowsScreen( m_xkb(false), m_xi2detected(false), m_xrandr(false), - m_events(events), - PlatformScreen(events) + m_events(events) { assert(s_screen == NULL); @@ -876,7 +877,7 @@ XWindowsScreen::fakeMouseWheel(SInt32, SInt32 yDelta) const return; } - yDelta *= ClientApp::instance().args().m_clientScrollDirection; + yDelta = mapClientScrollDirection(yDelta); // choose button depending on rotation direction const unsigned int xButton = mapButtonToX(static_cast( diff --git a/src/lib/platform/XWindowsScreen.h b/src/lib/platform/XWindowsScreen.h index 427c6fd0f..6a7be0ed5 100644 --- a/src/lib/platform/XWindowsScreen.h +++ b/src/lib/platform/XWindowsScreen.h @@ -21,6 +21,7 @@ #include "arch/Arch.h" #include "synergy/PlatformScreen.h" #include "synergy/KeyMap.h" +#include "synergy/ClientArgs.h" #include "common/stdset.h" #include "common/stdvector.h" #include "platform/XWindowsPowerManager.h" @@ -40,7 +41,8 @@ class XWindowsScreen : public PlatformScreen { public: XWindowsScreen(const char* displayName, bool isPrimary, bool disableXInitThreads, int mouseScrollDelta, - IEventQueue* events); + IEventQueue* events, + lib::synergy::ClientScrollDirection m_clientScrollDirection = lib::synergy::ClientScrollDirection::SERVER); virtual ~XWindowsScreen(); //! @name manipulators diff --git a/src/lib/synergy/ClientApp.cpp b/src/lib/synergy/ClientApp.cpp index 8785744fa..9df001941 100644 --- a/src/lib/synergy/ClientApp.cpp +++ b/src/lib/synergy/ClientApp.cpp @@ -180,13 +180,17 @@ ClientApp::createScreen() { #if WINAPI_MSWINDOWS return new synergy::Screen(new MSWindowsScreen( - false, args().m_noHooks, args().m_stopOnDeskSwitch, m_events), m_events); + false, args().m_noHooks, args().m_stopOnDeskSwitch, m_events, + args().m_enableLangSync, args().m_clientScrollDirection), m_events); #elif WINAPI_XWINDOWS return new synergy::Screen(new XWindowsScreen( args().m_display, false, args().m_disableXInitThreads, - args().m_yscroll, m_events), m_events); + args().m_yscroll, m_events, args().m_clientScrollDirection), m_events); #elif WINAPI_CARBON - return new synergy::Screen(new OSXScreen(m_events, false), m_events); + return new synergy::Screen(new OSXScreen(m_events, false, + args().m_enableLangSync, + args().m_clientScrollDirection), + m_events); #endif } diff --git a/src/lib/synergy/PlatformScreen.cpp b/src/lib/synergy/PlatformScreen.cpp index 51b374f91..734d208af 100644 --- a/src/lib/synergy/PlatformScreen.cpp +++ b/src/lib/synergy/PlatformScreen.cpp @@ -20,10 +20,11 @@ #include "synergy/App.h" #include "synergy/ArgsBase.h" -PlatformScreen::PlatformScreen(IEventQueue* events) : +PlatformScreen::PlatformScreen(IEventQueue* events, lib::synergy::ClientScrollDirection scrollDirection) : IPlatformScreen(events), m_draggingStarted(false), - m_fakeDraggingStarted(false) + m_fakeDraggingStarted(false), + m_clientScrollDirection(scrollDirection) { } @@ -121,3 +122,10 @@ PlatformScreen::isDraggingStarted() } return false; } + +SInt32 +PlatformScreen::mapClientScrollDirection(SInt32 x) const +{ + return (x * m_clientScrollDirection); +} + diff --git a/src/lib/synergy/PlatformScreen.h b/src/lib/synergy/PlatformScreen.h index 7079df138..d6f9c46e4 100644 --- a/src/lib/synergy/PlatformScreen.h +++ b/src/lib/synergy/PlatformScreen.h @@ -20,6 +20,7 @@ #include "synergy/IPlatformScreen.h" #include "synergy/DragInformation.h" +#include "synergy/ClientArgs.h" #include "common/stdexcept.h" //! Base screen implementation @@ -30,7 +31,7 @@ subclasses to implement the rest. */ class PlatformScreen : public IPlatformScreen { public: - PlatformScreen(IEventQueue* events); + PlatformScreen(IEventQueue* events, lib::synergy::ClientScrollDirection scrollDirection = lib::synergy::ClientScrollDirection::SERVER); virtual ~PlatformScreen(); // IScreen overrides @@ -120,8 +121,23 @@ protected: // IPlatformScreen overrides virtual void handleSystemEvent(const Event& event, void*) = 0; + /*! + * \brief mapClientScrollDirection + * Convert scroll according to client scroll directio + * \return converted value according to the client scroll direction + */ + virtual SInt32 mapClientScrollDirection(SInt32) const; + protected: String m_draggingFilename; bool m_draggingStarted; bool m_fakeDraggingStarted; + +private: + /*! + * \brief m_clientScrollDirection + * This member contains client scroll direction. + * This member is used only on client side. + */ + lib::synergy::ClientScrollDirection m_clientScrollDirection = lib::synergy::ClientScrollDirection::SERVER; };