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 LGUG2Z#1196
  • Loading branch information
LGUG2Z authored and alex-ds13 committed Dec 30, 2024
1 parent e9bb6b4 commit 17c6461
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
@@ -110,6 +110,7 @@ pub enum SocketMessage {
TogglePause,
Retile,
RetileWithResizeDimensions,
EnforceWorkspaceRules,
QuickSave,
QuickLoad,
Save(PathBuf),
3 changes: 3 additions & 0 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
@@ -742,6 +742,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)?,
2 changes: 1 addition & 1 deletion komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
@@ -159,7 +159,7 @@ impl WindowManager {
_ => {}
}

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

if matches!(event, WindowManagerEvent::MouseCapture(..)) {
tracing::trace!(
4 changes: 2 additions & 2 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
@@ -1185,7 +1185,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);
@@ -1246,7 +1246,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);
4 changes: 2 additions & 2 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
@@ -710,7 +710,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();
@@ -763,7 +763,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);

5 changes: 5 additions & 0 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
@@ -1171,6 +1171,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),
@@ -1726,6 +1728,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))?;
}

0 comments on commit 17c6461

Please sign in to comment.