MacでaddObserverをselectorのものに換装。
removeObserverは不要かもしれないが、現状入れてある。
This commit is contained in:
@@ -120,6 +120,7 @@ public class LibUniWinC : NSObject {
|
||||
public static var dropFilesCallback: stringCallback? = nil
|
||||
public static var monitorChangedCallback: intCallback? = nil
|
||||
public static var windowStyleChangedCallback: intCallback? = nil
|
||||
private static var observerObject: Any? = nil
|
||||
|
||||
/// Sub view to implement file dropping
|
||||
private static var overlayView: OverlayView? = nil
|
||||
@@ -234,21 +235,7 @@ public class LibUniWinC : NSObject {
|
||||
|
||||
/// Detach from the window
|
||||
@objc public static func detachWindow() -> Void {
|
||||
if (targetWindow != nil) {
|
||||
let center = NotificationCenter.default
|
||||
center.removeObserver(self)
|
||||
|
||||
// Restore the original style
|
||||
orgWindowInfo.Restore(window: targetWindow!)
|
||||
|
||||
// Remove the subview
|
||||
if (overlayView != nil) {
|
||||
overlayView?.removeFromSuperview()
|
||||
overlayView = nil
|
||||
}
|
||||
|
||||
targetWindow = nil
|
||||
}
|
||||
_detachWindow()
|
||||
}
|
||||
|
||||
/// Attach to my main window
|
||||
@@ -285,31 +272,116 @@ public class LibUniWinC : NSObject {
|
||||
_reapplyWindowStyles()
|
||||
|
||||
// Reapply the state at fullscreen
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: nil,
|
||||
object: nil,
|
||||
queue: OperationQueue.main)
|
||||
{
|
||||
notification -> Void in
|
||||
switch(notification.name) {
|
||||
// if (observerObject != nil) {
|
||||
// NotificationCenter.default.removeObserver(observerObject!)
|
||||
// }
|
||||
// observerObject = NotificationCenter.default.addObserver(
|
||||
// forName: nil,
|
||||
// object: nil,
|
||||
// queue: OperationQueue.main)
|
||||
// {
|
||||
// notification -> Void in
|
||||
// switch(notification.name) {
|
||||
// case NSWindow.didEnterFullScreenNotification:
|
||||
// _reapplyWindowStyles()
|
||||
// _doWindowStyleChangedCallback(num: EventType.Size)
|
||||
// break
|
||||
// case NSWindow.didExitFullScreenNotification:
|
||||
// _reapplyWindowStyles()
|
||||
// _doWindowStyleChangedCallback(num: EventType.Size)
|
||||
// break
|
||||
// case NSWindow.didMiniaturizeNotification:
|
||||
// _doWindowStyleChangedCallback(num: EventType.Size)
|
||||
// break
|
||||
// case NSWindow.didDeminiaturizeNotification:
|
||||
// _doWindowStyleChangedCallback(num: EventType.Size)
|
||||
// break
|
||||
// case NSWindow.didResizeNotification:
|
||||
// if ((targetWindow != nil) && (targetWindow!.isZoomed != state.isZoomed)) {
|
||||
// state.isZoomed = targetWindow!.isZoomed
|
||||
// _doWindowStyleChangedCallback(num: EventType.Size)
|
||||
// }
|
||||
// default:
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
|
||||
let center = NotificationCenter.default
|
||||
center.addObserver(self, selector: #selector(_fullScreenChangedObserver(notification:)), name: NSWindow.didEnterFullScreenNotification, object: window)
|
||||
center.addObserver(self, selector: #selector(_fullScreenChangedObserver(notification:)), name: NSWindow.didExitFullScreenNotification, object: window)
|
||||
center.addObserver(self, selector: #selector(_windowStateChangedObserver(notification:)), name: NSWindow.didMiniaturizeNotification, object: window)
|
||||
center.addObserver(self, selector: #selector(_windowStateChangedObserver(notification:)), name: NSWindow.didDeminiaturizeNotification, object: window)
|
||||
center.addObserver(self, selector: #selector(_resizedObserver(notification:)), name: NSWindow.didResizeNotification, object: window)
|
||||
|
||||
// observerObject = NotificationCenter.default.addObserver(
|
||||
// window,
|
||||
// selector:#selector(_windowStateObserver(name:)),
|
||||
// name: nil,
|
||||
// object: nil
|
||||
// )
|
||||
}
|
||||
|
||||
@objc static func _fullScreenChangedObserver(notification: Notification) {
|
||||
_reapplyWindowStyles()
|
||||
_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
}
|
||||
|
||||
@objc static func _windowStateChangedObserver(notification: Notification) {
|
||||
_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
}
|
||||
|
||||
@objc static func _resizedObserver(notification: Notification) {
|
||||
if ((targetWindow != nil) && (targetWindow!.isZoomed != state.isZoomed)) {
|
||||
state.isZoomed = targetWindow!.isZoomed
|
||||
_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static func _detachWindow() -> Void {
|
||||
if (targetWindow != nil) {
|
||||
let center = NotificationCenter.default
|
||||
center.removeObserver(self, name: NSWindow.didEnterFullScreenNotification, object: targetWindow)
|
||||
center.removeObserver(self, name: NSWindow.didExitFullScreenNotification, object: targetWindow)
|
||||
center.removeObserver(self, name: NSWindow.didMiniaturizeNotification, object: targetWindow)
|
||||
center.removeObserver(self, name: NSWindow.didDeminiaturizeNotification, object: targetWindow)
|
||||
center.removeObserver(self, name: NSWindow.didResizeNotification, object: targetWindow)
|
||||
//center.removeObserver(self)
|
||||
|
||||
// Restore the original style
|
||||
orgWindowInfo.Restore(window: targetWindow!)
|
||||
|
||||
// Remove the subview
|
||||
if (overlayView != nil) {
|
||||
overlayView?.removeFromSuperview()
|
||||
overlayView = nil
|
||||
}
|
||||
|
||||
targetWindow = nil
|
||||
}
|
||||
}
|
||||
|
||||
@objc static func _windowStateObserver(name: NSNotification.Name?) {
|
||||
if (name != nil) {
|
||||
switch(name) {
|
||||
case NSWindow.didEnterFullScreenNotification:
|
||||
_reapplyWindowStyles()
|
||||
_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
//_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
break
|
||||
case NSWindow.didExitFullScreenNotification:
|
||||
_reapplyWindowStyles()
|
||||
_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
//_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
break
|
||||
case NSWindow.didMiniaturizeNotification:
|
||||
_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
//_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
break
|
||||
case NSWindow.didDeminiaturizeNotification:
|
||||
_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
//_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
break
|
||||
case NSWindow.didResizeNotification:
|
||||
if ((targetWindow != nil) && (targetWindow!.isZoomed != state.isZoomed)) {
|
||||
state.isZoomed = targetWindow!.isZoomed
|
||||
_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
//_doWindowStyleChangedCallback(num: EventType.Size)
|
||||
}
|
||||
default:
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user