Skip to content

Instantly share code, notes, and snippets.

@ortango
Created October 27, 2021 17:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ortango/5333a193bb4141d65d3800de79fa462e to your computer and use it in GitHub Desktop.
Save ortango/5333a193bb4141d65d3800de79fa462e to your computer and use it in GitHub Desktop.
wmfocus quick n' dirty stdin support
#!/bin/jq -rf
.monitors[] |
.focusedDesktopId as $d |
.desktops[] |
select(.id==$d) |
.focusedNodeId as $fw |
getpath(paths(.client?!=null and .hidden==false)) |
.id as $w |
.client |
(if .state == "floating" then .floatingRectangle else .tiledRectangle end) |
"\($w) \(.x) \(.y) \(.width) \(.height) \($fw==$w)"
use anyhow::{Context, Result};
use std::{
str::FromStr,
num::ParseIntError,
io::stdin,
io::BufRead
};
use crate::DesktopWindow;
impl FromStr for DesktopWindow {
type Err = ParseIntError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let v: Vec<&str> = s.split_whitespace().collect();
Ok(DesktopWindow {
id: v[0].parse().unwrap(),
x_window_id: Some(v[0].parse().unwrap()),
pos: ( v[1].parse().unwrap(), v[2].parse().unwrap() ),
size: ( v[3].parse().unwrap(), v[4].parse().unwrap() ),
is_focused: v[5].parse().unwrap()
})
}
}
pub fn get_windows() -> Result<Vec<DesktopWindow>> {
let windows: Vec<DesktopWindow> = stdin()
.lock()
.lines()
.filter_map(|line_result| line_result.ok())
.filter_map(|line| line.parse().ok())
.collect();
Ok(windows)
}
pub fn focus_window(window: &DesktopWindow) -> Result<()> {
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment