Skip to content

Commit

Permalink
feat(wm): add enforce-workspace-rules command
Browse files Browse the repository at this point in the history
This commit adds a new komorebic command "enforce-workspace-rules" which
will enforce all persistent and initial workspace rules regardless of
whether they have already been applied (in the case of initial workspace
rules).

resolve #1196
  • Loading branch information
LGUG2Z committed Dec 24, 2024
1 parent 2c08fbe commit dee46f5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions komorebi/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub enum SocketMessage {
TogglePause,
Retile,
RetileWithResizeDimensions,
EnforceWorkspaceRules,
QuickSave,
QuickLoad,
Save(PathBuf),
Expand Down
3 changes: 3 additions & 0 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ impl WindowManager {
border_manager::destroy_all_borders()?;
self.retile_all(true)?
}
SocketMessage::EnforceWorkspaceRules => {
self.enforce_workspace_rules(true)?;
}
SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?,
SocketMessage::ChangeLayout(layout) => self.change_workspace_layout_default(layout)?,
SocketMessage::CycleLayout(direction) => self.cycle_layout(direction)?,
Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl WindowManager {
_ => {}
}

self.enforce_workspace_rules()?;
self.enforce_workspace_rules(false)?;

if matches!(event, WindowManagerEvent::MouseCapture(..)) {
tracing::trace!(
Expand Down
4 changes: 2 additions & 2 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ impl StaticConfig {
}
}

wm.enforce_workspace_rules()?;
wm.enforce_workspace_rules(false)?;

if value.border == Some(true) {
border_manager::BORDER_ENABLED.store(true, Ordering::SeqCst);
Expand Down Expand Up @@ -1236,7 +1236,7 @@ impl StaticConfig {
}
}

wm.enforce_workspace_rules()?;
wm.enforce_workspace_rules(false)?;

if let Some(enabled) = value.border {
border_manager::BORDER_ENABLED.store(enabled, Ordering::SeqCst);
Expand Down
4 changes: 2 additions & 2 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ impl WindowManager {
}

#[tracing::instrument(skip(self), level = "debug")]
pub fn enforce_workspace_rules(&mut self) -> Result<()> {
pub fn enforce_workspace_rules(&mut self, reapply_initial_rules: bool) -> Result<()> {
let mut to_move = vec![];

let focused_monitor_idx = self.focused_monitor_idx();
Expand Down Expand Up @@ -762,7 +762,7 @@ impl WindowManager {
if matched {
let floating = workspace.floating_windows().contains(window);

if rule.initial_only {
if !reapply_initial_rules && rule.initial_only {
if !already_moved_window_handles.contains(&window.hwnd) {
already_moved_window_handles.insert(window.hwnd);

Expand Down
5 changes: 5 additions & 0 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,8 @@ enum SubCommand {
PromoteWindow(PromoteWindow),
/// Force the retiling of all managed windows
Retile,
/// Enforce all workspace rules, including initial workspace rules that have already been applied
EnforceWorkspaceRules,
/// Set the monitor index preference for a monitor identified using its size
#[clap(arg_required_else_help = true)]
MonitorIndexPreference(MonitorIndexPreference),
Expand Down Expand Up @@ -1715,6 +1717,9 @@ fn main() -> Result<()> {
SubCommand::Retile => {
send_message(&SocketMessage::Retile)?;
}
SubCommand::EnforceWorkspaceRules => {
send_message(&SocketMessage::EnforceWorkspaceRules)?;
}
SubCommand::Move(arg) => {
send_message(&SocketMessage::MoveWindow(arg.operation_direction))?;
}
Expand Down

0 comments on commit dee46f5

Please sign in to comment.