mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-13 16:42:50 +02:00
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:
@@ -37,6 +37,7 @@ pub enum SocketMessage {
|
|||||||
ChangeLayout(Layout),
|
ChangeLayout(Layout),
|
||||||
FlipLayout(LayoutFlip),
|
FlipLayout(LayoutFlip),
|
||||||
// Monitor and Workspace Commands
|
// Monitor and Workspace Commands
|
||||||
|
EnsureWorkspaces(usize, usize),
|
||||||
Stop,
|
Stop,
|
||||||
TogglePause,
|
TogglePause,
|
||||||
Retile,
|
Retile,
|
||||||
@@ -45,7 +46,7 @@ pub enum SocketMessage {
|
|||||||
ContainerPadding(usize, usize, i32),
|
ContainerPadding(usize, usize, i32),
|
||||||
WorkspacePadding(usize, usize, i32),
|
WorkspacePadding(usize, usize, i32),
|
||||||
WorkspaceName(usize, usize, String),
|
WorkspaceName(usize, usize, String),
|
||||||
SetLayout(usize, usize, Layout),
|
WorkspaceLayout(usize, usize, Layout),
|
||||||
// Configuration
|
// Configuration
|
||||||
FloatClass(String),
|
FloatClass(String),
|
||||||
FloatExe(String),
|
FloatExe(String),
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ impl Monitor {
|
|||||||
Ok(())
|
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(
|
pub fn move_container_to_workspace(
|
||||||
&mut self,
|
&mut self,
|
||||||
target_workspace_idx: usize,
|
target_workspace_idx: usize,
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?,
|
SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?,
|
||||||
SocketMessage::ChangeLayout(layout) => self.change_workspace_layout(layout)?,
|
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)?;
|
self.set_workspace_layout(monitor_idx, workspace_idx, layout)?;
|
||||||
}
|
}
|
||||||
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
||||||
@@ -136,6 +136,9 @@ impl WindowManager {
|
|||||||
self.restore_all_windows();
|
self.restore_all_windows();
|
||||||
std::process::exit(0)
|
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) => {
|
SocketMessage::WorkspaceName(monitor_idx, workspace_idx, name) => {
|
||||||
self.set_workspace_name(monitor_idx, workspace_idx, name)?;
|
self.set_workspace_name(monitor_idx, workspace_idx, name)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(
|
pub fn set_workspace_padding(
|
||||||
&mut self,
|
&mut self,
|
||||||
monitor_idx: usize,
|
monitor_idx: usize,
|
||||||
|
|||||||
+20
-5
@@ -30,9 +30,11 @@ enum SubCommand {
|
|||||||
FocusMonitor(Target),
|
FocusMonitor(Target),
|
||||||
FocusWorkspace(Target),
|
FocusWorkspace(Target),
|
||||||
Promote,
|
Promote,
|
||||||
|
EnsureWorkspaces(WorkspaceCountForMonitor),
|
||||||
Retile,
|
Retile,
|
||||||
ContainerPadding(SizeForMonitorWorkspace),
|
ContainerPadding(SizeForMonitorWorkspace),
|
||||||
WorkspacePadding(SizeForMonitorWorkspace),
|
WorkspacePadding(SizeForMonitorWorkspace),
|
||||||
|
WorkspaceLayout(LayoutForMonitorWorkspace),
|
||||||
WorkspaceName(NameForMonitorWorkspace),
|
WorkspaceName(NameForMonitorWorkspace),
|
||||||
ToggleFloat,
|
ToggleFloat,
|
||||||
TogglePause,
|
TogglePause,
|
||||||
@@ -45,7 +47,12 @@ enum SubCommand {
|
|||||||
AdjustContainerPadding(SizingAdjustment),
|
AdjustContainerPadding(SizingAdjustment),
|
||||||
AdjustWorkspacePadding(SizingAdjustment),
|
AdjustWorkspacePadding(SizingAdjustment),
|
||||||
FlipLayout(LayoutFlip),
|
FlipLayout(LayoutFlip),
|
||||||
Layout(LayoutForMonitorWorkspace),
|
}
|
||||||
|
|
||||||
|
#[derive(Clap)]
|
||||||
|
struct WorkspaceCountForMonitor {
|
||||||
|
monitor: usize,
|
||||||
|
workspace_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clap)]
|
#[derive(Clap)]
|
||||||
@@ -174,10 +181,11 @@ fn main() -> Result<()> {
|
|||||||
let bytes = SocketMessage::ToggleMonocle.as_bytes()?;
|
let bytes = SocketMessage::ToggleMonocle.as_bytes()?;
|
||||||
send_message(&*bytes);
|
send_message(&*bytes);
|
||||||
}
|
}
|
||||||
SubCommand::Layout(layout) => {
|
SubCommand::WorkspaceLayout(layout) => {
|
||||||
let bytes = SocketMessage::SetLayout(layout.monitor, layout.workspace, layout.layout)
|
let bytes =
|
||||||
.as_bytes()
|
SocketMessage::WorkspaceLayout(layout.monitor, layout.workspace, layout.layout)
|
||||||
.unwrap();
|
.as_bytes()
|
||||||
|
.unwrap();
|
||||||
send_message(&*bytes);
|
send_message(&*bytes);
|
||||||
}
|
}
|
||||||
SubCommand::Start => {
|
SubCommand::Start => {
|
||||||
@@ -241,6 +249,13 @@ fn main() -> Result<()> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
send_message(&*bytes);
|
send_message(&*bytes);
|
||||||
}
|
}
|
||||||
|
SubCommand::EnsureWorkspaces(workspaces) => {
|
||||||
|
let bytes =
|
||||||
|
SocketMessage::EnsureWorkspaces(workspaces.monitor, workspaces.workspace_count)
|
||||||
|
.as_bytes()
|
||||||
|
.unwrap();
|
||||||
|
send_message(&*bytes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user