2023-05-15 23:32:26 +01:00
|
|
|
|
// 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;
|
2025-08-20 09:31:52 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-07-26 13:46:41 +02:00
|
|
|
|
using System.Diagnostics;
|
2023-05-15 23:32:26 +01:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
using System.Text.Json.Serialization;
|
2025-08-20 09:31:52 +08:00
|
|
|
|
using ManagedCommon;
|
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
2023-05-15 23:32:26 +01:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
|
|
|
|
|
{
|
2025-08-20 09:31:52 +08:00
|
|
|
|
public class MouseWithoutBordersSettings : BasePTModuleSettings, ISettingsConfig, IHotkeyConfig
|
2023-05-15 23:32:26 +01:00
|
|
|
|
{
|
|
|
|
|
|
public const string ModuleName = "MouseWithoutBorders";
|
|
|
|
|
|
|
2023-12-28 13:37:13 +03:00
|
|
|
|
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
WriteIndented = true,
|
|
|
|
|
|
MaxDepth = 0,
|
|
|
|
|
|
IncludeFields = true,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-05-15 23:32:26 +01:00
|
|
|
|
[JsonPropertyName("properties")]
|
|
|
|
|
|
public MouseWithoutBordersProperties Properties { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public MouseWithoutBordersSettings()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = ModuleName;
|
|
|
|
|
|
Properties = new MouseWithoutBordersProperties();
|
2023-07-26 13:46:41 +02:00
|
|
|
|
Version = "1.1";
|
2023-05-15 23:32:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetModuleName()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Name;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-20 09:31:52 +08:00
|
|
|
|
public ModuleType GetModuleType() => ModuleType.MouseWithoutBorders;
|
|
|
|
|
|
|
|
|
|
|
|
public HotkeyAccessor[] GetAllHotkeyAccessors()
|
|
|
|
|
|
{
|
|
|
|
|
|
var hotkeyAccessors = new List<HotkeyAccessor>
|
|
|
|
|
|
{
|
|
|
|
|
|
new HotkeyAccessor(
|
|
|
|
|
|
() => Properties.ToggleEasyMouseShortcut,
|
|
|
|
|
|
value => Properties.ToggleEasyMouseShortcut = value ?? MouseWithoutBordersProperties.DefaultHotKeyToggleEasyMouse,
|
|
|
|
|
|
"MouseWithoutBorders_ToggleEasyMouseShortcut"),
|
|
|
|
|
|
new HotkeyAccessor(
|
|
|
|
|
|
() => Properties.LockMachineShortcut,
|
|
|
|
|
|
value => Properties.LockMachineShortcut = value ?? MouseWithoutBordersProperties.DefaultHotKeyLockMachine,
|
|
|
|
|
|
"MouseWithoutBorders_LockMachinesShortcut"),
|
|
|
|
|
|
new HotkeyAccessor(
|
|
|
|
|
|
() => Properties.Switch2AllPCShortcut,
|
|
|
|
|
|
value => Properties.Switch2AllPCShortcut = value ?? MouseWithoutBordersProperties.DefaultHotKeySwitch2AllPC,
|
|
|
|
|
|
"MouseWithoutBorders_Switch2AllPcShortcut"),
|
|
|
|
|
|
new HotkeyAccessor(
|
|
|
|
|
|
() => Properties.ReconnectShortcut,
|
|
|
|
|
|
value => Properties.ReconnectShortcut = value ?? MouseWithoutBordersProperties.DefaultHotKeyReconnect,
|
|
|
|
|
|
"MouseWithoutBorders_ReconnectShortcut"),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return hotkeyAccessors.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-26 13:46:41 +02:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-15 23:32:26 +01:00
|
|
|
|
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
|
|
|
|
|
public bool UpgradeSettingsConfiguration()
|
|
|
|
|
|
{
|
2023-07-26 13:46:41 +02:00
|
|
|
|
#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";
|
|
|
|
|
|
|
2023-07-31 09:14:11 +01:00
|
|
|
|
if (Properties.HotKeyToggleEasyMouse != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Properties.ToggleEasyMouseShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeyToggleEasyMouse.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Properties.HotKeyLockMachine != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Properties.LockMachineShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeyLockMachine.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Properties.HotKeyReconnect != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Properties.ReconnectShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeyReconnect.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Properties.HotKeySwitch2AllPC != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Properties.Switch2AllPCShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeySwitch2AllPC.Value);
|
|
|
|
|
|
}
|
2023-07-26 13:46:41 +02:00
|
|
|
|
|
|
|
|
|
|
Properties.HotKeyToggleEasyMouse = null;
|
|
|
|
|
|
Properties.HotKeyLockMachine = null;
|
|
|
|
|
|
Properties.HotKeyReconnect = null;
|
|
|
|
|
|
Properties.HotKeySwitch2AllPC = null;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-15 23:32:26 +01:00
|
|
|
|
return false;
|
2023-07-26 13:46:41 +02:00
|
|
|
|
#pragma warning restore CS0618
|
2023-05-15 23:32:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-19 03:30:01 +01:00
|
|
|
|
public virtual void Save(SettingsUtils settingsUtils)
|
2023-05-15 23:32:26 +01:00
|
|
|
|
{
|
|
|
|
|
|
// Save settings to file
|
2023-12-28 13:37:13 +03:00
|
|
|
|
var options = _serializerOptions;
|
2023-05-15 23:32:26 +01:00
|
|
|
|
|
2023-11-22 12:46:59 -05:00
|
|
|
|
ArgumentNullException.ThrowIfNull(settingsUtils);
|
2023-05-15 23:32:26 +01:00
|
|
|
|
|
|
|
|
|
|
settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|