Docking Stations That Rearrange Displays
A docking station that rearranges monitors on every connect is an IT ticket classic. The user docks the laptop, the external monitors come up in a different order than last time, the clipboard overlay that was on the right monitor is now on the left, the taskbar has moved, and the user has to spend two minutes reconfiguring before they can work. The root cause is that Windows assigns display IDs at hot-plug time and the IDs are not stable across dock cycles. An overlay that persists its position by display ID will be wrong every time. The fix is to persist by geometry and by monitor name, not by display index. This guide explains why the rearrangement happens, what is stable and what is not, and how a well-behaved overlay persists position across dock and undock.
For neighbouring topics, see sleep/wake false copy events and left edge vs right edge: handedness and taskbars.
Why docking rearranges displays
Windows identifies monitors by a few different identifiers, none of which is fully stable:
- Display index (
\\.\DISPLAY1,\\.\DISPLAY2, etc.) — assigned at hot-plug time, in the order the monitors are detected. The first monitor to respond to hot-plug detect gets the lowest available index. Docking stations with multiple downstream ports may bring up monitors in a different order on each connect, depending on the order in which the dock's internal hub enumerates its ports. - Device ID — a string derived from the monitor's EDID, which includes the manufacturer, model, and serial number. Stable across reboots for the same physical monitor, but not stable if the user replaces the monitor.
- Monitor handle — a runtime handle used by the OS to refer to the monitor in the current session. Stable within a session, invalid after a session change.
- Geometry — the monitor's position and size in the virtual screen, expressed in pixels. Stable across reboots if the user does not change the arrangement, but changes if the user re-arranges or if the dock enumerates in a different order.
The display index is the least stable. A dock that brings up Monitor A before Monitor B on one connect and Monitor B before Monitor A on the next connect will swap the indices, even though the physical monitors are the same. An overlay that was configured to sit on \\.\DISPLAY2 will now be on the wrong monitor.
What is stable
The most stable identifier is the device ID, which includes the monitor's serial number. For a given physical monitor, the device ID is the same across reboots, across dock cycles, and across OS reinstalls. The cost of using the device ID is that it requires the overlay to query the monitor's EDID, which is a slightly more involved API call than querying the display index.
The next most stable is the geometry — the monitor's position in the virtual screen. If the user has arranged the monitors consistently (for example, "primary monitor at (0,0), secondary monitor at (1920,0)"), the geometry is stable across dock cycles as long as the OS restores the arrangement. Windows 10 and 11 do restore the arrangement, but only if the user has not changed it manually; if the user manually rearranges, the new arrangement is what gets restored.
The least stable is the display index. An overlay that persists by display index will be wrong on every rearrangement.
How a well-behaved overlay persists
The correct pattern is to persist a tuple of (device ID, geometry, edge choice). On startup and on display configuration change, the overlay:
- Enumerates the current monitors via the Win32
EnumDisplayMonitorsAPI or the newerDisplayConfigAPI. - For each monitor, queries the device ID and geometry.
- Looks for a monitor whose device ID matches the persisted device ID. If found, the overlay positions itself on that monitor at the persisted edge.
- If no match is found, looks for a monitor whose geometry matches the persisted geometry. This handles the case where the user has replaced the monitor with a different model but kept the same position.
- If still no match, falls back to the primary monitor and logs a warning that the persisted position could not be restored.
This pattern is robust to dock rearrangement, monitor replacement, and even OS reinstalls (as long as the device ID is stable, which it is for the same physical monitor).
What can go wrong
- The overlay persists by display index only. Symptom: the overlay is on the wrong monitor after every dock cycle. Fix: persist by device ID instead.
- The overlay re-queries the display configuration on every power-state change, including sleep/wake, and re-positions itself. Symptom: the overlay briefly disappears during sleep/wake, even if the display configuration did not actually change. Fix: only re-query on a real display-change event (
WM_DISPLAYCHANGE), not on every power event. - The overlay does not handle the case where the persisted monitor is no longer present. Symptom: the overlay fails to appear, or appears at (0,0) on the primary monitor. Fix: implement the fallback in step 5 above.
- The overlay picks the wrong monitor when the device ID matches but the geometry has changed. Symptom: the overlay appears on the right monitor but at the wrong position, because the user re-arranged. Fix: when the device ID matches but the geometry does not, update the persisted geometry to the new value.
The WM_DISPLAYCHANGE message
Windows notifies top-level windows of display configuration changes via the WM_DISPLAYCHANGE message. The message is sent to all top-level windows when the resolution, colour depth, or monitor arrangement changes. An overlay should handle this message by re-enumerating monitors and re-positioning itself.
The message is sent after the change has taken effect, so the overlay can query the new configuration immediately. The message is sent synchronously from the UI thread, so the overlay's handler should be quick — defer the actual re-positioning to a posted message or a timer if the enumeration is expensive.
For dock cycles, the sequence is typically:
- Dock is plugged in.
- The dock's downstream monitors are detected by the OS.
- The OS reconfigures the display arrangement.
WM_DISPLAYCHANGEis sent to all top-level windows.- The overlay re-enumerates, finds the persisted monitor by device ID, and re-positions itself.
The whole sequence takes 1–3 seconds, during which the overlay may be on the wrong monitor or invisible. A well-behaved overlay shows a brief "reconnecting" state or simply waits silently for the re-positioning to complete.
Multi-monitor and the primary monitor
The "primary monitor" in Windows is the monitor that contains the taskbar and the origin (0,0) of the virtual screen. The primary monitor can change across dock cycles — when the laptop is undocked, the built-in display is primary; when docked, one of the external monitors is primary.
An overlay should not assume that the primary monitor is stable. The overlay's configured monitor should be identified by device ID, not by "the primary monitor." If the user wants the overlay on the primary monitor, that is a separate preference that the overlay should re-evaluate on every display change.
For the multi-monitor discussion, see clipboard tools on multi-monitor Windows setups and how to pick which monitor Edge-Drop uses.
Honest positioning
Edge-Drop, the Windows hover-activated clipboard shelf, persists its monitor choice by a combination of device ID and geometry, and re-positions itself on WM_DISPLAYCHANGE. The shelf's choice persists across reboots and across dock cycles, which is the behaviour users expect. The shelf does not currently expose the underlying identifiers in its UI; the user-facing setting is "pick a monitor from a dropdown," and the shelf handles the persistence internally. The shelf does not handle every edge case — a monitor that is replaced with a different model with the same resolution will not be recognised, and the shelf will fall back to the primary monitor. For the vast majority of dock cycles, the persistence is correct.
What to check
If your overlay is repositioning incorrectly across dock cycles, work through these:
- Dock the laptop. Note the monitor arrangement in Settings → System → Display.
- Undock. Wait 10 seconds.
- Re-dock. Check whether the arrangement is the same as in step 1.
- If the arrangement is different, the dock is enumerating in a different order. The overlay must persist by device ID, not by index.
- If the arrangement is the same but the overlay is on the wrong monitor, the overlay is not re-querying on
WM_DISPLAYCHANGE. The overlay should be updated to handle the message.
For users who cannot update the overlay, the workaround is to manually re-select the monitor after each dock cycle. This is annoying but functional; the real fix is in the overlay's persistence logic.
Related reading
- Left Edge vs Right Edge: Handedness and Taskbars
- Vertical Monitor in Portrait: Hot Zones Change
- Clipboard Tools on Multi-Monitor Windows Setups
- Win+V Not Working on Windows 11: 9 Fixes
Sources
- Microsoft Learn — EnumDisplayMonitors — Win32 reference for the API applications use to enumerate the current monitors
- Microsoft Learn — WM_DISPLAYCHANGE message — Win32 reference for the message Windows sends when the display configuration changes
- Microsoft Learn — Display configuration API — Win32 reference for the API used to query monitor device IDs and EDID information
- Microsoft Learn — Multiple display monitors — Win32 reference for the multi-monitor programming model, including the virtual screen and primary monitor concepts
- Microsoft Support — Multiple monitors in Windows — official user-facing guide to arranging monitors, setting the primary display, and rearranging after dock cycles
Mohit Sehrawat is a B.Tech Computer Science Engineering student with a focus on software testing, bug detection, and product quality. He is interested in exploring applications, identifying issues, and improving the overall user experience through thorough testing.
GitHub · LinkedInCopy. Stack. Drop.
Transform your clipboard into an interactive edge shelf. Stack, pin, and drag assets into any app with zero friction.
Download for Windows Get from Microsoft Store
How to Install Guide · First 10 Minutes Guide · Drag & Drop Guide · Edge-Drop vs Win+V · Support
Free · Lightweight · Privacy First