Skip to content

fix(macOS): Use visibleFrame for window centering to exclude menu bar - #4516

Merged
leaanthony merged 6 commits into
wailsapp:v3-alphafrom
youngchoan:fix-window-center-macos
Sep 7, 2025
Merged

leaanthony merged 6 commits into
wailsapp:v3-alphafrom
youngchoan:fix-window-center-macos

Conversation

@youngchoan

@youngchoan youngchoan commented Aug 17, 2025 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the vertical window centering issue on macOS in Wails v3 alpha where windows appear positioned too high on the screen.

Problem

The windowCenter() function in webview_window_darwin.go was using [screen frame] which includes the menu bar and dock areas when calculating the center position. This caused windows to be positioned including the menu bar area, making them appear visually off-center (too high) on the screen.

Solution

Changed line 532 from:

NSRect screenFrame = [screen frame];

To:

NSRect screenFrame = [screen visibleFrame];

The visibleFrame method returns the screen area excluding the menu bar and dock, which results in proper visual centering.

Testing

This fix has been tested locally and resolves the vertical centering issue. Windows now appear properly centered both horizontally and vertically on macOS.

Technical Details

  • File changed: v3/pkg/application/webview_window_darwin.go
  • Lines changed: 1 (line 532)
  • Impact: macOS only - affects the Window.Center() method
  • Backward compatibility: No breaking changes

Fixes vertical centering on macOS for Wails v3 alpha applications.

Summary by CodeRabbit

  • Bug Fixes

    • macOS: New windows now center within the visible display area (respecting the menu bar and Dock) to avoid partial hiding and improve multi-monitor placement.
  • Documentation

    • Updated unreleased changelog with concrete example entries for Added/Changed/Fixed/Security and adjusted top-of-file comment formatting.

The windowCenter() function was using [screen frame] which includes
the menu bar and dock areas, causing windows to appear positioned
too high on the screen when centered.

This change uses [screen visibleFrame] instead, which excludes the
menu bar and dock areas, resulting in proper visual centering.

Fixes vertical centering issue on macOS in Wails v3 alpha.
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 17, 2025
@coderabbitai

coderabbitai Bot commented Aug 17, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

macOS window-centering now uses the screen's visibleFrame (excluding menu bar and dock) when calculating the centered window position; changelog updated with concrete entries. No exported APIs changed.

Changes

Cohort / File(s) Summary
Window Centering on macOS
v3/pkg/application/webview_window_darwin.go
Use screen.visibleFrame (usable area) instead of the full screen frame when computing the window center; offsets and final setFrame call unchanged.
Changelog
v3/UNRELEASED_CHANGELOG.md
Replace placeholder with concrete Added/Changed/Fixed/Security entries; document the visibleFrame change; minor top-of-file comment formatting adjusted.

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant Window
  participant Screen

  App->>Window: windowCenter()
  Window->>Screen: get visibleFrame (usable area)
  Screen-->>Window: visibleFrame
  Window->>Window: compute centered rect using visibleFrame and window size
  Window->>Window: setFrame(centeredRect)
  Window-->>App: done
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • leaanthony

Poem

A hop past the dock, I scout the scene,
I spy the visible patch so clean.
I nudge the window, snug and bright,
Centered just so, a rabbit’s delight.
Thump! — small joys done right 🐇✨


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 57346f7 and c274d67.

📒 Files selected for processing (1)
  • v3/UNRELEASED_CHANGELOG.md (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • v3/UNRELEASED_CHANGELOG.md
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot Bot added the Bug Something isn't working label Aug 17, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
v3/pkg/application/webview_window_darwin.go (2)

320-333: Optional: Consider whether relative positioning should also use visibleFrame

windowSetRelativePosition() still bases coordinates on [screen frame]. If the intended semantics are “relative to the usable area,” you may want to switch to visibleFrame here as well for consistency with centering. If “relative to the physical screen” is desired, keep as-is.


525-539: Sanity‐check window centering and unify frame usage

Please verify that windowCenter behaves correctly across:

  • Dock positions (bottom/left/right) and “Automatically hide and show Dock”
  • Primary vs. secondary monitors
  • Very large windows (larger than the visible work area)

Also, we’ve spotted other manual centering logic still using the full screen frame (which includes the menu bar and dock) rather than the visible frame. Consider updating these to [screen visibleFrame] for consistency:

• v3/pkg/application/webview_window_darwin.go:326–330
• v3/pkg/application/webview_window_darwin.go:568–572

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8115b88 and 28c7a03.

📒 Files selected for processing (1)
  • v3/pkg/application/webview_window_darwin.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
v3/pkg/application/webview_window_darwin.go (1)

532-538: Use visibleFrame for centering — LGTM

This correctly centers the window within the usable display area, excluding the menu bar and dock. Matches macOS conventions and resolves the “window too high” issue without impacting APIs. Safe for the 10.13 min target.

@leaanthony

Copy link
Copy Markdown
Member

Thanks 🙏 Please could you add an entry to the changelog located at v3/UNRELEASED_CHANGELOG.md? Thanks!

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Aug 25, 2025
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Aug 25, 2025
@youngchoan

Copy link
Copy Markdown
Contributor Author

@leaanthony Just pushed the changelog commit! Thanks for reviewing :)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
v3/UNRELEASED_CHANGELOG.md (1)

47-47: Fix markdownlint MD026: remove trailing punctuation from heading.

Minor style polish.

Apply this diff:

-### Example Entries:
+### Example entries
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 28c7a03 and 525d3b4.

📒 Files selected for processing (1)
  • v3/UNRELEASED_CHANGELOG.md (2 hunks)
🧰 Additional context used
🪛 LanguageTool
v3/UNRELEASED_CHANGELOG.md

[grammar] ~22-~22: There might be a mistake here.
Context: ...reen is not fully visible (mostly due to dock or menu bar). ## Changed - Chang...

(QB_NEW_EN)


[grammar] ~26-~26: There might be a mistake here.
Context: ... NSRect screenFrame = [screen frame]; to - Changed the NSRect screenFrame = [screen...

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.17.2)
v3/UNRELEASED_CHANGELOG.md

47-47: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)

🔇 Additional comments (4)
v3/UNRELEASED_CHANGELOG.md (4)

3-16: Header guidance block looks good.

Clear instructions, Keep a Changelog link included. No action needed.


34-35: Deprecated: N/A is appropriate.

No related deprecations for this change.


38-39: Removed: N/A is appropriate.

No removals tied to this fix.


42-43: Security: N/A is appropriate.

No security impact from this change.

Comment thread v3/UNRELEASED_CHANGELOG.md Outdated
Comment on lines +20 to +22
- Updated the configuration for detecting the screenFrame to use the
visibleFrame instead of the frame to handle cases where the screen is not
fully visible (mostly due to dock or menu bar).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Misclassified entry under “Added”; this is a behavioral fix. Move to “Fixed” and tighten wording.

This change corrects window centering on macOS; it’s not a new feature. Also, capitalize “Dock”.

Apply this diff to remove the entry from “Added”:

-- Updated the configuration for detecting the screenFrame to use the
-  visibleFrame instead of the frame to handle cases where the screen is not
-  fully visible (mostly due to dock or menu bar).

Follow up by adding a single, scoped bullet under “Fixed” (see separate comment on Lines 30-31).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Updated the configuration for detecting the screenFrame to use the
visibleFrame instead of the frame to handle cases where the screen is not
fully visible (mostly due to dock or menu bar).
🧰 Tools
🪛 LanguageTool

[grammar] ~22-~22: There might be a mistake here.
Context: ...reen is not fully visible (mostly due to dock or menu bar). ## Changed - Chang...

(QB_NEW_EN)

🤖 Prompt for AI Agents
In v3/UNRELEASED_CHANGELOG.md around lines 20-22, remove the current bullet
under "Added" that describes switching from frame to visibleFrame and then add a
single, scoped bullet under the "Fixed" section (around lines 30-31) that reads
concisely: "Fix window centering on macOS when parts of the screen are obscured
by the Dock or menu bar by using visibleFrame for screen detection." Ensure
"Dock" is capitalized and the wording frames this as a behavioral fix, not a new
feature.

Comment thread v3/UNRELEASED_CHANGELOG.md Outdated
Comment on lines +26 to +27
- Changed the NSRect screenFrame = [screen frame]; to
- Changed the NSRect screenFrame = [screen visibleFrame];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consolidate and de-duplicate the “Changed” bullets or remove them.

These two bullets read as an unfinished sentence split across two lines and duplicate the behavioral note that belongs under “Fixed”. Prefer a single “Fixed” entry; remove these.

Apply this diff to delete both lines:

-- Changed the NSRect screenFrame = [screen frame]; to
-- Changed the NSRect screenFrame = [screen visibleFrame];

If you do want a “Changed” entry instead, replace both with one clear line (but avoid duplicating the “Fixed” section):

+- macOS: Use `[screen visibleFrame]` instead of `[screen frame]` when centering windows. (#4516)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Changed the NSRect screenFrame = [screen frame]; to
- Changed the NSRect screenFrame = [screen visibleFrame];
🧰 Tools
🪛 LanguageTool

[grammar] ~26-~26: There might be a mistake here.
Context: ... NSRect screenFrame = [screen frame]; to - Changed the NSRect screenFrame = [screen...

(QB_NEW_EN)

🤖 Prompt for AI Agents
In v3/UNRELEASED_CHANGELOG.md around lines 26-27, two "Changed" bullets
duplicate an unfinished sentence about NSRect screenFrame and should be removed
or consolidated; delete both lines as requested (removing the duplicate
"Changed" bullets entirely) or alternatively replace them with a single, clear
entry under the "Fixed" section that succinctly states the behavioral change
(e.g., switched from using [screen frame] to [screen visibleFrame]) without
duplicating existing notes.

Comment thread v3/UNRELEASED_CHANGELOG.md Outdated
Comment on lines +30 to +31

N/A

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add the macOS window-centering fix here; replace “N/A”.

Place the user-impactful note under “Fixed” with scope, file, and PR reference.

Apply this diff:

- N/A
+ - macOS: Center windows using `[screen visibleFrame]` instead of `[screen frame]` to exclude the menu bar and Dock in `Window.Center()` (v3/pkg/application/webview_window_darwin.go, #4516).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
N/A
- macOS: Center windows using `[screen visibleFrame]` instead of `[screen frame]` to exclude the menu bar and Dock in `Window.Center()` (v3/pkg/application/webview_window_darwin.go, #4516).
🤖 Prompt for AI Agents
In v3/UNRELEASED_CHANGELOG.md around lines 30–31, replace the current "N/A"
entry with a user-facing "Fixed" bullet that documents the macOS
window-centering fix: add scope (e.g., "Desktop / macOS"), the affected
file/path, and the PR number in parentheses (e.g., "Fixed macOS window-centering
issue when opening new windows — Desktop / macOS: src/ui/window.ts (PR #1234)").
Ensure the entry is placed under the "Fixed" section and follows existing
changelog formatting and punctuation conventions.

@atterpac
atterpac enabled auto-merge August 28, 2025 16:52
@atterpac atterpac self-assigned this Aug 28, 2025

@leaanthony leaanthony left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. Could you please leave the comments in the template and move your changeling entry to "Changed"? Thank you!

auto-merge was automatically disabled August 29, 2025 21:44

Head branch was pushed to by a user without write access

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Aug 29, 2025
@youngchoan
youngchoan requested a review from leaanthony August 29, 2025 21:45
@youngchoan

Copy link
Copy Markdown
Contributor Author

Thanks. Could you please leave the comments in the template and move your changeling entry to "Changed"? Thank you!

done! (I think) 🙏

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Sep 7, 2025
@leaanthony
leaanthony enabled auto-merge (squash) September 7, 2025 09:27
@sonarqubecloud

sonarqubecloud Bot commented Sep 7, 2025

Copy link
Copy Markdown

@leaanthony
leaanthony merged commit 9d51280 into wailsapp:v3-alpha Sep 7, 2025
49 of 50 checks passed
Grantmartin2002 pushed a commit to Grantmartin2002/wails that referenced this pull request Apr 29, 2026
…wailsapp#4516)

* fix(macOS): Use visibleFrame for window centering to exclude menu bar

The windowCenter() function was using [screen frame] which includes
the menu bar and dock areas, causing windows to appear positioned
too high on the screen when centered.

This change uses [screen visibleFrame] instead, which excludes the
menu bar and dock areas, resulting in proper visual centering.

Fixes vertical centering issue on macOS in Wails v3 alpha.

* Update v3/UNRELEASED_CHANGELOG.md

* Update changelog entry format

---------

Co-authored-by: Atterpac <89053530+atterpac@users.noreply.github.com>
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
@taliesin-ai taliesin-ai added v3 and removed v3-alpha labels Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Documentation Improvements or additions to documentation lgtm This PR has been approved by a maintainer MacOS size:XS This PR changes 0-9 lines, ignoring generated files. v3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants