Skip to content

Conversation

@mikeclayton
Copy link
Contributor

@mikeclayton mikeclayton commented Jan 6, 2026

Summary of the Pull Request

Some focussed refactoring / simplifying / cleanup / delinting on the Mouse Without Borders codebase (see #44508 - [Mouse Without Borders] - de-linting codebase) now that the Common class has been broken down.

This PR does some cleaning up on the Logger class:

  • Uplifting coding style (string interpolation, pattern matching, var, etc)
  • Rationalising and simplifying code
  • Relocating e.g. IO and UI side effects (writing to disk, displaying dialog boxes) outside of Logger class
  • Removing dead code, tightening visibility of existing code
  • Added / updated tests to try to cover as much of the refactoring as possible to prevent regressions

I've split the changes into lots of small commits - it might be easier to review the individual commits rather than the whole PR in one go.

PR Checklist

  • Closes: #xxx
  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Run manual tests from Test Checklist Template:

  • Install PowerToys on two PCs in the same local network:

    • Verify that PowerToys is properly installed on both PCs.
    • Configure Windows Firewall Rules
      • netsh advfirewall firewall add rule name="PowerToys.MouseWithoutBorders - mc" dir=in action=allow program="C:\src\mc\PowerToys\x64\Debug\PowerToys.exe" enable=yes remoteip=any profile=any protocol=tcp
  • Setup Connection:

    • Open MWB's settings on the first PC and click the "New Key" button. Verify that a new security key is generated.
    • Copy the generated security key and paste it in the corresponding input field in the settings of MWB on the second PC. Also enter the name of the first PC in the required field.
    • Press "Connect" and verify that the machine layout now includes two PC tiles, each displaying their respective PC names.
  • Verify Connection Status:

    • Ensure that the border of the remote PC turns green, indicating a successful connection.
    • Enter an incorrect security key and verify that the border of the remote PC turns red, indicating a failed connection.
  • Test Remote Mouse/Keyboard Control:

    • With the PCs connected, test the mouse/keyboard control from one PC to another. Verify that the mouse/keyboard inputs are correctly registered on the other PC.
    • Test remote mouse/keyboard control across all four PCs, if available. Verify that inputs are correctly registered on each connected PC when the mouse is active there.
      • unable to test - only 2 machines available
  • Test Remote Control with Elevated Apps:

    • note - the main PowerToys.exe must be running as a non-admin for these tests
    • Open an elevated app on one of the PCs. Verify that without "Use Service" enabled, PowerToys does not control the elevated app.
    • Enable "Use Service" in MWB's settings (need to run PowerToys.exe as admin to enable "Use Service", then restart PowerToys.exe as non-admin). Verify that PowerToys can now control the elevated app remotely. Verify that MWB processes are running as LocalSystem, while the MWB helper process is running non-elevated.
      • get-process -Name "PowerToys.MouseWithoutBorders*" -IncludeUserName | format-table Id, ProcessName, UserName
      • Process: PowerToys.MouseWithoutBorders.exe - running as SYSTEM
      • Process: PowerToys.MouseWithoutBorders.Helper.exe - running as current user
      • get-service -Name "PowerToys.*" | ft Status, Name, UserName; get-ciminstance -Class "Win32_Service" -Filter "Name like 'PowerToys%'" | ft ProcessId, Name
      • Service: PowerToys.MWB.Service - running as Local System
    • Toggle "Use Service" again, verify that each time you do that, the MWB processes are restarted.
    • Run PowerToys elevated on one of the machines, verify that you can control elevated apps remotely now on that machine.
  • Test Module Enable Status:

    • For all combinations of "Use Service"/"Run PowerToys as admin", try enabling/disabling MWB module and verify that it's indeed being toggled using task manager.
  • Test Disconnection/Reconnection:

    • Disconnect one of the PCs from network. Verify that the machine layout updates to reflect the disconnection.
    • Do the same, but now by exiting PowerToys.
    • Start PowerToys again, verify that the PCs are reconnected.
  • Test Various Local Network Conditions:

    • Test MWB performance under various network conditions (e.g., low bandwidth, high latency). Verify that the tool maintains a stable connection and functions correctly.
  • Clipboard Sharing:

    • Copy some text on one PC and verify that the same text can be pasted on another PC.
    • Use the screenshot key and Win+Shift+S to take a screenshot on one PC and verify that the screenshot can be pasted on another PC.
    • Copy a file in Windows Explorer and verify that the file can be pasted on another PC. Make sure the file size is below 100MB.
    • Try to copy multiple files and directories and verify that it's not possible (only the first selected file is being copied).
  • Drag and Drop:

    • Drag a file from Windows Explorer on one PC, cross the screen border onto another PC, and release it there. Verify that the file is copied to the other PC. Make sure the file size is below 100MB.
    • While dragging the file, verify that a corresponding icon is displayed under the mouse cursor.
    • Without moving the mouse from one PC to the target PC, press CTRL+ALT+F1/2/3/4 hotkey to switch to the target PC directly and verify that file sharing/dropping is not working.
  • Lock and Unlock with "Use Service" Enabled:

    • Enable "Use Service" in MWB's settings.
    • Lock a remote PC using Win+L, move the mouse to it remotely, and try to unlock it. Verify that you can unlock the remote PC.
    • Disable "Use Service" in MWB's settings, lock the remote PC, move the mouse to it remotely, and try to unlock it. Verify that you can't unlock the remote PC.
  • Test Settings:

    • Change the rest of available settings on MWB page and verify that each setting works as described.

Group Policy Tests

See https://learn.microsoft.com/en-us/windows/powertoys/grouppolicy

  • Install *.admx / *.adml and check settings behave as expected
    • I'll expand the list of settings here when I get this far :-)
  • HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys
    • ConfigureEnabledUtilityMouseWithoutBorders
      • [missing] - "Activation -> Enable Mouse Without Borders" enabled, with GPO warning hidden
        • reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v ConfigureEnabledUtilityMouseWithoutBorders /f
      • 0 - "Activation -> Enable Mouse Without Borders" set to "off" and disabled, with GPO warning visible
        • reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v ConfigureEnabledUtilityMouseWithoutBorders /t REG_DWORD /d 0 /f
      • 1 - "Activation -> Enable Mouse Without Borders" set to "on" and disabled, with GPO warning visible
        • reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v ConfigureEnabledUtilityMouseWithoutBorders /t REG_DWORD /d 1 /f
    • MwbClipboardSharingEnabled
    • MwbFileTransferEnabled
    • MwbUseOriginalUserInterface
    • MwbDisallowBlockingScreensaver
    • MwbSameSubnetOnly
    • MwbValidateRemoteIp
    • MwbDisableUserDefinedIpMappingRules
      • [missing] - "Advanced Settings -> IP address mapping" enabled, with GPO warning hidden
        • reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v MwbDisableUserDefinedIpMappingRules /f
      • 0 - "Advanced Settings -> IP address mapping" enabled, with GPO warning hidden
        • reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v MwbDisableUserDefinedIpMappingRules /t REG_DWORD /d 0 /f
      • 1 - "Advanced Settings -> IP address mapping" disabled, with GPO warning visible
        • reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v MwbDisableUserDefinedIpMappingRules /t REG_DWORD /d 1 /f
    • MwbPolicyDefinedIpMappingRules
      • [missing] - "Advanced Settings -> IP address mapping" enabled, with GPO warning and GPO values hidden
        • reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v MwbPolicyDefinedIpMappingRules /f
      • [empty value] - "Advanced Settings -> IP address mapping" enabled, with GPO warning hidden and GPO values hidden
        • reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v MwbPolicyDefinedIpMappingRules /t REG_MULTI_SZ /d "" /f
      • [non-empty value] - "Advanced Settings -> IP address mapping" enabled, with GPO warning visible and GPO values visible
        • reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v MwbPolicyDefinedIpMappingRules /t REG_MULTI_SZ /d "aaa 10.0.0.1\0bbb 10.0.0.2" /f

@mikeclayton
Copy link
Contributor Author

@vanzue - I'm thinking about going through Mouse Without Borders and try to clean up some of the code in a series of focussed PRs like this one. From what I've been told, the original MWB code was ported like-for-like into PowerToys without any refactoring in order to avoid introducing any defects while it was being onboarded, but now that it's stable I figured it might be worth trying to do some light "modernising" to parts of it.

I'm not sure if this sort of refactoring work is going to be useful though, or if it's just going to create a testing overhead for releases without adding any new features.

My ultimate goal is to get to a point where I could implement this feature - #34126 - Integrate Mouse Jump with Mouse Without Borders to allow jumping to remote computers when MWB is enabled - but at the moment it would mean wrestling with some of the more complicated bits of the codebase. If I can simplify the existing code a bit first it might make that easier to do.

If this PR isn't a good use of the team's time though I'm happy to scrap it and delete this PR.

M

@vanzue
Copy link
Contributor

vanzue commented Jan 6, 2026

Thanks for the context and for taking the time to explain the motivation behind this.
The Mouse Jump + MWB integration you mentioned (#34126) would be a genuinely useful feature, and the rationale of first reducing complexity to make that work more approachable makes sense to me.
That said, even independent of that specific feature, ongoing, incremental efforts to clean up and modernize the MWB codebase are very welcome and appreciated in their own right, as long as the PRs stay focused, low-risk, and easy to reason about from a testing perspective. I’m happy to see this direction continue.

@vanzue vanzue added the Product-Mouse Without Borders Refers to the Mouse Without Borders module label Jan 6, 2026
@mikeclayton mikeclayton changed the title Dev/mikeclayton/mwb delinting WIP - [MouseWithoutBorders] - incremental code cleanup / refactor Jan 6, 2026
@mikeclayton
Copy link
Contributor Author

mikeclayton commented Jan 7, 2026

There's a couple of merge conflicts that didn't resolve properly that are making wonky changes to CmdPal and FancyZones - I'll fix those shortly...

@mikeclayton mikeclayton force-pushed the dev/mikeclayton/mwb-delinting branch from 84aed46 to abb26b6 Compare January 7, 2026 19:08
@mikeclayton
Copy link
Contributor Author

Update - wonky merge conflict fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Mouse Without Borders Refers to the Mouse Without Borders module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants