[MWB]Migrate to PowerToys-style shortcuts and better defaults(#27442)

* [MWB] Migrate to PowerToys-style shortcuts and disable Ctrlx3 for multiple mode

* f: analyzer fixes

* f: add Win to all default shortcuts

* f: remove capture screen feature

* f: add ability to disable shortcut

* f: restrict disabling shortcuts only for MWB for now, because we don't explicitly support this feature anywhere else

* handle downgrade->upgrade scenario

* f: res loader

* f: fix disabled state

* f: fix L hotkey handling
This commit is contained in:
Andrey Nekrasov
2023-07-26 13:46:41 +02:00
committed by GitHub
parent 61aa0a1f79
commit a99b2e0bc0
13 changed files with 354 additions and 415 deletions

View File

@@ -23,6 +23,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public class MouseWithoutBordersProperties : ICloneable
{
public static HotkeySettings DefaultHotKeySwitch2AllPC => new HotkeySettings();
public static HotkeySettings DefaultHotKeyLockMachine => new HotkeySettings(true, true, true, false, 0x4C);
public static HotkeySettings DefaultHotKeyReconnect => new HotkeySettings(true, true, true, false, 0x52);
public static HotkeySettings DefaultHotKeyToggleEasyMouse => new HotkeySettings(true, true, true, false, 0x45);
public StringProperty SecurityKey { get; set; }
[JsonConverter(typeof(BoolPropertyJsonConverter))]
@@ -86,14 +94,30 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public IntProperty HotKeySwitchMachine { get; set; }
[ObsoleteAttribute("Use ToggleEasyMouseShortcut instead", false)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IntProperty HotKeyToggleEasyMouse { get; set; }
[ObsoleteAttribute("Use LockMachineShortcut instead", false)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IntProperty HotKeyLockMachine { get; set; }
[ObsoleteAttribute("Use ReconnectShortcut instead", false)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IntProperty HotKeyReconnect { get; set; }
[ObsoleteAttribute("Use Switch2AllPCShortcut instead", false)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IntProperty HotKeySwitch2AllPC { get; set; }
public HotkeySettings ToggleEasyMouseShortcut { get; set; }
public HotkeySettings LockMachineShortcut { get; set; }
public HotkeySettings ReconnectShortcut { get; set; }
public HotkeySettings Switch2AllPCShortcut { get; set; }
public IntProperty TCPPort { get; set; }
[JsonConverter(typeof(BoolPropertyJsonConverter))]
@@ -127,10 +151,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library
UseService = false;
HotKeySwitchMachine = new IntProperty(0x70); // VK.F1
HotKeyToggleEasyMouse = new IntProperty(0x45); // VK.E
HotKeyLockMachine = new IntProperty(0x4C); // VK.L
HotKeyReconnect = new IntProperty(0x52); // VK.R
HotKeySwitch2AllPC = new IntProperty(0); // Disabled
ToggleEasyMouseShortcut = DefaultHotKeyToggleEasyMouse;
LockMachineShortcut = DefaultHotKeyLockMachine;
ReconnectShortcut = DefaultHotKeyReconnect;
Switch2AllPCShortcut = DefaultHotKeySwitch2AllPC;
// These are internal, i.e. cannot be edited directly from UI
MachinePool = ":,:,:,:";

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
@@ -20,7 +21,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
Name = ModuleName;
Properties = new MouseWithoutBordersProperties();
Version = "1.0";
Version = "1.1";
}
public string GetModuleName()
@@ -28,10 +29,51 @@ namespace Microsoft.PowerToys.Settings.UI.Library
return Name;
}
public HotkeySettings ConvertMouseWithoutBordersHotKeyToPowerToys(int value)
{
// VK_A <= value <= VK_Z
if (value >= 0x41 && value <= 0x5A)
{
return new HotkeySettings(false, true, true, false, value);
}
else
{
// Disabled state
return new HotkeySettings(false, false, false, false, 0);
}
}
// This can be utilized in the future if the settings.json file is to be modified/deleted.
public bool UpgradeSettingsConfiguration()
{
#pragma warning disable CS0618 // We use obsolete members to upgrade them
bool downgradedThenUpgraded = Version != "1.0" && (Properties.HotKeyToggleEasyMouse != null ||
Properties.HotKeyLockMachine != null ||
Properties.HotKeyReconnect != null ||
Properties.HotKeySwitch2AllPC != null);
if (Version == "1.0" || downgradedThenUpgraded)
{
Version = "1.1";
Properties.ToggleEasyMouseShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeyToggleEasyMouse.Value);
Properties.LockMachineShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeyLockMachine.Value);
Properties.ReconnectShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeyReconnect.Value);
Properties.Switch2AllPCShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeySwitch2AllPC.Value);
Properties.HotKeyToggleEasyMouse = null;
Properties.HotKeyLockMachine = null;
Properties.HotKeyReconnect = null;
Properties.HotKeySwitch2AllPC = null;
return true;
}
return false;
#pragma warning restore CS0618
}
public virtual void Save(ISettingsUtils settingsUtils)