Skip to content

Commit

Permalink
[MWB] - fixing references to DragDrop - microsoft#35155
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed Jan 17, 2025
1 parent 5ba7139 commit 808f25c
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 74 deletions.
14 changes: 7 additions & 7 deletions src/modules/MouseWithoutBorders/App/Class/Common.Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,23 @@ internal static void PrepareToSwitchToMachine(ID newDesMachineID, Point desMachi
_ = EvSwitch.Set();

// 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
{
DragDropStep11();
DragDrop.DragDropStep11();
}

// Change des machine
Expand Down
2 changes: 1 addition & 1 deletion src/modules/MouseWithoutBorders/App/Class/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ internal static void PrepareScreenCapture()
{
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);
InputSimulation.SendKey(new KEYBDDATA() { wVk = (int)VK.SNAPSHOT });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void SendLog(string log)

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

public void SendClipboardData(ByteArrayOrString data, bool isFilePath)
Expand Down
6 changes: 3 additions & 3 deletions src/modules/MouseWithoutBorders/App/Class/InputHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private int MouseHookProc(int nCode, int wParam, IntPtr lParam)
if (MachineStuff.NewDesMachineID == Common.MachineID || MachineStuff.NewDesMachineID == ID.ALL)
{
local = true;
if (Common.MainFormVisible && !Common.IsDropping)
if (Common.MainFormVisible && !DragDrop.IsDropping)
{
Common.MainFormDot();
}
Expand Down Expand Up @@ -315,8 +315,8 @@ private int MouseHookProc(int nCode, int wParam, IntPtr lParam)

MouseEvent(hookCallbackMouseData, dx, dy);

Common.DragDropStep01(wParam);
Common.DragDropStep09(wParam);
DragDrop.DragDropStep01(wParam);
DragDrop.DragDropStep09(wParam);
}

if (local)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ internal static uint SendMouse(MOUSEDATA md)
rv = SendInputEx(mouse_input);
});

if (Common.MainFormVisible && !Common.IsDropping)
if (Common.MainFormVisible && !DragDrop.IsDropping)
{
Common.MainFormDot();
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/MouseWithoutBorders/App/Class/SocketStuff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,9 +1611,9 @@ internal static void SendOrReceiveClipboardData(Socket s)
{
string remoteEndPoint = s.RemoteEndPoint.ToString();
Logger.LogDebug("SendClipboardData: Request accepted: " + s.LocalEndPoint.ToString() + "/" + remoteEndPoint);
Common.IsDropping = false;
Common.IsDragging = false;
Common.DragMachine = (ID)1;
DragDrop.IsDropping = false;
DragDrop.IsDragging = false;
DragDrop.DragMachine = (ID)1;

bool clientPushData = true;
ClipboardPostAction postAction = ClipboardPostAction.Other;
Expand Down
96 changes: 48 additions & 48 deletions src/modules/MouseWithoutBorders/App/Core/DragDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ internal static class DragDrop

internal static bool IsDragging
{
get => Common.isDragging;
set => Common.isDragging = value;
get => DragDrop.isDragging;
set => DragDrop.isDragging = value;
}

internal static void DragDropStep01(int wParam)
Expand All @@ -70,34 +70,34 @@ internal static void DragDropStep01(int wParam)
return;
}

if (wParam == WM_LBUTTONDOWN)
if (wParam == Common.WM_LBUTTONDOWN)
{
MouseDown = true;
DragMachine = MachineStuff.desMachineID;
MachineStuff.dropMachineID = ID.NONE;
Logger.LogDebug("DragDropStep01: MouseDown");
}
else if (wParam == WM_LBUTTONUP)
else if (wParam == Common.WM_LBUTTONUP)
{
MouseDown = false;
Logger.LogDebug("DragDropStep01: MouseUp");
}

if (wParam == WM_RBUTTONUP && IsDropping)
if (wParam == Common.WM_RBUTTONUP && IsDropping)
{
IsDropping = false;
LastIDWithClipboardData = ID.NONE;
Common.LastIDWithClipboardData = ID.NONE;
}
}

internal static void DragDropStep02()
{
if (MachineStuff.desMachineID == MachineID)
if (MachineStuff.desMachineID == Common.MachineID)
{
Logger.LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent to myself");
DoSomethingInUIThread(() =>
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
else
Expand All @@ -109,21 +109,21 @@ internal static void DragDropStep02()

internal static void DragDropStep03(DATA package)
{
if (RunOnLogonDesktop || RunOnScrSaverDesktop)
if (Common.RunOnLogonDesktop || Common.RunOnScrSaverDesktop)
{
return;
}

if (package.Des == MachineID || package.Des == ID.ALL)
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...");
DoSomethingInUIThread(() =>
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
}
Expand All @@ -140,8 +140,8 @@ internal static void DragDropStep04()
{
_ = Interlocked.Exchange(ref dragDropStep05ExCalledByIpc, 0);

MainForm.Hide();
MainFormVisible = false;
Common.MainForm.Hide();
Common.MainFormVisible = false;

Point p = default;

Expand Down Expand Up @@ -185,7 +185,7 @@ internal static void DragDropStep05Ex(string dragFileName)

_ = Interlocked.Exchange(ref dragDropStep05ExCalledByIpc, 1);

if (RunOnLogonDesktop || RunOnScrSaverDesktop)
if (Common.RunOnLogonDesktop || Common.RunOnScrSaverDesktop)
{
return;
}
Expand All @@ -207,12 +207,12 @@ internal static void DragDropStep05Ex(string dragFileName)

DragDropStep06();
Logger.LogDebug("DragDropStep05: File dragging: " + dragFileName);
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_HIDE_DD_HELPER, (IntPtr)1, (IntPtr)0);
_ = NativeMethods.PostMessage(Common.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);
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_HIDE_DD_HELPER, (IntPtr)0, (IntPtr)0);
}

Logger.LogDebug("DragDropStep05: WM_HIDE_DDHelper sent");
Expand All @@ -222,7 +222,7 @@ internal static void DragDropStep05Ex(string dragFileName)
{
Logger.LogDebug("DragDropStep05: IsDropping == true, change drop machine...");
IsDropping = false;
MainFormVisible = true; // WM_HIDE_DRAG_DROP
Common.MainFormVisible = true; // WM_HIDE_DRAG_DROP
SendDropBegin(); // To dropMachineID set in DragDropStep03
}

Expand All @@ -245,25 +245,25 @@ internal static void DragDropStep08(DATA package)

internal static void DragDropStep08_2(DATA package)
{
if (package.Des == MachineID && !RunOnLogonDesktop && !RunOnScrSaverDesktop)
if (package.Des == Common.MachineID && !Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
{
IsDropping = true;
MachineStuff.dropMachineID = MachineID;
MachineStuff.dropMachineID = Common.MachineID;
Logger.LogDebug("DragDropStep08_2: ClipboardDragDropOperation Received. IsDropping set");
}
}

internal static void DragDropStep09(int wParam)
{
if (wParam == WM_MOUSEMOVE && IsDropping)
if (wParam == Common.WM_MOUSEMOVE && IsDropping)
{
// Show/Move form
DoSomethingInUIThread(() =>
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_SHOW_DRAG_DROP, (IntPtr)0, (IntPtr)0);
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_SHOW_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}
else if (wParam == WM_LBUTTONUP && (IsDropping || IsDragging))
else if (wParam == Common.WM_LBUTTONUP && (IsDropping || IsDragging))
{
if (IsDropping)
{
Expand All @@ -273,7 +273,7 @@ internal static void DragDropStep09(int wParam)
else
{
IsDragging = false;
LastIDWithClipboardData = ID.NONE;
Common.LastIDWithClipboardData = ID.NONE;
}
}
}
Expand All @@ -283,15 +283,15 @@ internal static void DragDropStep10()
Logger.LogDebug("DragDropStep10: Hide the form and get data...");
IsDropping = false;
IsDragging = false;
LastIDWithClipboardData = ID.NONE;
Common.LastIDWithClipboardData = ID.NONE;

DoSomethingInUIThread(() =>
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_HIDE_DRAG_DROP, (IntPtr)0, (IntPtr)0);
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_HIDE_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});

PowerToysTelemetry.Log.WriteEvent(new MouseWithoutBorders.Telemetry.MouseWithoutBordersDragAndDropEvent());
GetRemoteClipboard("desktop");
Common.GetRemoteClipboard("desktop");
}

internal static void DragDropStep11()
Expand All @@ -301,20 +301,20 @@ internal static void DragDropStep11()
IsDropping = false;
IsDragging = false;
DragMachine = (ID)1;
LastIDWithClipboardData = ID.NONE;
LastDragDropFile = null;
Common.LastIDWithClipboardData = ID.NONE;
Common.LastDragDropFile = null;
MouseDown = false;
}

internal static void DragDropStep12()
{
Logger.LogDebug("DragDropStep12: ClipboardDragDropEnd received");
IsDropping = false;
LastIDWithClipboardData = ID.NONE;
Common.LastIDWithClipboardData = ID.NONE;

DoSomethingInUIThread(() =>
Common.DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_HIDE_DRAG_DROP, (IntPtr)0, (IntPtr)0);
_ = NativeMethods.PostMessage(Common.MainForm.Handle, NativeMethods.WM_HIDE_DRAG_DROP, (IntPtr)0, (IntPtr)0);
});
}

Expand All @@ -332,18 +332,18 @@ internal static void SendCheckExplorerDragDrop()
package.Src = MachineStuff.newDesMachineID;

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

SkSend(package, null, false);
Common.SkSend(package, null, false);
}

private static void ChangeDropMachine()
internal static void ChangeDropMachine()
{
// desMachineID = current drop machine
// newDesMachineID = new drop machine

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

// 2. SendClipboardBeatDragDrop to new drop machine
// new drop machine is not me
if (MachineStuff.newDesMachineID != MachineID)
if (MachineStuff.newDesMachineID != Common.MachineID)
{
MachineStuff.dropMachineID = MachineStuff.newDesMachineID;
SendDropBegin();
Expand All @@ -371,20 +371,20 @@ private static void ChangeDropMachine()

internal static void SendClipboardBeatDragDrop()
{
SendPackage(ID.ALL, PackageType.ClipboardDragDrop);
Common.SendPackage(ID.ALL, PackageType.ClipboardDragDrop);
}

internal static void SendDropBegin()
{
Logger.LogDebug("SendDropBegin...");
SendPackage(MachineStuff.dropMachineID, PackageType.ClipboardDragDropOperation);
Common.SendPackage(MachineStuff.dropMachineID, PackageType.ClipboardDragDropOperation);
}

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

Expand All @@ -393,14 +393,14 @@ internal static void SendClipboardBeatDragDropEnd()

internal static ID DragMachine
{
get => Common.dragMachine;
set => Common.dragMachine = value;
get => DragDrop.dragMachine;
set => DragDrop.dragMachine = value;
}

internal static bool IsDropping
{
get => Common.isDropping;
set => Common.isDropping = value;
get => DragDrop.isDropping;
set => DragDrop.isDropping = value;
}

internal static bool MouseDown { get; set; }
Expand Down
Loading

0 comments on commit 808f25c

Please sign in to comment.