Skip to content

Commit 094b755

Browse files
author
*
committed
add option to use main screen size
1 parent d6a5ee8 commit 094b755

10 files changed

+96
-27
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2022 Jahn Bertsch
1+
Copyright 2022-2023 Jahn Bertsch
22
Copyright 2021 Khaos Tian
33

44
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

virtualOS.xcodeproj/project.pbxproj

+8-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
00989C9A27E238930048776B /* VirtualMacConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00989C9927E238930048776B /* VirtualMacConfiguration.swift */; };
2626
00A4FFE8283E3D6F004DD9B3 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A4FFE7283E3D6F004DD9B3 /* SettingsView.swift */; };
2727
0114C02629AA2416004159AF /* MenuCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0114C02529AA2416004159AF /* MenuCommands.swift */; };
28+
01FCAD8429AB707C00F12689 /* ApplicationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01FCAD8329AB707C00F12689 /* ApplicationDelegate.swift */; };
2829
/* End PBXBuildFile section */
2930

3031
/* Begin PBXContainerItemProxy section */
@@ -68,6 +69,7 @@
6869
00A4FFE7283E3D6F004DD9B3 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
6970
00BA26AC2826DAF200E80B76 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
7071
0114C02529AA2416004159AF /* MenuCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuCommands.swift; sourceTree = "<group>"; };
72+
01FCAD8329AB707C00F12689 /* ApplicationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationDelegate.swift; sourceTree = "<group>"; };
7173
/* End PBXFileReference section */
7274

7375
/* Begin PBXFrameworksBuildPhase section */
@@ -169,6 +171,7 @@
169171
00989C9127E236A10048776B /* Model */ = {
170172
isa = PBXGroup;
171173
children = (
174+
01FCAD8329AB707C00F12689 /* ApplicationDelegate.swift */,
172175
0044A65427F601E60007988A /* MainViewModel.swift */,
173176
007987B027E24A8400960D74 /* VirtualMac.swift */,
174177
00989C9927E238930048776B /* VirtualMacConfiguration.swift */,
@@ -323,6 +326,7 @@
323326
00989C9627E236A10048776B /* MainView.swift in Sources */,
324327
0005A77A27E2809E0013BE83 /* VirtualMachineView.swift in Sources */,
325328
00989C6427E2340C0048776B /* virtualOSApp.swift in Sources */,
329+
01FCAD8429AB707C00F12689 /* ApplicationDelegate.swift in Sources */,
326330
007987B127E24A8400960D74 /* VirtualMac.swift in Sources */,
327331
0044A65A27F76BD30007988A /* URL+Paths.swift in Sources */,
328332
00A4FFE8283E3D6F004DD9B3 /* SettingsView.swift in Sources */,
@@ -492,7 +496,7 @@
492496
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
493497
CODE_SIGN_STYLE = Automatic;
494498
COMBINE_HIDPI_IMAGES = YES;
495-
CURRENT_PROJECT_VERSION = 4;
499+
CURRENT_PROJECT_VERSION = 5;
496500
DEAD_CODE_STRIPPING = YES;
497501
DEVELOPMENT_ASSET_PATHS = "\"virtualOS/Preview Content\"";
498502
DEVELOPMENT_TEAM = 2AD47BTDQ6;
@@ -507,7 +511,7 @@
507511
"@executable_path/../Frameworks",
508512
);
509513
MACOSX_DEPLOYMENT_TARGET = 12.0;
510-
MARKETING_VERSION = 1.1;
514+
MARKETING_VERSION = 1.2;
511515
PRODUCT_BUNDLE_IDENTIFIER = com.github.yep.ios.virtualOS;
512516
PRODUCT_NAME = "$(TARGET_NAME)";
513517
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -525,7 +529,7 @@
525529
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
526530
CODE_SIGN_STYLE = Automatic;
527531
COMBINE_HIDPI_IMAGES = YES;
528-
CURRENT_PROJECT_VERSION = 4;
532+
CURRENT_PROJECT_VERSION = 5;
529533
DEAD_CODE_STRIPPING = YES;
530534
DEVELOPMENT_ASSET_PATHS = "\"virtualOS/Preview Content\"";
531535
DEVELOPMENT_TEAM = 2AD47BTDQ6;
@@ -540,7 +544,7 @@
540544
"@executable_path/../Frameworks",
541545
);
542546
MACOSX_DEPLOYMENT_TARGET = 12.0;
543-
MARKETING_VERSION = 1.1;
547+
MARKETING_VERSION = 1.2;
544548
PRODUCT_BUNDLE_IDENTIFIER = com.github.yep.ios.virtualOS;
545549
PRODUCT_NAME = "$(TARGET_NAME)";
546550
SWIFT_EMIT_LOC_STRINGS = YES;
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// ApplicationDelegate.swift
3+
// virtualOS
4+
//
5+
// Created by Jahn Bertsch on 26.02.23.
6+
//
7+
8+
import AppKit
9+
10+
class ApplicationDelegate: NSObject, NSApplicationDelegate {
11+
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
12+
return true
13+
}
14+
}

virtualOS/Model/MainViewModel.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ final class MainViewModel: NSObject, ObservableObject {
2828
@Published var showLicenseInformationModal = false
2929
@Published var showConfirmationAlert = false
3030
@Published var showSettings = false
31+
@Published var isFullScreen = false
32+
@Published var useMainScreenSize = true
3133
@Published var licenseInformationTitleString = ""
3234
@Published var licenseInformationString = ""
3335
@Published var confirmationText = ""
@@ -72,7 +74,7 @@ final class MainViewModel: NSObject, ObservableObject {
7274
moveFilesAfterUpdate()
7375
}
7476

75-
func buttonPressed() {
77+
func statusButtonPressed() {
7678
switch state {
7779
case .Stopped:
7880
start()

virtualOS/Model/VirtualMac.swift

+18
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,31 @@ import Combine
1212

1313
final class VirtualMac: ObservableObject {
1414
struct Parameters: Codable {
15+
init() {}
16+
init(from decoder: Decoder) throws {
17+
let container = try decoder.container(keyedBy: CodingKeys.self)
18+
cpuCount = try container.decode(Int.self, forKey: .cpuCount)
19+
cpuCountMin = try container.decode(Int.self, forKey: .cpuCountMin)
20+
cpuCountMax = try container.decode(Int.self, forKey: .cpuCountMax)
21+
diskSizeInGB = try container.decode(UInt64.self, forKey: .diskSizeInGB)
22+
memorySizeInGB = try container.decode(UInt64.self, forKey: .memorySizeInGB)
23+
memorySizeInGBMin = try container.decode(UInt64.self, forKey: .memorySizeInGBMin)
24+
memorySizeInGBMax = try container.decode(UInt64.self, forKey: .memorySizeInGBMax)
25+
useMainScreenSize = try container.decodeIfPresent(Bool.self, forKey: .useMainScreenSize) ?? false // optional
26+
screenWidth = try container.decode(Int.self, forKey: .screenWidth)
27+
screenHeight = try container.decode(Int.self, forKey: .screenHeight)
28+
pixelsPerInch = try container.decode(Int.self, forKey: .pixelsPerInch)
29+
microphoneEnabled = try container.decode(Bool.self, forKey: .microphoneEnabled)
30+
}
31+
1532
var cpuCount = 1
1633
var cpuCountMin = 1
1734
var cpuCountMax = 2
1835
var diskSizeInGB: UInt64 = UInt64(UserDefaults.standard.diskSize)
1936
var memorySizeInGB: UInt64 = 1
2037
var memorySizeInGBMin: UInt64 = 1
2138
var memorySizeInGBMax: UInt64 = 2
39+
var useMainScreenSize = false
2240
var screenWidth = 1500
2341
var screenHeight = 900
2442
var pixelsPerInch = 250

virtualOS/Model/VirtualMacConfiguration.swift

+9-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,15 @@ final class VirtualMacConfiguration: VZVirtualMachineConfiguration {
118118

119119
fileprivate func configureGraphicsDevice(parameters: VirtualMac.Parameters) {
120120
let graphicsDevice = VZMacGraphicsDeviceConfiguration()
121-
graphicsDevice.displays = [VZMacGraphicsDisplayConfiguration(
122-
widthInPixels: parameters.screenWidth,
123-
heightInPixels: parameters.screenHeight,
124-
pixelsPerInch: parameters.pixelsPerInch
125-
)]
121+
if parameters.useMainScreenSize, let mainScreen = NSScreen.main {
122+
graphicsDevice.displays = [VZMacGraphicsDisplayConfiguration(for: mainScreen, sizeInPoints: NSSize(width: parameters.screenWidth, height: parameters.screenHeight))]
123+
} else {
124+
graphicsDevice.displays = [VZMacGraphicsDisplayConfiguration(
125+
widthInPixels: parameters.screenWidth,
126+
heightInPixels: parameters.screenHeight,
127+
pixelsPerInch: parameters.pixelsPerInch
128+
)]
129+
}
126130
graphicsDevices = [graphicsDevice]
127131
}
128132

virtualOS/View/ConfigurationView.swift

+22-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct ConfigurationView: View {
3232
viewModel.virtualMac.parameters.screenHeight = Int(screenHeightValue)
3333
}
3434
}
35+
@State fileprivate var useCustomScreenSize = true
36+
@State fileprivate var useMainScreenSize = false
3537

3638
var body: some View {
3739
VStack {
@@ -57,6 +59,22 @@ struct ConfigurationView: View {
5759
Text("RAM: \(viewModel.virtualMac.parameters.memorySizeInGB) GB")
5860
.frame(minWidth: sliderTextWidth, alignment: .leading)
5961
}
62+
63+
HStack() {
64+
Text("Screen Size:")
65+
Spacer()
66+
Toggle("Custom", isOn: $useCustomScreenSize).onChange(of: useCustomScreenSize) { newValue in
67+
useMainScreenSize = !newValue
68+
}
69+
Toggle("Main Screen", isOn: $useMainScreenSize).onChange(of: useMainScreenSize) { newValue in
70+
useCustomScreenSize = !newValue
71+
viewModel.virtualMac.parameters.useMainScreenSize = newValue
72+
if let mainScreen = NSScreen.main {
73+
screenWidthValue = Float(mainScreen.frame.width)
74+
screenHeightValue = Float(mainScreen.frame.height)
75+
}
76+
}
77+
}
6078

6179
Slider(value: Binding(get: {
6280
screenWidthValue
@@ -65,7 +83,7 @@ struct ConfigurationView: View {
6583
}), in: 800 ... Float(NSScreen.main?.frame.width ?? CGFloat(parameters.screenWidth)), step: 100) {
6684
Text("Screen Width: \(viewModel.virtualMac.parameters.screenWidth) px")
6785
.frame(minWidth: sliderTextWidth, alignment: .leading)
68-
}
86+
}.disabled(useMainScreenSize)
6987

7088
Slider(value: Binding(get: {
7189
screenHeightValue
@@ -74,11 +92,11 @@ struct ConfigurationView: View {
7492
}), in: 600 ... Float(NSScreen.main?.frame.height ?? CGFloat(parameters.screenHeight)), step: 50) {
7593
Text("Screen Height: \(viewModel.virtualMac.parameters.screenHeight) px")
7694
.frame(minWidth: sliderTextWidth, alignment: .leading)
77-
}
95+
}.disabled(useMainScreenSize)
7896
}
7997
.padding()
8098
.overlay {
81-
RoundedRectangle(cornerRadius: 10)
99+
RoundedRectangle(cornerRadius: 5)
82100
.stroke(.tertiary, lineWidth: 1)
83101
}
84102

@@ -90,6 +108,7 @@ struct ConfigurationView: View {
90108
let parameters = viewModel.virtualMac.parameters
91109
cpuCountSliderValue = Float(parameters.cpuCount)
92110
memorySliderValue = Float(parameters.memorySizeInGB)
111+
useMainScreenSize = parameters.useMainScreenSize
93112
screenWidthValue = Float(parameters.screenWidth)
94113
screenHeightValue = Float(parameters.screenHeight)
95114
}

virtualOS/View/MainView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ struct MainView: View {
1414

1515
var body: some View {
1616
VStack {
17-
Spacer()
1817
if viewModel.showStatusBar {
18+
Spacer()
1919
HStack {
2020
Text(viewModel.statusLabel)
2121
Spacer()
2222
Button {
23-
viewModel.buttonPressed()
23+
viewModel.statusButtonPressed()
2424
} label: {
2525
Text(viewModel.statusButtonLabel)
2626
}.disabled(viewModel.statusButtonDisabled)

virtualOS/View/MenuCommands.swift

+13-9
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import SwiftUI
99

10+
#if arch(arm64)
11+
1012
struct MenuCommands: Commands {
1113
@ObservedObject var viewModel: MainViewModel
1214

13-
#if arch(arm64)
14-
1515
var body: some Commands {
1616
CommandGroup(replacing: .appInfo) {
1717
Button("About virtualOS") {
@@ -23,8 +23,11 @@ struct MenuCommands: Commands {
2323
viewModel.showSettings = !viewModel.showSettings
2424
}.keyboardShortcut(",")
2525
}
26-
CommandGroup(replacing: .newItem) {}
27-
CommandGroup(after: .newItem) {
26+
CommandGroup(replacing: .newItem) {
27+
Button(viewModel.statusButtonLabel) {
28+
viewModel.statusButtonPressed()
29+
}.keyboardShortcut("R")
30+
Divider()
2831
Button("Delete Restore Image") {
2932
viewModel.deleteRestoreImage()
3033
}.disabled(!MainViewModel.restoreImageExists)
@@ -38,14 +41,15 @@ struct MenuCommands: Commands {
3841
viewModel.showStatusBar = !viewModel.showStatusBar
3942
}.keyboardShortcut("B")
4043
Divider()
41-
Button("Enter Full Screen") {
44+
Button(String(format: "%@ Full Screen", viewModel.isFullScreen ? "Exit" : "Enter")) {
4245
if let window = NSApplication.shared.windows.first {
46+
viewModel.isFullScreen = !viewModel.isFullScreen
47+
viewModel.showStatusBar = !viewModel.isFullScreen
4348
window.toggleFullScreen(nil)
4449
}
45-
}.keyboardShortcut("F", modifiers: [.command, .option])
50+
}.keyboardShortcut("F")
4651
}
47-
}
48-
49-
#endif // #if arch(arm64)
52+
}
5053
}
5154

55+
#endif // #if arch(arm64)

virtualOS/virtualOSApp.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ struct virtualOSApp: App {
1818

1919
#if arch(arm64)
2020
@StateObject var viewModel = MainViewModel()
21-
@AppStorage("NSFullScreenMenuItemEverywhere") var fullScreenItemEverywhere = false
2221
#endif
2322

23+
@AppStorage("NSFullScreenMenuItemEverywhere") var fullScreenMenuItemEverywhere = false
24+
@NSApplicationDelegateAdaptor(ApplicationDelegate.self) var applicationDelegate
25+
2426
init() {
25-
fullScreenItemEverywhere = false
27+
fullScreenMenuItemEverywhere = false
2628
NSWindow.allowsAutomaticWindowTabbing = false
2729
}
2830

@@ -57,7 +59,9 @@ struct virtualOSApp: App {
5759
#endif // #if arch(arm64)
5860
}
5961
.commands {
62+
#if arch(arm64)
6063
MenuCommands(viewModel: viewModel)
64+
#endif
6165
}
6266
}
6367

0 commit comments

Comments
 (0)