All Projects → leanflutter → window_manager

leanflutter / window_manager

Licence: MIT License
This plugin allows Flutter desktop apps to resizing and repositioning the window.

Programming Languages

C++
36643 projects - #6 most used programming language
dart
5743 projects
swift
15916 projects
CMake
9771 projects
c
50402 projects - #5 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to window manager

find aik
Find Aik game for #FlutterCreate
Stars: ✭ 18 (-83.93%)
Mutual labels:  flutter-desktop, flutter-web
flutter getx the moviedb
The Movie DB App with Flutter GetX State Management
Stars: ✭ 79 (-29.46%)
Mutual labels:  flutter-desktop, flutter-web
portfolio
The portfolio site for JFK.DEV, built with Flutter.
Stars: ✭ 56 (-50%)
Mutual labels:  flutter-web
editable
This library allows you to create editable tables and spreadsheets with ease, either by providing initial row and column count to display an empty table or use it with predefined rows and column data sets.
Stars: ✭ 85 (-24.11%)
Mutual labels:  flutter-desktop
DroidKaigi2019Presentation
The Flutter presentation that I made at the DroidKaigi conference
Stars: ✭ 23 (-79.46%)
Mutual labels:  flutter-desktop
hyperkeys
Unleash you keyboard shorcuts
Stars: ✭ 35 (-68.75%)
Mutual labels:  window-manager
conductor
A lightweight OS X window manager for hackers
Stars: ✭ 24 (-78.57%)
Mutual labels:  window-manager
fusuma-plugin-wmctrl
Window Manager plugin for Fusuma
Stars: ✭ 36 (-67.86%)
Mutual labels:  window-manager
invmovieconcept1
True Cross platform UI design featuring complex scroll based animations powered by flutter
Stars: ✭ 55 (-50.89%)
Mutual labels:  flutter-desktop
glfwm
GLFW Manager - C++ wrapper with multi-threading
Stars: ✭ 60 (-46.43%)
Mutual labels:  window-manager
addIt
Simple addition game made with Flutter for Mobile and Web using BLOC pattern
Stars: ✭ 16 (-85.71%)
Mutual labels:  flutter-web
axyl-iso
Axyl is a Linux distro centered on tiling window managers. Choose from i3, bspwm, dwm and more.
Stars: ✭ 348 (+210.71%)
Mutual labels:  window-manager
maxwelm
Maxwelm is a simple window manager for small displays
Stars: ✭ 20 (-82.14%)
Mutual labels:  window-manager
eseed-window
A minimal cross-platform C++17 window management library for rendering (deprecated)
Stars: ✭ 18 (-83.93%)
Mutual labels:  window-manager
x11-cr
X11 bindings for Crystal language.
Stars: ✭ 32 (-71.43%)
Mutual labels:  window-manager
DeveloperFolio
Flutter web - DeveloperFolio template
Stars: ✭ 143 (+27.68%)
Mutual labels:  flutter-web
InVision loginPage
Login page made with Flutter Web
Stars: ✭ 35 (-68.75%)
Mutual labels:  flutter-web
getwidget-web-kit
Get Widget Web app Demo
Stars: ✭ 40 (-64.29%)
Mutual labels:  flutter-web
gobble
Rust rewrite of Devour
Stars: ✭ 23 (-79.46%)
Mutual labels:  window-manager
ModMove
Move/Resize windows using modifiers and the mouse
Stars: ✭ 86 (-23.21%)
Mutual labels:  window-manager

window_manager

pub version

This plugin allows Flutter desktop apps to resizing and repositioning the window.


English | 简体中文


Platform Support

Linux macOS Windows
✔️ ✔️ ✔️

Quick Start

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  window_manager: ^0.1.7

Or

dependencies:
  window_manager:
    git:
      url: https://github.com/leanflutter/window_manager.git
      ref: main

Usage

import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Must add this line.
  await windowManager.ensureInitialized();

  // Use it only after calling `hiddenWindowAtLaunch`
  windowManager.waitUntilReadyToShow().then((_) async{
    // Hide window title bar
    await windowManager.setTitleBarStyle('hidden');
    await windowManager.setSize(Size(800, 600));
    await windowManager.center();
    await windowManager.show();
    await windowManager.setSkipTaskbar(false);
  });

  runApp(MyApp());
}

Please see the example app of this plugin for a full example.

Listening events

import 'package:flutter/cupertino.dart';
import 'package:window_manager/window_manager.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with WindowListener {
  @override
  void initState() {
    windowManager.addListener(this);
    super.initState();
  }

  @override
  void dispose() {
    windowManager.removeListener(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // ...
  }

  @override
  void onWindowEvent(String eventName) {
    print('[WindowManager] onWindowEvent: $eventName');
  }

  @override
  void onWindowClose() {
    // do something
  }

  @override
  void onWindowFocus() {
    // do something
  }

  @override
  void onWindowBlur() {
    // do something
  }

  @override
  void onWindowMaximize() {
    // do something
  }

  @override
  void onWindowUnmaximize() {
    // do something
  }

  @override
  void onWindowMinimize() {
    // do something
  }

  @override
  void onWindowRestore() {
    // do something
  }

  @override
  void onWindowResize() {
    // do something
  }

  @override
  void onWindowMove() {
    // do something
  }

  @override
  void onWindowEnterFullScreen() {
    // do something
  }

  @override
  void onWindowLeaveFullScreen() {
    // do something
  }
}

Quit on close

If you need to use the hide method, you need to disable QuitOnClose.

macOS

Change the file macos/Runner/AppDelegate.swift as follows:

import Cocoa
import FlutterMacOS

@NSApplicationMain
class AppDelegate: FlutterAppDelegate {
  override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
-    return true
+    return false
  }
}
Windows

Change the file windows/runner/main.cpp as follows:

int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
                      _In_ wchar_t *command_line, _In_ int show_command) {
  // ...

-  window.SetQuitOnClose(true);
+  window.SetQuitOnClose(false);

  // ...

  return EXIT_SUCCESS;
}

Confirm before closing

import 'package:flutter/cupertino.dart';
import 'package:window_manager/window_manager.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with WindowListener {
  @override
  void initState() {
    windowManager.addListener(this);
    super.initState();
  }

  void _init() async {
    // Add this line to override the default close handler
    await windowManager.setPreventClose(true);
    setState(() {});
  }

  @override
  void dispose() {
    windowManager.removeListener(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // ...
  }

  @override
  void onWindowClose() async {
    bool _isPreventClose = await windowManager.isPreventClose();
    if (_isPreventClose) {
      showDialog(
        context: context,
        builder: (_) {
          return AlertDialog(
            title: Text('Are you sure you want to close this window?'),
            actions: [
              TextButton(
                child: Text('No'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
              TextButton(
                child: Text('Yes'),
                onPressed: () {
                  Navigator.of(context).pop();
                  exit(0);
                },
              ),
            ],
          );
        },
      );
    }
  }
}

Hidden at launch

macOS

Change the file macos/Runner/MainFlutterWindow.swift as follows:

import Cocoa
import FlutterMacOS
+import window_manager

class MainFlutterWindow: NSWindow {
    override func awakeFromNib() {
        let flutterViewController = FlutterViewController.init()
        let windowFrame = self.frame
        self.contentViewController = flutterViewController
        self.setFrame(windowFrame, display: true)

        RegisterGeneratedPlugins(registry: flutterViewController)

        super.awakeFromNib()
    }

+    override public func order(_ place: NSWindow.OrderingMode, relativeTo otherWin: Int) {
+        super.order(place, relativeTo: otherWin)
+        hiddenWindowAtLaunch()
+    }
}
Windows

Change the file windows/runner/win32_window.cpp as follows:

bool Win32Window::CreateAndShow(const std::wstring& title,
                                const Point& origin,
                                const Size& size) {
  ...                              
  HWND window = CreateWindow(
-      window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+      window_class, title.c_str(),
+      WS_OVERLAPPEDWINDOW, // do not add WS_VISIBLE since the window will be shown later
      Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
      Scale(size.width, scale_factor), Scale(size.height, scale_factor),
      nullptr, nullptr, GetModuleHandle(nullptr), this);

Make sure to call setState once on the onWindowFocus event.

import 'package:flutter/cupertino.dart';
import 'package:window_manager/window_manager.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with WindowListener {
  @override
  void initState() {
    windowManager.addListener(this);
    super.initState();
  }

  @override
  void dispose() {
    windowManager.removeListener(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // ...
  }

  @override
  void onWindowFocus() {
    // Make sure to call once.
    setState(() {});
    // do something
  }
}

Who's using it?

  • AuthPass - Password Manager based on Flutter for all platforms. Keepass 2.x (kdbx 3.x) compatible.
  • Biyi (比译) - A convenient translation and dictionary app written in dart / Flutter.
  • BlueBubbles - BlueBubbles is an ecosystem of apps bringing iMessage to Android, Windows, and Linux
  • Yukino - Yukino lets you read manga or stream anime ad-free from multiple sources.
  • LunaSea - A self-hosted controller for mobile and macOS built using the Flutter framework.

API

WindowManager

Methods

close

Try to close the window.

isPreventClose

Check if is intercepting the native close signal.

setPreventClose

Set if intercept the native close signal. May useful when combine with the onclose event listener. This will also prevent the manually triggered close event.

focus

Focuses on the window.

blur macos windows

Removes focus from the window.

isFocused macos windows

Returns bool - Whether window is focused.

show

Shows and gives focus to the window.

hide

Hides the window.

isVisible

Returns bool - Whether the window is visible to the user.

isMaximized

Returns bool - Whether the window is maximized.

maximize

Maximizes the window.

unmaximize

Unmaximizes the window.

isMinimized

Returns bool - Whether the window is minimized.

minimize

Minimizes the window. On some platforms the minimized window will be shown in the Dock.

restore

Restores the window from minimized state to its previous state.

isFullScreen

Returns bool - Whether the window is in fullscreen mode.

setFullScreen

Sets whether the window should be in fullscreen mode.

setAspectRatio

This will make a window maintain an aspect ratio.

setBackgroundColor

Sets the background color of the window.

getBounds

Returns Rect - The bounds of the window as Object.

setBounds

Resizes and moves the window to the supplied bounds.

getPosition

Returns Offset - Contains the window's current position.

setAlignment

Move the window to a position aligned with the screen.

center

Moves window to the center of the screen.

setPosition

Moves window to position.

getSize

Returns Size - Contains the window's width and height.

setSize

Resizes the window to width and height.

setMinimumSize

Sets the minimum size of window to width and height.

setMaximumSize

Sets the maximum size of window to width and height.

isResizable

Returns bool - Whether the window can be manually resized by the user.

setResizable

Sets whether the window can be manually resized by the user.

isMovable macos

Returns bool - Whether the window can be moved by user.

setMovable macos

Sets whether the window can be moved by user.

isMinimizable macos windows

Returns bool - Whether the window can be manually minimized by the user.

setMinimizable macos windows

Sets whether the window can be manually minimized by user.

isClosable macos windows

Returns bool - Whether the window can be manually closed by user.

setClosable macos windows

Sets whether the window can be manually closed by user.

isAlwaysOnTop

Returns bool - Whether the window is always on top of other windows.

setAlwaysOnTop

Sets whether the window should show always on top of other windows.

getTitle

Returns String - The title of the native window.

setTitle

Changes the title of native window to title.

setTitleBarStyle macos windows

Changes the title bar style of native window.

getTitleBarHeight macos windows

Returns int - The title bar height of the native window.

setSkipTaskbar

Makes the window not show in the taskbar / dock.

setProgressBar macos

Sets progress value in progress bar. Valid range is [0, 1.0].

hasShadow macos

Returns bool - Whether the window has a shadow.

setHasShadow macos

Sets whether the window should have a shadow.

getOpacity macos windows

Returns double - between 0.0 (fully transparent) and 1.0 (fully opaque). On Linux, always returns 1.

setOpacity macos windows

Sets the opacity of the window.

startDragging

Starts a window drag based on the specified mouse-down event.

WindowListener

Methods

onWindowClose

Emitted when the window is going to be closed.

onWindowFocus

Emitted when the window gains focus.

onWindowBlur

Emitted when the window loses focus.

onWindowMaximize

Emitted when window is maximized.

onWindowUnmaximize

Emitted when the window exits from a maximized state.

onWindowMinimize

Emitted when the window is minimized.

onWindowRestore

Emitted when the window is restored from a minimized state.

onWindowResize

Emitted after the window has been resized.

onWindowMove

Emitted when the window is being moved to a new position.

onWindowEnterFullScreen

Emitted when the window enters a full-screen state.

onWindowLeaveFullScreen

Emitted when the window leaves a full-screen state.

onWindowEvent

Emitted all events.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].