workspacer
workspacer copied to clipboard
Grid layout
I really want to have a grid layout but I don't even know where to start, can someone help me with that? I saw the layouts in shared/layout
but I didn't really know how to turn them into a grid layout.
Also would be nice having a grid layout in the default layouts.
Thanks!
Hi @BeeryShklar , I really like the idea of a grid-based layout so I tried to come up with something. Sadly though actually implementing it is a massive headache so what I wrote is not a "true" grid, because instead of dynamically sizing depending on the number of windows (e.g. 9 windows --> 3x3 or 16 windows --> 4x4). it just adds another column to the right and has a fixed number of rows (2). I am still trying to create a true dynamic grid but as I said it's quite the challenge.
Also please note that none of the resizing functions are implemented because IMO that kind of defeats the purpose of a grid. So what I'd suggest is to load the workspace with the FullLayoutEngine
as secondary layout. That way you can always maximize the focused window.
sticky.CreateWorkspace("GRID", new GridLayoutEngine(), new FullLayoutEngine());
Let me know what you think 😄
public class GridLayoutEngine : ILayoutEngine
{
public GridLayoutEngine() {}
public string Name => "grid";
public IEnumerable<IWindowLocation> CalcLayout(IEnumerable<IWindow> windows, int spaceWidth, int spaceHeight)
{
var list = new List<IWindowLocation>();
var numWindows = windows.Count();
int rows;
int cols;
if (numWindows == 0)
return list;
if (numWindows < 4)
{
cols = numWindows;
rows = 1;
}
else
{
cols = numWindows % 2 == 0 ? numWindows / 2 : (numWindows + 1) / 2;
rows = 2;
}
for (int i = 0; i < numWindows; i++)
{
if (i < cols)
{
list.Add(new WindowLocation(spaceWidth / cols * i, 0, spaceWidth / cols, spaceHeight / rows, WindowState.Normal));
}
else
{
list.Add(new WindowLocation(spaceWidth / cols * (i - cols), spaceHeight / rows, spaceWidth / cols, spaceHeight / rows, WindowState.Normal));
}
}
return list;
}
public void ShrinkPrimaryArea() { }
public void ExpandPrimaryArea() { }
public void ResetPrimaryArea() { }
public void IncrementNumInPrimary() { }
public void DecrementNumInPrimary() { }
}
Thank you for this! This is exactly what I wanted.
Thank you @N1x0 but when i run this in my workspacer.config.csx
I get an error: IEnumerable<IWindow>' does not contain a definition for 'Count' and no accessible extension method 'Count' accepting a first argument of type 'IEnumerable<IWindow>
even without using the layout.
Can you help me?
@BeeryShklar Where did you place GridLayoutEngine.cs
? I placed mine on \src\workspacer.Shared\Layout\
and it compiled nicely.
I don't want to compile workspacer. I want to configure everything in my workspacer.config.csx
.
If anyone has a good workflow for compiling it I would but i prefer to do everything in my config file.
@lauverityhill thank you for your kind words, glad you like it!
@BeeryShklar so I'm not actually sure on how to just add this to a config... I guess you'd have to assign it to a variable and do something like var GridLayoutEngine = new ILayoutEngine
but I am not really familiar with c# or csx scripts so sorry I can't really help there. Compiling workspacer is super easy though. Just add the GridLayout.cs file to the Layouts folder in workspacer.Shared
select release in Visual studio and press run. You can then run the .exe file created in the release folder. You could also just copy the workspacer.shared.dll
file from the release folder to your system system wide installation and overwrite the old one
@N1x0 Alright, I think that's what I would do, thanks!