Skip to content

Commit

Permalink
feat(wm): ensure workspace count
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LGUG2Z committed Jul 30, 2021
1 parent d8a7179 commit 8c93932
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
3 changes: 2 additions & 1 deletion komorebi-core/src/lib.rs
Expand Up @@ -37,6 +37,7 @@ pub enum SocketMessage {
ChangeLayout(Layout),
FlipLayout(LayoutFlip),
// Monitor and Workspace Commands
EnsureWorkspaces(usize, usize),
Stop,
TogglePause,
Retile,
Expand All @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions komorebi/src/monitor.rs
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion komorebi/src/process_command.rs
Expand Up @@ -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) => {
Expand All @@ -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)?;
}
Expand Down
15 changes: 15 additions & 0 deletions komorebi/src/window_manager.rs
Expand Up @@ -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,
Expand Down
25 changes: 20 additions & 5 deletions komorebic/src/main.rs
Expand Up @@ -30,9 +30,11 @@ enum SubCommand {
FocusMonitor(Target),
FocusWorkspace(Target),
Promote,
EnsureWorkspaces(WorkspaceCountForMonitor),
Retile,
ContainerPadding(SizeForMonitorWorkspace),
WorkspacePadding(SizeForMonitorWorkspace),
WorkspaceLayout(LayoutForMonitorWorkspace),
WorkspaceName(NameForMonitorWorkspace),
ToggleFloat,
TogglePause,
Expand All @@ -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)]
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 8c93932

Please sign in to comment.