From d96969c6558099f4ffdbd9a8b630f284c6ec90c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Thu, 16 Sep 2021 10:20:16 +0200 Subject: [PATCH] Format code with clang-format --- .../winsendinputeventhandler.cpp | 70 ++++++--------- src/eventhandlers/winsendinputeventhandler.h | 11 +-- src/eventhandlers/winvmultieventhandler.cpp | 90 +++++++------------ src/eventhandlers/winvmultieventhandler.h | 16 ++-- src/winextras.cpp | 86 +++++++++--------- src/winextras.h | 18 ++-- 6 files changed, 120 insertions(+), 171 deletions(-) diff --git a/src/eventhandlers/winsendinputeventhandler.cpp b/src/eventhandlers/winsendinputeventhandler.cpp index e9fce333c..f969e0a90 100644 --- a/src/eventhandlers/winsendinputeventhandler.cpp +++ b/src/eventhandlers/winsendinputeventhandler.cpp @@ -15,27 +15,21 @@ * along with this program. If not, see . */ -#include #include +#include #include "winsendinputeventhandler.h" -#include #include +#include -WinSendInputEventHandler::WinSendInputEventHandler(QObject *parent) : - BaseEventHandler(parent) +WinSendInputEventHandler::WinSendInputEventHandler(QObject *parent) + : BaseEventHandler(parent) { } -bool WinSendInputEventHandler::init() -{ - return true; -} +bool WinSendInputEventHandler::init() { return true; } -bool WinSendInputEventHandler::cleanup() -{ - return true; -} +bool WinSendInputEventHandler::cleanup() { return true; } void WinSendInputEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) { @@ -47,7 +41,7 @@ void WinSendInputEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool press int tempflags = extended ? KEYEVENTF_EXTENDEDKEY : 0; temp[0].type = INPUT_KEYBOARD; - //temp[0].ki.wScan = MapVirtualKey(code, MAPVK_VK_TO_VSC); + // temp[0].ki.wScan = MapVirtualKey(code, MAPVK_VK_TO_VSC); temp[0].ki.wScan = scancode; temp[0].ki.time = 0; temp[0].ki.dwExtraInfo = 0; @@ -66,41 +60,33 @@ void WinSendInputEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool pr if (code == 1) { temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; - } - else if (code == 2) + } else if (code == 2) { temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP; - } - else if (code == 3) + } else if (code == 3) { temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP; - } - else if (code == 4) + } else if (code == 4) { temp[0].mi.dwFlags = MOUSEEVENTF_WHEEL; temp[0].mi.mouseData = pressed ? WHEEL_DELTA : 0; - } - else if (code == 5) + } else if (code == 5) { temp[0].mi.dwFlags = MOUSEEVENTF_WHEEL; temp[0].mi.mouseData = pressed ? -WHEEL_DELTA : 0; - } - else if (code == 6) + } else if (code == 6) { temp[0].mi.dwFlags = 0x01000; temp[0].mi.mouseData = pressed ? -WHEEL_DELTA : 0; - } - else if (code == 7) + } else if (code == 7) { temp[0].mi.dwFlags = 0x01000; temp[0].mi.mouseData = pressed ? WHEEL_DELTA : 0; - } - else if (code == 8) + } else if (code == 8) { temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP; temp[0].mi.mouseData = XBUTTON1; - } - else if (code == 9) + } else if (code == 9) { temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP; temp[0].mi.mouseData = XBUTTON2; @@ -114,24 +100,18 @@ void WinSendInputEventHandler::sendMouseEvent(int xDis, int yDis) INPUT temp[1] = {}; temp[0].type = INPUT_MOUSE; temp[0].mi.mouseData = 0; - temp[0].mi.dwFlags = MOUSEEVENTF_MOVE; + temp[0].mi.dwFlags = MOUSEEVENTF_MOVE; temp[0].mi.dx = xDis; temp[0].mi.dy = yDis; SendInput(1, temp, sizeof(INPUT)); } -QString WinSendInputEventHandler::getName() -{ - return QString("SendInput"); -} +QString WinSendInputEventHandler::getName() { return QString("SendInput"); } -QString WinSendInputEventHandler::getIdentifier() -{ - return QString("sendinput"); -} +QString WinSendInputEventHandler::getIdentifier() { return QString("sendinput"); } -void WinSendInputEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, - unsigned int width, unsigned int height) +void WinSendInputEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, unsigned int width, + unsigned int height) { if (width > 0 && height > 0) { @@ -140,8 +120,8 @@ void WinSendInputEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned temp[0].mi.mouseData = 0; temp[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; - int fx = ceil(xDis * (65535.0/static_cast(width))); - int fy = ceil(yDis * (65535.0/static_cast(height))); + int fx = ceil(xDis * (65535.0 / static_cast(width))); + int fy = ceil(yDis * (65535.0 / static_cast(height))); temp[0].mi.dx = fx; temp[0].mi.dy = fy; SendInput(1, temp, sizeof(INPUT)); @@ -154,9 +134,9 @@ void WinSendInputEventHandler::sendTextEntryEvent(QString maintext) if (mapper && mapper->getKeyMapper()) { - QtWinKeyMapper *keymapper = static_cast(mapper->getKeyMapper()); + QtWinKeyMapper *keymapper = static_cast(mapper->getKeyMapper()); - for (int i=0; i < maintext.size(); i++) + for (int i = 0; i < maintext.size(); i++) { QtWinKeyMapper::charKeyInformation temp = keymapper->getCharKeyInformation(maintext.at(i)); QList tempList; @@ -214,7 +194,7 @@ void WinSendInputEventHandler::sendTextEntryEvent(QString maintext) tempiter.toBack(); j = 0; memset(tempBuffer, 0, sizeof(tempBuffer)); - //INPUT tempBuffer2[tempList.size()] = {0}; + // INPUT tempBuffer2[tempList.size()] = {0}; while (tempiter.hasPrevious()) { unsigned int tempcode = tempiter.previous(); diff --git a/src/eventhandlers/winsendinputeventhandler.h b/src/eventhandlers/winsendinputeventhandler.h index fcecb3cbc..536814c85 100644 --- a/src/eventhandlers/winsendinputeventhandler.h +++ b/src/eventhandlers/winsendinputeventhandler.h @@ -24,11 +24,10 @@ #include - class WinSendInputEventHandler : public BaseEventHandler { Q_OBJECT -public: + public: explicit WinSendInputEventHandler(QObject *parent = 0); virtual bool init(); @@ -36,17 +35,15 @@ class WinSendInputEventHandler : public BaseEventHandler virtual void sendKeyboardEvent(JoyButtonSlot *slot, bool pressed); virtual void sendMouseButtonEvent(JoyButtonSlot *slot, bool pressed); virtual void sendMouseEvent(int xDis, int yDis); - virtual void sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, - unsigned int width, unsigned int height); + virtual void sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, unsigned int width, unsigned int height); virtual void sendTextEntryEvent(QString maintext); virtual QString getName(); virtual QString getIdentifier(); -signals: - -public slots: + signals: + public slots: }; #endif // WINSENDINPUTEVENTHANDLER_H diff --git a/src/eventhandlers/winvmultieventhandler.cpp b/src/eventhandlers/winvmultieventhandler.cpp index 0d1eb3e66..3e900b5d7 100644 --- a/src/eventhandlers/winvmultieventhandler.cpp +++ b/src/eventhandlers/winvmultieventhandler.cpp @@ -16,17 +16,17 @@ */ //#include +#include #include #include -#include #include "winvmultieventhandler.h" #include -WinVMultiEventHandler::WinVMultiEventHandler(QObject *parent) : - BaseEventHandler(parent), - sendInputHandler(this) +WinVMultiEventHandler::WinVMultiEventHandler(QObject *parent) + : BaseEventHandler(parent) + , sendInputHandler(this) { vmulti = 0; mouseButtons = 0; @@ -40,10 +40,7 @@ WinVMultiEventHandler::WinVMultiEventHandler(QObject *parent) : nativeKeyMapper = 0; } -WinVMultiEventHandler::~WinVMultiEventHandler() -{ - cleanup(); -} +WinVMultiEventHandler::~WinVMultiEventHandler() { cleanup(); } bool WinVMultiEventHandler::init() { @@ -109,10 +106,9 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) if (code <= 0x65) { pendingKey = code; - } - else if (code >= 0xE0 && code <= 0xE7) + } else if (code >= 0xE0 && code <= 0xE7) { - //pendingShift = 1 << (code - 0xE0); + // pendingShift = 1 << (code - 0xE0); if (nativeKeyMapper) { unsigned int nativeKey = nativeKeyMapper->returnVirtualKey(slot->getSlotCodeAlias()); @@ -122,8 +118,7 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) useSendInput = true; } } - } - else if (code > QtVMultiKeyMapper::consumerUsagePagePrefix) + } else if (code > QtVMultiKeyMapper::consumerUsagePagePrefix) { if (nativeKeyMapper) { @@ -186,8 +181,7 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) } */ - } - else if (code > 0x65) + } else if (code > 0x65) { if (nativeKeyMapper) { @@ -195,7 +189,7 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) if (nativeKey > 0) { tempSendInputSlot.setSlotCode(nativeKey); - //sendInputHandler.sendKeyboardEvent(tempslot, pressed); + // sendInputHandler.sendKeyboardEvent(tempslot, pressed); useSendInput = true; } } @@ -236,8 +230,7 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) keyboardKeys.replace(index, pendingKey); } } - } - else + } else { shiftKeys = shiftKeys ^ pendingShift; multiKeys = multiKeys ^ pendingMultimedia; @@ -262,8 +255,8 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) } */ - //qDebug() << "CURRENT: " << trying.join(","); - //qDebug() << keykeyArray; + // qDebug() << "CURRENT: " << trying.join(","); + // qDebug() << keykeyArray; if (pendingKey > 0x0) { @@ -272,10 +265,9 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed) if (pendingMultimedia > 0 || pendingExtra > 0) { - //vmulti_update_keyboard_enhanced(vmulti, multiKeys, extraKeys); + // vmulti_update_keyboard_enhanced(vmulti, multiKeys, extraKeys); } - } - else + } else { sendInputHandler.sendKeyboardEvent(&tempSendInputSlot, pressed); useSendInput = false; @@ -294,24 +286,19 @@ void WinVMultiEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool press if (code == 1) { pendingButton = 0x01; - } - else if (code == 2) + } else if (code == 2) { pendingButton = 0x04; - } - else if (code == 3) + } else if (code == 3) { pendingButton = 0x02; - } - else if (code == 4) + } else if (code == 4) { pendingWheel = pressed ? 1 : 0; - } - else if (code == 5) + } else if (code == 5) { pendingWheel = pressed ? -1 : 0; - } - else if (code >= 6 && code <= 9) + } else if (code >= 6 && code <= 9) { useSendInput = true; } @@ -339,15 +326,13 @@ void WinVMultiEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool press if (pressed) { mouseButtons = mouseButtons | pendingButton; - vmulti_update_relative_mouse(vmulti, mouseButtons, 0, 0, pendingWheel);//, pendingHWheel); - } - else + vmulti_update_relative_mouse(vmulti, mouseButtons, 0, 0, pendingWheel); //, pendingHWheel); + } else { mouseButtons = mouseButtons ^ pendingButton; - vmulti_update_relative_mouse(vmulti, mouseButtons, 0, 0, pendingWheel);//, pendingHWheel); + vmulti_update_relative_mouse(vmulti, mouseButtons, 0, 0, pendingWheel); //, pendingHWheel); } - } - else + } else { sendInputHandler.sendMouseButtonEvent(slot, pressed); } @@ -355,16 +340,16 @@ void WinVMultiEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool press void WinVMultiEventHandler::sendMouseEvent(int xDis, int yDis) { - vmulti_update_relative_mouse(vmulti, mouseButtons, xDis, yDis, 0);//, 0); + vmulti_update_relative_mouse(vmulti, mouseButtons, xDis, yDis, 0); //, 0); } -void WinVMultiEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, - unsigned int width, unsigned int height) +void WinVMultiEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, unsigned int width, + unsigned int height) { if (width > 0 && height > 0) { - int fx = ceil(xDis * (32767.0/static_cast(width))); - int fy = ceil(yDis * (32767.0/static_cast(height))); + int fx = ceil(xDis * (32767.0 / static_cast(width))); + int fy = ceil(yDis * (32767.0 / static_cast(height))); sendMouseAbsEvent(fx, fy, -1); } } @@ -373,23 +358,14 @@ void WinVMultiEventHandler::sendMouseAbsEvent(int xDis, int yDis, int screen) { Q_UNUSED(screen); - vmulti_update_mouse(vmulti, mouseButtons, xDis, yDis, 0);//, 0); + vmulti_update_mouse(vmulti, mouseButtons, xDis, yDis, 0); //, 0); } /* * TODO: Implement text event using information from QtWinKeyMapper. */ -void WinVMultiEventHandler::sendTextEntryEvent(QString maintext) -{ - sendInputHandler.sendTextEntryEvent(maintext); -} +void WinVMultiEventHandler::sendTextEntryEvent(QString maintext) { sendInputHandler.sendTextEntryEvent(maintext); } -QString WinVMultiEventHandler::getName() -{ - return QString("Vmulti"); -} +QString WinVMultiEventHandler::getName() { return QString("Vmulti"); } -QString WinVMultiEventHandler::getIdentifier() -{ - return QString("vmulti"); -} +QString WinVMultiEventHandler::getIdentifier() { return QString("vmulti"); } diff --git a/src/eventhandlers/winvmultieventhandler.h b/src/eventhandlers/winvmultieventhandler.h index 92acf1c34..e236e26a8 100644 --- a/src/eventhandlers/winvmultieventhandler.h +++ b/src/eventhandlers/winvmultieventhandler.h @@ -27,14 +27,13 @@ #include -#include #include "winsendinputeventhandler.h" - +#include class WinVMultiEventHandler : public BaseEventHandler { Q_OBJECT -public: + public: explicit WinVMultiEventHandler(QObject *parent = 0); ~WinVMultiEventHandler(); @@ -44,8 +43,7 @@ class WinVMultiEventHandler : public BaseEventHandler virtual void sendMouseButtonEvent(JoyButtonSlot *slot, bool pressed); virtual void sendMouseEvent(int xDis, int yDis); virtual void sendMouseAbsEvent(int xDis, int yDis, int screen); - virtual void sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, - unsigned int width, unsigned int height); + virtual void sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, unsigned int width, unsigned int height); // TODO: Implement text event using information from QtWinKeyMapper. virtual void sendTextEntryEvent(QString maintext); @@ -53,7 +51,7 @@ class WinVMultiEventHandler : public BaseEventHandler virtual QString getName(); virtual QString getIdentifier(); -protected: + protected: pvmulti_client vmulti; BYTE mouseButtons; BYTE shiftKeys; @@ -63,11 +61,9 @@ class WinVMultiEventHandler : public BaseEventHandler WinSendInputEventHandler sendInputHandler; QtKeyMapperBase *nativeKeyMapper; + signals: -signals: - -public slots: - + public slots: }; #endif // WINVMULTIEVENTHANDLER_H diff --git a/src/winextras.cpp b/src/winextras.cpp index 8dc282a8a..4e6c5be4b 100644 --- a/src/winextras.cpp +++ b/src/winextras.cpp @@ -2,14 +2,14 @@ #include -#include #include -//#include -#include -#include +#include + #include -#include #include +#include +#include +#include #include "winextras.h" #include @@ -17,8 +17,8 @@ typedef DWORD(WINAPI *MYPROC)(HANDLE, DWORD, LPTSTR, PDWORD); // Check if QueryFullProcessImageNameW function exists in kernel32.dll. // Function does not exist in Windows XP. -static MYPROC pQueryFullProcessImageNameW = (MYPROC) GetProcAddress( - GetModuleHandle(TEXT("kernel32.dll")), "QueryFullProcessImageNameW"); +static MYPROC pQueryFullProcessImageNameW = + (MYPROC)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "QueryFullProcessImageNameW"); /*static bool isWindowsVistaOrHigher() { @@ -39,8 +39,8 @@ static const QString PROGRAMASSOCIATIONKEY(QString("%1\\%2").arg(ROOTASSOCIATION WinExtras WinExtras::_instance; -WinExtras::WinExtras(QObject *parent) : - QObject(parent) +WinExtras::WinExtras(QObject *parent) + : QObject(parent) { populateKnownAliases(); } @@ -51,8 +51,7 @@ QString WinExtras::getDisplayString(unsigned int virtualkey) if (virtualkey <= 0) { temp = tr("[NO KEY]"); - } - else if (_instance.knownAliasesVKStrings.contains(virtualkey)) + } else if (_instance.knownAliasesVKStrings.contains(virtualkey)) { temp = _instance.knownAliasesVKStrings.value(virtualkey); } @@ -213,42 +212,44 @@ unsigned int WinExtras::scancodeFromVirtualKey(unsigned int virtualkey, unsigned { // MapVirtualKey does not work with VK_PAUSE scancode = 0x45; - } - else + } else { scancode = MapVirtualKey(virtualkey, MAPVK_VK_TO_VSC); } switch (virtualkey) { - case VK_LEFT: case VK_UP: case VK_RIGHT: case VK_DOWN: // arrow keys - case VK_PRIOR: case VK_NEXT: // page up and page down - case VK_END: case VK_HOME: - case VK_INSERT: case VK_DELETE: - case VK_DIVIDE: // numpad slash - case VK_NUMLOCK: - case VK_RCONTROL: - case VK_RMENU: - { - scancode |= EXTENDED_FLAG; // set extended bit - break; - } - case VK_RETURN: - { - // Remove ambiguity between Enter and Numpad Enter. - // In Windows, VK_RETURN is used for both. - if (alias == Qt::Key_Enter) - { - scancode |= EXTENDED_FLAG; // set extended bit - break; - } - } + case VK_LEFT: + case VK_UP: + case VK_RIGHT: + case VK_DOWN: // arrow keys + case VK_PRIOR: + case VK_NEXT: // page up and page down + case VK_END: + case VK_HOME: + case VK_INSERT: + case VK_DELETE: + case VK_DIVIDE: // numpad slash + case VK_NUMLOCK: + case VK_RCONTROL: + case VK_RMENU: { + scancode |= EXTENDED_FLAG; // set extended bit + break; + } + case VK_RETURN: { + // Remove ambiguity between Enter and Numpad Enter. + // In Windows, VK_RETURN is used for both. + if (alias == Qt::Key_Enter) + { + scancode |= EXTENDED_FLAG; // set extended bit + break; + } + } } return scancode; } - bool WinExtras::containsFileAssociationinRegistry() { bool result = false; @@ -271,8 +272,11 @@ void WinExtras::writeFileAssocationToRegistry() QSettings programAssociationReg(PROGRAMASSOCIATIONKEY, QSettings::NativeFormat); programAssociationReg.setValue("Default", tr("AntiMicro Profile")); - programAssociationReg.setValue("shell/open/command/Default", QString("\"%1\" \"%2\"").arg(QDir::toNativeSeparators(qApp->applicationFilePath())).arg("%1")); - programAssociationReg.setValue("DefaultIcon/Default", QString("%1,%2").arg(QDir::toNativeSeparators(qApp->applicationFilePath())).arg("0")); + programAssociationReg.setValue( + "shell/open/command/Default", + QString("\"%1\" \"%2\"").arg(QDir::toNativeSeparators(qApp->applicationFilePath())).arg("%1")); + programAssociationReg.setValue("DefaultIcon/Default", + QString("%1,%2").arg(QDir::toNativeSeparators(qApp->applicationFilePath())).arg("0")); programAssociationReg.sync(); // Required to refresh settings used in Windows Explorer @@ -306,9 +310,8 @@ bool WinExtras::IsRunningAsAdmin() BOOL isAdmin = FALSE; PSID administratorsGroup; SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY; - isAdmin = AllocateAndInitializeSid(&ntAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, - DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, - &administratorsGroup); + isAdmin = AllocateAndInitializeSid(&ntAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, + 0, &administratorsGroup); if (isAdmin) { if (!CheckTokenMembership(NULL, administratorsGroup, &isAdmin)) @@ -384,7 +387,6 @@ void WinExtras::grabCurrentPointerPrecision() originalMouseAccel = mouseInfo[2]; } - bool WinExtras::raiseProcessPriority() { bool result = false; diff --git a/src/winextras.h b/src/winextras.h index e8e2b057c..ef127c77a 100644 --- a/src/winextras.h +++ b/src/winextras.h @@ -1,20 +1,19 @@ #ifndef WINEXTRAS_H #define WINEXTRAS_H -#include -#include #include +#include #include +#include class WinExtras : public QObject { Q_OBJECT -public: + public: static QString getDisplayString(unsigned int virtualkey); static unsigned int getVirtualKey(QString codestring); - static unsigned int correctVirtualKey(unsigned int scancode, - unsigned int virtualkey); - static unsigned int scancodeFromVirtualKey(unsigned int virtualkey, unsigned int alias=0); + static unsigned int correctVirtualKey(unsigned int scancode, unsigned int virtualkey); + static unsigned int scancodeFromVirtualKey(unsigned int virtualkey, unsigned int alias = 0); static const unsigned int EXTENDED_FLAG; static bool containsFileAssociationinRegistry(); @@ -28,7 +27,7 @@ class WinExtras : public QObject static bool raiseProcessPriority(); static QPoint getCursorPos(); -protected: + protected: explicit WinExtras(QObject *parent = 0); void populateKnownAliases(); @@ -37,10 +36,9 @@ class WinExtras : public QObject QHash knownAliasesVKStrings; static int originalMouseAccel; -signals: - -public slots: + signals: + public slots: }; #endif // WINEXTRAS_H