Fixed a crash when setting the window to borderless on macOS if the screen was initially in full screen mode.

This commit is contained in:
Kirurobo
2025-02-03 18:16:02 +09:00
parent 3ede014d7c
commit cd416cfbc9
4 changed files with 52 additions and 29 deletions

View File

@@ -80,7 +80,7 @@ func getOpenFileNames() -> String {
}
struct ContentView: View {
@State private var messageText = "Get all windows"
@State private var buttonText = "Get all windows"
@State private var outputText = ""
@State private var window: NSWindow?
@@ -131,30 +131,39 @@ struct ContentView: View {
}
}){ Text("Save") }
Text("Windows info").padding()
Text("Window Info.").padding()
Button(action: {
// if (LibUniWinC.attachMyWindow()) {
// //LibUniWinC.setTransparent(isTransparent: true)
// messageText = "IsActive: " + String(LibUniWinC.isActive())
// } else {
// messageText = "Can't attach"
// }
let dict = getWindowList()
outputText = String(findWindowNumber(dict: dict, name: "DebugUniWinC"))
buttonText = String(findWindowNumber(dict: dict, name: "DebugUniWinC"))
window = findWindow(dict: dict, name: "DebugUniWinC")
if (window != nil) {
outputText = "Class Name: " + window!.className
buttonText = "Attached class: " + window!.className
LibUniWinC._attachWindow(window: window!)
outputText = "Title : " + window!.title
+ "\nStyleMask : " + window!.styleMask.rawValue.description
+ "\nFrame : " + window!.frame.debugDescription
+ "\nIsKeyWindow : " + window!.isKeyWindow.description
+ "\nIsZoomed : " + window!.isZoomed.description
+ "\nCanHide : " + window!.canHide.description
+ "\nIsOpaque : " + window!.isOpaque.description
+ "\nHasShadow : " + window!.hasShadow.description
+ "\nIsSheet : " + window!.isSheet.description
+ "\nOcclusionState : " + window!.occlusionState.rawValue.description
+ "\n\n"
window!.hasShadow = false
} else {
outputText = "Window is nil"
buttonText = "Current window is nil"
outputText = ""
}
messageText = outputText
outputText = toString(dict: dict) + getAllWindows()
}){ Text(messageText) }
outputText += toString(dict: dict) + getAllWindows()
}){ Text(buttonText) }
ScrollView([.vertical, .horizontal]) {
Text(outputText)

View File

@@ -555,19 +555,30 @@ public class LibUniWinC {
/// - isBorderless:
private static func _setWindowBorderless(window: NSWindow, isBorderless: Bool) -> Void {
if (isBorderless) {
//
window.hasShadow = false
window.styleMask = [.borderless]
//window.styleMask.insert(.borderless)
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
// macOSstyleMask 0 (== [.borderless])
// .fullscreen
// .borderless .borderless
if (!window.styleMask.contains(.fullScreen) && (window.styleMask != [.borderless])) {
window.styleMask = [.borderless]
if (window.hasTitleBar) {
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
}
}
} else {
window.styleMask = orgWindowInfo.styleMask
if (!orgWindowInfo.styleMask.contains(.borderless)) {
// .borderless
window.styleMask.remove(.borderless)
}
window.titlebarAppearsTransparent = orgWindowInfo.titlebarAppearsTransparent
window.titleVisibility = orgWindowInfo.titleVisibility
if (window.hasTitleBar) {
window.titlebarAppearsTransparent = orgWindowInfo.titlebarAppearsTransparent
window.titleVisibility = orgWindowInfo.titleVisibility
}
window.hasShadow = orgWindowInfo.hasShadow
}
}
@@ -1237,6 +1248,9 @@ public class LibUniWinC {
if (targetWindow!.canBecomeMain) { result += 1 }
if (targetWindow!.canBecomeKey) { result += 2 }
if (targetWindow!.isKeyWindow) { result += 4 }
// // styleMask調
// result = Int32(targetWindow!.styleMask.rawValue)
}
return result
}