feat(wm): ensure workspace count

Allow the number of workspaces for a given monitor to be pre-created, so
that configuration options can be sent (name, padding, layout) before
the workspace has ever been activated.
This commit is contained in:
LGUG2Z
2021-07-30 12:06:29 -07:00
parent d8a717950c
commit 8c939328d1
5 changed files with 48 additions and 7 deletions

View File

@@ -37,6 +37,7 @@ pub enum SocketMessage {
ChangeLayout(Layout),
FlipLayout(LayoutFlip),
// Monitor and Workspace Commands
EnsureWorkspaces(usize, usize),
Stop,
TogglePause,
Retile,
@@ -45,7 +46,7 @@ pub enum SocketMessage {
ContainerPadding(usize, usize, i32),
WorkspacePadding(usize, usize, i32),
WorkspaceName(usize, usize, String),
SetLayout(usize, usize, Layout),
WorkspaceLayout(usize, usize, Layout),
// Configuration
FloatClass(String),
FloatExe(String),

View File

@@ -53,6 +53,13 @@ impl Monitor {
Ok(())
}
pub fn ensure_workspace_count(&mut self, ensure_count: usize) {
if self.workspaces().len() < ensure_count {
self.workspaces_mut()
.resize(ensure_count, Workspace::default());
}
}
pub fn move_container_to_workspace(
&mut self,
target_workspace_idx: usize,

View File

@@ -125,7 +125,7 @@ impl WindowManager {
}
SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?,
SocketMessage::ChangeLayout(layout) => self.change_workspace_layout(layout)?,
SocketMessage::SetLayout(monitor_idx, workspace_idx, layout) => {
SocketMessage::WorkspaceLayout(monitor_idx, workspace_idx, layout) => {
self.set_workspace_layout(monitor_idx, workspace_idx, layout)?;
}
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
@@ -136,6 +136,9 @@ impl WindowManager {
self.restore_all_windows();
std::process::exit(0)
}
SocketMessage::EnsureWorkspaces(monitor_idx, workspace_count) => {
self.ensure_workspaces_for_monitor(monitor_idx, workspace_count)?;
}
SocketMessage::WorkspaceName(monitor_idx, workspace_idx, name) => {
self.set_workspace_name(monitor_idx, workspace_idx, name)?;
}

View File

@@ -387,6 +387,21 @@ impl WindowManager {
}
}
pub fn ensure_workspaces_for_monitor(
&mut self,
monitor_idx: usize,
workspace_count: usize,
) -> Result<()> {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.context("there is no monitor")?;
monitor.ensure_workspace_count(workspace_count);
Ok(())
}
pub fn set_workspace_padding(
&mut self,
monitor_idx: usize,

View File

@@ -30,9 +30,11 @@ enum SubCommand {
FocusMonitor(Target),
FocusWorkspace(Target),
Promote,
EnsureWorkspaces(WorkspaceCountForMonitor),
Retile,
ContainerPadding(SizeForMonitorWorkspace),
WorkspacePadding(SizeForMonitorWorkspace),
WorkspaceLayout(LayoutForMonitorWorkspace),
WorkspaceName(NameForMonitorWorkspace),
ToggleFloat,
TogglePause,
@@ -45,7 +47,12 @@ enum SubCommand {
AdjustContainerPadding(SizingAdjustment),
AdjustWorkspacePadding(SizingAdjustment),
FlipLayout(LayoutFlip),
Layout(LayoutForMonitorWorkspace),
}
#[derive(Clap)]
struct WorkspaceCountForMonitor {
monitor: usize,
workspace_count: usize,
}
#[derive(Clap)]
@@ -174,10 +181,11 @@ fn main() -> Result<()> {
let bytes = SocketMessage::ToggleMonocle.as_bytes()?;
send_message(&*bytes);
}
SubCommand::Layout(layout) => {
let bytes = SocketMessage::SetLayout(layout.monitor, layout.workspace, layout.layout)
.as_bytes()
.unwrap();
SubCommand::WorkspaceLayout(layout) => {
let bytes =
SocketMessage::WorkspaceLayout(layout.monitor, layout.workspace, layout.layout)
.as_bytes()
.unwrap();
send_message(&*bytes);
}
SubCommand::Start => {
@@ -241,6 +249,13 @@ fn main() -> Result<()> {
.unwrap();
send_message(&*bytes);
}
SubCommand::EnsureWorkspaces(workspaces) => {
let bytes =
SocketMessage::EnsureWorkspaces(workspaces.monitor, workspaces.workspace_count)
.as_bytes()
.unwrap();
send_message(&*bytes);
}
}
Ok(())