mirror of
https://forge.katzen.cafe/schrottkatze/nix-configs.git
synced 2024-11-23 21:48:45 +01:00
54 lines
1.2 KiB
Rust
54 lines
1.2 KiB
Rust
use core::panic;
|
|
|
|
use serde::Serialize;
|
|
use swayipc::{Connection, Event, EventType, Fallible, Workspace, WorkspaceChange};
|
|
|
|
fn main() -> Fallible<()> {
|
|
let mut con = Connection::new()?;
|
|
let mut workspaces: Vec<WsData> = con
|
|
.get_workspaces()?
|
|
.into_iter()
|
|
.map(|ws| ws.into())
|
|
.collect();
|
|
println!("{}", serde_json::ser::to_string(&workspaces).unwrap());
|
|
|
|
for ev in con.subscribe([EventType::Workspace])? {
|
|
// the lazy/ugly solution!
|
|
// we create a new connection and request workspaces again and again and again
|
|
// TODO: properly handle events one by one
|
|
let mut con = Connection::new()?;
|
|
workspaces = con
|
|
.get_workspaces()?
|
|
.into_iter()
|
|
.map(|ws| ws.into())
|
|
.collect();
|
|
println!("{}", serde_json::ser::to_string(&workspaces).unwrap());
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
struct WsData {
|
|
name: String,
|
|
focused: bool,
|
|
urgent: bool,
|
|
}
|
|
|
|
impl From<Workspace> for WsData {
|
|
fn from(
|
|
Workspace {
|
|
name,
|
|
focused,
|
|
urgent,
|
|
..
|
|
}: Workspace,
|
|
) -> Self {
|
|
WsData {
|
|
name,
|
|
focused,
|
|
urgent,
|
|
}
|
|
}
|
|
}
|