-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft implementation for layout command
- Loading branch information
1 parent
73647e4
commit 5180eb8
Showing
5 changed files
with
77 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,69 @@ | ||
/// Syntax: | ||
/// layout (main|h_accordion|v_accordion|h_list|v_list|floating|tiling)... | ||
struct LayoutCommand: Command { | ||
let toggleTo: [Layout] | ||
enum Layout { | ||
case main | ||
case h_accordion | ||
case v_accordion | ||
case h_list | ||
case v_list | ||
case floating | ||
let toggleBetween: [Layout] | ||
enum Layout: String { | ||
//case main // todo drop? | ||
case h_accordion, v_accordion, h_list, v_list | ||
case floating, tiling | ||
} | ||
|
||
init?(toggleBetween: [Layout]) { | ||
if toggleBetween.isEmpty { | ||
return nil | ||
} | ||
self.toggleBetween = toggleBetween | ||
} | ||
|
||
func run() async { | ||
precondition(Thread.current.isMainThread) | ||
// todo | ||
guard let window = focusedWindow ?? Workspace.focused.mruWindows.mostRecent else { return } | ||
let targetLayout = toggleBetween.firstIndex(of: window.verboseLayout) | ||
.flatMap { toggleBetween.getOrNil(atIndex: $0 + 1) } ?? toggleBetween.first | ||
if let parent = window.parent as? TilingContainer { | ||
parent.layout = targetLayout?.simpleLayout ?? errorT("TODO") | ||
parent.orientation = targetLayout?.orientation ?? errorT("TODO") | ||
refresh() | ||
} else { | ||
precondition(window.parent is Workspace) | ||
// todo | ||
} | ||
} | ||
} | ||
|
||
private extension LayoutCommand.Layout { | ||
var simpleLayout: Layout? { | ||
switch self { | ||
case .h_accordion, .v_accordion: | ||
return .Accordion | ||
case .h_list, .v_list: | ||
return .List | ||
case .floating, .tiling: | ||
return nil | ||
} | ||
} | ||
|
||
var orientation: Orientation? { | ||
switch self { | ||
case .h_accordion, .h_list: | ||
return .H | ||
case .v_accordion, .v_list: | ||
return .V | ||
case .floating, .tiling: | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
private extension MacWindow { | ||
var verboseLayout: LayoutCommand.Layout { | ||
(parent as? TilingContainer).flatMap { | ||
switch $0.layout { | ||
case .List: | ||
return $0.orientation == .H ? .h_list : .v_list | ||
case .Accordion: | ||
return $0.orientation == .H ? .h_accordion : .v_accordion | ||
} | ||
} ?? .floating | ||
} | ||
} |
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
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