Skip to content

Fix showing a minimized main window - #11646

Merged
kevinushey merged 1 commit into
mainfrom
bugfix/electron-fix-show-window
Jul 21, 2022
Merged

kevinushey merged 1 commit into
mainfrom
bugfix/electron-fix-show-window

Conversation

@timtmok

@timtmok timtmok commented Jul 20, 2022

Copy link
Copy Markdown
Contributor

Intent

There was an issue showing a minimized window when Jon tested this initially. #11407

Approach

show() will raise and focus the window. The secondary window is then focused to bring it back to the top. I tried showInactive() which seems to imply that it will raise but not focus the window but it always focused the window for me on Mac.

Automated Tests

None

QA Notes

None

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

@timtmok
timtmok requested a review from jgutman July 20, 2022 21:19
@kevinushey
kevinushey merged commit 05d7419 into main Jul 21, 2022
@kevinushey
kevinushey deleted the bugfix/electron-fix-show-window branch July 21, 2022 19:56
kevinushey added a commit that referenced this pull request Aug 26, 2026
The previous revision made the visible case a no-op, which dropped the z-order
raise the callback exists to perform: AppCommand documents the intent as "we
still want the main window to be as visible as possible, so bring it up behind
the current window", and the Qt implementation restacked with SetWindowPos(...,
SWP_NOACTIVATE). A main window buried under a browser or terminal would stay
buried when a background command ran from a satellite.

moveTop() on the main window followed by moveTop() on the active one restores
that raise without touching focus. It is a non-activating restack on every
platform Electron implements it for -- SetWindowPos(HWND_TOP, SWP_NOACTIVATE)
on Windows, _NET_RESTACK_WINDOW on X11, orderWindow:NSWindowAbove on macOS --
and a no-op on Wayland, which matches the Qt version's platform coverage.

showInactive() also does not de-miniaturize a window: on macOS it is
orderFrontRegardless, which Apple documents as pure ordering, "without changing
either the key window or the main window". The minimized case #11646 fixed now
goes through restore() -- [window_ deminiaturize:nil] -- which is what
raiseAndActivateWindow() in utils.ts already does.

Addresses #18635
kevinushey added a commit that referenced this pull request Aug 27, 2026
…te (#18642)

* don't bounce OS focus when surfacing the main window behind a satellite

The bringMainFrameBehindActive desktop callback means "make the main window
visible, but leave focus alone" -- GWT routes every cross-window event whose
focus mode is MODE_AUXILIARY through it, including the SendToConsoleEvent fired
when code is run from a popped-out source window with "focus console after
executing code" turned off.

The Electron implementation got there by focusing the main window and then
handing focus back to the active one. Window managers with focus-stealing
prevention refuse the second half of that bounce, so focus is left on the main
window and the caret lands in the console -- exactly what the preference asks
RStudio not to do. The Qt implementation this replaced used SetWindowPos with
SWP_NOACTIVATE and was a deliberate no-op outside Windows.

A main window that is already on screen now needs nothing done to it at all,
and a hidden or minimized one is surfaced with showInactive() so focus is never
touched. The minimized case that #11646 fixed is preserved.

Addresses #18635

* restack the main window instead of leaving it alone when it is visible

The previous revision made the visible case a no-op, which dropped the z-order
raise the callback exists to perform: AppCommand documents the intent as "we
still want the main window to be as visible as possible, so bring it up behind
the current window", and the Qt implementation restacked with SetWindowPos(...,
SWP_NOACTIVATE). A main window buried under a browser or terminal would stay
buried when a background command ran from a satellite.

moveTop() on the main window followed by moveTop() on the active one restores
that raise without touching focus. It is a non-activating restack on every
platform Electron implements it for -- SetWindowPos(HWND_TOP, SWP_NOACTIVATE)
on Windows, _NET_RESTACK_WINDOW on X11, orderWindow:NSWindowAbove on macOS --
and a no-op on Wayland, which matches the Qt version's platform coverage.

showInactive() also does not de-miniaturize a window: on macOS it is
orderFrontRegardless, which Apple documents as pure ordering, "without changing
either the key window or the main window". The minimized case #11646 fixed now
goes through restore() -- [window_ deminiaturize:nil] -- which is what
raiseAndActivateWindow() in utils.ts already does.

Addresses #18635

* re-add the NEWS entry for #18635

Lost in the merge of main: #18644 rewrote the Autumn Hawkbit entries and
resolving the conflict by taking main's NEWS.md wholesale dropped this
branch's entry instead of re-adding it.

* hand focus back when de-miniaturizing had to activate the main window

restore() is an activating call on every platform where it is the only way
back onto the screen -- ExecuteSystemMenuCommand(SC_RESTORE) on Windows,
deminiaturize: on macOS -- so the minimized branch moved OS focus to the main
window and, unlike the pre-Electron-port code, never handed it back. Combined
with the moveTop pair that follows, the satellite ended up visually on top
while keystrokes went to the console.

Try showInactive() first: on Windows it is SW_SHOWNOACTIVATE, which
de-miniaturizes without activating. It is pure ordering on macOS and a no-op
for an already-mapped window on X11, so restore() is still needed there, and
focus is returned to the active window afterwards. Only the minimized path
does this; the case #18635 is about never reaches it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants