Skip to content

Commit

Permalink
display(macos): add a setting to start a given VM in fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
haroldm committed Apr 14, 2024
1 parent db72c98 commit c1de201
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Configuration/UTMConfigurationInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ struct UTMConfigurationInfo: Codable {
/// VM name displayed to user.
var name: String = NSLocalizedString("Virtual Machine", comment: "UTMConfigurationInfo")

#if os(macOS)
/// If true, starts the VM in full screen.
var isFullScreenStart: Bool = false
#endif

/// Path to the icon.
var iconURL: URL?

Expand All @@ -39,6 +44,7 @@ struct UTMConfigurationInfo: Codable {
case isIconCustom = "IconCustom"
case notes = "Notes"
case uuid = "UUID"
case isFullScreenStart = "IsFullScreenStart"
}

init() {
Expand All @@ -59,6 +65,9 @@ struct UTMConfigurationInfo: Codable {
}
notes = try values.decodeIfPresent(String.self, forKey: .notes)
uuid = try values.decode(UUID.self, forKey: .uuid)
#if os(macOS)
isFullScreenStart = try values.decodeIfPresent(Bool.self, forKey: .isFullScreenStart) ?? false
#endif
}

func encode(to encoder: Encoder) throws {
Expand All @@ -75,6 +84,9 @@ struct UTMConfigurationInfo: Codable {
}
try container.encodeIfPresent(notes, forKey: .notes)
try container.encode(uuid, forKey: .uuid)
#if os(macOS)
try container.encode(isFullScreenStart, forKey: .isFullScreenStart)
#endif
}

static func builtinIcon(named name: String) -> URL? {
Expand Down
9 changes: 9 additions & 0 deletions Platform/Shared/VMConfigInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ struct VMConfigInfoView: View {
Text("Name").frame(width: 50, alignment: .trailing)
nameField
}
HStack {
Text("").frame(width: 50, alignment: .trailing)
Toggle(isOn:
$config.isFullScreenStart,
label: {
Text("Start the VM display(s) in full screen")
}
)
}
HStack(alignment: .top) {
Text("Notes").frame(width: 50, alignment: .trailing)
notesField
Expand Down
4 changes: 4 additions & 0 deletions Platform/macOS/UTMDataExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ extension UTMData {
vm.wrapped!.delegate = unwrappedWindow
unwrappedWindow.showWindow(nil)
unwrappedWindow.window!.makeMain()
if vm.wrapped!.config.information.isFullScreenStart && !unwrappedWindow.window!.styleMask.contains(.fullScreen) {
unwrappedWindow.window!.toggleFullScreen(nil)
}

if startImmediately {
unwrappedWindow.requestAutoStart(options: options)
}
Expand Down

0 comments on commit c1de201

Please sign in to comment.