12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- //
- // KMSnapshotWindow.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/12/13.
- //
- import Cocoa
- class KMSnapshotWindow: NSWindow {
- var disableConstrainToScreen = false
-
- private let MIN_WINDOW_COORDINATE: CGFloat = -16000
-
- var windowImage: NSImage? {
- get {
- let frame = self.frame
- let visible = self.isVisible
- if visible == false {
- self.disableConstrainToScreen = true
- self.setFrameOrigin(NSMakePoint(MIN_WINDOW_COORDINATE, MIN_WINDOW_COORDINATE))
- self.orderBack(nil)
- self.displayIfNeeded()
- self.disableConstrainToScreen = false
- }
- let cgImage = CGWindowListCreateImage(CGRect.null, .optionIncludingWindow, CGWindowID(self.windowNumber), .boundsIgnoreFraming)
- if visible == false {
- self.orderOut(nil)
- self.setFrameOrigin(frame.origin)
- }
- if let data = cgImage {
- let image = NSImage(cgImage: data, size: frame.size)
- return image
- }
- return nil
- }
- }
-
- override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask, backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) {
- super.init(contentRect: contentRect, styleMask: style, backing: backingStoreType, defer: flag)
-
- self.standardWindowButton(.miniaturizeButton)?.isEnabled = true
- }
-
- override func miniaturize(_ sender: Any?) {
- (self.windowController as? KMSnapshotWindowController)?.miniaturize()
- }
-
- override func constrainFrameRect(_ frameRect: NSRect, to screen: NSScreen?) -> NSRect {
- if self.disableConstrainToScreen {
- return frameRect
- }
- return super.constrainFrameRect(frameRect, to: screen)
- }
- // - (id)_updateButtonsForModeChanged {
- // id rv = [super _updateButtonsForModeChanged];
- // [[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled:YES];
- // return rv;
- // }
- }
|