Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081import AppKitimport ParcelConfigimport ParcelCoreimport QuartzCore
/// Decorative feedback. Mouse ownership remains entirely with the existing edge gesture monitor;/// keyboard and assistive resizing remain available through configured size commands.@MainActorfinal class DividerHandleController { private(set) var panel: OverlayPanel? private(set) var identity: TileEdge.Identity? private(set) var line: CALayer? private(set) var edge: TileEdge?
func clear() { panel?.close() panel = nil identity = nil line = nil edge = nil }
isolated deinit { panel?.close() }
func update( _ edge: TileEdge?, displays: [OverlayDisplay], primaryHeight: CGFloat, configuration: MotionConfiguration, accessibility: OverlayAccessibility, paletteSource: OverlayPaletteSource, orderPanels: Bool ) { self.edge = edge let motion = OverlayMotion(configuration: configuration, accessibility: accessibility, geometry: false) guard let edge, let display = displays.first(where: { $0.id == edge.workspace.display.rawValue }), let frame = DividerHandleGeometry.frame( for: edge, scale: display.scale, increaseContrast: accessibility.increaseContrast) else { identity = nil setVisible(false, motion: motion) return } let appearing = identity != edge.identity if panel?.display.id != display.id { clear(); self.edge = edge } let panel = panel ?? OverlayPanel(display: display, primaryDisplayHeight: primaryHeight) self.panel = panel panel.update(display: display, primaryDisplayHeight: primaryHeight) let line = line ?? OverlayLayerAllocation.makeLayer() if self.line == nil { line.opacity = 0 panel.canvas.addSublayer(line) } self.line = line let palette = paletteSource.resolve(for: panel.effectiveAppearance, accessibility: accessibility) withoutImplicitAnimations { line.frame = display.localFrame(frame) line.cornerRadius = min(frame.width, frame.height) / 2 line.backgroundColor = palette.chipText line.contentsScale = display.scale } if appearing { setVisible(true, motion: motion) } if motion.behavior == .instant { line.removeAllAnimations() } identity = edge.identity if orderPanels, !panel.isVisible { panel.orderFrontRegardless() } }
private func setVisible(_ visible: Bool, motion: OverlayMotion) { guard let line else { return } let target: Float = visible ? 1 : 0 if motion.behavior == .instant { line.removeAllAnimations() } guard line.opacity != target else { return } let previous = line.presentation()?.opacity ?? line.opacity withoutImplicitAnimations { line.opacity = target } line.removeAnimation(forKey: "divider-visibility") guard case .fade(let duration) = motion.behavior else { return } let fade = CABasicAnimation(keyPath: "opacity") fade.fromValue = previous fade.toValue = target fade.duration = duration fade.timingFunction = CAMediaTimingFunction(name: .easeOut) line.add(fade, forKey: "divider-visibility") }}