-
Notifications
You must be signed in to change notification settings - Fork 0
/
whim.commands.csx
165 lines (145 loc) · 5.84 KB
/
whim.commands.csx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using Whim;
using System.Threading.Tasks; // used for FocusFollowsMouse hack
void AddUserCommands(IContext context)
{
/************************************
* Cycle over _inactive_ workspaces *
************************************/
// Activate next workspace, skipping over those that are active on other monitors
context.CommandManager.Add(
identifier: "activate_previous_workspace",
title: "Activate the previous inactive workspace",
callback: () => context.Butler.ActivateAdjacent(reverse: true, skipActive: true)
);
// Activate previous workspace, skipping over those that are active on other monitors
context.CommandManager.Add(
identifier: "activate_next_workspace",
title: "Activate the next inactive workspace",
callback: () => context.Butler.ActivateAdjacent(skipActive: true)
);
// Move current window to next workspace, skipping over those that are active on other monitors
context.CommandManager.Add(
identifier: "move_window_to_previous_workspace",
title: "Move focused window to the previous inactive workspace",
callback: () => context.Butler.MoveWindowToAdjacentWorkspace(reverse: true, skipActive: true)
);
// Move current window to previous workspace, skipping over those that are active on other monitors
context.CommandManager.Add(
identifier: "move_window_to_next_workspace",
title: "Move focused window to the next inactive workspace",
callback: () => context.Butler.MoveWindowToAdjacentWorkspace(skipActive: true)
);
/*****************
* Swap monitors *
*****************/
// Swap workspace with next monitor
context.CommandManager.Add(
identifier:"swap_workspace_with_next_monitor",
title: "Swap monitors",
callback: () => context.Butler.SwapWorkspaceWithAdjacentMonitor()
);
/***********************
* Toggle focus layout *
***********************/
// Toggle focus layout
context.CommandManager.Add(
identifier: "toggle_focus_layout",
title: "Toggle focus layout",
callback: () =>
{
IWorkspace workspace = context.WorkspaceManager.ActiveWorkspace;
if (workspace.ActiveLayoutEngine.Name == "Focus")
{
workspace.ActivatePreviouslyActiveLayoutEngine();
}
else
{
workspace.PerformCustomLayoutEngineAction(
new LayoutEngineCustomAction()
{
Name = "Focus.unset_maximized",
Window = null
}
);
workspace.TrySetLayoutEngineFromName("Focus");
}
}
);
// Toggle maximized if focus layout is active, otherwise activate focus layout and set maximized to true
context.CommandManager.Add(
identifier: "toggle_focus_maximize",
title: "Toggle focus layout maximize state",
callback: () =>
{
IWorkspace workspace = context.WorkspaceManager.ActiveWorkspace;
if (workspace.ActiveLayoutEngine.Name == "Focus")
{
context.CommandManager.TryGetCommand("whim.core.focus_layout.toggle_maximized").TryExecute();
}
else
{
workspace.PerformCustomLayoutEngineAction(
new LayoutEngineCustomAction()
{
Name = "Focus.set_maximized",
Window = null
}
);
workspace.TrySetLayoutEngineFromName("Focus");
}
}
);
/****************
* Close window *
****************/
// Close active window
context.CommandManager.Add(
identifier: "close_window",
title: "Close focused window",
callback: () => context.WorkspaceManager.ActiveWorkspace.LastFocusedWindow.Close()
);
/**************************
* FocusFollowsMouse hack *
**************************/
// Move window to next monitor variant that refocuses moved window after 200ms
context.CommandManager.Add(
identifier: "move_window_to_next_monitor",
title: "Move focused window to the next monitor",
callback: () =>
{
// Get the next monitor.
IMonitor monitor = context.MonitorManager.ActiveMonitor;
IMonitor nextMonitor = context.MonitorManager.GetNextMonitor(monitor);
// Get the current window
IWindow? window = context.WorkspaceManager.ActiveWorkspace.LastFocusedWindow;
if (window == null)
{
Logger.Error("No window was found");
return;
}
IMonitor? oldMonitor = context.Butler.Pantry.GetMonitorForWindow(window);
if (oldMonitor == null)
{
Logger.Error($"Window {window} was not found in any monitor");
return;
}
if (oldMonitor.Equals(nextMonitor))
{
Logger.Error($"Window {window} is already on monitor {nextMonitor}");
return;
}
IWorkspace? workspace = context.Butler.Pantry.GetWorkspaceForMonitor(nextMonitor);
if (workspace == null)
{
Logger.Error($"Monitor {nextMonitor} was not found in any workspace");
return;
}
context.Butler.MoveWindowToWorkspace(workspace, window);
Task.Run(async delegate
{
await Task.Delay(200);
window.Focus();
});
}
);
}