Macでは常にネイティブのカーソル位置をウインドウドラッグに使うようにした。
Mac側ネイティブプラグインのコード整理と修正。
This commit is contained in:
@@ -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: trueなら透過、falseなら戻す
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ウィンドウの位置を設定
|
||||
|
||||
Reference in New Issue
Block a user