Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
[MouseWithoutBorders] - moving Common.Helper.cs -> Core\Helper.cs - #…
  • Loading branch information
mikeclayton committed Feb 21, 2025
commit f2087948a6828a088a796d67227d259c9b2d3904
526 changes: 0 additions & 526 deletions src/modules/MouseWithoutBorders/App/Class/Common.Helper.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ internal static void SetupMachineNameAndID()

internal static void Init()
{
_ = Common.GetUserName();
_ = Helper.GetUserName();
Common.GeneratedKey = true;

try
@@ -148,7 +148,7 @@ internal static void Init()

private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
Common.WndProcCounter++;
Helper.WndProcCounter++;

if (e.Mode is PowerModes.Resume or PowerModes.Suspend)
{
@@ -167,21 +167,21 @@ private static void CreateHelperThreads()
watchDogThread.Start();
*/

helper = new Thread(new ThreadStart(HelperThread), "Helper Thread");
helper = new Thread(new ThreadStart(Helper.HelperThread), "Helper Thread");
helper.SetApartmentState(ApartmentState.STA);
helper.Start();
}

private static void AskHelperThreadsToExit(int waitTime)
{
signalHelperToExit = true;
signalWatchDogToExit = true;
Helper.signalHelperToExit = true;
Helper.signalWatchDogToExit = true;
_ = EvSwitch.Set();

int c = 0;
if (helper != null && c < waitTime)
{
while (signalHelperToExit)
while (Helper.signalHelperToExit)
{
Thread.Sleep(1);
}
@@ -251,7 +251,7 @@ internal static void ReleaseAllKeys()
private static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
Logger.LogDebug("NetworkAvailabilityEventArgs.IsAvailable: " + e.IsAvailable.ToString(CultureInfo.InvariantCulture));
Common.WndProcCounter++;
Helper.WndProcCounter++;
ScheduleReopenSocketsDueToNetworkChanges(!e.IsAvailable);
}

2 changes: 1 addition & 1 deletion src/modules/MouseWithoutBorders/App/Class/Common.WinAPI.cs
Original file line number Diff line number Diff line change
@@ -279,7 +279,7 @@ internal static void CheckForDesktopSwitchEvent(bool cleanupIfExit)
{
if (!IsMyDesktopActive() || Common.CurrentProcess.SessionId != NativeMethods.WTSGetActiveConsoleSessionId())
{
Common.RunDDHelper(true);
Helper.RunDDHelper(true);
int waitCount = 20;

while (NativeMethods.WTSGetActiveConsoleSessionId() == 0xFFFFFFFF && waitCount > 0)
12 changes: 7 additions & 5 deletions src/modules/MouseWithoutBorders/App/Class/Common.cs
Original file line number Diff line number Diff line change
@@ -101,8 +101,10 @@ internal Common()
private static bool runOnLogonDesktop;
private static bool runOnScrSaverDesktop;

private static int[] toggleIcons;
private static int toggleIconsIndex;
#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter
internal static int[] toggleIcons;
internal static int toggleIconsIndex;
#pragma warning restore SA1307
internal const int TOGGLE_ICONS_SIZE = 4;
internal const int ICON_ONE = 0;
internal const int ICON_ALL = 1;
@@ -667,7 +669,7 @@ internal static void PrepareScreenCapture()
{
Common.DoSomethingInUIThread(() =>
{
if (!DragDrop.MouseDown && Common.SendMessageToHelper(0x401, IntPtr.Zero, IntPtr.Zero) > 0)
if (!DragDrop.MouseDown && Helper.SendMessageToHelper(0x401, IntPtr.Zero, IntPtr.Zero) > 0)
{
Common.MMSleep(0.2);
InputSimulation.SendKey(new KEYBDDATA() { wVk = (int)VK.SNAPSHOT });
@@ -676,14 +678,14 @@ internal static void PrepareScreenCapture()
Logger.LogDebug("PrepareScreenCapture: SNAPSHOT simulated.");

_ = NativeMethods.MoveWindow(
(IntPtr)NativeMethods.FindWindow(null, Common.HELPER_FORM_TEXT),
(IntPtr)NativeMethods.FindWindow(null, Helper.HELPER_FORM_TEXT),
MachineStuff.DesktopBounds.Left,
MachineStuff.DesktopBounds.Top,
MachineStuff.DesktopBounds.Right - MachineStuff.DesktopBounds.Left,
MachineStuff.DesktopBounds.Bottom - MachineStuff.DesktopBounds.Top,
false);

_ = Common.SendMessageToHelper(0x406, IntPtr.Zero, IntPtr.Zero, false);
_ = Helper.SendMessageToHelper(0x406, IntPtr.Zero, IntPtr.Zero, false);
}
else
{
2 changes: 1 addition & 1 deletion src/modules/MouseWithoutBorders/App/Class/InputHook.cs
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ private int MouseHookProc(int nCode, int wParam, IntPtr lParam)
local = true;
if (Common.MainFormVisible && !DragDrop.IsDropping)
{
Common.MainFormDot();
Helper.MainFormDot();
}
}

Original file line number Diff line number Diff line change
@@ -223,7 +223,7 @@ internal static uint SendMouse(MOUSEDATA md)

if (Common.MainFormVisible && !DragDrop.IsDropping)
{
Common.MainFormDot();
Helper.MainFormDot();
}

return rv;
5 changes: 3 additions & 2 deletions src/modules/MouseWithoutBorders/App/Class/Program.cs
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
using StreamJsonRpc;

using Logger = MouseWithoutBorders.Core.Logger;
using SettingsHelper = Microsoft.PowerToys.Settings.UI.Library.Utilities.Helper;
using Thread = MouseWithoutBorders.Core.Thread;

[module: SuppressMessage("Microsoft.MSInternal", "CA904:DeclareTypesInMicrosoftOrSystemNamespace", Scope = "namespace", Target = "MouseWithoutBorders", Justification = "Dotnet port with style preservation")]
@@ -128,7 +129,7 @@ private static void Main()
{
if (args.Length > 2)
{
Helper.UserLocalAppDataPath = args[2].Trim();
SettingsHelper.UserLocalAppDataPath = args[2].Trim();
}
}

@@ -235,7 +236,7 @@ private static void Main()
Application.SetCompatibleTextRenderingDefault(false);

Common.Init();
Common.WndProcCounter++;
Core.Helper.WndProcCounter++;

var formScreen = new FrmScreen();

3 changes: 2 additions & 1 deletion src/modules/MouseWithoutBorders/App/Class/Setting.cs
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
using Settings.UI.Library.Attributes;

using Lock = System.Threading.Lock;
using SettingsHelper = Microsoft.PowerToys.Settings.UI.Library.Utilities.Helper;

[module: SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "MouseWithoutBorders.Properties.Setting.Values.#LoadIntSetting(System.String,System.Int32)", Justification = "Dotnet port with style preservation")]
[module: SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "MouseWithoutBorders.Properties.Setting.Values.#SaveSetting(System.String,System.Object)", Justification = "Dotnet port with style preservation")]
@@ -193,7 +194,7 @@ internal Settings()
{
_settingsUtils = new SettingsUtils();

_watcher = Helper.GetFileWatcher("MouseWithoutBorders", "settings.json", () =>
_watcher = SettingsHelper.GetFileWatcher("MouseWithoutBorders", "settings.json", () =>
{
try
{
2 changes: 1 addition & 1 deletion src/modules/MouseWithoutBorders/App/Core/DragDrop.cs
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ internal static void DragDropStep04()
{
if (!IsDropping)
{
IntPtr h = (IntPtr)NativeMethods.FindWindow(null, Common.HELPER_FORM_TEXT);
IntPtr h = (IntPtr)NativeMethods.FindWindow(null, Helper.HELPER_FORM_TEXT);
if (h.ToInt32() > 0)
{
_ = Interlocked.Exchange(ref dragDropStep05ExCalledByIpc, 0);
Loading
Oops, something went wrong.