Skip to content

fix(v2): Prevent Esc from exiting fullscreen on macOS#5242

Closed
leaanthony wants to merge 4 commits into
masterfrom
fix/4649-esc-exits-fullscreen-macos
Closed

fix(v2): Prevent Esc from exiting fullscreen on macOS#5242
leaanthony wants to merge 4 commits into
masterfrom
fix/4649-esc-exits-fullscreen-macos

Conversation

@leaanthony

Copy link
Copy Markdown
Member

Summary

Fixes #4649

On macOS, pressing the Escape key while a Wails app is in fullscreen mode would exit fullscreen, preventing web content (e.g., modals, dialogs) from handling the Esc key.

Fix

Override cancelOperation: in WailsWindow (NSWindow subclass) to check if the window is currently in fullscreen mode:

  • In fullscreen: The cancelOperation: message is swallowed, allowing the Esc keypress to reach the web content via WKWebView's normal key event handling.
  • Not in fullscreen: The default cancelOperation: behavior is preserved.

This is the standard macOS pattern for customizing Esc behavior in fullscreen apps.

Files Changed

  • v2/internal/frontend/desktop/darwin/WailsContext.m - Added cancelOperation: override to WailsWindow
  • v2/test/4649/test_esc_fullscreen.go - Manual test documentation

Test Plan

This is a macOS-only fix and needs manual testing on macOS:

  1. Create a Wails v2 app with fullscreen mode
  2. Add an HTML modal dialog
  3. Press Esc - the modal should close but the window should remain in fullscreen
  4. Use WindowUnfullscreen() or Cmd+Ctrl+F to exit fullscreen

💡 This PR was created by the Wails Engineer agent.

Override cancelOperation: in WailsWindow to check if the window is in
fullscreen mode. When fullscreen, the Esc key press is swallowed so web
content can handle it (e.g., closing modals). When not fullscreen, the
default behavior is preserved.

Note: This is a macOS-only fix. Needs manual testing on macOS to verify.
@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2e0357a0-964e-446d-bcfd-4d715131852e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4649-esc-exits-fullscreen-macos

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@leaanthony

Copy link
Copy Markdown
Member Author

🤖 PR Triage Review

Accepted

This PR prevents Esc key from exiting fullscreen on macOS (v2). Important UX fix to match platform conventions.

Platform: macOS (v2-only)

Next Steps: Dispatching for Mac testing.


Reviewed by Wails PR Reviewer Bot

leaanthony added 3 commits May 2, 2026 15:05
…Fullscreen

Adds an opt-in mac.Options.DisableEscapeExitsFullscreen field. When true,
WailsWindow.cancelOperation: swallows the Esc keypress in fullscreen so
web content (modals, custom handlers) can consume it. When false (default),
the standard macOS behaviour is preserved — Esc exits fullscreen.

Threads the bool through Create()/CreateWindow() so the property is set on
the WailsWindow at creation. Existing apps see no behaviour change.

Closes #4649
@leaanthony

Copy link
Copy Markdown
Member Author

This PR has been superseded by #5310, which refactors the cancelOperation: override to be opt-in via mac.Options.DisableEscapeExitsFullscreen rather than applying unconditionally to all Wails v2 apps. Default behaviour (Escape exits fullscreen) is preserved for existing apps.

@leaanthony leaanthony closed this May 3, 2026
leaanthony added a commit that referenced this pull request May 3, 2026
…Esc (#5307)

Add DisableEscapeExitsFullscreen bool to MacWindow options so apps can
opt in to preventing the Escape key from exiting fullscreen mode, allowing
web content (e.g. modals with Esc-to-close behaviour) to handle Esc
without triggering the macOS system behaviour that exits the fullscreen
window.

The flag is stored as a BOOL property on WebviewWindow (the custom
NSWindow subclass) and checked in a cancelOperation: override: when the
window is fullscreen and the flag is true, the Esc keypress is swallowed;
otherwise the default macOS behaviour is preserved via [super
cancelOperation:sender].

Default false, so all existing apps are unaffected.

Ports v2 PR #5242 to v3.

Co-authored-by: wails-fleet-bot <noreply@wails-fleet.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When fullscreen on MacOS, press Esc causing app out of fullscreen.

1 participant