MacでもIsMinimized()を追加。

macOS 10.15 以降にすれば NSScreen.localizedName が使える...。
This commit is contained in:
Kirurobo
2020-12-10 21:01:44 +09:00
parent ac73bee6db
commit d8612481fe
3 changed files with 41 additions and 0 deletions

View File

@@ -39,6 +39,10 @@ UNIWINC_EXPORT BOOL IsMaximized() {
return [LibUniWinC isMaximized];
}
UNIWINC_EXPORT BOOL IsMinimized() {
return [LibUniWinC isMinimized];
}
UNIWINC_EXPORT BOOL DetachWindow() {
[LibUniWinC detachWindow];
return true;
@@ -104,6 +108,10 @@ UNIWINC_EXPORT BOOL GetMonitorRectangle(SInt32 monitorIndex, Float32* x, Float32
return [LibUniWinC getMonitorRectangleWithMonitorIndex:monitorIndex x:x y:y width:width height:height];
}
UNIWINC_EXPORT BOOL GetMonitorName(SInt32 monitorIndex, void* nameString) {
return [LibUniWinC getMonitorNameWithMonitorIndex: monitorIndex name: nameString];
}
UNIWINC_EXPORT BOOL RegisterMonitorChangedCallback(IntCallback callback) {
return [LibUniWinC registerMonitorChangedCallbackWithCallback: callback];
}

View File

@@ -154,6 +154,10 @@ public class LibUniWinC : NSObject {
}
}
@objc public static func isMinimized() -> Bool {
return (targetWindow?.isMiniaturized ?? false)
}
// MARK: - Initialize, window handling
/// Initialize
@@ -307,6 +311,22 @@ public class LibUniWinC : NSObject {
setTransparent(isTransparent: state.isTransparent)
}
}
/// Copy UTF-16 string to uint16 buffer and add null for the end of the string
private static func _copyUTF16ToBuffer(text: String.UTF16View, buffer: UnsafeMutablePointer<uint16>) -> Bool {
let count = text.count
if (count <= 0) {
return false
}
var i = 0
for c in text {
buffer[i] = c
i += 1
}
buffer[count] = uint16.zero // End of the string
return true
}
// MARK: - Functions to get or set the window state
@@ -619,6 +639,19 @@ public class LibUniWinC : NSObject {
return true
}
@objc public static func getMonitorName(monitorIndex: Int32, name: UnsafeMutableRawPointer) -> Bool {
let screen = NSScreen.screens[monitorIndices[Int(monitorIndex)]]
let utf16Name = screen.localizedName.utf16
let buffer = UnsafeMutablePointer<uint16>.allocate(capacity: utf16Name.count + 1)
let result = _copyUTF16ToBuffer(text: utf16Name, buffer: buffer)
buffer.deallocate()
return result
}
@objc public static func registerMonitorChangedCallback(callback: @escaping intCallback) -> Bool {
monitorChangedCallback = callback