-
Notifications
You must be signed in to change notification settings - Fork 503
Add Floating Grid Layout #1604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MutatingFunc
wants to merge
9
commits into
ianyh:development
Choose a base branch
from
MutatingFunc:stage-manager
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Floating Grid Layout #1604
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0a34b90
Add Stage Manager layout
MutatingFunc bb4b8b0
Allow reflow on window drag
MutatingFunc 05d310f
Respect Amethyst settings
MutatingFunc 9038fd5
Prepare for PR - blend with Amethyst naming
MutatingFunc 2f0cda8
Use a more suitable sort order
MutatingFunc 2270392
Improve approach to detecting window resize
MutatingFunc 8ca247a
Reorder guard conditions to allow FloatingGridLayout to bypass mouseR…
MutatingFunc ba86ba2
Add handler for window move
MutatingFunc f6b4de8
Generalise window resize event
MutatingFunc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// FloatingGridLayout.swift | ||
// Amethyst | ||
// | ||
// Created by James Froggatt on 31/10/23. | ||
// Copyright © 2015 Ian Ynda-Hummel. All rights reserved. | ||
// | ||
|
||
import Silica | ||
|
||
class FloatingGridLayout<Window: WindowType>: Layout<Window> { | ||
override static var layoutName: String { return "Floating Grid" } | ||
override static var layoutKey: String { return "floating-grid" } | ||
|
||
override var layoutDescription: String { return "" } | ||
|
||
override func frameAssignments(_ windowSet: WindowSet<Window>, on screen: Screen) -> [FrameAssignmentOperation<Window>]? { | ||
let screenFrame = screen.adjustedFrame() | ||
let smartWindowMargins = UserConfiguration.shared.smartWindowMargins() | ||
let windowMarginSize = UserConfiguration.shared.windowMarginSize() | ||
let gridGuides = ( | ||
horizontal: self.gridGuides(in: screenFrame.width, from: screenFrame.minX), | ||
vertical: self.gridGuides(in: screenFrame.height, from: screenFrame.minY) | ||
) | ||
return windowSet.windows.map { window in | ||
let frameInset: CGFloat = windowMarginSize/2 | ||
var frame = window.frame.insetBy(dx: -frameInset, dy: -frameInset) | ||
// Limit windows to screen bounds | ||
// 1. Pull window up left onto screen | ||
if frame.maxX > screenFrame.maxX { | ||
frame.origin.x += screenFrame.maxX - frame.maxX | ||
} | ||
if frame.maxY > screenFrame.maxY { | ||
frame.origin.y += screenFrame.maxY - frame.maxY | ||
} | ||
// 2. Push window down right onto screen | ||
if frame.minX < screenFrame.minX { | ||
frame.origin.x = screenFrame.minX | ||
} | ||
if frame.minY < screenFrame.minY { | ||
frame.origin.y = screenFrame.minY | ||
} | ||
// 3. Trim window's bottom right | ||
if frame.maxX > screenFrame.maxX { | ||
frame.size.width += screenFrame.maxX - frame.maxX | ||
} | ||
if frame.maxY > screenFrame.maxY { | ||
frame.origin.y += screenFrame.maxY - frame.maxY | ||
} | ||
// Align to grid | ||
let oldX = frame.minX | ||
let oldY = frame.minY | ||
frame.origin.x = match(frame.minX, to: gridGuides.horizontal, leadingEdge: true) | ||
frame.origin.y = match(frame.minY, to: gridGuides.vertical, leadingEdge: true) | ||
frame.size.width += oldX - frame.origin.x | ||
frame.size.height += oldY - frame.origin.y | ||
frame.size.width = match(frame.maxX, to: gridGuides.horizontal, leadingEdge: false) - frame.minX | ||
frame.size.height = match(frame.maxY, to: gridGuides.vertical, leadingEdge: false) - frame.minY | ||
|
||
let isFullscreen = smartWindowMargins && frame.union(screenFrame) == frame | ||
|
||
let resizeRules = ResizeRules(isMain: true, unconstrainedDimension: .horizontal, scaleFactor: 1) | ||
let frameAssignment = FrameAssignment<Window>( | ||
frame: isFullscreen ? screen.adjustedFrame(disableWindowMargins: true) : frame, | ||
window: window, | ||
screenFrame: isFullscreen ? screen.adjustedFrame(disableWindowMargins: true) : screenFrame, | ||
resizeRules: resizeRules, | ||
disableWindowMargins: isFullscreen | ||
) | ||
return FrameAssignmentOperation(frameAssignment: frameAssignment, windowSet: windowSet) | ||
} | ||
} | ||
|
||
func gridGuides(in dimension: CGFloat, from origin: CGFloat) -> [CGFloat] { | ||
let baseGridSize: CGFloat = 64 | ||
let points = Int(dimension / baseGridSize) | ||
let gridItemSize = dimension / CGFloat(points) | ||
return (0...points).map { CGFloat($0) * gridItemSize + origin } | ||
} | ||
|
||
func match(_ value: CGFloat, to guides: [CGFloat], leadingEdge: Bool) -> CGFloat { | ||
var guides = guides | ||
// Prevent offscreen snapping | ||
if leadingEdge { | ||
guides.removeLast() | ||
} else { | ||
guides.removeFirst() | ||
} | ||
// Make it easier to snap to screen edges and avoid stage manager sidebar | ||
if guides.indices.count > 2 { | ||
guides.remove(at: 1) | ||
guides.remove(at: guides.endIndex-2) | ||
} | ||
// Find closest snap guide | ||
let index = guides.firstIndex(where: { $0 >= value }) ?? guides.indices.last! | ||
let previous = guides.indices.contains(index-1) ? guides[index-1] : guides.first! | ||
let next = guides.indices.contains(index) ? guides[index] : guides.last! | ||
if (value - previous) > (next - value) { | ||
return next | ||
} else { | ||
return previous | ||
} | ||
} | ||
} | ||
|
||
// To ensure updates when resizing | ||
extension FloatingGridLayout: PanedLayout { | ||
var mainPaneRatio: CGFloat { 0.5 } | ||
var mainPaneCount: Int { 1 } | ||
func recommendMainPaneRawRatio(rawRatio: CGFloat) {} | ||
func increaseMainPaneCount() {} | ||
func decreaseMainPaneCount() {} | ||
|
||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert these?