Created
November 1, 2018 23:01
-
-
Save tmandry/87cbf7e181fc36fc24c8cae1ebf55a85 to your computer and use it in GitHub Desktop.
Creating window borders for a WM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win: NSWindow! | |
func makeWindow() { | |
let rect = NSRect(x: 1000, y: 1000, width: 400, height: 300) | |
win = NSWindow(contentRect: rect, styleMask: .borderless, backing: .buffered, defer: false) | |
win.center() | |
win.level = .floating | |
win.hasShadow = false | |
win.backgroundColor = NSColor.clear | |
win.animationBehavior = .none | |
win.ignoresMouseEvents = true | |
win.isOpaque = false // doesn't seem needed, might hurt performance | |
win.makeKeyAndOrderFront(nil) | |
win.title = "HEY" | |
win.contentView = Border(frame: NSRect(x: 0, y: 0, width: 400, height: 300)) | |
print(win.isVisible) | |
} | |
class Border: NSView { | |
let thickness: CGFloat = 5 | |
override func draw(_ dirtyRect: NSRect) { | |
let rect = NSInsetRect(frame, thickness, thickness) | |
let border = NSBezierPath(roundedRect: rect, xRadius: thickness, yRadius: thickness) | |
border.lineWidth = thickness | |
border.stroke() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment