add workspace monitor to bottom bar and remove waybar

This commit is contained in:
Schrottkatze 2024-09-02 20:33:22 +02:00
parent 089740ffaf
commit a9525ec467
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
7 changed files with 144 additions and 22 deletions

View file

@ -0,0 +1,9 @@
[package]
name = "bar-ws-monitor"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0.209", features = [ "derive" ] }
serde_json = "1.0.127"
swayipc = "3.0.2"

View file

@ -0,0 +1,53 @@
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,
}
}
}