From 5fc00f7af49b3fa9a8997fafda256e8e139fb2ef Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Thu, 25 Sep 2025 20:55:14 -0400 Subject: [PATCH] refactor: use bool for invert scrolling --- src/lib/deskflow/ClientApp.cpp | 13 +++++-------- src/lib/deskflow/PlatformScreen.cpp | 7 ++++--- src/lib/deskflow/PlatformScreen.h | 7 +++---- src/lib/platform/EiScreen.cpp | 4 ++-- src/lib/platform/EiScreen.h | 5 +---- src/lib/platform/MSWindowsScreen.cpp | 5 ++--- src/lib/platform/MSWindowsScreen.h | 3 +-- src/lib/platform/OSXScreen.h | 5 +---- src/lib/platform/OSXScreen.mm | 6 ++---- src/lib/platform/XWindowsScreen.cpp | 5 ++--- src/lib/platform/XWindowsScreen.h | 3 +-- 11 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/lib/deskflow/ClientApp.cpp b/src/lib/deskflow/ClientApp.cpp index 8af2a2678..72cb08b14 100644 --- a/src/lib/deskflow/ClientApp.cpp +++ b/src/lib/deskflow/ClientApp.cpp @@ -146,11 +146,12 @@ const char *ClientApp::daemonInfo() const deskflow::Screen *ClientApp::createScreen() { + const bool invertScrolling = Settings::value(Settings::Client::InvertScrollDirection).toBool(); #if WINAPI_MSWINDOWS return new deskflow::Screen( new MSWindowsScreen( false, Settings::value(Settings::Core::UseHooks).toBool(), getEvents(), - Settings::value(Settings::Client::LanguageSync).toBool(), args().m_clientScrollDirection + Settings::value(Settings::Client::LanguageSync).toBool(), invertScrolling ), getEvents() ); @@ -160,9 +161,7 @@ deskflow::Screen *ClientApp::createScreen() if (deskflow::platform::isWayland()) { #if WINAPI_LIBEI LOG_INFO("using ei screen for wayland"); - return new deskflow::Screen( - new deskflow::EiScreen(false, getEvents(), true, args().m_clientScrollDirection), getEvents() - ); + return new deskflow::Screen(new deskflow::EiScreen(false, getEvents(), true, invertScrolling), getEvents()); #else throw XNoEiSupport(); #endif @@ -174,7 +173,7 @@ deskflow::Screen *ClientApp::createScreen() return new deskflow::Screen( new XWindowsScreen( qPrintable(Settings::value(Settings::Core::Display).toString()), false, - Settings::value(Settings::Client::ScrollSpeed).toInt(), getEvents(), args().m_clientScrollDirection + Settings::value(Settings::Client::ScrollSpeed).toInt(), getEvents(), invertScrolling ), getEvents() ); @@ -183,9 +182,7 @@ deskflow::Screen *ClientApp::createScreen() #if WINAPI_CARBON return new deskflow::Screen( - new OSXScreen( - getEvents(), false, Settings::value(Settings::Client::LanguageSync).toBool(), args().m_clientScrollDirection - ), + new OSXScreen(getEvents(), false, Settings::value(Settings::Client::LanguageSync).toBool(), invertScrolling), getEvents() ); #endif diff --git a/src/lib/deskflow/PlatformScreen.cpp b/src/lib/deskflow/PlatformScreen.cpp index 28b2588d3..cfa8a4be6 100644 --- a/src/lib/deskflow/PlatformScreen.cpp +++ b/src/lib/deskflow/PlatformScreen.cpp @@ -7,11 +7,12 @@ #include "deskflow/PlatformScreen.h" #include "base/DirectionTypes.h" +#include "common/Settings.h" #include "deskflow/App.h" -PlatformScreen::PlatformScreen(IEventQueue *events, deskflow::ClientScrollDirection scrollDirection) +PlatformScreen::PlatformScreen(IEventQueue *events, bool invertScrolling) : IPlatformScreen(events), - m_clientScrollDirection(scrollDirection) + m_invertScrollDirection(invertScrolling) { // do nothing } @@ -86,7 +87,7 @@ void PlatformScreen::pollPressedKeys(KeyButtonSet &pressedKeys) const int32_t PlatformScreen::mapClientScrollDirection(int32_t x) const { - return (x * static_cast(m_clientScrollDirection)); + return (m_invertScrollDirection ? -x : x); } std::string PlatformScreen::sidesMaskToString(uint32_t sides) diff --git a/src/lib/deskflow/PlatformScreen.h b/src/lib/deskflow/PlatformScreen.h index 6b8648587..a4e912fee 100644 --- a/src/lib/deskflow/PlatformScreen.h +++ b/src/lib/deskflow/PlatformScreen.h @@ -7,6 +7,7 @@ #pragma once +#include "common/Settings.h" #include "deskflow/ClientArgs.h" #include "deskflow/IPlatformScreen.h" @@ -21,9 +22,7 @@ subclasses to implement the rest. class PlatformScreen : public IPlatformScreen { public: - explicit PlatformScreen( - IEventQueue *events, deskflow::ClientScrollDirection scrollDirection = deskflow::ClientScrollDirection::Normal - ); + explicit PlatformScreen(IEventQueue *events, bool invertScrollDirection); ~PlatformScreen() override = default; // IScreen overrides @@ -117,5 +116,5 @@ private: * This member contains client scroll direction. * This member is used only on client side. */ - deskflow::ClientScrollDirection m_clientScrollDirection = deskflow::ClientScrollDirection::Normal; + bool m_invertScrollDirection = false; }; diff --git a/src/lib/platform/EiScreen.cpp b/src/lib/platform/EiScreen.cpp index 9d205e0de..54c1e24fd 100644 --- a/src/lib/platform/EiScreen.cpp +++ b/src/lib/platform/EiScreen.cpp @@ -40,8 +40,8 @@ struct ScrollRemainder namespace deskflow { -EiScreen::EiScreen(bool isPrimary, IEventQueue *events, bool usePortal, deskflow::ClientScrollDirection scrollDirection) - : PlatformScreen{events, scrollDirection}, +EiScreen::EiScreen(bool isPrimary, IEventQueue *events, bool usePortal, bool invertScrolling) + : PlatformScreen{events, invertScrolling}, m_isPrimary{isPrimary}, m_events{events}, m_w{1}, diff --git a/src/lib/platform/EiScreen.h b/src/lib/platform/EiScreen.h index 145fb7a75..5f42ac2e4 100644 --- a/src/lib/platform/EiScreen.h +++ b/src/lib/platform/EiScreen.h @@ -33,10 +33,7 @@ class PortalInputCapture; class EiScreen : public PlatformScreen { public: - EiScreen( - bool isPrimary, IEventQueue *events, bool usePortal, - deskflow::ClientScrollDirection scrollDirection = deskflow::ClientScrollDirection::Normal - ); + EiScreen(bool isPrimary, IEventQueue *events, bool usePortal, bool invertScrolling = false); ~EiScreen() override; // IScreen overrides diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp index 6f9a3cc4c..c98aee4fa 100644 --- a/src/lib/platform/MSWindowsScreen.cpp +++ b/src/lib/platform/MSWindowsScreen.cpp @@ -81,10 +81,9 @@ HINSTANCE MSWindowsScreen::s_windowInstance = nullptr; MSWindowsScreen *MSWindowsScreen::s_screen = nullptr; MSWindowsScreen::MSWindowsScreen( - bool isPrimary, bool noHooks, IEventQueue *events, bool enableLangSync, - deskflow::ClientScrollDirection scrollDirection + bool isPrimary, bool noHooks, IEventQueue *events, bool enableLangSync, bool invertScrolling ) - : PlatformScreen(events, scrollDirection), + : PlatformScreen(events, invertScrolling), m_isPrimary(isPrimary), m_noHooks(noHooks), m_isOnScreen(m_isPrimary), diff --git a/src/lib/platform/MSWindowsScreen.h b/src/lib/platform/MSWindowsScreen.h index c11389e14..2ad858c73 100644 --- a/src/lib/platform/MSWindowsScreen.h +++ b/src/lib/platform/MSWindowsScreen.h @@ -31,8 +31,7 @@ class MSWindowsScreen : public PlatformScreen { public: MSWindowsScreen( - bool isPrimary, bool noHooks, IEventQueue *events, bool enableLangSync = false, - deskflow::ClientScrollDirection scrollDirection = deskflow::ClientScrollDirection::Normal + bool isPrimary, bool noHooks, IEventQueue *events, bool enableLangSync = false, bool invetScrolling = false ); ~MSWindowsScreen() override; diff --git a/src/lib/platform/OSXScreen.h b/src/lib/platform/OSXScreen.h index 603a6e208..b956db6a7 100644 --- a/src/lib/platform/OSXScreen.h +++ b/src/lib/platform/OSXScreen.h @@ -44,10 +44,7 @@ class Mutex; class OSXScreen : public PlatformScreen { public: - OSXScreen( - IEventQueue *events, bool isPrimary, bool enableLangSync = false, - deskflow::ClientScrollDirection scrollDirection = deskflow::ClientScrollDirection::Normal - ); + OSXScreen(IEventQueue *events, bool isPrimary, bool enableLangSync = false, bool invertScrolling = false); virtual ~OSXScreen(); diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index 6a456529e..9f25a4bd2 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -73,10 +73,8 @@ void avoidHesitatingCursor(); bool OSXScreen::s_testedForGHOM = false; bool OSXScreen::s_hasGHOM = false; -OSXScreen::OSXScreen( - IEventQueue *events, bool isPrimary, bool enableLangSync, deskflow::ClientScrollDirection scrollDirection -) - : PlatformScreen(events, scrollDirection), +OSXScreen::OSXScreen(IEventQueue *events, bool isPrimary, bool enableLangSync, bool invertScrolling) + : PlatformScreen(events, invertScrolling), m_isPrimary(isPrimary), m_isOnScreen(m_isPrimary), m_cursorPosValid(false), diff --git a/src/lib/platform/XWindowsScreen.cpp b/src/lib/platform/XWindowsScreen.cpp index d10a4d8cc..578bfdb14 100644 --- a/src/lib/platform/XWindowsScreen.cpp +++ b/src/lib/platform/XWindowsScreen.cpp @@ -84,10 +84,9 @@ static int xi_opcode; XWindowsScreen *XWindowsScreen::s_screen = nullptr; XWindowsScreen::XWindowsScreen( - const char *displayName, bool isPrimary, int mouseScrollDelta, IEventQueue *events, - deskflow::ClientScrollDirection scrollDirection + const char *displayName, bool isPrimary, int mouseScrollDelta, IEventQueue *events, bool invertScrolling ) - : PlatformScreen(events, scrollDirection), + : PlatformScreen(events, invertScrolling), m_isPrimary(isPrimary), m_mouseScrollDelta(mouseScrollDelta), m_isOnScreen(m_isPrimary), diff --git a/src/lib/platform/XWindowsScreen.h b/src/lib/platform/XWindowsScreen.h index 3d05929e3..83341dbb8 100644 --- a/src/lib/platform/XWindowsScreen.h +++ b/src/lib/platform/XWindowsScreen.h @@ -30,8 +30,7 @@ class XWindowsScreen : public PlatformScreen { public: XWindowsScreen( - const char *displayName, bool isPrimary, int mouseScrollDelta, IEventQueue *events, - deskflow::ClientScrollDirection m_clientScrollDirection = deskflow::ClientScrollDirection::Normal + const char *displayName, bool isPrimary, int mouseScrollDelta, IEventQueue *events, bool invertScrolling = false ); ~XWindowsScreen() override;