Skip to content

Window: set a window level above the menu bar / Dock / taskbar #81

Done

Description

@lijy91

Problem

A full-display overlay (region screenshot, color picker, presentation HUD) has to cover the menu bar and the Dock on macOS, and the taskbar on Windows. Window can't do that today:

  • SetAlwaysOnTop(true) maps to NSFloatingWindowLevel on macOS, which is below the menu bar and the Dock. Nothing in the public API raises a window higher.
  • SetBounds() with a rectangle covering the whole display (including the menu-bar strip) is not honoured for this kind of window: AppKit's -[NSWindow constrainFrameRect:toScreen:] moves the frame below the menu bar.

The Flutter screen-capture example (examples/flutter_screen_capture_example, PR #75) works around both in MainFlutterWindow.swift: it sets NSWindow.level to CGWindowLevelForKey(kCGScreenSaverWindowLevelKey) and overrides constrainFrameRect(_:to:) to return the requested frame unchanged.

Proposal

A window level setting. The names follow Electron's BrowserWindow.setAlwaysOnTop(flag, level) (see specs/api-style.md §1.7). It is a separate setter rather than an overload (§1.6):

enum class WindowLevel {
  /** Normal stacking. */
  Normal,
  /** Above normal windows; same as SetAlwaysOnTop(true). */
  Floating,
  /** Above the menu bar / taskbar, e.g. status overlays. */
  Status,
  /** Above everything the user normally sees, including the Dock. */
  ScreenSaver,
};

bool Window::SetLevel(WindowLevel level);
WindowLevel Window::GetLevel() const;

Open questions for the design pass:

  • How SetLevel interacts with SetAlwaysOnTop / SetAlwaysOnBottom and with the fullscreen coordinator, which already saves and restores NSFloatingWindowLevel.
  • Whether SetBounds() should skip AppKit's frame constraint when the level is Status or higher, so a whole-display rectangle is honoured.

Per-platform mapping:

  • macOS: NSWindow.level (NSStatusWindowLevel, kCGScreenSaverWindowLevel), plus the frame constraint change above.
  • Windows: HWND_TOPMOST; a borderless topmost window covering the monitor already sits over the taskbar.
  • Linux: _NET_WM_STATE_ABOVE on X11; on Wayland this is compositor-dependent (⚠️).
  • Mobile / OpenHarmony / WASM: return false.

Acceptance

With only Dart calls (setLevel(WindowLevel.screenSaver), bounds = <display bounds>), a window covers the whole display, menu bar and Dock included, on macOS, with no edits to the app's MainFlutterWindow.swift.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions