Created
October 27, 2021 17:03
-
-
Save ortango/5333a193bb4141d65d3800de79fa462e to your computer and use it in GitHub Desktop.
wmfocus quick n' dirty stdin support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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