Skip to content

WIP [desktop_multi_window | macOS and Windows]: window creation options, window events, window options #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

krjw-eyev
Copy link

@krjw-eyev krjw-eyev commented Mar 28, 2025

This is a work in progress currently for macOS and Windows.

window creation options

  final options = WindowOptions(
    macos: MacOSWindowOptions.nswindow(
      title: 'Sub Window',
      backgroundColor: Colors.transparent,
      level: MacOsWindowLevel.floating,
      isOpaque: false,
      hasShadow: false,
    ),
    windows: const WindowsWindowOptions(
      style: WindowsWindowStyle.WS_OVERLAPPEDWINDOW,
      exStyle: WindowsExtendedWindowStyle.WS_EX_APPWINDOW,
      width: 1280,
      height: 720,
      backgroundColor: Colors.transparent,
    ),
  );

Window functions adapted from window_manager

  Future<void> close();
  Future<void> show();
  Future<void> hide();
  Future<Rect> getFrame();
  Future<void> setFrame(Rect frame, {bool animate = false, double devicePixelRatio = 1.0});
  Future<Size> getSize();
  Future<void> setSize(Size size, {bool animate = false, double devicePixelRatio = 1.0});
  Future<Offset> getPosition();
  Future<void> setPosition(Offset position, {bool animate = false, double devicePixelRatio = 1.0});
  Future<void> center();
  Future<void> setTitle(String title);
  Future<bool> isFocused();
  Future<bool> isVisible();
  Future<bool> isMaximized();
  Future<void> maximize({bool vertically = false});
  Future<void> unmaximize();
  Future<bool> isMinimized();
  Future<void> minimize();
  Future<void> restore();
  Future<bool> isFullScreen();
  Future<void> setFullScreen(bool isFullScreen);

  Future<void> setStyle({
    int? styleMask,
    int? collectionBehavior,
    MacOsWindowLevel? level,
    bool? isOpaque,
    bool? hasShadow,
    Color? backgroundColor,
    int? style,
    int? extendedStyle,
  });

  Future<void> setBackgroundColor(Color backgroundColor);
  Future<void> resizable(bool resizable);
  Future<void> setFrameAutosaveName(String name);
  Future<void> setIgnoreMouseEvents(bool ignore);

Window events

// Just add `with WindowEvents` to your `StatefulWidget`
// and `controller.addListener(this);` in the `initState()` function
// and `controller.removeListener(this);` in the `dispose()` function
// `controller` is a `WindowController`.
// You can override these functions and you will receive the events for that window. 
abstract mixin class WindowEvents {
  void onWindowClose() {}
  void onWindowShow() {}
  void onWindowHide() {}
  void onWindowFocus() {}
  void onWindowBlur() {}
  void onWindowMaximize() {}
  void onWindowUnmaximize() {}
  void onWindowMinimize() {}
  void onWindowRestore() {}
  void onWindowResize() {}
  void onWindowResized() {}
  void onWindowMove() {}
  void onWindowMoved() {}
  void onWindowEnterFullScreen() {}
  void onWindowLeaveFullScreen() {}
  void onWindowDocked() {}
  void onWindowUndocked() {}
  void onMouseMove(int x, int y) {}
  void onWindowEvent(String eventName, Map<String, dynamic>? eventData) {}
}

This does not work on linux yet

This still has some minor issues regarding the functions and styles for both macOS and windows.

I wanted to share this so someone might want to add more, test more and help finish this.

@krjw-eyev krjw-eyev changed the title added window creation options for macOS and Window WIP: Window creation options, window events, window options Mar 28, 2025
@krjw-eyev krjw-eyev changed the title WIP: Window creation options, window events, window options WIP [desktop_multi_window | macOS and Windows]: window creation options, window events, window options Mar 28, 2025
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.

1 participant