Skip to content

Commit

Permalink
WIP: config
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Sep 13, 2023
1 parent 0cb6ea0 commit 025fefe
Show file tree
Hide file tree
Showing 13 changed files with 388 additions and 51 deletions.
6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 22 additions & 10 deletions AeroSpace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
/* Begin PBXBuildFile section */
07FF7938628995F68DFEB524 /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24F99E8C4FD17A1D939C41F1 /* ViewModel.swift */; };
080DAA83BADA766D94A2BD3C /* Workspace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38A4C333EA5B4D4527DD97D4 /* Workspace.swift */; };
082EECCB2607F31DCBBF3870 /* defaultConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA7CD89E786588324DFB5575 /* defaultConfig.swift */; };
115F5CA4BEB80B645E66D198 /* NSScreenEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF3BB3DD434C75536217CB88 /* NSScreenEx.swift */; };
1C46EBB55D401C0D1AFD50F0 /* CollectionEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51CE37C1B8D858C81A396F40 /* CollectionEx.swift */; };
1CB4082BE5C95CA8CD52BED9 /* Maybe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345148B22F8A8F85109229AE /* Maybe.swift */; };
2F8DC074DAB97DC87E07A559 /* Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9CAC977020A08D0227FAFB2 /* Bundle.swift */; };
4005ECE237BD9230F74CA917 /* TreeNodeEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C39B0C4E4888832129C4C7 /* TreeNodeEx.swift */; };
Expand All @@ -18,7 +20,6 @@
64A058E536F1EEF7F01043AF /* TOMLKit in Frameworks */ = {isa = PBXBuildFile; productRef = EC8E4F2CA4FF8884F9F59975 /* TOMLKit */; };
66E6CDA75DDD5E4B9647EDE2 /* AeroSpaceApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E81623E8954701269A22322 /* AeroSpaceApp.swift */; };
6820E6846AE51B6988B6F673 /* utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD02433B4415EEB163074CE5 /* utils.swift */; };
7035674CE8D4D0D5D43FAD95 /* Toml.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB0A5C2842534F121A0C430 /* Toml.swift */; };
783B0B965BA45D7A2943F7BF /* TilingContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E05FB0C7158C8B6DECBD603 /* TilingContainer.swift */; };
78EE0CEF814ABDBA67941B84 /* Rect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28B788A95DD3C267878E05B5 /* Rect.swift */; };
7FE92DDAC2F094C83A177914 /* MacApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6296D5F9AFE5F266EE4B1D0 /* MacApp.swift */; };
Expand All @@ -32,7 +33,9 @@
B1E2002BB8F70F2555AAA82D /* TreeNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D295CA45172ADBDB1E4DF708 /* TreeNode.swift */; };
B3702BB393A9B03CCAE4C60E /* refresh.swift in Sources */ = {isa = PBXBuildFile; fileRef = 526B113159987FA43EA41120 /* refresh.swift */; };
C0A88261ECF505FC5648FC0A /* OptionalEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EDFD4A9F45182CA6E0BD7B /* OptionalEx.swift */; };
C39C2054893A6506C35732D7 /* config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651C5EE18862C252795811B3 /* config.swift */; };
E2FD8E2B2D2BE6B88BF8E8AD /* accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE605CF46DE6377C69B9D49D /* accessibility.swift */; };
F2AFA702961A1D653EB7D269 /* command.swift in Sources */ = {isa = PBXBuildFile; fileRef = 776E3F4EE298A9C69C97EF7F /* command.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -45,13 +48,17 @@
38A4C333EA5B4D4527DD97D4 /* Workspace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Workspace.swift; sourceTree = "<group>"; };
3C2E5977331398421A4FC168 /* GlobalObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalObserver.swift; sourceTree = "<group>"; };
3E05FB0C7158C8B6DECBD603 /* TilingContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TilingContainer.swift; sourceTree = "<group>"; };
51CE37C1B8D858C81A396F40 /* CollectionEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionEx.swift; sourceTree = "<group>"; };
526B113159987FA43EA41120 /* refresh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = refresh.swift; sourceTree = "<group>"; };
651C5EE18862C252795811B3 /* config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = config.swift; sourceTree = "<group>"; };
6935AF0A2DB3D186D1C6218F /* NSWorkspaceEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSWorkspaceEx.swift; sourceTree = "<group>"; };
776E3F4EE298A9C69C97EF7F /* command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = command.swift; sourceTree = "<group>"; };
7E6F3930E3BF5D8196A20E9B /* axObservers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = axObservers.swift; sourceTree = "<group>"; };
883D7F7F87FBE7D0BDE4E87F /* ArrayEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrayEx.swift; sourceTree = "<group>"; };
A9EDFD4A9F45182CA6E0BD7B /* OptionalEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalEx.swift; sourceTree = "<group>"; };
AAE5DCAEC5EE619CE33859E7 /* SequenceEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SequenceEx.swift; sourceTree = "<group>"; };
AF3BB3DD434C75536217CB88 /* NSScreenEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSScreenEx.swift; sourceTree = "<group>"; };
BA7CD89E786588324DFB5575 /* defaultConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = defaultConfig.swift; sourceTree = "<group>"; };
BD02433B4415EEB163074CE5 /* utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = utils.swift; sourceTree = "<group>"; };
BEF353340822CD20E9DAB3EC /* AeroSpace.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AeroSpace.entitlements; sourceTree = "<group>"; };
D295CA45172ADBDB1E4DF708 /* TreeNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TreeNode.swift; sourceTree = "<group>"; };
Expand All @@ -62,7 +69,6 @@
F6507EBAA795220FD0C05384 /* Monitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Monitor.swift; sourceTree = "<group>"; };
F8C39B0C4E4888832129C4C7 /* TreeNodeEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TreeNodeEx.swift; sourceTree = "<group>"; };
F9CAC977020A08D0227FAFB2 /* Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = "<group>"; };
FDB0A5C2842534F121A0C430 /* Toml.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toml.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -97,20 +103,22 @@
);
sourceTree = "<group>";
};
62BEA6F49E6648E2EE3C208F /* Products */ = {
50A41C4CCFC95C514CA1EAD5 /* config */ = {
isa = PBXGroup;
children = (
09685297933511208058F7CF /* AeroSpace.app */,
776E3F4EE298A9C69C97EF7F /* command.swift */,
651C5EE18862C252795811B3 /* config.swift */,
BA7CD89E786588324DFB5575 /* defaultConfig.swift */,
);
name = Products;
path = config;
sourceTree = "<group>";
};
80F16ED76205CA1AC4E0BF3E /* settings */ = {
62BEA6F49E6648E2EE3C208F /* Products */ = {
isa = PBXGroup;
children = (
FDB0A5C2842534F121A0C430 /* Toml.swift */,
09685297933511208058F7CF /* AeroSpace.app */,
);
path = settings;
name = Products;
sourceTree = "<group>";
};
8338180CE208CBDCD6D8E911 /* src */ = {
Expand All @@ -126,8 +134,8 @@
526B113159987FA43EA41120 /* refresh.swift */,
24F99E8C4FD17A1D939C41F1 /* ViewModel.swift */,
89B36C927EF9F6CB9CE830C7 /* axWrappers */,
50A41C4CCFC95C514CA1EAD5 /* config */,
38E5F06C862662755065FF1D /* model */,
80F16ED76205CA1AC4E0BF3E /* settings */,
C136937AA077E63558E9707C /* util */,
);
path = src;
Expand All @@ -147,6 +155,7 @@
isa = PBXGroup;
children = (
883D7F7F87FBE7D0BDE4E87F /* ArrayEx.swift */,
51CE37C1B8D858C81A396F40 /* CollectionEx.swift */,
345148B22F8A8F85109229AE /* Maybe.swift */,
F6507EBAA795220FD0C05384 /* Monitor.swift */,
AF3BB3DD434C75536217CB88 /* NSScreenEx.swift */,
Expand Down Expand Up @@ -237,6 +246,7 @@
66E6CDA75DDD5E4B9647EDE2 /* AeroSpaceApp.swift in Sources */,
A2CBF9674964F9083BB198D2 /* ArrayEx.swift in Sources */,
2F8DC074DAB97DC87E07A559 /* Bundle.swift in Sources */,
1C46EBB55D401C0D1AFD50F0 /* CollectionEx.swift in Sources */,
B0D0C37BAE7E7F0D0FF1E9FC /* GlobalObserver.swift in Sources */,
7FE92DDAC2F094C83A177914 /* MacApp.swift in Sources */,
518B9E5AC031C24C7C84CD70 /* MacWindow.swift in Sources */,
Expand All @@ -248,13 +258,15 @@
78EE0CEF814ABDBA67941B84 /* Rect.swift in Sources */,
AE76A183D0454E4C8ADCE380 /* SequenceEx.swift in Sources */,
783B0B965BA45D7A2943F7BF /* TilingContainer.swift in Sources */,
7035674CE8D4D0D5D43FAD95 /* Toml.swift in Sources */,
B1E2002BB8F70F2555AAA82D /* TreeNode.swift in Sources */,
4005ECE237BD9230F74CA917 /* TreeNodeEx.swift in Sources */,
07FF7938628995F68DFEB524 /* ViewModel.swift in Sources */,
080DAA83BADA766D94A2BD3C /* Workspace.swift in Sources */,
E2FD8E2B2D2BE6B88BF8E8AD /* accessibility.swift in Sources */,
96593DF93A69CA2E05189A3F /* axObservers.swift in Sources */,
F2AFA702961A1D653EB7D269 /* command.swift in Sources */,
C39C2054893A6506C35732D7 /* config.swift in Sources */,
082EECCB2607F31DCBBF3870 /* defaultConfig.swift in Sources */,
B3702BB393A9B03CCAE4C60E /* refresh.swift in Sources */,
6820E6846AE51B6988B6F673 /* utils.swift in Sources */,
);
Expand Down
38 changes: 25 additions & 13 deletions src/AeroSpaceApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,29 @@ struct Setting {
let modifiers: NSEvent.ModifierFlags
}

//osascript -e 'tell app "Terminal"
//activate
//do script "tail -f ~/log/0.txt"
//end tell'

@main
struct AeroSpaceApp: App {
var hotKeys: [HotKey] = [] // Keep hotkeys in memory
@StateObject var viewModel = ViewModel.shared

init() {
checkAccessibilityPermissions()
GlobalObserver.initObserver()
for setting in settings {
hotKeys.append(HotKey(key: setting.hotkey, modifiers: setting.modifiers, keyUpHandler: {
switchToWorkspace(Workspace.get(byName: setting.name))
}))
}
refresh()
test()
reloadConfig()

//checkAccessibilityPermissions()
//GlobalObserver.initObserver()
//for setting in settings {
// hotKeys.append(HotKey(key: setting.hotkey, modifiers: setting.modifiers, keyUpHandler: {
// switchToWorkspace(Workspace.get(byName: setting.name))
// }))
//}
//refresh()
//test()

}

var body: some Scene {
Expand All @@ -44,16 +52,20 @@ struct AeroSpaceApp: App {
switchToWorkspace(workspace)
} label: {
Toggle(isOn: workspace.name == viewModel.focusedWorkspaceTrayText
? Binding(get: { true }, set: { _, _ in })
: Binding(get: { false }, set: { _, _ in })) {
? Binding(get: { true }, set: { _, _ in })
: Binding(get: { false }, set: { _, _ in })) {
let monitor = (workspace.assignedMonitor?.name).flatMap { " - \($0)" } ?? ""
Text(workspace.name + monitor).font(.system(.body, design: .monospaced))
}
}
}
Divider()
Button("Quit \(Bundle.appName)") { NSApplication.shared.terminate(nil) }
.keyboardShortcut("Q", modifiers: .command)
Button("Reload config") {
} // todo
Button("Quit \(Bundle.appName)") {
NSApplication.shared.terminate(nil)
}
.keyboardShortcut("Q", modifiers: .command)
} label: {
// .font(.system(.body, design: .monospaced)) doesn't work unfortunately :(
Text(viewModel.focusedWorkspaceTrayText)
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class ViewModel: ObservableObject {
private init() {
}

@Published var focusedWorkspaceTrayText: String = currentEmptyWorkspace.name // settings.first?.name ?? "W: 1"
@Published var focusedWorkspaceTrayText: String = currentEmptyWorkspace.name // config.first?.name ?? "W: 1"
}

77 changes: 77 additions & 0 deletions src/config/command.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import Foundation

protocol Command {
func run()
}

struct ChainedCommand: Command {
let subCommands: [Command]

func run() {
for command in subCommands {
command.run()
}
}
}

enum NoOpCommand: Command {
case instance

func run() {} // It does nothing
}

struct WorkspaceCommand : Command {
let workspaceName: String

func run() {
switchToWorkspace(Workspace.get(byName: workspaceName))
}
}

struct ModeCommand: Command {
let idToActivate: String

func run() {
for mode in config.modes {
for binding in mode.bindings {
if mode.id == idToActivate {
binding.activate()
} else {
binding.deactivate()
}
}
}
}
}

struct BashCommand: Command {
let bashCommand: String

func run() {
do {
try Process.run(URL(filePath: "/bin/bash"), arguments: ["-c", bashCommand])
} catch {
}
}
}

struct FocusCommand: Command {
let direction: Direction

enum Direction {
case up
case down
case left
case right

case parent
case child
case floating
case tiling
case toggle_tiling_floating
}

func run() {
// todo
}
}
Loading

0 comments on commit 025fefe

Please sign in to comment.