Skip to content

Commit

Permalink
hopefully this is the first and last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nowakf committed Oct 10, 2021
0 parents commit a844a7e
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
72 changes: 72 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "i3-alternating"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
i3ipc = "*"
24 changes: 24 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use i3ipc::{reply::NodeLayout, I3Connection, I3EventListener, Subscription, event::Event, event::inner::WindowChange};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut connection = I3Connection::connect()?;
let mut listener = I3EventListener::connect()?;
let subs = [Subscription::Window];
listener.subscribe(&subs)?;
for event in listener.listen() {
if let Event::WindowEvent(info) = event? {
match info.container.layout {
NodeLayout::SplitH | NodeLayout::SplitV if info.change == WindowChange::New => {
let (_, _, w, h) = info.container.window_rect;
if w > h {
connection.run_command("split h")?;
} else {
connection.run_command("split v")?;
}
},
_ => (),
}
}
}
Ok(())
}

0 comments on commit a844a7e

Please sign in to comment.