Skip to content

Commit 82fbcfd

Browse files
committed
Bug fixes from testing envar combinations
1 parent 532ecb8 commit 82fbcfd

File tree

4 files changed

+44
-23
lines changed

4 files changed

+44
-23
lines changed

LittleBigMouse.Daemon/LittleBigMouse.Engine/MouseEngine.cpp

+23-16
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ void MouseEngine::OnMouseMoveCross(MouseEventArg& e)
236236
NoZoneMatches(e);
237237
}
238238

239-
int stallCount = 0;
239+
static int stallCount = 0;
240240

241-
bool canCross(bool checkEdge, MouseEngine* engine, MouseEventArg& e) {
241+
static bool canCross(bool checkEdge, MouseEngine* engine, MouseEventArg& e) {
242242
if (!checkEdge) {
243243
#if defined(_DEBUG)
244244
std::cout << "edge not checked\n";
@@ -248,28 +248,35 @@ bool canCross(bool checkEdge, MouseEngine* engine, MouseEventArg& e) {
248248
return true;
249249
}
250250

251-
bool isTriggerKeyPressed = engine->enableCtrlKeyCrossing && ((GetAsyncKeyState(VK_CONTROL) & 0x8000) == 0x8000);
252-
if (isTriggerKeyPressed) {
251+
if (engine->enableCtrlKeyCrossing) {
252+
bool isTriggerKeyPressed = ((GetAsyncKeyState(VK_CONTROL) & 0x8000) == 0x8000);
253+
if (isTriggerKeyPressed) {
253254
#if defined(_DEBUG)
254-
std::cout << "trigger key pressed\n";
255+
std::cout << "trigger key pressed\n";
255256
#endif
256-
stallCount = 0;
257-
// Allow transistion
258-
return true;
257+
stallCount = 0;
258+
// Allow transistion
259+
return true;
260+
}
261+
}
262+
263+
264+
if (engine->controlCrossingThreshold < 1) {
265+
// Cannot cross
266+
return false;
259267
}
260268

261269
stallCount++;
262270
#if defined(_DEBUG)
263-
std::cout << "count " << stallCount << "\n";
271+
std::cout << "threshold: " << stallCount << " of " << engine->controlCrossingThreshold << "\n";
264272
#endif
265-
if (stallCount < engine->controlCrossingThreshold) {
266-
// Cannot cross yet
267-
return false;
273+
if (stallCount > engine->controlCrossingThreshold) {
274+
stallCount = 0;
275+
// Can cross now
276+
return true;
268277
}
269-
270-
stallCount = 0;
271-
// Allow transistion
272-
return true;
278+
// Cannot cross
279+
return false;
273280
}
274281

275282
void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)

LittleBigMouse.Daemon/LittleBigMouse.Engine/MouseEngine.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class MouseEngine
5252

5353
ZonesLayout Layout = ZonesLayout();
5454

55-
bool enableControlHorzEdgeCrossing = false;
56-
bool enableControlVertEdgeCrossing = false;
57-
bool enableCtrlKeyCrossing = false;
58-
int controlCrossingThreshold = 0;
55+
bool enableControlHorzEdgeCrossing;
56+
bool enableControlVertEdgeCrossing;
57+
bool enableCtrlKeyCrossing;
58+
int controlCrossingThreshold;
5959

6060
};
6161

LittleBigMouse.Daemon/LittleBigMouse.Hook/LittleBigMouse.Hook.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static std::string GetEnv(const std::wstring& varName)
7878
return std::string(str.begin(), str.end());
7979
}
8080

81-
static int GetEnvInt(const std::wstring& varName, int def = -1)
81+
static int GetEnvInt(const std::wstring& varName, int def = 0)
8282
{
8383
int num = def;
8484
std::string envar = GetEnv(varName);
@@ -124,14 +124,16 @@ int main(int argc, char *argv[]){
124124

125125
// Gather environment variables for the engine
126126

127+
engine.controlCrossingThreshold = 0;
127128
int thresh = GetEnvInt(L"LBM_CC_THRESHOLD");
128129
#if defined(_DEBUG)
129130
std::cout << "LBM_CC_THRESHOLD is: " << thresh << '\n';
130131
#endif
131-
if (thresh != -1) {
132+
if (thresh > 1) {
132133
engine.controlCrossingThreshold = thresh;
133134
}
134135

136+
engine.enableControlHorzEdgeCrossing = false;
135137
std::string envar = GetEnv(L"LBM_CC_HORZ_EDGE");
136138
#if defined(_DEBUG)
137139
std::cout << "LBM_CC_THRESHOLD is: " << envar << '\n';
@@ -140,6 +142,7 @@ int main(int argc, char *argv[]){
140142
engine.enableControlHorzEdgeCrossing = true;
141143
}
142144

145+
engine.enableControlVertEdgeCrossing = false;
143146
envar = GetEnv(L"LBM_CC_VERT_EDGE");
144147
#if defined(_DEBUG)
145148
std::cout << "LBM_CC_VERT_EDGE is: " << envar << '\n';
@@ -148,6 +151,7 @@ int main(int argc, char *argv[]){
148151
engine.enableControlVertEdgeCrossing = true;
149152
}
150153

154+
engine.enableCtrlKeyCrossing = false;
151155
envar = GetEnv(L"LBM_CC_CTRL_KEY");
152156
#if defined(_DEBUG)
153157
std::cout << "LBM_CC_CTRL_KEY is: " << envar << '\n';
@@ -156,6 +160,14 @@ int main(int argc, char *argv[]){
156160
engine.enableCtrlKeyCrossing = true;
157161
}
158162

163+
// Make sure the user does not configure in a way that prevent all edge crossings.
164+
// If so, then disable edge crossing checks completely.
165+
if (engine.enableControlHorzEdgeCrossing || engine.enableControlVertEdgeCrossing) {
166+
if (!engine.enableCtrlKeyCrossing && engine.controlCrossingThreshold < 1) {
167+
engine.enableControlHorzEdgeCrossing = false;
168+
engine.enableControlVertEdgeCrossing = false;
169+
}
170+
}
159171
auto p = GetParentProcess();
160172

161173
// Test if daemon was started from UI

LittleBigMouse.sln

+3-1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ Global
391391
{CB83115D-78BA-490D-AABD-31949F013F78}.Debug|Any CPU.ActiveCfg = Debug|Win32
392392
{CB83115D-78BA-490D-AABD-31949F013F78}.Debug|Any CPU.Build.0 = Debug|Win32
393393
{CB83115D-78BA-490D-AABD-31949F013F78}.Debug|x64.ActiveCfg = Debug|x64
394+
{CB83115D-78BA-490D-AABD-31949F013F78}.Debug|x64.Build.0 = Debug|x64
394395
{CB83115D-78BA-490D-AABD-31949F013F78}.Debug|x86.ActiveCfg = Debug|Win32
395396
{CB83115D-78BA-490D-AABD-31949F013F78}.Debug|x86.Build.0 = Debug|Win32
396397
{CB83115D-78BA-490D-AABD-31949F013F78}.DebugRelease|Any CPU.ActiveCfg = Release|x64
@@ -732,6 +733,7 @@ Global
732733
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
733734
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
734735
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Debug|x64.ActiveCfg = Debug|x64
736+
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Debug|x64.Build.0 = Debug|x64
735737
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Debug|x86.ActiveCfg = Debug|x86
736738
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Debug|x86.Build.0 = Debug|x86
737739
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.DebugRelease|Any CPU.ActiveCfg = Release|Any CPU
@@ -746,7 +748,6 @@ Global
746748
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Release|x64.Build.0 = Release|x64
747749
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Release|x86.ActiveCfg = Release|x86
748750
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Release|x86.Build.0 = Release|x86
749-
{9BAC842F-54A9-4104-859F-43C8AE7CC8F4}.Debug|x64.Build.0 = Debug|x64
750751
{DF43E1E0-D8B8-44DA-9F4F-D25E161A48EB}.Debug|Any CPU.ActiveCfg = Debug|Win32
751752
{DF43E1E0-D8B8-44DA-9F4F-D25E161A48EB}.Debug|Any CPU.Build.0 = Debug|Win32
752753
{DF43E1E0-D8B8-44DA-9F4F-D25E161A48EB}.Debug|x64.ActiveCfg = Debug|x64
@@ -767,6 +768,7 @@ Global
767768
{109D43C0-AF82-4A09-B149-55612D7D7142}.Debug|Any CPU.ActiveCfg = Debug|Win32
768769
{109D43C0-AF82-4A09-B149-55612D7D7142}.Debug|Any CPU.Build.0 = Debug|Win32
769770
{109D43C0-AF82-4A09-B149-55612D7D7142}.Debug|x64.ActiveCfg = Debug|x64
771+
{109D43C0-AF82-4A09-B149-55612D7D7142}.Debug|x64.Build.0 = Debug|x64
770772
{109D43C0-AF82-4A09-B149-55612D7D7142}.Debug|x86.ActiveCfg = Debug|Win32
771773
{109D43C0-AF82-4A09-B149-55612D7D7142}.Debug|x86.Build.0 = Debug|Win32
772774
{109D43C0-AF82-4A09-B149-55612D7D7142}.DebugRelease|Any CPU.ActiveCfg = Release|x64

0 commit comments

Comments
 (0)