Skip to content

Commit 5a238c4

Browse files
committed
Use envars to configure controlled crossing options
1 parent ade8816 commit 5a238c4

File tree

5 files changed

+103
-22
lines changed

5 files changed

+103
-22
lines changed

LittleBigMouse.Daemon/LittleBigMouse.Engine/MouseEngine.cpp

+36-12
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,13 @@ void MouseEngine::OnMouseMoveCross(MouseEventArg& e)
237237
}
238238

239239
int stallCount = 0;
240-
int maxStallCount = 250;
241240

242241
void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
243242
{
244243
ResetClip();
245244
if(CheckForStopped(e)) return;
246245

247246
int triggerKey = VK_CONTROL;
248-
bool isTriggerKeyPressed = ((GetAsyncKeyState(triggerKey) & 0x8000) == 0x8000);
249247
const auto pIn = e.Point;
250248

251249
const ZoneLink* zoneOut;
@@ -258,11 +256,23 @@ void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
258256
zoneOut = _oldZone->RightZones->AtPixel(pIn.Y());
259257
if (zoneOut->Target)
260258
{
261-
if (_oldZone->ExitTriggerRight && !isTriggerKeyPressed)
259+
bool isTriggerKeyPressed = enableCtrlKeyCrossing && ((GetAsyncKeyState(triggerKey) & 0x8000) == 0x8000);
260+
if (enableControlVertEdgeCrossing && !isTriggerKeyPressed)
262261
{
263-
NoZoneMatches(e);
264-
return;
262+
stallCount++;
263+
if (stallCount < controlCrossingThreshold) {
264+
#if defined(_DEBUG)
265+
std::cout << "count " << stallCount << "\n";
266+
#endif
267+
NoZoneMatches(e);
268+
return;
269+
}
270+
else {
271+
stallCount = 0;
272+
}
265273
}
274+
stallCount = 0;
275+
pOut = { zoneOut->ToTargetPixel(pIn.X()), zoneOut->Target->PixelsBounds().Top() };
266276

267277
pOut = { zoneOut->Target->PixelsBounds().Left(),zoneOut->ToTargetPixel(pIn.Y()) };
268278
}
@@ -278,11 +288,23 @@ void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
278288
zoneOut = _oldZone->LeftZones->AtPixel(pIn.Y());
279289
if (zoneOut->Target)
280290
{
281-
if (_oldZone->ExitTriggerLeft && !isTriggerKeyPressed)
291+
bool isTriggerKeyPressed = enableCtrlKeyCrossing && ((GetAsyncKeyState(triggerKey) & 0x8000) == 0x8000);
292+
if (enableControlVertEdgeCrossing && !isTriggerKeyPressed)
282293
{
283-
NoZoneMatches(e);
284-
return;
294+
stallCount++;
295+
if (stallCount < controlCrossingThreshold) {
296+
#if defined(_DEBUG)
297+
std::cout << "count " << stallCount << "\n";
298+
#endif
299+
NoZoneMatches(e);
300+
return;
301+
}
302+
else {
303+
stallCount = 0;
304+
}
285305
}
306+
stallCount = 0;
307+
pOut = { zoneOut->ToTargetPixel(pIn.X()), zoneOut->Target->PixelsBounds().Top() };
286308

287309
pOut = { zoneOut->Target->PixelsBounds().Right() - 1,zoneOut->ToTargetPixel(pIn.Y()) };
288310
}
@@ -298,10 +320,11 @@ void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
298320
zoneOut = _oldZone->BottomZones->AtPixel(pIn.X());
299321
if (zoneOut->Target)
300322
{
301-
if (_oldZone->ExitTriggerBottom && !isTriggerKeyPressed)
323+
bool isTriggerKeyPressed = enableCtrlKeyCrossing && ((GetAsyncKeyState(triggerKey) & 0x8000) == 0x8000);
324+
if (enableControlHorzEdgeCrossing && !isTriggerKeyPressed)
302325
{
303326
stallCount++;
304-
if (stallCount < maxStallCount) {
327+
if (stallCount < controlCrossingThreshold) {
305328
#if defined(_DEBUG)
306329
std::cout << "count " << stallCount << "\n";
307330
#endif
@@ -328,10 +351,11 @@ void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
328351
zoneOut = _oldZone->TopZones->AtPixel(pIn.X());
329352
if (zoneOut->Target)
330353
{
331-
if (_oldZone->ExitTriggerTop && !isTriggerKeyPressed)
354+
bool isTriggerKeyPressed = enableCtrlKeyCrossing && ((GetAsyncKeyState(triggerKey) & 0x8000) == 0x8000);
355+
if (enableControlHorzEdgeCrossing && !isTriggerKeyPressed)
332356
{
333357
stallCount++;
334-
if (stallCount < maxStallCount) {
358+
if (stallCount < controlCrossingThreshold) {
335359
#if defined(_DEBUG)
336360
std::cout << "count " << stallCount << "\n";
337361
#endif

LittleBigMouse.Daemon/LittleBigMouse.Engine/MouseEngine.h

+5
Original file line numberDiff line numberDiff line change
@@ -52,5 +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;
59+
5560
};
5661

LittleBigMouse.Daemon/LittleBigMouse.Engine/Zone.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ Zone::Zone(int id, std::string deviceId, std::string name, const geo::Rect<long>
131131
#if defined(_DEBUG)
132132
std::cout << "Create Zone: " << id << " " << DeviceId << "\n";
133133
#endif
134-
135-
ExitTriggerBottom = true;
136-
ExitTriggerTop = true;
137-
ExitTriggerLeft = false;
138-
ExitTriggerRight = false;
139134
}
140135

141136

LittleBigMouse.Daemon/LittleBigMouse.Engine/Zone.h

-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ class Zone
4343
ZoneLink* RightZones;
4444
ZoneLink* BottomZones;
4545

46-
bool ExitTriggerLeft;
47-
bool ExitTriggerRight;
48-
bool ExitTriggerTop;
49-
bool ExitTriggerBottom;
50-
5146
[[nodiscard]] bool IsMain() const;
5247

5348
double Dpi;

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

+62
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ std::string GetParentProcess()
6666
return std::string(ws.begin(), ws.end());
6767
}
6868

69+
static std::string GetEnv(const std::wstring& varName)
70+
{
71+
std::wstring str;
72+
DWORD len = GetEnvironmentVariableW(varName.c_str(), NULL, 0);
73+
if (len > 0)
74+
{
75+
str.resize(len);
76+
str.resize(GetEnvironmentVariableW(varName.c_str(), &str[0], len));
77+
}
78+
return std::string(str.begin(), str.end());
79+
}
80+
81+
static int GetEnvInt(const std::wstring& varName, int def = -1)
82+
{
83+
int num = def;
84+
std::string envar = GetEnv(varName);
85+
try {
86+
num = std::stoi(envar);
87+
}
88+
catch (std::invalid_argument& e) {
89+
//std::cout << "That is not a valid number." << '\n';
90+
}
91+
catch (std::out_of_range& e) {
92+
//std::cout << "That is not a valid number." << '\n';
93+
}
94+
return num;
95+
}
96+
6997
int main(int argc, char *argv[]){
7098

7199
constexpr LPCWSTR szUniqueNamedMutex = L"LittleBigMouse_Daemon";
@@ -94,6 +122,40 @@ int main(int argc, char *argv[]){
94122
MouseEngine engine;
95123
Hooker hook;
96124

125+
// Gather environment variables for the engine
126+
127+
int thresh = GetEnvInt(L"LBM_CC_THRESHOLD");
128+
#if defined(_DEBUG)
129+
std::cout << "LBM_CC_THRESHOLD is: " << thresh << '\n';
130+
#endif
131+
if (thresh != -1) {
132+
engine.controlCrossingThreshold = thresh;
133+
}
134+
135+
std::string envar = GetEnv(L"LBM_CC_HORZ_EDGE");
136+
#if defined(_DEBUG)
137+
std::cout << "LBM_CC_THRESHOLD is: " << envar << '\n';
138+
#endif
139+
if (envar.size() != 0) {
140+
engine.enableControlHorzEdgeCrossing = true;
141+
}
142+
143+
envar = GetEnv(L"LBM_CC_VERT_EDGE");
144+
#if defined(_DEBUG)
145+
std::cout << "LBM_CC_VERT_EDGE is: " << envar << '\n';
146+
#endif
147+
if (envar.size() != 0) {
148+
engine.enableControlVertEdgeCrossing = true;
149+
}
150+
151+
envar = GetEnv(L"LBM_CC_CTRL_KEY");
152+
#if defined(_DEBUG)
153+
std::cout << "LBM_CC_CTRL_KEY is: " << envar << '\n';
154+
#endif
155+
if (envar.size() != 0) {
156+
engine.enableCtrlKeyCrossing = true;
157+
}
158+
97159
auto p = GetParentProcess();
98160

99161
// Test if daemon was started from UI

0 commit comments

Comments
 (0)