forked from mirrors_public/oddlama_nix-config
chore: don't change i3 layout if workspace already uses that layout
This commit is contained in:
parent
c3b7cee555
commit
a575d2e271
1 changed files with 19 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use clap::Parser;
|
||||
use log::{debug, info};
|
||||
use log::{debug, info, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
@ -8,7 +8,7 @@ use tokio::{sync::mpsc, task::JoinHandle};
|
|||
use tokio_i3ipc::{
|
||||
event::{Event, Subscribe, WindowChange, WorkspaceChange},
|
||||
msg::Msg,
|
||||
reply::{Node, NodeType},
|
||||
reply::{Node, NodeLayout, NodeType},
|
||||
I3,
|
||||
};
|
||||
use tokio_stream::StreamExt;
|
||||
|
@ -33,7 +33,7 @@ struct Cli {
|
|||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Config {
|
||||
/// The workspace -> layout associations
|
||||
layouts: HashMap<String, String>,
|
||||
layouts: HashMap<String, NodeLayout>,
|
||||
}
|
||||
|
||||
fn find_workspace_for_window(tree: &Node, window_id: usize) -> Option<&Node> {
|
||||
|
@ -144,6 +144,22 @@ fn cmd_toggle_layout(config: &Config, workspace: &Node) -> Option<String> {
|
|||
// we can operate on the workspace.
|
||||
}
|
||||
|
||||
// Don't do anything if the layout is already correct
|
||||
if &con.layout == desired_layout {
|
||||
return None
|
||||
}
|
||||
|
||||
let desired_layout = match desired_layout {
|
||||
NodeLayout::SplitH => "splith",
|
||||
NodeLayout::SplitV => "splitv",
|
||||
NodeLayout::Stacked => "stacked",
|
||||
NodeLayout::Tabbed => "tabbed",
|
||||
x => {
|
||||
warn!("Encountered invalid layout in configuration: {:?}", x);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
debug!(
|
||||
"Changing layout of workspace {:?} to {} (modifying con_id={})",
|
||||
&name, desired_layout, con.id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue