Skip to content

Commit

Permalink
Rename normalization flags
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Oct 24, 2023
1 parent 4a038ab commit fd704c9
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions config-examples/default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
after-login-command = [] # You can use it to add command or commands that run after login to macOS user session.
after-startup-command = [] # You can use it to add command or commands that run after startup.
indent-for-nested-containers-with-the-same-orientation = 30
auto-flatten-containers = true
auto-opposite-orientation-for-nested-containers = true
enable-normalization-flatten-containers = true
enable-normalization-opposite-orientation-for-nested-containers = true
start-at-login = false
floating-windows-on-top = true
main-layout = 'h_list' # todo change
Expand Down
4 changes: 2 additions & 2 deletions config-examples/i3-like-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# todo finish

auto-flatten-containers = false
auto-opposite-orientation-for-nested-containers = false
enable-normalization-flatten-containers = false
enable-normalization-opposite-orientation-for-nested-containers = false

[mode.main.binding]
alt-enter = 'exec-and-forget open /System/Applications/Utilities/Terminal.app'
Expand Down
2 changes: 1 addition & 1 deletion src/command/LayoutCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct LayoutCommand: Command {
switch window.parent.kind {
case .tilingContainer(let parent):
parent.layout = targetLayout?.simpleLayout ?? errorT("TODO")
if config.autoOppositeOrientationForNestedContainers {
if config.enableNormalizationOppositeOrientationForNestedContainers {
var orientation = targetLayout?.orientation ?? errorT("TODO")
parent.parentsWithSelf
.prefix(while: { $0 is TilingContainer })
Expand Down
4 changes: 2 additions & 2 deletions src/config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ struct Config {
var afterStartupCommand: Command
var afterLoginCommand: Command
var indentForNestedContainersWithTheSameOrientation: Int
var autoFlattenContainers: Bool
var enableNormalizationFlattenContainers: Bool
var floatingWindowsOnTop: Bool
var mainLayout: ConfigLayout // todo rename to defaultLayout
var debugAllWindowsAreFloating: Bool
var startAtLogin: Bool
var accordionPadding: Int
var autoOppositeOrientationForNestedContainers: Bool
var enableNormalizationOppositeOrientationForNestedContainers: Bool

let modes: [String: Mode]
var preservedWorkspaceNames: [String]
Expand Down
8 changes: 4 additions & 4 deletions src/config/parseConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func parseConfig(_ rawToml: String) -> ParsedTomlWriter<Config> {
let key2 = "indent-for-nested-containers-with-the-same-orientation"
var value2: Int? = nil

let key3 = "auto-flatten-containers"
let key3 = "enable-normalization-flatten-containers"
var value3: Bool? = nil

let key4 = "floating-windows-on-top"
Expand All @@ -112,7 +112,7 @@ func parseConfig(_ rawToml: String) -> ParsedTomlWriter<Config> {
let key12 = "accordion-padding"
var value12: Int? = nil

let key13 = "auto-opposite-orientation-for-nested-containers"
let key13 = "enable-normalization-opposite-orientation-for-nested-containers"
var value13: Bool? = nil

for (key, value) in rawTable {
Expand Down Expand Up @@ -151,13 +151,13 @@ func parseConfig(_ rawToml: String) -> ParsedTomlWriter<Config> {
afterStartupCommand: value1 ?? defaultConfig.afterStartupCommand,
afterLoginCommand: value9 ?? defaultConfig.afterLoginCommand,
indentForNestedContainersWithTheSameOrientation: value2 ?? defaultConfig.indentForNestedContainersWithTheSameOrientation,
autoFlattenContainers: value3 ?? defaultConfig.autoFlattenContainers,
enableNormalizationFlattenContainers: value3 ?? defaultConfig.enableNormalizationFlattenContainers,
floatingWindowsOnTop: value4 ?? defaultConfig.floatingWindowsOnTop,
mainLayout: value5 ?? defaultConfig.mainLayout,
debugAllWindowsAreFloating: value7 ?? defaultConfig.debugAllWindowsAreFloating,
startAtLogin: value8 ?? defaultConfig.startAtLogin,
accordionPadding: value12 ?? defaultConfig.accordionPadding,
autoOppositeOrientationForNestedContainers: value13 ?? defaultConfig.autoOppositeOrientationForNestedContainers,
enableNormalizationOppositeOrientationForNestedContainers: value13 ?? defaultConfig.enableNormalizationOppositeOrientationForNestedContainers,

modes: modesOrDefault,
preservedWorkspaceNames: modesOrDefault.values.lazy
Expand Down
4 changes: 2 additions & 2 deletions src/tree/normalizeContainers.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
extension Workspace {
func normalizeContainers() {
rootTilingContainer.unbindEmptyAndAutoFlatten() // Beware! rootTilingContainer may change after this line of code
if config.autoOppositeOrientationForNestedContainers {
if config.enableNormalizationOppositeOrientationForNestedContainers {
rootTilingContainer.normalizeOppositeOrientationForNestedContainers()
}
}
}

private extension TilingContainer {
func unbindEmptyAndAutoFlatten() {
if let child = children.singleOrNil(), config.autoFlattenContainers && (child is TilingContainer || !isRootContainer) {
if let child = children.singleOrNil(), config.enableNormalizationFlattenContainers && (child is TilingContainer || !isRootContainer) {
child.unbindFromParent()
let previousBinding = unbindFromParent()
child.bindTo(parent: previousBinding.parent, adaptiveWeight: previousBinding.adaptiveWeight, index: previousBinding.index)
Expand Down
10 changes: 5 additions & 5 deletions test/config/ConfigTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class ConfigTest: XCTestCase {
let toml = try! String(contentsOf: projectRoot.appending(component: "config-examples/i3-like-config-example.toml"))
let (i3Config, errors) = parseConfig(toml).toTuple()
XCTAssertEqual(errors.descriptions, [])
XCTAssertEqual(i3Config.autoFlattenContainers, false)
XCTAssertEqual(i3Config.enableNormalizationFlattenContainers, false)
}

func testParseMode() {
Expand Down Expand Up @@ -75,25 +75,25 @@ final class ConfigTest: XCTestCase {
let (config, errors) = parseConfig(
"""
unknownKey = true
auto-flatten-containers = false
enable-normalization-flatten-containers = false
"""
).toTuple()
XCTAssertEqual(
errors.descriptions,
["unknownKey: Unknown key"]
)
XCTAssertEqual(config.autoFlattenContainers, false)
XCTAssertEqual(config.enableNormalizationFlattenContainers, false)
}

func testTypeMismatch() {
let errors = parseConfig(
"""
auto-flatten-containers = 'true'
enable-normalization-flatten-containers = 'true'
"""
).log
XCTAssertEqual(
errors.descriptions,
["auto-flatten-containers: Expected type is \'bool\'. But actual type is \'string\'"]
["enable-normalization-flatten-containers: Expected type is \'bool\'. But actual type is \'string\'"]
)
}

Expand Down
4 changes: 2 additions & 2 deletions test/testUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ func setUpWorkspacesForTests() {
afterStartupCommand: defaultConfig.afterStartupCommand,
afterLoginCommand: defaultConfig.afterLoginCommand,
indentForNestedContainersWithTheSameOrientation: defaultConfig.indentForNestedContainersWithTheSameOrientation,
autoFlattenContainers: false, // Make layout tests more predictable
enableNormalizationFlattenContainers: false, // Make layout tests more predictable
floatingWindowsOnTop: defaultConfig.floatingWindowsOnTop,
mainLayout: .h_list, // Make default layout predictable
debugAllWindowsAreFloating: defaultConfig.debugAllWindowsAreFloating,
startAtLogin: defaultConfig.startAtLogin,
accordionPadding: defaultConfig.accordionPadding,
autoOppositeOrientationForNestedContainers: false, // Make layout tests more predictable
enableNormalizationOppositeOrientationForNestedContainers: false, // Make layout tests more predictable

// Don't create any workspaces for tests
modes: [mainModeId: Mode(name: nil, bindings: [])],
Expand Down
6 changes: 3 additions & 3 deletions test/tree/TreeNodeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ final class TreeNodeTest: XCTestCase {
}
test()

config.autoFlattenContainers = true
config.enableNormalizationFlattenContainers = true
test()
}

func testNormalizeContainers_singleWindowChild() {
config.autoFlattenContainers = true
config.enableNormalizationFlattenContainers = true
let workspace = Workspace.get(byName: name)
workspace.rootTilingContainer.apply {
TestWindow(id: 0, parent: $0)
Expand Down Expand Up @@ -81,7 +81,7 @@ final class TreeNodeTest: XCTestCase {
workspace.normalizeContainers()
XCTAssertTrue(workspace.rootTilingContainer.children.singleOrNil() is TilingContainer)

config.autoFlattenContainers = true
config.enableNormalizationFlattenContainers = true
workspace.normalizeContainers()
XCTAssertTrue(workspace.rootTilingContainer.children.singleOrNil() is TestWindow)
}
Expand Down

0 comments on commit fd704c9

Please sign in to comment.