Skip to content

Commit

Permalink
Fix some marginal UI regressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Vaidyam committed Feb 15, 2018
1 parent 39334f5 commit 21b8fbc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
16 changes: 16 additions & 0 deletions MochaUI/NSAppearance+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ public class NSAntiVisualEffectView: NSVisualEffectView {
//
}
}

public extension CALayer {

/// Creates a `CALayer` that mirrors the given window ID (can either be within the same
/// app, or from another app entirely) into its contents. Note: this will only work if
/// the containing window hosts its layers in windowserver (`layerUsesCoreImageFilters=NO`).
public class func mirroring(windowID: CGWindowID, includesShadow: Bool = true, contentsGravity: String = kCAGravityResizeAspect) -> CALayer {
let clz = NSClassFromString("CAPluginLayer") as! CALayer.Type
let layer = clz.init()
layer.setValue("com.apple.WindowServer.CGSWindow", forKey: "pluginType")
layer.setValue(windowID, forKey: "pluginId")
layer.setValue(contentsGravity, forKey: "pluginGravity")
layer.setValue(includesShadow ? 0x0 : 0x4, forKey: "pluginFlags")
return layer
}
}
7 changes: 3 additions & 4 deletions MochaUI/NSWindow+Transforms.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import AppKit
import Mocha

/* TODO: Works in another sample project, but fails within Parrot? */

/*
DispatchQueue.main.async {
var perspective = CATransform3DIdentity
perspective.m34 = 1 / 70
perspective.m34 = 1 / 500
perspective = CATransform3DRotate(perspective, .pi * 0.4, 1, 0, 0)
window.transform = perspective
}
Expand All @@ -15,7 +13,7 @@ public extension NSWindow {
public var transform: CATransform3D {
get { return CATransform3DIdentity }
set {
let t = CATransform3DConcat(newValue, CATransform3DMakeScale(1, -1, 1))
let t = newValue//CATransform3DConcat(newValue, CATransform3DMakeScale(1, -1, 1))
let f = self.frame
let p = CGPoint(x: self.frame.minX, y: self.screen!.frame.height - self.frame.maxY)
let w = Float(f.width), h = Float(f.height)
Expand All @@ -30,6 +28,7 @@ public extension NSWindow {
global: CAMesh(CGSMeshPoint(x: w, y: h), f, p, t))

let warps = [bl, br, tl, tr]
print("\n\nSETTING WARPS \(warps)\n\n")
let ptr: UnsafeMutablePointer<CGSWarpPoint> = UnsafeMutablePointer(mutating: warps)
_ = ptr.withMemoryRebound(to: CGSWarpPoint.self, capacity: 4) {
CGSSetWindowWarp(NSApp.value(forKey: "contextID") as! Int32,
Expand Down
12 changes: 6 additions & 6 deletions Parrot/MessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class MessageCell: NSCollectionViewItem, NSTextViewDelegate {
v.isEditable = false
v.isSelectable = true
v.drawsBackground = false
v.backgroundColor = NSColor.clear
v.textColor = NSColor.labelColor
v.backgroundColor = .clear
v.textColor = .labelColor
v.textContainerInset = NSSize(width: 4, height: 4)

//v.setContentCompressionResistancePriority(1000, for: .vertical)
Expand Down Expand Up @@ -88,14 +88,15 @@ public class MessageCell: NSCollectionViewItem, NSTextViewDelegate {
//self.textLabel.alignment = (o.sender.me ?? false) ? .right : .left

// Enable automatic links and data detectors.
self.updateTextStyles()
self.textLabel.isEditable = true
self.textLabel.checkTextInDocument(nil)
self.textLabel.isEditable = false

let text = self.textLabel
let appearance: NSAppearance = self.view.appearance ?? NSAppearance.current
text.textColor = NSColor.labelColor
//self.setColors()
text.textColor = .labelColor
self.setColors()

// NSTextView doesn't automatically change its text color when the
// backing view's appearance changes, so we need to set it each time.
Expand Down Expand Up @@ -123,7 +124,6 @@ public class MessageCell: NSCollectionViewItem, NSTextViewDelegate {
NSAttributedStringKey.foregroundColor: NSColor.labelColor,
NSAttributedStringKey.underlineStyle: 0,
]
self.updateTextStyles()
}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ public class MessageCell: NSCollectionViewItem, NSTextViewDelegate {
}

public override func viewWillAppear() {
self.setColors()
//self.setColors()
}

/// Allows the circle crop and masking to dynamically change.
Expand Down
1 change: 0 additions & 1 deletion Parrot/MessageInputViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ public class MessageInputViewController: NSViewController, NSTextViewExtendedDel
} else {
text.appearance = self.view.effectiveAppearance//self.appearance
}
text.appearance = self.view.effectiveAppearance
text.layer?.backgroundColor = color.cgColor
}

Expand Down

0 comments on commit 21b8fbc

Please sign in to comment.