mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-22 10:07:37 +00:00
## Summary of the Pull Request Accumulated information from internal transition about the modules development, and reworked it to be added in dev docs. Also the dev docs intself was restructured to be more organized. New pages was verified by transition team. ## PR Checklist - [x] **Dev docs:** Added/updated --------- Co-authored-by: Zhaopeng Wang (from Dev Box) <zhaopengwang@microsoft.com> Co-authored-by: Hao Liu <liuhao3418@gmail.com> Co-authored-by: Peiyao Zhao <105847726+zhaopy536@users.noreply.github.com> Co-authored-by: Mengyuan <162882040+chenmy77@users.noreply.github.com> Co-authored-by: zhaopeng wang <33367956+wang563681252@users.noreply.github.com> Co-authored-by: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com>
4.0 KiB
4.0 KiB
Always on Top
Public overview - Microsoft Learn
Quick Links
Overview
The Always on Top module allows users to pin windows on top of others, ensuring they remain visible even when switching between applications. The module provides visual indicators (customizable borders) to identify which windows are pinned.
Features
- Pin any window to stay on top of other windows
- Customizable border color, opacity, and thickness around pinned windows
- User-defined keyboard shortcut for toggling window pinning
- Visual indicators to identify pinned windows
Architecture
Main Components
- Hotkey Listener: Detects the user-defined hotkey to toggle the Always on Top state
- AlwaysOnTop: Manages the state of windows, ensuring the selected window stays on top
- Settings: Stores user preferences and configurations
- WindowHook: Hooks all window events
Data Flow
- The Hotkey Listener detects the hotkey press and notifies the AlwaysOnTop
- The AlwaysOnTop updates the window state and interacts with the operating system to keep the window on top
- User preferences are saved and loaded from the Settings
Code Structure
Key Files
- AlwaysOnTop.cpp: Contains the core logic for the module, including initialization and event handling
- Settings.cpp: Defines the settings structure and provides methods to load and save settings
- main.cpp: Starts thread and initializes AlwaysOnTop
Initialization
The module is initialized in the AlwaysOnTop class. During initialization, the following steps are performed:
- LoadSettings: The module loads user settings from a configuration file
- RegisterHotkey: The HotkeyManager registers the keyboard shortcut for pinning/unpinning windows
- SubscribeToEvents: Event handlers are attached to respond to user actions, such as pressing the hotkey
Pinning and Unpinning Windows
The AlwaysOnTop class handles the pinning and unpinning of windows. Key methods include:
- PinTopmostWindow: Pins the specified window on top of others and applies visual indicators
- UnpinTopmostWindowss: Removes the pinning status and visual indicators from the specified window
- AssignBorder: Applies a colored border around the pinned window based on user settings
Settings Management
The Settings class manages the module's settings. Key methods include:
- LoadSettings: Loads settings from a configuration file
- NotifyObservers: Distributes the data for the settings
- GetDefaultSettings: Returns the default settings for the module
User Interface
The module provides a user interface for configuring settings in the PowerToys Settings UI. This interface is implemented using XAML and includes options for customizing the:
- Border color
- Border opacity
- Border thickness
- Keyboard shortcut
Development Environment Setup
Prerequisites
- Visual Studio 2019 or later
- Windows 10 SDK
- PowerToys repository cloned from GitHub
Building and Testing
- Clone the repository:
git clone https://github.com/microsoft/PowerToys.git
- Open PowerToys.sln in Visual Studio
- Select the Release configuration and build the solution
- Run PowerToys.exe from the output directory to test the module