add workspace monitor to bottom bar and remove waybar
This commit is contained in:
parent
089740ffaf
commit
a9525ec467
7 changed files with 144 additions and 22 deletions
9
programs/bar-ws-monitor/Cargo.toml
Normal file
9
programs/bar-ws-monitor/Cargo.toml
Normal 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"
|
53
programs/bar-ws-monitor/src/main.rs
Normal file
53
programs/bar-ws-monitor/src/main.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue