Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to snap 2 windows side-by-side(split view) programmatically

Tags:

macos

swift

cocoa

NSWorkspace does not have any support for this. I tried with Accessibility, but still couldn't find anything useful.

I was thinking about AppleScript, but can't find anything helpful too.

I need exactly this effect Use two Mac apps side by side in Split View

Have you any idea how can I achieve that?

like image 831
Rajmund Zawiślak Avatar asked Oct 09 '17 08:10

Rajmund Zawiślak


1 Answers

I managed to find a very helpful presentation available here from WWDC 2015. (The link will download the presentation as a PDF)

See the section on Metrics and NSSplitView - 2nd half (Slide 130 or so)

You'll find some useful code pertaining to the NSSplitViewItem class. This will do (I think) what you're looking to do. I looked and wasn't able to find many examples other than these.

It looks like NSSplitViewuses multiple NSView objects to arrange them in "Full Screen Order". The first few slides of the presentation, show how to make an app Fullscreen capable.

Example :

// Add View
class NSView {
     var subviews: [NSView]
     func addSubview(NSView)
     func addSubview(NSView, positioned: NSWindowOrderingMode, relativeTo: NSView?)
     func removeFromSuperview()
}
// Create SplitView
class NSSplitView {
    var arrangedSubviews: [NSView]
    func addArrangedSubview(NSView)
    func insertArrangedSubview(NSView, atIndex: NSInteger)
    func removeArrangedSubview(NSView)
    var arrangesAllSubviews: Bool
}
like image 196
KSigWyatt Avatar answered Sep 28 '22 04:09

KSigWyatt