Compare commits

...

3 Commits

Author SHA1 Message Date
Niels Laute
96f89906e4 Small settings UI tweaks 2025-09-05 16:09:55 +02:00
Mike Hall
7697876174 add settle time and progress arc 2025-09-05 13:47:47 +01:00
Mike Hall
6593ec69d5 add dwell cursor functionality 2025-09-04 15:57:33 +01:00
21 changed files with 2016 additions and 34 deletions

View File

@@ -262,7 +262,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "utils", "utils", "{B39DC643
src\common\utils\EventLocker.h = src\common\utils\EventLocker.h
src\common\utils\EventWaiter.h = src\common\utils\EventWaiter.h
src\common\utils\excluded_apps.h = src\common\utils\excluded_apps.h
src\common\utils\shell_ext_registration.h = src\common\utils\shell_ext_registration.h
src\common\utils\exec.h = src\common\utils\exec.h
src\common\utils\game_mode.h = src\common\utils\game_mode.h
src\common\utils\gpo.h = src\common\utils\gpo.h
@@ -282,6 +281,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "utils", "utils", "{B39DC643
src\common\utils\registry.h = src\common\utils\registry.h
src\common\utils\resources.h = src\common\utils\resources.h
src\common\utils\serialized.h = src\common\utils\serialized.h
src\common\utils\shell_ext_registration.h = src\common\utils\shell_ext_registration.h
src\common\utils\string_utils.h = src\common\utils\string_utils.h
src\common\utils\timeutil.h = src\common\utils\timeutil.h
src\common\utils\UnhandledExceptionHandler.h = src\common\utils\UnhandledExceptionHandler.h
@@ -801,6 +801,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.WebSea
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.Shell.UnitTests", "src\modules\cmdpal\Tests\Microsoft.CmdPal.Ext.Shell.UnitTests\Microsoft.CmdPal.Ext.Shell.UnitTests.csproj", "{E816D7B4-4688-4ECB-97CC-3D8E798F3833}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DwellCursor", "src\modules\MouseUtils\DwellCursor\DwellCursor.vcxproj", "{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
@@ -2695,22 +2697,6 @@ Global
{61CBF221-9452-4934-B685-146285E080D7}.Release|ARM64.Build.0 = Release|ARM64
{61CBF221-9452-4934-B685-146285E080D7}.Release|x64.ActiveCfg = Release|x64
{61CBF221-9452-4934-B685-146285E080D7}.Release|x64.Build.0 = Release|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Debug|ARM64.ActiveCfg = Debug|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Debug|ARM64.Build.0 = Debug|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Debug|x64.ActiveCfg = Debug|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Debug|x64.Build.0 = Debug|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Release|ARM64.ActiveCfg = Release|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Release|ARM64.Build.0 = Release|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Release|x64.ActiveCfg = Release|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Release|x64.Build.0 = Release|x64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Debug|ARM64.ActiveCfg = Debug|ARM64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Debug|ARM64.Build.0 = Debug|ARM64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Debug|x64.ActiveCfg = Debug|x64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Debug|x64.Build.0 = Debug|x64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Release|ARM64.ActiveCfg = Release|ARM64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Release|ARM64.Build.0 = Release|ARM64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Release|x64.ActiveCfg = Release|x64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Release|x64.Build.0 = Release|x64
{38F187B2-6638-5A40-072F-DBE5E54070A0}.Debug|ARM64.ActiveCfg = Debug|ARM64
{38F187B2-6638-5A40-072F-DBE5E54070A0}.Debug|ARM64.Build.0 = Debug|ARM64
{38F187B2-6638-5A40-072F-DBE5E54070A0}.Debug|x64.ActiveCfg = Debug|x64
@@ -2727,14 +2713,22 @@ Global
{DA0744BC-E822-680E-9CEB-D0FBA903A8EE}.Release|ARM64.Build.0 = Release|ARM64
{DA0744BC-E822-680E-9CEB-D0FBA903A8EE}.Release|x64.ActiveCfg = Release|x64
{DA0744BC-E822-680E-9CEB-D0FBA903A8EE}.Release|x64.Build.0 = Release|x64
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Debug|ARM64.ActiveCfg = Debug|ARM64
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Debug|ARM64.Build.0 = Debug|ARM64
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Debug|x64.ActiveCfg = Debug|x64
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Debug|x64.Build.0 = Debug|x64
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Release|ARM64.ActiveCfg = Release|ARM64
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Release|ARM64.Build.0 = Release|ARM64
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Release|x64.ActiveCfg = Release|x64
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Release|x64.Build.0 = Release|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Debug|ARM64.ActiveCfg = Debug|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Debug|ARM64.Build.0 = Debug|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Debug|x64.ActiveCfg = Debug|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Debug|x64.Build.0 = Debug|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Release|ARM64.ActiveCfg = Release|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Release|ARM64.Build.0 = Release|ARM64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Release|x64.ActiveCfg = Release|x64
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1}.Release|x64.Build.0 = Release|x64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Debug|ARM64.ActiveCfg = Debug|ARM64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Debug|ARM64.Build.0 = Debug|ARM64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Debug|x64.ActiveCfg = Debug|x64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Debug|x64.Build.0 = Debug|x64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Release|ARM64.ActiveCfg = Release|ARM64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Release|ARM64.Build.0 = Release|ARM64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Release|x64.ActiveCfg = Release|x64
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9}.Release|x64.Build.0 = Release|x64
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Debug|ARM64.ActiveCfg = Debug|ARM64
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Debug|ARM64.Build.0 = Debug|ARM64
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Debug|x64.ActiveCfg = Debug|x64
@@ -2919,6 +2913,14 @@ Global
{E816D7B4-4688-4ECB-97CC-3D8E798F3833}.Release|ARM64.Build.0 = Release|ARM64
{E816D7B4-4688-4ECB-97CC-3D8E798F3833}.Release|x64.ActiveCfg = Release|x64
{E816D7B4-4688-4ECB-97CC-3D8E798F3833}.Release|x64.Build.0 = Release|x64
{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}.Debug|ARM64.ActiveCfg = Debug|ARM64
{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}.Debug|ARM64.Build.0 = Debug|ARM64
{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}.Debug|x64.ActiveCfg = Debug|x64
{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}.Debug|x64.Build.0 = Debug|x64
{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}.Release|ARM64.ActiveCfg = Release|ARM64
{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}.Release|ARM64.Build.0 = Release|ARM64
{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}.Release|x64.ActiveCfg = Release|x64
{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -3194,10 +3196,10 @@ Global
{9BC1C986-1E97-4D07-A7B1-CE226C239EFA} = {2F305555-C296-497E-AC20-5FA1B237996A}
{99CA1509-FB73-456E-AFAF-AB89C017BD72} = {6B01F1CF-F4DB-48B5-BFE7-0BF576C1D704}
{61CBF221-9452-4934-B685-146285E080D7} = {6B01F1CF-F4DB-48B5-BFE7-0BF576C1D704}
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1} = {2C318EC3-BA86-4372-B1BC-DB0F33C208B2}
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9} = {68328142-5B31-4715-BCBB-7B6345EE0971}
{38F187B2-6638-5A40-072F-DBE5E54070A0} = {1AFB6476-670D-4E80-A464-657E01DFF482}
{DA0744BC-E822-680E-9CEB-D0FBA903A8EE} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A1} = {2C318EC3-BA86-4372-B1BC-DB0F33C208B2}
{43E779F3-D83C-48B1-BA8D-1912DBD76FC9} = {68328142-5B31-4715-BCBB-7B6345EE0971}
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6} = {1AFB6476-670D-4E80-A464-657E01DFF482}
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A} = {1AFB6476-670D-4E80-A464-657E01DFF482}
{9D3F3793-EFE3-4525-8782-238015DABA62} = {66E1534A-1587-42B2-912F-45C994D32904}
@@ -3237,6 +3239,7 @@ Global
{E816D7B3-4688-4ECB-97CC-3D8E798F3832} = {8EF25507-2575-4ADE-BF7E-D23376903AB8}
{E816D7B2-4688-4ECB-97CC-3D8E798F3831} = {8EF25507-2575-4ADE-BF7E-D23376903AB8}
{E816D7B4-4688-4ECB-97CC-3D8E798F3833} = {8EF25507-2575-4ADE-BF7E-D23376903AB8}
{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61} = {322566EF-20DC-43A6-B9F8-616AF942579A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}

View File

@@ -0,0 +1,7 @@
#include <windows.h>
#include "resource.h"
STRINGTABLE
BEGIN
IDS_MODULE_NAME "DwellCursor"
END

View File

@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" />
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{6C2AD2F7-8BDF-4C5E-B3F5-7E1B7A0A8A61}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DwellCursor</RootNamespace>
<ProjectName>DwellCursor</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="..\..\..\..\deps\spdlog.props" />
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<OutDir>..\..\..\..\$(Platform)\$(Configuration)\</OutDir>
<TargetName>PowerToys.DwellCursor</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)src\;$(SolutionDir)src\modules;$(SolutionDir)src\common\Telemetry;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="DwellIndicator.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="trace.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="DwellIndicator.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="trace.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DwellCursor.rc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\logger\logger.vcxproj">
<Project>{d9b8fc84-322a-4f9f-bbb9-20915c47ddfd}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\common\SettingsAPI\SettingsAPI.vcxproj">
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
</Target>
</Project>

View File

@@ -0,0 +1,830 @@
#include "pch.h"
#include "DwellIndicator.h"
#include <gdiplus.h>
#include <cmath>
#pragma comment(lib, "gdiplus.lib")
#pragma comment(lib, "dwmapi.lib")
using namespace Gdiplus;
/**
* @brief Implementation class for the dwell indicator using the Pimpl idiom
*
* This class handles all the visual indicator functionality:
* - Creates a transparent, topmost window at cursor position
* - Draws a circular progress arc using GDI+
* - Updates progress smoothly during countdown
* - Uses system accent color for theming
*/
class DwellIndicatorImpl
{
public:
DwellIndicatorImpl() = default;
~DwellIndicatorImpl() = default;
// Public interface methods
bool Initialize();
void Show(int x, int y);
void UpdateProgress(float progress);
void Hide();
void Cleanup();
private:
// Window management
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) noexcept;
bool CreateIndicatorWindow();
void DrawIndicator(HDC hdc);
float GetDpiScale() const;
// Window class and visual constants
static constexpr auto m_className = L"DwellCursorIndicator";
static constexpr auto m_windowTitle = L"PowerToys Dwell Cursor Indicator";
static constexpr float kIndicatorRadius = 20.0f; // Circle radius in pixels
static constexpr float kStrokeWidth = 3.0f; // Arc stroke width in pixels
// Window and positioning state
HWND m_hwnd = NULL; // Handle to the indicator window
HINSTANCE m_hinstance = NULL; // Module instance handle
bool m_isVisible = false; // Current visibility state
int m_currentX = 0; // Last shown X position
int m_currentY = 0; // Last shown Y position
float m_progress = 0.0f; // Current progress (0.0 to 1.0)
// GDI+ resources
ULONG_PTR m_gdiplusToken = 0; // GDI+ initialization token
friend class DwellIndicator;
};
/**
* @brief Window procedure for the indicator window
*
* Handles window messages for the transparent indicator overlay:
* - WM_PAINT: Triggers redraw of the progress arc
* - WM_NCHITTEST: Returns HTTRANSPARENT to allow mouse events to pass through
* - WM_DESTROY: Standard cleanup
*
* @param hWnd Window handle
* @param message Windows message ID
* @param wParam Message parameter
* @param lParam Message parameter
* @return Message handling result
*/
LRESULT CALLBACK DwellIndicatorImpl::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) noexcept
{
DwellIndicatorImpl* pThis = nullptr;
// Retrieve the instance pointer stored during window creation
if (message == WM_NCCREATE)
{
// During window creation, extract the 'this' pointer from creation params
CREATESTRUCT* pcs = reinterpret_cast<CREATESTRUCT*>(lParam);
pThis = static_cast<DwellIndicatorImpl*>(pcs->lpCreateParams);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pThis));
}
else
{
// For all other messages, retrieve the stored 'this' pointer
pThis = reinterpret_cast<DwellIndicatorImpl*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
}
switch (message)
{
case WM_PAINT:
// Redraw the indicator - this is where our visual progress arc gets drawn
if (pThis)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
pThis->DrawIndicator(hdc); // Draw the circular progress indicator
EndPaint(hWnd, &ps);
}
return 0;
case WM_NCHITTEST:
// Restore transparent mouse behavior - allow clicks to pass through
return HTTRANSPARENT;
case WM_DESTROY:
// DO NOT call PostQuitMessage(0) for overlay windows!
// This was interfering with PowerToys main message loop and causing settings menu issues
// Just let the window be destroyed normally
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
/**
* @brief Initialize the indicator system
*
* Sets up GDI+ graphics system and creates the indicator window.
* This must be called before any Show/Update operations.
*
* @return true if initialization successful, false on failure
*/
bool DwellIndicatorImpl::Initialize()
{
m_hinstance = GetModuleHandle(NULL);
// Initialize GDI+ graphics system for smooth drawing
GdiplusStartupInput gdiplusStartupInput;
Gdiplus::Status status = GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
if (status != Gdiplus::Ok)
{
// GDI+ initialization failed - no visual indicator will work
return false;
}
// Create the transparent overlay window
bool windowCreated = CreateIndicatorWindow();
if (!windowCreated)
{
// Clean up GDI+ if window creation failed
if (m_gdiplusToken != 0)
{
GdiplusShutdown(m_gdiplusToken);
m_gdiplusToken = 0;
}
}
return windowCreated;
}
/**
* @brief Create the transparent indicator window
*
* Creates a layered, transparent, topmost window that:
* - Appears above all other windows
* - Allows mouse events to pass through
* - Has no border, title bar, or decorations
* - Is positioned and sized later when shown
*
* @return true if window created successfully, false on failure
*/
bool DwellIndicatorImpl::CreateIndicatorWindow()
{
WNDCLASS wc{};
// Set DPI awareness for proper scaling on high-DPI displays
SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
// Register window class only if not already registered
if (!GetClassInfoW(m_hinstance, m_className, &wc))
{
wc.lpfnWndProc = WndProc; // Our window procedure
wc.hInstance = m_hinstance; // Module instance
wc.hIcon = LoadIcon(m_hinstance, IDI_APPLICATION); // Default icon
wc.hCursor = LoadCursor(nullptr, IDC_ARROW); // Default cursor
wc.hbrBackground = static_cast<HBRUSH>(GetStockObject(NULL_BRUSH)); // Transparent background
wc.lpszClassName = m_className; // Class name for window
if (!RegisterClassW(&wc))
{
// Failed to register window class
DWORD error = GetLastError();
// Note: Can't use Logger here as it might not be available in all contexts
return false;
}
}
// Create window with transparency and mouse pass-through restored
DWORD exStyle = WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
m_hwnd = CreateWindowExW(
exStyle, // Extended window styles with transparency restored
m_className, // Window class name
m_windowTitle, // Window title (not visible)
WS_POPUP, // Window style - popup with no decorations
0, 0, 100, 100, // Initial position and size (will be adjusted in Show())
nullptr, // No parent window
nullptr, // No menu
m_hinstance, // Module instance
this); // Pass 'this' pointer for WndProc to access
if (!m_hwnd)
{
DWORD error = GetLastError();
// Note: Can't use Logger here as it might not be available in all contexts
}
else
{
OutputDebugStringA("DwellIndicator: Created transparent layered window with mouse pass-through\n");
}
return m_hwnd != nullptr;
}
/**
* @brief Show the indicator at specified cursor position
*
* Positions the window centered on the cursor location and makes it visible.
* The window size is calculated based on indicator radius and DPI scaling.
*
* @param x Cursor X coordinate in screen pixels
* @param y Cursor Y coordinate in screen pixels
*/
void DwellIndicatorImpl::Show(int x, int y)
{
// Check if window handle is valid before proceeding
if (!m_hwnd)
{
OutputDebugStringA("DwellIndicator: ERROR - Window handle is NULL, cannot show indicator\n");
return;
}
// **CRITICAL FIX: Reset progress state immediately when showing at new position**
float oldProgress = m_progress;
m_progress = 0.0f;
// Store current position for reference
m_currentX = x;
m_currentY = y;
// Calculate window size based on indicator radius and DPI scaling
const float dpiScale = GetDpiScale();
const int windowSize = static_cast<int>((kIndicatorRadius * 2 + kStrokeWidth * 2 + 10) * dpiScale);
// Calculate final window position (centered on cursor)
const int windowX = x - windowSize / 2;
const int windowY = y - windowSize / 2;
// Log detailed positioning information for debugging
char debugMsg[512];
sprintf_s(debugMsg, sizeof(debugMsg),
"DwellIndicator: SHOW - Cursor:(%d,%d) Window:(%d,%d) Size:%dx%d DPI:%.2f Progress: %.3f->0.0\n",
x, y, windowX, windowY, windowSize, windowSize, dpiScale, oldProgress);
OutputDebugStringA(debugMsg);
// **GDI+ EXPERT FIX: Use UpdateLayeredWindow for proper transparency reset**
// This is the correct way to handle layered windows with transparency
// First hide the window to ensure clean state
if (m_isVisible)
{
ShowWindow(m_hwnd, SW_HIDE);
m_isVisible = false;
}
// Position window (while hidden for clean transition)
BOOL setWindowPosResult = SetWindowPos(m_hwnd, HWND_TOPMOST,
windowX, windowY, // Calculated position
windowSize, windowSize, // Square window to contain circle
SWP_NOACTIVATE | SWP_HIDEWINDOW); // Position but keep hidden for now
if (!setWindowPosResult)
{
DWORD error = GetLastError();
sprintf_s(debugMsg, sizeof(debugMsg),
"DwellIndicator: ERROR - SetWindowPos failed with error %lu\n", error);
OutputDebugStringA(debugMsg);
}
// **GDI+ EXPERT FIX: Create clean bitmap and use UpdateLayeredWindow**
// This completely clears any previous drawing artifacts
HDC screenDC = GetDC(NULL);
HDC memoryDC = CreateCompatibleDC(screenDC);
// Create 32-bit bitmap with alpha channel for proper transparency
BITMAPINFO bmi = {};
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = windowSize;
bmi.bmiHeader.biHeight = -windowSize; // Top-down DIB
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32; // 32-bit with alpha
bmi.bmiHeader.biCompression = BI_RGB;
void* pvBits = nullptr;
HBITMAP hBitmap = CreateDIBSection(screenDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
if (hBitmap && memoryDC)
{
HBITMAP oldBitmap = static_cast<HBITMAP>(SelectObject(memoryDC, hBitmap));
// **CRITICAL: Clear the entire bitmap with transparent pixels**
// This ensures no artifacts from previous drawings
// Fix for C26451: Use safe arithmetic to prevent overflow
const size_t bitmapSizeBytes = static_cast<size_t>(windowSize) * static_cast<size_t>(windowSize) * 4ULL;
memset(pvBits, 0, bitmapSizeBytes); // Clear to transparent
// Create GDI+ Graphics object from memory DC
Graphics graphics(memoryDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
graphics.SetCompositingMode(CompositingModeSourceOver);
graphics.SetCompositingQuality(CompositingQualityHighQuality);
// **GDI+ EXPERT: Use Graphics::Clear with transparent color**
// This properly clears the alpha channel
graphics.Clear(Color(0, 0, 0, 0)); // Fully transparent
// Draw only the background circle (no progress arc yet since progress = 0.0)
const float centerX = windowSize / 2.0f;
const float centerY = windowSize / 2.0f;
const float radius = kIndicatorRadius * dpiScale;
const float strokeWidth = kStrokeWidth * dpiScale;
// Get system accent color
DWORD accentColor = 0;
BOOL isOpaque = FALSE;
Color backgroundCircleColor;
if (SUCCEEDED(DwmGetColorizationColor(&accentColor, &isOpaque)))
{
const BYTE r = (accentColor >> 16) & 0xFF;
const BYTE g = (accentColor >> 8) & 0xFF;
const BYTE b = accentColor & 0xFF;
const BYTE bgR = static_cast<BYTE>((r + 128) / 2);
const BYTE bgG = static_cast<BYTE>((g + 128) / 2);
const BYTE bgB = static_cast<BYTE>((b + 128) / 2);
backgroundCircleColor = Color(80, bgR, bgG, bgB);
}
else
{
backgroundCircleColor = Color(80, 160, 160, 160);
}
// Draw background circle
RectF ellipseRect(centerX - radius, centerY - radius, radius * 2, radius * 2);
Pen bgPen(backgroundCircleColor, strokeWidth * 0.6f);
graphics.DrawEllipse(&bgPen, ellipseRect);
// **GDI+ EXPERT: Use UpdateLayeredWindow for artifact-free display**
POINT ptSrc = {0, 0};
POINT ptDst = {windowX, windowY};
SIZE size = {windowSize, windowSize};
BLENDFUNCTION blend = {};
blend.BlendOp = AC_SRC_OVER;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA; // Use per-pixel alpha
BOOL updateResult = UpdateLayeredWindow(m_hwnd, screenDC, &ptDst, &size,
memoryDC, &ptSrc, 0, &blend, ULW_ALPHA);
// Cleanup
SelectObject(memoryDC, oldBitmap);
DeleteObject(hBitmap);
sprintf_s(debugMsg, sizeof(debugMsg),
"DwellIndicator: UpdateLayeredWindow result: %s\n",
updateResult ? "SUCCESS" : "FAILED");
OutputDebugStringA(debugMsg);
}
DeleteDC(memoryDC);
ReleaseDC(NULL, screenDC);
// Now show the window with clean, artifact-free display
ShowWindow(m_hwnd, SW_SHOWNOACTIVATE);
m_isVisible = true;
OutputDebugStringA("DwellIndicator: SHOW Complete - Clean display with no artifacts\n");
}
/**
* @brief Update the progress of the countdown indicator
*
* Updates the internal progress value and triggers a redraw.
* Progress is clamped to [0.0, 1.0] range.
*
* @param progress Progress value from 0.0 (start) to 1.0 (complete)
*/
void DwellIndicatorImpl::UpdateProgress(float progress)
{
// Clamp progress to valid range [0.0, 1.0]
if (progress < 0.0f) progress = 0.0f;
if (progress > 1.0f) progress = 1.0f;
// Log progress updates for debugging
char debugMsg[256];
sprintf_s(debugMsg, sizeof(debugMsg),
"DwellIndicator: UPDATE Progress %.3f -> %.3f - Window: %s, Visible: %s\n",
m_progress, progress,
m_hwnd ? "VALID" : "NULL",
m_isVisible ? "TRUE" : "FALSE");
OutputDebugStringA(debugMsg);
float oldProgress = m_progress;
m_progress = progress;
// **GDI+ EXPERT FIX: Use UpdateLayeredWindow for artifact-free updates**
if (m_hwnd && m_isVisible)
{
// Get window dimensions
RECT rect;
GetClientRect(m_hwnd, &rect);
int windowSize = rect.right - rect.left;
// Create memory DC and bitmap for off-screen rendering
HDC screenDC = GetDC(NULL);
HDC memoryDC = CreateCompatibleDC(screenDC);
// Create 32-bit bitmap with alpha channel
BITMAPINFO bmi = {};
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = windowSize;
bmi.bmiHeader.biHeight = -windowSize; // Top-down DIB
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32; // 32-bit with alpha
bmi.bmiHeader.biCompression = BI_RGB;
void* pvBits = nullptr;
HBITMAP hBitmap = CreateDIBSection(screenDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
if (hBitmap && memoryDC)
{
HBITMAP oldBitmap = static_cast<HBITMAP>(SelectObject(memoryDC, hBitmap));
// **CRITICAL: Clear entire bitmap to transparent**
const size_t bitmapSizeBytes = static_cast<size_t>(windowSize) * static_cast<size_t>(windowSize) * 4ULL;
memset(pvBits, 0, bitmapSizeBytes);
// Create GDI+ Graphics object
Graphics graphics(memoryDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
graphics.SetCompositingMode(CompositingModeSourceOver);
graphics.SetCompositingQuality(CompositingQualityHighQuality);
// **GDI+ EXPERT: Proper alpha channel clearing**
graphics.Clear(Color(0, 0, 0, 0));
// Calculate drawing parameters
const float dpiScale = GetDpiScale();
const float centerX = windowSize / 2.0f;
const float centerY = windowSize / 2.0f;
const float radius = kIndicatorRadius * dpiScale;
const float strokeWidth = kStrokeWidth * dpiScale;
// Get system colors
DWORD accentColor = 0;
BOOL isOpaque = FALSE;
Color progressColor;
Color backgroundCircleColor;
if (SUCCEEDED(DwmGetColorizationColor(&accentColor, &isOpaque)))
{
const BYTE a = 255;
const BYTE r = (accentColor >> 16) & 0xFF;
const BYTE g = (accentColor >> 8) & 0xFF;
const BYTE b = accentColor & 0xFF;
progressColor = Color(a, r, g, b);
const BYTE bgR = static_cast<BYTE>((r + 128) / 2);
const BYTE bgG = static_cast<BYTE>((g + 128) / 2);
const BYTE bgB = static_cast<BYTE>((b + 128) / 2);
backgroundCircleColor = Color(80, bgR, bgG, bgB);
}
else
{
progressColor = Color(255, 0, 120, 215);
backgroundCircleColor = Color(80, 160, 160, 160);
}
// Create bounding rectangle
RectF ellipseRect(centerX - radius, centerY - radius, radius * 2, radius * 2);
// Draw background circle
Pen bgPen(backgroundCircleColor, strokeWidth * 0.6f);
graphics.DrawEllipse(&bgPen, ellipseRect);
// Draw progress arc if we have progress
if (m_progress > 0.0f)
{
Pen progressPen(progressColor, strokeWidth);
progressPen.SetStartCap(LineCapRound);
progressPen.SetEndCap(LineCapRound);
const float startAngle = -90.0f; // 12 o'clock
const float sweepAngle = m_progress * 360.0f;
graphics.DrawArc(&progressPen, ellipseRect, startAngle, sweepAngle);
sprintf_s(debugMsg, sizeof(debugMsg),
"DwellIndicator: Drew arc - Progress %.3f, SweepAngle %.1f degrees\n",
m_progress, sweepAngle);
OutputDebugStringA(debugMsg);
}
// **GDI+ EXPERT: Update layered window with new content**
POINT ptSrc = {0, 0};
POINT ptDst = {m_currentX - windowSize/2, m_currentY - windowSize/2};
SIZE size = {windowSize, windowSize};
BLENDFUNCTION blend = {};
blend.BlendOp = AC_SRC_OVER;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA;
BOOL updateResult = UpdateLayeredWindow(m_hwnd, screenDC, &ptDst, &size,
memoryDC, &ptSrc, 0, &blend, ULW_ALPHA);
// Cleanup
SelectObject(memoryDC, oldBitmap);
DeleteObject(hBitmap);
sprintf_s(debugMsg, sizeof(debugMsg),
"DwellIndicator: UPDATE Complete - UpdateLayeredWindow: %s (%.3f->%.3f)\n",
updateResult ? "SUCCESS" : "FAILED", oldProgress, progress);
OutputDebugStringA(debugMsg);
}
DeleteDC(memoryDC);
ReleaseDC(NULL, screenDC);
}
else
{
OutputDebugStringA("DwellIndicator: UPDATE Skipped - window not ready or not visible\n");
}
}
/**
* @brief Draw the circular progress indicator
*
* **NOTE: This method is now primarily for fallback WM_PAINT handling**
* The main rendering is done through UpdateLayeredWindow in Show() and UpdateProgress()
* for artifact-free display on layered windows.
*
* @param hdc Device context to draw into
*/
void DwellIndicatorImpl::DrawIndicator(HDC hdc)
{
// Log drawing calls for debugging
char debugMsg[256];
sprintf_s(debugMsg, sizeof(debugMsg),
"DwellIndicator: DRAW (Fallback WM_PAINT) - Progress %.3f, Visible: %s\n",
m_progress, m_isVisible ? "TRUE" : "FALSE");
OutputDebugStringA(debugMsg);
// **GDI+ EXPERT: For WM_PAINT on layered windows, we need special handling**
// Generally, UpdateLayeredWindow bypasses WM_PAINT, but this provides fallback
// Set up GDI+ graphics object with optimal settings for layered windows
Graphics graphics(hdc);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
graphics.SetCompositingMode(CompositingModeSourceOver);
graphics.SetCompositingQuality(CompositingQualityHighQuality);
graphics.SetPixelOffsetMode(PixelOffsetModeHighQuality);
// Get window client area dimensions
RECT rect;
GetClientRect(m_hwnd, &rect);
const float centerX = (rect.right - rect.left) / 2.0f;
const float centerY = (rect.bottom - rect.top) / 2.0f;
// **GDI+ EXPERT: Proper clearing for layered windows**
// Use Graphics::Clear instead of FillRectangle for proper alpha handling
graphics.Clear(Color(0, 0, 0, 0)); // Fully transparent background
// Apply DPI scaling for high-resolution displays
const float dpiScale = GetDpiScale();
const float radius = kIndicatorRadius * dpiScale;
const float strokeWidth = kStrokeWidth * dpiScale;
// Get system accent color for theming consistency
DWORD accentColor = 0;
BOOL isOpaque = FALSE;
Color progressColor;
Color backgroundCircleColor;
if (SUCCEEDED(DwmGetColorizationColor(&accentColor, &isOpaque)))
{
// Extract RGB components from system accent color
const BYTE a = 255;
const BYTE r = (accentColor >> 16) & 0xFF;
const BYTE g = (accentColor >> 8) & 0xFF;
const BYTE b = accentColor & 0xFF;
progressColor = Color(a, r, g, b);
// Create subtle background color
const BYTE bgR = static_cast<BYTE>((r + 128) / 2);
const BYTE bgG = static_cast<BYTE>((g + 128) / 2);
const BYTE bgB = static_cast<BYTE>((b + 128) / 2);
backgroundCircleColor = Color(80, bgR, bgG, bgB);
}
else
{
// Fallback colors
progressColor = Color(255, 0, 120, 215);
backgroundCircleColor = Color(80, 160, 160, 160);
}
// Create bounding rectangle for the circle
RectF ellipseRect(
centerX - radius,
centerY - radius,
radius * 2,
radius * 2
);
// Draw background circle
Pen bgPen(backgroundCircleColor, strokeWidth * 0.6f);
graphics.DrawEllipse(&bgPen, ellipseRect);
// Draw progress arc only if we have measurable progress
if (m_progress > 0.0f)
{
Pen progressPen(progressColor, strokeWidth);
progressPen.SetStartCap(LineCapRound);
progressPen.SetEndCap(LineCapRound);
const float startAngle = -90.0f; // 12 o'clock position
const float sweepAngle = m_progress * 360.0f;
graphics.DrawArc(&progressPen, ellipseRect, startAngle, sweepAngle);
sprintf_s(debugMsg, sizeof(debugMsg),
"DwellIndicator: DRAW Arc (Fallback) - Progress %.3f, SweepAngle %.1f degrees\n",
m_progress, sweepAngle);
OutputDebugStringA(debugMsg);
}
else
{
OutputDebugStringA("DwellIndicator: DRAW (Fallback) - No arc (progress 0.0)\n");
}
}
/**
* @brief Hide the indicator window
*
* Makes the window invisible but keeps it alive for potential re-showing.
* Also resets the progress state to ensure clean restart on next show.
*/
void DwellIndicatorImpl::Hide()
{
if (m_hwnd && m_isVisible)
{
char debugMsg[256];
sprintf_s(debugMsg, sizeof(debugMsg),
"DwellIndicator: HIDE - Progress %.3f->0.0, Visible: %s->FALSE\n",
m_progress, m_isVisible ? "TRUE" : "FALSE");
OutputDebugStringA(debugMsg);
// **GDI+ EXPERT FIX: Proper layered window hiding**
// Clear the layered window content before hiding to prevent artifacts
RECT rect;
GetClientRect(m_hwnd, &rect);
int windowSize = rect.right - rect.left;
if (windowSize > 0)
{
HDC screenDC = GetDC(NULL);
HDC memoryDC = CreateCompatibleDC(screenDC);
// Create transparent bitmap
BITMAPINFO bmi = {};
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = windowSize;
bmi.bmiHeader.biHeight = -windowSize;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
void* pvBits = nullptr;
HBITMAP hBitmap = CreateDIBSection(screenDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
if (hBitmap && memoryDC)
{
HBITMAP oldBitmap = static_cast<HBITMAP>(SelectObject(memoryDC, hBitmap));
// Clear to fully transparent
// Fix for C26451: Use safe arithmetic to prevent overflow
const size_t bitmapSizeBytes = static_cast<size_t>(windowSize) * static_cast<size_t>(windowSize) * 4ULL;
memset(pvBits, 0, bitmapSizeBytes);
// Update layered window with transparent content
POINT ptSrc = {0, 0};
POINT ptDst = {m_currentX - windowSize/2, m_currentY - windowSize/2};
SIZE size = {windowSize, windowSize};
BLENDFUNCTION blend = {};
blend.BlendOp = AC_SRC_OVER;
blend.SourceConstantAlpha = 0; // Make completely transparent
blend.AlphaFormat = AC_SRC_ALPHA;
UpdateLayeredWindow(m_hwnd, screenDC, &ptDst, &size,
memoryDC, &ptSrc, 0, &blend, ULW_ALPHA);
SelectObject(memoryDC, oldBitmap);
DeleteObject(hBitmap);
}
DeleteDC(memoryDC);
ReleaseDC(NULL, screenDC);
}
// Now hide the window
ShowWindow(m_hwnd, SW_HIDE);
m_isVisible = false;
// **CRITICAL: Reset progress when hiding to ensure clean state for next show**
m_progress = 0.0f;
OutputDebugStringA("DwellIndicator: HIDE Complete - Layered window cleared and hidden\n");
}
else
{
OutputDebugStringA("DwellIndicator: HIDE Skipped - already hidden or invalid window\n");
}
}
/**
* @brief Clean up all indicator resources
*
* Hides and destroys the window, shuts down GDI+.
* Called during module shutdown or when indicator is no longer needed.
*/
void DwellIndicatorImpl::Cleanup()
{
Hide(); // Hide window first
// Destroy the window and clean up Windows resources
if (m_hwnd)
{
DestroyWindow(m_hwnd);
m_hwnd = NULL;
}
// Shutdown GDI+ graphics system
if (m_gdiplusToken != 0)
{
GdiplusShutdown(m_gdiplusToken);
m_gdiplusToken = 0;
}
}
/**
* @brief Get DPI scaling factor for the current display
*
* @return DPI scale factor (1.0 = 96 DPI, 1.25 = 120 DPI, etc.)
*/
float DwellIndicatorImpl::GetDpiScale() const
{
if (!m_hwnd) return 1.0f; // Default scale if no window
return static_cast<float>(GetDpiForWindow(m_hwnd)) / 96.0f;
}
// ============================================================================
// DwellIndicator Public Interface Implementation
// ============================================================================
/**
* @brief Constructor - creates the implementation instance
*/
DwellIndicator::DwellIndicator() : m_impl(std::make_unique<DwellIndicatorImpl>())
{
}
/**
* @brief Destructor - ensures cleanup of resources
*/
DwellIndicator::~DwellIndicator()
{
if (m_impl)
{
m_impl->Cleanup();
}
}
/**
* @brief Initialize the indicator system
* @return true if successful, false on failure
*/
bool DwellIndicator::Initialize()
{
return m_impl ? m_impl->Initialize() : false;
}
/**
* @brief Show indicator at cursor position
* @param x Cursor X coordinate
* @param y Cursor Y coordinate
*/
void DwellIndicator::Show(int x, int y)
{
if (m_impl) m_impl->Show(x, y);
}
/**
* @brief Update countdown progress
* @param progress Progress from 0.0 to 1.0
*/
void DwellIndicator::UpdateProgress(float progress)
{
if (m_impl) m_impl->UpdateProgress(progress);
}
/**
* @brief Hide the indicator
*/
void DwellIndicator::Hide()
{
if (m_impl) m_impl->Hide();
}
/**
* @brief Clean up all resources
*/
void DwellIndicator::Cleanup()
{
if (m_impl) m_impl->Cleanup();
}

View File

@@ -0,0 +1,125 @@
/**
* @file DwellIndicator.h
* @brief Visual countdown indicator for DwellCursor module
*
* This header defines the interface for the visual feedback system that shows
* users when a dwell click is about to occur. The indicator appears as a
* circular progress arc that fills clockwise during the countdown period.
*
* Key Features:
* - Transparent overlay window that doesn't interfere with normal interaction
* - System accent color theming for consistency with Windows
* - DPI-aware rendering for high-resolution displays
* - Smooth progress animation updated at 30 FPS
* - Automatic positioning centered on cursor location
*/
#pragma once
#include <memory>
// Forward declaration to hide implementation details (Pimpl idiom)
class DwellIndicatorImpl;
/**
* @brief Visual countdown indicator for dwell cursor functionality
*
* This class provides a clean interface for showing a circular progress
* indicator during dwell cursor countdown. It uses the Pimpl (Pointer to
* Implementation) idiom to hide all Windows/GDI+ dependencies from the header.
*
* Usage Pattern:
* 1. Create instance: DwellIndicator indicator;
* 2. Initialize: indicator.Initialize();
* 3. Show at cursor: indicator.Show(x, y);
* 4. Update progress: indicator.UpdateProgress(0.5f); // 50% complete
* 5. Hide when done: indicator.Hide();
* 6. Cleanup: indicator.Cleanup(); // or let destructor handle it
*
* Thread Safety:
* - All methods must be called from the same thread (UI thread)
* - Progress updates can be called frequently (30ms intervals recommended)
* - Hide/Show calls are safe to call multiple times
*/
class DwellIndicator
{
public:
/**
* @brief Constructor - creates implementation instance
*
* Note: This only creates the object, call Initialize() before use.
*/
DwellIndicator();
/**
* @brief Destructor - ensures proper cleanup
*
* Automatically calls Cleanup() if not already called.
*/
~DwellIndicator();
/**
* @brief Initialize the indicator system
*
* Must be called before any other operations. Sets up:
* - GDI+ graphics system
* - Transparent overlay window
* - DPI awareness
*
* @return true if initialization successful, false on failure
*/
bool Initialize();
/**
* @brief Show the indicator at specified screen coordinates
*
* Displays the circular indicator centered on the given position.
* If already visible, moves to new position. Window is sized
* automatically based on DPI and indicator radius.
*
* @param x Screen X coordinate in pixels
* @param y Screen Y coordinate in pixels
*/
void Show(int x, int y);
/**
* @brief Update the countdown progress
*
* Updates the progress arc to show how much of the dwell delay
* has elapsed. Can be called frequently for smooth animation.
*
* @param progress Progress value from 0.0 (start) to 1.0 (complete)
* Values outside this range are automatically clamped
*/
void UpdateProgress(float progress);
/**
* @brief Hide the indicator
*
* Makes the indicator invisible but keeps resources allocated
* for potential re-showing. Safe to call multiple times.
*/
void Hide();
/**
* @brief Clean up all resources
*
* Destroys the window, shuts down GDI+, releases all resources.
* Called automatically by destructor if not called explicitly.
* After calling this, Initialize() must be called again before reuse.
*/
void Cleanup();
// Disable copy constructor and assignment operator
// The indicator manages Windows resources that shouldn't be copied
DwellIndicator(const DwellIndicator&) = delete;
DwellIndicator& operator=(const DwellIndicator&) = delete;
private:
/**
* @brief Pointer to implementation (Pimpl idiom)
*
* This hides all Windows/GDI+ implementation details from the header,
* reducing compile dependencies and keeping the interface clean.
*/
std::unique_ptr<DwellIndicatorImpl> m_impl;
};

View File

@@ -0,0 +1,595 @@
#include "pch.h"
#include <common/SettingsAPI/settings_objects.h>
#include <interface/powertoy_module_interface.h>
#include "trace.h"
#include <atomic>
#include <thread>
#include <common/utils/logger_helper.h>
#include "DwellIndicator.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
namespace
{
// JSON configuration keys for settings persistence
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_DELAY_TIME_MS[] = L"delay_time_ms";
const wchar_t JSON_KEY_SETTLE_TIME_SECONDS[] = L"settle_time_seconds";
// Update interval for the visual indicator (in milliseconds)
// 30ms gives ~33 FPS for smooth animation without excessive CPU usage
constexpr DWORD kIndicatorUpdateIntervalMs = 30;
}
/**
* @brief Send a left mouse click via Windows input system
*
* Simulates a complete left click (down + up) at the current cursor position.
* This is the core functionality that gets triggered after the dwell delay.
*/
static void SendLeftClick()
{
INPUT inputs[2]{};
// First input: Left mouse button down
inputs[0].type = INPUT_MOUSE;
inputs[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
// Second input: Left mouse button up
inputs[1].type = INPUT_MOUSE;
inputs[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
// Send both inputs to simulate a complete click
SendInput(2, inputs, sizeof(INPUT));
}
/**
* @brief Main DwellCursor PowerToy module implementation
*
* This class implements the dwell cursor functionality:
* - Monitors mouse movement continuously
* - Detects when mouse becomes stationary
* - Shows visual countdown indicator
* - Triggers left click after configured delay
* - Provides hotkey toggle for enable/disable
*
* State Management:
* - m_enabled: Whether module is active (controlled by PowerToys settings)
* - m_armed: Whether dwell clicking is currently armed (toggled by hotkey)
* - firedForThisStationary: Prevents multiple clicks during one stationary period
*/
class DwellCursorModule : public PowertoyModuleIface
{
private:
// Core module state - SINGLE DECLARATIONS ONLY
bool m_enabled{ false }; // Module enabled/disabled state
Hotkey m_activationHotkey{}; // Hotkey for toggling armed state
// Configuration settings - SINGLE DECLARATIONS ONLY
std::atomic<int> m_delayMs{ 1000 }; // Dwell delay in milliseconds (500-10000ms)
std::atomic<int> m_settleTimeSeconds{ 1 }; // Settle time in seconds (1-5s)
// Runtime state management - SINGLE DECLARATIONS ONLY
std::atomic<bool> m_armed{ true }; // Whether dwell clicking is armed
std::atomic<bool> m_stop{ false }; // Signal to stop the worker thread
std::thread m_worker; // Background thread for mouse monitoring
// Visual feedback system
std::unique_ptr<DwellIndicator> m_indicator;
// Progress tracking - Use member variable instead of static
float m_lastProgress{ -1.0f }; // Last progress value for change detection
// Mouse movement sensitivity (pixels) - SINGLE DECLARATION ONLY
// Movement within this threshold is considered "stationary"
static constexpr int kMoveThresholdPx = 5;
public:
/**
* @brief Constructor - Initialize the DwellCursor module
*
* Sets up logging, loads settings, configures default hotkey,
* and creates the visual indicator instance.
*/
DwellCursorModule()
{
// Initialize logging system for debugging and telemetry
LoggerHelpers::init_logger(L"DwellCursor", L"ModuleInterface", "dwell-cursor");
Logger::trace(L"DwellCursor: Constructor called");
// Load saved settings from PowerToys configuration
init_settings();
// Set default hotkey if not configured: Win+Alt+D
if (m_activationHotkey.key == 0)
{
m_activationHotkey.win = true; // Windows key required
m_activationHotkey.alt = true; // Alt key required
m_activationHotkey.key = 'D'; // D key
}
// Create visual indicator instance (but don't initialize yet)
m_indicator = std::make_unique<DwellIndicator>();
Logger::trace(L"DwellCursor: Constructor completed");
}
/**
* @brief Destructor cleanup
*/
virtual void destroy() override
{
disable(); // Stop all activity
delete this;
}
// PowerToy identification methods
virtual const wchar_t* get_name() override { return L"DwellCursor"; }
virtual const wchar_t* get_key() override { return L"DwellCursor"; }
/**
* @brief Get module configuration for PowerToys settings UI
*/
virtual bool get_config(wchar_t* buffer, int* buffer_size) override
{
HINSTANCE hinstance = reinterpret_cast<HINSTANCE>(&__ImageBase);
PowerToysSettings::Settings settings(hinstance, get_name());
return settings.serialize_to_buffer(buffer, buffer_size);
}
/**
* @brief Apply new configuration from PowerToys settings UI
*/
virtual void set_config(const wchar_t* config) override
{
try
{
PowerToysSettings::PowerToyValues values = PowerToysSettings::PowerToyValues::from_json_string(config, get_key());
parse_settings(values);
}
catch (...)
{
// Ignore configuration errors to prevent crashes
}
}
virtual void call_custom_action(const wchar_t* /*action*/) override {}
/**
* @brief Enable the DwellCursor module
*
* This is called when:
* 1. PowerToys starts up (if module is enabled in settings)
* 2. User enables the module via PowerToys settings UI
*
* Actions performed:
* 1. Initialize visual indicator system
* 2. Start background mouse monitoring thread
* 3. Begin dwell detection
*/
virtual void enable() override
{
if (m_enabled)
{
Logger::trace(L"DwellCursor: Already enabled");
return;
}
Logger::trace(L"DwellCursor: Enabling module");
m_enabled = true;
m_stop = false;
// Initialize the visual indicator system (GDI+, window creation)
if (m_indicator)
{
if (!m_indicator->Initialize())
{
Logger::trace(L"DwellCursor: Failed to initialize visual indicator");
// Continue without visual indicator - core functionality still works
}
else
{
Logger::trace(L"DwellCursor: Visual indicator initialized successfully");
}
}
else
{
Logger::trace(L"DwellCursor: No indicator instance available");
}
// Start the mouse monitoring thread
m_worker = std::thread([this]() { this->RunLoop(); });
Logger::trace(L"DwellCursor: Module enabled and worker thread started");
}
/**
* @brief Disable the DwellCursor module
*
* This is called when:
* 1. PowerToys shuts down
* 2. User disables the module via PowerToys settings UI
*
* Actions performed:
* 1. Stop mouse monitoring thread
* 2. Hide any visible indicator
* 3. Clean up visual indicator resources
*/
virtual void disable() override
{
if (!m_enabled)
{
Logger::trace(L"DwellCursor: Already disabled");
return;
}
Logger::trace(L"DwellCursor: Disabling module");
m_enabled = false;
m_stop = true;
// Wait for worker thread to finish
if (m_worker.joinable()) m_worker.join();
// Clean up visual indicator resources
if (m_indicator)
{
m_indicator->Cleanup();
}
Logger::trace(L"DwellCursor: Module disabled");
}
virtual bool is_enabled() override { return m_enabled; }
virtual bool is_enabled_by_default() const override { return false; } // User must explicitly enable
/**
* @brief Report hotkeys to PowerToys for registration
*/
virtual size_t get_hotkeys(Hotkey* buffer, size_t buffer_size) override
{
if (buffer && buffer_size >= 1)
{
buffer[0] = m_activationHotkey;
}
return 1; // We have exactly one hotkey
}
/**
* @brief Handle hotkey press events
*
* The hotkey toggles the "armed" state:
* - Armed: Dwell clicking is active, countdown indicator shows
* - Disarmed: No dwell clicking, indicator hidden
*
* This allows users to temporarily disable dwell clicking without
* going into settings (e.g., when typing or doing precise work).
*
* @param hotkeyId Index of the pressed hotkey (we only have one)
* @return true if handled, false otherwise
*/
virtual bool on_hotkey(size_t hotkeyId) override
{
// Handle our single registered hotkey
if (hotkeyId == 0)
{
// Toggle armed state (enabled/disabled functionality)
m_armed = !m_armed.load();
// Hide indicator immediately when disarming or when module disabled
if ((!m_armed || !m_enabled) && m_indicator)
{
m_indicator->Hide();
}
Logger::trace(L"DwellCursor: Hotkey pressed, armed={}, enabled={}", m_armed.load(), m_enabled);
return true;
}
return false;
}
private:
/**
* @brief Load settings from PowerToys configuration files
*/
void init_settings()
{
try
{
PowerToysSettings::PowerToyValues settings = PowerToysSettings::PowerToyValues::load_from_settings_file(get_key());
parse_settings(settings);
}
catch (...)
{
// Use default settings if loading fails
}
}
/**
* @brief Parse and apply settings from JSON configuration
*
* Extracts:
* - Activation hotkey configuration
* - Dwell delay time (with validation)
*/
void parse_settings(PowerToysSettings::PowerToyValues& settings)
{
auto obj = settings.get_raw_json();
if (!obj.GetView().Size()) return;
// Parse hotkey configuration
try
{
auto jsonHotkey = obj.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_ACTIVATION_SHORTCUT);
auto hk = PowerToysSettings::HotkeyObject::from_json(jsonHotkey);
m_activationHotkey = {};
m_activationHotkey.win = hk.win_pressed();
m_activationHotkey.ctrl = hk.ctrl_pressed();
m_activationHotkey.shift = hk.shift_pressed();
m_activationHotkey.alt = hk.alt_pressed();
m_activationHotkey.key = static_cast<unsigned char>(hk.get_code());
}
catch (...)
{
// Keep default hotkey if parsing fails
}
// Parse dwell delay setting
try
{
auto jsonDelay = obj.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_DELAY_TIME_MS);
int v = static_cast<int>(jsonDelay.GetNamedNumber(JSON_KEY_VALUE));
// Validate delay range: 0.5 seconds to 10 seconds
if (v < 500) v = 500; // Minimum 0.5 seconds
if (v > 10000) v = 10000; // Maximum 10 seconds
m_delayMs = v;
}
catch (...)
{
// Keep default delay if parsing fails
}
// Parse settle time setting
try
{
auto jsonSettleTime = obj.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_SETTLE_TIME_SECONDS);
int v = static_cast<int>(jsonSettleTime.GetNamedNumber(JSON_KEY_VALUE));
// Validate settle time range: 1 to 5 seconds
if (v < 1) v = 1; // Minimum 1 second
if (v > 5) v = 5; // Maximum 5 seconds
m_settleTimeSeconds = v;
}
catch (...)
{
// Keep default settle time if parsing fails
}
}
/**
* @brief Check if two points are within movement threshold
*
* @param a First coordinate
* @param b Second coordinate
* @param thr Threshold in pixels
* @return true if coordinates are within threshold (considered "near")
*/
static bool Near(int a, int b, int thr) { return (abs(a - b) <= thr); }
/**
* @brief Main mouse monitoring loop (runs in background thread)
*
* This is the core logic that runs continuously while the module is enabled:
*
* State Machine:
* 1. Monitor mouse position every 50ms (20 Hz)
* 2. If mouse moves > threshold: Reset timer, hide indicator
* 3. If mouse stationary for SETTLE_TIME: Show indicator
* 4. If mouse stationary for SETTLE_TIME + dwell delay: Send click
*
* CRITICAL: This method handles ALL progress reset logic
*/
void RunLoop()
{
constexpr DWORD ACTIVE_POLL_INTERVAL = 50; // 50ms = 20 Hz monitoring when active
constexpr DWORD INACTIVE_POLL_INTERVAL = 200; // 200ms when disabled
// Initialize tracking variables
POINT last{}; // Last recorded mouse position
GetCursorPos(&last); // Get initial position
DWORD lastMove = GetTickCount(); // Time of last movement
bool firedForThisStationary = false; // Prevents multiple clicks during one stationary period
bool indicatorShown = false; // Current indicator visibility state
DWORD lastIndicatorUpdate = 0; // Last time we updated indicator progress
Logger::trace(L"DwellCursor: RunLoop started with 50ms polling and {}s configurable settle time, enabled={}, armed={}",
m_settleTimeSeconds.load(), m_enabled, m_armed.load());
// Main monitoring loop - continues until module shutdown
while (!m_stop)
{
// Performance optimization: When module disabled, sleep longer and skip processing
if (!m_enabled)
{
// Hide any visible indicator when disabled
if (indicatorShown && m_indicator)
{
m_indicator->Hide();
indicatorShown = false;
m_lastProgress = -1.0f; // Reset progress tracking
}
Sleep(INACTIVE_POLL_INTERVAL); // Sleep 200ms when disabled
continue;
}
// Get current mouse position and time
POINT p{};
GetCursorPos(&p);
DWORD currentTime = GetTickCount();
// Check if mouse has moved beyond our threshold
if (!Near(p.x, last.x, kMoveThresholdPx) || !Near(p.y, last.y, kMoveThresholdPx))
{
// MOUSE MOVEMENT DETECTED - RESET ALL STATE
Logger::trace(L"DwellCursor: Mouse movement detected, resetting state");
// Update tracking variables
last = p; // Record new position
lastMove = currentTime; // Record movement time
firedForThisStationary = false; // Re-arm for next stationary period
// CRITICAL: Hide indicator and reset progress immediately on movement
if (indicatorShown && m_indicator)
{
m_indicator->Hide();
indicatorShown = false;
}
// Reset progress tracking for next stationary period
m_lastProgress = -1.0f;
}
else
{
// MOUSE IS STATIONARY - Process dwell logic
// Check if we should process dwell logic
if (m_enabled && m_armed && !firedForThisStationary)
{
// Calculate how long mouse has been stationary
DWORD elapsed = currentTime - lastMove;
DWORD delayMs = static_cast<DWORD>(m_delayMs.load());
DWORD settleTimeMs = static_cast<DWORD>(m_settleTimeSeconds.load() * 1000); // Convert seconds to milliseconds
DWORD totalTimeRequired = settleTimeMs + delayMs; // Settle time + dwell delay
if (elapsed >= totalTimeRequired)
{
// SETTLE TIME + DWELL DELAY COMPLETED - TRIGGER CLICK
Logger::trace(L"DwellCursor: Triggering click after {}ms total ({}ms settle + {}ms dwell)", elapsed, settleTimeMs, delayMs);
// Hide indicator before clicking
if (indicatorShown && m_indicator)
{
m_indicator->Hide();
indicatorShown = false;
}
// Reset progress tracking
m_lastProgress = -1.0f;
SendLeftClick(); // Send the mouse click
firedForThisStationary = true; // Prevent additional clicks
}
else if (elapsed >= settleTimeMs)
{
// SETTLE TIME COMPLETED - START/UPDATE COUNTDOWN INDICATOR
DWORD dwellElapsed = elapsed - settleTimeMs; // Time since settle completed
// Show indicator if not already visible
if (!indicatorShown && m_indicator)
{
Logger::trace(L"DwellCursor: Settle time ({}ms) completed, showing NEW indicator at ({}, {}) - dwellElapsed={}ms, delayMs={}",
settleTimeMs, p.x, p.y, dwellElapsed, delayMs);
// CRITICAL: Force complete reset before showing
m_lastProgress = -1.0f;
m_indicator->Show(p.x, p.y); // This internally resets indicator progress to 0.0
indicatorShown = true;
lastIndicatorUpdate = currentTime; // Reset update timer when showing
}
// Update indicator progress ONLY at throttled intervals
if (indicatorShown && (currentTime - lastIndicatorUpdate >= ACTIVE_POLL_INTERVAL))
{
// Calculate progress as percentage: 0.0 = just started, 1.0 = almost complete
float newProgress = static_cast<float>(dwellElapsed) / static_cast<float>(delayMs);
if (newProgress > 1.0f) newProgress = 1.0f; // Clamp to prevent over-draw
// Only update if progress changed significantly (at least 3% or 0.03) OR forced reset
if (abs(newProgress - m_lastProgress) >= 0.03f || m_lastProgress < 0.0f)
{
Logger::trace(L"DwellCursor: Updating progress from {:.2f} to {:.2f} (dwellElapsed={}ms)",
m_lastProgress, newProgress, dwellElapsed);
if (m_indicator)
{
m_indicator->UpdateProgress(newProgress);
}
m_lastProgress = newProgress;
lastIndicatorUpdate = currentTime;
}
}
}
// else: Still in settle time, do nothing (no indicator shown)
}
else if (indicatorShown && m_indicator)
{
// STATIONARY BUT CONDITIONS NOT MET - HIDE INDICATOR
// This happens when: not enabled, not armed, or already fired
Logger::trace(L"DwellCursor: Hiding indicator - conditions not met (enabled={}, armed={}, fired={})",
m_enabled, m_armed.load(), firedForThisStationary);
m_indicator->Hide();
indicatorShown = false;
// Reset progress tracking
m_lastProgress = -1.0f;
}
}
// Sleep appropriate interval based on activity (20 Hz when active)
Sleep(ACTIVE_POLL_INTERVAL);
}
// THREAD SHUTDOWN CLEANUP
Logger::trace(L"DwellCursor: RunLoop shutdown - cleaning up");
// Hide indicator when stopping
if (indicatorShown && m_indicator)
{
m_indicator->Hide();
}
// Final progress reset
m_lastProgress = -1.0f;
Logger::trace(L"DwellCursor: RunLoop ended");
}
};
// ============================================================================
// DLL Entry Points
// ============================================================================
/**
* @brief DLL entry point for Windows module loading
*/
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
Trace::RegisterProvider(); // Initialize ETW tracing
break;
case DLL_PROCESS_DETACH:
Trace::UnregisterProvider(); // Cleanup ETW tracing
break;
}
return TRUE;
}
/**
* @brief PowerToys module factory function
*
* This is the entry point called by PowerToys runner to create an instance
* of our module. The runner will call this once during startup.
*
* @return New instance of DwellCursorModule
*/
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
{
return new DwellCursorModule();
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" />
</packages>

View File

@@ -0,0 +1 @@
#include "pch.h"

View File

@@ -0,0 +1,20 @@
#pragma once
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <ShellScalingApi.h>
#include <dwmapi.h>
#include <stdint.h>
#include <atomic>
#include <thread>
#include <chrono>
#include <optional>
#include <string>
#include <memory>
#include <algorithm>
#include <cmath>
#include <common/SettingsAPI/settings_objects.h>
#include <interface/powertoy_module_interface.h>
#include <common/logger/logger.h>
#include <common/utils/logger_helper.h>

View File

@@ -0,0 +1,2 @@
#pragma once
#define IDS_MODULE_NAME 1001

View File

@@ -0,0 +1,2 @@
#include "pch.h"
#include "trace.h"

View File

@@ -0,0 +1,2 @@
#pragma once
namespace Trace { inline void RegisterProvider(){} inline void UnregisterProvider(){} }

View File

@@ -177,6 +177,7 @@ int runner(bool isProcessElevated, bool openSettings, std::string settingsWindow
L"PowerToys.WorkspacesModuleInterface.dll",
L"PowerToys.CmdPalModuleInterface.dll",
L"PowerToys.ZoomItModuleInterface.dll",
L"PowerToys.DwellCursor.dll",
};
for (auto moduleSubdir : knownModules)

View File

@@ -0,0 +1,42 @@
// 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.Text.Json.Serialization;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class DwellCursorSettings : BasePTModuleSettings, ISettingsConfig, IHotkeyConfig
{
public const string ModuleName = "DwellCursor";
[JsonPropertyName("properties")]
public DwellCursorSettingsProperties Properties { get; set; } = new DwellCursorSettingsProperties();
public DwellCursorSettings()
{
Name = ModuleName;
Version = "1.0";
}
public string GetModuleName() => Name;
public ModuleType GetModuleType() => ModuleType.MouseJump; // grouped under Mouse Utils UI
public HotkeyAccessor[] GetAllHotkeyAccessors()
{
return new HotkeyAccessor[]
{
new HotkeyAccessor(
() => Properties.ActivationShortcut,
value => Properties.ActivationShortcut = value ?? DwellCursorSettingsProperties.DefaultActivationShortcut,
"MouseUtils_DwellCursor_ActivationShortcut"),
};
}
public bool UpgradeSettingsConfiguration() => false;
}
}

View File

@@ -0,0 +1,22 @@
// 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.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class DwellCursorSettingsProperties
{
[JsonPropertyName("activation_shortcut")]
public HotkeySettings ActivationShortcut { get; set; } = DefaultActivationShortcut;
public static HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, false, true, false, 0x44); // Win + Alt + D
[JsonPropertyName("delay_time_ms")]
public IntProperty DelayTimeMs { get; set; } = new IntProperty() { Value = 1000 }; // 0.5s-10s
[JsonPropertyName("settle_time_seconds")]
public IntProperty SettleTimeSeconds { get; set; } = new IntProperty() { Value = 1 }; // 1-5 seconds
}
}

View File

@@ -282,6 +282,22 @@ namespace Microsoft.PowerToys.Settings.UI.Library
}
}
private bool dwellCursor; // defaulting to off
[JsonPropertyName("DwellCursor")]
public bool DwellCursor
{
get => dwellCursor;
set
{
if (dwellCursor != value)
{
LogTelemetryEvent(value);
dwellCursor = value;
}
}
}
private bool powerAccent; // defaulting to off
[JsonPropertyName("QuickAccent")]

View File

@@ -0,0 +1,25 @@
// 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.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class SndDwellCursorSettings
{
[JsonPropertyName("DwellCursor")]
public DwellCursorSettings DwellCursor { get; set; }
public SndDwellCursorSettings()
{
}
public SndDwellCursorSettings(DwellCursorSettings s)
{
DwellCursor = s;
}
public string ToJsonString() => System.Text.Json.JsonSerializer.Serialize(this);
}
}

View File

@@ -169,7 +169,7 @@
Severity="Informational"
Visibility="{x:Bind ViewModel.IsAnimationEnabledBySystem, Mode=OneWay, Converter={StaticResource ReverseBoolToVisibilityConverter}}">
<InfoBar.ActionButton>
<HyperlinkButton x:Uid="OpenSettings" Click="OpenAnimationsSettings_Click" />
<HyperlinkButton x:Uid="OpenAnimationsSettings" Click="OpenAnimationsSettings_Click" />
</InfoBar.ActionButton>
</InfoBar>
<tkcontrols:SettingsExpander
@@ -413,6 +413,42 @@
</tkcontrols:SettingsExpander.Items>
</tkcontrols:SettingsExpander>
</controls:SettingsGroup>
<!-- Dwell Cursor -->
<controls:SettingsGroup x:Uid="MouseUtils_DwellCursor">
<tkcontrols:SettingsCard
Name="MouseUtilsEnableDwellCursor"
x:Uid="MouseUtils_Enable_DwellCursor"
HeaderIcon="{ui:BitmapIcon Source=/Assets/Settings/Icons/MouseCrosshairs.png}">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.IsDwellCursorEnabled, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsExpander
Name="MouseUtilsDwellCursorActivationShortcut"
x:Uid="MouseUtils_DwellCursor_ActivationShortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xEDA7;}"
IsEnabled="{x:Bind ViewModel.IsDwellCursorEnabled, Mode=OneWay}"
IsExpanded="True">
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind Path=ViewModel.DwellCursorActivationShortcut, Mode=TwoWay}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard Name="MouseUtilsDwellCursorDelayMs" x:Uid="MouseUtils_DwellCursor_DelayMs">
<Slider
MinWidth="{StaticResource SettingActionControlMinWidth}"
Maximum="10"
Minimum="1"
Value="{x:Bind ViewModel.DwellCursorDelayTimeSeconds, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard Name="MouseUtilsDwellCursorSettleTimeSeconds" x:Uid="MouseUtils_DwellCursor_SettleTimeSeconds">
<Slider
MinWidth="{StaticResource SettingActionControlMinWidth}"
Maximum="5"
Minimum="1"
Value="{x:Bind ViewModel.DwellCursorSettleTimeSeconds, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
</tkcontrols:SettingsExpander.Items>
</tkcontrols:SettingsExpander>
</controls:SettingsGroup>
</StackPanel>
</controls:SettingsPageControl.ModuleContent>
<controls:SettingsPageControl.PrimaryLinks>

View File

@@ -42,6 +42,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
SettingsRepository<MouseHighlighterSettings>.GetInstance(settingsUtils),
SettingsRepository<MouseJumpSettings>.GetInstance(settingsUtils),
SettingsRepository<MousePointerCrosshairsSettings>.GetInstance(settingsUtils),
SettingsRepository<DwellCursorSettings>.GetInstance(settingsUtils),
ShellPage.SendDefaultIPCMessage);
DataContext = ViewModel;

View File

@@ -5299,4 +5299,33 @@ To record a specific window, enter the hotkey with the Alt key in the opposite m
<data name="UtilitiesHeader.Title" xml:space="preserve">
<value>Utilities</value>
</data>
<data name="MouseUtils_DwellCursor.Header" xml:space="preserve">
<value>Dwell Cursor (placeholder)</value>
<comment>Dwell Cursor description</comment>
</data>
<data name="MouseUtils_Enable_DwellCursor.Header" xml:space="preserve">
<value>Enable Dwell Cursor</value>
<comment>"Dwell Cursor" is the name of the utility.</comment>
</data>
<data name="MouseUtils_GlidingCursor_InitialSpeed.Header" xml:space="preserve">
<value>Initial line speed</value>
</data>
<data name="MouseUtils_DwellCursor_DelayMs.Header" xml:space="preserve">
<value>Delay time (in seconds)</value>
</data>
<data name="MouseUtils_DwellCursor_DelayMs.Description" xml:space="preserve">
<value>Seconds to wait before automatically clicking when the cursor is still (110)</value>
</data>
<data name="MouseUtils_DwellCursor_ActivationShortcut.Header" xml:space="preserve">
<value>Activation shortcut</value>
</data>
<data name="MouseUtils_DwellCursor_ActivationShortcut.Description" xml:space="preserve">
<value>Customize the shortcut to turn on or off this mode</value>
</data>
<data name="MouseUtils_DwellCursor_SettleTimeSeconds.Header" xml:space="preserve">
<value>Cursor settle time (seconds)</value>
</data>
<data name="MouseUtils_DwellCursor_SettleTimeSeconds.Description" xml:space="preserve">
<value>Time the cursor must remain still before the countdown starts</value>
</data>
</root>

View File

@@ -29,13 +29,22 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private MousePointerCrosshairsSettings MousePointerCrosshairsSettingsConfig { get; set; }
public MouseUtilsViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<FindMyMouseSettings> findMyMouseSettingsRepository, ISettingsRepository<MouseHighlighterSettings> mouseHighlighterSettingsRepository, ISettingsRepository<MouseJumpSettings> mouseJumpSettingsRepository, ISettingsRepository<MousePointerCrosshairsSettings> mousePointerCrosshairsSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
private DwellCursorSettings DwellCursorSettingsConfig { get; set; }
public MouseUtilsViewModel(
ISettingsUtils settingsUtils,
ISettingsRepository<GeneralSettings> settingsRepository,
ISettingsRepository<FindMyMouseSettings> findMyMouseSettingsRepository,
ISettingsRepository<MouseHighlighterSettings> mouseHighlighterSettingsRepository,
ISettingsRepository<MouseJumpSettings> mouseJumpSettingsRepository,
ISettingsRepository<MousePointerCrosshairsSettings> mousePointerCrosshairsSettingsRepository,
ISettingsRepository<DwellCursorSettings> dwellCursorSettingsRepository,
Func<string, int> ipcMSGCallBackFunc)
{
SettingsUtils = settingsUtils;
// To obtain the general settings configurations of PowerToys Settings.
ArgumentNullException.ThrowIfNull(settingsRepository);
GeneralSettingsConfig = settingsRepository.SettingsConfig;
InitializeEnabledValues();
@@ -43,7 +52,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// To obtain the find my mouse settings, if the file exists.
// If not, to create a file with the default settings and to return the default configurations.
ArgumentNullException.ThrowIfNull(findMyMouseSettingsRepository);
FindMyMouseSettingsConfig = findMyMouseSettingsRepository.SettingsConfig;
_findMyMouseActivationMethod = FindMyMouseSettingsConfig.Properties.ActivationMethod.Value < 4 ? FindMyMouseSettingsConfig.Properties.ActivationMethod.Value : 0;
_findMyMouseIncludeWinKey = FindMyMouseSettingsConfig.Properties.IncludeWinKey.Value;
@@ -65,7 +73,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_findMyMouseShakingFactor = FindMyMouseSettingsConfig.Properties.ShakingFactor.Value;
ArgumentNullException.ThrowIfNull(mouseHighlighterSettingsRepository);
MouseHighlighterSettingsConfig = mouseHighlighterSettingsRepository.SettingsConfig;
string leftClickColor = MouseHighlighterSettingsConfig.Properties.LeftButtonClickColor.Value;
_highlighterLeftButtonClickColor = !string.IsNullOrEmpty(leftClickColor) ? leftClickColor : "#a6FFFF00";
@@ -85,7 +92,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
this.InitializeMouseJumpSettings(mouseJumpSettingsRepository);
ArgumentNullException.ThrowIfNull(mousePointerCrosshairsSettingsRepository);
MousePointerCrosshairsSettingsConfig = mousePointerCrosshairsSettingsRepository.SettingsConfig;
string crosshairsColor = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsColor.Value;
@@ -103,8 +109,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_mousePointerCrosshairsFixedLength = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsFixedLength.Value;
_mousePointerCrosshairsAutoActivate = MousePointerCrosshairsSettingsConfig.Properties.AutoActivate.Value;
int isEnabled = 0;
// Dwell Cursor
ArgumentNullException.ThrowIfNull(dwellCursorSettingsRepository);
DwellCursorSettingsConfig = dwellCursorSettingsRepository.SettingsConfig;
_dwellCursorDelayTimeSeconds = DwellCursorSettingsConfig.Properties.DelayTimeMs.Value / 1000;
_dwellCursorSettleTimeSeconds = DwellCursorSettingsConfig.Properties.SettleTimeSeconds.Value;
int isEnabled = 0;
Utilities.NativeMethods.SystemParametersInfo(Utilities.NativeMethods.SPI_GETCLIENTAREAANIMATION, 0, ref isEnabled, 0);
_isAnimationEnabledBySystem = isEnabled != 0;
@@ -151,6 +162,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
_isMousePointerCrosshairsEnabled = GeneralSettingsConfig.Enabled.MousePointerCrosshairs;
}
// Dwell Cursor enabled state
_isDwellCursorEnabled = GeneralSettingsConfig.Enabled.DwellCursor;
}
public override Dictionary<string, HotkeySettings[]> GetAllHotkeySettings()
@@ -163,6 +177,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
MousePointerCrosshairsActivationShortcut,
GlidingCursorActivationShortcut],
[MouseJumpSettings.ModuleName] = [MouseJumpActivationShortcut],
[DwellCursorSettings.ModuleName] = [DwellCursorActivationShortcut],
};
return hotkeysDict;
@@ -959,6 +974,84 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
SettingsUtils.SaveSettings(MousePointerCrosshairsSettingsConfig.ToJsonString(), MousePointerCrosshairsSettings.ModuleName);
}
// Dwell Cursor properties
private bool _isDwellCursorEnabled;
private int _dwellCursorDelayTimeSeconds;
private int _dwellCursorSettleTimeSeconds;
public bool IsDwellCursorEnabled
{
get => _isDwellCursorEnabled;
set
{
if (_isDwellCursorEnabled != value)
{
_isDwellCursorEnabled = value;
GeneralSettingsConfig.Enabled.DwellCursor = value;
OnPropertyChanged(nameof(IsDwellCursorEnabled));
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoing.ToString());
NotifyDwellCursorPropertyChanged();
}
}
}
public HotkeySettings DwellCursorActivationShortcut
{
get => DwellCursorSettingsConfig.Properties.ActivationShortcut;
set
{
if (DwellCursorSettingsConfig.Properties.ActivationShortcut != value)
{
DwellCursorSettingsConfig.Properties.ActivationShortcut = value ?? DwellCursorSettingsProperties.DefaultActivationShortcut;
NotifyDwellCursorPropertyChanged();
}
}
}
public int DwellCursorDelayTimeSeconds
{
get => _dwellCursorDelayTimeSeconds;
set
{
if (value != _dwellCursorDelayTimeSeconds)
{
_dwellCursorDelayTimeSeconds = value;
// Convert seconds to milliseconds for storage
DwellCursorSettingsConfig.Properties.DelayTimeMs.Value = value * 1000;
NotifyDwellCursorPropertyChanged();
}
}
}
public int DwellCursorSettleTimeSeconds
{
get => _dwellCursorSettleTimeSeconds;
set
{
if (value != _dwellCursorSettleTimeSeconds)
{
_dwellCursorSettleTimeSeconds = value;
DwellCursorSettingsConfig.Properties.SettleTimeSeconds.Value = value;
NotifyDwellCursorPropertyChanged();
}
}
}
public void NotifyDwellCursorPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(propertyName);
var outsettings = new SndDwellCursorSettings(DwellCursorSettingsConfig);
var ipcMessage = new SndModuleSettings<SndDwellCursorSettings>(outsettings);
SendConfigMSG(ipcMessage.ToJsonString());
SettingsUtils.SaveSettings(DwellCursorSettingsConfig.ToJsonString(), DwellCursorSettings.ModuleName);
}
public void RefreshEnabledState()
{
InitializeEnabledValues();
@@ -966,6 +1059,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
OnPropertyChanged(nameof(IsMouseHighlighterEnabled));
OnPropertyChanged(nameof(IsMouseJumpEnabled));
OnPropertyChanged(nameof(IsMousePointerCrosshairsEnabled));
OnPropertyChanged(nameof(IsDwellCursorEnabled));
}
private Func<string, int> SendConfigMSG { get; }