Ready for Review - [Mouse Without Borders] - refactoring "Common" classes (Part 3) - #35155 (#36950)

* [MWB] - refactoring MachineInf from Common.MachineStuff.cs into MachineInf.cs - #35155

* [MWB] - fixing references to MachineInf - #35155

* [MWB] - cleaning up MachineInf.cs - #35155

* [MWB] - moving MyRectangle from Common.MachineStuff.cs into MyRectangle.cs - #35155

* [MWB] - cleaning up MyRectangle.cs - #35155

* [MWB] - moving Common.MachineStuff.cs to MachineStuff.cs - #35155

* [MWB] - fixing references to MachineStuff - #35155

* [MWB] - cleaning up MachineStuff.cs - #35155

* [MWB] - cleaning up MachineStuff.cs - #35155

* [MWB] - moving Common.DragDrop.cs to DragDrop.cs - #35155

* [MWB] - fixing references to DragDrop - #35155

* [MWB] - fixing unit test - #35155

* [MWB] - cleaning up DragDrop.cs - #35155

* [MWB] - cleaning up DragDrop.cs - #35155
This commit is contained in:
Michael Clayton
2025-02-21 08:31:44 +00:00
committed by GitHub
parent 273a45ff1f
commit 6515374ce9
32 changed files with 1889 additions and 1845 deletions

View File

@@ -431,7 +431,7 @@ namespace MouseWithoutBorders
if (!IsConnectedByAClientSocketTo(remoteMachine)) if (!IsConnectedByAClientSocketTo(remoteMachine))
{ {
Logger.Log($"No potential inbound connection from {MachineName} to {remoteMachine}, ask for a push back instead."); 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) if (machineId != ID.NONE)
{ {
@@ -840,7 +840,7 @@ namespace MouseWithoutBorders
Logger.LogDebug($"{nameof(ShakeHand)}: Connection from {name}:{package.Src}"); 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; clientPushData = package.Type == PackageType.ClipboardPush;
postAction = package.PostAction; postAction = package.PostAction;

View File

@@ -1,409 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Microsoft.PowerToys.Telemetry;
// <summary>
// Drag/Drop implementation.
// </summary>
// <history>
// 2008 created by Truong Do (ductdo).
// 2009-... modified by Truong Do (TruongDo).
// 2023- Included in PowerToys.
// </history>
using MouseWithoutBorders.Class;
using MouseWithoutBorders.Core;
using Thread = MouseWithoutBorders.Core.Thread;
namespace MouseWithoutBorders
{
/* Common.DragDrop.cs
* Drag&Drop is one complicated implementation of the tool with some tricks.
*
* SEQUENCE OF EVENTS:
* DragDropStep01: MachineX: Remember mouse down state since it could be a start of a dragging
* DragDropStep02: MachineY: Send an message to the MachineX to ask it to check if it is
* doing drag/drop
* DragDropStep03: MachineX: Got explorerDragDrop, send WM_CHECK_EXPLORER_DRAG_DROP to its mainForm
* DragDropStep04: MachineX: Show Mouse Without Borders Helper form at mouse cursor to get DragEnter event.
* DragDropStepXX: MachineX: Mouse Without Borders Helper: Called by DragEnter, check if dragging a single file,
* remember the file (set as its window caption)
* DragDropStep05: MachineX: Get the file name from Mouse Without Borders Helper, hide Mouse Without Borders Helper window
* DragDropStep06: MachineX: Broadcast a message saying that it has some drag file.
* DragDropStep08: MachineY: Got ClipboardDragDrop, isDropping set, get the MachineX name from the package.
* DragDropStep09: MachineY: Since isDropping is true, show up the drop form (looks like an icon).
* DragDropStep10: MachineY: MouseUp, set isDropping to false, hide the drop "icon" and get data.
* DragDropStep11: MachineX: Mouse move back without drop event, cancelling drag/dop
* SendClipboardBeatDragDropEnd
* DragDropStep12: MachineY: Hide the drop "icon" when received ClipboardDragDropEnd.
*
* FROM VERSION 1.6.3: Drag/Drop is temporary removed, Drop action cannot be done from a lower integrity app to a higher one.
* We have to run a helper process...
* http://forums.microsoft.com/MSDN/ShowPost.aspx?PageIndex=1&SiteID=1&PageID=1&PostID=736086
*
* 2008.10.28: Trying to restore the Drag/Drop feature by adding the drag/drop helper process. Coming in version
* 1.6.5
* */
internal partial class Common
{
private static bool isDragging;
internal static bool IsDragging
{
get => Common.isDragging;
set => Common.isDragging = value;
}
internal static void DragDropStep01(int wParam)
{
if (!Setting.Values.TransferFile)
{
return;
}
if (wParam == WM_LBUTTONDOWN)
{
MouseDown = true;
DragMachine = desMachineID;
dropMachineID = ID.NONE;
Logger.LogDebug("DragDropStep01: MouseDown");
}
else if (wParam == WM_LBUTTONUP)
{
MouseDown = false;
Logger.LogDebug("DragDropStep01: MouseUp");
}
if (wParam == WM_RBUTTONUP && IsDropping)
{
IsDropping = false;
LastIDWithClipboardData = ID.NONE;
}
}
internal static void DragDropStep02()
{
if (desMachineID == MachineID)
{
Logger.LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent to myself");
DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
else
{
SendCheckExplorerDragDrop();
Logger.LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent");
}
}
internal static void DragDropStep03(DATA package)
{
if (RunOnLogonDesktop || RunOnScrSaverDesktop)
{
return;
}
if (package.Des == MachineID || package.Des == ID.ALL)
{
Logger.LogDebug("DragDropStep03: ExplorerDragDrop Received.");
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...");
DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
}
}
private static int dragDropStep05ExCalledByIpc;
internal static void DragDropStep04()
{
if (!IsDropping)
{
IntPtr h = (IntPtr)NativeMethods.FindWindow(null, Common.HELPER_FORM_TEXT);
if (h.ToInt32() > 0)
{
_ = Interlocked.Exchange(ref dragDropStep05ExCalledByIpc, 0);
MainForm.Hide();
MainFormVisible = false;
Point p = default;
// NativeMethods.SetWindowText(h, "");
_ = NativeMethods.SetWindowPos(h, NativeMethods.HWND_TOPMOST, 0, 0, 0, 0, NativeMethods.SWP_SHOWWINDOW);
for (int i = -10; i < 10; i++)
{
if (dragDropStep05ExCalledByIpc > 0)
{
Logger.LogDebug("DragDropStep04: DragDropStep05ExCalledByIpc.");
break;
}
_ = NativeMethods.GetCursorPos(ref p);
Logger.LogDebug("DragDropStep04: Moving Mouse Without Borders Helper to (" + p.X.ToString(CultureInfo.CurrentCulture) + ", " + p.Y.ToString(CultureInfo.CurrentCulture) + ")");
_ = NativeMethods.SetWindowPos(h, NativeMethods.HWND_TOPMOST, p.X - 100 + i, p.Y - 100 + i, 200, 200, 0);
_ = NativeMethods.SendMessage(h, 0x000F, IntPtr.Zero, IntPtr.Zero); // WM_PAINT
Thread.Sleep(20);
Application.DoEvents();
// if (GetText(h).Length > 1) break;
}
}
else
{
Logger.LogDebug("DragDropStep04: Mouse without Borders Helper not found!");
}
}
else
{
Logger.LogDebug("DragDropStep04: IsDropping == true, skip checking");
}
Logger.LogDebug("DragDropStep04: Got WM_CHECK_EXPLORER_DRAG_DROP, done with processing jump to DragDropStep05...");
}
internal static void DragDropStep05Ex(string dragFileName)
{
Logger.LogDebug("DragDropStep05 called.");
_ = Interlocked.Exchange(ref dragDropStep05ExCalledByIpc, 1);
if (RunOnLogonDesktop || RunOnScrSaverDesktop)
{
return;
}
if (!IsDropping)
{
_ = Common.ImpersonateLoggedOnUserAndDoSomething(() =>
{
if (!string.IsNullOrEmpty(dragFileName) && (File.Exists(dragFileName) || Directory.Exists(dragFileName)))
{
Common.LastDragDropFile = dragFileName;
/*
* possibleDropMachineID is used as desID sent in DragDropStep06();
* */
if (dropMachineID == ID.NONE)
{
dropMachineID = newDesMachineID;
}
DragDropStep06();
Logger.LogDebug("DragDropStep05: File dragging: " + dragFileName);
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_HIDE_DD_HELPER, (IntPtr)1, (IntPtr)0);
}
else
{
Logger.LogDebug("DragDropStep05: File not found: [" + dragFileName + "]");
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_HIDE_DD_HELPER, (IntPtr)0, (IntPtr)0);
}
Logger.LogDebug("DragDropStep05: WM_HIDE_DDHelper sent");
});
}
else
{
Logger.LogDebug("DragDropStep05: IsDropping == true, change drop machine...");
IsDropping = false;
MainFormVisible = true; // WM_HIDE_DRAG_DROP
SendDropBegin(); // To dropMachineID set in DragDropStep03
}
MouseDown = false;
}
internal static void DragDropStep06()
{
IsDragging = true;
Logger.LogDebug("DragDropStep06: SendClipboardBeatDragDrop");
SendClipboardBeatDragDrop();
SendDropBegin();
}
internal static void DragDropStep08(DATA package)
{
Receiver.GetNameOfMachineWithClipboardData(package);
Logger.LogDebug("DragDropStep08: ClipboardDragDrop Received. machine with drag file was set");
}
internal static void DragDropStep08_2(DATA package)
{
if (package.Des == MachineID && !RunOnLogonDesktop && !RunOnScrSaverDesktop)
{
IsDropping = true;
dropMachineID = MachineID;
Logger.LogDebug("DragDropStep08_2: ClipboardDragDropOperation Received. IsDropping set");
}
}
internal static void DragDropStep09(int wParam)
{
if (wParam == WM_MOUSEMOVE && IsDropping)
{
// Show/Move form
DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_SHOW_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
else if (wParam == WM_LBUTTONUP && (IsDropping || IsDragging))
{
if (IsDropping)
{
// Hide form, get data
DragDropStep10();
}
else
{
IsDragging = false;
LastIDWithClipboardData = ID.NONE;
}
}
}
internal static void DragDropStep10()
{
Logger.LogDebug("DragDropStep10: Hide the form and get data...");
IsDropping = false;
IsDragging = false;
LastIDWithClipboardData = ID.NONE;
DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_HIDE_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
PowerToysTelemetry.Log.WriteEvent(new MouseWithoutBorders.Telemetry.MouseWithoutBordersDragAndDropEvent());
GetRemoteClipboard("desktop");
}
internal static void DragDropStep11()
{
Logger.LogDebug("DragDropStep11: Mouse drag coming back, canceling drag/drop");
SendClipboardBeatDragDropEnd();
IsDropping = false;
IsDragging = false;
DragMachine = (ID)1;
LastIDWithClipboardData = ID.NONE;
LastDragDropFile = null;
MouseDown = false;
}
internal static void DragDropStep12()
{
Logger.LogDebug("DragDropStep12: ClipboardDragDropEnd received");
IsDropping = false;
LastIDWithClipboardData = ID.NONE;
DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_HIDE_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
internal static void SendCheckExplorerDragDrop()
{
DATA package = new();
package.Type = PackageType.ExplorerDragDrop;
/*
* package.src = newDesMachineID:
* sent from the master machine but the src must be the
* new des machine since the previous des machine will get this and set
* to possibleDropMachineID in DragDropStep3()
* */
package.Src = newDesMachineID;
package.Des = desMachineID;
package.MachineName = MachineName;
SkSend(package, null, false);
}
private static void ChangeDropMachine()
{
// desMachineID = current drop machine
// newDesMachineID = new drop machine
// 1. Cancelling dropping in current drop machine
if (dropMachineID == MachineID)
{
// Drag/Drop coming through me
IsDropping = false;
}
else
{
// Drag/Drop coming back
SendClipboardBeatDragDropEnd();
}
// 2. SendClipboardBeatDragDrop to new drop machine
// new drop machine is not me
if (newDesMachineID != MachineID)
{
dropMachineID = newDesMachineID;
SendDropBegin();
}
// New drop machine is me
else
{
IsDropping = true;
}
}
internal static void SendClipboardBeatDragDrop()
{
SendPackage(ID.ALL, PackageType.ClipboardDragDrop);
}
internal static void SendDropBegin()
{
Logger.LogDebug("SendDropBegin...");
SendPackage(dropMachineID, PackageType.ClipboardDragDropOperation);
}
internal static void SendClipboardBeatDragDropEnd()
{
if (desMachineID != MachineID)
{
SendPackage(desMachineID, PackageType.ClipboardDragDropEnd);
}
}
private static bool isDropping;
private static ID dragMachine;
internal static ID DragMachine
{
get => Common.dragMachine;
set => Common.dragMachine = value;
}
internal static bool IsDropping
{
get => Common.isDropping;
set => Common.isDropping = value;
}
internal static bool MouseDown { get; set; }
}
}

View File

@@ -72,7 +72,7 @@ namespace MouseWithoutBorders
if (switchByMouseEnabled && Sk != null && (DesMachineID == MachineID || !Setting.Values.MoveMouseRelatively) && e.dwFlags == WM_MOUSEMOVE) 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) if (!p.IsEmpty)
{ {
@@ -81,20 +81,20 @@ namespace MouseWithoutBorders
Logger.LogDebug(string.Format( Logger.LogDebug(string.Format(
CultureInfo.CurrentCulture, CultureInfo.CurrentCulture,
"***** Host Machine: newDesMachineIdEx set = [{0}]. Mouse is now at ({1},{2})", "***** Host Machine: newDesMachineIdEx set = [{0}]. Mouse is now at ({1},{2})",
newDesMachineIdEx, MachineStuff.newDesMachineIdEx,
e.X, e.X,
e.Y)); e.Y));
myLastX = e.X; myLastX = e.X;
myLastY = e.Y; 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.Type = PackageType.Mouse;
MousePackage.Md.dwFlags = e.dwFlags; MousePackage.Md.dwFlags = e.dwFlags;
MousePackage.Md.WheelDelta = e.WheelDelta; MousePackage.Md.WheelDelta = e.WheelDelta;
@@ -107,8 +107,8 @@ namespace MouseWithoutBorders
} }
else else
{ {
MousePackage.Md.X = (e.X - primaryScreenBounds.Left) * 65535 / screenWidth; MousePackage.Md.X = (e.X - MachineStuff.primaryScreenBounds.Left) * 65535 / screenWidth;
MousePackage.Md.Y = (e.Y - primaryScreenBounds.Top) * 65535 / screenHeight; MousePackage.Md.Y = (e.Y - MachineStuff.primaryScreenBounds.Top) * 65535 / screenHeight;
} }
SkSend(MousePackage, null, false); SkSend(MousePackage, null, false);
@@ -156,15 +156,15 @@ namespace MouseWithoutBorders
{ {
Logger.LogDebug($"PrepareToSwitchToMachine: newDesMachineID = {newDesMachineID}, desMachineXY = {desMachineXY}"); 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"); Logger.LogDebug("PrepareToSwitchToMachine: lastJump");
return; return;
} }
lastJump = GetTick(); MachineStuff.lastJump = GetTick();
string newDesMachineName = NameFromID(newDesMachineID); string newDesMachineName = MachineStuff.NameFromID(newDesMachineID);
if (!IsConnectedTo(newDesMachineID)) if (!IsConnectedTo(newDesMachineID))
{// Connection lost, cancel switching {// Connection lost, cancel switching
@@ -174,46 +174,46 @@ namespace MouseWithoutBorders
} }
else else
{ {
Common.newDesMachineID = newDesMachineID; MachineStuff.newDesMachineID = newDesMachineID;
SwitchLocation.X = desMachineXY.X; MachineStuff.SwitchLocation.X = desMachineXY.X;
SwitchLocation.Y = desMachineXY.Y; MachineStuff.SwitchLocation.Y = desMachineXY.Y;
SwitchLocation.ResetCount(); MachineStuff.SwitchLocation.ResetCount();
_ = EvSwitch.Set(); _ = EvSwitch.Set();
// PostMessage(mainForm.Handle, WM_SWITCH, IntPtr.Zero, IntPtr.Zero); // PostMessage(mainForm.Handle, WM_SWITCH, IntPtr.Zero, IntPtr.Zero);
if (newDesMachineID != DragMachine) if (newDesMachineID != DragDrop.DragMachine)
{ {
if (!IsDragging && !IsDropping) if (!DragDrop.IsDragging && !DragDrop.IsDropping)
{ {
if (MouseDown && !RunOnLogonDesktop && !RunOnScrSaverDesktop) if (DragDrop.MouseDown && !RunOnLogonDesktop && !RunOnScrSaverDesktop)
{ {
DragDropStep02(); DragDrop.DragDropStep02();
} }
} }
else if (DragMachine != (ID)1) else if (DragDrop.DragMachine != (ID)1)
{ {
ChangeDropMachine(); DragDrop.ChangeDropMachine();
} }
} }
else else
{ {
DragDropStep11(); DragDrop.DragDropStep11();
} }
// Change des machine // Change des machine
if (desMachineID != newDesMachineID) if (MachineStuff.desMachineID != newDesMachineID)
{ {
Logger.LogDebug("MouseEvent: Switching to new machine:" + newDesMachineName); Logger.LogDebug("MouseEvent: Switching to new machine:" + newDesMachineName);
// Ask current machine to hide the Mouse cursor // 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; DesMachineID = newDesMachineID;
if (desMachineID == MachineID) if (MachineStuff.desMachineID == MachineID)
{ {
if (GetTick() - clipboardCopiedTime < BIG_CLIPBOARD_DATA_TIMEOUT) if (GetTick() - clipboardCopiedTime < BIG_CLIPBOARD_DATA_TIMEOUT)
{ {
@@ -224,7 +224,7 @@ namespace MouseWithoutBorders
else else
{ {
// Ask the new active machine to get clipboard data (if the data is too big) // 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); _ = Interlocked.Increment(ref switchCount);
@@ -249,15 +249,15 @@ namespace MouseWithoutBorders
try try
{ {
PaintCount = 0; PaintCount = 0;
if (desMachineID != newDesMachineID) if (MachineStuff.desMachineID != MachineStuff.newDesMachineID)
{ {
Logger.LogDebug("KeybdEvent: Switching to new machine..."); 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.Type = PackageType.Keyboard;
KeybdPackage.Kd = e; KeybdPackage.Kd = e;
KeybdPackage.DateTime = GetTick(); KeybdPackage.DateTime = GetTick();

View File

@@ -88,35 +88,35 @@ namespace MouseWithoutBorders
break; break;
} }
if (Common.NewDesMachineID != Common.MachineID && Common.NewDesMachineID != ID.ALL) if (MachineStuff.NewDesMachineID != Common.MachineID && MachineStuff.NewDesMachineID != ID.ALL)
{ {
HideMouseCursor(false); HideMouseCursor(false);
Common.MainFormDotEx(true); Common.MainFormDotEx(true);
} }
else 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). // 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. // 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 else
{ {
InputSimulation.MoveMouseEx(Common.SwitchLocation.X, Common.SwitchLocation.Y); InputSimulation.MoveMouseEx(MachineStuff.SwitchLocation.X, MachineStuff.SwitchLocation.Y);
} }
Common.MainFormDot(); Common.MainFormDot();
} }
} }
if (Common.NewDesMachineID == Common.MachineID) if (MachineStuff.NewDesMachineID == Common.MachineID)
{ {
ReleaseAllKeys(); ReleaseAllKeys();
} }
@@ -137,8 +137,8 @@ namespace MouseWithoutBorders
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop) if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
{ {
int left = Common.PrimaryScreenBounds.Left + ((Common.PrimaryScreenBounds.Right - Common.PrimaryScreenBounds.Left) / 2) - 1; int left = MachineStuff.PrimaryScreenBounds.Left + ((MachineStuff.PrimaryScreenBounds.Right - MachineStuff.PrimaryScreenBounds.Left) / 2) - 1;
int top = Setting.Values.HideMouse ? 3 : Common.PrimaryScreenBounds.Top + ((Common.PrimaryScreenBounds.Bottom - Common.PrimaryScreenBounds.Top) / 2); int top = Setting.Values.HideMouse ? 3 : MachineStuff.PrimaryScreenBounds.Top + ((MachineStuff.PrimaryScreenBounds.Bottom - MachineStuff.PrimaryScreenBounds.Top) / 2);
Common.MainFormVisible = true; Common.MainFormVisible = true;
@@ -198,8 +198,8 @@ namespace MouseWithoutBorders
DoSomethingInUIThread( DoSomethingInUIThread(
() => () =>
{ {
MainForm.Left = Common.PrimaryScreenBounds.Left + ((Common.PrimaryScreenBounds.Right - Common.PrimaryScreenBounds.Left) / 2) - 2; MainForm.Left = MachineStuff.PrimaryScreenBounds.Left + ((MachineStuff.PrimaryScreenBounds.Right - MachineStuff.PrimaryScreenBounds.Left) / 2) - 2;
MainForm.Top = Setting.Values.HideMouse ? 3 : Common.PrimaryScreenBounds.Top + ((Common.PrimaryScreenBounds.Bottom - Common.PrimaryScreenBounds.Top) / 2) - 1; MainForm.Top = Setting.Values.HideMouse ? 3 : MachineStuff.PrimaryScreenBounds.Top + ((MachineStuff.PrimaryScreenBounds.Bottom - MachineStuff.PrimaryScreenBounds.Top) / 2) - 1;
MainForm.Width = 3; MainForm.Width = 3;
MainForm.Height = 3; MainForm.Height = 3;
MainForm.Opacity = 0.11D; MainForm.Opacity = 0.11D;
@@ -230,8 +230,8 @@ namespace MouseWithoutBorders
{ {
_ = Common.SendMessageToHelper(0x408, IntPtr.Zero, IntPtr.Zero, false); _ = Common.SendMessageToHelper(0x408, IntPtr.Zero, IntPtr.Zero, false);
MainForm.Left = Common.PrimaryScreenBounds.Left + ((Common.PrimaryScreenBounds.Right - Common.PrimaryScreenBounds.Left) / 2) - 1; MainForm.Left = MachineStuff.PrimaryScreenBounds.Left + ((MachineStuff.PrimaryScreenBounds.Right - MachineStuff.PrimaryScreenBounds.Left) / 2) - 1;
MainForm.Top = Setting.Values.HideMouse ? 3 : Common.PrimaryScreenBounds.Top + ((Common.PrimaryScreenBounds.Bottom - Common.PrimaryScreenBounds.Top) / 2); MainForm.Top = Setting.Values.HideMouse ? 3 : MachineStuff.PrimaryScreenBounds.Top + ((MachineStuff.PrimaryScreenBounds.Bottom - MachineStuff.PrimaryScreenBounds.Top) / 2);
MainForm.Width = 1; MainForm.Width = 1;
MainForm.Height = 1; MainForm.Height = 1;
MainForm.Opacity = 0.15; MainForm.Opacity = 0.15;
@@ -381,7 +381,7 @@ namespace MouseWithoutBorders
log += $"{Setting.Values.Username}/{GetDebugInfo(MyKey)}\r\n"; log += $"{Setting.Values.Username}/{GetDebugInfo(MyKey)}\r\n";
log += $"{MachineName}/{MachineID}/{DesMachineID}\r\n"; log += $"{MachineName}/{MachineID}/{DesMachineID}\r\n";
log += $"Id: {Setting.Values.DeviceId}\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 += $"McPool: {Setting.Values.MachinePoolString}\r\n";
log += "\r\nOPTIONS:\r\n"; log += "\r\nOPTIONS:\r\n";

View File

@@ -46,7 +46,7 @@ namespace MouseWithoutBorders
internal static void UpdateMachineTimeAndID() internal static void UpdateMachineTimeAndID()
{ {
Common.MachineName = Common.MachineName.Trim(); Common.MachineName = Common.MachineName.Trim();
_ = Common.MachinePool.TryUpdateMachineID(Common.MachineName, Common.MachineID, true); _ = MachineStuff.MachinePool.TryUpdateMachineID(Common.MachineName, Common.MachineID, true);
} }
private static void InitializeMachinePoolFromSettings() private static void InitializeMachinePoolFromSettings()
@@ -59,13 +59,13 @@ namespace MouseWithoutBorders
info[i].Name = info[i].Name.Trim(); info[i].Name = info[i].Name.Trim();
} }
Common.MachinePool.Initialize(info); MachineStuff.MachinePool.Initialize(info);
Common.MachinePool.ResetIPAddressesForDeadMachines(true); MachineStuff.MachinePool.ResetIPAddressesForDeadMachines(true);
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log(ex); Logger.Log(ex);
Common.MachinePool.Clear(); MachineStuff.MachinePool.Clear();
} }
} }
@@ -74,16 +74,16 @@ namespace MouseWithoutBorders
try try
{ {
GetMachineName(); GetMachineName();
DesMachineID = NewDesMachineID = MachineID; DesMachineID = MachineStuff.NewDesMachineID = MachineID;
// MessageBox.Show(machineID.ToString(CultureInfo.CurrentCulture)); // For test // MessageBox.Show(machineID.ToString(CultureInfo.CurrentCulture)); // For test
InitializeMachinePoolFromSettings(); InitializeMachinePoolFromSettings();
Common.MachineName = Common.MachineName.Trim(); Common.MachineName = Common.MachineName.Trim();
_ = Common.MachinePool.LearnMachine(Common.MachineName); _ = MachineStuff.MachinePool.LearnMachine(Common.MachineName);
_ = Common.MachinePool.TryUpdateMachineID(Common.MachineName, Common.MachineID, true); _ = MachineStuff.MachinePool.TryUpdateMachineID(Common.MachineName, Common.MachineID, true);
Common.UpdateMachinePoolStringSetting(); MachineStuff.UpdateMachinePoolStringSetting();
} }
catch (Exception e) catch (Exception e)
{ {
@@ -154,7 +154,7 @@ namespace MouseWithoutBorders
{ {
Logger.TelemetryLogTrace($"{nameof(SystemEvents_PowerModeChanged)}: {e.Mode}", SeverityLevel.Information); Logger.TelemetryLogTrace($"{nameof(SystemEvents_PowerModeChanged)}: {e.Mode}", SeverityLevel.Information);
LastResumeSuspendTime = DateTime.UtcNow; LastResumeSuspendTime = DateTime.UtcNow;
SwitchToMultipleMode(false, true); MachineStuff.SwitchToMultipleMode(false, true);
} }
} }

View File

@@ -41,7 +41,7 @@ namespace MouseWithoutBorders
GetScreenConfig(); GetScreenConfig();
} }
private static readonly List<Point> SensitivePoints = new(); internal static readonly List<Point> SensitivePoints = new();
private static bool MonitorEnumProc(IntPtr hMonitor, IntPtr hdcMonitor, ref NativeMethods.RECT lprcMonitor, IntPtr dwData) private static bool MonitorEnumProc(IntPtr hMonitor, IntPtr hdcMonitor, ref NativeMethods.RECT lprcMonitor, IntPtr dwData)
{ {
@@ -162,21 +162,21 @@ namespace MouseWithoutBorders
// 1000 calls to EnumDisplayMonitors cost a dozen of milliseconds // 1000 calls to EnumDisplayMonitors cost a dozen of milliseconds
#endif #endif
Interlocked.Exchange(ref desktopBounds, newDesktopBounds); Interlocked.Exchange(ref MachineStuff.desktopBounds, newDesktopBounds);
Interlocked.Exchange(ref primaryScreenBounds, newPrimaryScreenBounds); Interlocked.Exchange(ref MachineStuff.primaryScreenBounds, newPrimaryScreenBounds);
Logger.Log(string.Format( Logger.Log(string.Format(
CultureInfo.CurrentCulture, CultureInfo.CurrentCulture,
"logon = {0} PrimaryScreenBounds = {1},{2},{3},{4} desktopBounds = {5},{6},{7},{8}", "logon = {0} PrimaryScreenBounds = {1},{2},{3},{4} desktopBounds = {5},{6},{7},{8}",
Common.RunOnLogonDesktop, Common.RunOnLogonDesktop,
Common.PrimaryScreenBounds.Left, MachineStuff.PrimaryScreenBounds.Left,
Common.PrimaryScreenBounds.Top, MachineStuff.PrimaryScreenBounds.Top,
Common.PrimaryScreenBounds.Right, MachineStuff.PrimaryScreenBounds.Right,
Common.PrimaryScreenBounds.Bottom, MachineStuff.PrimaryScreenBounds.Bottom,
Common.DesktopBounds.Left, MachineStuff.DesktopBounds.Left,
Common.DesktopBounds.Top, MachineStuff.DesktopBounds.Top,
Common.DesktopBounds.Right, MachineStuff.DesktopBounds.Right,
Common.DesktopBounds.Bottom)); MachineStuff.DesktopBounds.Bottom));
Logger.Log("==================== GetScreenConfig ended"); Logger.Log("==================== GetScreenConfig ended");
} }

View File

@@ -112,7 +112,7 @@ namespace MouseWithoutBorders
internal const int JUST_GOT_BACK_FROM_SCREEN_SAVER = 9999; internal const int JUST_GOT_BACK_FROM_SCREEN_SAVER = 9999;
internal const int NETWORK_STREAM_BUF_SIZE = 1024 * 1024; internal const int NETWORK_STREAM_BUF_SIZE = 1024 * 1024;
private static readonly EventWaitHandle EvSwitch = new(false, EventResetMode.AutoReset); internal static readonly EventWaitHandle EvSwitch = new(false, EventResetMode.AutoReset);
private static Point lastPos; private static Point lastPos;
private static int switchCount; private static int switchCount;
private static long lastReconnectByHotKeyTime; private static long lastReconnectByHotKeyTime;
@@ -236,12 +236,12 @@ namespace MouseWithoutBorders
internal static ID DesMachineID internal static ID DesMachineID
{ {
get => Common.desMachineID; get => MachineStuff.desMachineID;
set set
{ {
Common.desMachineID = value; MachineStuff.desMachineID = value;
Common.DesMachineName = Common.NameFromID(Common.desMachineID); MachineStuff.DesMachineName = MachineStuff.NameFromID(MachineStuff.desMachineID);
} }
} }
@@ -351,7 +351,7 @@ namespace MouseWithoutBorders
Logger.TelemetryLogTrace($"[{actionName}] took more than {(long)timeout.TotalSeconds}, restarting the process.", SeverityLevel.Warning, true); Logger.TelemetryLogTrace($"[{actionName}] took more than {(long)timeout.TotalSeconds}, restarting the process.", SeverityLevel.Warning, true);
string desktop = Common.GetMyDesktop(); string desktop = Common.GetMyDesktop();
oneInstanceCheck?.Close(); MachineStuff.oneInstanceCheck?.Close();
_ = Process.Start(Application.ExecutablePath, desktop); _ = Process.Start(Application.ExecutablePath, desktop);
Logger.LogDebug($"Started on desktop {desktop}"); Logger.LogDebug($"Started on desktop {desktop}");
@@ -619,12 +619,12 @@ namespace MouseWithoutBorders
internal static void ProcessByeByeMessage(DATA package) internal static void ProcessByeByeMessage(DATA package)
{ {
if (package.Src == desMachineID) if (package.Src == MachineStuff.desMachineID)
{ {
SwitchToMachine(MachineName.Trim()); MachineStuff.SwitchToMachine(MachineName.Trim());
} }
_ = RemoveDeadMachines(package.Src); _ = MachineStuff.RemoveDeadMachines(package.Src);
} }
internal static long GetTick() // ms internal static long GetTick() // ms
@@ -644,12 +644,12 @@ namespace MouseWithoutBorders
try try
{ {
string fileName = GetMyStorageDir() + @"ScreenCaptureByMouseWithoutBorders.png"; string fileName = GetMyStorageDir() + @"ScreenCaptureByMouseWithoutBorders.png";
int w = desktopBounds.Right - desktopBounds.Left; int w = MachineStuff.desktopBounds.Right - MachineStuff.desktopBounds.Left;
int h = desktopBounds.Bottom - desktopBounds.Top; int h = MachineStuff.desktopBounds.Bottom - MachineStuff.desktopBounds.Top;
Bitmap bm = new(w, h); Bitmap bm = new(w, h);
Graphics g = Graphics.FromImage(bm); Graphics g = Graphics.FromImage(bm);
Size s = new(w, h); Size s = new(w, h);
g.CopyFromScreen(desktopBounds.Left, desktopBounds.Top, 0, 0, s); g.CopyFromScreen(MachineStuff.desktopBounds.Left, MachineStuff.desktopBounds.Top, 0, 0, s);
bm.Save(fileName, ImageFormat.Png); bm.Save(fileName, ImageFormat.Png);
bm.Dispose(); bm.Dispose();
return fileName; return fileName;
@@ -665,7 +665,7 @@ namespace MouseWithoutBorders
{ {
Common.DoSomethingInUIThread(() => Common.DoSomethingInUIThread(() =>
{ {
if (!MouseDown && Common.SendMessageToHelper(0x401, IntPtr.Zero, IntPtr.Zero) > 0) if (!DragDrop.MouseDown && Common.SendMessageToHelper(0x401, IntPtr.Zero, IntPtr.Zero) > 0)
{ {
Common.MMSleep(0.2); Common.MMSleep(0.2);
InputSimulation.SendKey(new KEYBDDATA() { wVk = (int)VK.SNAPSHOT }); InputSimulation.SendKey(new KEYBDDATA() { wVk = (int)VK.SNAPSHOT });
@@ -675,10 +675,10 @@ namespace MouseWithoutBorders
_ = NativeMethods.MoveWindow( _ = NativeMethods.MoveWindow(
(IntPtr)NativeMethods.FindWindow(null, Common.HELPER_FORM_TEXT), (IntPtr)NativeMethods.FindWindow(null, Common.HELPER_FORM_TEXT),
Common.DesktopBounds.Left, MachineStuff.DesktopBounds.Left,
Common.DesktopBounds.Top, MachineStuff.DesktopBounds.Top,
Common.DesktopBounds.Right - Common.DesktopBounds.Left, MachineStuff.DesktopBounds.Right - MachineStuff.DesktopBounds.Left,
Common.DesktopBounds.Bottom - Common.DesktopBounds.Top, MachineStuff.DesktopBounds.Bottom - MachineStuff.DesktopBounds.Top,
false); false);
_ = Common.SendMessageToHelper(0x406, IntPtr.Zero, IntPtr.Zero, false); _ = Common.SendMessageToHelper(0x406, IntPtr.Zero, IntPtr.Zero, false);
@@ -729,7 +729,7 @@ namespace MouseWithoutBorders
} }
else else
{ {
ID id = Common.MachinePool.ResolveID(machine); ID id = MachineStuff.MachinePool.ResolveID(machine);
if (id != ID.NONE) if (id != ID.NONE)
{ {
SendPackage(id, PackageType.ClipboardCapture); SendPackage(id, PackageType.ClipboardCapture);
@@ -753,7 +753,7 @@ namespace MouseWithoutBorders
{ {
if (Setting.Values.FirstRun) if (Setting.Values.FirstRun)
{ {
Common.Settings?.ShowTip(icon, tip, timeOutInMilliseconds); MachineStuff.Settings?.ShowTip(icon, tip, timeOutInMilliseconds);
} }
Common.MatrixForm?.ShowTip(icon, tip, timeOutInMilliseconds); Common.MatrixForm?.ShowTip(icon, tip, timeOutInMilliseconds);
@@ -882,7 +882,7 @@ namespace MouseWithoutBorders
if (updateClientSockets) if (updateClientSockets)
{ {
UpdateClientSockets(nameof(IsConnectedTo)); MachineStuff.UpdateClientSockets(nameof(IsConnectedTo));
} }
return false; return false;
@@ -921,7 +921,7 @@ namespace MouseWithoutBorders
{ {
if (t != null && t.BackingSocket != null && (t.Status == SocketStatus.Connected || (t.Status == SocketStatus.Handshaking && includeHandShakingSockets))) if (t != null && t.BackingSocket != null && (t.Status == SocketStatus.Connected || (t.Status == SocketStatus.Handshaking && includeHandShakingSockets)))
{ {
if (t.MachineId == (uint)data.Des || (data.Des == ID.ALL && t.MachineId != exceptDes && InMachineMatrix(t.MachineName))) if (t.MachineId == (uint)data.Des || (data.Des == ID.ALL && t.MachineId != exceptDes && MachineStuff.InMachineMatrix(t.MachineName)))
{ {
try try
{ {
@@ -952,20 +952,20 @@ namespace MouseWithoutBorders
{ {
Logger.LogDebug("********** No active connection found for the remote machine! **********" + data.Des.ToString()); Logger.LogDebug("********** No active connection found for the remote machine! **********" + data.Des.ToString());
if (data.Des == ID.NONE || RemoveDeadMachines(data.Des)) if (data.Des == ID.NONE || MachineStuff.RemoveDeadMachines(data.Des))
{ {
// SwitchToMachine(MachineName.Trim()); // SwitchToMachine(MachineName.Trim());
NewDesMachineID = DesMachineID = MachineID; MachineStuff.NewDesMachineID = DesMachineID = MachineID;
SwitchLocation.X = XY_BY_PIXEL + myLastX; MachineStuff.SwitchLocation.X = XY_BY_PIXEL + myLastX;
SwitchLocation.Y = XY_BY_PIXEL + myLastY; MachineStuff.SwitchLocation.Y = XY_BY_PIXEL + myLastY;
SwitchLocation.ResetCount(); MachineStuff.SwitchLocation.ResetCount();
EvSwitch.Set(); EvSwitch.Set();
} }
} }
if (updateClientSockets) if (updateClientSockets)
{ {
UpdateClientSockets("SkSend"); MachineStuff.UpdateClientSockets("SkSend");
} }
} }
catch (Exception e) catch (Exception e)
@@ -1203,7 +1203,7 @@ namespace MouseWithoutBorders
{ {
int machineCt = 0; int machineCt = 0;
foreach (string m in Common.MachineMatrix) foreach (string m in MachineStuff.MachineMatrix)
{ {
if (!string.IsNullOrEmpty(m.Trim())) if (!string.IsNullOrEmpty(m.Trim()))
{ {
@@ -1211,15 +1211,15 @@ namespace MouseWithoutBorders
} }
} }
if (machineCt < 2 && Common.Settings != null && (Common.Settings.GetCurrentPage() is SetupPage1 || Common.Settings.GetCurrentPage() is SetupPage2b)) if (machineCt < 2 && MachineStuff.Settings != null && (MachineStuff.Settings.GetCurrentPage() is SetupPage1 || MachineStuff.Settings.GetCurrentPage() is SetupPage2b))
{ {
Common.MachineMatrix = new string[Common.MAX_MACHINE] { Common.MachineName.Trim(), desMachine, string.Empty, string.Empty }; MachineStuff.MachineMatrix = new string[MachineStuff.MAX_MACHINE] { Common.MachineName.Trim(), desMachine, string.Empty, string.Empty };
Logger.LogDebug("UpdateSetupMachineMatrix: " + string.Join(",", Common.MachineMatrix)); Logger.LogDebug("UpdateSetupMachineMatrix: " + string.Join(",", MachineStuff.MachineMatrix));
Common.DoSomethingInUIThread( Common.DoSomethingInUIThread(
() => () =>
{ {
Common.Settings.SetControlPage(new SetupPage4()); MachineStuff.Settings.SetControlPage(new SetupPage4());
}, },
true); true);
} }
@@ -1255,7 +1255,7 @@ namespace MouseWithoutBorders
SocketStuff.ClearBadIPs(); SocketStuff.ClearBadIPs();
} }
UpdateClientSockets("ReopenSockets"); MachineStuff.UpdateClientSockets("ReopenSockets");
} }
}, },
true); true);
@@ -1473,17 +1473,17 @@ namespace MouseWithoutBorders
{ {
Logger.LogDebug("+++++ MoveMouseToCenter"); Logger.LogDebug("+++++ MoveMouseToCenter");
InputSimulation.MoveMouse( InputSimulation.MoveMouse(
Common.PrimaryScreenBounds.Left + ((Common.PrimaryScreenBounds.Right - Common.PrimaryScreenBounds.Left) / 2), MachineStuff.PrimaryScreenBounds.Left + ((MachineStuff.PrimaryScreenBounds.Right - MachineStuff.PrimaryScreenBounds.Left) / 2),
Common.PrimaryScreenBounds.Top + ((Common.PrimaryScreenBounds.Bottom - Common.PrimaryScreenBounds.Top) / 2)); MachineStuff.PrimaryScreenBounds.Top + ((MachineStuff.PrimaryScreenBounds.Bottom - MachineStuff.PrimaryScreenBounds.Top) / 2));
} }
internal static void HideMouseCursor(bool byHideMouseMessage) internal static void HideMouseCursor(bool byHideMouseMessage)
{ {
Common.LastPos = new Point( Common.LastPos = new Point(
Common.PrimaryScreenBounds.Left + ((Common.PrimaryScreenBounds.Right - Common.PrimaryScreenBounds.Left) / 2), MachineStuff.PrimaryScreenBounds.Left + ((MachineStuff.PrimaryScreenBounds.Right - MachineStuff.PrimaryScreenBounds.Left) / 2),
Setting.Values.HideMouse ? 4 : Common.PrimaryScreenBounds.Top + ((Common.PrimaryScreenBounds.Bottom - Common.PrimaryScreenBounds.Top) / 2)); Setting.Values.HideMouse ? 4 : MachineStuff.PrimaryScreenBounds.Top + ((MachineStuff.PrimaryScreenBounds.Bottom - MachineStuff.PrimaryScreenBounds.Top) / 2));
if ((desMachineID != MachineID && desMachineID != ID.ALL) || byHideMouseMessage) if ((MachineStuff.desMachineID != MachineID && MachineStuff.desMachineID != ID.ALL) || byHideMouseMessage)
{ {
_ = NativeMethods.SetCursorPos(Common.LastPos.X, Common.LastPos.Y); _ = NativeMethods.SetCursorPos(Common.LastPos.X, Common.LastPos.Y);
_ = NativeMethods.GetCursorPos(ref Common.lastPos); _ = NativeMethods.GetCursorPos(ref Common.lastPos);

View File

@@ -154,7 +154,7 @@ namespace MouseWithoutBorders
public void SendDragFile(string fileName) public void SendDragFile(string fileName)
{ {
Common.DragDropStep05Ex(fileName); DragDrop.DragDropStep05Ex(fileName);
} }
public void SendClipboardData(ByteArrayOrString data, bool isFilePath) public void SendClipboardData(ByteArrayOrString data, bool isFilePath)

View File

@@ -222,10 +222,10 @@ namespace MouseWithoutBorders.Class
{ {
Common.RealInputEventCount++; Common.RealInputEventCount++;
if (Common.NewDesMachineID == Common.MachineID || Common.NewDesMachineID == ID.ALL) if (MachineStuff.NewDesMachineID == Common.MachineID || MachineStuff.NewDesMachineID == ID.ALL)
{ {
local = true; local = true;
if (Common.MainFormVisible && !Common.IsDropping) if (Common.MainFormVisible && !DragDrop.IsDropping)
{ {
Common.MainFormDot(); Common.MainFormDot();
} }
@@ -265,19 +265,19 @@ namespace MouseWithoutBorders.Class
} }
else else
{ {
if (Common.SwitchLocation.Count > 0 && Common.NewDesMachineID != Common.MachineID && Common.NewDesMachineID != ID.ALL) if (MachineStuff.SwitchLocation.Count > 0 && MachineStuff.NewDesMachineID != Common.MachineID && MachineStuff.NewDesMachineID != ID.ALL)
{ {
Common.SwitchLocation.Count--; MachineStuff.SwitchLocation.Count--;
if (Common.SwitchLocation.X > Common.XY_BY_PIXEL - 100000 || Common.SwitchLocation.Y > Common.XY_BY_PIXEL - 100000) if (MachineStuff.SwitchLocation.X > Common.XY_BY_PIXEL - 100000 || MachineStuff.SwitchLocation.Y > Common.XY_BY_PIXEL - 100000)
{ {
hookCallbackMouseData.X = Common.SwitchLocation.X - Common.XY_BY_PIXEL; hookCallbackMouseData.X = MachineStuff.SwitchLocation.X - Common.XY_BY_PIXEL;
hookCallbackMouseData.Y = Common.SwitchLocation.Y - Common.XY_BY_PIXEL; hookCallbackMouseData.Y = MachineStuff.SwitchLocation.Y - Common.XY_BY_PIXEL;
} }
else else
{ {
hookCallbackMouseData.X = (Common.SwitchLocation.X * Common.ScreenWidth / 65535) + Common.PrimaryScreenBounds.Left; hookCallbackMouseData.X = (MachineStuff.SwitchLocation.X * Common.ScreenWidth / 65535) + MachineStuff.PrimaryScreenBounds.Left;
hookCallbackMouseData.Y = (Common.SwitchLocation.Y * Common.ScreenHeight / 65535) + Common.PrimaryScreenBounds.Top; hookCallbackMouseData.Y = (MachineStuff.SwitchLocation.Y * Common.ScreenHeight / 65535) + MachineStuff.PrimaryScreenBounds.Top;
} }
Common.HideMouseCursor(false); Common.HideMouseCursor(false);
@@ -290,22 +290,22 @@ namespace MouseWithoutBorders.Class
hookCallbackMouseData.X += dx; hookCallbackMouseData.X += dx;
hookCallbackMouseData.Y += dy; hookCallbackMouseData.Y += dy;
if (hookCallbackMouseData.X < Common.PrimaryScreenBounds.Left) if (hookCallbackMouseData.X < MachineStuff.PrimaryScreenBounds.Left)
{ {
hookCallbackMouseData.X = Common.PrimaryScreenBounds.Left - 1; hookCallbackMouseData.X = MachineStuff.PrimaryScreenBounds.Left - 1;
} }
else if (hookCallbackMouseData.X > Common.PrimaryScreenBounds.Right) else if (hookCallbackMouseData.X > MachineStuff.PrimaryScreenBounds.Right)
{ {
hookCallbackMouseData.X = Common.PrimaryScreenBounds.Right + 1; hookCallbackMouseData.X = MachineStuff.PrimaryScreenBounds.Right + 1;
} }
if (hookCallbackMouseData.Y < Common.PrimaryScreenBounds.Top) if (hookCallbackMouseData.Y < MachineStuff.PrimaryScreenBounds.Top)
{ {
hookCallbackMouseData.Y = Common.PrimaryScreenBounds.Top - 1; hookCallbackMouseData.Y = MachineStuff.PrimaryScreenBounds.Top - 1;
} }
else if (hookCallbackMouseData.Y > Common.PrimaryScreenBounds.Bottom) else if (hookCallbackMouseData.Y > MachineStuff.PrimaryScreenBounds.Bottom)
{ {
hookCallbackMouseData.Y = Common.PrimaryScreenBounds.Bottom + 1; hookCallbackMouseData.Y = MachineStuff.PrimaryScreenBounds.Bottom + 1;
} }
dx += dx < 0 ? -Common.MOVE_MOUSE_RELATIVE : Common.MOVE_MOUSE_RELATIVE; dx += dx < 0 ? -Common.MOVE_MOUSE_RELATIVE : Common.MOVE_MOUSE_RELATIVE;
@@ -315,8 +315,8 @@ namespace MouseWithoutBorders.Class
MouseEvent(hookCallbackMouseData, dx, dy); MouseEvent(hookCallbackMouseData, dx, dy);
Common.DragDropStep01(wParam); DragDrop.DragDropStep01(wParam);
Common.DragDropStep09(wParam); DragDrop.DragDropStep09(wParam);
} }
if (local) if (local)
@@ -432,7 +432,7 @@ namespace MouseWithoutBorders.Class
if (Common.DesMachineID != ID.ALL) if (Common.DesMachineID != ID.ALL)
{ {
Common.SwitchToMachine(Common.MachineName.Trim()); MachineStuff.SwitchToMachine(Common.MachineName.Trim());
} }
/* /*
@@ -518,7 +518,7 @@ namespace MouseWithoutBorders.Class
if (Common.HotkeyMatched(vkCode, winDown, CtrlDown, altDown, shiftDown, Setting.Values.HotKeySwitch2AllPC)) if (Common.HotkeyMatched(vkCode, winDown, CtrlDown, altDown, shiftDown, Setting.Values.HotKeySwitch2AllPC))
{ {
ResetLastSwitchKeys(); ResetLastSwitchKeys();
Common.SwitchToMultipleMode(Common.DesMachineID != ID.ALL, true); MachineStuff.SwitchToMultipleMode(Common.DesMachineID != ID.ALL, true);
} }
if (Common.HotkeyMatched(vkCode, winDown, CtrlDown, altDown, shiftDown, Setting.Values.HotKeyToggleEasyMouse)) if (Common.HotkeyMatched(vkCode, winDown, CtrlDown, altDown, shiftDown, Setting.Values.HotKeyToggleEasyMouse))
@@ -543,7 +543,7 @@ namespace MouseWithoutBorders.Class
{ {
if (Common.GetTick() - lastHotKeyLockMachine < 500) if (Common.GetTick() - lastHotKeyLockMachine < 500)
{ {
Common.SwitchToMultipleMode(true, true); MachineStuff.SwitchToMultipleMode(true, true);
var codes = GetVkCodesList(Setting.Values.HotKeyLockMachine); var codes = GetVkCodesList(Setting.Values.HotKeyLockMachine);
@@ -561,7 +561,7 @@ namespace MouseWithoutBorders.Class
KeyboardEvent(hookCallbackKeybdData); KeyboardEvent(hookCallbackKeybdData);
} }
Common.SwitchToMultipleMode(false, true); MachineStuff.SwitchToMultipleMode(false, true);
_ = NativeMethods.LockWorkStation(); _ = NativeMethods.LockWorkStation();
} }
@@ -625,9 +625,9 @@ namespace MouseWithoutBorders.Class
private static bool Switch2(int index) private static bool Switch2(int index)
{ {
if (Common.MachineMatrix != null && Common.MachineMatrix.Length > index) if (MachineStuff.MachineMatrix != null && MachineStuff.MachineMatrix.Length > index)
{ {
string mcName = Common.MachineMatrix[index].Trim(); string mcName = MachineStuff.MachineMatrix[index].Trim();
if (!string.IsNullOrEmpty(mcName)) if (!string.IsNullOrEmpty(mcName))
{ {
// Common.DoSomethingInUIThread(delegate() // Common.DoSomethingInUIThread(delegate()
@@ -636,7 +636,7 @@ namespace MouseWithoutBorders.Class
} }
// ); // );
Common.SwitchToMachine(mcName); MachineStuff.SwitchToMachine(mcName);
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop) if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
{ {

View File

@@ -162,10 +162,10 @@ namespace MouseWithoutBorders.Class
uint rv = 0; uint rv = 0;
NativeMethods.INPUT mouse_input = default; NativeMethods.INPUT mouse_input = default;
long w65535 = (Common.DesktopBounds.Right - Common.DesktopBounds.Left) * 65535 / Common.ScreenWidth; long w65535 = (MachineStuff.DesktopBounds.Right - MachineStuff.DesktopBounds.Left) * 65535 / Common.ScreenWidth;
long h65535 = (Common.DesktopBounds.Bottom - Common.DesktopBounds.Top) * 65535 / Common.ScreenHeight; long h65535 = (MachineStuff.DesktopBounds.Bottom - MachineStuff.DesktopBounds.Top) * 65535 / Common.ScreenHeight;
long l65535 = Common.DesktopBounds.Left * 65535 / Common.ScreenWidth; long l65535 = MachineStuff.DesktopBounds.Left * 65535 / Common.ScreenWidth;
long t65535 = Common.DesktopBounds.Top * 65535 / Common.ScreenHeight; long t65535 = MachineStuff.DesktopBounds.Top * 65535 / Common.ScreenHeight;
mouse_input.type = 0; mouse_input.type = 0;
long dx = (md.X * w65535 / 65535) + l65535; long dx = (md.X * w65535 / 65535) + l65535;
long dy = (md.Y * h65535 / 65535) + t65535; long dy = (md.Y * h65535 / 65535) + t65535;
@@ -221,7 +221,7 @@ namespace MouseWithoutBorders.Class
rv = SendInputEx(mouse_input); rv = SendInputEx(mouse_input);
}); });
if (Common.MainFormVisible && !Common.IsDropping) if (Common.MainFormVisible && !DragDrop.IsDropping)
{ {
Common.MainFormDot(); Common.MainFormDot();
} }
@@ -233,10 +233,10 @@ namespace MouseWithoutBorders.Class
{ {
NativeMethods.INPUT mouse_input = default; NativeMethods.INPUT mouse_input = default;
long w65535 = (Common.DesktopBounds.Right - Common.DesktopBounds.Left) * 65535 / Common.ScreenWidth; long w65535 = (MachineStuff.DesktopBounds.Right - MachineStuff.DesktopBounds.Left) * 65535 / Common.ScreenWidth;
long h65535 = (Common.DesktopBounds.Bottom - Common.DesktopBounds.Top) * 65535 / Common.ScreenHeight; long h65535 = (MachineStuff.DesktopBounds.Bottom - MachineStuff.DesktopBounds.Top) * 65535 / Common.ScreenHeight;
long l65535 = Common.DesktopBounds.Left * 65535 / Common.ScreenWidth; long l65535 = MachineStuff.DesktopBounds.Left * 65535 / Common.ScreenWidth;
long t65535 = Common.DesktopBounds.Top * 65535 / Common.ScreenHeight; long t65535 = MachineStuff.DesktopBounds.Top * 65535 / Common.ScreenHeight;
mouse_input.type = 0; mouse_input.type = 0;
long dx = (x * w65535 / 65535) + l65535; long dx = (x * w65535 / 65535) + l65535;
long dy = (y * h65535 / 65535) + t65535; long dy = (y * h65535 / 65535) + t65535;

View File

@@ -12,6 +12,8 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using MouseWithoutBorders.Core;
namespace MouseWithoutBorders.Class namespace MouseWithoutBorders.Class
{ {
/// <summary> /// <summary>
@@ -113,10 +115,10 @@ namespace MouseWithoutBorders.Class
{ {
Name = list[i].Name, Name = list[i].Name,
Id = list[i].Id, Id = list[i].Id,
Time = list[i].Time > Common.GetTick() - Common.HEARTBEAT_TIMEOUT + 10000 ? Common.GetTick() - Common.HEARTBEAT_TIMEOUT + 10000 : list[i].Time, Time = list[i].Time > Common.GetTick() - MachineStuff.HEARTBEAT_TIMEOUT + 10000 ? Common.GetTick() - MachineStuff.HEARTBEAT_TIMEOUT + 10000 : list[i].Time,
}; };
foundAndTimedOut = list[i].Time < Common.GetTick() - Common.HEARTBEAT_TIMEOUT + 10000 - 5000; foundAndTimedOut = list[i].Time < Common.GetTick() - MachineStuff.HEARTBEAT_TIMEOUT + 10000 - 5000;
} }
} }
@@ -157,7 +159,7 @@ namespace MouseWithoutBorders.Class
} }
else if (list.Count >= 4) else if (list.Count >= 4)
{ {
throw new ArgumentException($"The number of machines exceeded the maximum allowed limit of {Common.MAX_MACHINE}. Actual count: {list.Count}."); throw new ArgumentException($"The number of machines exceeded the maximum allowed limit of {MachineStuff.MAX_MACHINE}. Actual count: {list.Count}.");
} }
_ = LearnMachine(name); _ = LearnMachine(name);
@@ -179,7 +181,7 @@ namespace MouseWithoutBorders.Class
} }
else if (list.Count >= 4) else if (list.Count >= 4)
{ {
throw new ArgumentException($"The number of machines exceeded the maximum allowed limit of {Common.MAX_MACHINE}. Actual count: {list.Count}."); throw new ArgumentException($"The number of machines exceeded the maximum allowed limit of {MachineStuff.MAX_MACHINE}. Actual count: {list.Count}.");
} }
_ = LearnMachine(inf.Name); _ = LearnMachine(inf.Name);
@@ -212,13 +214,13 @@ namespace MouseWithoutBorders.Class
} }
} }
if (list.Count >= Common.MAX_MACHINE) if (list.Count >= MachineStuff.MAX_MACHINE)
{ {
int slotFound = -1; int slotFound = -1;
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
{ {
if (!Common.InMachineMatrix(list[i].Name)) if (!MachineStuff.InMachineMatrix(list[i].Name))
{ {
slotFound = i; slotFound = i;
break; break;
@@ -289,7 +291,7 @@ namespace MouseWithoutBorders.Class
List<MachineInf> machinePool = ListAllMachines(); List<MachineInf> machinePool = ListAllMachines();
string rv = string.Join(",", machinePool.Select(m => $"{m.Name}:{m.Id}")); string rv = string.Join(",", machinePool.Select(m => $"{m.Name}:{m.Id}"));
for (int j = machinePool.Count; j < Common.MAX_MACHINE; j++) for (int j = machinePool.Count; j < MachineStuff.MAX_MACHINE; j++)
{ {
rv += ",:"; rv += ",:";
} }
@@ -301,7 +303,7 @@ namespace MouseWithoutBorders.Class
/// <param name="clockSkewInMS_forTesting">When doing unit tests it's nice to be able to fudge with the clock time, adding milliseconds, instead of sleeping.</param> /// <param name="clockSkewInMS_forTesting">When doing unit tests it's nice to be able to fudge with the clock time, adding milliseconds, instead of sleeping.</param>
internal static bool IsAlive(MachineInf inf, int clockSkewInMS_forTesting = 0) internal static bool IsAlive(MachineInf inf, int clockSkewInMS_forTesting = 0)
{ {
return inf.Id != ID.NONE && (Common.GetTick() + clockSkewInMS_forTesting - inf.Time <= Common.HEARTBEAT_TIMEOUT || Common.IsConnectedTo(inf.Id)); return inf.Id != ID.NONE && (Common.GetTick() + clockSkewInMS_forTesting - inf.Time <= MachineStuff.HEARTBEAT_TIMEOUT || Common.IsConnectedTo(inf.Id));
} }
private static bool NamesAreEqual(string name1, string name2) private static bool NamesAreEqual(string name1, string name2)
@@ -326,7 +328,7 @@ namespace MouseWithoutBorders.Class
continue; continue;
} }
if ((firstLoaded && !Common.InMachineMatrix(list[i].Name)) || (!firstLoaded && (!Common.InMachineMatrix(list[i].Name) || !IsAlive(list[i])))) if ((firstLoaded && !MachineStuff.InMachineMatrix(list[i].Name)) || (!firstLoaded && (!MachineStuff.InMachineMatrix(list[i].Name) || !IsAlive(list[i]))))
{ {
list[i] = list[i] =
new MachineInf new MachineInf

View File

@@ -4,6 +4,8 @@
using System; using System;
using MouseWithoutBorders.Core;
namespace MouseWithoutBorders.Class namespace MouseWithoutBorders.Class
{ {
internal static class MachinePoolHelpers internal static class MachinePoolHelpers
@@ -20,20 +22,20 @@ namespace MouseWithoutBorders.Class
string[] st = s.Split(Comma); string[] st = s.Split(Comma);
if (st.Length < Common.MAX_MACHINE) if (st.Length < MachineStuff.MAX_MACHINE)
{ {
throw new ArgumentException("Not enough elements in encoded MachinePool string"); throw new ArgumentException("Not enough elements in encoded MachinePool string");
} }
MachineInf[] rv = new MachineInf[Common.MAX_MACHINE]; MachineInf[] rv = new MachineInf[MachineStuff.MAX_MACHINE];
for (int i = 0; i < Common.MAX_MACHINE; i++) for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
{ {
string[] mc = st[i].Split(Colon); string[] mc = st[i].Split(Colon);
if (mc.Length == 2) if (mc.Length == 2)
{ {
rv[i].Name = mc[0]; rv[i].Name = mc[0];
rv[i].Id = uint.TryParse(mc[1], out uint ip) ? (ID)ip : ID.NONE; rv[i].Id = uint.TryParse(mc[1], out uint ip) ? (ID)ip : ID.NONE;
rv[i].Time = rv[i].Id == ID.NONE ? Common.GetTick() - Common.HEARTBEAT_TIMEOUT : Common.GetTick(); rv[i].Time = rv[i].Id == ID.NONE ? Common.GetTick() - MachineStuff.HEARTBEAT_TIMEOUT : Common.GetTick();
} }
} }

View File

@@ -31,6 +31,7 @@ using System.Xml.Linq;
using ManagedCommon; using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Telemetry; using Microsoft.PowerToys.Telemetry;
using MouseWithoutBorders.Core;
using Newtonsoft.Json; using Newtonsoft.Json;
using StreamJsonRpc; using StreamJsonRpc;
@@ -135,7 +136,7 @@ namespace MouseWithoutBorders.Class
if (firstArg != string.Empty) if (firstArg != string.Empty)
{ {
if (Common.CheckSecondInstance(Common.RunWithNoAdminRight)) if (MachineStuff.CheckSecondInstance(Common.RunWithNoAdminRight))
{ {
Logger.Log("*** Second instance, exiting..."); Logger.Log("*** Second instance, exiting...");
return; return;
@@ -165,7 +166,7 @@ namespace MouseWithoutBorders.Class
} }
else else
{ {
if (Common.CheckSecondInstance(true)) if (MachineStuff.CheckSecondInstance(true))
{ {
Logger.Log("*** Second instance, exiting..."); Logger.Log("*** Second instance, exiting...");
return; return;
@@ -301,20 +302,20 @@ namespace MouseWithoutBorders.Class
{ {
Setting.Values.PauseInstantSaving = true; Setting.Values.PauseInstantSaving = true;
Common.ClearComputerMatrix(); MachineStuff.ClearComputerMatrix();
Setting.Values.MyKey = securityKey; Setting.Values.MyKey = securityKey;
Common.MyKey = securityKey; Common.MyKey = securityKey;
Common.MagicNumber = Common.Get24BitHash(Common.MyKey); Common.MagicNumber = Common.Get24BitHash(Common.MyKey);
Common.MachineMatrix = new string[Common.MAX_MACHINE] { pcName.Trim().ToUpper(CultureInfo.CurrentCulture), Common.MachineName.Trim(), string.Empty, string.Empty }; MachineStuff.MachineMatrix = new string[MachineStuff.MAX_MACHINE] { pcName.Trim().ToUpper(CultureInfo.CurrentCulture), Common.MachineName.Trim(), string.Empty, string.Empty };
string[] machines = Common.MachineMatrix; string[] machines = MachineStuff.MachineMatrix;
Common.MachinePool.Initialize(machines); MachineStuff.MachinePool.Initialize(machines);
Common.UpdateMachinePoolStringSetting(); MachineStuff.UpdateMachinePoolStringSetting();
SocketStuff.InvalidKeyFound = false; SocketStuff.InvalidKeyFound = false;
Common.ReopenSocketDueToReadError = true; Common.ReopenSocketDueToReadError = true;
Common.ReopenSockets(true); Common.ReopenSockets(true);
Common.SendMachineMatrix(); MachineStuff.SendMachineMatrix();
Setting.Values.PauseInstantSaving = false; Setting.Values.PauseInstantSaving = false;
Setting.Values.SaveSettings(); Setting.Values.SaveSettings();
@@ -325,7 +326,7 @@ namespace MouseWithoutBorders.Class
Setting.Values.PauseInstantSaving = true; Setting.Values.PauseInstantSaving = true;
Setting.Values.EasyMouse = (int)EasyMouseOption.Enable; Setting.Values.EasyMouse = (int)EasyMouseOption.Enable;
Common.ClearComputerMatrix(); MachineStuff.ClearComputerMatrix();
Setting.Values.MyKey = Common.MyKey = Common.CreateRandomKey(); Setting.Values.MyKey = Common.MyKey = Common.CreateRandomKey();
Common.GeneratedKey = true; Common.GeneratedKey = true;
@@ -352,7 +353,7 @@ namespace MouseWithoutBorders.Class
Common.MMSleep(0.2); Common.MMSleep(0.2);
} }
Common.SendMachineMatrix(); MachineStuff.SendMachineMatrix();
} }
public void Shutdown() public void Shutdown()

View File

@@ -102,7 +102,7 @@ namespace MouseWithoutBorders.Class
if (!Enumerable.SequenceEqual(last_properties.MachineMatrixString, _settings.Properties.MachineMatrixString)) if (!Enumerable.SequenceEqual(last_properties.MachineMatrixString, _settings.Properties.MachineMatrixString))
{ {
_properties.MachineMatrixString = _settings.Properties.MachineMatrixString; _properties.MachineMatrixString = _settings.Properties.MachineMatrixString;
Common.MachineMatrix = null; // Forces read next time it's needed. MachineStuff.MachineMatrix = null; // Forces read next time it's needed.
shouldSendMachineMatrix = true; shouldSendMachineMatrix = true;
} }
@@ -123,7 +123,7 @@ namespace MouseWithoutBorders.Class
if (shouldSendMachineMatrix) if (shouldSendMachineMatrix)
{ {
Common.SendMachineMatrix(); MachineStuff.SendMachineMatrix();
shouldSaveNewSettingsValues = true; shouldSaveNewSettingsValues = true;
} }

View File

@@ -188,7 +188,7 @@ namespace MouseWithoutBorders.Class
{ {
if (Common.DesMachineID != Common.MachineID) if (Common.DesMachineID != Common.MachineID)
{ {
Common.SwitchToMultipleMode(false, true); MachineStuff.SwitchToMultipleMode(false, true);
} }
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop) if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
@@ -253,7 +253,7 @@ namespace MouseWithoutBorders.Class
{ {
if (Setting.Values.LastX == Common.JUST_GOT_BACK_FROM_SCREEN_SAVER) if (Setting.Values.LastX == Common.JUST_GOT_BACK_FROM_SCREEN_SAVER)
{ {
Common.NewDesMachineID = Common.DesMachineID = Common.MachineID; MachineStuff.NewDesMachineID = Common.DesMachineID = Common.MachineID;
} }
else else
{ {
@@ -263,11 +263,11 @@ namespace MouseWithoutBorders.Class
if (Common.RunOnLogonDesktop && Setting.Values.DesMachineID == (uint)ID.ALL) if (Common.RunOnLogonDesktop && Setting.Values.DesMachineID == (uint)ID.ALL)
{ {
Common.SwitchToMultipleMode(true, false); MachineStuff.SwitchToMultipleMode(true, false);
} }
else else
{ {
Common.SwitchToMultipleMode(false, false); MachineStuff.SwitchToMultipleMode(false, false);
} }
} }
} }
@@ -804,11 +804,11 @@ namespace MouseWithoutBorders.Class
try try
{ {
if (Common.MachineMatrix != null) if (MachineStuff.MachineMatrix != null)
{ {
Logger.LogDebug("MachineMatrix = " + string.Join(", ", Common.MachineMatrix)); Logger.LogDebug("MachineMatrix = " + string.Join(", ", MachineStuff.MachineMatrix));
foreach (string st in Common.MachineMatrix) foreach (string st in MachineStuff.MachineMatrix)
{ {
string machineName = st.Trim(); string machineName = st.Trim();
if (!string.IsNullOrEmpty(machineName) && if (!string.IsNullOrEmpty(machineName) &&
@@ -961,7 +961,7 @@ namespace MouseWithoutBorders.Class
UpdateTcpSockets(dummyTcp, SocketStatus.NA); UpdateTcpSockets(dummyTcp, SocketStatus.NA);
if (!Common.InMachineMatrix(machineName)) if (!MachineStuff.InMachineMatrix(machineName))
{ {
// While Resolving from name to IP, user may have changed the machine name and clicked on Apply. // While Resolving from name to IP, user may have changed the machine name and clicked on Apply.
return; return;
@@ -1449,19 +1449,19 @@ namespace MouseWithoutBorders.Class
Common.SendHeartBeat(initial: true); Common.SendHeartBeat(initial: true);
if (Common.MachinePool.TryFindMachineByName(remoteMachine, out MachineInf machineInfo)) if (MachineStuff.MachinePool.TryFindMachineByName(remoteMachine, out MachineInf machineInfo))
{ {
Logger.LogDebug("Machine updated: " + remoteMachine + "/" + remoteID.ToString()); Logger.LogDebug("Machine updated: " + remoteMachine + "/" + remoteID.ToString());
if (machineInfo.Name.Equals(Common.DesMachineName, StringComparison.OrdinalIgnoreCase)) if (machineInfo.Name.Equals(MachineStuff.DesMachineName, StringComparison.OrdinalIgnoreCase))
{ {
Logger.LogDebug("Des ID updated: " + Common.DesMachineID.ToString() + Logger.LogDebug("Des ID updated: " + Common.DesMachineID.ToString() +
"/" + remoteID.ToString()); "/" + remoteID.ToString());
Common.NewDesMachineID = Common.DesMachineID = remoteID; MachineStuff.NewDesMachineID = Common.DesMachineID = remoteID;
} }
_ = Common.MachinePool.TryUpdateMachineID(remoteMachine, remoteID, true); _ = MachineStuff.MachinePool.TryUpdateMachineID(remoteMachine, remoteID, true);
Common.UpdateMachinePoolStringSetting(); MachineStuff.UpdateMachinePoolStringSetting();
} }
else else
{ {
@@ -1475,7 +1475,7 @@ namespace MouseWithoutBorders.Class
if (!isClient) if (!isClient)
{ {
Common.UpdateClientSockets("MainTCPRoutine"); MachineStuff.UpdateClientSockets("MainTCPRoutine");
} }
} }
else else
@@ -1559,7 +1559,7 @@ namespace MouseWithoutBorders.Class
if (remoteID != ID.NONE) if (remoteID != ID.NONE)
{ {
_ = Common.RemoveDeadMachines(remoteID); _ = MachineStuff.RemoveDeadMachines(remoteID);
} }
} }
@@ -1635,9 +1635,9 @@ namespace MouseWithoutBorders.Class
{ {
string remoteEndPoint = s.RemoteEndPoint.ToString(); string remoteEndPoint = s.RemoteEndPoint.ToString();
Logger.LogDebug("SendClipboardData: Request accepted: " + s.LocalEndPoint.ToString() + "/" + remoteEndPoint); Logger.LogDebug("SendClipboardData: Request accepted: " + s.LocalEndPoint.ToString() + "/" + remoteEndPoint);
Common.IsDropping = false; DragDrop.IsDropping = false;
Common.IsDragging = false; DragDrop.IsDragging = false;
Common.DragMachine = (ID)1; DragDrop.DragMachine = (ID)1;
bool clientPushData = true; bool clientPushData = true;
ClipboardPostAction postAction = ClipboardPostAction.Other; ClipboardPostAction postAction = ClipboardPostAction.Other;
@@ -2064,7 +2064,7 @@ namespace MouseWithoutBorders.Class
if (string.IsNullOrEmpty(tcp.MachineName) || tcp.MachineName.Contains('.') || tcp.MachineName.Contains(':')) if (string.IsNullOrEmpty(tcp.MachineName) || tcp.MachineName.Contains('.') || tcp.MachineName.Contains(':'))
{ {
tcp.MachineName = Common.NameFromID((ID)tcp.MachineId); tcp.MachineName = MachineStuff.NameFromID((ID)tcp.MachineId);
} }
if (string.IsNullOrEmpty(tcp.MachineName) || tcp.MachineName.Contains('.') || tcp.MachineName.Contains(':')) if (string.IsNullOrEmpty(tcp.MachineName) || tcp.MachineName.Contains('.') || tcp.MachineName.Contains(':'))

View File

@@ -0,0 +1,404 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Microsoft.PowerToys.Telemetry;
using MouseWithoutBorders.Class;
// <summary>
// Drag/Drop implementation.
// </summary>
// <history>
// 2008 created by Truong Do (ductdo).
// 2009-... modified by Truong Do (TruongDo).
// 2023- Included in PowerToys.
// </history>
namespace MouseWithoutBorders.Core;
/* Common.DragDrop.cs
* Drag&Drop is one complicated implementation of the tool with some tricks.
*
* SEQUENCE OF EVENTS:
* DragDropStep01: MachineX: Remember mouse down state since it could be a start of a dragging
* DragDropStep02: MachineY: Send an message to the MachineX to ask it to check if it is
* doing drag/drop
* DragDropStep03: MachineX: Got explorerDragDrop, send WM_CHECK_EXPLORER_DRAG_DROP to its mainForm
* DragDropStep04: MachineX: Show Mouse Without Borders Helper form at mouse cursor to get DragEnter event.
* DragDropStepXX: MachineX: Mouse Without Borders Helper: Called by DragEnter, check if dragging a single file,
* remember the file (set as its window caption)
* DragDropStep05: MachineX: Get the file name from Mouse Without Borders Helper, hide Mouse Without Borders Helper window
* DragDropStep06: MachineX: Broadcast a message saying that it has some drag file.
* DragDropStep08: MachineY: Got ClipboardDragDrop, isDropping set, get the MachineX name from the package.
* DragDropStep09: MachineY: Since isDropping is true, show up the drop form (looks like an icon).
* DragDropStep10: MachineY: MouseUp, set isDropping to false, hide the drop "icon" and get data.
* DragDropStep11: MachineX: Mouse move back without drop event, cancelling drag/dop
* SendClipboardBeatDragDropEnd
* DragDropStep12: MachineY: Hide the drop "icon" when received ClipboardDragDropEnd.
*
* FROM VERSION 1.6.3: Drag/Drop is temporary removed, Drop action cannot be done from a lower integrity app to a higher one.
* We have to run a helper process...
* http://forums.microsoft.com/MSDN/ShowPost.aspx?PageIndex=1&SiteID=1&PageID=1&PostID=736086
*
* 2008.10.28: Trying to restore the Drag/Drop feature by adding the drag/drop helper process. Coming in version
* 1.6.5
* */
internal static class DragDrop
{
private static bool isDragging;
internal static bool IsDragging
{
get => DragDrop.isDragging;
set => DragDrop.isDragging = value;
}
internal static void DragDropStep01(int wParam)
{
if (!Setting.Values.TransferFile)
{
return;
}
if (wParam == Common.WM_LBUTTONDOWN)
{
MouseDown = true;
DragMachine = MachineStuff.desMachineID;
MachineStuff.dropMachineID = ID.NONE;
Logger.LogDebug("DragDropStep01: MouseDown");
}
else if (wParam == Common.WM_LBUTTONUP)
{
MouseDown = false;
Logger.LogDebug("DragDropStep01: MouseUp");
}
if (wParam == Common.WM_RBUTTONUP && IsDropping)
{
IsDropping = false;
Common.LastIDWithClipboardData = ID.NONE;
}
}
internal static void DragDropStep02()
{
if (MachineStuff.desMachineID == Common.MachineID)
{
Logger.LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent to myself");
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
else
{
SendCheckExplorerDragDrop();
Logger.LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent");
}
}
internal static void DragDropStep03(DATA package)
{
if (Common.RunOnLogonDesktop || Common.RunOnScrSaverDesktop)
{
return;
}
if (package.Des == Common.MachineID || package.Des == ID.ALL)
{
Logger.LogDebug("DragDropStep03: ExplorerDragDrop Received.");
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...");
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
}
}
private static int dragDropStep05ExCalledByIpc;
internal static void DragDropStep04()
{
if (!IsDropping)
{
IntPtr h = (IntPtr)NativeMethods.FindWindow(null, Common.HELPER_FORM_TEXT);
if (h.ToInt32() > 0)
{
_ = Interlocked.Exchange(ref dragDropStep05ExCalledByIpc, 0);
Common.MainForm.Hide();
Common.MainFormVisible = false;
Point p = default;
// NativeMethods.SetWindowText(h, "");
_ = NativeMethods.SetWindowPos(h, NativeMethods.HWND_TOPMOST, 0, 0, 0, 0, NativeMethods.SWP_SHOWWINDOW);
for (int i = -10; i < 10; i++)
{
if (dragDropStep05ExCalledByIpc > 0)
{
Logger.LogDebug("DragDropStep04: DragDropStep05ExCalledByIpc.");
break;
}
_ = NativeMethods.GetCursorPos(ref p);
Logger.LogDebug("DragDropStep04: Moving Mouse Without Borders Helper to (" + p.X.ToString(CultureInfo.CurrentCulture) + ", " + p.Y.ToString(CultureInfo.CurrentCulture) + ")");
_ = NativeMethods.SetWindowPos(h, NativeMethods.HWND_TOPMOST, p.X - 100 + i, p.Y - 100 + i, 200, 200, 0);
_ = NativeMethods.SendMessage(h, 0x000F, IntPtr.Zero, IntPtr.Zero); // WM_PAINT
Thread.Sleep(20);
Application.DoEvents();
// if (GetText(h).Length > 1) break;
}
}
else
{
Logger.LogDebug("DragDropStep04: Mouse without Borders Helper not found!");
}
}
else
{
Logger.LogDebug("DragDropStep04: IsDropping == true, skip checking");
}
Logger.LogDebug("DragDropStep04: Got WM_CHECK_EXPLORER_DRAG_DROP, done with processing jump to DragDropStep05...");
}
internal static void DragDropStep05Ex(string dragFileName)
{
Logger.LogDebug("DragDropStep05 called.");
_ = Interlocked.Exchange(ref dragDropStep05ExCalledByIpc, 1);
if (Common.RunOnLogonDesktop || Common.RunOnScrSaverDesktop)
{
return;
}
if (!IsDropping)
{
_ = Common.ImpersonateLoggedOnUserAndDoSomething(() =>
{
if (!string.IsNullOrEmpty(dragFileName) && (File.Exists(dragFileName) || Directory.Exists(dragFileName)))
{
Common.LastDragDropFile = dragFileName;
/*
* possibleDropMachineID is used as desID sent in DragDropStep06();
* */
if (MachineStuff.dropMachineID == ID.NONE)
{
MachineStuff.dropMachineID = MachineStuff.newDesMachineID;
}
DragDropStep06();
Logger.LogDebug("DragDropStep05: File dragging: " + dragFileName);
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_HIDE_DD_HELPER, (IntPtr)1, (IntPtr)0);
}
else
{
Logger.LogDebug("DragDropStep05: File not found: [" + dragFileName + "]");
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_HIDE_DD_HELPER, (IntPtr)0, (IntPtr)0);
}
Logger.LogDebug("DragDropStep05: WM_HIDE_DDHelper sent");
});
}
else
{
Logger.LogDebug("DragDropStep05: IsDropping == true, change drop machine...");
IsDropping = false;
Common.MainFormVisible = true; // WM_HIDE_DRAG_DROP
SendDropBegin(); // To dropMachineID set in DragDropStep03
}
MouseDown = false;
}
private static void DragDropStep06()
{
IsDragging = true;
Logger.LogDebug("DragDropStep06: SendClipboardBeatDragDrop");
SendClipboardBeatDragDrop();
SendDropBegin();
}
internal static void DragDropStep08(DATA package)
{
Receiver.GetNameOfMachineWithClipboardData(package);
Logger.LogDebug("DragDropStep08: ClipboardDragDrop Received. machine with drag file was set");
}
internal static void DragDropStep08_2(DATA package)
{
if (package.Des == Common.MachineID && !Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
{
IsDropping = true;
MachineStuff.dropMachineID = Common.MachineID;
Logger.LogDebug("DragDropStep08_2: ClipboardDragDropOperation Received. IsDropping set");
}
}
internal static void DragDropStep09(int wParam)
{
if (wParam == Common.WM_MOUSEMOVE && IsDropping)
{
// Show/Move form
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_SHOW_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
else if (wParam == Common.WM_LBUTTONUP && (IsDropping || IsDragging))
{
if (IsDropping)
{
// Hide form, get data
DragDropStep10();
}
else
{
IsDragging = false;
Common.LastIDWithClipboardData = ID.NONE;
}
}
}
private static void DragDropStep10()
{
Logger.LogDebug("DragDropStep10: Hide the form and get data...");
IsDropping = false;
IsDragging = false;
Common.LastIDWithClipboardData = ID.NONE;
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_HIDE_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
PowerToysTelemetry.Log.WriteEvent(new MouseWithoutBorders.Telemetry.MouseWithoutBordersDragAndDropEvent());
Common.GetRemoteClipboard("desktop");
}
internal static void DragDropStep11()
{
Logger.LogDebug("DragDropStep11: Mouse drag coming back, canceling drag/drop");
SendClipboardBeatDragDropEnd();
IsDropping = false;
IsDragging = false;
DragMachine = (ID)1;
Common.LastIDWithClipboardData = ID.NONE;
Common.LastDragDropFile = null;
MouseDown = false;
}
internal static void DragDropStep12()
{
Logger.LogDebug("DragDropStep12: ClipboardDragDropEnd received");
IsDropping = false;
Common.LastIDWithClipboardData = ID.NONE;
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_HIDE_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
private static void SendCheckExplorerDragDrop()
{
DATA package = new();
package.Type = PackageType.ExplorerDragDrop;
/*
* package.src = newDesMachineID:
* sent from the master machine but the src must be the
* new des machine since the previous des machine will get this and set
* to possibleDropMachineID in DragDropStep3()
* */
package.Src = MachineStuff.newDesMachineID;
package.Des = MachineStuff.desMachineID;
package.MachineName = Common.MachineName;
Common.SkSend(package, null, false);
}
internal static void ChangeDropMachine()
{
// desMachineID = current drop machine
// newDesMachineID = new drop machine
// 1. Cancelling dropping in current drop machine
if (MachineStuff.dropMachineID == Common.MachineID)
{
// Drag/Drop coming through me
IsDropping = false;
}
else
{
// Drag/Drop coming back
SendClipboardBeatDragDropEnd();
}
// 2. SendClipboardBeatDragDrop to new drop machine
// new drop machine is not me
if (MachineStuff.newDesMachineID != Common.MachineID)
{
MachineStuff.dropMachineID = MachineStuff.newDesMachineID;
SendDropBegin();
}
// New drop machine is me
else
{
IsDropping = true;
}
}
private static void SendClipboardBeatDragDrop()
{
Common.SendPackage(ID.ALL, PackageType.ClipboardDragDrop);
}
private static void SendDropBegin()
{
Logger.LogDebug("SendDropBegin...");
Common.SendPackage(MachineStuff.dropMachineID, PackageType.ClipboardDragDropOperation);
}
private static void SendClipboardBeatDragDropEnd()
{
if (MachineStuff.desMachineID != Common.MachineID)
{
Common.SendPackage(MachineStuff.desMachineID, PackageType.ClipboardDragDropEnd);
}
}
private static bool isDropping;
private static ID dragMachine;
internal static ID DragMachine
{
get => DragDrop.dragMachine;
set => DragDrop.dragMachine = value;
}
internal static bool IsDropping
{
get => DragDrop.isDropping;
set => DragDrop.isDropping = value;
}
internal static bool MouseDown { get; set; }
}

View File

@@ -199,8 +199,11 @@ internal static class Logger
_ = Logger.PrivateDump(sb, AllLogs, "[Program logs]\r\n===============\r\n", 0, level, false); _ = Logger.PrivateDump(sb, AllLogs, "[Program logs]\r\n===============\r\n", 0, level, false);
_ = Logger.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, level, false); _ = Logger.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, level, false);
sb.AppendLine("[Logger]\r\n===============");
Logger.DumpType(sb, typeof(Logger), 0, level); Logger.DumpType(sb, typeof(Logger), 0, level);
sb.AppendLine("[DragDrop]\r\n===============");
Logger.DumpType(sb, typeof(DragDrop), 0, level);
sb.AppendLine("[MachineStuff]\r\n===============");
Logger.DumpType(sb, typeof(MachineStuff), 0, level);
sb.AppendLine("[Receiver]\r\n==============="); sb.AppendLine("[Receiver]\r\n===============");
Logger.DumpType(sb, typeof(Receiver), 0, level); Logger.DumpType(sb, typeof(Receiver), 0, level);

View File

@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// <summary>
// Machine setup/switching implementation.
// </summary>
// <history>
// 2008 created by Truong Do (ductdo).
// 2009-... modified by Truong Do (TruongDo).
// 2023- Included in PowerToys.
// </history>
namespace MouseWithoutBorders.Core;
internal struct MachineInf
{
internal string Name;
internal ID Id;
internal long Time;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// <summary>
// Machine setup/switching implementation.
// </summary>
// <history>
// 2008 created by Truong Do (ductdo).
// 2009-... modified by Truong Do (TruongDo).
// 2023- Included in PowerToys.
// </history>
namespace MouseWithoutBorders.Core;
internal sealed class MyRectangle
{
internal int Left;
internal int Top;
internal int Right;
internal int Bottom;
}

View File

@@ -120,16 +120,16 @@ internal static class Receiver
if (package.Des == Common.MachineID || package.Des == ID.ALL) if (package.Des == Common.MachineID || package.Des == ID.ALL)
{ {
if (Common.desMachineID != Common.MachineID) if (MachineStuff.desMachineID != Common.MachineID)
{ {
Common.NewDesMachineID = Common.DesMachineID = Common.MachineID; MachineStuff.NewDesMachineID = Common.DesMachineID = Common.MachineID;
} }
// NOTE(@yuyoyuppe): disabled to drop elevation requirement // NOTE(@yuyoyuppe): disabled to drop elevation requirement
bool nonElevated = Common.RunWithNoAdminRight && false; bool nonElevated = Common.RunWithNoAdminRight && false;
if (nonElevated && Setting.Values.OneWayControlMode && package.Md.dwFlags != Common.WM_MOUSEMOVE) if (nonElevated && Setting.Values.OneWayControlMode && package.Md.dwFlags != Common.WM_MOUSEMOVE)
{ {
if (!Common.IsDropping) if (!DragDrop.IsDropping)
{ {
if (package.Md.dwFlags is Common.WM_LBUTTONDOWN or Common.WM_RBUTTONDOWN) if (package.Md.dwFlags is Common.WM_LBUTTONDOWN or Common.WM_RBUTTONDOWN)
{ {
@@ -138,7 +138,7 @@ internal static class Receiver
} }
else if (package.Md.dwFlags is Common.WM_LBUTTONUP or Common.WM_RBUTTONUP) else if (package.Md.dwFlags is Common.WM_LBUTTONUP or Common.WM_RBUTTONUP)
{ {
Common.IsDropping = false; DragDrop.IsDropping = false;
} }
return; return;
@@ -153,7 +153,7 @@ internal static class Receiver
package.Md.Y < 0 ? package.Md.Y + Common.MOVE_MOUSE_RELATIVE : package.Md.Y - Common.MOVE_MOUSE_RELATIVE); package.Md.Y < 0 ? package.Md.Y + Common.MOVE_MOUSE_RELATIVE : package.Md.Y - Common.MOVE_MOUSE_RELATIVE);
_ = NativeMethods.GetCursorPos(ref lastXY); _ = NativeMethods.GetCursorPos(ref lastXY);
Point p = Common.MoveToMyNeighbourIfNeeded(lastXY.X, lastXY.Y, Common.MachineID); Point p = MachineStuff.MoveToMyNeighbourIfNeeded(lastXY.X, lastXY.Y, Common.MachineID);
if (!p.IsEmpty) if (!p.IsEmpty)
{ {
@@ -162,11 +162,11 @@ internal static class Receiver
Logger.LogDebug(string.Format( Logger.LogDebug(string.Format(
CultureInfo.CurrentCulture, CultureInfo.CurrentCulture,
"***** Controlled Machine: newDesMachineIdEx set = [{0}]. Mouse is now at ({1},{2})", "***** Controlled Machine: newDesMachineIdEx set = [{0}]. Mouse is now at ({1},{2})",
Common.newDesMachineIdEx, MachineStuff.newDesMachineIdEx,
lastXY.X, lastXY.X,
lastXY.Y)); lastXY.Y));
Common.SendNextMachine(package.Src, Common.newDesMachineIdEx, p); Common.SendNextMachine(package.Src, MachineStuff.newDesMachineIdEx, p);
} }
} }
else else
@@ -188,8 +188,8 @@ internal static class Receiver
CustomCursor.ShowFakeMouseCursor(Common.LastX, Common.LastY); CustomCursor.ShowFakeMouseCursor(Common.LastX, Common.LastY);
} }
Common.DragDropStep01(package.Md.dwFlags); DragDrop.DragDropStep01(package.Md.dwFlags);
Common.DragDropStep09(package.Md.dwFlags); DragDrop.DragDropStep09(package.Md.dwFlags);
break; break;
case PackageType.NextMachine: case PackageType.NextMachine:
@@ -204,7 +204,7 @@ internal static class Receiver
case PackageType.ExplorerDragDrop: case PackageType.ExplorerDragDrop:
Common.PackageReceived.ExplorerDragDrop++; Common.PackageReceived.ExplorerDragDrop++;
Common.DragDropStep03(package); DragDrop.DragDropStep03(package);
break; break;
case PackageType.Heartbeat: case PackageType.Heartbeat:
@@ -219,12 +219,12 @@ internal static class Receiver
Common.SendPackage(ID.ALL, PackageType.Heartbeat_ex_l2); Common.SendPackage(ID.ALL, PackageType.Heartbeat_ex_l2);
} }
string desMachine = Common.AddToMachinePool(package); string desMachine = MachineStuff.AddToMachinePool(package);
if (Setting.Values.FirstRun && !string.IsNullOrEmpty(desMachine)) if (Setting.Values.FirstRun && !string.IsNullOrEmpty(desMachine))
{ {
Common.UpdateSetupMachineMatrix(desMachine); Common.UpdateSetupMachineMatrix(desMachine);
Common.UpdateClientSockets("UpdateSetupMachineMatrix"); MachineStuff.UpdateClientSockets("UpdateSetupMachineMatrix");
} }
break; break;
@@ -244,14 +244,14 @@ internal static class Receiver
case PackageType.Awake: case PackageType.Awake:
Common.PackageReceived.Heartbeat++; Common.PackageReceived.Heartbeat++;
_ = Common.AddToMachinePool(package); _ = MachineStuff.AddToMachinePool(package);
Common.HumanBeingDetected(); Common.HumanBeingDetected();
break; break;
case PackageType.Hello: case PackageType.Hello:
Common.PackageReceived.Hello++; Common.PackageReceived.Hello++;
Common.SendHeartBeat(); Common.SendHeartBeat();
string newMachine = Common.AddToMachinePool(package); string newMachine = MachineStuff.AddToMachinePool(package);
if (Setting.Values.MachineMatrixString == null) if (Setting.Values.MachineMatrixString == null)
{ {
string tip = newMachine + " saying Hello!"; string tip = newMachine + " saying Hello!";
@@ -345,17 +345,17 @@ internal static class Receiver
case PackageType.ClipboardDragDrop: case PackageType.ClipboardDragDrop:
Common.PackageReceived.ClipboardDragDrop++; Common.PackageReceived.ClipboardDragDrop++;
Common.DragDropStep08(package); DragDrop.DragDropStep08(package);
break; break;
case PackageType.ClipboardDragDropOperation: case PackageType.ClipboardDragDropOperation:
Common.PackageReceived.ClipboardDragDrop++; Common.PackageReceived.ClipboardDragDrop++;
Common.DragDropStep08_2(package); DragDrop.DragDropStep08_2(package);
break; break;
case PackageType.ClipboardDragDropEnd: case PackageType.ClipboardDragDropEnd:
Common.PackageReceived.ClipboardDragDropEnd++; Common.PackageReceived.ClipboardDragDropEnd++;
Common.DragDropStep12(); DragDrop.DragDropStep12();
break; break;
case PackageType.ClipboardText: case PackageType.ClipboardText:
@@ -391,7 +391,7 @@ internal static class Receiver
if ((package.Type & PackageType.Matrix) == PackageType.Matrix) if ((package.Type & PackageType.Matrix) == PackageType.Matrix)
{ {
Common.PackageReceived.Matrix++; Common.PackageReceived.Matrix++;
Common.UpdateMachineMatrix(package); MachineStuff.UpdateMachineMatrix(package);
break; break;
} }
else else
@@ -406,7 +406,7 @@ internal static class Receiver
internal static void GetNameOfMachineWithClipboardData(DATA package) internal static void GetNameOfMachineWithClipboardData(DATA package)
{ {
Common.LastIDWithClipboardData = package.Src; Common.LastIDWithClipboardData = package.Src;
List<MachineInf> matchingMachines = Common.MachinePool.TryFindMachineByID(Common.LastIDWithClipboardData); List<MachineInf> matchingMachines = MachineStuff.MachinePool.TryFindMachineByID(Common.LastIDWithClipboardData);
if (matchingMachines.Count >= 1) if (matchingMachines.Count >= 1)
{ {
Common.LastMachineWithClipboardData = matchingMachines[0].Name.Trim(); Common.LastMachineWithClipboardData = matchingMachines[0].Name.Trim();

View File

@@ -39,7 +39,7 @@ namespace MouseWithoutBorders
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{ {
Common.Settings = null; MachineStuff.Settings = null;
if (_currentPage != null) if (_currentPage != null)
{ {

View File

@@ -6,6 +6,7 @@ using System;
using System.Windows.Forms; using System.Windows.Forms;
using MouseWithoutBorders.Class; using MouseWithoutBorders.Class;
using MouseWithoutBorders.Core;
using MouseWithoutBorders.Form.Settings; using MouseWithoutBorders.Form.Settings;
namespace MouseWithoutBorders namespace MouseWithoutBorders
@@ -59,8 +60,8 @@ namespace MouseWithoutBorders
MessageBoxDefaultButton.Button2) == DialogResult.Yes) MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{ {
Setting.Values.FirstRun = false; Setting.Values.FirstRun = false;
Common.CloseSetupForm(); MachineStuff.CloseSetupForm();
Common.ShowMachineMatrix(); MachineStuff.ShowMachineMatrix();
} }
} }
} }

View File

@@ -4,6 +4,8 @@
using System; using System;
using MouseWithoutBorders.Core;
namespace MouseWithoutBorders namespace MouseWithoutBorders
{ {
public partial class SetupPage1 : SettingsFormPage public partial class SetupPage1 : SettingsFormPage
@@ -12,7 +14,7 @@ namespace MouseWithoutBorders
{ {
InitializeComponent(); InitializeComponent();
Common.ClearComputerMatrix(); MachineStuff.ClearComputerMatrix();
} }
private void NoButtonClick(object sender, EventArgs e) private void NoButtonClick(object sender, EventArgs e)

View File

@@ -6,6 +6,7 @@ using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using MouseWithoutBorders.Class; using MouseWithoutBorders.Class;
using MouseWithoutBorders.Core;
namespace MouseWithoutBorders namespace MouseWithoutBorders
{ {
@@ -92,12 +93,12 @@ namespace MouseWithoutBorders
SecurityCode = Common.MyKey; SecurityCode = Common.MyKey;
} }
Common.MachineMatrix = new string[Common.MAX_MACHINE] { ComputerNameField.Text.Trim().ToUpper(CultureInfo.CurrentCulture), Common.MachineName.Trim(), string.Empty, string.Empty }; MachineStuff.MachineMatrix = new string[MachineStuff.MAX_MACHINE] { ComputerNameField.Text.Trim().ToUpper(CultureInfo.CurrentCulture), Common.MachineName.Trim(), string.Empty, string.Empty };
string[] machines = Common.MachineMatrix; string[] machines = MachineStuff.MachineMatrix;
Common.MachinePool.Initialize(machines); MachineStuff.MachinePool.Initialize(machines);
Common.UpdateMachinePoolStringSetting(); MachineStuff.UpdateMachinePoolStringSetting();
SendNextPage(new SetupPage3a { ReturnToSettings = !Setting.Values.FirstRun }); SendNextPage(new SetupPage3a { ReturnToSettings = !Setting.Values.FirstRun });
} }

View File

@@ -70,7 +70,7 @@ namespace MouseWithoutBorders
ShowStatus($"Connecting..."); ShowStatus($"Connecting...");
Common.SwitchToMultipleMode(false, false); MachineStuff.SwitchToMultipleMode(false, false);
Common.ReopenSockets(true); Common.ReopenSockets(true);
int timeOut = 0; int timeOut = 0;

View File

@@ -4,6 +4,8 @@
using System; using System;
using MouseWithoutBorders.Core;
namespace MouseWithoutBorders namespace MouseWithoutBorders
{ {
public partial class SetupPage5 : SettingsFormPage public partial class SetupPage5 : SettingsFormPage
@@ -16,8 +18,8 @@ namespace MouseWithoutBorders
private void DoneButtonClick(object sender, EventArgs e) private void DoneButtonClick(object sender, EventArgs e)
{ {
// SendNextPage(new SettingsPage1()); // SendNextPage(new SettingsPage1());
Common.CloseSetupForm(); MachineStuff.CloseSetupForm();
Common.ShowMachineMatrix(); MachineStuff.ShowMachineMatrix();
} }
} }
} }

View File

@@ -76,8 +76,8 @@ namespace MouseWithoutBorders
return; return;
} }
string[] st = new string[Common.MAX_MACHINE]; string[] st = new string[MachineStuff.MAX_MACHINE];
for (int i = 0; i < Common.MAX_MACHINE; i++) for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
{ {
if (machines[i].MachineEnabled) if (machines[i].MachineEnabled)
{ {
@@ -98,7 +98,7 @@ namespace MouseWithoutBorders
} }
} }
Common.MachineMatrix = st; MachineStuff.MachineMatrix = st;
Setting.Values.MatrixOneRow = matrixOneRow = !checkBoxTwoRow.Checked; Setting.Values.MatrixOneRow = matrixOneRow = !checkBoxTwoRow.Checked;
if (Process.GetCurrentProcess().SessionId != NativeMethods.WTSGetActiveConsoleSessionId()) if (Process.GetCurrentProcess().SessionId != NativeMethods.WTSGetActiveConsoleSessionId())
@@ -124,7 +124,7 @@ namespace MouseWithoutBorders
Common.MMSleep(0.2); Common.MMSleep(0.2);
} }
Common.SendMachineMatrix(); MachineStuff.SendMachineMatrix();
} }
buttonOK.Enabled = true; buttonOK.Enabled = true;
@@ -150,13 +150,13 @@ namespace MouseWithoutBorders
bool meAdded = false; bool meAdded = false;
string machineName; string machineName;
if (Common.MachineMatrix != null && Common.MachineMatrix.Length == Common.MAX_MACHINE) if (MachineStuff.MachineMatrix != null && MachineStuff.MachineMatrix.Length == MachineStuff.MAX_MACHINE)
{ {
Logger.LogDebug("LoadMachines: Machine Matrix: " + Setting.Values.MachineMatrixString); Logger.LogDebug("LoadMachines: Machine Matrix: " + Setting.Values.MachineMatrixString);
for (int i = 0; i < Common.MAX_MACHINE; i++) for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
{ {
machineName = Common.MachineMatrix[i].Trim(); machineName = MachineStuff.MachineMatrix[i].Trim();
machines[i].MachineName = machineName; machines[i].MachineName = machineName;
if (string.IsNullOrEmpty(machineName)) if (string.IsNullOrEmpty(machineName))
@@ -168,7 +168,7 @@ namespace MouseWithoutBorders
machines[i].MachineEnabled = true; machines[i].MachineEnabled = true;
} }
bool found = Common.MachinePool.TryFindMachineByName(machineName, out MachineInf machineInfo); bool found = MachineStuff.MachinePool.TryFindMachineByName(machineName, out MachineInf machineInfo);
if (found) if (found)
{ {
if (machineInfo.Id == Common.MachineID) if (machineInfo.Id == Common.MachineID)
@@ -340,7 +340,7 @@ namespace MouseWithoutBorders
string newMachine; string newMachine;
Machine unUsedMachine; Machine unUsedMachine;
foreach (MachineInf inf in Common.MachinePool.ListAllMachines()) foreach (MachineInf inf in MachineStuff.MachinePool.ListAllMachines())
{ {
bool found = false; bool found = false;
unUsedMachine = null; unUsedMachine = null;
@@ -519,7 +519,7 @@ namespace MouseWithoutBorders
return true; return true;
} }
private readonly Machine[] machines = new Machine[Common.MAX_MACHINE]; private readonly Machine[] machines = new Machine[MachineStuff.MAX_MACHINE];
private Machine dragDropMachine; private Machine dragDropMachine;
private Machine desMachine; private Machine desMachine;
private Machine desMachineX; private Machine desMachineX;
@@ -530,7 +530,7 @@ namespace MouseWithoutBorders
private void CreateMachines() private void CreateMachines()
{ {
for (int i = 0; i < Common.MAX_MACHINE; i++) for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
{ {
Machine m = new(); Machine m = new();
m.MouseDown += Machine_MouseDown; m.MouseDown += Machine_MouseDown;
@@ -550,7 +550,7 @@ namespace MouseWithoutBorders
int dx = (groupBoxMachineMatrix.Width - 40) / 4; int dx = (groupBoxMachineMatrix.Width - 40) / 4;
int yOffset = groupBoxMachineMatrix.Height / 3; int yOffset = groupBoxMachineMatrix.Height / 3;
for (int i = 0; i < Common.MAX_MACHINE; i++) for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
{ {
machines[i].Left = matrixOneRow ? 22 + (i * dx) : 22 + dx + ((i % 2) * dx); machines[i].Left = matrixOneRow ? 22 + (i * dx) : 22 + dx + ((i % 2) * dx);
machines[i].Top = matrixOneRow ? yOffset : (yOffset / 2) + (i / 2 * (machines[i].Width + 2)); machines[i].Top = matrixOneRow ? yOffset : (yOffset / 2) + (i / 2 * (machines[i].Width + 2));
@@ -649,7 +649,7 @@ namespace MouseWithoutBorders
desMachineX = desMachineY = desMachine; desMachineX = desMachineY = desMachine;
for (int i = 0; i < Common.MAX_MACHINE; i++) for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
{ {
if (machines[i] == dragDropMachine) if (machines[i] == dragDropMachine)
{ {
@@ -703,9 +703,9 @@ namespace MouseWithoutBorders
dragDropMachine.Top = desMachinePos.Y; dragDropMachine.Top = desMachinePos.Y;
Machine tmp; Machine tmp;
for (int i = 0; i < Common.MAX_MACHINE - 1; i++) for (int i = 0; i < MachineStuff.MAX_MACHINE - 1; i++)
{ {
for (int j = 0; j < Common.MAX_MACHINE - 1 - i; j++) for (int j = 0; j < MachineStuff.MAX_MACHINE - 1 - i; j++)
{ {
if (machines[j + 1].Top < machines[j].Top || (machines[j + 1].Top == machines[j].Top && machines[j + 1].Left < machines[j].Left)) if (machines[j + 1].Top < machines[j].Top || (machines[j + 1].Top == machines[j].Top && machines[j + 1].Left < machines[j].Left))
{ {
@@ -1041,7 +1041,7 @@ namespace MouseWithoutBorders
{ {
Setting.Values.MatrixCircle = checkBoxCircle.Checked; Setting.Values.MatrixCircle = checkBoxCircle.Checked;
ShowUpdateMessage(); ShowUpdateMessage();
Common.SendMachineMatrix(); MachineStuff.SendMachineMatrix();
} }
} }
@@ -1187,8 +1187,8 @@ namespace MouseWithoutBorders
ButtonCancel_Click(this, new EventArgs()); ButtonCancel_Click(this, new EventArgs());
Setting.Values.FirstRun = true; Setting.Values.FirstRun = true;
Setting.Values.EasyMouse = (int)EasyMouseOption.Enable; Setting.Values.EasyMouse = (int)EasyMouseOption.Enable;
Common.ClearComputerMatrix(); MachineStuff.ClearComputerMatrix();
Common.ShowSetupForm(true); MachineStuff.ShowSetupForm(true);
} }
} }

View File

@@ -171,7 +171,7 @@ namespace MouseWithoutBorders
internal void MenuOnClick(object sender, EventArgs e) internal void MenuOnClick(object sender, EventArgs e)
{ {
string name = (sender as ToolStripMenuItem).Text; string name = (sender as ToolStripMenuItem).Text;
Common.SwitchToMachine(name); MachineStuff.SwitchToMachine(name);
} }
internal void UpdateMenu() internal void UpdateMenu()
@@ -199,11 +199,11 @@ namespace MouseWithoutBorders
menuGetScreenCapture.DropDown.Items.Count - 1]); menuGetScreenCapture.DropDown.Items.Count - 1]);
} }
for (int i = 0; i < Common.MAX_MACHINE; i++) for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
{ {
string newMachine = Common.MachineMatrix[i].Trim(); string newMachine = MachineStuff.MachineMatrix[i].Trim();
if (Common.MachinePool.TryFindMachineByName(newMachine, out MachineInf inf) && MachinePool.IsAlive(inf)) if (MachineStuff.MachinePool.TryFindMachineByName(newMachine, out MachineInf inf) && MachinePool.IsAlive(inf))
{ {
ToolStripMenuItem newItem = new( ToolStripMenuItem newItem = new(
newMachine, newMachine,
@@ -372,14 +372,14 @@ namespace MouseWithoutBorders
Common.MyKey = Setting.Values.MyKey; Common.MyKey = Setting.Values.MyKey;
} }
Common.UpdateMachinePoolStringSetting(); MachineStuff.UpdateMachinePoolStringSetting();
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop && (Setting.Values.FirstRun || Common.KeyCorrupted)) if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop && (Setting.Values.FirstRun || Common.KeyCorrupted))
{ {
if (!shownSetupFormOneTime) if (!shownSetupFormOneTime)
{ {
shownSetupFormOneTime = true; shownSetupFormOneTime = true;
Common.ShowMachineMatrix(); MachineStuff.ShowMachineMatrix();
if (Common.KeyCorrupted && !Setting.Values.FirstRun) if (Common.KeyCorrupted && !Setting.Values.FirstRun)
{ {
@@ -439,7 +439,7 @@ namespace MouseWithoutBorders
Common.GetMachineName(); Common.GetMachineName();
Logger.LogDebug("Common.pleaseReopenSocket: " + Common.PleaseReopenSocket.ToString(CultureInfo.InvariantCulture)); Logger.LogDebug("Common.pleaseReopenSocket: " + Common.PleaseReopenSocket.ToString(CultureInfo.InvariantCulture));
Common.ReopenSockets(false); Common.ReopenSockets(false);
Common.NewDesMachineID = Common.DesMachineID = Common.MachineID; MachineStuff.NewDesMachineID = Common.DesMachineID = Common.MachineID;
} }
} }
else else
@@ -457,7 +457,7 @@ namespace MouseWithoutBorders
{ {
Common.PleaseReopenSocket = 0; Common.PleaseReopenSocket = 0;
Thread.Sleep(1000); Thread.Sleep(1000);
Common.UpdateClientSockets("REOPEN_WHEN_WSAECONNRESET"); MachineStuff.UpdateClientSockets("REOPEN_WHEN_WSAECONNRESET");
} }
if (Common.RunOnLogonDesktop) if (Common.RunOnLogonDesktop)
@@ -496,7 +496,7 @@ namespace MouseWithoutBorders
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop) if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
{ {
Common.ShowMachineMatrix(); MachineStuff.ShowMachineMatrix();
Common.MatrixForm?.UpdateKeyTextBox(); Common.MatrixForm?.UpdateKeyTextBox();
@@ -511,7 +511,7 @@ namespace MouseWithoutBorders
if (myKeyDaysToExpire <= 0) if (myKeyDaysToExpire <= 0)
{ {
Common.ShowMachineMatrix(); MachineStuff.ShowMachineMatrix();
Common.Sk?.Close(false); Common.Sk?.Close(false);
@@ -532,7 +532,7 @@ namespace MouseWithoutBorders
// if (Common.RunOnLogonDesktop) ShowMouseWithoutBordersUiOnWinLogonDesktop(false); // if (Common.RunOnLogonDesktop) ShowMouseWithoutBordersUiOnWinLogonDesktop(false);
#endif #endif
Common.CheckForDesktopSwitchEvent(true); Common.CheckForDesktopSwitchEvent(true);
Common.UpdateClientSockets("helperTimer_Tick"); // Sockets may be closed by the remote host when both machines switch desktop at the same time. MachineStuff.UpdateClientSockets("helperTimer_Tick"); // Sockets may be closed by the remote host when both machines switch desktop at the same time.
} }
count++; count++;
@@ -553,11 +553,11 @@ namespace MouseWithoutBorders
Logger.LogAll(); Logger.LogAll();
// Need to review this code on why it is needed (moved from MoveToMyNeighbourIfNeeded(...)) // Need to review this code on why it is needed (moved from MoveToMyNeighbourIfNeeded(...))
for (int i = 0; i < Common.MachineMatrix.Length; i++) for (int i = 0; i < MachineStuff.MachineMatrix.Length; i++)
{ {
if (string.IsNullOrEmpty(Common.MachineMatrix[i]) && !Common.InMachineMatrix(Common.MachineName)) if (string.IsNullOrEmpty(MachineStuff.MachineMatrix[i]) && !MachineStuff.InMachineMatrix(Common.MachineName))
{ {
Common.MachineMatrix[i] = Common.MachineName; MachineStuff.MachineMatrix[i] = Common.MachineName;
} }
} }
@@ -567,7 +567,7 @@ namespace MouseWithoutBorders
if (Setting.Values.BlockScreenSaver || count % 3000 == 0) if (Setting.Values.BlockScreenSaver || count % 3000 == 0)
{ {
Common.SendAwakeBeat(); Common.SendAwakeBeat();
Common.RemoveDeadMachines(); MachineStuff.RemoveDeadMachines();
// GC.Collect(); // GC.Collect();
// GC.WaitForPendingFinalizers(); // GC.WaitForPendingFinalizers();
@@ -601,12 +601,12 @@ namespace MouseWithoutBorders
private void MenuMachineMatrix_Click(object sender, EventArgs e) private void MenuMachineMatrix_Click(object sender, EventArgs e)
{ {
Common.ShowMachineMatrix(); MachineStuff.ShowMachineMatrix();
} }
private void FrmScreen_MouseMove(object sender, MouseEventArgs e) private void FrmScreen_MouseMove(object sender, MouseEventArgs e)
{ {
if (!Common.IsDropping) if (!Core.DragDrop.IsDropping)
{ {
if (Cursor != dotCur) if (Cursor != dotCur)
{ {
@@ -702,7 +702,7 @@ namespace MouseWithoutBorders
internal void MenuAllPC_Click(object sender, EventArgs e) internal void MenuAllPC_Click(object sender, EventArgs e)
{ {
Logger.LogDebug("menuAllPC_Click"); Logger.LogDebug("menuAllPC_Click");
Common.SwitchToMultipleMode(MenuAllPC.Checked, true); MachineStuff.SwitchToMultipleMode(MenuAllPC.Checked, true);
CurIcon = MenuAllPC.Checked ? Common.ICON_ALL : Common.ICON_ONE; CurIcon = MenuAllPC.Checked ? Common.ICON_ALL : Common.ICON_ONE;
ChangeIcon(CurIcon); ChangeIcon(CurIcon);
} }
@@ -711,7 +711,7 @@ namespace MouseWithoutBorders
{ {
Common.DoSomethingInUIThread(() => Common.DoSomethingInUIThread(() =>
{ {
MenuAllPC.Checked = Common.NewDesMachineID == ID.ALL; MenuAllPC.Checked = MachineStuff.NewDesMachineID == ID.ALL;
CurIcon = MenuAllPC.Checked ? Common.ICON_ALL : Common.ICON_ONE; CurIcon = MenuAllPC.Checked ? Common.ICON_ALL : Common.ICON_ONE;
ChangeIcon(CurIcon); ChangeIcon(CurIcon);
}); });
@@ -819,7 +819,7 @@ namespace MouseWithoutBorders
case NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP: case NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP:
Logger.LogDebug("Got WM_CHECK_EXPLORER_DRAG_DROP!"); Logger.LogDebug("Got WM_CHECK_EXPLORER_DRAG_DROP!");
Common.DragDropStep04(); Core.DragDrop.DragDropStep04();
break; break;
case NativeMethods.WM_QUIT: case NativeMethods.WM_QUIT:
@@ -841,7 +841,7 @@ namespace MouseWithoutBorders
case NativeMethods.WM_SHOW_SETTINGS_FORM: case NativeMethods.WM_SHOW_SETTINGS_FORM:
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop) if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
{ {
Common.ShowMachineMatrix(); MachineStuff.ShowMachineMatrix();
} }
break; break;
@@ -856,7 +856,7 @@ namespace MouseWithoutBorders
{ {
if (e.Button == MouseButtons.Left) if (e.Button == MouseButtons.Left)
{ {
Common.ShowMachineMatrix(); MachineStuff.ShowMachineMatrix();
} }
} }
@@ -872,7 +872,7 @@ namespace MouseWithoutBorders
internal void UpdateNotifyIcon() internal void UpdateNotifyIcon()
{ {
string[] x = Common.MachineMatrix; string[] x = MachineStuff.MachineMatrix;
string iconText; string iconText;
if (x != null && (x[0].Length > 0 || x[1].Length > 0 || x[2].Length > 0 || x[3].Length > 0)) if (x != null && (x[0].Length > 0 || x[1].Length > 0 || x[2].Length > 0 || x[3].Length > 0))
{ {
@@ -943,13 +943,13 @@ namespace MouseWithoutBorders
string menuCaption = (sender as ToolStripMenuItem).Text; string menuCaption = (sender as ToolStripMenuItem).Text;
// Send CaptureScreenCommand // Send CaptureScreenCommand
ID des = menuCaption.Equals("All", StringComparison.OrdinalIgnoreCase) ? ID.ALL : Common.IdFromName(menuCaption); ID des = menuCaption.Equals("All", StringComparison.OrdinalIgnoreCase) ? ID.ALL : MachineStuff.IdFromName(menuCaption);
Common.SendPackage(des, PackageType.CaptureScreenCommand); Common.SendPackage(des, PackageType.CaptureScreenCommand);
} }
private void FrmScreen_Shown(object sender, EventArgs e) private void FrmScreen_Shown(object sender, EventArgs e)
{ {
Common.AssertOneInstancePerDesktopSession(); MachineStuff.AssertOneInstancePerDesktopSession();
Common.MainForm = this; Common.MainForm = this;
Hide(); Hide();
@@ -1057,11 +1057,11 @@ namespace MouseWithoutBorders
r.Right = Common.ScreenWidth - (Common.ScreenWidth / 5); r.Right = Common.ScreenWidth - (Common.ScreenWidth / 5);
r.Bottom = 20; r.Bottom = 20;
for (int i = 0; i < Common.MAX_MACHINE; i++) for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
{ {
string newMachine = Common.MachineMatrix[i].Trim(); string newMachine = MachineStuff.MachineMatrix[i].Trim();
if (Common.MachinePool.TryFindMachineByName(newMachine, out MachineInf inf) && MachinePool.IsAlive(inf)) if (MachineStuff.MachinePool.TryFindMachineByName(newMachine, out MachineInf inf) && MachinePool.IsAlive(inf))
{ {
machineMatrix += "[" + inf.Name.Trim() + "]"; machineMatrix += "[" + inf.Name.Trim() + "]";
} }

View File

@@ -68,11 +68,6 @@ avgSendTime = 0
maxSendTime = 0 maxSendTime = 0
totalSendCount = 0 totalSendCount = 0
totalSendTime = 0 totalSendTime = 0
isDragging = False
dragDropStep05ExCalledByIpc = 0
isDropping = False
dragMachine = NONE
<MouseDown>k__BackingField = False
magicNumber = 0 magicNumber = 0
ran = System.Random ran = System.Random
--_impl = System.Random+XoshiroImpl --_impl = System.Random+XoshiroImpl
@@ -163,35 +158,6 @@ ReopenSocketDueToReadError = False
--MaxValue = 31/12/9999 23:59:59 --MaxValue = 31/12/9999 23:59:59
--UnixEpoch = 01/01/1970 00:00:00 --UnixEpoch = 01/01/1970 00:00:00
lastReleaseAllKeysCall = 0 lastReleaseAllKeysCall = 0
McMatrixLock = Lock
--_owningThreadId = 0
--_state = 0
--_recursionCount = 0
--_spinCount = 22
--_waiterStartTimeMs = 0
--s_contentionCount = 0
--s_maxSpinCount = 22
--s_minSpinCountForAdaptiveSpin = -100
desMachineID = NONE
DesMachineName =
newDesMachineID = NONE
newDesMachineIdEx = NONE
dropMachineID = NONE
lastJump = ????????????
desktopBounds = MouseWithoutBorders.MyRectangle
--Left = 0
--Top = 0
--Right = 0
--Bottom = 0
primaryScreenBounds = MouseWithoutBorders.MyRectangle
--Left = 0
--Top = 0
--Right = 0
--Bottom = 0
SwitchLocation = MouseWithoutBorders.Class.MouseLocation
--<X>k__BackingField = 0
--<Y>k__BackingField = 0
--<Count>k__BackingField = 0
PackageSent = MouseWithoutBorders.PackageMonitor PackageSent = MouseWithoutBorders.PackageMonitor
--Keyboard = 0 --Keyboard = 0
--Mouse = 0 --Mouse = 0
@@ -259,11 +225,6 @@ SymAlBlockSize = 16
PW_LENGTH = 16 PW_LENGTH = 16
HELPER_FORM_TEXT = Mouse without Borders Helper HELPER_FORM_TEXT = Mouse without Borders Helper
HelperProcessName = PowerToys.MouseWithoutBordersHelper HelperProcessName = PowerToys.MouseWithoutBordersHelper
MAX_MACHINE = 4
MAX_SOCKET = 8
HEARTBEAT_TIMEOUT = 1500000
SKIP_PIXELS = 1
JUMP_PIXELS = 2
PACKAGE_SIZE = 32 PACKAGE_SIZE = 32
PACKAGE_SIZE_EX = 64 PACKAGE_SIZE_EX = 64
WP_PACKAGE_SIZE = 6 WP_PACKAGE_SIZE = 6
@@ -358,6 +319,49 @@ MAX_LOG = 10000
MaxLogExceptionPerHour = 1000 MaxLogExceptionPerHour = 1000
HeaderSENT = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},Ie{12},Ni{13} HeaderSENT = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},Ie{12},Ni{13}
HeaderRECEIVED = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},In{12},Ni{13},Pc{14}/{15} HeaderRECEIVED = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},In{12},Ni{13},Pc{14}/{15}
[DragDrop]
===============
isDragging = False
dragDropStep05ExCalledByIpc = 0
isDropping = False
dragMachine = NONE
<MouseDown>k__BackingField = False
[MachineStuff]
===============
McMatrixLock = Lock
--_owningThreadId = 0
--_state = 0
--_recursionCount = 0
--_spinCount = 22
--_waiterStartTimeMs = 0
--s_contentionCount = 0
--s_maxSpinCount = 22
--s_minSpinCountForAdaptiveSpin = -100
desMachineID = NONE
DesMachineName =
newDesMachineID = NONE
newDesMachineIdEx = NONE
dropMachineID = NONE
lastJump = ????????????
desktopBounds = MouseWithoutBorders.Core.MyRectangle
--Left = 0
--Top = 0
--Right = 0
--Bottom = 0
primaryScreenBounds = MouseWithoutBorders.Core.MyRectangle
--Left = 0
--Top = 0
--Right = 0
--Bottom = 0
SwitchLocation = MouseWithoutBorders.Class.MouseLocation
--<X>k__BackingField = 0
--<Y>k__BackingField = 0
--<Count>k__BackingField = 0
MAX_MACHINE = 4
MAX_SOCKET = 8
HEARTBEAT_TIMEOUT = 1500000
SKIP_PIXELS = 1
JUMP_PIXELS = 2
[Receiver] [Receiver]
=============== ===============
QUEUE_SIZE = 50 QUEUE_SIZE = 50

View File

@@ -120,6 +120,10 @@ public static class LoggerTests
_ = Logger.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, settingsDumpObjectsLevel, false); _ = Logger.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, settingsDumpObjectsLevel, false);
sb.AppendLine("[Logger]\r\n==============="); sb.AppendLine("[Logger]\r\n===============");
Logger.DumpType(sb, typeof(Logger), 0, settingsDumpObjectsLevel); Logger.DumpType(sb, typeof(Logger), 0, settingsDumpObjectsLevel);
sb.AppendLine("[DragDrop]\r\n===============");
Logger.DumpType(sb, typeof(DragDrop), 0, settingsDumpObjectsLevel);
sb.AppendLine("[MachineStuff]\r\n===============");
Logger.DumpType(sb, typeof(MachineStuff), 0, settingsDumpObjectsLevel);
sb.AppendLine("[Receiver]\r\n==============="); sb.AppendLine("[Receiver]\r\n===============");
Logger.DumpType(sb, typeof(Receiver), 0, settingsDumpObjectsLevel); Logger.DumpType(sb, typeof(Receiver), 0, settingsDumpObjectsLevel);
var actual = sb.ToString(); var actual = sb.ToString();