diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b1bea33..df887b3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,14 +58,15 @@ option(USE_SDL_2 "Use SDL 2 libraries rather than SDL 1." ON) if(UNIX) option(WITH_X11 "Compile with support for X11." ON) - option(WITH_UINPUT "Compile with support for uinput. uinput will be usable to simulate events." OFF) + option(WITH_UINPUT "Compile with support for uinput. uinput will be usable to simulate events." ON) option(WITH_XTEST "Compile with support for XTest. XTest will be usable to simulate events." ON) - option(APPDATA "Build project with AppData file support." OFF) + option(APPDATA "Build project with AppData file support." ON) endif(UNIX) -option(UPDATE_TRANSLATIONS "Call lupdate to update translation files from source." OFF) +option(UPDATE_TRANSLATIONS "Call lupdate to update translation files from source." ON) option(TRANS_KEEP_OBSOLETE "Do not specify -no-obsolete when calling lupdate." OFF) + if(WIN32) option(PORTABLE_PACKAGE "Create portable Windows package" OFF) #option(TARGET_ARCH "Choose which version of some libraries to use. (x86, x86_64)" "x86") diff --git a/src/addeditautoprofiledialog.cpp b/src/addeditautoprofiledialog.cpp index 7e694e3a..87cd86f9 100644 --- a/src/addeditautoprofiledialog.cpp +++ b/src/addeditautoprofiledialog.cpp @@ -326,7 +326,7 @@ void AddEditAutoProfileDialog::showCaptureHelpWindow() box->show(); UnixCaptureWindowUtility *util = new UnixCaptureWindowUtility(); - QThread *thread = new QThread(this); + QThread *thread = new QThread; // QTHREAD(this) util->moveToThread(thread); connect(thread, SIGNAL(started()), util, SLOT(attemptWindowCapture())); diff --git a/src/advancebuttondialog.cpp b/src/advancebuttondialog.cpp index 291f1c94..b2d987c1 100644 --- a/src/advancebuttondialog.cpp +++ b/src/advancebuttondialog.cpp @@ -1140,6 +1140,7 @@ void AdvanceButtonDialog::checkSlotTimeUpdate() updateSlotsScrollArea(actionTime); } } + } void AdvanceButtonDialog::checkSlotMouseModUpdate() @@ -1381,7 +1382,7 @@ void AdvanceButtonDialog::populateSetSelectionComboBox() ui->setSelectionComboBox->insertItem(0, trUtf8("Disabled")); int currentIndex = 1; - for (int i=0; i < InputDevice::NUMBER_JOYSETS; i++) + for (int i = 0; i < InputDevice::NUMBER_JOYSETS; i++) { if (this->button->getOriginSet() != i) { diff --git a/src/advancebuttondialog.h b/src/advancebuttondialog.h index 72ee86f2..7219b5aa 100644 --- a/src/advancebuttondialog.h +++ b/src/advancebuttondialog.h @@ -45,7 +45,7 @@ private: enum SlotTypeComboIndex { KBMouseSlot = 0, CycleSlot, DelaySlot, DistanceSlot, ExecuteSlot, HoldSlot, LoadSlot, MouseModSlot, PauseSlot, PressTimeSlot, - ReleaseSlot, SetChangeSlot, TextEntry, + ReleaseSlot, SetChangeSlot, TextEntry }; protected: diff --git a/src/advancebuttondialog.ui b/src/advancebuttondialog.ui index adb3b5f8..92ca79b6 100644 --- a/src/advancebuttondialog.ui +++ b/src/advancebuttondialog.ui @@ -284,8 +284,7 @@ - - + .. @@ -299,8 +298,7 @@ - - + .. @@ -314,8 +312,7 @@ - - + .. @@ -352,7 +349,7 @@ - 0 + 8 diff --git a/src/eventhandlers/uinputeventhandler.cpp b/src/eventhandlers/uinputeventhandler.cpp index e969f131..65832bdd 100644 --- a/src/eventhandlers/uinputeventhandler.cpp +++ b/src/eventhandlers/uinputeventhandler.cpp @@ -259,8 +259,8 @@ void UInputEventHandler::sendMouseAbsEvent(int xDis, int yDis, int screen) write_uinput_event(springMouseFileHandler, EV_ABS, ABS_Y, yDis); } -void UInputEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, - unsigned int width, unsigned int height) +void UInputEventHandler::sendMouseSpringEvent(int xDis, int yDis, + int width, int height) { if (width > 0 && height > 0) { @@ -336,57 +336,56 @@ int UInputEventHandler::openUInputHandle() void UInputEventHandler::setKeyboardEvents(int filehandle) { - int result = 0; - result = ioctl(filehandle, UI_SET_EVBIT, EV_KEY); - result = ioctl(filehandle, UI_SET_EVBIT, EV_SYN); + ioctl(filehandle, UI_SET_EVBIT, EV_KEY); + ioctl(filehandle, UI_SET_EVBIT, EV_SYN); } void UInputEventHandler::setRelMouseEvents(int filehandle) { - int result = 0; - result = ioctl(filehandle, UI_SET_EVBIT, EV_KEY); - result = ioctl(filehandle, UI_SET_EVBIT, EV_SYN); - result = ioctl(filehandle, UI_SET_EVBIT, EV_REL); - result = ioctl(filehandle, UI_SET_RELBIT, REL_X); - result = ioctl(filehandle, UI_SET_RELBIT, REL_Y); - result = ioctl(filehandle, UI_SET_RELBIT, REL_WHEEL); - result = ioctl(filehandle, UI_SET_RELBIT, REL_HWHEEL); + ioctl(filehandle, UI_SET_EVBIT, EV_KEY); + ioctl(filehandle, UI_SET_EVBIT, EV_SYN); + ioctl(filehandle, UI_SET_EVBIT, EV_REL); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_LEFT); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_RIGHT); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_MIDDLE); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_SIDE); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_EXTRA); + ioctl(filehandle, UI_SET_RELBIT, REL_X); + ioctl(filehandle, UI_SET_RELBIT, REL_Y); + ioctl(filehandle, UI_SET_RELBIT, REL_WHEEL); + ioctl(filehandle, UI_SET_RELBIT, REL_HWHEEL); + + ioctl(filehandle, UI_SET_KEYBIT, BTN_LEFT); + ioctl(filehandle, UI_SET_KEYBIT, BTN_RIGHT); + ioctl(filehandle, UI_SET_KEYBIT, BTN_MIDDLE); + ioctl(filehandle, UI_SET_KEYBIT, BTN_SIDE); + ioctl(filehandle, UI_SET_KEYBIT, BTN_EXTRA); } void UInputEventHandler::setSpringMouseEvents(int filehandle) { - int result = 0; - result = ioctl(filehandle, UI_SET_EVBIT, EV_KEY); - result = ioctl(filehandle, UI_SET_EVBIT, EV_SYN); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_LEFT); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_RIGHT); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_MIDDLE); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_SIDE); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_EXTRA); + ioctl(filehandle, UI_SET_EVBIT, EV_KEY); + ioctl(filehandle, UI_SET_EVBIT, EV_SYN); - result = ioctl(filehandle, UI_SET_EVBIT, EV_ABS); - result = ioctl(filehandle, UI_SET_ABSBIT, ABS_X); - result = ioctl(filehandle, UI_SET_ABSBIT, ABS_Y); - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_TOUCH); + ioctl(filehandle, UI_SET_KEYBIT, BTN_LEFT); + ioctl(filehandle, UI_SET_KEYBIT, BTN_RIGHT); + ioctl(filehandle, UI_SET_KEYBIT, BTN_MIDDLE); + ioctl(filehandle, UI_SET_KEYBIT, BTN_SIDE); + ioctl(filehandle, UI_SET_KEYBIT, BTN_EXTRA); + + ioctl(filehandle, UI_SET_EVBIT, EV_ABS); + ioctl(filehandle, UI_SET_ABSBIT, ABS_X); + ioctl(filehandle, UI_SET_ABSBIT, ABS_Y); + ioctl(filehandle, UI_SET_KEYBIT, BTN_TOUCH); // BTN_TOOL_PEN is required for the mouse to be seen as an // absolute mouse as opposed to a relative mouse. - result = ioctl(filehandle, UI_SET_KEYBIT, BTN_TOOL_PEN); + ioctl(filehandle, UI_SET_KEYBIT, BTN_TOOL_PEN); } void UInputEventHandler::populateKeyCodes(int filehandle) { - int result = 0; + for (unsigned int i=KEY_ESC; i <= KEY_MICMUTE; i++) { - result = ioctl(filehandle, UI_SET_KEYBIT, i); + ioctl(filehandle, UI_SET_KEYBIT, i); } } @@ -402,9 +401,9 @@ void UInputEventHandler::createUInputKeyboardDevice(int filehandle) uidev.id.product = 0x0; uidev.id.version = 1; - int result = 0; - result = write(filehandle, &uidev, sizeof(uidev)); - result = ioctl(filehandle, UI_DEV_CREATE); + + write(filehandle, &uidev, sizeof(uidev)); + ioctl(filehandle, UI_DEV_CREATE); } void UInputEventHandler::createUInputMouseDevice(int filehandle) @@ -419,9 +418,9 @@ void UInputEventHandler::createUInputMouseDevice(int filehandle) uidev.id.product = 0x0; uidev.id.version = 1; - int result = 0; - result = write(filehandle, &uidev, sizeof(uidev)); - result = ioctl(filehandle, UI_DEV_CREATE); + + write(filehandle, &uidev, sizeof(uidev)); + ioctl(filehandle, UI_DEV_CREATE); } void UInputEventHandler::createUInputSpringMouseDevice(int filehandle) @@ -444,21 +443,21 @@ void UInputEventHandler::createUInputSpringMouseDevice(int filehandle) uidev.absmax[ABS_Y] = 32767; uidev.absflat[ABS_Y] = 0; - int result = 0; - result = write(filehandle, &uidev, sizeof(uidev)); - result = ioctl(filehandle, UI_DEV_CREATE); + + write(filehandle, &uidev, sizeof(uidev)); + ioctl(filehandle, UI_DEV_CREATE); } void UInputEventHandler::closeUInputDevice(int filehandle) { - int result = 0; - result = ioctl(filehandle, UI_DEV_DESTROY); - result = close(filehandle); + + ioctl(filehandle, UI_DEV_DESTROY); + close(filehandle); } -void UInputEventHandler::write_uinput_event(int filehandle, unsigned int type, - unsigned int code, int value, bool syn) +void UInputEventHandler::write_uinput_event(int filehandle, int type, + int code, int value, bool syn) { struct input_event ev; struct input_event ev2; @@ -469,8 +468,7 @@ void UInputEventHandler::write_uinput_event(int filehandle, unsigned int type, ev.code = code; ev.value = value; - int result = 0; - result = write(filehandle, &ev, sizeof(struct input_event)); + write(filehandle, &ev, sizeof(struct input_event)); if (syn) { @@ -480,7 +478,7 @@ void UInputEventHandler::write_uinput_event(int filehandle, unsigned int type, ev2.code = SYN_REPORT; ev2.value = 0; - result = write(filehandle, &ev2, sizeof(struct input_event)); + write(filehandle, &ev2, sizeof(struct input_event)); } } diff --git a/src/inputdaemon.cpp b/src/inputdaemon.cpp index 9bb430e0..d9997f32 100644 --- a/src/inputdaemon.cpp +++ b/src/inputdaemon.cpp @@ -56,7 +56,7 @@ InputDaemon::InputDaemon(QMap *joysticks, sdlWorkerThread = nullptr; if (graphical) { - sdlWorkerThread = new QThread(); + sdlWorkerThread = new QThread; eventWorker->moveToThread(sdlWorkerThread); } diff --git a/src/joybutton.cpp b/src/joybutton.cpp index 7dd88804..9a5ecd22 100644 --- a/src/joybutton.cpp +++ b/src/joybutton.cpp @@ -21,6 +21,7 @@ #include "vdpad.h" #include "event.h" #include "logger.h" +#include "SDL2/SDL_events.h" #ifdef Q_OS_WIN #include "eventhandlerfactory.h" @@ -33,7 +34,7 @@ #include #include #include - +#include const QString JoyButton::xmlName = "button"; @@ -709,6 +710,7 @@ bool JoyButton::distanceEvent() QListIterator iter(assignments); if (previousCycle) { + qDebug() << "find previous Cycle in next steps in assignments and skip to it"; iter.findNext(previousCycle); } @@ -779,9 +781,12 @@ bool JoyButton::distanceEvent() currentPause = currentHold = 0; //quitEvent = true; + qDebug() << "Deactive slots in previous range and activate new slots"; + slotiter->toFront(); if (previousCycle) { + qDebug() << "Find previous Cycle in slotiter starting from beginning"; slotiter->findNext(previousCycle); } @@ -819,6 +824,7 @@ void JoyButton::createDeskEvent() { currentCycle = 0; distanceEvent(); + } assignmentsLock.lockForRead(); @@ -839,7 +845,7 @@ void JoyButton::activateSlots() { qDebug() << "[" << __FILE__ << ": " << __LINE__ << "] " << __FUNCTION__; - if (slotiter) + if (slotiter != nullptr) { QWriteLocker tempLocker(&activeZoneLock); @@ -848,6 +854,7 @@ void JoyButton::activateSlots() bool delaySequence = false; // bool changeRepeatState = false; + int i = 0; while (slotiter->hasNext() && !exit) { JoyButtonSlot *slot = slotiter->next(); @@ -856,23 +863,29 @@ void JoyButton::activateSlots() if (mode == JoyButtonSlot::JoyKeyboard) { + i++; + qDebug() << i << ": It's a JoyKeyboard with code: " << tempcode << " and name: " << slot->getSlotString(); sendevent(slot, true); activeSlots.append(slot); int oldvalue = activeKeys.value(tempcode, 0) + 1; activeKeys.insert(tempcode, oldvalue); if (!slot->isModifierKey()) { + qDebug() << "There has been assigned a lastActiveKey"; lastActiveKey = slot; // changeRepeatState = true; } else { + qDebug() << "It's not modifier key. lastActiveKey is null pointer"; lastActiveKey = 0; // changeRepeatState = true; } } else if (mode == JoyButtonSlot::JoyMouseButton) { + i++; + qDebug() << i << ": It's a JoyMouseButton with code: " << tempcode << " and name: " << slot->getSlotString(); if ((tempcode == JoyButtonSlot::MouseWheelUp) || (tempcode == JoyButtonSlot::MouseWheelDown)) { @@ -903,6 +916,8 @@ void JoyButton::activateSlots() } else if (mode == JoyButtonSlot::JoyMouseMovement) { + i++; + qDebug() << i << ": It's a JoyMouseMovement with code: " << tempcode << " and name: " << slot->getSlotString(); slot->getMouseInterval()->restart(); //currentMouseEvent = slot; activeSlots.append(slot); @@ -935,10 +950,14 @@ void JoyButton::activateSlots() } else if (mode == JoyButtonSlot::JoyPause) { + i++; + qDebug() << i << ": It's a JoyPause with code: " << tempcode << " and name: " << slot->getSlotString(); if (!activeSlots.isEmpty()) { + qDebug() << "active slots QHash is not empty"; if (slotiter->hasPrevious()) { + i--; slotiter->previous(); } delaySequence = true; @@ -947,6 +966,7 @@ void JoyButton::activateSlots() // Segment can be ignored on a 0 interval pause else if (tempcode > 0) { + qDebug() << "active slots QHash is empty"; currentPause = slot; pauseHold.restart(); inpauseHold.restart(); @@ -956,12 +976,16 @@ void JoyButton::activateSlots() } else if (mode == JoyButtonSlot::JoyHold) { + i++; + qDebug() << i << ": It's a JoyHold with code: " << tempcode << " and name: " << slot->getSlotString(); currentHold = slot; holdTimer.start(0); exit = true; } else if (mode == JoyButtonSlot::JoyDelay) { + i++; + qDebug() << i << ": It's a JoyDelay with code: " << tempcode << " and name: " << slot->getSlotString(); currentDelay = slot; buttonDelay.restart(); delayTimer.start(0); @@ -969,15 +993,21 @@ void JoyButton::activateSlots() } else if (mode == JoyButtonSlot::JoyCycle) { + i++; + qDebug() << i << ": It's a JoyCycle with code: " << tempcode << " and name: " << slot->getSlotString(); currentCycle = slot; exit = true; } else if (mode == JoyButtonSlot::JoyDistance) { + i++; + qDebug() << i << ": It's a JoyDistance with code: " << tempcode << " and name: " << slot->getSlotString(); exit = true; } else if (mode == JoyButtonSlot::JoyRelease) { + i++; + qDebug() << i << ": It's a JoyRelease with code: " << tempcode << " and name: " << slot->getSlotString(); if (!currentRelease) { findReleaseEventEnd(); @@ -990,13 +1020,17 @@ void JoyButton::activateSlots() else if (currentRelease && activeSlots.isEmpty()) { + qDebug() << "current is release but activeSlots is empty"; //currentRelease = 0; exit = true; } else if (currentRelease && !activeSlots.isEmpty()) { + qDebug() << "current is release and activeSlots is not empty"; if (slotiter->hasPrevious()) { + qDebug() << "Back to previous slotiter from release"; + i--; slotiter->previous(); } delaySequence = true; @@ -1005,21 +1039,29 @@ void JoyButton::activateSlots() } else if (mode == JoyButtonSlot::JoyMouseSpeedMod) { + i++; + qDebug() << i << ": It's a JoyMouseSpeedMod with code: " << tempcode << " and name: " << slot->getSlotString(); mouseSpeedModifier = tempcode * 0.01; mouseSpeedModList.append(slot); activeSlots.append(slot); } else if (mode == JoyButtonSlot::JoyKeyPress) { + i++; + qDebug() << i << ": It's a JoyKeyPress with code: " << tempcode << " and name: " << slot->getSlotString(); if (activeSlots.isEmpty()) { + qDebug() << "activeSlots is empty. It's a true delaySequence and assigned currentKeyPress"; delaySequence = true; currentKeyPress = slot; } else { + qDebug() << "activeSlots is not empty. It's a true delaySequence and exit"; if (slotiter->hasPrevious()) { + qDebug() << "Back to previous slotiter from JoyKeyPress"; + i--; slotiter->previous(); } delaySequence = true; @@ -1028,6 +1070,8 @@ void JoyButton::activateSlots() } else if (mode == JoyButtonSlot::JoyLoadProfile) { + i++; + qDebug() << i << ": It's a JoyLoadProfile with code: " << tempcode << " and name: " << slot->getSlotString(); releaseActiveSlots(); slotiter->toBack(); exit = true; @@ -1040,14 +1084,20 @@ void JoyButton::activateSlots() } else if (mode == JoyButtonSlot::JoySetChange) { + i++; + qDebug() << i << ": It's a JoySetChange with code: " << tempcode << " and name: " << slot->getSlotString(); activeSlots.append(slot); } else if (mode == JoyButtonSlot::JoyTextEntry) { + i++; + qDebug() << i << ": It's a JoyTextEntry with code: " << tempcode << " and name: " << slot->getSlotString(); sendevent(slot, true); } else if (mode == JoyButtonSlot::JoyExecute) { + i++; + qDebug() << i << ": It's a JoyExecute with code: " << tempcode << " and name: " << slot->getSlotString(); sendevent(slot, true); } } @@ -2643,6 +2693,7 @@ QList JoyButton::getActiveZoneList() { if (previousCycle) { + qDebug() << "if there exists previous Cycle, find it in activeSlots"; iter->findNext(previousCycle); } } @@ -3604,6 +3655,8 @@ void JoyButton::holdEvent() // Activate hold event if (currentlyPressed && (buttonHold.elapsed() > currentHold->getSlotCode())) { + qDebug() << buttonHold.elapsed() << " > " << currentHold->getSlotCode(); + qDebug() << "Activate hold event"; releaseActiveSlots(); currentHold = 0; holdTimer.stop(); @@ -3613,6 +3666,7 @@ void JoyButton::holdEvent() // Elapsed time has not occurred else if (currentlyPressed) { + qDebug() << "Elapsed time has not occurred, because buttonHold: " << buttonHold.elapsed() << " is not greater than currentHoldCode: " << currentHold->getSlotCode(); int holdTime = currentHold->getSlotCode(); int proposedInterval = holdTime - buttonHold.elapsed(); proposedInterval = (proposedInterval > 0) ? proposedInterval : 0; @@ -3622,11 +3676,13 @@ void JoyButton::holdEvent() // Pre-emptive release else { + qDebug() << "Hold button is not pressed"; currentHold = 0; holdTimer.stop(); if (slotiter) { + qDebug() << "slotiter exists"; findHoldEventEnd(); createDeskEvent(); } @@ -3638,6 +3694,7 @@ void JoyButton::holdEvent() } } + void JoyButton::delayEvent() { qDebug() << "[" << __FILE__ << ": " << __LINE__ << "] " << __FUNCTION__; @@ -3788,6 +3845,7 @@ void JoyButton::releaseDeskEvent(bool skipsetchange) if (slotiter && !slotiter->hasNext()) { // At the end of the list of assignments. + qDebug() << "There is end of slotiter. Set currentCycle and previousCycle as null pointers"; currentCycle = 0; previousCycle = 0; slotiter->toFront(); @@ -3795,6 +3853,7 @@ void JoyButton::releaseDeskEvent(bool skipsetchange) else if (slotiter && slotiter->hasNext() && currentCycle) { // Cycle at the end of a segment. + qDebug() << "There exists next element in slotiter and exists currentCycle. Skip to currentCycle in slotiter starting from beginning"; slotiter->toFront(); slotiter->findNext(currentCycle); } @@ -3803,6 +3862,7 @@ void JoyButton::releaseDeskEvent(bool skipsetchange) // Check if there is a cycle action slot after // current slot. Useful after dealing with pause // actions. + qDebug() << "There exists next element and previous element in slotiter but doesn't exists currentCycle. From current point in slotiter find JoyButtonSlot::JoyCycle as slotMode and assign to currentCycle"; JoyButtonSlot *tempslot = 0; bool exit = false; while (slotiter->hasNext() && !exit) @@ -3819,6 +3879,7 @@ void JoyButton::releaseDeskEvent(bool skipsetchange) // to the front. if (!currentCycle) { + qDebug() << "Didn't find any cycle. Back to start of slotiter"; slotiter->toFront(); previousCycle = 0; } @@ -3826,11 +3887,13 @@ void JoyButton::releaseDeskEvent(bool skipsetchange) if (currentCycle) { + qDebug() << "currentCycle exists and previousCycle will be current but current will be null pointer"; previousCycle = currentCycle; currentCycle = 0; } else if (slotiter && slotiter->hasNext() && containsReleaseSlots()) { + qDebug() << "Slotiter has next element on the list. In assignments exists JoyButtonSlot::JoyRelease starting from current point. CurrentCycle and previousCycle are set null pointers now"; currentCycle = 0; previousCycle = 0; slotiter->toFront(); @@ -4013,6 +4076,7 @@ void JoyButton::clearSlotsEventReset(bool clearSignalEmit) mouseWheelVerticalEventQueue.clear(); mouseWheelHorizontalEventQueue.clear(); + qDebug() << "all current slots and previous slots ale cleared"; currentCycle = 0; previousCycle = 0; currentPause = 0; @@ -4052,6 +4116,7 @@ void JoyButton::eventReset() keyPressTimer.stop(); delayTimer.stop(); activeZoneTimer.stop(); + #ifdef Q_OS_WIN repeatHelper.getRepeatTimer()->stop(); #endif @@ -4068,6 +4133,7 @@ void JoyButton::eventReset() mouseWheelVerticalEventQueue.clear(); mouseWheelHorizontalEventQueue.clear(); + qDebug() << "all current slots and previous slots ale cleared"; currentCycle = 0; previousCycle = 0; currentPause = 0; @@ -4485,6 +4551,7 @@ void JoyButton::findReleaseEventEnd() bool found = false; while (!found && slotiter->hasNext()) { + qDebug() << "slotiter has next element"; JoyButtonSlot *currentSlot = slotiter->next(); JoyButtonSlot::JoySlotInputAction mode = currentSlot->getSlotMode(); @@ -4504,6 +4571,7 @@ void JoyButton::findReleaseEventEnd() if (found && slotiter->hasPrevious()) { + qDebug() << "There has been found end release. Back to previous slotiter element"; slotiter->previous(); } } @@ -4549,6 +4617,7 @@ void JoyButton::findHoldEventEnd() while (!found && slotiter->hasNext()) { + qDebug() << "There is next element in slotiter"; JoyButtonSlot *currentSlot = slotiter->next(); JoyButtonSlot::JoySlotInputAction mode = currentSlot->getSlotMode(); @@ -4569,6 +4638,8 @@ void JoyButton::findHoldEventEnd() if (found && slotiter->hasPrevious()) { slotiter->previous(); + } else { + qDebug() << "There wasn't end for hold"; } } @@ -5875,6 +5946,7 @@ void JoyButton::resetProperties() { qDebug() << "[" << __FILE__ << ": " << __LINE__ << "] " << __FUNCTION__; + qDebug() << "all current slots and previous slots ale cleared"; currentCycle = nullptr; previousCycle = nullptr; currentPause = nullptr; diff --git a/src/joybutton.h b/src/joybutton.h index a0e2575f..5f51fe31 100644 --- a/src/joybutton.h +++ b/src/joybutton.h @@ -292,6 +292,7 @@ public: static double cursorRemainderX; static double cursorRemainderY; + protected: double getTotalSlotDistance(JoyButtonSlot *slot); bool distanceEvent(); @@ -347,6 +348,7 @@ protected: bool isDown; bool toggleActiveState; bool useTurbo; + bool lastUnlessInList; QList assignments; QList activeSlots; QString customName; diff --git a/src/joytabwidget.cpp b/src/joytabwidget.cpp index 6c357389..ab0d83e6 100644 --- a/src/joytabwidget.cpp +++ b/src/joytabwidget.cpp @@ -2268,7 +2268,7 @@ void JoyTabWidget::fillSetButtons(SetJoystick *set) { button->establishPropertyUpdatedConnections(); - if (!hideEmptyButtons || button->getAssignedSlots()->count() > 0) + if (!hideEmptyButtons || (button->getAssignedSlots()->count() > 0)) { JoyButtonWidget *buttonWidget = new JoyButtonWidget (button, displayingNames, this); buttonWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); diff --git a/src/keyboard/virtualkeyboardmousewidget.cpp b/src/keyboard/virtualkeyboardmousewidget.cpp index b95ba3c2..c3d4a34a 100644 --- a/src/keyboard/virtualkeyboardmousewidget.cpp +++ b/src/keyboard/virtualkeyboardmousewidget.cpp @@ -27,6 +27,9 @@ #include "quicksetdialog.h" #include "buttoneditdialog.h" +#include "x11extras.h" +#include + #include #include #include @@ -102,6 +105,24 @@ VirtualKeyboardMouseWidget::VirtualKeyboardMouseWidget(QWidget *parent) : } + +bool VirtualKeyboardMouseWidget::is_numlock_activated() +{ +#ifdef Q_OS_WIN + short status = GetKeyState(VK_NUMLOCK); + return status == 1; +#endif + +#ifdef Q_OS_UNIX + Display *dpy = XOpenDisplay(":0"); // X11Extras::getInstance()->display(); + XKeyboardState x; + XGetKeyboardControl(dpy, &x); + XCloseDisplay(dpy); + return x.led_mask & 2; +#endif +} + + void VirtualKeyboardMouseWidget::setupVirtualKeyboardLayout() { qDebug() << "[" << __FILE__ << ": " << __LINE__ << "] " << __FUNCTION__; @@ -110,7 +131,21 @@ void VirtualKeyboardMouseWidget::setupVirtualKeyboardLayout() QVBoxLayout *tempMainKeyLayout = setupMainKeyboardLayout(); QVBoxLayout *tempAuxKeyLayout = setupAuxKeyboardLayout(); - QVBoxLayout *tempNumKeyPadLayout = setupKeyboardNumPadLayout(); + QVBoxLayout *tempNumKeyPadLayout = new QVBoxLayout(); + + if (is_numlock_activated()) + tempNumKeyPadLayout = setupKeyboardNumPadLayout(); + else { + + QPushButton *othersKeysButton = createOtherKeysMenu(); + + tempNumKeyPadLayout->addWidget(noneButton); + tempNumKeyPadLayout->addWidget(othersKeysButton); + tempNumKeyPadLayout->setStretchFactor(noneButton, 1); + tempNumKeyPadLayout->setStretchFactor(othersKeysButton, 1); + tempNumKeyPadLayout->addSpacerItem(new QSpacerItem(0, 20, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding)); + } + QHBoxLayout *tempHBoxLayout = new QHBoxLayout(); tempHBoxLayout->addLayout(tempMainKeyLayout); @@ -153,6 +188,7 @@ QVBoxLayout *VirtualKeyboardMouseWidget::setupMainKeyboardLayout() tempHBoxLayout = new QHBoxLayout(); tempHBoxLayout->setSpacing(0); tempHBoxLayout->addWidget(createNewKey("grave")); + for (int i=1; i <= 9; i++) { tempHBoxLayout->addWidget(createNewKey(QString::number(i))); diff --git a/src/keyboard/virtualkeyboardmousewidget.h b/src/keyboard/virtualkeyboardmousewidget.h index 659b0776..ae025cec 100644 --- a/src/keyboard/virtualkeyboardmousewidget.h +++ b/src/keyboard/virtualkeyboardmousewidget.h @@ -43,6 +43,7 @@ public: explicit VirtualKeyboardMouseWidget(InputDevice *joystick, ButtonEditDialogHelper* helper, QuickSetDialog* quickSetDialog = nullptr, QWidget *parent = nullptr); explicit VirtualKeyboardMouseWidget(QWidget *parent = nullptr); bool isKeyboardTabVisible(); + bool is_numlock_activated(); protected: void setupVirtualKeyboardLayout(); diff --git a/src/main.cpp b/src/main.cpp index 0488849f..4c2631a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -558,7 +558,7 @@ int main(int argc, char *argv[]) { PadderCommon::mouseHelperObj.initDeskWid(); InputDaemon *joypad_worker = new InputDaemon(joysticks, settings); - inputEventThread = new QThread(); + inputEventThread = new QThread; MainWindow *w = new MainWindow(joysticks, &cmdutility, settings); diff --git a/src/qtuinputkeymapper.cpp b/src/qtuinputkeymapper.cpp index df62b0ef..ba79dbb0 100644 --- a/src/qtuinputkeymapper.cpp +++ b/src/qtuinputkeymapper.cpp @@ -216,7 +216,7 @@ void QtUInputKeyMapper::populateMappingHashes() qtKeyToVirtualKey[Qt::Key_LaunchMedia] = KEY_MEDIA; // Map 0-9 keys - for (unsigned int i=0; i <= (KEY_9 - KEY_1); i++) + for (int i=0; i <= (KEY_9 - KEY_1); i++) { qtKeyToVirtualKey[Qt::Key_1 + i] = KEY_1 + i; } @@ -325,7 +325,7 @@ void QtUInputKeyMapper::populateMappingHashes() // Populate other hash. Flip key and value so mapping // goes VK -> Qt Key. - QHashIterator iter(qtKeyToVirtualKey); + QHashIterator iter(qtKeyToVirtualKey); while (iter.hasNext()) { iter.next(); @@ -364,15 +364,15 @@ void QtUInputKeyMapper::populateCharKeyInformation() { virtualkeyToCharKeyInformation.clear(); - unsigned int unicodeTempValue = 0; - unsigned int listIndex = 0; + int unicodeTempValue = 0; + int listIndex = 0; charKeyInformation temp; temp.modifiers = Qt::NoModifier; temp.virtualkey = 0; // Map 0-9 keys - for (unsigned int i=QChar('1').unicode(); i <= QChar('9').unicode(); i++) + for (int i=QChar('1').unicode(); i <= QChar('9').unicode(); i++) { temp.virtualkey = KEY_1 + i; virtualkeyToCharKeyInformation.insert(i, temp); @@ -387,7 +387,7 @@ void QtUInputKeyMapper::populateCharKeyInformation() temp.virtualkey = KEY_EQUAL; virtualkeyToCharKeyInformation.insert(QChar('=').unicode(), temp); - QList tempKeys; + QList tempKeys; tempKeys.append(KEY_A); tempKeys.append(KEY_B); tempKeys.append(KEY_C); @@ -416,7 +416,7 @@ void QtUInputKeyMapper::populateCharKeyInformation() tempKeys.append(KEY_Z); unicodeTempValue = QChar('a').unicode(); - QListIterator tempIter(tempKeys); + QListIterator tempIter(tempKeys); while (tempIter.hasNext()) { temp.virtualkey = tempIter.next(); @@ -451,7 +451,7 @@ void QtUInputKeyMapper::populateCharKeyInformation() tempKeys.append(QChar('_').unicode()); tempKeys.append(QChar('+').unicode()); - tempIter = QListIterator(tempKeys); + tempIter = QListIterator(tempKeys); listIndex = 0; while (tempIter.hasNext()) { diff --git a/src/quicksetdialog.cpp b/src/quicksetdialog.cpp index bcf6f10e..c7bfea77 100644 --- a/src/quicksetdialog.cpp +++ b/src/quicksetdialog.cpp @@ -387,6 +387,8 @@ void QuickSetDialog::showAxisButtonDialog() helper->setThisButton(lastButton); + helper->moveToThread(lastButton->thread()); + qDebug() << "Thread in QuickSetDialog"; if (withClear) { @@ -437,6 +439,8 @@ void QuickSetDialog::showButtonDialog() helper->setThisButton(lastButton); + helper->moveToThread(lastButton->thread()); + qDebug() << "Thread in QuickSetDialog"; @@ -491,6 +495,8 @@ void QuickSetDialog::showStickButtonDialog() helper->setThisButton(lastButton); + helper->moveToThread(lastButton->thread()); + qDebug() << "Thread in QuickSetDialog"; if (withClear) { @@ -544,6 +550,8 @@ void QuickSetDialog::showDPadButtonDialog() helper->setThisButton(lastButton); + helper->moveToThread(lastButton->thread()); + qDebug() << "Thread in QuickSetDialog"; diff --git a/src/setjoystick.cpp b/src/setjoystick.cpp index 8ead8460..51e49b78 100644 --- a/src/setjoystick.cpp +++ b/src/setjoystick.cpp @@ -27,6 +27,7 @@ #include #include #include +#include const int SetJoystick::MAXNAMELENGTH = 30; @@ -39,6 +40,7 @@ SetJoystick::SetJoystick(InputDevice *device, int index, QObject *parent) : this->device = device; this->index = index; + reset(); } @@ -64,6 +66,8 @@ SetJoystick::~SetJoystick() deleteButtons(); deleteAxes(); deleteHats(); + + removeAllBtnFromQueue(); } JoyButton* SetJoystick::getJoyButton(int index) @@ -169,6 +173,7 @@ void SetJoystick::deleteButtons() buttons.clear(); } + void SetJoystick::deleteAxes() { qDebug() << "[" << __FILE__ << ": " << __LINE__ << "] " << __FUNCTION__; @@ -702,16 +707,43 @@ void SetJoystick::propogateSetButtonClick(int button) { qDebug() << "[" << __FILE__ << ": " << __LINE__ << "] " << __FUNCTION__; - JoyButton *jButton = qobject_cast(sender()); // static_cast - if (jButton) + //JoyButton *jButton = qobject_cast(sender()); // static_cast + JoyButton* jButton = qobject_cast(sender()); + if (jButton != nullptr) { if (!jButton->getIgnoreEventState()) { emit setButtonClick(index, button); + lastClickedButtons.append(jButton); + qDebug() << "Added button " << jButton->getPartialName(false,true) << " to list"; + qDebug() << "List has " << lastClickedButtons.count() << " buttons"; } } } +QList SetJoystick::getLastClickedButtons() { + + return lastClickedButtons; +} + +void SetJoystick::removeAllBtnFromQueue() { + + if (!lastClickedButtons.isEmpty()) + lastClickedButtons.clear(); + +} + +int SetJoystick::getCountBtnInList(QString partialName) { + + int count = 0; + + foreach(JoyButton* joyBtn, lastClickedButtons) { + if (joyBtn->getPartialName(false, true) == partialName) count++; + } + + return count; +} + void SetJoystick::propogateSetButtonRelease(int button) { qDebug() << "[" << __FILE__ << ": " << __LINE__ << "] " << __FUNCTION__; diff --git a/src/setjoystick.h b/src/setjoystick.h index eea25449..e9d4b8f6 100644 --- a/src/setjoystick.h +++ b/src/setjoystick.h @@ -75,6 +75,9 @@ public: void currentAxesDeadZones(QList *axesDeadZones); void setAxesDeadZones(QList *axesDeadZones); void setAxisThrottle(int axisNum, JoyAxis::ThrottleTypes throttle); + QList getLastClickedButtons(); + void removeAllBtnFromQueue(); + int getCountBtnInList(QString partialName); virtual void readConfig(QXmlStreamReader *xml); virtual void writeConfig(QXmlStreamWriter *xml); @@ -100,6 +103,8 @@ protected: QHash sticks; QHash vdpads; + QList lastClickedButtons; + int index; InputDevice *device; QString name; diff --git a/src/uinputhelper.cpp b/src/uinputhelper.cpp index 632c44a4..7b13b273 100644 --- a/src/uinputhelper.cpp +++ b/src/uinputhelper.cpp @@ -293,7 +293,7 @@ void UInputHelper::deleteInstance() } } -QString UInputHelper::getDisplayString(unsigned int virtualkey) +QString UInputHelper::getDisplayString(int virtualkey) { QString temp; if (virtualkey <= 0) @@ -308,7 +308,7 @@ QString UInputHelper::getDisplayString(unsigned int virtualkey) return temp; } -unsigned int UInputHelper::getVirtualKey(QString codestring) +int UInputHelper::getVirtualKey(QString codestring) { int temp = 0; if (knownAliasesX11SymVK.contains(codestring))