Skip to content

Commit

Permalink
[MWB] - fixing references to MachineStuff - microsoft#35155
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed Jan 17, 2025
1 parent 5fec44c commit 742a7ef
Show file tree
Hide file tree
Showing 24 changed files with 334 additions and 326 deletions.
4 changes: 2 additions & 2 deletions src/modules/MouseWithoutBorders/App/Class/Common.Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private static void ConnectAndGetData(object postAction)
if (!IsConnectedByAClientSocketTo(remoteMachine))
{
Logger.Log($"No potential inbound connection from {MachineName} to {remoteMachine}, ask for a push back instead.");
ID machineId = MachinePool.ResolveID(remoteMachine);
ID machineId = MachineStuff.MachinePool.ResolveID(remoteMachine);

if (machineId != ID.NONE)
{
Expand Down Expand Up @@ -832,7 +832,7 @@ internal static bool ShakeHand(ref string remoteName, Socket s, out Stream enStr

Logger.LogDebug($"{nameof(ShakeHand)}: Connection from {name}:{package.Src}");

if (Common.MachinePool.ResolveID(name) == package.Src && Common.IsConnectedTo(package.Src))
if (MachineStuff.MachinePool.ResolveID(name) == package.Src && Common.IsConnectedTo(package.Src))
{
clientPushData = package.Type == PackageType.ClipboardPush;
postAction = package.PostAction;
Expand Down
30 changes: 15 additions & 15 deletions src/modules/MouseWithoutBorders/App/Class/Common.DragDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ internal static void DragDropStep01(int wParam)
if (wParam == WM_LBUTTONDOWN)
{
MouseDown = true;
DragMachine = desMachineID;
dropMachineID = ID.NONE;
DragMachine = MachineStuff.desMachineID;
MachineStuff.dropMachineID = ID.NONE;
Logger.LogDebug("DragDropStep01: MouseDown");
}
else if (wParam == WM_LBUTTONUP)
Expand All @@ -93,7 +93,7 @@ internal static void DragDropStep01(int wParam)

internal static void DragDropStep02()
{
if (desMachineID == MachineID)
if (MachineStuff.desMachineID == MachineID)
{
Logger.LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent to myself");
DoSomethingInUIThread(() =>
Expand All @@ -118,7 +118,7 @@ internal static void DragDropStep03(DATA package)
if (package.Des == MachineID || package.Des == ID.ALL)
{
Logger.LogDebug("DragDropStep03: ExplorerDragDrop Received.");
dropMachineID = package.Src; // Drop machine is the machine that sent ExplorerDragDrop
MachineStuff.dropMachineID = package.Src; // Drop machine is the machine that sent ExplorerDragDrop
if (MouseDown || IsDropping)
{
Logger.LogDebug("DragDropStep03: Mouse is down, check if dragging...sending WM_CHECK_EXPLORER_DRAG_DROP to myself...");
Expand Down Expand Up @@ -201,9 +201,9 @@ internal static void DragDropStep05Ex(string dragFileName)
/*
* possibleDropMachineID is used as desID sent in DragDropStep06();
* */
if (dropMachineID == ID.NONE)
if (MachineStuff.dropMachineID == ID.NONE)
{
dropMachineID = newDesMachineID;
MachineStuff.dropMachineID = MachineStuff.newDesMachineID;
}

DragDropStep06();
Expand Down Expand Up @@ -249,7 +249,7 @@ internal static void DragDropStep08_2(DATA package)
if (package.Des == MachineID && !RunOnLogonDesktop && !RunOnScrSaverDesktop)
{
IsDropping = true;
dropMachineID = MachineID;
MachineStuff.dropMachineID = MachineID;
Logger.LogDebug("DragDropStep08_2: ClipboardDragDropOperation Received. IsDropping set");
}
}
Expand Down Expand Up @@ -330,9 +330,9 @@ internal static void SendCheckExplorerDragDrop()
* new des machine since the previous des machine will get this and set
* to possibleDropMachineID in DragDropStep3()
* */
package.Src = newDesMachineID;
package.Src = MachineStuff.newDesMachineID;

package.Des = desMachineID;
package.Des = MachineStuff.desMachineID;
package.MachineName = MachineName;

SkSend(package, null, false);
Expand All @@ -344,7 +344,7 @@ private static void ChangeDropMachine()
// newDesMachineID = new drop machine

// 1. Cancelling dropping in current drop machine
if (dropMachineID == MachineID)
if (MachineStuff.dropMachineID == MachineID)
{
// Drag/Drop coming through me
IsDropping = false;
Expand All @@ -357,9 +357,9 @@ private static void ChangeDropMachine()

// 2. SendClipboardBeatDragDrop to new drop machine
// new drop machine is not me
if (newDesMachineID != MachineID)
if (MachineStuff.newDesMachineID != MachineID)
{
dropMachineID = newDesMachineID;
MachineStuff.dropMachineID = MachineStuff.newDesMachineID;
SendDropBegin();
}

Expand All @@ -378,14 +378,14 @@ internal static void SendClipboardBeatDragDrop()
internal static void SendDropBegin()
{
Logger.LogDebug("SendDropBegin...");
SendPackage(dropMachineID, PackageType.ClipboardDragDropOperation);
SendPackage(MachineStuff.dropMachineID, PackageType.ClipboardDragDropOperation);
}

internal static void SendClipboardBeatDragDropEnd()
{
if (desMachineID != MachineID)
if (MachineStuff.desMachineID != MachineID)
{
SendPackage(desMachineID, PackageType.ClipboardDragDropEnd);
SendPackage(MachineStuff.desMachineID, PackageType.ClipboardDragDropEnd);
}
}

Expand Down
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 = 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
Loading

0 comments on commit 742a7ef

Please sign in to comment.