[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

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using CommunityToolkit.WinUI.UI;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.UI.Xaml;
@@ -33,9 +34,39 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register("Enabled", typeof(bool), typeof(ShortcutControl), null);
public static readonly DependencyProperty HotkeySettingsProperty = DependencyProperty.Register("HotkeySettings", typeof(HotkeySettings), typeof(ShortcutControl), null);
public static readonly DependencyProperty AllowDisableProperty = DependencyProperty.Register("AllowDisable", typeof(bool), typeof(ShortcutControl), new PropertyMetadata(false, OnAllowDisableChanged));
private static void OnAllowDisableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var me = d as ShortcutControl;
if (me == null)
{
return;
}
var description = me.c?.FindDescendant<TextBlock>();
if (description == null)
{
return;
}
var resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
var newValue = (bool)(e?.NewValue ?? false);
var text = newValue ? resourceLoader.GetString("Activation_Shortcut_With_Disable_Description") : resourceLoader.GetString("Activation_Shortcut_Description");
description.Text = text;
}
private ShortcutDialogContentControl c = new ShortcutDialogContentControl();
private ContentDialog shortcutDialog;
public bool AllowDisable
{
get => (bool)GetValue(AllowDisableProperty);
set => SetValue(AllowDisableProperty, value);
}
public bool Enabled
{
get
@@ -106,9 +137,12 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
};
shortcutDialog.PrimaryButtonClick += ShortcutDialog_PrimaryButtonClick;
shortcutDialog.SecondaryButtonClick += ShortcutDialog_Reset;
shortcutDialog.RightTapped += ShortcutDialog_Disable;
shortcutDialog.Opened += ShortcutDialog_Opened;
shortcutDialog.Closing += ShortcutDialog_Closing;
AutomationProperties.SetName(EditButton, resourceLoader.GetString("Activation_Shortcut_Title"));
OnAllowDisableChanged(this, null);
}
private void ShortcutControl_Unloaded(object sender, RoutedEventArgs e)
@@ -381,6 +415,21 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
shortcutDialog.Hide();
}
private void ShortcutDialog_Disable(object sender, RightTappedRoutedEventArgs e)
{
if (!AllowDisable)
{
return;
}
var empty = new HotkeySettings();
HotkeySettings = empty;
PreviewKeysControl.ItemsSource = HotkeySettings.GetKeysList();
AutomationProperties.SetHelpText(EditButton, HotkeySettings.ToString());
shortcutDialog.Hide();
}
private static bool ComboIsValid(HotkeySettings settings)
{
if (settings != null && (settings.IsValid() || settings.IsEmpty()))

View File

@@ -18,7 +18,6 @@
</Grid.RowDefinitions>
<TextBlock
x:Uid="Activation_Shortcut_Description"
Grid.Row="0" />
<ItemsControl

View File

@@ -254,131 +254,40 @@
<ComboBoxItem x:Uid="MouseWithoutBorders_EasyMouseOption_Shift" />
</ComboBox>
</labs:SettingsCard>
<labs:SettingsCard x:Uid="MouseWithoutBorders_ToggleEasyMouseShortcut">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.ToggleEasyMouseShortcutIndex, Mode=TwoWay}">
<ComboBoxItem x:Uid="MouseWithoutBorders_ToggleEasyMouseShortcut_Disabled" />
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
<ComboBoxItem>D</ComboBoxItem>
<ComboBoxItem>E</ComboBoxItem>
<ComboBoxItem>F</ComboBoxItem>
<ComboBoxItem>G</ComboBoxItem>
<ComboBoxItem>H</ComboBoxItem>
<ComboBoxItem>I</ComboBoxItem>
<ComboBoxItem>J</ComboBoxItem>
<ComboBoxItem>K</ComboBoxItem>
<ComboBoxItem>L</ComboBoxItem>
<ComboBoxItem>M</ComboBoxItem>
<ComboBoxItem>N</ComboBoxItem>
<ComboBoxItem>O</ComboBoxItem>
<ComboBoxItem>P</ComboBoxItem>
<ComboBoxItem>Q</ComboBoxItem>
<ComboBoxItem>R</ComboBoxItem>
<ComboBoxItem>S</ComboBoxItem>
<ComboBoxItem>T</ComboBoxItem>
<ComboBoxItem>U</ComboBoxItem>
<ComboBoxItem>V</ComboBoxItem>
<ComboBoxItem>W</ComboBoxItem>
<ComboBoxItem>X</ComboBoxItem>
<ComboBoxItem>Y</ComboBoxItem>
<ComboBoxItem>Z</ComboBoxItem>
</ComboBox>
<labs:SettingsCard x:Uid="MouseWithoutBorders_ToggleEasyMouseShortcut"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xEDA7;}">
<controls:ShortcutControl
AllowDisable="True"
MinWidth="{StaticResource SettingActionControlMinWidth}"
HotkeySettings="{x:Bind Path=ViewModel.ToggleEasyMouseShortcut, Mode=TwoWay}" />
</labs:SettingsCard>
<labs:SettingsCard x:Uid="MouseWithoutBorders_LockMachinesShortcut">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.LockMachinesShortcutIndex, Mode=TwoWay}">
<ComboBoxItem x:Uid="MouseWithoutBorders_LockMachinesShortcut_Disabled" />
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
<ComboBoxItem>D</ComboBoxItem>
<ComboBoxItem>E</ComboBoxItem>
<ComboBoxItem>F</ComboBoxItem>
<ComboBoxItem>G</ComboBoxItem>
<ComboBoxItem>H</ComboBoxItem>
<ComboBoxItem>I</ComboBoxItem>
<ComboBoxItem>J</ComboBoxItem>
<ComboBoxItem>K</ComboBoxItem>
<ComboBoxItem>L</ComboBoxItem>
<ComboBoxItem>M</ComboBoxItem>
<ComboBoxItem>N</ComboBoxItem>
<ComboBoxItem>O</ComboBoxItem>
<ComboBoxItem>P</ComboBoxItem>
<ComboBoxItem>Q</ComboBoxItem>
<ComboBoxItem>R</ComboBoxItem>
<ComboBoxItem>S</ComboBoxItem>
<ComboBoxItem>T</ComboBoxItem>
<ComboBoxItem>U</ComboBoxItem>
<ComboBoxItem>V</ComboBoxItem>
<ComboBoxItem>W</ComboBoxItem>
<ComboBoxItem>X</ComboBoxItem>
<ComboBoxItem>Y</ComboBoxItem>
<ComboBoxItem>Z</ComboBoxItem>
</ComboBox>
<labs:SettingsCard x:Uid="MouseWithoutBorders_LockMachinesShortcut"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xEDA7;}">
<controls:ShortcutControl
AllowDisable="True"
MinWidth="{StaticResource SettingActionControlMinWidth}"
HotkeySettings="{x:Bind Path=ViewModel.LockMachinesShortcut, Mode=TwoWay}" />
</labs:SettingsCard>
<labs:SettingsCard x:Uid="MouseWithoutBorders_ReconnectShortcut">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.ReconnectShortcutIndex, Mode=TwoWay}">
<ComboBoxItem x:Uid="MouseWithoutBorders_ReconnectShortcut_Disabled" />
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
<ComboBoxItem>D</ComboBoxItem>
<ComboBoxItem>E</ComboBoxItem>
<ComboBoxItem>F</ComboBoxItem>
<ComboBoxItem>G</ComboBoxItem>
<ComboBoxItem>H</ComboBoxItem>
<ComboBoxItem>I</ComboBoxItem>
<ComboBoxItem>J</ComboBoxItem>
<ComboBoxItem>K</ComboBoxItem>
<ComboBoxItem>L</ComboBoxItem>
<ComboBoxItem>M</ComboBoxItem>
<ComboBoxItem>N</ComboBoxItem>
<ComboBoxItem>O</ComboBoxItem>
<ComboBoxItem>P</ComboBoxItem>
<ComboBoxItem>Q</ComboBoxItem>
<ComboBoxItem>R</ComboBoxItem>
<ComboBoxItem>S</ComboBoxItem>
<ComboBoxItem>T</ComboBoxItem>
<ComboBoxItem>U</ComboBoxItem>
<ComboBoxItem>V</ComboBoxItem>
<ComboBoxItem>W</ComboBoxItem>
<ComboBoxItem>X</ComboBoxItem>
<ComboBoxItem>Y</ComboBoxItem>
<ComboBoxItem>Z</ComboBoxItem>
</ComboBox>
</labs:SettingsCard>
<labs:SettingsCard x:Uid="MouseWithoutBorders_Switch2AllPcShortcut">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.Switch2AllPcShortcutIndex, Mode=TwoWay}">
<ComboBoxItem x:Uid="MouseWithoutBorders_Switch2AllPcShortcut_Disabled" />
<ComboBoxItem x:Uid="MouseWithoutBorders_Switch2AllPcShortcut_Ctrl3" />
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
<ComboBoxItem>D</ComboBoxItem>
<ComboBoxItem>E</ComboBoxItem>
<ComboBoxItem>F</ComboBoxItem>
<ComboBoxItem>G</ComboBoxItem>
<ComboBoxItem>H</ComboBoxItem>
<ComboBoxItem>I</ComboBoxItem>
<ComboBoxItem>J</ComboBoxItem>
<ComboBoxItem>K</ComboBoxItem>
<ComboBoxItem>L</ComboBoxItem>
<ComboBoxItem>M</ComboBoxItem>
<ComboBoxItem>N</ComboBoxItem>
<ComboBoxItem>O</ComboBoxItem>
<ComboBoxItem>P</ComboBoxItem>
<ComboBoxItem>Q</ComboBoxItem>
<ComboBoxItem>R</ComboBoxItem>
<ComboBoxItem>S</ComboBoxItem>
<ComboBoxItem>T</ComboBoxItem>
<ComboBoxItem>U</ComboBoxItem>
<ComboBoxItem>V</ComboBoxItem>
<ComboBoxItem>W</ComboBoxItem>
<ComboBoxItem>X</ComboBoxItem>
<ComboBoxItem>Y</ComboBoxItem>
<ComboBoxItem>Z</ComboBoxItem>
</ComboBox>
<labs:SettingsCard x:Uid="MouseWithoutBorders_Switch2AllPcShortcut"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xEDA7;}">
<controls:ShortcutControl
AllowDisable="True"
MinWidth="{StaticResource SettingActionControlMinWidth}"
HotkeySettings="{x:Bind Path=ViewModel.HotKeySwitch2AllPC, Mode=TwoWay}" />
</labs:SettingsCard>
<labs:SettingsCard
x:Uid="MouseWithoutBorders_ReconnectShortcut"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xEDA7;}">
<controls:ShortcutControl
AllowDisable="True"
MinWidth="{StaticResource SettingActionControlMinWidth}"
HotkeySettings="{x:Bind Path=ViewModel.ReconnectShortcut, Mode=TwoWay}" />
</labs:SettingsCard>
<labs:SettingsCard x:Uid="MouseWithoutBorders_SwitchBetweenMachineShortcut" HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xE92E;}">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.SelectedSwitchBetweenMachineShortcutOptionsIndex, Mode=TwoWay}">
<!-- These should be in the same order as the array items in MouseWithoutBordersViewModel.cs -->

View File

@@ -420,8 +420,14 @@
<value>Shift</value>
<comment>This is the Shift keyboard key</comment>
</data>
<data name="MouseWithoutBorders_LockMachinesShortcut.Header" xml:space="preserve">
<value>Shortcut to lock all machines.</value>
</data>
<data name="MouseWithoutBorders_LockMachinesShortcut.Description" xml:space="preserve">
<value>Hit this hotkey twice to lock all machines. Note: Only the machines which have the same shortcut configured will be locked.</value>
</data>
<data name="MouseWithoutBorders_ToggleEasyMouseShortcut.Header" xml:space="preserve">
<value>Shortcut to toggle Easy Mouse. Ctrl+Alt+:</value>
<value>Shortcut to toggle Easy Mouse.</value>
<comment>Ctrl and Alt are the keyboard keys</comment>
</data>
<data name="MouseWithoutBorders_ToggleEasyMouseShortcut.Description" xml:space="preserve">
@@ -449,35 +455,23 @@
<data name="MouseWithoutBorders_SwitchBetweenMachineShortcut_Disabled.Content" xml:space="preserve">
<value>Disabled</value>
</data>
<data name="MouseWithoutBorders_LockMachinesShortcut.Header" xml:space="preserve">
<value>Shortcut to press twice quickly to lock all machines. Ctrl+Alt+:</value>
<comment>Ctrl and Alt are the keyboard keys</comment>
</data>
<data name="MouseWithoutBorders_LockMachinesShortcut.Description" xml:space="preserve">
<value>Click on Ctrl+Alt+ the chosen option twice quickly to lock all machines. Note: Only the machines which have the same shortcut configured will be locked.</value>
<comment>Ctrl and Alt are the keyboard keys</comment>
</data>
<data name="MouseWithoutBorders_LockMachinesShortcut_Disabled.Content" xml:space="preserve">
<value>Disabled</value>
</data>
<data name="MouseWithoutBorders_ReconnectShortcut.Header" xml:space="preserve">
<value>Shortcut to try reconnecting. Ctrl+Alt+:</value>
<comment>Ctrl and Alt are the keyboard keys</comment>
<value>Shortcut to try reconnecting</value>
</data>
<data name="MouseWithoutBorders_ReconnectShortcut.Description" xml:space="preserve">
<value>Click on Ctrl+Alt+ the chosen option to reconnect.</value>
<comment>Ctrl and Alt are the keyboard keys</comment>
<value>Just in case the connection is lost for any reason.</value>
</data>
<data name="MouseWithoutBorders_ReconnectShortcut_Disabled.Content" xml:space="preserve">
<value>Disabled</value>
</data>
<data name="MouseWithoutBorders_Switch2AllPcShortcut.Header" xml:space="preserve">
<value>Shortcut to switch to multiple machine mode. Ctrl+Alt+:</value>
<comment>Ctrl and Alt are the keyboard keys</comment>
<value>Shortcut to switch to multiple machine mode.</value>
</data>
<data name="MouseWithoutBorders_Switch2AllPcShortcut.Description" xml:space="preserve">
<value>Allows controlling all computers at once. Pressing Ctrl three times is also an option.</value>
<comment>This is the Ctrl keyboard key</comment>
<value>Allows controlling all computers at once.</value>
</data>
<data name="MouseWithoutBorders_Switch2AllPcShortcut_Disabled.Content" xml:space="preserve">
<value>Disabled</value>
@@ -2471,8 +2465,12 @@ From there, simply click on one of the supported files in the File Explorer and
<data name="Activation_Shortcut_Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="Activation_Shortcut_Description.Text" xml:space="preserve">
<value>Press a combination of keys to change this shortcut</value>
<data name="Activation_Shortcut_Description" xml:space="preserve">
<value>Press a combination of keys to change this shortcut</value>
</data>
<data name="Activation_Shortcut_With_Disable_Description" xml:space="preserve">
<value>Press a combination of keys to change this shortcut.
Right-click to remove the key combination, thereby deactivating the shortcut.</value>
</data>
<data name="Activation_Shortcut_Reset" xml:space="preserve">
<value>Reset</value>

View File

@@ -276,7 +276,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
catch (Exception ex)
{
Logger.LogError($"Couldn't create SettingsSync: {ex}");
if (IsEnabled)
{
Logger.LogError($"Couldn't create SettingsSync: {ex}");
}
return null;
}
}
@@ -475,10 +479,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
/* TODO: Error handling */
_selectedSwitchBetweenMachineShortcutOptionsIndex = Array.IndexOf(_switchBetweenMachineShortcutOptions, moduleSettings.Properties.HotKeySwitchMachine.Value);
_easyMouseOptionIndex = (EasyMouseOption)moduleSettings.Properties.EasyMouse.Value;
_toggleEasyMouseShortcutIndex = ConvertMouseWithoutBordersHotKeyValueToIndex(moduleSettings.Properties.HotKeyToggleEasyMouse.Value);
_lockMachinesShortcutIndex = ConvertMouseWithoutBordersHotKeyValueToIndex(moduleSettings.Properties.HotKeyLockMachine.Value);
_reconnectShortcutIndex = ConvertMouseWithoutBordersHotKeyValueToIndex(moduleSettings.Properties.HotKeyReconnect.Value);
_switch2AllPcShortcutIndex = ConvertMouseWithoutBordersHotKeyValueToIndex(moduleSettings.Properties.HotKeySwitch2AllPC.Value, 1);
LoadMachineMatrixString();
}
@@ -822,111 +823,60 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public int ConvertMouseWithoutBordersHotKeyValueToIndex(int value, int additionalOptions = 0)
public HotkeySettings ToggleEasyMouseShortcut
{
if (value >= 0x41 && value <= 0x5A)
{
return value - 0x40 + additionalOptions; /* VK_A <= value <= VK_Z */
}
if (value <= additionalOptions)
{
return value;
}
return 0; /* Disabled */
}
public int ConvertMouseWithoutBordersHotKeyIndexToValue(int index, int additionalOptions = 0)
{
if (index >= additionalOptions + 1 && index <= additionalOptions + 26)
{
return index + 0x40 - additionalOptions; /* VK_A to VK_Z */
}
if (index <= additionalOptions)
{
return index;
}
return 0; /* Disabled */
}
private int _toggleEasyMouseShortcutIndex;
public int ToggleEasyMouseShortcutIndex
{
get
{
return _toggleEasyMouseShortcutIndex;
}
get => Settings.Properties.ToggleEasyMouseShortcut;
set
{
if (_toggleEasyMouseShortcutIndex != value)
if (Settings.Properties.ToggleEasyMouseShortcut != value)
{
_toggleEasyMouseShortcutIndex = value;
Settings.Properties.HotKeyToggleEasyMouse.Value = ConvertMouseWithoutBordersHotKeyIndexToValue(value);
Settings.Properties.ToggleEasyMouseShortcut = value ?? MouseWithoutBordersProperties.DefaultHotKeyToggleEasyMouse;
NotifyPropertyChanged();
}
}
}
private int _lockMachinesShortcutIndex;
public int LockMachinesShortcutIndex
public HotkeySettings LockMachinesShortcut
{
get
{
return _lockMachinesShortcutIndex;
}
get => Settings.Properties.LockMachineShortcut;
set
{
if (_lockMachinesShortcutIndex != value)
if (Settings.Properties.LockMachineShortcut != value)
{
_lockMachinesShortcutIndex = value;
Settings.Properties.HotKeyLockMachine.Value = ConvertMouseWithoutBordersHotKeyIndexToValue(value);
Settings.Properties.LockMachineShortcut = value;
Settings.Properties.LockMachineShortcut = value ?? MouseWithoutBordersProperties.DefaultHotKeyLockMachine;
NotifyPropertyChanged();
}
}
}
private int _reconnectShortcutIndex;
public int ReconnectShortcutIndex
public HotkeySettings ReconnectShortcut
{
get
{
return _reconnectShortcutIndex;
}
get => Settings.Properties.ReconnectShortcut;
set
{
if (_reconnectShortcutIndex != value)
if (Settings.Properties.ReconnectShortcut != value)
{
_reconnectShortcutIndex = value;
Settings.Properties.HotKeyReconnect.Value = ConvertMouseWithoutBordersHotKeyIndexToValue(value);
Settings.Properties.ReconnectShortcut = value;
Settings.Properties.ReconnectShortcut = value ?? MouseWithoutBordersProperties.DefaultHotKeyReconnect;
NotifyPropertyChanged();
}
}
}
private int _switch2AllPcShortcutIndex;
public int Switch2AllPcShortcutIndex
public HotkeySettings HotKeySwitch2AllPC
{
get
{
return _switch2AllPcShortcutIndex;
}
get => Settings.Properties.Switch2AllPCShortcut;
set
{
if (_switch2AllPcShortcutIndex != value)
if (Settings.Properties.Switch2AllPCShortcut != value)
{
_switch2AllPcShortcutIndex = value;
Settings.Properties.HotKeySwitch2AllPC.Value = ConvertMouseWithoutBordersHotKeyIndexToValue(value, 1);
Settings.Properties.Switch2AllPCShortcut = value;
Settings.Properties.Switch2AllPCShortcut = value ?? MouseWithoutBordersProperties.DefaultHotKeySwitch2AllPC;
NotifyPropertyChanged();
}
}