└── workspacer.config.csx /workspacer.config.csx: -------------------------------------------------------------------------------- 1 | // Development 2 | // #r "C:\Users\dalyisaac\Repos\workspacer\src\workspacer.Shared\bin\Debug\net5.0-windows\win10-x64\workspacer.Shared.dll" 3 | // #r "C:\Users\dalyisaac\Repos\workspacer\src\workspacer.Bar\bin\Debug\net5.0-windows\win10-x64\workspacer.Bar.dll" 4 | // #r "C:\Users\dalyisaac\Repos\workspacer\src\workspacer.Gap\bin\Debug\net5.0-windows\win10-x64\workspacer.Gap.dll" 5 | // #r "C:\Users\dalyisaac\Repos\workspacer\src\workspacer.ActionMenu\bin\Debug\net5.0-windows\win10-x64\workspacer.ActionMenu.dll" 6 | // #r "C:\Users\dalyisaac\Repos\workspacer\src\workspacer.FocusIndicator\bin\Debug\net5.0-windows\win10-x64\workspacer.FocusIndicator.dll" 7 | 8 | 9 | // Production 10 | #r "C:\Program Files\workspacer\workspacer.Shared.dll" 11 | #r "C:\Program Files\workspacer\plugins\workspacer.Bar\workspacer.Bar.dll" 12 | #r "C:\Program Files\workspacer\plugins\workspacer.Gap\workspacer.Gap.dll" 13 | #r "C:\Program Files\workspacer\plugins\workspacer.ActionMenu\workspacer.ActionMenu.dll" 14 | #r "C:\Program Files\workspacer\plugins\workspacer.FocusIndicator\workspacer.FocusIndicator.dll" 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using workspacer; 20 | using workspacer.Bar; 21 | using workspacer.Bar.Widgets; 22 | using workspacer.Gap; 23 | using workspacer.ActionMenu; 24 | using workspacer.FocusIndicator; 25 | 26 | return new Action((IConfigContext context) => 27 | { 28 | /* Variables */ 29 | var fontSize = 9; 30 | var barHeight = 19; 31 | var fontName = "Cascadia Code PL"; 32 | var background = new Color(0x0, 0x0, 0x0); 33 | 34 | /* Config */ 35 | context.CanMinimizeWindows = true; 36 | 37 | /* Gap */ 38 | var gap = barHeight - 8; 39 | var gapPlugin = context.AddGap(new GapPluginConfig() { InnerGap = gap, OuterGap = gap / 2, Delta = gap / 2 }); 40 | 41 | /* Bar */ 42 | context.AddBar(new BarPluginConfig() 43 | { 44 | FontSize = fontSize, 45 | BarHeight = barHeight, 46 | FontName = fontName, 47 | DefaultWidgetBackground = background, 48 | LeftWidgets = () => new IBarWidget[] 49 | { 50 | new WorkspaceWidget() 51 | }, 52 | RightWidgets = () => new IBarWidget[] 53 | { 54 | // new ActiveLayoutWidget(), 55 | // new BatteryWidget(), 56 | new TimeWidget(1000, "dd/MM/yyyy HH:mm:ss"), 57 | } 58 | }); 59 | 60 | /* Bar focus indicator */ 61 | context.AddFocusIndicator(); 62 | 63 | /* Default layouts */ 64 | Func defaultLayouts = () => new ILayoutEngine[] 65 | { 66 | new TallLayoutEngine(), 67 | new VertLayoutEngine(), 68 | new HorzLayoutEngine(), 69 | new FullLayoutEngine(), 70 | }; 71 | 72 | context.DefaultLayouts = defaultLayouts; 73 | 74 | /* Workspaces */ 75 | // Array of workspace names and their layouts 76 | (string, ILayoutEngine[])[] workspaces = 77 | { 78 | ("1", defaultLayouts()), 79 | ("2", defaultLayouts()), 80 | ("3", defaultLayouts()), 81 | ("music", defaultLayouts()), 82 | ("obs", defaultLayouts()), 83 | }; 84 | 85 | foreach ((string name, ILayoutEngine[] layouts) in workspaces) 86 | { 87 | context.WorkspaceContainer.CreateWorkspace(name, layouts); 88 | } 89 | 90 | /* Filters */ 91 | context.WindowRouter.AddFilter((window) => !window.ProcessFileName.Equals("1Password.exe")); 92 | context.WindowRouter.AddFilter((window) => !window.ProcessFileName.Equals("pinentry.exe")); 93 | 94 | // The following filter means that Edge will now open on the correct display 95 | context.WindowRouter.AddFilter((window) => !window.Class.Equals("ShellTrayWnd")); 96 | 97 | /* Routes */ 98 | context.WindowRouter.RouteProcessName("OBS", "obs"); 99 | 100 | /* Action menu */ 101 | var actionMenu = context.AddActionMenu(new ActionMenuPluginConfig() 102 | { 103 | RegisterKeybind = false, 104 | MenuHeight = barHeight, 105 | FontSize = fontSize, 106 | FontName = fontName, 107 | Background = background, 108 | }); 109 | 110 | /* Action menu builder */ 111 | Func createActionMenuBuilder = () => 112 | { 113 | var menuBuilder = actionMenu.Create(); 114 | 115 | // Switch to workspace 116 | menuBuilder.AddMenu("switch", () => 117 | { 118 | var workspaceMenu = actionMenu.Create(); 119 | var monitor = context.MonitorContainer.FocusedMonitor; 120 | var workspaces = context.WorkspaceContainer.GetWorkspaces(monitor); 121 | 122 | Func createChildMenu = (workspaceIndex) => () => 123 | { 124 | context.Workspaces.SwitchMonitorToWorkspace(monitor.Index, workspaceIndex); 125 | }; 126 | 127 | int workspaceIndex = 0; 128 | foreach (var workspace in workspaces) 129 | { 130 | workspaceMenu.Add(workspace.Name, createChildMenu(workspaceIndex)); 131 | workspaceIndex++; 132 | } 133 | 134 | return workspaceMenu; 135 | }); 136 | 137 | // Move window to workspace 138 | menuBuilder.AddMenu("move", () => 139 | { 140 | var moveMenu = actionMenu.Create(); 141 | var focusedWorkspace = context.Workspaces.FocusedWorkspace; 142 | 143 | var workspaces = context.WorkspaceContainer.GetWorkspaces(focusedWorkspace).ToArray(); 144 | Func createChildMenu = (index) => () => { context.Workspaces.MoveFocusedWindowToWorkspace(index); }; 145 | 146 | for (int i = 0; i < workspaces.Length; i++) 147 | { 148 | moveMenu.Add(workspaces[i].Name, createChildMenu(i)); 149 | } 150 | 151 | return moveMenu; 152 | }); 153 | 154 | // Rename workspace 155 | menuBuilder.AddFreeForm("rename", (name) => 156 | { 157 | context.Workspaces.FocusedWorkspace.Name = name; 158 | }); 159 | 160 | // Create workspace 161 | menuBuilder.AddFreeForm("create workspace", (name) => 162 | { 163 | context.WorkspaceContainer.CreateWorkspace(name); 164 | }); 165 | 166 | // Delete focused workspace 167 | menuBuilder.Add("close", () => 168 | { 169 | context.WorkspaceContainer.RemoveWorkspace(context.Workspaces.FocusedWorkspace); 170 | }); 171 | 172 | // Workspacer 173 | menuBuilder.Add("toggle keybind helper", () => context.Keybinds.ShowKeybindDialog()); 174 | menuBuilder.Add("toggle enabled", () => context.Enabled = !context.Enabled); 175 | menuBuilder.Add("restart", () => context.Restart()); 176 | menuBuilder.Add("quit", () => context.Quit()); 177 | 178 | return menuBuilder; 179 | }; 180 | var actionMenuBuilder = createActionMenuBuilder(); 181 | 182 | /* Keybindings */ 183 | Action setKeybindings = () => 184 | { 185 | KeyModifiers winShift = KeyModifiers.Win | KeyModifiers.Shift; 186 | KeyModifiers winCtrl = KeyModifiers.Win | KeyModifiers.Control; 187 | KeyModifiers win = KeyModifiers.Win; 188 | 189 | IKeybindManager manager = context.Keybinds; 190 | 191 | var workspaces = context.Workspaces; 192 | 193 | manager.UnsubscribeAll(); 194 | manager.Subscribe(MouseEvent.LButtonDown, () => workspaces.SwitchFocusedMonitorToMouseLocation()); 195 | 196 | // Left, Right keys 197 | manager.Subscribe(winCtrl, Keys.Left, () => workspaces.SwitchToPreviousWorkspace(), "switch to previous workspace"); 198 | manager.Subscribe(winCtrl, Keys.Right, () => workspaces.SwitchToNextWorkspace(), "switch to next workspace"); 199 | 200 | manager.Subscribe(winShift, Keys.Left, () => workspaces.MoveFocusedWindowToPreviousMonitor(), "move focused window to previous monitor"); 201 | manager.Subscribe(winShift, Keys.Right, () => workspaces.MoveFocusedWindowToNextMonitor(), "move focused window to next monitor"); 202 | 203 | // H, L keys 204 | manager.Subscribe(winShift, Keys.H, () => workspaces.FocusedWorkspace.ShrinkPrimaryArea(), "shrink primary area"); 205 | manager.Subscribe(winShift, Keys.L, () => workspaces.FocusedWorkspace.ExpandPrimaryArea(), "expand primary area"); 206 | 207 | // K, J keys 208 | manager.Subscribe(winShift, Keys.K, () => workspaces.FocusedWorkspace.SwapFocusAndNextWindow(), "swap focus and next window"); 209 | manager.Subscribe(winShift, Keys.J, () => workspaces.FocusedWorkspace.SwapFocusAndPreviousWindow(), "swap focus and previous window"); 210 | 211 | // move focused window to 1,2,3,4 workspace 212 | manager.Subscribe(winCtrl, Keys.D1, () => context.Workspaces.MoveFocusedWindowToWorkspace(0), "switch focused window to workspace 1"); 213 | manager.Subscribe(winCtrl, Keys.D2, () => context.Workspaces.MoveFocusedWindowToWorkspace(1), "switch focused window to workspace 2"); 214 | manager.Subscribe(winCtrl, Keys.D3, () => context.Workspaces.MoveFocusedWindowToWorkspace(2), "switch focused window to workspace 3"); 215 | manager.Subscribe(winCtrl, Keys.D4, () => context.Workspaces.MoveFocusedWindowToWorkspace(3), "switch focused window to workspace 4"); 216 | manager.Subscribe(winCtrl, Keys.D5, () => context.Workspaces.MoveFocusedWindowToWorkspace(4), "switch focused window to workspace 5"); 217 | 218 | // Add, Subtract keys 219 | manager.Subscribe(winCtrl, Keys.Add, () => gapPlugin.IncrementInnerGap(), "increment inner gap"); 220 | manager.Subscribe(winCtrl, Keys.Subtract, () => gapPlugin.DecrementInnerGap(), "decrement inner gap"); 221 | 222 | manager.Subscribe(winShift, Keys.Add, () => gapPlugin.IncrementOuterGap(), "increment outer gap"); 223 | manager.Subscribe(winShift, Keys.Subtract, () => gapPlugin.DecrementOuterGap(), "decrement outer gap"); 224 | 225 | // Other shortcuts 226 | manager.Subscribe(winCtrl, Keys.P, () => actionMenu.ShowMenu(actionMenuBuilder), "show menu"); 227 | manager.Subscribe(winShift, Keys.Escape, () => context.Enabled = !context.Enabled, "toggle enabled/disabled"); 228 | manager.Subscribe(winShift, Keys.I, () => context.ToggleConsoleWindow(), "toggle console window"); 229 | 230 | }; 231 | setKeybindings(); 232 | }); 233 | --------------------------------------------------------------------------------