Skip to content

Commit

Permalink
[MouseWithoutBorders] - fixing more MachineStuff references - microso…
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed Jan 28, 2025
1 parent 0e50e61 commit c024c9c
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 124 deletions.
46 changes: 23 additions & 23 deletions src/modules/MouseWithoutBorders/App/Class/Common.Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal static void MouseEvent(MOUSEDATA e, int dx, int dy)

if (switchByMouseEnabled && Sk != null && (DesMachineID == MachineID || !Setting.Values.MoveMouseRelatively) && e.dwFlags == WM_MOUSEMOVE)
{
Point p = MachineStuff.MoveToMyNeighbourIfNeeded(e.X, e.Y, desMachineID);
Point p = MachineStuff.MoveToMyNeighbourIfNeeded(e.X, e.Y, MachineStuff.desMachineID);

if (!p.IsEmpty)
{
Expand All @@ -81,20 +81,20 @@ internal static void MouseEvent(MOUSEDATA e, int dx, int dy)
Logger.LogDebug(string.Format(
CultureInfo.CurrentCulture,
"***** Host Machine: newDesMachineIdEx set = [{0}]. Mouse is now at ({1},{2})",
newDesMachineIdEx,
MachineStuff.newDesMachineIdEx,
e.X,
e.Y));

myLastX = e.X;
myLastY = e.Y;

PrepareToSwitchToMachine(newDesMachineIdEx, p);
PrepareToSwitchToMachine(MachineStuff.newDesMachineIdEx, p);
}
}

if (desMachineID != MachineID && SwitchLocation.Count <= 0)
if (MachineStuff.desMachineID != MachineID && MachineStuff.SwitchLocation.Count <= 0)
{
MousePackage.Des = desMachineID;
MousePackage.Des = MachineStuff.desMachineID;
MousePackage.Type = PackageType.Mouse;
MousePackage.Md.dwFlags = e.dwFlags;
MousePackage.Md.WheelDelta = e.WheelDelta;
Expand All @@ -107,8 +107,8 @@ internal static void MouseEvent(MOUSEDATA e, int dx, int dy)
}
else
{
MousePackage.Md.X = (e.X - primaryScreenBounds.Left) * 65535 / screenWidth;
MousePackage.Md.Y = (e.Y - primaryScreenBounds.Top) * 65535 / screenHeight;
MousePackage.Md.X = (e.X - MachineStuff.primaryScreenBounds.Left) * 65535 / screenWidth;
MousePackage.Md.Y = (e.Y - MachineStuff.primaryScreenBounds.Top) * 65535 / screenHeight;
}

SkSend(MousePackage, null, false);
Expand Down Expand Up @@ -156,15 +156,15 @@ internal static void PrepareToSwitchToMachine(ID newDesMachineID, Point desMachi
{
Logger.LogDebug($"PrepareToSwitchToMachine: newDesMachineID = {newDesMachineID}, desMachineXY = {desMachineXY}");

if (((GetTick() - lastJump < 100) && (GetTick() - lastJump > 0)) || desMachineID == ID.ALL)
if (((GetTick() - MachineStuff.lastJump < 100) && (GetTick() - MachineStuff.lastJump > 0)) || MachineStuff.desMachineID == ID.ALL)
{
Logger.LogDebug("PrepareToSwitchToMachine: lastJump");
return;
}

lastJump = GetTick();
MachineStuff.lastJump = GetTick();

string newDesMachineName = NameFromID(newDesMachineID);
string newDesMachineName = MachineStuff.NameFromID(newDesMachineID);

if (!IsConnectedTo(newDesMachineID))
{// Connection lost, cancel switching
Expand All @@ -174,10 +174,10 @@ internal static void PrepareToSwitchToMachine(ID newDesMachineID, Point desMachi
}
else
{
Common.newDesMachineID = newDesMachineID;
SwitchLocation.X = desMachineXY.X;
SwitchLocation.Y = desMachineXY.Y;
SwitchLocation.ResetCount();
MachineStuff.newDesMachineID = newDesMachineID;
MachineStuff.SwitchLocation.X = desMachineXY.X;
MachineStuff.SwitchLocation.Y = desMachineXY.Y;
MachineStuff.SwitchLocation.ResetCount();
_ = EvSwitch.Set();

// PostMessage(mainForm.Handle, WM_SWITCH, IntPtr.Zero, IntPtr.Zero);
Expand All @@ -201,19 +201,19 @@ internal static void PrepareToSwitchToMachine(ID newDesMachineID, Point desMachi
}

// Change des machine
if (desMachineID != newDesMachineID)
if (MachineStuff.desMachineID != newDesMachineID)
{
Logger.LogDebug("MouseEvent: Switching to new machine:" + newDesMachineName);

// Ask current machine to hide the Mouse cursor
if (newDesMachineID != ID.ALL && desMachineID != MachineID)
if (newDesMachineID != ID.ALL && MachineStuff.desMachineID != MachineID)
{
SendPackage(desMachineID, PackageType.HideMouse);
SendPackage(MachineStuff.desMachineID, PackageType.HideMouse);
}

DesMachineID = newDesMachineID;

if (desMachineID == MachineID)
if (MachineStuff.desMachineID == MachineID)
{
if (GetTick() - clipboardCopiedTime < BIG_CLIPBOARD_DATA_TIMEOUT)
{
Expand All @@ -224,7 +224,7 @@ internal static void PrepareToSwitchToMachine(ID newDesMachineID, Point desMachi
else
{
// Ask the new active machine to get clipboard data (if the data is too big)
SendPackage(desMachineID, PackageType.MachineSwitched);
SendPackage(MachineStuff.desMachineID, PackageType.MachineSwitched);
}

_ = Interlocked.Increment(ref switchCount);
Expand All @@ -249,15 +249,15 @@ internal static void KeybdEvent(KEYBDDATA e)
try
{
PaintCount = 0;
if (desMachineID != newDesMachineID)
if (MachineStuff.desMachineID != MachineStuff.newDesMachineID)
{
Logger.LogDebug("KeybdEvent: Switching to new machine...");
DesMachineID = newDesMachineID;
DesMachineID = MachineStuff.newDesMachineID;
}

if (desMachineID != MachineID)
if (MachineStuff.desMachineID != MachineID)
{
KeybdPackage.Des = desMachineID;
KeybdPackage.Des = MachineStuff.desMachineID;
KeybdPackage.Type = PackageType.Keyboard;
KeybdPackage.Kd = e;
KeybdPackage.DateTime = GetTick();
Expand Down
30 changes: 15 additions & 15 deletions src/modules/MouseWithoutBorders/App/Class/Common.Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,35 @@ private static void HelperThread()
break;
}

if (Common.NewDesMachineID != Common.MachineID && Common.NewDesMachineID != ID.ALL)
if (MachineStuff.NewDesMachineID != Common.MachineID && MachineStuff.NewDesMachineID != ID.ALL)
{
HideMouseCursor(false);
Common.MainFormDotEx(true);
}
else
{
if (Common.SwitchLocation.Count > 0)
if (MachineStuff.SwitchLocation.Count > 0)
{
Common.SwitchLocation.Count--;
MachineStuff.SwitchLocation.Count--;

// When we want to move mouse by pixels, we add 300k to x and y (search for XY_BY_PIXEL for other related code).
Logger.LogDebug($"+++++ Moving mouse to {Common.SwitchLocation.X}, {Common.SwitchLocation.Y}");
Logger.LogDebug($"+++++ Moving mouse to {MachineStuff.SwitchLocation.X}, {MachineStuff.SwitchLocation.Y}");

// MaxXY = 65535 so 100k is safe.
if (Common.SwitchLocation.X > XY_BY_PIXEL - 100000 || Common.SwitchLocation.Y > XY_BY_PIXEL - 100000)
if (MachineStuff.SwitchLocation.X > XY_BY_PIXEL - 100000 || MachineStuff.SwitchLocation.Y > XY_BY_PIXEL - 100000)
{
InputSimulation.MoveMouse(Common.SwitchLocation.X - XY_BY_PIXEL, Common.SwitchLocation.Y - XY_BY_PIXEL);
InputSimulation.MoveMouse(MachineStuff.SwitchLocation.X - XY_BY_PIXEL, MachineStuff.SwitchLocation.Y - XY_BY_PIXEL);
}
else
{
InputSimulation.MoveMouseEx(Common.SwitchLocation.X, Common.SwitchLocation.Y);
InputSimulation.MoveMouseEx(MachineStuff.SwitchLocation.X, MachineStuff.SwitchLocation.Y);
}

Common.MainFormDot();
}
}

if (Common.NewDesMachineID == Common.MachineID)
if (MachineStuff.NewDesMachineID == Common.MachineID)
{
ReleaseAllKeys();
}
Expand All @@ -132,8 +132,8 @@ internal static void MainFormDotEx(bool bCheckTS)

if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
{
int left = Common.PrimaryScreenBounds.Left + ((Common.PrimaryScreenBounds.Right - Common.PrimaryScreenBounds.Left) / 2) - 1;
int top = Setting.Values.HideMouse ? 3 : Common.PrimaryScreenBounds.Top + ((Common.PrimaryScreenBounds.Bottom - Common.PrimaryScreenBounds.Top) / 2);
int left = MachineStuff.PrimaryScreenBounds.Left + ((MachineStuff.PrimaryScreenBounds.Right - MachineStuff.PrimaryScreenBounds.Left) / 2) - 1;
int top = Setting.Values.HideMouse ? 3 : MachineStuff.PrimaryScreenBounds.Top + ((MachineStuff.PrimaryScreenBounds.Bottom - MachineStuff.PrimaryScreenBounds.Top) / 2);

Common.MainFormVisible = true;

Expand Down Expand Up @@ -193,8 +193,8 @@ internal static void MainForm3Pixels()
DoSomethingInUIThread(
() =>
{
MainForm.Left = Common.PrimaryScreenBounds.Left + ((Common.PrimaryScreenBounds.Right - Common.PrimaryScreenBounds.Left) / 2) - 2;
MainForm.Top = Setting.Values.HideMouse ? 3 : Common.PrimaryScreenBounds.Top + ((Common.PrimaryScreenBounds.Bottom - Common.PrimaryScreenBounds.Top) / 2) - 1;
MainForm.Left = MachineStuff.PrimaryScreenBounds.Left + ((MachineStuff.PrimaryScreenBounds.Right - MachineStuff.PrimaryScreenBounds.Left) / 2) - 2;
MainForm.Top = Setting.Values.HideMouse ? 3 : MachineStuff.PrimaryScreenBounds.Top + ((MachineStuff.PrimaryScreenBounds.Bottom - MachineStuff.PrimaryScreenBounds.Top) / 2) - 1;
MainForm.Width = 3;
MainForm.Height = 3;
MainForm.Opacity = 0.11D;
Expand Down Expand Up @@ -225,8 +225,8 @@ internal static void MainFormDot()
{
_ = Common.SendMessageToHelper(0x408, IntPtr.Zero, IntPtr.Zero, false);

MainForm.Left = Common.PrimaryScreenBounds.Left + ((Common.PrimaryScreenBounds.Right - Common.PrimaryScreenBounds.Left) / 2) - 1;
MainForm.Top = Setting.Values.HideMouse ? 3 : Common.PrimaryScreenBounds.Top + ((Common.PrimaryScreenBounds.Bottom - Common.PrimaryScreenBounds.Top) / 2);
MainForm.Left = MachineStuff.PrimaryScreenBounds.Left + ((MachineStuff.PrimaryScreenBounds.Right - MachineStuff.PrimaryScreenBounds.Left) / 2) - 1;
MainForm.Top = Setting.Values.HideMouse ? 3 : MachineStuff.PrimaryScreenBounds.Top + ((MachineStuff.PrimaryScreenBounds.Bottom - MachineStuff.PrimaryScreenBounds.Top) / 2);
MainForm.Width = 1;
MainForm.Height = 1;
MainForm.Opacity = 0.15;
Expand Down Expand Up @@ -376,7 +376,7 @@ internal static string GetMiniLog(IEnumerable<ControlCollection> optionControls)
log += $"{Setting.Values.Username}/{GetDebugInfo(MyKey)}\r\n";
log += $"{MachineName}/{MachineID}/{DesMachineID}\r\n";
log += $"Id: {Setting.Values.DeviceId}\r\n";
log += $"Matrix: {string.Join(",", MachineMatrix)}\r\n";
log += $"Matrix: {string.Join(",", MachineStuff.MachineMatrix)}\r\n";
log += $"McPool: {Setting.Values.MachinePoolString}\r\n";

log += "\r\nOPTIONS:\r\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void SendLog(string log)

public void SendDragFile(string fileName)
{
Common.DragDropStep05Ex(fileName);
DragDrop.DragDropStep05Ex(fileName);
}

public void SendClipboardData(ByteArrayOrString data, bool isFilePath)
Expand Down
Loading

0 comments on commit c024c9c

Please sign in to comment.