Skip to content

Commit 1d1e7eb

Browse files
Merge pull request #8 from Adrian-Samoticha/issue_6
Issue #6
2 parents 0170146 + f1d2554 commit 1d1e7eb

File tree

9 files changed

+201
-1
lines changed

9 files changed

+201
-1
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 1.0.1
2+
3+
- Add `setLevel` method.
4+
- Add the following `order*` methods:
5+
- `orderOut`
6+
- `orderBack`
7+
- `orderFront`
8+
- `orderFrontRegardless`
9+
- Add methods to modify the window's `styleMask` property.
10+
- Improve documentation.
11+
112
## 1.0.0+1
213

314
- Improve “Getting started” section in the project's readme.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ and the Flutter guide for
3131
+ A method that makes the window fully transparent (with no blur effect).
3232
+ Methods to enable/disable the window's shadow.
3333
+ Methods and widgets to add, remove, and modify visual effect subviews.
34+
+ Methods to set the window's level as well as reorder the window within its level.
35+
+ Methods to modify the window's style mask.
3436

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

example/lib/main_area/command_list_provider.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22

33
import 'package:macos_window_utils/macos/ns_window_level.dart';
4+
import 'package:macos_window_utils/macos/ns_window_style_mask.dart';
45
import 'package:macos_window_utils/macos/ns_window_toolbar_style.dart';
56
import 'package:macos_window_utils/macos/ns_visual_effect_view_material.dart';
67
import 'package:macos_window_utils/macos/ns_visual_effect_view_state.dart';
@@ -376,6 +377,24 @@ class CommandListProvider {
376377
'or the main window.',
377378
function: () => WindowManipulator.orderFrontRegardless(),
378379
),
380+
Command(
381+
name: 'removeFromStyleMask(NSWindowStyleMask.titled); '
382+
'insertIntoStyleMask(NSWindowStyleMask.borderless)',
383+
description: 'Makes the window non-titled and borderless.',
384+
function: () {
385+
WindowManipulator.removeFromStyleMask(NSWindowStyleMask.titled);
386+
WindowManipulator.insertIntoStyleMask(NSWindowStyleMask.borderless);
387+
},
388+
),
389+
Command(
390+
name: 'insertIntoStyleMask(NSWindowStyleMask.titled); '
391+
'removeFromStyleMask(NSWindowStyleMask.borderless)',
392+
description: 'Makes the window titled and non-borderless.',
393+
function: () {
394+
WindowManipulator.insertIntoStyleMask(NSWindowStyleMask.titled);
395+
WindowManipulator.removeFromStyleMask(NSWindowStyleMask.borderless);
396+
},
397+
),
379398
];
380399
}
381400
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/// Constants that specify the style of a window.
2+
enum NSWindowStyleMask {
3+
/// The window displays none of the usual peripheral elements. Useful only for
4+
/// display or caching purposes. A window that uses
5+
/// `NSWindowStyleMaskBorderless` can't become key or main, unless the value
6+
/// of `canBecomeKey` or `canBecomeMain` is true.
7+
borderless,
8+
9+
/// The window displays a title bar.
10+
titled,
11+
12+
/// The window displays a close button.
13+
closable,
14+
15+
/// The window displays a minimize button.
16+
miniaturizable,
17+
18+
/// The window can be resized by the user.
19+
resizable,
20+
21+
/// This constant has no effect, because all windows that include a toolbar
22+
/// use the unified style.
23+
unifiedTitleAndToolbar,
24+
25+
/// The window can appear full screen. A fullscreen window does not draw its
26+
/// title bar, and may have special handling for its toolbar. (This mask is
27+
/// automatically toggled when `toggleFullScreen(_:)` is called.)
28+
fullScreen,
29+
30+
/// When set, the window's contentView consumes the full size of the window.
31+
/// Although you can combine this constant with other window style masks, it
32+
/// is respected only for windows with a title bar. Note that using this mask
33+
/// opts in to layer-backing. Use the `contentLayoutRect` or the
34+
/// `contentLayoutGuide` to lay out views underneath the title bar–toolbar
35+
/// area.
36+
fullSizeContentView,
37+
38+
/// The window is a panel or a subclass of `NSPanel`.
39+
utilityWindow,
40+
41+
/// The window is a document-modal panel (or a subclass of `NSPanel`).
42+
docModalWindow,
43+
44+
/// The window is a panel or a subclass of `NSPanel` that does not activate
45+
/// the owning app.
46+
nonactivatingPanel,
47+
48+
/// The window is a HUD panel.
49+
hudWindow,
50+
}

lib/window_manipulator.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:async';
33
import 'package:flutter/services.dart';
44
import 'package:macos_window_utils/macos/ns_visual_effect_view_state.dart';
55
import 'package:macos_window_utils/macos/ns_window_level.dart';
6+
import 'package:macos_window_utils/macos/ns_window_style_mask.dart';
67
import 'package:macos_window_utils/macos/ns_window_toolbar_style.dart';
78
import 'package:macos_window_utils/macos/visual_effect_view_properties.dart';
89
import 'package:macos_window_utils/macos/ns_visual_effect_view_material.dart';
@@ -513,4 +514,36 @@ class WindowManipulator {
513514
await _completer.future;
514515
await _methodChannel.invokeMethod('orderFrontRegardless');
515516
}
517+
518+
/// Enables a flag that describes the window's current style, such as if it's
519+
/// resizable or in full-screen mode.
520+
///
521+
/// Usage example:
522+
/// ```dart
523+
/// // Make window non-titled and borderless.
524+
/// WindowManipulator.removeFromStyleMask(NSWindowStyleMask.titled);
525+
/// WindowManipulator.insertIntoStyleMask(NSWindowStyleMask.borderless);
526+
/// ```
527+
static Future<void> insertIntoStyleMask(NSWindowStyleMask styleMask) async {
528+
await _completer.future;
529+
await _methodChannel.invokeMethod('insertIntoStyleMask', {
530+
'styleMask': styleMask.name,
531+
});
532+
}
533+
534+
/// Disables a flag that describes the window's current style, such as if it's
535+
/// resizable or in full-screen mode.
536+
///
537+
/// Usage example:
538+
/// ```dart
539+
/// // Make window non-titled and borderless.
540+
/// WindowManipulator.removeFromStyleMask(NSWindowStyleMask.titled);
541+
/// WindowManipulator.insertIntoStyleMask(NSWindowStyleMask.borderless);
542+
/// ```
543+
static Future<void> removeFromStyleMask(NSWindowStyleMask styleMask) async {
544+
await _completer.future;
545+
await _methodChannel.invokeMethod('removeFromStyleMask', {
546+
'styleMask': styleMask.name,
547+
});
548+
}
516549
}

macos/Classes/MacOSWindowUtilsPlugin.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,20 @@ public class MacOSWindowUtilsPlugin: NSObject, FlutterPlugin {
383383
MainFlutterWindowManipulator.orderFrontRegardless()
384384
result(true)
385385

386+
case "insertIntoStyleMask":
387+
let styleMaskName = args["styleMask"] as! String
388+
let styleMask = StyleMaskNameToStyleMaskConverter.getStyleMaskFromName(styleMaskName)
389+
390+
MainFlutterWindowManipulator.insertIntoStyleMask(styleMask)
391+
result(true)
392+
393+
case "removeFromStyleMask":
394+
let styleMaskName = args["styleMask"] as! String
395+
let styleMask = StyleMaskNameToStyleMaskConverter.getStyleMaskFromName(styleMaskName)
396+
397+
MainFlutterWindowManipulator.removeFromStyleMask(styleMask)
398+
result(true)
399+
386400
default:
387401
result(FlutterMethodNotImplemented)
388402
break

macos/Classes/MainFlutterWindowManipulator.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,4 +534,22 @@ public class MainFlutterWindowManipulator {
534534

535535
self.mainFlutterWindow!.orderFrontRegardless()
536536
}
537+
538+
public static func insertIntoStyleMask(_ styleMask: NSWindow.StyleMask) {
539+
if (self.mainFlutterWindow == nil) {
540+
printNotStartedWarning()
541+
return
542+
}
543+
544+
self.mainFlutterWindow!.styleMask.insert(styleMask)
545+
}
546+
547+
public static func removeFromStyleMask(_ styleMask: NSWindow.StyleMask) {
548+
if (self.mainFlutterWindow == nil) {
549+
printNotStartedWarning()
550+
return
551+
}
552+
553+
self.mainFlutterWindow!.styleMask.remove(styleMask)
554+
}
537555
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// StyleMaskNameToStyleMaskConverter.swift
3+
// macos_window_utils
4+
//
5+
// Created by Adrian Samoticha on 11.01.23.
6+
//
7+
8+
import Foundation
9+
10+
class StyleMaskNameToStyleMaskConverter {
11+
public static func getStyleMaskFromName(_ name: String) -> NSWindow.StyleMask {
12+
switch (name) {
13+
case "borderless":
14+
return .borderless
15+
16+
case "titled":
17+
return .titled
18+
19+
case "closable":
20+
return .closable
21+
22+
case "miniaturizable":
23+
return .miniaturizable
24+
25+
case "resizable":
26+
return .resizable
27+
28+
case "unifiedTitleAndToolbar":
29+
return .unifiedTitleAndToolbar
30+
31+
case "fullScreen":
32+
return .fullScreen
33+
34+
case "fullSizeContentView":
35+
return .fullSizeContentView
36+
37+
case "utilityWindow":
38+
return .utilityWindow
39+
40+
case "docModalWindow":
41+
return .docModalWindow
42+
43+
case "nonactivatingPanel":
44+
return .nonactivatingPanel
45+
46+
case "hudWindow":
47+
return .hudWindow
48+
49+
default:
50+
return .borderless
51+
}
52+
}
53+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: macos_window_utils
22
description:
33
macos_window_utils is a Flutter package that provides a set of methods for
44
modifying the NSWindow of a Flutter application on macOS.
5-
version: 1.0.0+1
5+
version: 1.0.1
66
repository: https://github.com/Adrian-Samoticha/macos_window_utils.dart
77

88
environment:

0 commit comments

Comments
 (0)