Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 1.0.1

- Add `setLevel` method.
- Add the following `order*` methods:
- `orderOut`
- `orderBack`
- `orderFront`
- `orderFrontRegardless`
- Add methods to modify the window's `styleMask` property.
- Improve documentation.

## 1.0.0+1

- Improve “Getting started” section in the project's readme.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ and the Flutter guide for
+ A method that makes the window fully transparent (with no blur effect).
+ Methods to enable/disable the window's shadow.
+ Methods and widgets to add, remove, and modify visual effect subviews.
+ Methods to set the window's level as well as reorder the window within its level.
+ Methods to modify the window's style mask.

Additionally, the package ships with an example project that showcases the plugin's features via an intuitive searchable user interface:

Expand Down
19 changes: 19 additions & 0 deletions example/lib/main_area/command_list_provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:macos_window_utils/macos/ns_window_level.dart';
import 'package:macos_window_utils/macos/ns_window_style_mask.dart';
import 'package:macos_window_utils/macos/ns_window_toolbar_style.dart';
import 'package:macos_window_utils/macos/ns_visual_effect_view_material.dart';
import 'package:macos_window_utils/macos/ns_visual_effect_view_state.dart';
Expand Down Expand Up @@ -376,6 +377,24 @@ class CommandListProvider {
'or the main window.',
function: () => WindowManipulator.orderFrontRegardless(),
),
Command(
name: 'removeFromStyleMask(NSWindowStyleMask.titled); '
'insertIntoStyleMask(NSWindowStyleMask.borderless)',
description: 'Makes the window non-titled and borderless.',
function: () {
WindowManipulator.removeFromStyleMask(NSWindowStyleMask.titled);
WindowManipulator.insertIntoStyleMask(NSWindowStyleMask.borderless);
},
),
Command(
name: 'insertIntoStyleMask(NSWindowStyleMask.titled); '
'removeFromStyleMask(NSWindowStyleMask.borderless)',
description: 'Makes the window titled and non-borderless.',
function: () {
WindowManipulator.insertIntoStyleMask(NSWindowStyleMask.titled);
WindowManipulator.removeFromStyleMask(NSWindowStyleMask.borderless);
},
),
];
}
}
50 changes: 50 additions & 0 deletions lib/macos/ns_window_style_mask.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/// Constants that specify the style of a window.
enum NSWindowStyleMask {
/// The window displays none of the usual peripheral elements. Useful only for
/// display or caching purposes. A window that uses
/// `NSWindowStyleMaskBorderless` can't become key or main, unless the value
/// of `canBecomeKey` or `canBecomeMain` is true.
borderless,

/// The window displays a title bar.
titled,

/// The window displays a close button.
closable,

/// The window displays a minimize button.
miniaturizable,

/// The window can be resized by the user.
resizable,

/// This constant has no effect, because all windows that include a toolbar
/// use the unified style.
unifiedTitleAndToolbar,

/// The window can appear full screen. A fullscreen window does not draw its
/// title bar, and may have special handling for its toolbar. (This mask is
/// automatically toggled when `toggleFullScreen(_:)` is called.)
fullScreen,

/// When set, the window's contentView consumes the full size of the window.
/// Although you can combine this constant with other window style masks, it
/// is respected only for windows with a title bar. Note that using this mask
/// opts in to layer-backing. Use the `contentLayoutRect` or the
/// `contentLayoutGuide` to lay out views underneath the title bar–toolbar
/// area.
fullSizeContentView,

/// The window is a panel or a subclass of `NSPanel`.
utilityWindow,

/// The window is a document-modal panel (or a subclass of `NSPanel`).
docModalWindow,

/// The window is a panel or a subclass of `NSPanel` that does not activate
/// the owning app.
nonactivatingPanel,

/// The window is a HUD panel.
hudWindow,
}
33 changes: 33 additions & 0 deletions lib/window_manipulator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/services.dart';
import 'package:macos_window_utils/macos/ns_visual_effect_view_state.dart';
import 'package:macos_window_utils/macos/ns_window_level.dart';
import 'package:macos_window_utils/macos/ns_window_style_mask.dart';
import 'package:macos_window_utils/macos/ns_window_toolbar_style.dart';
import 'package:macos_window_utils/macos/visual_effect_view_properties.dart';
import 'package:macos_window_utils/macos/ns_visual_effect_view_material.dart';
Expand Down Expand Up @@ -513,4 +514,36 @@ class WindowManipulator {
await _completer.future;
await _methodChannel.invokeMethod('orderFrontRegardless');
}

/// Enables a flag that describes the window's current style, such as if it's
/// resizable or in full-screen mode.
///
/// Usage example:
/// ```dart
/// // Make window non-titled and borderless.
/// WindowManipulator.removeFromStyleMask(NSWindowStyleMask.titled);
/// WindowManipulator.insertIntoStyleMask(NSWindowStyleMask.borderless);
/// ```
static Future<void> insertIntoStyleMask(NSWindowStyleMask styleMask) async {
await _completer.future;
await _methodChannel.invokeMethod('insertIntoStyleMask', {
'styleMask': styleMask.name,
});
}

/// Disables a flag that describes the window's current style, such as if it's
/// resizable or in full-screen mode.
///
/// Usage example:
/// ```dart
/// // Make window non-titled and borderless.
/// WindowManipulator.removeFromStyleMask(NSWindowStyleMask.titled);
/// WindowManipulator.insertIntoStyleMask(NSWindowStyleMask.borderless);
/// ```
static Future<void> removeFromStyleMask(NSWindowStyleMask styleMask) async {
await _completer.future;
await _methodChannel.invokeMethod('removeFromStyleMask', {
'styleMask': styleMask.name,
});
}
}
14 changes: 14 additions & 0 deletions macos/Classes/MacOSWindowUtilsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,20 @@ public class MacOSWindowUtilsPlugin: NSObject, FlutterPlugin {
MainFlutterWindowManipulator.orderFrontRegardless()
result(true)

case "insertIntoStyleMask":
let styleMaskName = args["styleMask"] as! String
let styleMask = StyleMaskNameToStyleMaskConverter.getStyleMaskFromName(styleMaskName)

MainFlutterWindowManipulator.insertIntoStyleMask(styleMask)
result(true)

case "removeFromStyleMask":
let styleMaskName = args["styleMask"] as! String
let styleMask = StyleMaskNameToStyleMaskConverter.getStyleMaskFromName(styleMaskName)

MainFlutterWindowManipulator.removeFromStyleMask(styleMask)
result(true)

default:
result(FlutterMethodNotImplemented)
break
Expand Down
18 changes: 18 additions & 0 deletions macos/Classes/MainFlutterWindowManipulator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,22 @@ public class MainFlutterWindowManipulator {

self.mainFlutterWindow!.orderFrontRegardless()
}

public static func insertIntoStyleMask(_ styleMask: NSWindow.StyleMask) {
if (self.mainFlutterWindow == nil) {
printNotStartedWarning()
return
}

self.mainFlutterWindow!.styleMask.insert(styleMask)
}

public static func removeFromStyleMask(_ styleMask: NSWindow.StyleMask) {
if (self.mainFlutterWindow == nil) {
printNotStartedWarning()
return
}

self.mainFlutterWindow!.styleMask.remove(styleMask)
}
}
53 changes: 53 additions & 0 deletions macos/Classes/StyleMaskNameToStyleMaskConverter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// StyleMaskNameToStyleMaskConverter.swift
// macos_window_utils
//
// Created by Adrian Samoticha on 11.01.23.
//

import Foundation

class StyleMaskNameToStyleMaskConverter {
public static func getStyleMaskFromName(_ name: String) -> NSWindow.StyleMask {
switch (name) {
case "borderless":
return .borderless

case "titled":
return .titled

case "closable":
return .closable

case "miniaturizable":
return .miniaturizable

case "resizable":
return .resizable

case "unifiedTitleAndToolbar":
return .unifiedTitleAndToolbar

case "fullScreen":
return .fullScreen

case "fullSizeContentView":
return .fullSizeContentView

case "utilityWindow":
return .utilityWindow

case "docModalWindow":
return .docModalWindow

case "nonactivatingPanel":
return .nonactivatingPanel

case "hudWindow":
return .hudWindow

default:
return .borderless
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: macos_window_utils
description:
macos_window_utils is a Flutter package that provides a set of methods for
modifying the NSWindow of a Flutter application on macOS.
version: 1.0.0+1
version: 1.0.1
repository: https://github.com/Adrian-Samoticha/macos_window_utils.dart

environment:
Expand Down