mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-29 08:29:10 +01:00
Compare commits
3 Commits
user/yeela
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14820a22a4 | ||
|
|
b6e002c565 | ||
|
|
ba4c57ed2e |
@@ -27,6 +27,7 @@ struct Highlighter
|
||||
static Highlighter* instance;
|
||||
void Terminate();
|
||||
void SwitchActivationMode();
|
||||
void SwitchHighlightMode();
|
||||
void ApplySettings(MouseHighlighterSettings settings);
|
||||
|
||||
private:
|
||||
@@ -60,6 +61,7 @@ private:
|
||||
HWND m_hwnd = NULL;
|
||||
HINSTANCE m_hinstance = NULL;
|
||||
static constexpr DWORD WM_SWITCH_ACTIVATION_MODE = WM_APP;
|
||||
static constexpr DWORD WM_SWITCH_HIGHLIGHT_MODE = WM_APP + 1;
|
||||
|
||||
winrt::DispatcherQueueController m_dispatcherQueueController{ nullptr };
|
||||
winrt::Compositor m_compositor{ nullptr };
|
||||
@@ -466,6 +468,11 @@ void Highlighter::SwitchActivationMode()
|
||||
PostMessage(m_hwnd, WM_SWITCH_ACTIVATION_MODE, 0, 0);
|
||||
}
|
||||
|
||||
void Highlighter::SwitchHighlightMode()
|
||||
{
|
||||
PostMessage(m_hwnd, WM_SWITCH_HIGHLIGHT_MODE, 0, 0);
|
||||
}
|
||||
|
||||
void Highlighter::ApplySettings(MouseHighlighterSettings settings)
|
||||
{
|
||||
m_radius = static_cast<float>(settings.radius);
|
||||
@@ -535,6 +542,15 @@ LRESULT CALLBACK Highlighter::WndProc(HWND hWnd, UINT message, WPARAM wParam, LP
|
||||
instance->StartDrawing();
|
||||
}
|
||||
break;
|
||||
case WM_SWITCH_HIGHLIGHT_MODE:
|
||||
// Toggle spotlight mode
|
||||
instance->m_spotlightMode = !instance->m_spotlightMode;
|
||||
if (instance->m_visible)
|
||||
{
|
||||
instance->StopDrawing();
|
||||
instance->StartDrawing();
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
instance->DestroyHighlighter();
|
||||
break;
|
||||
@@ -663,6 +679,15 @@ void MouseHighlighterSwitch()
|
||||
}
|
||||
}
|
||||
|
||||
void MouseHighlighterSwitchMode()
|
||||
{
|
||||
if (Highlighter::instance != nullptr)
|
||||
{
|
||||
Logger::info("Switching highlight mode.");
|
||||
Highlighter::instance->SwitchHighlightMode();
|
||||
}
|
||||
}
|
||||
|
||||
void MouseHighlighterDisable()
|
||||
{
|
||||
if (Highlighter::instance != nullptr)
|
||||
|
||||
@@ -25,4 +25,5 @@ int MouseHighlighterMain(HINSTANCE hinst, MouseHighlighterSettings settings);
|
||||
void MouseHighlighterDisable();
|
||||
bool MouseHighlighterIsEnabled();
|
||||
void MouseHighlighterSwitch();
|
||||
void MouseHighlighterSwitchMode();
|
||||
void MouseHighlighterApplySettings(MouseHighlighterSettings settings);
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
#include "trace.h"
|
||||
#include "MouseHighlighter.h"
|
||||
#include "common/utils/color.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
const wchar_t JSON_KEY_PROPERTIES[] = L"properties";
|
||||
const wchar_t JSON_KEY_VALUE[] = L"value";
|
||||
const wchar_t JSON_KEY_ACTIVATION_SHORTCUT[] = L"activation_shortcut";
|
||||
const wchar_t JSON_KEY_MODE_SWITCH_SHORTCUT[] = L"mode_switch_shortcut";
|
||||
const wchar_t JSON_KEY_LEFT_BUTTON_CLICK_COLOR[] = L"left_button_click_color";
|
||||
const wchar_t JSON_KEY_RIGHT_BUTTON_CLICK_COLOR[] = L"right_button_click_color";
|
||||
const wchar_t JSON_KEY_HIGHLIGHT_OPACITY[] = L"highlight_opacity";
|
||||
@@ -55,8 +58,8 @@ private:
|
||||
// The PowerToy state.
|
||||
bool m_enabled = false;
|
||||
|
||||
// Hotkey to invoke the module
|
||||
HotkeyEx m_hotkey;
|
||||
// Hotkeys to invoke the module
|
||||
std::vector<PowertoyModuleIface::Hotkey> m_hotkeys;
|
||||
|
||||
// Mouse Highlighter specific settings
|
||||
MouseHighlighterSettings m_highlightSettings;
|
||||
@@ -148,14 +151,29 @@ public:
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
virtual std::optional<HotkeyEx> GetHotkeyEx() override
|
||||
virtual size_t get_hotkeys(Hotkey* buffer, size_t buffer_size) override
|
||||
{
|
||||
return m_hotkey;
|
||||
if (buffer == nullptr || buffer_size == 0)
|
||||
{
|
||||
return m_hotkeys.size();
|
||||
}
|
||||
|
||||
size_t copied = std::min(buffer_size, m_hotkeys.size());
|
||||
std::copy_n(m_hotkeys.begin(), copied, buffer);
|
||||
return copied;
|
||||
}
|
||||
|
||||
virtual void OnHotkeyEx() override
|
||||
virtual bool on_hotkey(size_t hotkeyId) override
|
||||
{
|
||||
MouseHighlighterSwitch();
|
||||
if (hotkeyId == 0)
|
||||
{
|
||||
MouseHighlighterSwitch();
|
||||
}
|
||||
else if (hotkeyId == 1)
|
||||
{
|
||||
MouseHighlighterSwitchMode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Load the settings file.
|
||||
@@ -183,36 +201,43 @@ public:
|
||||
{
|
||||
try
|
||||
{
|
||||
// Parse HotKey
|
||||
// Initialize hotkeys vector
|
||||
m_hotkeys.clear();
|
||||
m_hotkeys.resize(2); // Activation and Mode Switch hotkeys
|
||||
|
||||
// Parse Activation HotKey
|
||||
auto jsonPropertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_ACTIVATION_SHORTCUT);
|
||||
auto hotkey = PowerToysSettings::HotkeyObject::from_json(jsonPropertiesObject);
|
||||
m_hotkey = HotkeyEx();
|
||||
if (hotkey.win_pressed())
|
||||
{
|
||||
m_hotkey.modifiersMask |= MOD_WIN;
|
||||
}
|
||||
|
||||
if (hotkey.ctrl_pressed())
|
||||
{
|
||||
m_hotkey.modifiersMask |= MOD_CONTROL;
|
||||
}
|
||||
|
||||
if (hotkey.shift_pressed())
|
||||
{
|
||||
m_hotkey.modifiersMask |= MOD_SHIFT;
|
||||
}
|
||||
|
||||
if (hotkey.alt_pressed())
|
||||
{
|
||||
m_hotkey.modifiersMask |= MOD_ALT;
|
||||
}
|
||||
|
||||
m_hotkey.vkCode = hotkey.get_code();
|
||||
|
||||
m_hotkeys[0].win = hotkey.win_pressed();
|
||||
m_hotkeys[0].ctrl = hotkey.ctrl_pressed();
|
||||
m_hotkeys[0].shift = hotkey.shift_pressed();
|
||||
m_hotkeys[0].alt = hotkey.alt_pressed();
|
||||
m_hotkeys[0].key = hotkey.get_code();
|
||||
m_hotkeys[0].id = 0;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Logger::warn("Failed to initialize Mouse Highlighter activation shortcut");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Parse Mode Switch HotKey
|
||||
auto jsonPropertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_MODE_SWITCH_SHORTCUT);
|
||||
auto hotkey = PowerToysSettings::HotkeyObject::from_json(jsonPropertiesObject);
|
||||
|
||||
m_hotkeys[1].win = hotkey.win_pressed();
|
||||
m_hotkeys[1].ctrl = hotkey.ctrl_pressed();
|
||||
m_hotkeys[1].shift = hotkey.shift_pressed();
|
||||
m_hotkeys[1].alt = hotkey.alt_pressed();
|
||||
m_hotkeys[1].key = hotkey.get_code();
|
||||
m_hotkeys[1].id = 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Logger::warn("Failed to initialize Mouse Highlighter mode switch shortcut");
|
||||
}
|
||||
// Migration from <=1.1
|
||||
auto version = (std::wstring)settingsObject.GetNamedString(L"version");
|
||||
auto migration = false;
|
||||
@@ -383,12 +408,47 @@ public:
|
||||
{
|
||||
Logger::info("Mouse Highlighter settings are empty");
|
||||
}
|
||||
if (!m_hotkey.modifiersMask)
|
||||
|
||||
// Set default hotkeys if not configured
|
||||
if (m_hotkeys.empty() || m_hotkeys.size() < 2)
|
||||
{
|
||||
Logger::info("Mouse Highlighter is going to use default shortcut");
|
||||
m_hotkey.modifiersMask = MOD_SHIFT | MOD_WIN;
|
||||
m_hotkey.vkCode = 0x48; // H key
|
||||
Logger::info("Mouse Highlighter is going to use default shortcuts");
|
||||
m_hotkeys.clear();
|
||||
m_hotkeys.resize(2);
|
||||
|
||||
// Default activation shortcut: Win + Shift + H
|
||||
m_hotkeys[0].win = true;
|
||||
m_hotkeys[0].shift = true;
|
||||
m_hotkeys[0].key = 0x48; // H key
|
||||
m_hotkeys[0].id = 0;
|
||||
|
||||
// Default mode switch shortcut: Win + Shift + M
|
||||
m_hotkeys[1].win = true;
|
||||
m_hotkeys[1].shift = true;
|
||||
m_hotkeys[1].key = 0x4D; // M key
|
||||
m_hotkeys[1].id = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if activation hotkey is empty and set default
|
||||
if (!m_hotkeys[0].win && !m_hotkeys[0].ctrl && !m_hotkeys[0].shift && !m_hotkeys[0].alt && m_hotkeys[0].key == 0)
|
||||
{
|
||||
m_hotkeys[0].win = true;
|
||||
m_hotkeys[0].shift = true;
|
||||
m_hotkeys[0].key = 0x48; // H key
|
||||
m_hotkeys[0].id = 0;
|
||||
}
|
||||
|
||||
// Check if mode switch hotkey is empty and set default
|
||||
if (!m_hotkeys[1].win && !m_hotkeys[1].ctrl && !m_hotkeys[1].shift && !m_hotkeys[1].alt && m_hotkeys[1].key == 0)
|
||||
{
|
||||
m_hotkeys[1].win = true;
|
||||
m_hotkeys[1].shift = true;
|
||||
m_hotkeys[1].key = 0x4D; // M key
|
||||
m_hotkeys[1].id = 1;
|
||||
}
|
||||
}
|
||||
|
||||
m_highlightSettings = highlightSettings;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,6 +44,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
[JsonPropertyName("spotlight_mode")]
|
||||
public BoolProperty SpotlightMode { get; set; }
|
||||
|
||||
[JsonPropertyName("mode_switch_shortcut")]
|
||||
public HotkeySettings ModeSwitchShortcut { get; set; }
|
||||
|
||||
[CmdConfigureIgnore]
|
||||
public HotkeySettings DefaultModeSwitchShortcut => new HotkeySettings(true, false, false, true, 0x4D);
|
||||
|
||||
public MouseHighlighterProperties()
|
||||
{
|
||||
ActivationShortcut = DefaultActivationShortcut;
|
||||
@@ -56,6 +62,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
HighlightFadeDurationMs = new IntProperty(250);
|
||||
AutoActivate = new BoolProperty(false);
|
||||
SpotlightMode = new BoolProperty(false);
|
||||
ModeSwitchShortcut = DefaultModeSwitchShortcut;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +226,13 @@
|
||||
</tkcontrols:SettingsCard>
|
||||
</tkcontrols:SettingsExpander.Items>
|
||||
</tkcontrols:SettingsExpander>
|
||||
<tkcontrols:SettingsCard
|
||||
Name="MouseUtilsMouseHighlighterModeSwitchShortcut"
|
||||
x:Uid="MouseUtils_MouseHighlighter_ModeSwitchShortcut"
|
||||
HeaderIcon="{ui:FontIcon Glyph=}"
|
||||
IsEnabled="{x:Bind ViewModel.IsMouseHighlighterEnabled, Mode=OneWay}">
|
||||
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind Path=ViewModel.MouseHighlighterModeSwitchShortcut, Mode=TwoWay}" />
|
||||
</tkcontrols:SettingsCard>
|
||||
<tkcontrols:SettingsExpander
|
||||
Name="MouseHighlighterAppearanceBehavior"
|
||||
x:Uid="Appearance_Behavior"
|
||||
|
||||
@@ -2824,6 +2824,13 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
|
||||
<value>Customize the shortcut to turn on or off this mode</value>
|
||||
<comment>"Mouse Highlighter" is the name of the utility. Mouse is the hardware mouse.</comment>
|
||||
</data>
|
||||
<data name="MouseUtils_MouseHighlighter_ModeSwitchShortcut.Header" xml:space="preserve">
|
||||
<value>Mode switch shortcut</value>
|
||||
</data>
|
||||
<data name="MouseUtils_MouseHighlighter_ModeSwitchShortcut.Description" xml:space="preserve">
|
||||
<value>Customize the shortcut to switch between spotlight and circle highlight modes</value>
|
||||
<comment>"Mouse Highlighter" is the name of the utility. Mouse is the hardware mouse.</comment>
|
||||
</data>
|
||||
<data name="MouseUtils_MouseHighlighter_PrimaryButtonClickColor.Header" xml:space="preserve">
|
||||
<value>Primary button highlight color</value>
|
||||
</data>
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
var hotkeysDict = new Dictionary<string, HotkeySettings[]>
|
||||
{
|
||||
[FindMyMouseSettings.ModuleName] = [FindMyMouseActivationShortcut],
|
||||
[MouseHighlighterSettings.ModuleName] = [MouseHighlighterActivationShortcut],
|
||||
[MouseHighlighterSettings.ModuleName] = [MouseHighlighterActivationShortcut, MouseHighlighterModeSwitchShortcut],
|
||||
[MousePointerCrosshairsSettings.ModuleName] = [
|
||||
MousePointerCrosshairsActivationShortcut,
|
||||
GlidingCursorActivationShortcut],
|
||||
@@ -523,6 +523,23 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings MouseHighlighterModeSwitchShortcut
|
||||
{
|
||||
get
|
||||
{
|
||||
return MouseHighlighterSettingsConfig.Properties.ModeSwitchShortcut;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (MouseHighlighterSettingsConfig.Properties.ModeSwitchShortcut != value)
|
||||
{
|
||||
MouseHighlighterSettingsConfig.Properties.ModeSwitchShortcut = value ?? MouseHighlighterSettingsConfig.Properties.DefaultModeSwitchShortcut;
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string MouseHighlighterLeftButtonClickColor
|
||||
{
|
||||
get
|
||||
|
||||
Reference in New Issue
Block a user