Skip to content

fix: Windows: Calling window.setFocusable(true) will no longer cause a window to lose focus#45640

Merged
jkleinsc merged 1 commit intoelectron:mainfrom
vulture:vulture/fix-setfocusable
Nov 12, 2025
Merged

fix: Windows: Calling window.setFocusable(true) will no longer cause a window to lose focus#45640
jkleinsc merged 1 commit intoelectron:mainfrom
vulture:vulture/fix-setfocusable

Conversation

@vulture
Copy link
Copy Markdown
Contributor

@vulture vulture commented Feb 15, 2025

Description of Change

On Windows, calling NativeWindowViews::SetFocusable(bool focusable) currently always calls Focus(false) at the end of the function regardless of if we're setting focusable to true or false. While it does make sense to lose focus when calling SetFocusable(false), it doesn't make sense to drop focus when calling SetFocusable(true). Setting to true should also not forcibly focus. So I propose to drop focus only when !focusable, and do not call Focus() at all when focusable.

Release Notes

Notes: Windows: Calling window.setFocusable(true) will no longer cause a window to lose focus

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Feb 15, 2025
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Feb 22, 2025
@codebytere codebytere self-requested a review February 24, 2025 17:43
Copy link
Copy Markdown
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me.

CC @codebytere for a second opinion since she self-requested a review on this PR

…not deactivate a window when setting focusable to true.
@jkleinsc jkleinsc force-pushed the vulture/fix-setfocusable branch from 21ae330 to e39b648 Compare November 11, 2025 21:04
@jkleinsc jkleinsc changed the title Windows: Make setFocusable only deactivate a window if focusable is false. Do not deactivate a window when setting focusable to true. fix: Windows: Calling window.setFocusable(true) will no longer cause a window to lose focus Nov 11, 2025
@codebytere codebytere added semver/patch backwards-compatible bug fixes target/39-x-y PR should also be added to the "39-x-y" branch. target/40-x-y PR should also be added to the "40-x-y" branch. labels Nov 12, 2025
@jkleinsc jkleinsc merged commit 92a910d into electron:main Nov 12, 2025
63 of 64 checks passed
@release-clerk
Copy link
Copy Markdown

release-clerk bot commented Nov 12, 2025

Release Notes Persisted

Windows: Calling window.setFocusable(true) will no longer cause a window to lose focus

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Nov 12, 2025

I have automatically backported this PR to "40-x-y", please check out #48927

@trop trop bot added in-flight/40-x-y and removed target/40-x-y PR should also be added to the "40-x-y" branch. labels Nov 12, 2025
@trop
Copy link
Copy Markdown
Contributor

trop bot commented Nov 12, 2025

I have automatically backported this PR to "39-x-y", please check out #48928

@trop trop bot added in-flight/39-x-y merged/39-x-y PR was merged to the "39-x-y" branch. merged/40-x-y PR was merged to the "40-x-y" branch. and removed target/39-x-y PR should also be added to the "39-x-y" branch. in-flight/39-x-y in-flight/40-x-y labels Nov 12, 2025
nilayarya pushed a commit to nilayarya/electron that referenced this pull request Nov 21, 2025
…a window to lose focus (electron#45640)

Make setFocusable only deactivate a window if focusable is false. Do not deactivate a window when setting focusable to true.
nilayarya added a commit to nilayarya/electron that referenced this pull request Nov 21, 2025
…a window to lose focus (electron#45640)

Make setFocusable only deactivate a window if focusable is false. Do not deactivate a window when setting focusable to true.
nilayarya added a commit to nilayarya/electron that referenced this pull request Nov 21, 2025
…a window to lose focus (electron#45640)

Make setFocusable only deactivate a window if focusable is false. Do not deactivate a window when setting focusable to true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/39-x-y PR was merged to the "39-x-y" branch. merged/40-x-y PR was merged to the "40-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants