Skip to content

Maximized frameless window does not persist to correct display when using RDP #47016

Closed as not planned

Description

@jkleinsc

Preflight Checklist

Electron Version

37.0.0-alpha.3

What operating system(s) are you using?

Windows

Operating System Version

Windows 11 Enterprise 24H2 26100.3775

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

Electron application windows when maximized should stay on the display that they are maximized to even when the display is a client display on a RDP connection that is using multiple monitors.

Actual Behavior

Maximized Electron application windows move to the primary display after disconnecting and reconnecting via RDP when using multiple monitors for the RDP connection.

Testcase Gist URL

https://gist.github.com/jkleinsc/6553f9299e74705cb4e2d17b5928e2ec

Additional Information

Steps to reproduce:

  1. RDP into a Win11 machine/VM with VS Code installed, using the "Use all my monitors for the remote session" checked in the Display options, and optionally the "Save my settings for future connections to this virtual machine"
  2. Run 2(or more if you have more monitors) instances of VS Code.
  3. Create/open a text file in each instance
  4. Drag an instance into each window and maximize each instance to display in a different monitor.
  5. Edit the text files so that they are labeled to id each of the monitors to which they are maximized in.
  6. Terminate the RDP session
  7. Remote back in ensuring "Use all my monitors for the remote session" is checked.
  8. Observe that the windows are no longer parented into the same monitors.

Further debugging information:

The issue can be replicated with the Electron Fiddle gist attached to this issue. In order to replicate you will have to run the gist on a remote Windows machine that you are connected to with multiple monitors. Run the gist and move the application window to the non primary display. Exit the remote connection and then reconnect and the application window will now be on the primary display.

Why is this happening

The gist contains debugging information which reveals the following happening when disconnecting/connecting to RDP:
When disconnecting from RDP, display-removed events fire for all of the displays on the local machine. Additionally, a display-added event fires for a display that apparently is the default display for the remote machine. After the default display for the remote machine gets added the code here ends up firing: https://source.chromium.org/chromium/chromium/src/+/main:ui/views/win/hwnd_message_handler.cc;l=2396;drc=467a8e68f685f9cfa47ee3fbfca20c22f7f6e893 which causes the application window to move to the (new) default display.

Annotated log from attached fiddle

Here's an annotated log from running the attached fiddle that describes what is happening at what time (eg when RDP exits and reconnects):

Electron v37.0.0-alpha.3 started.

==== Dump the displays ====

Display info: {
accelerometerSupport: 'unknown',
bounds: { x: 0, y: 0, width: 2560, height: 1080 },
colorDepth: 24,
colorSpace: '{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}',
depthPerComponent: 8,
detected: true,
displayFrequency: 32,
id: 1569316729,
internal: false,
label: '',
maximumCursorSize: { width: 0, height: 0 },
monochrome: false,
nativeOrigin: { x: 0, y: 0 },
rotation: 0,
scaleFactor: 1,
size: { width: 2560, height: 1080 },
workArea: { x: 0, y: 0, width: 2560, height: 1032 },
workAreaSize: { width: 2560, height: 1032 },
touchSupport: 'unknown'
}
Display info: {
accelerometerSupport: 'unknown',
bounds: { x: -1728, y: 38, width: 1728, height: 1079 },
colorDepth: 24,
colorSpace: '{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}',
depthPerComponent: 8,
detected: true,
displayFrequency: 32,
id: 1989602237,
internal: false,
label: '',
maximumCursorSize: { width: 0, height: 0 },
monochrome: false,
nativeOrigin: { x: -1728, y: 38 },
rotation: 0,
scaleFactor: 1,
size: { width: 1728, height: 1079 },
workArea: { x: -1728, y: 38, width: 1728, height: 1031 },
workAreaSize: { width: 1728, height: 1031 },
touchSupport: 'unknown'
}

Window bounds on maximize:  { x: -1736, y: 30, width: 1744, height: 1047 }

==== RDP EXIT ====

==== PRIMARY DISPLAY FROM LOCAL MACHINE GETS REMOVED ====
display-removed at Thu May 08 2025 15:15:35 GMT-0400 (Eastern Daylight Time): {
accelerometerSupport: 'unknown',
bounds: { x: 0, y: 0, width: 2560, height: 1080 },
colorDepth: 24,
colorSpace: '{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}',
depthPerComponent: 8,
detected: true,
displayFrequency: 32,
id: 1569316729,
internal: false,
label: '',
maximumCursorSize: { width: 0, height: 0 },
monochrome: false,
nativeOrigin: { x: 0, y: 0 },
rotation: 0,
scaleFactor: 1,
size: { width: 2560, height: 1080 },
workArea: { x: 0, y: 0, width: 2560, height: 1032 },
workAreaSize: { width: 2560, height: 1032 },
touchSupport: 'unknown'
}
After display-removed window bounds is:  { x: -1736, y: 30, width: 1744, height: 1047 }

==== SECONDARY DISPLAY FROM LOCAL MACHINE GETS REMOVED ====
display-removed at Thu May 08 2025 15:15:35 GMT-0400 (Eastern Daylight Time): {
accelerometerSupport: 'unknown',
bounds: { x: -1728, y: 38, width: 1728, height: 1079 },
colorDepth: 24,
colorSpace: '{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}',
depthPerComponent: 8,
detected: true,
displayFrequency: 32,
id: 1989602237,
internal: false,
label: '',
maximumCursorSize: { width: 0, height: 0 },
monochrome: false,
nativeOrigin: { x: -1728, y: 38 },
rotation: 0,
scaleFactor: 1,
size: { width: 1728, height: 1079 },
workArea: { x: -1728, y: 38, width: 1728, height: 1031 },
workAreaSize: { width: 1728, height: 1031 },
touchSupport: 'unknown'
}
After display-removed window bounds is:  { x: -1736, y: 30, width: 1744, height: 1047 }

==== REMOTE DESKTOP ADDS DEFAULT DISPLAY ====
display-added at Thu May 08 2025 15:15:35 GMT-0400 (Eastern Daylight Time): {
accelerometerSupport: 'unknown',
bounds: { x: 0, y: 0, width: 1920, height: 1080 },
colorDepth: 24,
colorSpace: '{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}',
depthPerComponent: 8,
detected: true,
displayFrequency: 60,
id: 4097432655,
internal: false,
label: '',
maximumCursorSize: { width: 0, height: 0 },
monochrome: false,
nativeOrigin: { x: 0, y: 0 },
rotation: 0,
scaleFactor: 1,
size: { width: 1920, height: 1080 },
workArea: { x: 0, y: 0, width: 1920, height: 1032 },
workAreaSize: { width: 1920, height: 1032 },
touchSupport: 'unknown'
}
After display-added window bounds is:  { x: -1736, y: 30, width: 1744, height: 1047 }
Newly added screen is the one that the window should be in

==== WINDOW GETS MOVED TO THE NEW DISPLAY ====
Window bounds on move at Thu May 08 2025 15:15:35 GMT-0400 (Eastern Daylight Time):  { x: -8, y: -8, width: 1936, height: 1048 }

==== RDP RECONNECTS ====

==== DEFAULT DISPLAY FROM REMOTE GETS REMOVED ====
display-removed at Thu May 08 2025 15:17:44 GMT-0400 (Eastern Daylight Time): {
accelerometerSupport: 'unknown',
bounds: { x: 0, y: 0, width: 1920, height: 1080 },
colorDepth: 24,
colorSpace: '{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}',
depthPerComponent: 8,
detected: true,
displayFrequency: 60,
id: 4097432655,
internal: false,
label: '',
maximumCursorSize: { width: 0, height: 0 },
monochrome: false,
nativeOrigin: { x: 0, y: 0 },
rotation: 0,
scaleFactor: 1,
size: { width: 1920, height: 1080 },
workArea: { x: 0, y: 0, width: 1920, height: 1032 },
workAreaSize: { width: 1920, height: 1032 },
touchSupport: 'unknown'
}
After display-removed window bounds is:  { x: -8, y: -8, width: 1936, height: 1048 }

==== PRIMARY DISPLAY FROM LOCAL MACHINE GETS ADDED ====
display-added at Thu May 08 2025 15:17:44 GMT-0400 (Eastern Daylight Time): {
accelerometerSupport: 'unknown',
bounds: { x: 0, y: 0, width: 2560, height: 1080 },
colorDepth: 24,
colorSpace: '{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}',
depthPerComponent: 8,
detected: true,
displayFrequency: 32,
id: 101874985,
internal: false,
label: '',
maximumCursorSize: { width: 0, height: 0 },
monochrome: false,
nativeOrigin: { x: 0, y: 0 },
rotation: 0,
scaleFactor: 1,
size: { width: 2560, height: 1080 },
workArea: { x: 0, y: 0, width: 2560, height: 1032 },
workAreaSize: { width: 2560, height: 1032 },
touchSupport: 'unknown'
}
After display-added window bounds is:  { x: -8, y: -8, width: 1936, height: 1048 }

==== SECONDARY DISPLAY FROM LOCAL MACHINE GETS REMOVED ====
display-added at Thu May 08 2025 15:17:44 GMT-0400 (Eastern Daylight Time): {
accelerometerSupport: 'unknown',
bounds: { x: -1728, y: 38, width: 1728, height: 1079 },
colorDepth: 24,
colorSpace: '{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}',
depthPerComponent: 8,
detected: true,
displayFrequency: 32,
id: 4071963261,
internal: false,
label: '',
maximumCursorSize: { width: 0, height: 0 },
monochrome: false,
nativeOrigin: { x: -1728, y: 38 },
rotation: 0,
scaleFactor: 1,
size: { width: 1728, height: 1079 },
workArea: { x: -1728, y: 38, width: 1728, height: 1031 },
workAreaSize: { width: 1728, height: 1031 },
touchSupport: 'unknown'
}
==== Application window does not get moved to the new display ====
After display-added window bounds is:  { x: -8, y: -8, width: 1936, height: 1048 }
==== Newly added screen does match the bounds of the saved window location so logic could be added to move the window to the new display ====
Newly added screen is the one that the window should be in

Electron exited with code 0.

Workaround

I've added a workaround in the attached fiddle gist that can be enabled by flipping the USE_SAVE_WINDOW_WORKAROUND boolean in the gist. At a high level the workaround is:

  1. Listen for the maximize window event. When that fires, save the current window bounds to a variable for later use.
  2. Listen for the unmaximize and minimize window events. When they fire, clear the saved window bounds variable.
  3. Listen for the display-added event. When it fires, if a saved window bounds exists use screen.getDisplayMatching(rect) to get the display that matches that saved bounds. If the screen returned is the same as the screen passed in to the display-added event then move the application to that screen via win.setBounds(bounds).

Activity

  1. added theissue type on May 8, 2025
  2. added
    has-repro-gist
    on May 8, 2025
  3. moved this to 👀 Unsorted Items in 37-x-yon May 8, 2025
  4. nikwen commented on May 8, 2025

    @nikwen
    Member

    That's a great issue description!

    Do you know if this is a regression or if it has been around for a while?

  5. deepak1556 commented on May 9, 2025

    @deepak1556
    Member

    Since the issue can also be repro in Chrome since we share the same taskbar calculation code path, I have filed an issue at https://issues.chromium.org/issues/416535750

  6. deepak1556 commented on May 9, 2025

    @deepak1556
    Member

    Regards to the workaround, based on some more testing there is a scenario it doesn't capture.

    • Once rdp disconnects, unmaximize the window on the host machine (this is possible since a user can work on the host machine and perform some window operations)
    • Reconnect rdp and the window will not be put back to the correct display

    applications with native titlebar still work fine in this case

  7. jkleinsc commented on May 9, 2025

    @jkleinsc
    MemberAuthor

    @nikwen this is not a regression. I tested on v13.5.0 (which was the earliest version that supports titlebarOverlay and it repros there.

  8. moved this from 👀 Unsorted Items to 👍 Does Not Block Stable in 37-x-yon May 14, 2025
  9. electron-issue-triage commented on Aug 8, 2025

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  10. jkleinsc commented on Aug 8, 2025

    @jkleinsc
    MemberAuthor
  11. electron-issue-triage commented on Nov 8, 2025

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  12. electron-issue-triage commented on Dec 8, 2025

    @electron-issue-triage

    This issue has been closed due to inactivity, and will not be monitored. If this is a bug and you can reproduce this issue on a supported version of Electron please open a new issue and include instructions for reproducing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    37-x-ybug 🪲component/BrowserWindowhas-repro-gistplatform/windowsstale

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions