Repository navigation
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
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
Additional Information
Steps to reproduce:
- 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"
- Run 2(or more if you have more monitors) instances of VS Code.
- Create/open a text file in each instance
- Drag an instance into each window and maximize each instance to display in a different monitor.
- Edit the text files so that they are labeled to id each of the monitors to which they are maximized in.
- Terminate the RDP session
- Remote back in ensuring "Use all my monitors for the remote session" is checked.
- 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:
- Listen for the maximize window event. When that fires, save the current window bounds to a variable for later use.
- Listen for the unmaximize and minimize window events. When they fire, clear the saved window bounds variable.
- 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-addedevent then move the application to that screen via win.setBounds(bounds).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields👍 Does Not Block Stable
Activity
nikwen commentedon May 8, 2025
That's a great issue description!
Do you know if this is a regression or if it has been around for a while?
deepak1556 commentedon May 9, 2025
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
deepak1556 commentedon May 9, 2025
Regards to the workaround, based on some more testing there is a scenario it doesn't capture.
applications with native titlebar still work fine in this case
jkleinsc commentedon May 9, 2025
@nikwen this is not a regression. I tested on v13.5.0 (which was the earliest version that supports
titlebarOverlayand it repros there.electron-issue-triage commentedon Aug 8, 2025
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!
jkleinsc commentedon Aug 8, 2025
Issue still exists in electron v38.0.0-beta.2 and electron v39.0.0-nightly.20250807
electron-issue-triage commentedon Nov 8, 2025
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!
electron-issue-triage commentedon Dec 8, 2025
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.