Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.

Commit 3a4e856

Browse files
committed
Added transition modifier, added default values
Signed-off-by: Wouter01 <wouterhennen@gmail.com>
1 parent a6e2287 commit 3a4e856

5 files changed

Lines changed: 31 additions & 17 deletions

File tree

Example/WindowManagementProject.xcodeproj/project.pbxproj

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 56;
6+
objectVersion = 60;
77
objects = {
88

99
/* Begin PBXBuildFile section */
1010
6C11A8C02A36610500E86728 /* CodeFileDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C11A8BF2A36610500E86728 /* CodeFileDocument.swift */; };
11+
6C11A8C42A368C3F00E86728 /* WindowManagement in Frameworks */ = {isa = PBXBuildFile; productRef = 6C11A8C32A368C3F00E86728 /* WindowManagement */; };
1112
6CC243D12A3648FE003F9C1A /* WindowManagementProjectApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CC243D02A3648FE003F9C1A /* WindowManagementProjectApp.swift */; };
1213
6CC243D32A3648FE003F9C1A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CC243D22A3648FE003F9C1A /* ContentView.swift */; };
1314
6CC243D52A3648FF003F9C1A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CC243D42A3648FF003F9C1A /* Assets.xcassets */; };
@@ -32,6 +33,7 @@
3233
buildActionMask = 2147483647;
3334
files = (
3435
6CC243E12A36491D003F9C1A /* WindowManagement in Frameworks */,
36+
6C11A8C42A368C3F00E86728 /* WindowManagement in Frameworks */,
3537
);
3638
runOnlyForDeploymentPostprocessing = 0;
3739
};
@@ -94,6 +96,7 @@
9496
name = WindowManagementProject;
9597
packageProductDependencies = (
9698
6CC243E02A36491D003F9C1A /* WindowManagement */,
99+
6C11A8C32A368C3F00E86728 /* WindowManagement */,
97100
);
98101
productName = WindowManagementProject;
99102
productReference = 6CC243CD2A3648FE003F9C1A /* WindowManagementProject.app */;
@@ -124,7 +127,7 @@
124127
);
125128
mainGroup = 6CC243C42A3648FE003F9C1A;
126129
packageReferences = (
127-
6C11A8C12A36722D00E86728 /* XCRemoteSwiftPackageReference "SwiftUI-WindowManagement" */,
130+
6C11A8C22A368C3F00E86728 /* XCLocalSwiftPackageReference ".." */,
128131
);
129132
productRefGroup = 6CC243CE2A3648FE003F9C1A /* Products */;
130133
projectDirPath = "";
@@ -358,18 +361,18 @@
358361
};
359362
/* End XCConfigurationList section */
360363

361-
/* Begin XCRemoteSwiftPackageReference section */
362-
6C11A8C12A36722D00E86728 /* XCRemoteSwiftPackageReference "SwiftUI-WindowManagement" */ = {
363-
isa = XCRemoteSwiftPackageReference;
364-
repositoryURL = "https://github.com/Wouter01/SwiftUI-WindowManagement";
365-
requirement = {
366-
kind = upToNextMajorVersion;
367-
minimumVersion = 2.0.0;
368-
};
364+
/* Begin XCLocalSwiftPackageReference section */
365+
6C11A8C22A368C3F00E86728 /* XCLocalSwiftPackageReference ".." */ = {
366+
isa = XCLocalSwiftPackageReference;
367+
relativePath = ..;
369368
};
370-
/* End XCRemoteSwiftPackageReference section */
369+
/* End XCLocalSwiftPackageReference section */
371370

372371
/* Begin XCSwiftPackageProductDependency section */
372+
6C11A8C32A368C3F00E86728 /* WindowManagement */ = {
373+
isa = XCSwiftPackageProductDependency;
374+
productName = WindowManagement;
375+
};
373376
6CC243E02A36491D003F9C1A /* WindowManagement */ = {
374377
isa = XCSwiftPackageProductDependency;
375378
productName = WindowManagement;

Example/WindowManagementProject/WindowManagementProjectApp.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ struct WindowManagementProjectApp: App {
3030
.injectWindow(.firstWindowGroup)
3131
}
3232
.register(.firstWindowGroup)
33-
.titlebarAppearsTransparent(true)
34-
.movableByBackground(true)
33+
.titlebarAppearsTransparent()
34+
.movableByBackground()
3535
.windowButton(.closeButton, hidden: true)
3636
.backgroundColor(.systemGray.withAlphaComponent(0.001))
3737

@@ -42,12 +42,13 @@ struct WindowManagementProjectApp: App {
4242
.frame(minWidth: 300, minHeight: 300)
4343
}
4444
.enableOpenWindow()
45-
45+
4646
NSDocumentGroup(for: CodeFileDocument.self) { document in
4747
Text(document.fileURL?.absoluteString ?? "")
4848
}
4949
.register(.document(CodeFileDocument.self))
50-
.movableByBackground(true)
50+
.transition(.documentWindow)
51+
.movableByBackground()
5152
.windowButton(.miniaturizeButton, hidden: true)
5253
}
5354
.environment(\.controlSize, .large)

Sources/WindowManagement/NSWindow+Extensions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ extension NSWindow {
7070
self.isRestorable = !disableRestore
7171
}
7272

73+
if let animationBehavior = value.animationBehavior {
74+
self.animationBehavior = animationBehavior
75+
}
76+
7377
value.windowButtonsEnabled.forEach {
7478
standardWindowButton($0)?.isHidden = $1.isHidden
7579
standardWindowButton($0)?.isEnabled = $1.enabled

Sources/WindowManagement/Scene+Window.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public extension Scene {
3737
}
3838

3939
/// Indicates whether the window can be moved by clicking and dragging its background.
40-
func movableByBackground(_ value: Bool) -> some Scene {
40+
func movableByBackground(_ value: Bool = true) -> some Scene {
4141
WM.modifications[WM.currentIdentifier]?.movableByBackground = value
4242
return self
4343
}
@@ -92,7 +92,7 @@ public extension Scene {
9292
}
9393

9494
/// Makes the titlebar transparent.
95-
func titlebarAppearsTransparent(_ value: Bool) -> some Scene {
95+
func titlebarAppearsTransparent(_ value: Bool = true) -> some Scene {
9696
WM.modifications[WM.currentIdentifier]?.titlebarAppearsTransparent = value
9797
return self
9898
}
@@ -102,4 +102,9 @@ public extension Scene {
102102
WM.modifications[WM.currentIdentifier]?.disableRestoreOnLaunch = true
103103
return self
104104
}
105+
106+
func transition(_ transition: NSWindow.AnimationBehavior) -> some Scene {
107+
WM.modifications[WM.currentIdentifier]?.animationBehavior = transition
108+
return self
109+
}
105110
}

Sources/WindowManagement/WindowManagement.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct WindowModifications {
2121
var backgroundColor: NSColor?
2222
var titlebarAppearsTransparent: Bool?
2323
var disableRestoreOnLaunch: Bool?
24+
var animationBehavior: NSWindow.AnimationBehavior?
2425

2526
struct WindowButton {
2627
var enabled = true

0 commit comments

Comments
 (0)