handle that which is tabbed
This commit is contained in:
parent
4abdca0ca1
commit
0355dfb5dc
|
@ -12,6 +12,7 @@ pub struct Config {
|
||||||
pub flash_colour: colour::Format,
|
pub flash_colour: colour::Format,
|
||||||
pub autosplit_enabled: bool,
|
pub autosplit_enabled: bool,
|
||||||
pub autosplit_ratio: f64,
|
pub autosplit_ratio: f64,
|
||||||
|
pub force_tabbed: Vec<String>,
|
||||||
pub output_blocklist: Vec<String>,
|
pub output_blocklist: Vec<String>,
|
||||||
#[serde(default = "default_log_dir")]
|
#[serde(default = "default_log_dir")]
|
||||||
pub log_dir: std::path::PathBuf,
|
pub log_dir: std::path::PathBuf,
|
||||||
|
@ -130,6 +131,7 @@ impl Default for Config {
|
||||||
flash_colour: colour::parse_hex("#ff0000").unwrap(),
|
flash_colour: colour::parse_hex("#ff0000").unwrap(),
|
||||||
autosplit_enabled: true,
|
autosplit_enabled: true,
|
||||||
autosplit_ratio: 1.0,
|
autosplit_ratio: 1.0,
|
||||||
|
force_tabbed: Vec::new(),
|
||||||
output_blocklist: Vec::new(),
|
output_blocklist: Vec::new(),
|
||||||
log_dir: std::path::PathBuf::new(),
|
log_dir: std::path::PathBuf::new(),
|
||||||
}
|
}
|
||||||
|
|
64
src/main.rs
64
src/main.rs
|
@ -61,12 +61,49 @@ async fn main() -> Res<()> {
|
||||||
log::warn!("error {e:?}");
|
log::warn!("error {e:?}");
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
} else if binding.command.starts_with("focus parent") {
|
||||||
|
let tree = command_connection.get_tree().await?;
|
||||||
|
|
||||||
|
if let Some(node) = tree.find_focused_as_ref(|n| {
|
||||||
|
n.focused && n.node_type == swayipc_async::NodeType::Con
|
||||||
|
}) {
|
||||||
|
let (width, height) = (node.window_rect.width, node.window_rect.height);
|
||||||
|
if width == 0 || height == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let ratio = (width as f64) / (height as f64);
|
||||||
|
let autosplit_ratio = CONFIG.get().await.autosplit_ratio;
|
||||||
|
if let Err(e) = if ratio > autosplit_ratio {
|
||||||
|
command_connection.run_command("splith").await
|
||||||
|
} else {
|
||||||
|
command_connection.run_command("splitv").await
|
||||||
|
} {
|
||||||
|
log::warn!("error {e:?} setting split");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
swayipc_async::Event::Window(window)
|
swayipc_async::Event::Window(window)
|
||||||
if window.change != swayipc_async::WindowChange::Mark =>
|
if window.change != swayipc_async::WindowChange::Mark =>
|
||||||
{
|
{
|
||||||
let node = window.container;
|
let node = window.container;
|
||||||
|
let tree = command_connection.get_tree().await?;
|
||||||
|
let config = CONFIG.get().await;
|
||||||
|
if window.change == swayipc_async::WindowChange::New
|
||||||
|
&& node.app_id.as_ref().is_some_and(|app_id| {
|
||||||
|
config
|
||||||
|
.force_tabbed
|
||||||
|
.iter()
|
||||||
|
.any(|name| name.eq_ignore_ascii_case(app_id))
|
||||||
|
})
|
||||||
|
{
|
||||||
|
if let Some(parent) = tree.clone().find(|n| n.focus.contains(&node.id)) {
|
||||||
|
if parent.layout != swayipc_async::NodeLayout::Tabbed {
|
||||||
|
command_connection.run_command("splith").await?;
|
||||||
|
command_connection.run_command("layout tabbed").await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if window.change == swayipc_async::WindowChange::New
|
if window.change == swayipc_async::WindowChange::New
|
||||||
&& node.app_id == Some(String::from("code-url-handler"))
|
&& node.app_id == Some(String::from("code-url-handler"))
|
||||||
|
@ -84,6 +121,7 @@ async fn main() -> Res<()> {
|
||||||
recent_code = None;
|
recent_code = None;
|
||||||
log::info!("focused the window we want with id {id}");
|
log::info!("focused the window we want with id {id}");
|
||||||
if let Err(e) = code_trigger(
|
if let Err(e) = code_trigger(
|
||||||
|
tree,
|
||||||
&mut command_connection,
|
&mut command_connection,
|
||||||
id,
|
id,
|
||||||
&CONFIG.get().await.output_blocklist,
|
&CONFIG.get().await.output_blocklist,
|
||||||
|
@ -99,7 +137,14 @@ async fn main() -> Res<()> {
|
||||||
// the node we're given is the one that closes
|
// the node we're given is the one that closes
|
||||||
if node.node_type == swayipc_async::NodeType::Con {
|
if node.node_type == swayipc_async::NodeType::Con {
|
||||||
let config = CONFIG.get().await;
|
let config = CONFIG.get().await;
|
||||||
if !config.autosplit_enabled {
|
if !config.autosplit_enabled
|
||||||
|
|| config.force_tabbed.iter().any(|blocked| {
|
||||||
|
node.app_id
|
||||||
|
.as_ref()
|
||||||
|
.map(|v| blocked.eq_ignore_ascii_case(v))
|
||||||
|
.unwrap_or_default()
|
||||||
|
})
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let (width, height) = (node.window_rect.width, node.window_rect.height);
|
let (width, height) = (node.window_rect.width, node.window_rect.height);
|
||||||
|
@ -129,15 +174,15 @@ async fn main() -> Res<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn code_trigger<T: AsRef<str> + std::cmp::PartialEq<str>>(
|
async fn code_trigger<T: AsRef<str> + std::cmp::PartialEq<str>>(
|
||||||
|
tree: swayipc_async::Node,
|
||||||
connection: &mut swayipc_async::Connection,
|
connection: &mut swayipc_async::Connection,
|
||||||
id: i64,
|
id: i64,
|
||||||
output_blocklist: &[T],
|
output_blocklist: &[T],
|
||||||
) -> Res<()> {
|
) -> Res<()> {
|
||||||
let tree = connection.get_tree().await?;
|
|
||||||
|
|
||||||
for workspace in connection.get_workspaces().await? {
|
for workspace in connection.get_workspaces().await? {
|
||||||
let width = workspace.rect.width;
|
|
||||||
if workspace.focused {
|
if workspace.focused {
|
||||||
|
let width = workspace.rect.width;
|
||||||
|
|
||||||
let mut workspace = get_with_id(&tree, workspace.id)?;
|
let mut workspace = get_with_id(&tree, workspace.id)?;
|
||||||
if workspace
|
if workspace
|
||||||
.output
|
.output
|
||||||
|
@ -150,7 +195,16 @@ async fn code_trigger<T: AsRef<str> + std::cmp::PartialEq<str>>(
|
||||||
while workspace.focus.len() == 1 {
|
while workspace.focus.len() == 1 {
|
||||||
workspace = get_with_id(workspace, workspace.focus[0])?;
|
workspace = get_with_id(workspace, workspace.focus[0])?;
|
||||||
}
|
}
|
||||||
if workspace.layout == swayipc_async::NodeLayout::SplitH && workspace.focus.len() == 2 {
|
if workspace.layout == swayipc_async::NodeLayout::Tabbed {
|
||||||
|
for _ in 0..workspace.nodes.len() {
|
||||||
|
connection.run_command("move left").await?;
|
||||||
|
}
|
||||||
|
connection
|
||||||
|
.run_command(format!("resize set width {}px", width - 1220))
|
||||||
|
.await?;
|
||||||
|
} else if workspace.layout == swayipc_async::NodeLayout::SplitH
|
||||||
|
&& workspace.focus.len() == 2
|
||||||
|
{
|
||||||
let (code, other) = {
|
let (code, other) = {
|
||||||
let a = get_with_id(&tree, workspace.focus[0])?;
|
let a = get_with_id(&tree, workspace.focus[0])?;
|
||||||
let b = get_with_id(&tree, workspace.focus[1])?;
|
let b = get_with_id(&tree, workspace.focus[1])?;
|
||||||
|
|
Loading…
Reference in a new issue