[MouseUtils]Auto activate setting for highlighter and crosshairs (#27826)

* auto activate for mouse highlighter and crosshairs

* revert changed encoding
This commit is contained in:
Davide Giacometti
2023-08-08 18:01:23 +02:00
committed by GitHub
parent a49f806ac7
commit 8e712c6f49
11 changed files with 112 additions and 9 deletions

View File

@@ -534,6 +534,11 @@ int MouseHighlighterMain(HINSTANCE hInstance, MouseHighlighterSettings settings)
}
Logger::info("Initialized the highlighter instance.");
if (settings.autoActivate)
{
highlighter.SwitchActivationMode();
}
MSG msg;
// Main message loop:

View File

@@ -7,6 +7,7 @@ const winrt::Windows::UI::Color MOUSE_HIGHLIGHTER_DEFAULT_ALWAYS_COLOR = winrt::
constexpr int MOUSE_HIGHLIGHTER_DEFAULT_RADIUS = 20;
constexpr int MOUSE_HIGHLIGHTER_DEFAULT_DELAY_MS = 500;
constexpr int MOUSE_HIGHLIGHTER_DEFAULT_DURATION_MS = 250;
constexpr bool MOUSE_HIGHLIGHTER_DEFAULT_AUTO_ACTIVATE = false;
struct MouseHighlighterSettings
{
@@ -16,6 +17,7 @@ struct MouseHighlighterSettings
int radius = MOUSE_HIGHLIGHTER_DEFAULT_RADIUS;
int fadeDelayMs = MOUSE_HIGHLIGHTER_DEFAULT_DELAY_MS;
int fadeDurationMs = MOUSE_HIGHLIGHTER_DEFAULT_DURATION_MS;
bool autoActivate = MOUSE_HIGHLIGHTER_DEFAULT_AUTO_ACTIVATE;
};
int MouseHighlighterMain(HINSTANCE hinst, MouseHighlighterSettings settings);

View File

@@ -17,6 +17,7 @@ namespace
const wchar_t JSON_KEY_HIGHLIGHT_RADIUS[] = L"highlight_radius";
const wchar_t JSON_KEY_HIGHLIGHT_FADE_DELAY_MS[] = L"highlight_fade_delay_ms";
const wchar_t JSON_KEY_HIGHLIGHT_FADE_DURATION_MS[] = L"highlight_fade_duration_ms";
const wchar_t JSON_KEY_AUTO_ACTIVATE[] = L"auto_activate";
}
extern "C" IMAGE_DOS_HEADER __ImageBase;
@@ -356,6 +357,16 @@ public:
{
Logger::warn("Failed to initialize Fade Duration from settings. Will use default value");
}
try
{
// Parse auto activate
auto jsonPropertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_AUTO_ACTIVATE);
highlightSettings.autoActivate = jsonPropertiesObject.GetNamedBoolean(JSON_KEY_VALUE);
}
catch (...)
{
Logger::warn("Failed to initialize auto activate from settings. Will use default value");
}
}
else
{

View File

@@ -548,6 +548,11 @@ int InclusiveCrosshairsMain(HINSTANCE hInstance, InclusiveCrosshairsSettings& se
}
Logger::info("Initialized the crosshairs instance.");
if (settings.autoActivate)
{
crosshairs.SwitchActivationMode();
}
MSG msg;
// Main message loop:

View File

@@ -10,6 +10,7 @@ constexpr int INCLUSIVE_MOUSE_DEFAULT_CROSSHAIRS_BORDER_SIZE = 1;
constexpr bool INCLUSIVE_MOUSE_DEFAULT_AUTO_HIDE = false;
constexpr bool INCLUSIVE_MOUSE_DEFAULT_CROSSHAIRS_IS_FIXED_LENGTH_ENABLED = false;
constexpr int INCLUSIVE_MOUSE_DEFAULT_CROSSHAIRS_FIXED_LENGTH = 1;
constexpr bool INCLUSIVE_MOUSE_DEFAULT_AUTO_ACTIVATE = false;
struct InclusiveCrosshairsSettings
{
@@ -22,6 +23,7 @@ struct InclusiveCrosshairsSettings
bool crosshairsAutoHide = INCLUSIVE_MOUSE_DEFAULT_AUTO_HIDE;
bool crosshairsIsFixedLengthEnabled = INCLUSIVE_MOUSE_DEFAULT_CROSSHAIRS_IS_FIXED_LENGTH_ENABLED;
int crosshairsFixedLength = INCLUSIVE_MOUSE_DEFAULT_CROSSHAIRS_FIXED_LENGTH;
bool autoActivate = INCLUSIVE_MOUSE_DEFAULT_AUTO_ACTIVATE;
};
int InclusiveCrosshairsMain(HINSTANCE hinst, InclusiveCrosshairsSettings& settings);

View File

@@ -20,6 +20,7 @@ namespace
const wchar_t JSON_KEY_CROSSHAIRS_AUTO_HIDE[] = L"crosshairs_auto_hide";
const wchar_t JSON_KEY_CROSSHAIRS_IS_FIXED_LENGTH_ENABLED[] = L"crosshairs_is_fixed_length_enabled";
const wchar_t JSON_KEY_CROSSHAIRS_FIXED_LENGTH[] = L"crosshairs_fixed_length";
const wchar_t JSON_KEY_AUTO_ACTIVATE[] = L"auto_activate";
}
extern "C" IMAGE_DOS_HEADER __ImageBase;
@@ -337,7 +338,7 @@ public:
{
// Parse auto hide
auto jsonPropertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_CROSSHAIRS_AUTO_HIDE);
inclusiveCrosshairsSettings.crosshairsAutoHide = static_cast<bool>(jsonPropertiesObject.GetNamedBoolean(JSON_KEY_VALUE));
inclusiveCrosshairsSettings.crosshairsAutoHide = jsonPropertiesObject.GetNamedBoolean(JSON_KEY_VALUE);
}
catch (...)
{
@@ -372,6 +373,16 @@ public:
{
Logger::warn("Failed to initialize fixed length from settings. Will use default value");
}
try
{
// Parse auto activate
auto jsonPropertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_AUTO_ACTIVATE);
inclusiveCrosshairsSettings.autoActivate = jsonPropertiesObject.GetNamedBoolean(JSON_KEY_VALUE);
}
catch (...)
{
Logger::warn("Failed to initialize auto activate from settings. Will use default value");
}
}
else
{

View File

@@ -34,6 +34,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("highlight_fade_duration_ms")]
public IntProperty HighlightFadeDurationMs { get; set; }
[JsonPropertyName("auto_activate")]
public BoolProperty AutoActivate { get; set; }
public MouseHighlighterProperties()
{
ActivationShortcut = DefaultActivationShortcut;
@@ -44,6 +47,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
HighlightRadius = new IntProperty(20);
HighlightFadeDelayMs = new IntProperty(500);
HighlightFadeDurationMs = new IntProperty(250);
AutoActivate = new BoolProperty(false);
}
}
}

View File

@@ -40,6 +40,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("crosshairs_fixed_length")]
public IntProperty CrosshairsFixedLength { get; set; }
[JsonPropertyName("auto_activate")]
public BoolProperty AutoActivate { get; set; }
public MousePointerCrosshairsProperties()
{
ActivationShortcut = DefaultActivationShortcut;
@@ -52,6 +55,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
CrosshairsAutoHide = new BoolProperty(false);
CrosshairsIsFixedLengthEnabled = new BoolProperty(false);
CrosshairsFixedLength = new IntProperty(1);
AutoActivate = new BoolProperty(false);
}
}
}

View File

@@ -149,14 +149,22 @@
IsOpen="{x:Bind Mode=OneWay, Path=ViewModel.IsHighlighterEnabledGpoConfigured}"
IsTabStop="{x:Bind Mode=OneWay, Path=ViewModel.IsHighlighterEnabledGpoConfigured}"
Severity="Informational" />
<labs:SettingsCard
<labs:SettingsExpander
x:Uid="MouseUtils_MouseHighlighter_ActivationShortcut"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xEDA7;}"
IsEnabled="{x:Bind ViewModel.IsMouseHighlighterEnabled, Mode=OneWay}">
IsEnabled="{x:Bind ViewModel.IsMouseHighlighterEnabled, Mode=OneWay}"
IsExpanded="True">
<controls:ShortcutControl
MinWidth="{StaticResource SettingActionControlMinWidth}"
HotkeySettings="{x:Bind Path=ViewModel.MouseHighlighterActivationShortcut, Mode=TwoWay}" />
</labs:SettingsCard>
<labs:SettingsExpander.Items>
<labs:SettingsCard ContentAlignment="Left">
<CheckBox
x:Uid="MouseUtils_AutoActivate"
IsChecked="{x:Bind ViewModel.MouseHighlighterAutoActivate, Mode=TwoWay}" />
</labs:SettingsCard>
</labs:SettingsExpander.Items>
</labs:SettingsExpander>
<labs:SettingsExpander
x:Uid="Appearance_Behavior"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xEB3C;}"
@@ -317,14 +325,22 @@
IsOpen="{x:Bind Mode=OneWay, Path=ViewModel.IsMousePointerCrosshairsEnabledGpoConfigured}"
IsTabStop="{x:Bind Mode=OneWay, Path=ViewModel.IsMousePointerCrosshairsEnabledGpoConfigured}"
Severity="Informational" />
<labs:SettingsCard
<labs:SettingsExpander
x:Uid="MouseUtils_MousePointerCrosshairs_ActivationShortcut"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xEDA7;}"
IsEnabled="{x:Bind ViewModel.IsMousePointerCrosshairsEnabled, Mode=OneWay}">
IsEnabled="{x:Bind ViewModel.IsMousePointerCrosshairsEnabled, Mode=OneWay}"
IsExpanded="True">
<controls:ShortcutControl
MinWidth="{StaticResource SettingActionControlMinWidth}"
HotkeySettings="{x:Bind Path=ViewModel.MousePointerCrosshairsActivationShortcut, Mode=TwoWay}" />
</labs:SettingsCard>
<labs:SettingsExpander.Items>
<labs:SettingsCard ContentAlignment="Left">
<CheckBox
x:Uid="MouseUtils_AutoActivate"
IsChecked="{x:Bind ViewModel.MousePointerCrosshairsAutoActivate, Mode=TwoWay}" />
</labs:SettingsCard>
</labs:SettingsExpander.Items>
</labs:SettingsExpander>
<labs:SettingsExpander
x:Uid="Appearance_Behavior"

View File

@@ -2466,10 +2466,10 @@ From there, simply click on one of the supported files in the File Explorer and
<value>Cancel</value>
</data>
<data name="Activation_Shortcut_Description" xml:space="preserve">
<value>Press a combination of keys to change this shortcut</value>
<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.
<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">
@@ -3593,6 +3593,9 @@ Activate by holding the key for the character you want to add an accent to, then
<data name="MouseUtils_MousePointerCrosshairs_CrosshairsAutoHide.Content" xml:space="preserve">
<value>Automatically hide crosshairs when the mouse pointer is hidden</value>
</data>
<data name="MouseUtils_AutoActivate.Content" xml:space="preserve">
<value>Automatically activate on utility startup</value>
</data>
<data name="Run_FindMorePlugins.Text" xml:space="preserve">
<value>Find more plugins</value>
</data>

View File

@@ -82,6 +82,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_highlighterRadius = MouseHighlighterSettingsConfig.Properties.HighlightRadius.Value;
_highlightFadeDelayMs = MouseHighlighterSettingsConfig.Properties.HighlightFadeDelayMs.Value;
_highlightFadeDurationMs = MouseHighlighterSettingsConfig.Properties.HighlightFadeDurationMs.Value;
_highlighterAutoActivate = MouseHighlighterSettingsConfig.Properties.AutoActivate.Value;
if (mouseJumpSettingsRepository == null)
{
@@ -111,6 +112,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_mousePointerCrosshairsAutoHide = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsAutoHide.Value;
_mousePointerCrosshairsIsFixedLengthEnabled = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsIsFixedLengthEnabled.Value;
_mousePointerCrosshairsFixedLength = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsFixedLength.Value;
_mousePointerCrosshairsAutoActivate = MousePointerCrosshairsSettingsConfig.Properties.AutoActivate.Value;
// set the callback functions value to handle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
@@ -549,6 +551,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool MouseHighlighterAutoActivate
{
get
{
return _highlighterAutoActivate;
}
set
{
if (value != _highlighterAutoActivate)
{
_highlighterAutoActivate = value;
MouseHighlighterSettingsConfig.Properties.AutoActivate.Value = value;
NotifyMouseHighlighterPropertyChanged();
}
}
}
public void NotifyMouseHighlighterPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(propertyName);
@@ -852,6 +872,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool MousePointerCrosshairsAutoActivate
{
get
{
return _mousePointerCrosshairsAutoActivate;
}
set
{
if (value != _mousePointerCrosshairsAutoActivate)
{
_mousePointerCrosshairsAutoActivate = value;
MousePointerCrosshairsSettingsConfig.Properties.AutoActivate.Value = value;
NotifyMousePointerCrosshairsPropertyChanged();
}
}
}
public void NotifyMousePointerCrosshairsPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(propertyName);
@@ -896,6 +934,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private int _highlighterRadius;
private int _highlightFadeDelayMs;
private int _highlightFadeDurationMs;
private bool _highlighterAutoActivate;
private GpoRuleConfigured _jumpEnabledGpoRuleConfiguration;
private bool _jumpEnabledStateIsGPOConfigured;
@@ -913,5 +952,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private bool _mousePointerCrosshairsAutoHide;
private bool _mousePointerCrosshairsIsFixedLengthEnabled;
private int _mousePointerCrosshairsFixedLength;
private bool _mousePointerCrosshairsAutoActivate;
}
}