Skip to content

Commit

Permalink
fix: focus old on workspace focus events
Browse files Browse the repository at this point in the history
Same fix as in 299fc77, but only on focus events, seems to resolve the
issue, without disrupting other functionality

ref: #34
  • Loading branch information
roosta committed Dec 25, 2024
1 parent b87f411 commit 242fd40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ pub fn update_tree(
conn: &mut Connection,
config: &Config,
res: &regex::Compiled,
focus: bool,
) -> Result<(), Box<dyn Error>> {
let tree = conn.get_tree()?;
let separator = config.get_general("separator").unwrap_or_else(|| " | ".to_string());
Expand Down Expand Up @@ -334,9 +335,11 @@ pub fn update_tree(
}
}

// First focus the workspace to ensure we're renaming the correct one
// let focus_cmd = format!("workspace \"{}\"", old);
// conn.run_command(&focus_cmd)?;
// Focus on flag, fix for moving floating windows across multiple monitors
if focus {
let focus_cmd = format!("workspace \"{}\"", old);
conn.run_command(&focus_cmd)?;
}

// Then rename it
conn.run_command(&command)?;
Expand All @@ -358,7 +361,7 @@ pub fn handle_window_event(
}
match e.change {
WindowChange::New | WindowChange::Close | WindowChange::Move | WindowChange::Title => {
update_tree(conn, config, res)
update_tree(conn, config, res, false)
.map_err(|e| AppError::Event(format!("Tree update failed: {}", e)))?;
}
_ => (),
Expand All @@ -380,7 +383,7 @@ pub fn handle_ws_event(
}
match e.change {
WorkspaceChange::Empty | WorkspaceChange::Focus => {
update_tree(conn, config, res)
update_tree(conn, config, res, e.change == WorkspaceChange::Focus)
.map_err(|e| AppError::Event(format!("Tree update failed: {}", e)))?;
}
_ => (),
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ fn run() -> Result<(), AppError> {
let mut conn = Connection::new()?;
let subscriptions = [EventType::Window, EventType::Workspace];

i3wsr_core::update_tree(&mut conn, &config, &res)
i3wsr_core::update_tree(&mut conn, &config, &res, false)
.map_err(|e| AppError::Event(format!("Initial tree update failed: {}", e)))?;

let event_connection = Connection::new()?;
Expand Down

0 comments on commit 242fd40

Please sign in to comment.