Macでは常にネイティブのカーソル位置をウインドウドラッグに使うようにした。

Mac側ネイティブプラグインのコード整理と修正。
This commit is contained in:
Kirurobo
2020-10-13 16:55:45 +09:00
parent 9ec0cbf0f2
commit ec84b1e6cc
5 changed files with 103 additions and 109 deletions

View File

@@ -22,7 +22,7 @@ import Cocoa
@objcMembers
public class LibUniWinC : NSObject {
//
//
private struct State {
public var isReady: Bool = false
public var isTopmost: Bool = false
@@ -30,15 +30,16 @@ public class LibUniWinC : NSObject {
public var isTransparent: Bool = false
}
///
private class OriginalWindowInfo {
/// StyleMask
public var StyleMask: NSWindow.StyleMask = []
public var styleMask: NSWindow.StyleMask = []
/// CollectionBehavior
public var CollectionBehavior: NSWindow.CollectionBehavior = []
public var collectionBehavior: NSWindow.CollectionBehavior = []
/// Level
public var Level: NSWindow.Level = NSWindow.Level.normal
public var level: NSWindow.Level = NSWindow.Level.normal
public var titlebarAppearsTransparent: Bool = false
public var titleVisibility: NSWindow.TitleVisibility = NSWindow.TitleVisibility.visible
@@ -49,23 +50,12 @@ public class LibUniWinC : NSObject {
public var contentViewLayerIsOpaque: Bool = true
public var contentViewLayerBackgroundColor: CGColor? = CGColor.clear
// public init() {
// self.StyleMask = []
// self.CollectionBehavior = []
// self.Level = NSWindow.Level.normal
// self.titlebarAppearsTransparent = false
// self.titleVisibility = NSWindow.TitleVisibility.visible
//
// window.backgroundColor = NSColor.clear
// window.isOpaque = true
// window.hasShadow = true
// }
///
public func Store(window: NSWindow) -> Void {
self.CollectionBehavior = window.collectionBehavior
self.StyleMask = window.styleMask
self.Level = window.level
self.collectionBehavior = window.collectionBehavior
self.styleMask = window.styleMask
self.level = window.level
self.titlebarAppearsTransparent = window.titlebarAppearsTransparent
self.titleVisibility = window.titleVisibility
self.backgroundColor = window.backgroundColor
@@ -83,9 +73,9 @@ public class LibUniWinC : NSObject {
///
public func Restore(window: NSWindow) -> Void {
window.collectionBehavior = self.CollectionBehavior
window.styleMask = self.StyleMask
window.level = self.Level
window.collectionBehavior = self.collectionBehavior
window.styleMask = self.styleMask
window.level = self.level
window.titlebarAppearsTransparent = self.titlebarAppearsTransparent
window.titleVisibility = self.titleVisibility
window.backgroundColor = self.backgroundColor
@@ -98,6 +88,7 @@ public class LibUniWinC : NSObject {
}
}
// MARK: - Static variables
/// nil
@@ -112,10 +103,6 @@ public class LibUniWinC : NSObject {
///
private static var primaryMonitorHeight: CGFloat = 0
/// StyleMask
/// see: https://developer.apple.com/documentation/appkit/nswindow.stylemask
private static let transparentStyleMask: NSWindow.StyleMask = [.closable, .titled, .resizable]
// MARK: - Methods
@@ -231,84 +218,26 @@ public class LibUniWinC : NSObject {
_reapplyWindowStyles()
}
///
/// Windows
/// - Parameter type: 0:None, 1:Alpha, 2:ColorKey
@objc public static func setTransparentType(type: Int32) -> Void {
}
///
/// Windows
/// - Parameter color:
@objc public static func setKeyColor(color: Int32) -> Void {
}
///
/// - Parameter isTransparent: true
@objc public static func setTransparent(isTransparent: Bool) -> Void {
if let window: NSWindow = targetWindow {
_setWindowTransparent(window: window, isTransparent: isTransparent)
_setContentViewTransparent(window: window, isTransparent: isTransparent)
_setWindowBorderless(window: window, isBorderless: !isTransparent)
}
state.isTransparent = isTransparent
}
///
/// - Parameter isBorderless: true
@objc public static func setBorderless(isBorderless: Bool) -> Void {
if let window: NSWindow = targetWindow {
_setWindowBorderless(window: window, isBorderless: isBorderless)
}
state.isBorderless = isBorderless
}
///
/// - Parameter isTopmost: true
@objc public static func setTopmost(isTopmost: Bool) -> Void {
if let window: NSWindow = targetWindow {
if (isTopmost) {
window.collectionBehavior = [.fullScreenAuxiliary]
window.level = NSWindow.Level.floating
} else {
window.collectionBehavior = orgWindowInfo.CollectionBehavior
window.level = orgWindowInfo.Level
}
}
state.isTopmost = isTopmost
}
///
@objc public static func setClickThrough(isTransparent: Bool) -> Void {
if (targetWindow != nil) {
targetWindow!.ignoresMouseEvents = isTransparent
}
}
///
@objc public static func setMaximized(isZoomed: Bool) -> Void {
if (targetWindow != nil) {
if (targetWindow!.isZoomed != isZoomed) {
//
targetWindow!.zoom(nil)
}
}
}
///
/// - Parameters:
/// - window:
/// - isTransparent: truefalse
private static func _setWindowTransparent(window: NSWindow, isTransparent: Bool) -> Void {
if (isTransparent) {
window.styleMask = transparentStyleMask
window.styleMask = []
if (state.isBorderless) {
window.styleMask.insert(.borderless)
}
window.backgroundColor = NSColor.clear
window.isOpaque = false
window.hasShadow = false
//window.contentView?.wantsLayer = true
} else {
window.styleMask = orgWindowInfo.StyleMask
window.styleMask = orgWindowInfo.styleMask
if (state.isBorderless) {
window.styleMask.insert(.borderless)
}
window.backgroundColor = orgWindowInfo.backgroundColor
window.isOpaque = orgWindowInfo.isOpaque
window.hasShadow = orgWindowInfo.hasShadow
@@ -338,9 +267,81 @@ public class LibUniWinC : NSObject {
/// - window:
/// - isBorderless:
private static func _setWindowBorderless(window: NSWindow, isBorderless: Bool) -> Void {
window.styleMask = isBorderless ? transparentStyleMask : orgWindowInfo.StyleMask
window.titlebarAppearsTransparent = isBorderless || orgWindowInfo.titlebarAppearsTransparent
window.titleVisibility = isBorderless ? .hidden : orgWindowInfo.titleVisibility
if (isBorderless) {
window.styleMask.insert(.borderless)
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
} else {
if (!orgWindowInfo.styleMask.contains(.borderless)) {
// .borderless
window.styleMask.remove(.borderless)
}
window.titlebarAppearsTransparent = orgWindowInfo.titlebarAppearsTransparent
window.titleVisibility = orgWindowInfo.titleVisibility
}
}
///
/// Windows
/// - Parameter type: 0:None, 1:Alpha, 2:ColorKey
@objc public static func setTransparentType(type: Int32) -> Void {
}
///
/// Windows
/// - Parameter color:
@objc public static func setKeyColor(color: Int32) -> Void {
}
///
/// - Parameter isTransparent: true
@objc public static func setTransparent(isTransparent: Bool) -> Void {
if let window: NSWindow = targetWindow {
_setWindowTransparent(window: window, isTransparent: isTransparent)
_setContentViewTransparent(window: window, isTransparent: isTransparent)
}
state.isTransparent = isTransparent
}
///
/// - Parameter isBorderless: true
@objc public static func setBorderless(isBorderless: Bool) -> Void {
if let window: NSWindow = targetWindow {
_setWindowBorderless(window: window, isBorderless: isBorderless)
}
state.isBorderless = isBorderless
}
///
/// - Parameter isTopmost: true
@objc public static func setTopmost(isTopmost: Bool) -> Void {
if let window: NSWindow = targetWindow {
if (isTopmost) {
window.collectionBehavior = [.fullScreenAuxiliary]
window.level = NSWindow.Level.floating
} else {
window.collectionBehavior = orgWindowInfo.collectionBehavior
window.level = orgWindowInfo.level
}
}
state.isTopmost = isTopmost
}
///
@objc public static func setClickThrough(isTransparent: Bool) -> Void {
if (targetWindow != nil) {
targetWindow!.ignoresMouseEvents = isTransparent
}
}
///
@objc public static func setMaximized(isZoomed: Bool) -> Void {
if (targetWindow != nil) {
if (targetWindow!.isZoomed != isZoomed) {
//
targetWindow!.zoom(nil)
}
}
}
///