flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

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

Open krjw-eyev opened this issue 8 months ago • 0 comments

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 avatar Mar 28 '25 23:03 krjw-eyev