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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
// macOSのフルスクリーンでは、styleMask が 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user