Cmdpal Powertoys Extension: Support mouse without borders easy mouse … (#45350)

## Description

You don't have to go to powertoys settings to 
* toggle the mouse move from machine to another
* you can trigger reconnect when connection lost from cmdpal
* You can toggle whether kbm is turning on or not from cmdpal

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Add several missing cmd to powretoys cmdpal extension


<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **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
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed


https://github.com/user-attachments/assets/9ea019f7-988b-4542-afc5-a80f0fc99ef8

For the kbm toggle, when it's off, kbm will not map anything, if it's
on, kbm will take effect

For the mouse without borders, add these two functionality as command
<img width="1182" height="158" alt="image"
src="https://github.com/user-attachments/assets/27f526b1-9c91-4923-be6c-e505673f5892"
/>

And verified for the two command, works as expected
This commit is contained in:
Kai Tao
2026-03-09 10:25:11 +08:00
committed by GitHub
parent f6b0996c9b
commit 3d69785ca4
28 changed files with 574 additions and 24 deletions

View File

@@ -229,6 +229,7 @@ namespace MouseWithoutBorders.Class
if (!Common.RunOnLogonDesktop)
{
StartSettingSyncThread();
CommandEventHandler.StartListening();
}
Application.EnableVisualStyles();

View File

@@ -0,0 +1,114 @@
// 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.Threading;
using MouseWithoutBorders.Class;
using PowerToys.Interop;
namespace MouseWithoutBorders.Core
{
/// <summary>
/// Handles command events from external sources (e.g., Command Palette).
/// Uses named events for inter-process communication, following the same pattern as other PowerToys modules.
/// </summary>
internal static class CommandEventHandler
{
private static CancellationTokenSource _cancellationTokenSource;
/// <summary>
/// Starts listening for command events on background threads.
/// </summary>
public static void StartListening()
{
_cancellationTokenSource = new CancellationTokenSource();
CancellationToken exitToken = _cancellationTokenSource.Token;
// Start listener for Toggle Easy Mouse event
StartEventListener(Constants.MWBToggleEasyMouseEvent(), ToggleEasyMouse, exitToken);
// Start listener for Reconnect event
StartEventListener(Constants.MWBReconnectEvent(), Reconnect, exitToken);
}
/// <summary>
/// Stops listening for command events.
/// </summary>
public static void StopListening()
{
_cancellationTokenSource?.Cancel();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = null;
}
private static void StartEventListener(string eventName, Action callback, CancellationToken cancel)
{
new System.Threading.Thread(() =>
{
try
{
using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
WaitHandle[] waitHandles = new WaitHandle[] { cancel.WaitHandle, eventHandle };
while (!cancel.IsCancellationRequested)
{
int result = WaitHandle.WaitAny(waitHandles);
if (result == 1)
{
// Execute callback on UI thread using Common.DoSomethingInUIThread
Common.DoSomethingInUIThread(callback);
}
else
{
// Cancellation requested
return;
}
}
}
catch (Exception ex)
{
Logger.Log($"Error in event listener for {eventName}: {ex.Message}");
}
})
{ IsBackground = true, Name = $"MWB-{eventName}-Listener" }.Start();
}
/// <summary>
/// Toggles Easy Mouse between Enabled and Disabled states.
/// This is the same logic used by the hotkey handler.
/// </summary>
public static void ToggleEasyMouse()
{
if (Common.RunOnLogonDesktop || Common.RunOnScrSaverDesktop)
{
return;
}
EasyMouseOption easyMouseOption = (EasyMouseOption)Setting.Values.EasyMouse;
if (easyMouseOption is EasyMouseOption.Disable or EasyMouseOption.Enable)
{
Setting.Values.EasyMouse = (int)(easyMouseOption == EasyMouseOption.Disable ? EasyMouseOption.Enable : EasyMouseOption.Disable);
Common.ShowToolTip($"Easy Mouse has been toggled to [{(EasyMouseOption)Setting.Values.EasyMouse}].", 3000);
Logger.Log($"Easy Mouse toggled to {(EasyMouseOption)Setting.Values.EasyMouse} via command event.");
}
}
/// <summary>
/// Initiates a reconnection attempt to all machines.
/// This is the same logic used by the hotkey handler.
/// </summary>
public static void Reconnect()
{
Common.ShowToolTip("Reconnecting...", 2000);
Common.LastReconnectByHotKeyTime = Common.GetTick();
InitAndCleanup.PleaseReopenSocket = InitAndCleanup.REOPEN_WHEN_HOTKEY;
Logger.Log("Reconnect initiated via command event.");
}
}
}

View File

@@ -218,6 +218,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<rect x="2.25" y="4.25" width="19.5" height="12.5" rx="2.5" fill="#5F5F5F"/>
<rect x="4.5" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="7.1" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="9.7" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="12.3" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="14.9" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="17.5" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="4.5" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="7.6" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="10.7" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="13.8" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="16.9" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="4.5" y="12.25" width="10.9" height="1.9" rx="0.4" fill="#FFFFFF"/>
<rect x="16.1" y="12.25" width="3.3" height="1.9" rx="0.4" fill="#FFFFFF"/>
<circle cx="18.5" cy="18.5" r="4.5" fill="#C50F1F"/>
<path d="M16.35 18.5h4.3" fill="none" stroke="#FFFFFF" stroke-linecap="round" stroke-width="1.5"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<rect x="2.25" y="4.25" width="19.5" height="12.5" rx="2.5" fill="#0078D4"/>
<rect x="4.5" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="7.1" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="9.7" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="12.3" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="14.9" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="17.5" y="6.75" width="1.9" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="4.5" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="7.6" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="10.7" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="13.8" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="16.9" y="9.5" width="2.4" height="1.75" rx="0.35" fill="#FFFFFF"/>
<rect x="4.5" y="12.25" width="10.9" height="1.9" rx="0.4" fill="#FFFFFF"/>
<rect x="16.1" y="12.25" width="3.3" height="1.9" rx="0.4" fill="#FFFFFF"/>
<circle cx="18.5" cy="18.5" r="4.5" fill="#107C10"/>
<path d="M16.55 18.4l1.35 1.35 2.6-3.05" fill="none" stroke="#FFFFFF" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.45"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,24 @@
// 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 Microsoft.CommandPalette.Extensions.Toolkit;
using PowerToysExtension.Helpers;
using PowerToysExtension.Properties;
namespace PowerToysExtension.Commands;
internal sealed partial class ToggleKeyboardManagerListeningCommand : InvokableCommand
{
public ToggleKeyboardManagerListeningCommand()
{
Name = "Toggle Keyboard Manager active state";
}
public override CommandResult Invoke()
{
return KeyboardManagerStateService.TryToggleListening()
? CommandResult.KeepOpen()
: CommandResult.ShowToast(Resources.ResourceManager.GetString("KeyboardManager_ToggleListening_Error", Resources.Culture) ?? "Keyboard Manager is unavailable. Try enabling it in PowerToys settings.");
}
}

View File

@@ -0,0 +1,35 @@
// 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.Threading;
using Microsoft.CommandPalette.Extensions.Toolkit;
using PowerToys.Interop;
namespace PowerToysExtension.Commands;
/// <summary>
/// Triggers a reconnection attempt in Mouse Without Borders via the shared event.
/// </summary>
internal sealed partial class MWBReconnectCommand : InvokableCommand
{
public MWBReconnectCommand()
{
Name = "Mouse Without Borders: Reconnect";
}
public override CommandResult Invoke()
{
try
{
using var evt = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.MWBReconnectEvent());
evt.Set();
return CommandResult.Dismiss();
}
catch (Exception ex)
{
return CommandResult.ShowToast($"Failed to reconnect Mouse Without Borders: {ex.Message}");
}
}
}

View File

@@ -0,0 +1,35 @@
// 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.Threading;
using Microsoft.CommandPalette.Extensions.Toolkit;
using PowerToys.Interop;
namespace PowerToysExtension.Commands;
/// <summary>
/// Toggles Easy Mouse feature in Mouse Without Borders via the shared event.
/// </summary>
internal sealed partial class ToggleMWBEasyMouseCommand : InvokableCommand
{
public ToggleMWBEasyMouseCommand()
{
Name = "Mouse Without Borders: Toggle Easy Mouse";
}
public override CommandResult Invoke()
{
try
{
using var evt = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.MWBToggleEasyMouseEvent());
evt.Set();
return CommandResult.Dismiss();
}
catch (Exception ex)
{
return CommandResult.ShowToast($"Failed to toggle Easy Mouse: {ex.Message}");
}
}
}

View File

@@ -0,0 +1,80 @@
// 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.Threading;
using PowerToys.Interop;
namespace PowerToysExtension.Helpers;
internal static class KeyboardManagerStateService
{
private static readonly object Sync = new();
private static readonly Timer PollingTimer;
private static bool _lastKnownListeningState = IsListening();
internal static event Action? StatusChanged;
static KeyboardManagerStateService()
{
PollingTimer = new Timer(
static _ => PollStatus(),
null,
TimeSpan.FromMilliseconds(500),
TimeSpan.FromMilliseconds(500));
}
internal static bool IsListening()
{
try
{
if (Mutex.TryOpenExisting(Constants.KeyboardManagerEngineInstanceMutex(), out var mutex))
{
mutex.Dispose();
return true;
}
}
catch
{
// The engine mutex is best-effort state. Treat failures as not listening.
}
return false;
}
internal static bool TryToggleListening()
{
try
{
using var evt = EventWaitHandle.OpenExisting(Constants.ToggleKeyboardManagerActiveEvent());
var signaled = evt.Set();
PollStatus();
return signaled;
}
catch
{
return false;
}
}
private static void PollStatus()
{
var isListening = IsListening();
var raiseChanged = false;
lock (Sync)
{
if (isListening != _lastKnownListeningState)
{
_lastKnownListeningState = isListening;
raiseChanged = true;
}
}
if (raiseChanged)
{
StatusChanged?.Invoke();
}
}
}

View File

@@ -9,11 +9,21 @@ namespace PowerToysExtension.Helpers;
internal static class PowerToysResourcesHelper
{
private const string AssetsRoot = "Assets\\";
private const string SettingsIconRoot = "WinUI3Apps\\Assets\\Settings\\Icons\\";
internal static IconInfo IconFromSettingsIcon(string fileName) => IconHelpers.FromRelativePath($"{SettingsIconRoot}{fileName}");
internal static IconInfo KeyboardManagerListeningIcon(bool isListening) => IconHelpers.FromRelativePath(
isListening
? $"{AssetsRoot}KeyboardManager\\KeyboardManagerListeningOn.svg"
: $"{AssetsRoot}KeyboardManager\\KeyboardManagerListeningOff.svg");
#if DEBUG
public static IconInfo ProviderIcon() => IconFromSettingsIcon("PowerToys.dark.png");
#else
public static IconInfo ProviderIcon() => IconFromSettingsIcon("PowerToys.png");
#endif
public static IconInfo ModuleIcon(this SettingsWindow module)
{

View File

@@ -30,6 +30,10 @@
<Content Include="..\..\..\..\settings-ui\Settings.UI\Assets\Settings\Icons\*.png" Link="WinUI3Apps\Assets\Settings\Icons\%(Filename)%(Extension)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<!-- Monochrome icons from PowerToys Run Plugin for debug mode differentiation -->
<Content Include="..\..\..\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.PowerToys\Images\PowerToys.dark.png" Link="WinUI3Apps\Assets\Settings\Icons\PowerToys.dark.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
@@ -77,6 +81,20 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Remove="Assets\KeyboardManager\KeyboardManagerListeningOn.svg" />
<None Remove="Assets\KeyboardManager\KeyboardManagerListeningOff.svg" />
</ItemGroup>
<ItemGroup>
<Content Update="Assets\KeyboardManager\KeyboardManagerListeningOn.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\KeyboardManager\KeyboardManagerListeningOff.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<PropertyGroup>
<!-- Always build/publish AOT so the extension ships as native code -->
<SelfContained>true</SelfContained>

View File

@@ -18,8 +18,22 @@ internal sealed class KeyboardManagerModuleCommandProvider : ModuleCommandProvid
{
public override IEnumerable<ListItem> BuildCommands()
{
var title = SettingsWindow.KBM.ModuleDisplayName();
var icon = SettingsWindow.KBM.ModuleIcon();
var module = SettingsWindow.KBM;
var title = module.ModuleDisplayName();
var icon = module.ModuleIcon();
if (ModuleEnablementService.IsModuleEnabled(module))
{
var isListening = KeyboardManagerStateService.IsListening();
yield return new ListItem(new ToggleKeyboardManagerListeningCommand() { Id = "com.microsoft.powertoys.keyboardManager.toggleListening" })
{
Title = GetResourceString("KeyboardManager_ToggleListening_Title", "Keyboard Manager: Toggle active state"),
Subtitle = isListening
? GetResourceString("KeyboardManager_ToggleListening_On_Subtitle", "Keyboard Manager is active. Invoke to stop listening.")
: GetResourceString("KeyboardManager_ToggleListening_Off_Subtitle", "Keyboard Manager is paused. Invoke to start listening."),
Icon = PowerToysResourcesHelper.KeyboardManagerListeningIcon(isListening),
};
}
if (IsUseNewEditorEnabled())
{
@@ -31,7 +45,7 @@ internal sealed class KeyboardManagerModuleCommandProvider : ModuleCommandProvid
};
}
yield return new ListItem(new OpenInSettingsCommand(SettingsWindow.KBM, title) { Id = "com.microsoft.powertoys.keyboardManager.openSettings" })
yield return new ListItem(new OpenInSettingsCommand(module, title) { Id = "com.microsoft.powertoys.keyboardManager.openSettings" })
{
Title = title,
Subtitle = Resources.KeyboardManager_Settings_Subtitle,
@@ -39,6 +53,11 @@ internal sealed class KeyboardManagerModuleCommandProvider : ModuleCommandProvid
};
}
private static string GetResourceString(string resourceName, string fallback)
{
return Resources.ResourceManager.GetString(resourceName, Resources.Culture) ?? fallback;
}
private static bool IsUseNewEditorEnabled()
{
try

View File

@@ -17,6 +17,8 @@ internal sealed class MouseWithoutBordersModuleCommandProvider : ModuleCommandPr
{
var title = SettingsWindow.MouseWithoutBorders.ModuleDisplayName();
var icon = SettingsWindow.MouseWithoutBorders.ModuleIcon();
var easyMouseIcon = new IconInfo("\uE962");
var reconnectIcon = new IconInfo("\uE72C");
yield return new ListItem(new OpenInSettingsCommand(SettingsWindow.MouseWithoutBorders, title) { Id = "com.microsoft.powertoys.mouseWithoutBorders.openSettings" })
{
@@ -24,5 +26,19 @@ internal sealed class MouseWithoutBordersModuleCommandProvider : ModuleCommandPr
Subtitle = Resources.MouseWithoutBorders_Settings_Subtitle,
Icon = icon,
};
yield return new ListItem(new ToggleMWBEasyMouseCommand())
{
Title = Resources.MouseWithoutBorders_ToggleEasyMouse_Title,
Subtitle = Resources.MouseWithoutBorders_ToggleEasyMouse_Subtitle,
Icon = easyMouseIcon,
};
yield return new ListItem(new MWBReconnectCommand())
{
Title = Resources.MouseWithoutBorders_Reconnect_Title,
Subtitle = Resources.MouseWithoutBorders_Reconnect_Subtitle,
Icon = reconnectIcon,
};
}
}

View File

@@ -14,7 +14,7 @@ internal sealed partial class PowerToysExtensionPage : ListPage
{
public PowerToysExtensionPage()
{
Icon = Helpers.PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png");
Icon = Helpers.PowerToysResourcesHelper.ProviderIcon();
Title = Resources.PowerToys_DisplayName;
Name = Resources.PowerToysExtension_CommandsName;
}

View File

@@ -15,20 +15,21 @@ internal sealed partial class PowerToysListPage : ListPage
public PowerToysListPage()
{
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png");
Icon = PowerToysResourcesHelper.ProviderIcon();
Name = Title = Resources.PowerToys_DisplayName;
Id = "com.microsoft.cmdpal.powertoys";
SettingsChangeNotifier.SettingsChanged += OnSettingsChanged;
SettingsChangeNotifier.SettingsChanged += OnItemsChanged;
KeyboardManagerStateService.StatusChanged += OnItemsChanged;
_empty = new CommandItem()
{
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png"),
Icon = PowerToysResourcesHelper.ProviderIcon(),
Title = Resources.PowerToys_NoMatchingModule,
Subtitle = SearchText,
};
EmptyContent = _empty;
}
private void OnSettingsChanged()
private void OnItemsChanged()
{
RaiseItemsChanged(0);
}

View File

@@ -16,7 +16,7 @@ public sealed partial class PowerToysCommandsProvider : CommandProvider
public PowerToysCommandsProvider()
{
DisplayName = Resources.PowerToys_DisplayName;
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png");
Icon = PowerToysResourcesHelper.ProviderIcon();
}
public override ICommandItem[] TopLevelCommands() =>

View File

@@ -17,7 +17,7 @@ public partial class PowerToysExtensionCommandsProvider : CommandProvider
public PowerToysExtensionCommandsProvider()
{
DisplayName = Resources.PowerToys_DisplayName;
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png");
Icon = PowerToysResourcesHelper.ProviderIcon();
_commands = [
new CommandItem(new Pages.PowerToysListPage())
{
@@ -25,6 +25,9 @@ public partial class PowerToysExtensionCommandsProvider : CommandProvider
Subtitle = Resources.PowerToys_Subtitle,
},
];
SettingsChangeNotifier.SettingsChanged += RaiseModuleItemsChanged;
KeyboardManagerStateService.StatusChanged += RaiseModuleItemsChanged;
}
public override ICommandItem[] TopLevelCommands()
@@ -63,4 +66,9 @@ public partial class PowerToysExtensionCommandsProvider : CommandProvider
return null;
}
private void RaiseModuleItemsChanged()
{
RaiseItemsChanged();
}
}

View File

@@ -1014,6 +1014,42 @@ namespace PowerToysExtension.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Toggle Easy Mouse.
/// </summary>
internal static string MouseWithoutBorders_ToggleEasyMouse_Title {
get {
return ResourceManager.GetString("MouseWithoutBorders_ToggleEasyMouse_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Toggle easy mouse switching between machines.
/// </summary>
internal static string MouseWithoutBorders_ToggleEasyMouse_Subtitle {
get {
return ResourceManager.GetString("MouseWithoutBorders_ToggleEasyMouse_Subtitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Reconnect.
/// </summary>
internal static string MouseWithoutBorders_Reconnect_Title {
get {
return ResourceManager.GetString("MouseWithoutBorders_Reconnect_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Reconnect to other machines.
/// </summary>
internal static string MouseWithoutBorders_Reconnect_Subtitle {
get {
return ResourceManager.GetString("MouseWithoutBorders_Reconnect_Subtitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Open New+ settings.
/// </summary>

View File

@@ -414,6 +414,18 @@
<data name="KeyboardManager_OpenNewEditor_Subtitle" xml:space="preserve">
<value>Open the Keyboard Manager remap editor</value>
</data>
<data name="KeyboardManager_ToggleListening_Title" xml:space="preserve">
<value>Keyboard Manager: Toggle active state</value>
</data>
<data name="KeyboardManager_ToggleListening_On_Subtitle" xml:space="preserve">
<value>Keyboard Manager is active. Invoke to stop listening.</value>
</data>
<data name="KeyboardManager_ToggleListening_Off_Subtitle" xml:space="preserve">
<value>Keyboard Manager is paused. Invoke to start listening.</value>
</data>
<data name="KeyboardManager_ToggleListening_Error" xml:space="preserve">
<value>Keyboard Manager is unavailable. Try enabling it in PowerToys settings.</value>
</data>
<!-- Light Switch Module -->
<data name="LightSwitch_Toggle_Title" xml:space="preserve">
<value>Light Switch: Toggle theme</value>
@@ -462,6 +474,18 @@
<data name="MouseWithoutBorders_Settings_Subtitle" xml:space="preserve">
<value>Open Mouse Without Borders settings</value>
</data>
<data name="MouseWithoutBorders_ToggleEasyMouse_Title" xml:space="preserve">
<value>Toggle Easy Mouse</value>
</data>
<data name="MouseWithoutBorders_ToggleEasyMouse_Subtitle" xml:space="preserve">
<value>Mouse Without Borders: Toggle Easy Mouse feature on/off</value>
</data>
<data name="MouseWithoutBorders_Reconnect_Title" xml:space="preserve">
<value>Reconnect</value>
</data>
<data name="MouseWithoutBorders_Reconnect_Subtitle" xml:space="preserve">
<value>Mouse Without Borders: Reconnect to all machines</value>
</data>
<!-- New+ Module -->
<data name="NewPlus_Settings_Subtitle" xml:space="preserve">
<value>Open New+ settings</value>
@@ -640,3 +664,4 @@
<value>N/A</value>
</data>
</root>

View File

@@ -12,7 +12,7 @@
#include <keyboardmanager/KeyboardManagerEngineLibrary/trace.h>
#include <common/interop/shared_constants.h>
const std::wstring instanceMutexName = L"Local\\PowerToys_KBMEngine_InstanceMutex";
const std::wstring instanceMutexName = CommonSharedConstants::KEYBOARD_MANAGER_ENGINE_INSTANCE_MUTEX;
int WINAPI wWinMain(_In_ HINSTANCE /*hInstance*/,
_In_opt_ HINSTANCE /*hPrevInstance*/,
@@ -90,3 +90,4 @@ int WINAPI wWinMain(_In_ HINSTANCE /*hInstance*/,
return 0;
}

View File

@@ -73,6 +73,7 @@ private:
HANDLE m_hTerminateEngineEvent = nullptr;
HANDLE m_open_new_editor_event_handle{ nullptr };
HANDLE m_toggle_active_event_handle{ nullptr };
std::thread m_toggle_thread;
std::atomic<bool> m_toggle_thread_running{ false };
@@ -87,6 +88,19 @@ private:
}
}
void toggle_engine()
{
refresh_process_state();
if (m_active)
{
stop_engine();
}
else
{
start_engine();
}
}
bool start_engine()
{
refresh_process_state();
@@ -273,6 +287,7 @@ public:
}
m_open_new_editor_event_handle = CreateDefaultEvent(CommonSharedConstants::OPEN_NEW_KEYBOARD_MANAGER_EVENT);
m_toggle_active_event_handle = CreateDefaultEvent(CommonSharedConstants::TOGGLE_KEYBOARD_MANAGER_ACTIVE_EVENT);
init_settings();
};
@@ -291,6 +306,11 @@ public:
CloseHandle(m_open_new_editor_event_handle);
m_open_new_editor_event_handle = nullptr;
}
if (m_toggle_active_event_handle)
{
CloseHandle(m_toggle_active_event_handle);
m_toggle_active_event_handle = nullptr;
}
if (m_hEditorProcess)
{
CloseHandle(m_hEditorProcess);
@@ -422,25 +442,45 @@ public:
void StartOpenEditorListener()
{
if (m_toggle_thread_running || !m_open_new_editor_event_handle)
if (m_toggle_thread_running || (!m_open_new_editor_event_handle && !m_toggle_active_event_handle))
{
return;
}
m_toggle_thread_running = true;
m_toggle_thread = std::thread([this]() {
HANDLE handles[2]{};
DWORD handle_count = 0;
DWORD open_editor_index = MAXDWORD;
DWORD toggle_active_index = MAXDWORD;
if (m_open_new_editor_event_handle)
{
open_editor_index = handle_count;
handles[handle_count++] = m_open_new_editor_event_handle;
}
if (m_toggle_active_event_handle)
{
toggle_active_index = handle_count;
handles[handle_count++] = m_toggle_active_event_handle;
}
while (m_toggle_thread_running)
{
const DWORD wait_result = WaitForSingleObject(m_open_new_editor_event_handle, 500);
const DWORD wait_result = WaitForMultipleObjects(handle_count, handles, FALSE, 500);
if (!m_toggle_thread_running)
{
break;
}
if (wait_result == WAIT_OBJECT_0)
if (open_editor_index != MAXDWORD && wait_result == (WAIT_OBJECT_0 + open_editor_index))
{
launch_editor();
ResetEvent(m_open_new_editor_event_handle);
}
else if (toggle_active_index != MAXDWORD && wait_result == (WAIT_OBJECT_0 + toggle_active_index))
{
toggle_engine();
}
}
});
@@ -458,6 +498,10 @@ public:
{
SetEvent(m_open_new_editor_event_handle);
}
if (m_toggle_active_event_handle)
{
SetEvent(m_toggle_active_event_handle);
}
if (m_toggle_thread.joinable())
{
m_toggle_thread.join();
@@ -551,15 +595,7 @@ public:
if (hotkeyId == 0)
{
// Toggle engine on/off
refresh_process_state();
if (m_active)
{
stop_engine();
}
else
{
start_engine();
}
toggle_engine();
}
else if (hotkeyId == 1)
{
@@ -575,3 +611,4 @@ extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
{
return new KeyboardManager();
}