Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/wm-common/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ pub enum InvokeCommand {
},
Position(InvokePositionCommand),
Resize(InvokeResizeCommand),
UpdateWorkspaceConfig {
#[clap(long, allow_hyphen_values = true)]
workspace: Option<String>,
#[clap(flatten)]
new_config: InvokeUpdateWorkspaceConfig,
},
SetFloating {
#[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
shown_on_top: Option<bool>,
Expand Down Expand Up @@ -411,3 +417,26 @@ pub struct InvokePositionCommand {
#[clap(long, allow_hyphen_values = true)]
pub y_pos: Option<i32>,
}

#[derive(Args, Clone, Debug, PartialEq, Serialize)]
#[group(required = true, multiple = true)]
pub struct InvokeUpdateWorkspaceConfig {
#[clap(long, allow_hyphen_values = true)]
pub name: Option<String>,

#[clap(
long,
allow_hyphen_values = true,
conflicts_with = "no_display_name"
)]
pub display_name: Option<String>,

#[clap(long, conflicts_with = "display_name")]
pub no_display_name: bool,

#[clap(long)]
pub bind_to_monitor: Option<u32>,

#[clap(long)]
pub keep_alive: Option<bool>,
}
2 changes: 2 additions & 0 deletions packages/wm/src/commands/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ mod activate_workspace;
mod deactivate_workspace;
mod focus_workspace;
mod move_workspace_in_direction;
mod update_workspace_config;
mod sort_workspaces;

pub use activate_workspace::*;
pub use deactivate_workspace::*;
pub use focus_workspace::*;
pub use move_workspace_in_direction::*;
pub use update_workspace_config::*;
pub use sort_workspaces::*;
62 changes: 62 additions & 0 deletions packages/wm/src/commands/workspace/update_workspace_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use anyhow::{bail, Context};
use wm_common::{InvokeUpdateWorkspaceConfig, WmEvent, WorkspaceConfig};

use super::sort_workspaces;
use crate::{
models::Workspace, traits::CommonGetters, user_config::UserConfig,
wm_state::WmState,
};

pub fn update_workspace_config(
workspace: &Workspace,
state: &WmState,
config: &UserConfig,
new_config: &InvokeUpdateWorkspaceConfig,
) -> anyhow::Result<()> {
let WorkspaceConfig {
mut name,
display_name,
bind_to_monitor,
keep_alive,
} = workspace.config();

let mut need_sort = false;

// validate the workspace name change
if let Some(new_name) = &new_config.name {
if new_name != &name {
if let Some(_other_workspace) = state.workspace_by_name(new_name) {
bail!("The workspace \"{}\" already exists", new_name);
}
name.clone_from(new_name);
need_sort = true;
}
}

// the updated config
let updated_config = WorkspaceConfig {
name,
display_name: if new_config.no_display_name {
None
} else {
new_config.display_name.clone().or(display_name)
},
bind_to_monitor: new_config.bind_to_monitor.or(bind_to_monitor),
keep_alive: new_config.keep_alive.unwrap_or(keep_alive),
};

// Commit the change
workspace.set_config(updated_config);

if need_sort {
let monitor =
workspace.monitor().context("No displayed workspace.")?;
sort_workspaces(&monitor, config)?;
}

state.emit_event(WmEvent::WorkspaceUpdated {
updated_workspace: workspace.to_dto()?,
});

Ok(())
}
18 changes: 17 additions & 1 deletion packages/wm/src/wm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use crate::{
resize_window, set_window_position, set_window_size,
update_window_state, WindowPositionTarget,
},
workspace::{focus_workspace, move_workspace_in_direction},
workspace::{
focus_workspace, move_workspace_in_direction,
update_workspace_config,
},
},
events::{
handle_display_settings_changed, handle_mouse_move,
Expand Down Expand Up @@ -431,6 +434,19 @@ impl WindowManager {
_ => Ok(()),
}
}
InvokeCommand::UpdateWorkspaceConfig {
workspace,
new_config,
} => {
let workspace = if let Some(workspace_name) = workspace {
state
.workspace_by_name(workspace_name)
.context("Workspace doesn't exist.")?
} else {
subject_container.workspace().context("No workspace.")?
};
update_workspace_config(&workspace, state, config, new_config)
}
InvokeCommand::Resize(args) => {
match subject_container.as_window_container() {
Ok(window) => resize_window(
Expand Down