<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This PR updates the PowerToys solution to support **Visual Studio 2026 (PlatformToolset v145)**. It centralizes the build configuration, updates the C++ language standards, and fixes an issue with a MouseJump unit test that appears while using the VS 2026 supported build agent. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [x] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments **Build System & Configuration:** - Updated `Cpp.Build.props` to use `v145` (VS 2026) as the default `PlatformToolset`, with fall back to `v143` for VS 2022. - Configured C++ Language Standard: - `stdcpplatest` for production projects. - Removed explicit `<PlatformToolset>` definitions from individual project files (approx. 37 modules) to inherit correctly from the central `Cpp.Build.props`. **Code Refactoring & Fixes:** - Updated `DrawingHelperTests.cs` in MouseJump Unit Test to ease the pixel difference tolerance. This became an issue after switching to the new VS2026 build agent. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed - Validated successful compilation of the entire solution. Similar updates have been made to the .NET 10 branch, but these are much cleaner and will be merged into that branch once fully confirmed working. --------- Co-authored-by: Kai Tao (from Dev Box) <kaitao@microsoft.com> Co-authored-by: Gordon Lam (SH) <yeelam@microsoft.com>
5.4 KiB
PowerToys Awake Module
A PowerToys utility that prevents Windows from sleeping and/or turning off the display.
Author: Den Delimarsky
Resources
- Awake Website - Official documentation and guides
- Microsoft Learn Documentation - Usage instructions and feature overview
- GitHub Issues - Report bugs or request features
Overview
The Awake module consists of three projects:
| Project | Purpose |
|---|---|
Awake/ |
Main WinExe application with CLI support |
Awake.ModuleServices/ |
Service layer for PowerToys integration |
AwakeModuleInterface/ |
C++ native module bridge |
How It Works
The module uses the Win32 SetThreadExecutionState() API to signal Windows that the system should remain awake:
ES_SYSTEM_REQUIRED- Prevents system sleepES_DISPLAY_REQUIRED- Prevents display sleepES_CONTINUOUS- Maintains state until explicitly changed
Operating Modes
| Mode | Description |
|---|---|
| PASSIVE | Normal power behavior (off) |
| INDEFINITE | Keep awake until manually stopped |
| TIMED | Keep awake for a specified duration |
| EXPIRABLE | Keep awake until a specific date/time |
Command-Line Usage
Awake can be run standalone with the following options:
PowerToys.Awake.exe [options]
Options:
-c, --use-pt-config Use PowerToys configuration file
-d, --display-on Keep display on (default: false)
-t, --time-limit Time limit in seconds
-p, --pid Process ID to bind to
-e, --expire-at Expiration date/time
-u, --use-parent-pid Bind to parent process
Examples
Keep system awake indefinitely:
PowerToys.Awake.exe
Keep awake for 1 hour with display on:
PowerToys.Awake.exe --time-limit 3600 --display-on
Keep awake until a specific time:
PowerToys.Awake.exe --expire-at "2024-12-31 23:59:59"
Keep awake while another process is running:
PowerToys.Awake.exe --pid 1234
Architecture
Design Highlights
-
Pure Win32 API for Tray UI - No WPF/WinForms dependencies, keeping the binary small. Uses direct
Shell_NotifyIconAPI for tray icon management. -
Reactive Extensions (Rx.NET) - Used for timed operations via
Observable.Interval()andObservable.Timer(). File system watching uses 25ms throttle to debounce rapid config changes. -
Custom SynchronizationContext - Queue-based message dispatch ensures tray operations run on a dedicated thread for thread-safe UI updates.
-
Dual-Mode Operation
- Standalone: Command-line arguments only
- Integrated: PowerToys settings file + process binding
-
Process Binding - The
--pidparameter keeps the system awake only while a target process runs, with auto-exit when the parent PowerToys runner terminates.
Key Files
| File | Purpose |
|---|---|
Program.cs |
Entry point & CLI parsing |
Core/Manager.cs |
State orchestration & power management |
Core/TrayHelper.cs |
System tray UI management |
Core/Native/Bridge.cs |
Win32 P/Invoke declarations |
Core/Threading/SingleThreadSynchronizationContext.cs |
Threading utilities |
Building
Prerequisites
- Visual Studio 2022 or 2026 with C++ and .NET workloads
- Windows SDK 10.0.26100.0 or later
Build Commands
From the src/modules/awake directory:
# Using the build script
.\scripts\Build-Awake.ps1
# Or with specific configuration
.\scripts\Build-Awake.ps1 -Configuration Debug -Platform x64
Or using MSBuild directly:
msbuild Awake\Awake.csproj /p:Configuration=Release /p:Platform=x64
Dependencies
- System.CommandLine - Command-line parsing
- System.Reactive - Rx.NET for timer management
- PowerToys.ManagedCommon - Shared PowerToys utilities
- PowerToys.Settings.UI.Lib - Settings integration
- PowerToys.Interop - Native interop layer
Configuration
When running with PowerToys (--use-pt-config), settings are stored in:
%LOCALAPPDATA%\Microsoft\PowerToys\Awake\settings.json
Known Limitations
Task Scheduler Idle Detection (#44134)
When "Keep display on" is enabled, Awake uses the ES_DISPLAY_REQUIRED flag which blocks Windows Task Scheduler from detecting the system as idle. This prevents scheduled maintenance tasks (like SSD TRIM, disk defragmentation, and other idle-triggered tasks) from running.
Per Microsoft's documentation:
"An exception would be for any presentation type application that sets the ES_DISPLAY_REQUIRED flag. This flag forces Task Scheduler to not consider the system as being idle, regardless of user activity or resource consumption."
Workarounds:
-
Disable "Keep display on" - With this setting off, Awake only uses
ES_SYSTEM_REQUIREDwhich still prevents sleep but allows Task Scheduler to detect idle state. -
Manually run maintenance tasks - For example, to run TRIM manually:
# Run as Administrator Optimize-Volume -DriveLetter C -ReTrim -Verbose
Telemetry
The module emits telemetry events for:
- Keep-awake mode changes (indefinite, timed, expirable, passive)
- Privacy-compliant event tagging via
Microsoft.PowerToys.Telemetry