a simple program to make i3 open windows in alternating orientations

Overview

i3-alternating

     1	use i3ipc::{reply::NodeLayout, I3Connection, I3EventListener, Subscription, event::{Event, WindowEventInfo}, event::inner::WindowChange};
       
     2	fn main() -> Result<(), Box<dyn std::error::Error>> {
     3	    let mut connection = I3Connection::connect()?;
     4	    let mut listener = I3EventListener::connect()?;
     5	    let subs = [Subscription::Window, Subscription::Binding];
     6	    listener.subscribe(&subs)?;
     7	    for event in listener.listen() {
     8	        let relevant_event = |i : &WindowEventInfo| 
     9	            i.container.layout == NodeLayout::SplitH 
    10	            || i.container.layout == NodeLayout::SplitV
    11	            && i.change == WindowChange::Focus;
       
    12	        let (_, _, w, h) = match event? {
    13	            Event::WindowEvent(info) if relevant_event(&info) => {
    14	                info.container.window_rect
    15	            },
    16	            Event::BindingEvent(binding) if binding.binding.command.starts_with("resize") => {
    17	                let mut node = &connection.get_tree()?;
    18	                while !node.focused {
    19	                    node = node.nodes.iter().find(|n| node.focus.first().map(|&id| id == n.id).unwrap_or(false)).expect("no focused node");
    20	                }
    21	                node.window_rect
    22	            },
    23	            _ => continue,
    24	        };
       
    25	        if w > h {
    26	            connection.run_command("split h")?;
    27	        } else {
    28	            connection.run_command("split v")?;
    29	        }
    30	    }
    31	    Ok(())
    32	}

That's the whole thing. I just put it in the i3 config as: exec_always --no-startup-id /home/username/bin/i3-alternating & so if you have problems, you can probably find them in the 5(?) lines of non-boilerplate code.

Due to feature requests, the code size has grown prodigiously, and contains a very suspicious line (19) that personally I just don't trust at all. If you hit a bug, it's probably on that line.

You might also like...
NeosPeeps is tool that allows for listing your NeosVR friends quickly, without having to actually open the whole game
NeosPeeps is tool that allows for listing your NeosVR friends quickly, without having to actually open the whole game

Neos Peeps NeosPeeps is tool that allows for listing your NeosVR friends quickly, without having to actually open the whole game. It also has a bunch

This tool allows you to open one or more notebooks in Visual Studio and go hog wild exploring your systems in Bevy.
This tool allows you to open one or more notebooks in Visual Studio and go hog wild exploring your systems in Bevy.

Bevyrly Bevy is rly useful, but requires some hygiene! Pronounced as /ˈbɛvə(ɹ)li/, derives from Old English, combining befer ("beaver") and leah ("cle

A refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

A prototype plugin providing a simple line drawing api for bevy.
A prototype plugin providing a simple line drawing api for bevy.

bevy_debug_lines A prototype plugin providing a simple line drawing api for bevy. See docs.rs for documentation. Expect breakage on master. Click on t

Simple profiler scopes for wgpu using timer queries

wgpu-profiler Simple profiler scopes for wgpu using timer queries Features Easy to use profiler scopes Allows nesting! Can be disabled by runtime flag

Rustcraft is a simple Minecraft engine written in rust using wgpu.
Rustcraft is a simple Minecraft engine written in rust using wgpu.

Rustcraft is a simple Minecraft engine written in rust using wgpu.

Endless Trial is a simple 2D bullet-hell-like game made in Rust with Tetra.

Endless Trial Endless Trial is a simple 2D bullet-hell-like game made in Rust with Tetra. To-do Sound Credits This project uses several free sprites:

Simple RUST game with the Bevy Engine

Simple RUST Game using the Bevy Engine YouTube videos for this code base: Episode 1 - Rust Game Development tutorial from Scratch with Bevy Engine Epi

Owner
null
Using the powers of Rust, Go and Dragonfly to make a vanilla-like world generation.

df-rs-gen — Dragonfly Rust Generator Using the powers of Rust, Go and Dragonfly to make a vanilla-like world generation. How to use Clone the repo. gi

Sculas 1 Apr 13, 2022
Make production Rust binaries auditable

rust-audit Know the exact crate versions used to build your Rust executable. Audit binaries for known bugs or security vulnerabilities in production,

Sergey 324 Dec 27, 2022
Extreme Bevy is what you end up with by following my tutorial series on how to make a low-latency p2p web game.

Extreme Bevy Extreme Bevy is what you end up with by following my tutorial series on how to make a low-latency p2p web game. There game can be played

Johan Klokkhammer Helsing 39 Jan 5, 2023
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

webview 10.8k Jan 9, 2023
Windows game hack helper utilities in rust.

⚗️ toy-arms Windows game hack helper utilities in rust. This crate has some useful macros, functions and traits. ?? How to use this crate? With this c

s3pt3mb3r 100 Jan 1, 2023
A Rust port of the "Heroes of Math & Mech" game. Currently macOS, Windows, Linux and iOS app. WIP.

[WIP] Герои Мата и Меха Попытка переписать известный в узких кругах текстовый квест «Герои Мата и Меха» на Rust. Ещё не закончено! Оригинальная версия

null 2 Jan 18, 2022
A Bevy plugin to easily create and manage windows that remember where they were.

bevy-persistent-windows A Bevy plugin to easily create and manage windows that remember where they were. Background When you're developing a game, thu

Umut 4 Aug 12, 2023
This is an online game in which you program your character and he fights with other players

Game for programmers The goal of this project is to create a simple game for programmers. The essence of the game Each player has his own character th

Danila 1 Dec 10, 2021
A Win32 GUI program which modifies save files from the game Freelancer (2003).

FL Save Convert A Win32 GUI program which modifies save files from the game Freelancer (2003). System Dependencies Your system will need the latest Mi

Devin Mutlu 3 Nov 15, 2022
An (unofficial) open source Rust implementation of the Discord Game SDK.

⚔️ discord-sdk An (unofficial) open source Rust implementation of the Discord Game SDK. Why not use this? This project is not official and is using a

Embark 86 Dec 23, 2022