PowerToys/doc/devdocs/modules/alwaysontop.md
Gleb Khmyznikov 725535b760
Some checks failed
Spell checking / Check Spelling (push) Has been cancelled
Spell checking / Report (Push) (push) Has been cancelled
Spell checking / Report (PR) (push) Has been cancelled
Spell checking / Update PR (push) Has been cancelled
[DevDocs] More content and restructure (#40165)
## 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>
2025-07-01 14:27:34 +02:00

4.0 KiB

Always on Top

Public overview - Microsoft Learn

All Issues
Bugs
Pull Requests

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

  1. The Hotkey Listener detects the hotkey press and notifies the AlwaysOnTop
  2. The AlwaysOnTop updates the window state and interacts with the operating system to keep the window on top
  3. 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:

  1. LoadSettings: The module loads user settings from a configuration file
  2. RegisterHotkey: The HotkeyManager registers the keyboard shortcut for pinning/unpinning windows
  3. 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

  1. Clone the repository: git clone https://github.com/microsoft/PowerToys.git
  2. Open PowerToys.sln in Visual Studio
  3. Select the Release configuration and build the solution
  4. Run PowerToys.exe from the output directory to test the module

Debug

  1. build the entire project
  2. launch the built Powertoys
  3. select AlwaysOnTop as the startup project in VS
  4. In the debug button, choose "Attach to process". image
  5. Attach to AlwaysOnTop.image