refactor: use bool for invert scrolling

This commit is contained in:
sithlord48 2025-09-25 20:55:14 -04:00 committed by Chris Rizzitello
parent 2cb36777f9
commit 5fc00f7af4
11 changed files with 24 additions and 39 deletions

View file

@ -146,11 +146,12 @@ const char *ClientApp::daemonInfo() const
deskflow::Screen *ClientApp::createScreen() deskflow::Screen *ClientApp::createScreen()
{ {
const bool invertScrolling = Settings::value(Settings::Client::InvertScrollDirection).toBool();
#if WINAPI_MSWINDOWS #if WINAPI_MSWINDOWS
return new deskflow::Screen( return new deskflow::Screen(
new MSWindowsScreen( new MSWindowsScreen(
false, Settings::value(Settings::Core::UseHooks).toBool(), getEvents(), 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() getEvents()
); );
@ -160,9 +161,7 @@ deskflow::Screen *ClientApp::createScreen()
if (deskflow::platform::isWayland()) { if (deskflow::platform::isWayland()) {
#if WINAPI_LIBEI #if WINAPI_LIBEI
LOG_INFO("using ei screen for wayland"); LOG_INFO("using ei screen for wayland");
return new deskflow::Screen( return new deskflow::Screen(new deskflow::EiScreen(false, getEvents(), true, invertScrolling), getEvents());
new deskflow::EiScreen(false, getEvents(), true, args().m_clientScrollDirection), getEvents()
);
#else #else
throw XNoEiSupport(); throw XNoEiSupport();
#endif #endif
@ -174,7 +173,7 @@ deskflow::Screen *ClientApp::createScreen()
return new deskflow::Screen( return new deskflow::Screen(
new XWindowsScreen( new XWindowsScreen(
qPrintable(Settings::value(Settings::Core::Display).toString()), false, 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() getEvents()
); );
@ -183,9 +182,7 @@ deskflow::Screen *ClientApp::createScreen()
#if WINAPI_CARBON #if WINAPI_CARBON
return new deskflow::Screen( return new deskflow::Screen(
new OSXScreen( new OSXScreen(getEvents(), false, Settings::value(Settings::Client::LanguageSync).toBool(), invertScrolling),
getEvents(), false, Settings::value(Settings::Client::LanguageSync).toBool(), args().m_clientScrollDirection
),
getEvents() getEvents()
); );
#endif #endif

View file

@ -7,11 +7,12 @@
#include "deskflow/PlatformScreen.h" #include "deskflow/PlatformScreen.h"
#include "base/DirectionTypes.h" #include "base/DirectionTypes.h"
#include "common/Settings.h"
#include "deskflow/App.h" #include "deskflow/App.h"
PlatformScreen::PlatformScreen(IEventQueue *events, deskflow::ClientScrollDirection scrollDirection) PlatformScreen::PlatformScreen(IEventQueue *events, bool invertScrolling)
: IPlatformScreen(events), : IPlatformScreen(events),
m_clientScrollDirection(scrollDirection) m_invertScrollDirection(invertScrolling)
{ {
// do nothing // do nothing
} }
@ -86,7 +87,7 @@ void PlatformScreen::pollPressedKeys(KeyButtonSet &pressedKeys) const
int32_t PlatformScreen::mapClientScrollDirection(int32_t x) const int32_t PlatformScreen::mapClientScrollDirection(int32_t x) const
{ {
return (x * static_cast<int>(m_clientScrollDirection)); return (m_invertScrollDirection ? -x : x);
} }
std::string PlatformScreen::sidesMaskToString(uint32_t sides) std::string PlatformScreen::sidesMaskToString(uint32_t sides)

View file

@ -7,6 +7,7 @@
#pragma once #pragma once
#include "common/Settings.h"
#include "deskflow/ClientArgs.h" #include "deskflow/ClientArgs.h"
#include "deskflow/IPlatformScreen.h" #include "deskflow/IPlatformScreen.h"
@ -21,9 +22,7 @@ subclasses to implement the rest.
class PlatformScreen : public IPlatformScreen class PlatformScreen : public IPlatformScreen
{ {
public: public:
explicit PlatformScreen( explicit PlatformScreen(IEventQueue *events, bool invertScrollDirection);
IEventQueue *events, deskflow::ClientScrollDirection scrollDirection = deskflow::ClientScrollDirection::Normal
);
~PlatformScreen() override = default; ~PlatformScreen() override = default;
// IScreen overrides // IScreen overrides
@ -117,5 +116,5 @@ private:
* This member contains client scroll direction. * This member contains client scroll direction.
* This member is used only on client side. * This member is used only on client side.
*/ */
deskflow::ClientScrollDirection m_clientScrollDirection = deskflow::ClientScrollDirection::Normal; bool m_invertScrollDirection = false;
}; };

View file

@ -40,8 +40,8 @@ struct ScrollRemainder
namespace deskflow { namespace deskflow {
EiScreen::EiScreen(bool isPrimary, IEventQueue *events, bool usePortal, deskflow::ClientScrollDirection scrollDirection) EiScreen::EiScreen(bool isPrimary, IEventQueue *events, bool usePortal, bool invertScrolling)
: PlatformScreen{events, scrollDirection}, : PlatformScreen{events, invertScrolling},
m_isPrimary{isPrimary}, m_isPrimary{isPrimary},
m_events{events}, m_events{events},
m_w{1}, m_w{1},

View file

@ -33,10 +33,7 @@ class PortalInputCapture;
class EiScreen : public PlatformScreen class EiScreen : public PlatformScreen
{ {
public: public:
EiScreen( EiScreen(bool isPrimary, IEventQueue *events, bool usePortal, bool invertScrolling = false);
bool isPrimary, IEventQueue *events, bool usePortal,
deskflow::ClientScrollDirection scrollDirection = deskflow::ClientScrollDirection::Normal
);
~EiScreen() override; ~EiScreen() override;
// IScreen overrides // IScreen overrides

View file

@ -81,10 +81,9 @@ HINSTANCE MSWindowsScreen::s_windowInstance = nullptr;
MSWindowsScreen *MSWindowsScreen::s_screen = nullptr; MSWindowsScreen *MSWindowsScreen::s_screen = nullptr;
MSWindowsScreen::MSWindowsScreen( MSWindowsScreen::MSWindowsScreen(
bool isPrimary, bool noHooks, IEventQueue *events, bool enableLangSync, bool isPrimary, bool noHooks, IEventQueue *events, bool enableLangSync, bool invertScrolling
deskflow::ClientScrollDirection scrollDirection
) )
: PlatformScreen(events, scrollDirection), : PlatformScreen(events, invertScrolling),
m_isPrimary(isPrimary), m_isPrimary(isPrimary),
m_noHooks(noHooks), m_noHooks(noHooks),
m_isOnScreen(m_isPrimary), m_isOnScreen(m_isPrimary),

View file

@ -31,8 +31,7 @@ class MSWindowsScreen : public PlatformScreen
{ {
public: public:
MSWindowsScreen( MSWindowsScreen(
bool isPrimary, bool noHooks, IEventQueue *events, bool enableLangSync = false, bool isPrimary, bool noHooks, IEventQueue *events, bool enableLangSync = false, bool invetScrolling = false
deskflow::ClientScrollDirection scrollDirection = deskflow::ClientScrollDirection::Normal
); );
~MSWindowsScreen() override; ~MSWindowsScreen() override;

View file

@ -44,10 +44,7 @@ class Mutex;
class OSXScreen : public PlatformScreen class OSXScreen : public PlatformScreen
{ {
public: public:
OSXScreen( OSXScreen(IEventQueue *events, bool isPrimary, bool enableLangSync = false, bool invertScrolling = false);
IEventQueue *events, bool isPrimary, bool enableLangSync = false,
deskflow::ClientScrollDirection scrollDirection = deskflow::ClientScrollDirection::Normal
);
virtual ~OSXScreen(); virtual ~OSXScreen();

View file

@ -73,10 +73,8 @@ void avoidHesitatingCursor();
bool OSXScreen::s_testedForGHOM = false; bool OSXScreen::s_testedForGHOM = false;
bool OSXScreen::s_hasGHOM = false; bool OSXScreen::s_hasGHOM = false;
OSXScreen::OSXScreen( OSXScreen::OSXScreen(IEventQueue *events, bool isPrimary, bool enableLangSync, bool invertScrolling)
IEventQueue *events, bool isPrimary, bool enableLangSync, deskflow::ClientScrollDirection scrollDirection : PlatformScreen(events, invertScrolling),
)
: PlatformScreen(events, scrollDirection),
m_isPrimary(isPrimary), m_isPrimary(isPrimary),
m_isOnScreen(m_isPrimary), m_isOnScreen(m_isPrimary),
m_cursorPosValid(false), m_cursorPosValid(false),

View file

@ -84,10 +84,9 @@ static int xi_opcode;
XWindowsScreen *XWindowsScreen::s_screen = nullptr; XWindowsScreen *XWindowsScreen::s_screen = nullptr;
XWindowsScreen::XWindowsScreen( XWindowsScreen::XWindowsScreen(
const char *displayName, bool isPrimary, int mouseScrollDelta, IEventQueue *events, const char *displayName, bool isPrimary, int mouseScrollDelta, IEventQueue *events, bool invertScrolling
deskflow::ClientScrollDirection scrollDirection
) )
: PlatformScreen(events, scrollDirection), : PlatformScreen(events, invertScrolling),
m_isPrimary(isPrimary), m_isPrimary(isPrimary),
m_mouseScrollDelta(mouseScrollDelta), m_mouseScrollDelta(mouseScrollDelta),
m_isOnScreen(m_isPrimary), m_isOnScreen(m_isPrimary),

View file

@ -30,8 +30,7 @@ class XWindowsScreen : public PlatformScreen
{ {
public: public:
XWindowsScreen( XWindowsScreen(
const char *displayName, bool isPrimary, int mouseScrollDelta, IEventQueue *events, const char *displayName, bool isPrimary, int mouseScrollDelta, IEventQueue *events, bool invertScrolling = false
deskflow::ClientScrollDirection m_clientScrollDirection = deskflow::ClientScrollDirection::Normal
); );
~XWindowsScreen() override; ~XWindowsScreen() override;