Added update function to keep the window transparent

This commit is contained in:
Kirurobo
2021-09-12 19:52:48 +09:00
parent 9154384fa9
commit b9edd88134
4 changed files with 84 additions and 40 deletions

View File

@@ -140,7 +140,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\ncp -r -f $BUILT_PRODUCTS_DIR/*.bundle $SRCROOT/../Unity/Assets/Kirurobo/UniWindowController/Runtime/Plugins/macOS/\n";
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\ncp -r -f $BUILT_PRODUCTS_DIR/*.bundle $SRCROOT/../UniWinC/Assets/Kirurobo/UniWindowController/Runtime/Plugins/macOS/\n";
};
/* End PBXShellScriptBuildPhase section */
@@ -210,7 +210,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
@@ -265,7 +265,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;

View File

@@ -159,3 +159,8 @@ UNIWINC_EXPORT void SetTransparentType(SInt32 type) {
UNIWINC_EXPORT void SetKeyColor(SInt32 color) {
[LibUniWinC setKeyColorWithColor: color];
}
// Call periodically to maintain window state.
UNIWINC_EXPORT void Update() {
[LibUniWinC update];
}

View File

@@ -161,17 +161,31 @@ public class LibUniWinC : NSObject {
}
@objc public static func isMaximized() -> Bool {
if (state.isTransparent) {
return state.isZoomed
} else {
return (targetWindow?.isZoomed ?? false)
}
return state.isZoomed
//return _isZoomedActually()
}
@objc public static func isMinimized() -> Bool {
return (targetWindow?.isMiniaturized ?? false)
}
private static func _isZoomedActually() -> Bool {
if (targetWindow == nil) {
return false
} else if (targetWindow!.isMiniaturized) {
return false
} else if (state.isTransparent) {
// When the window is transparent
let monitorIndex = getCurrentMonitor()
let rect = monitorRectangles[monitorIndices[Int(monitorIndex)]]
let frame = targetWindow!.frame
return (frame.size == rect.size) && (frame.origin == rect.origin)
} else {
// When the window is opaque
return targetWindow!.isZoomed
}
}
// MARK: - Initialize, window handling
/// Initialize
@@ -278,7 +292,8 @@ public class LibUniWinC : NSObject {
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)
//center.addObserver(self, selector: #selector(_resizedObserver(notification:)), name: NSWindow.didResizeNotification, object: window)
center.addObserver(self, selector: #selector(_resizedObserver(notification:)), name: NSWindow.didEndLiveResizeNotification, object: window)
center.addObserver(self, selector: #selector(_keepBottommostObserver(notification:)), name: NSWindow.didBecomeKeyNotification, object: window)
}
@@ -289,7 +304,8 @@ public class LibUniWinC : NSObject {
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, name: NSWindow.didResizeNotification, object: targetWindow)
center.removeObserver(self, name: NSWindow.didEndLiveResizeNotification, object: targetWindow)
center.removeObserver(self, name: NSWindow.didBecomeKeyNotification, object: targetWindow)
//center.removeObserver(self)
@@ -318,8 +334,12 @@ public class LibUniWinC : NSObject {
}
@objc static func _resizedObserver(notification: Notification) {
if ((targetWindow != nil) && (targetWindow!.isZoomed != state.isZoomed)) {
state.isZoomed = targetWindow!.isZoomed
if (targetWindow != nil) {
let zoomed = _isZoomedActually()
if (state.isZoomed != zoomed) {
state.isZoomed = zoomed
}
_doWindowStyleChangedCallback(num: EventType.Size)
}
}
@@ -332,6 +352,23 @@ public class LibUniWinC : NSObject {
}
}
/// Call this periodically to maintain window state.
@objc public static func update() {
if (targetWindow != nil) {
if (state.isTransparent) {
// Keep window transparent
if (targetWindow!.isOpaque) {
_setWindowTransparent(window: targetWindow!, isTransparent: true)
}
// Keep contentView transparent
if (targetWindow!.contentView?.layer?.isOpaque ?? false) {
_setContentViewTransparent(window: targetWindow!, isTransparent: true)
}
}
}
}
private static func _doWindowStyleChangedCallback(num : EventType) -> Void {
windowStyleChangedCallback?(num.rawValue)
}
@@ -461,26 +498,24 @@ public class LibUniWinC : NSObject {
state.isTransparent = isTransparent
}
///
/// - Parameter isBorderless: true
/// Hide or show the window border
/// - Parameter isBorderless: true for borderless
@objc public static func setBorderless(isBorderless: Bool) -> Void {
if let window: NSWindow = targetWindow {
if (isMaximized()) {
////
////
//setMaximized(isZoomed: false)
_setWindowBorderless(window: window, isBorderless: isBorderless)
//setMaximized(isZoomed: true)
} else {
//
_setWindowBorderless(window: window, isBorderless: isBorderless)
_setWindowBorderless(window: window, isBorderless: isBorderless)
if (state.isZoomed && isBorderless) {
// Zoom to the screen size
let monitorIndex = getCurrentMonitor()
let rect = monitorRectangles[monitorIndices[Int(monitorIndex)]]
window.setFrame(rect, display: true, animate: false)
}
}
state.isBorderless = isBorderless
}
///
/// - Parameter isTopmost: true
/// - Parameter isTopmost: true for topmost (higher than the menu bar)
@objc public static func setTopmost(isTopmost: Bool) -> Void {
if let window: NSWindow = targetWindow {
if (isTopmost) {
@@ -522,32 +557,36 @@ public class LibUniWinC : NSObject {
/// Maximize the window
@objc public static func setMaximized(isZoomed: Bool) -> Void {
if (targetWindow != nil) {
if (state.isTransparent) {
//
//
setTransparent(isTransparent: false)
if (targetWindow!.isZoomed != isZoomed) {
targetWindow!.zoom(nil)
}
setTransparent(isTransparent: true)
if (state.isBorderless) {
// The window is ransparent (borderless)
if (isZoomed) {
// zoom()
// The window couldn't be zoomed when it is borderless
let monitorIndex = getCurrentMonitor()
let rect = monitorRectangles[monitorIndices[Int(monitorIndex)]]
var frame = targetWindow!.frame
frame.size.width = CGFloat(rect.width)
frame.size.height = CGFloat(rect.height)
targetWindow?.setFrame(frame, display: true)
targetWindow?.setFrame(rect, display: true, animate: false)
state.isZoomed = isZoomed
} else {
//setTransparent(isTransparent: false)
setBorderless(isBorderless: false)
if (targetWindow!.isZoomed != isZoomed) {
targetWindow!.zoom(nil)
state.isZoomed = targetWindow!.isZoomed
}
//setTransparent(isTransparent: true)
setBorderless(isBorderless: true)
}
} else {
// The window is opaque
if (targetWindow!.isZoomed != isZoomed) {
// Toggle
targetWindow!.zoom(nil)
state.isZoomed = targetWindow!.isZoomed
}
}
} else {
// Remember the state
state.isZoomed = isZoomed
}
state.isZoomed = isZoomed
}
///
@@ -604,7 +643,7 @@ public class LibUniWinC : NSObject {
frame.size.width = CGFloat(width)
frame.size.height = CGFloat(height)
targetWindow?.setFrame(frame, display: true)
targetWindow?.setFrame(frame, display: true, animate: false)
return true
}