1 /* antimicro Gamepad to KB+M event mapper
2 * Copyright (C) 2015 Travis Nickles <nickles.travis@gmail.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <QTextStream>
19 #include <QMapIterator>
20 #include <QDesktopWidget>
21
22 #include "applaunchhelper.h"
23
24 #ifdef Q_OS_WIN
25 #include <winextras.h>
26 #endif
27
AppLaunchHelper(AntiMicroSettings * settings,bool graphical,QObject * parent)28 AppLaunchHelper::AppLaunchHelper(AntiMicroSettings *settings, bool graphical,
29 QObject *parent) :
30 QObject(parent)
31 {
32 this->settings = settings;
33 this->graphical = graphical;
34 }
35
initRunMethods()36 void AppLaunchHelper::initRunMethods()
37 {
38 if (graphical)
39 {
40 establishMouseTimerConnections();
41 enablePossibleMouseSmoothing();
42 changeMouseRefreshRate();
43 changeSpringModeScreen();
44 changeGamepadPollRate();
45
46 #ifdef Q_OS_WIN
47 checkPointerPrecision();
48 #endif
49 }
50 }
51
enablePossibleMouseSmoothing()52 void AppLaunchHelper::enablePossibleMouseSmoothing()
53 {
54 bool smoothingEnabled = settings->value("Mouse/Smoothing", false).toBool();
55 if (smoothingEnabled)
56 {
57 int historySize = settings->value("Mouse/HistorySize", 0).toInt();
58 if (historySize > 0)
59 {
60 JoyButton::setMouseHistorySize(historySize);
61 }
62
63 double weightModifier = settings->value("Mouse/WeightModifier", 0.0).toDouble();
64 if (weightModifier > 0.0)
65 {
66 JoyButton::setWeightModifier(weightModifier);
67 }
68 }
69 }
70
changeMouseRefreshRate()71 void AppLaunchHelper::changeMouseRefreshRate()
72 {
73 int refreshRate = settings->value("Mouse/RefreshRate", 0).toInt();
74 if (refreshRate > 0)
75 {
76 JoyButton::setMouseRefreshRate(refreshRate);
77 }
78 }
79
changeGamepadPollRate()80 void AppLaunchHelper::changeGamepadPollRate()
81 {
82 unsigned int pollRate = settings->value("GamepadPollRate",
83 AntiMicroSettings::defaultSDLGamepadPollRate).toUInt();
84 if (pollRate > 0)
85 {
86 JoyButton::setGamepadRefreshRate(pollRate);
87 }
88 }
89
printControllerList(QMap<SDL_JoystickID,InputDevice * > * joysticks)90 void AppLaunchHelper::printControllerList(QMap<SDL_JoystickID, InputDevice *> *joysticks)
91 {
92 QTextStream outstream(stdout);
93
94 outstream << QObject::tr("# of joysticks found: %1").arg(joysticks->size()) << endl;
95 outstream << endl;
96 outstream << QObject::tr("List Joysticks:") << endl;
97 outstream << QObject::tr("---------------") << endl;
98 QMapIterator<SDL_JoystickID, InputDevice*> iter(*joysticks);
99 unsigned int indexNumber = 1;
100 while (iter.hasNext())
101 {
102 InputDevice *tempdevice = iter.next().value();
103 outstream << QObject::tr("Joystick %1:").arg(indexNumber) << endl;
104 outstream << " " << QObject::tr("Index: %1").arg(tempdevice->getRealJoyNumber()) << endl;
105 #ifdef USE_SDL_2
106 outstream << " " << QObject::tr("GUID: %1").arg(tempdevice->getGUIDString()) << endl;
107 #endif
108 outstream << " " << QObject::tr("Name: %1").arg(tempdevice->getSDLName()) << endl;
109 #ifdef USE_SDL_2
110 QString gameControllerStatus = tempdevice->isGameController() ?
111 QObject::tr("Yes") : QObject::tr("No");
112 outstream << " " << QObject::tr("Game Controller: %1").arg(gameControllerStatus) << endl;
113 #endif
114
115 outstream << " " << QObject::tr("# of Axes: %1").arg(tempdevice->getNumberRawAxes()) << endl;
116 outstream << " " << QObject::tr("# of Buttons: %1").arg(tempdevice->getNumberRawButtons()) << endl;
117 outstream << " " << QObject::tr("# of Hats: %1").arg(tempdevice->getNumberHats()) << endl;
118
119 if (iter.hasNext())
120 {
121 outstream << endl;
122 indexNumber++;
123 }
124 }
125 }
126
changeSpringModeScreen()127 void AppLaunchHelper::changeSpringModeScreen()
128 {
129 QDesktopWidget deskWid;
130 int springScreen = settings->value("Mouse/SpringScreen",
131 AntiMicroSettings::defaultSpringScreen).toInt();
132
133 if (springScreen >= deskWid.screenCount())
134 {
135 springScreen = -1;
136 settings->setValue("Mouse/SpringScreen",
137 AntiMicroSettings::defaultSpringScreen);
138 settings->sync();
139 }
140
141 JoyButton::setSpringModeScreen(springScreen);
142 }
143
144 #ifdef Q_OS_WIN
checkPointerPrecision()145 void AppLaunchHelper::checkPointerPrecision()
146 {
147 WinExtras::grabCurrentPointerPrecision();
148 bool disableEnhandedPoint = settings->value("Mouse/DisableWinEnhancedPointer",
149 AntiMicroSettings::defaultDisabledWinEnhanced).toBool();
150 if (disableEnhandedPoint)
151 {
152 WinExtras::disablePointerPrecision();
153 }
154 }
155
appQuitPointerPrecision()156 void AppLaunchHelper::appQuitPointerPrecision()
157 {
158 bool disableEnhancedPoint = settings->value("Mouse/DisableWinEnhancedPointer",
159 AntiMicroSettings::defaultDisabledWinEnhanced).toBool();
160 if (disableEnhancedPoint && !WinExtras::isUsingEnhancedPointerPrecision())
161 {
162 WinExtras::enablePointerPrecision();
163 }
164 }
165
166 #endif
167
revertMouseThread()168 void AppLaunchHelper::revertMouseThread()
169 {
170 JoyButton::indirectStaticMouseThread(QThread::currentThread());
171 }
172
changeMouseThread(QThread * thread)173 void AppLaunchHelper::changeMouseThread(QThread *thread)
174 {
175 JoyButton::setStaticMouseThread(thread);
176 }
177
establishMouseTimerConnections()178 void AppLaunchHelper::establishMouseTimerConnections()
179 {
180 JoyButton::establishMouseTimerConnections();
181 }
182