Compare commits

..

No commits in common. "beceee7c99ce65d63c12c12402d87b7594c87583" and "b08b46f4a8950b8c9666f531d06b14b7039074be" have entirely different histories.

8 changed files with 89 additions and 115 deletions

56
Cargo.lock generated
View file

@ -148,9 +148,9 @@ version = "0.1.0"
name = "bar-ws-monitor" name = "bar-ws-monitor"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"niri-ipc",
"serde", "serde",
"serde_json", "serde_json",
"swayipc",
] ]
[[package]] [[package]]
@ -864,16 +864,6 @@ dependencies = [
"unicode-segmentation", "unicode-segmentation",
] ]
[[package]]
name = "niri-ipc"
version = "25.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01515d0a7e73f1f3bd0347100542c4c3f6ebc280688add12e7ed2af4c35af4fb"
dependencies = [
"serde",
"serde_json",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.18" version = "0.2.18"
@ -1004,9 +994,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.94" version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1299,18 +1289,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.219" version = "1.0.209"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.219" version = "1.0.209"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1319,9 +1309,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.140" version = "1.0.128"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
dependencies = [ dependencies = [
"itoa", "itoa",
"memchr", "memchr",
@ -1459,10 +1449,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "syn" name = "swayipc"
version = "2.0.100" version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" checksum = "daa5d19f881f372e225095e297072e2e3ee1c4e9e3a46cafe5f5cf70f1313f29"
dependencies = [
"serde",
"serde_json",
"swayipc-types",
]
[[package]]
name = "swayipc-types"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e487a656336f74341c70a73a289f68d9ba3cab579ba776352ea0c6cdf603fcda"
dependencies = [
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "syn"
version = "2.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -42,7 +42,7 @@ with builtins; {
prusa-slicer prusa-slicer
wget wget
git git
hyfetch neofetch
pciutils pciutils
zip zip
unzip unzip

View file

@ -67,8 +67,7 @@
"Mod+BracketLeft".action.consume-or-expel-window-left = []; "Mod+BracketLeft".action.consume-or-expel-window-left = [];
"Mod+BracketRight".action.consume-or-expel-window-right = []; "Mod+BracketRight".action.consume-or-expel-window-right = [];
"Mod+F".action.maximize-column = []; "Mod+F".action.maximize-column = [];
"Mod+Shift+F".action.expand-column-to-available-width = []; "Mod+Shift+F".action.fullscreen-window = [];
"Mod+Ctrl+F".action.fullscreen-window = [];
"Mod+C".action.center-column = []; "Mod+C".action.center-column = [];
"Mod+Minus".action.set-column-width = "-5%"; "Mod+Minus".action.set-column-width = "-5%";
"Mod+Equal".action.set-column-width = "+5%"; "Mod+Equal".action.set-column-width = "+5%";

View file

@ -28,9 +28,17 @@
window-rules = [ window-rules = [
# TODO: privacy screen rules # TODO: privacy screen rules
# {
# geometry-corner-radius = let val = 1.; in {
# bottom-left = val;
# bottom-right = val;
# top-left = val;
# top-right = val;
# };
# clip-to-geometry = true;
# }
]; ];
# fix electron apps not doing wayland
environment.ELECTRON_OZONE_PLATFORM_HINT = "auto"; environment.ELECTRON_OZONE_PLATFORM_HINT = "auto";
}; };
} }

View file

@ -36,9 +36,8 @@
hide-when-single-tab = true; hide-when-single-tab = true;
active.color = "#5bcefa"; active.color = "#5bcefa";
inactive.color = "#3c3836"; inactive.color = "#3c3836";
gap = 2; gap = 1;
width = 5; width = 3;
corner-radius= 3;
position = "left"; position = "left";
gaps-between-tabs = 0; gaps-between-tabs = 0;
}; };

View file

@ -3,10 +3,9 @@
:class "workspaces" :class "workspaces"
(for workspace in workspaces (for workspace in workspaces
(button (button
:style "border-bottom: 4px solid ${workspace.color}" :class "${workspace.urgent ? "urgent" : ""} ${workspace.focused ? "focused" : 0}"
:class "${workspace.active ? "focused" : 0}"
:onclick "swaymsg workspace ${workspace.name}" :onclick "swaymsg workspace ${workspace.name}"
(label :text "${workspace.idx}") (label :text "${workspace.name}")
) )
) )
) )

View file

@ -6,4 +6,4 @@ edition = "2021"
[dependencies] [dependencies]
serde = { version = "1.0.209", features = [ "derive" ] } serde = { version = "1.0.209", features = [ "derive" ] }
serde_json = "1.0.127" serde_json = "1.0.127"
niri-ipc = "25.2.0" swayipc = "3.0.2"

View file

@ -1,87 +1,28 @@
use core::panic; use core::panic;
use std::{collections::HashMap, io::Write};
use niri_ipc::{
socket::Socket,
state::{EventStreamState, EventStreamStatePart},
Request, Response, Workspace,
};
use serde::Serialize; use serde::Serialize;
use swayipc::{Connection, Event, EventType, Fallible, Workspace, WorkspaceChange};
// gruvbox colors fn main() -> Fallible<()> {
const COLORS: [[&str; 2]; 7] = [ let mut con = Connection::new()?;
["#458588", "#83a598"], // blue let mut workspaces: Vec<WsData> = con
["#b16286", "#d3869b"], // purple .get_workspaces()?
["#689d6a", "#8ec07c"], // aqua
["#97971a", "#b8bb26"], // green
["#d79921", "#fabd2f"], // yellow
["#d65d0e", "#fe8019"], // orange
["#cc241d", "#fb4934"], // red
];
fn main() -> Result<(), std::io::Error> {
let mut state = EventStreamState::default();
let sock = Socket::connect()?;
let mut func = sock.send(Request::EventStream).and_then(|it| match it {
(Ok(Response::Handled), func) => Ok(func),
_ => unreachable!(),
})?;
while let Ok(ev) = (func)() {
// check only relevant later, only done here to avoid a clone
let ev_is_ws_related = matches!(
&ev,
niri_ipc::Event::WorkspacesChanged { .. }
| niri_ipc::Event::WorkspaceActivated { .. }
| niri_ipc::Event::WorkspaceActiveWindowChanged { .. }
);
// apply event to state
state.apply(ev);
if ev_is_ws_related {
let mut workspaces = state
.workspaces
.workspaces
.values()
.map(|it| it.clone())
.collect::<Vec<Workspace>>();
workspaces.sort_by(|a, b| a.idx.cmp(&b.idx));
workspaces.sort_by(|a, b| {
a.output
.clone()
.expect("unreachable")
.to_lowercase()
.cmp(&b.output.clone().expect("unreachable").to_lowercase())
});
let output_colors_lut = workspaces
.iter()
.map(|it| it.output.clone().expect("unreachable"))
.fold(Vec::new(), |mut acc, it| {
if !acc.contains(&it) {
acc.push(it);
}
acc
})
.into_iter() .into_iter()
.enumerate() .map(|ws| ws.into())
.map(|(idx, val)| (val, &COLORS[idx])) .collect();
.collect::<HashMap<String, &[&str; 2]>>(); println!("{}", serde_json::ser::to_string(&workspaces).unwrap());
let results = workspaces for ev in con.subscribe([EventType::Workspace])? {
.iter() // the lazy/ugly solution!
.map(|ws| WsData { // we create a new connection and request workspaces again and again and again
color: output_colors_lut[&ws.output.clone().expect("unreachable")] // TODO: properly handle events one by one
[if ws.is_active { 1 } else { 0 }], let mut con = Connection::new()?;
idx: ws.idx, workspaces = con
focused: ws.is_focused, .get_workspaces()?
active: ws.is_active, .into_iter()
}) .map(|ws| ws.into())
.collect::<Vec<_>>(); .collect();
println!("{}", serde_json::ser::to_string(&workspaces).unwrap());
println!("{}", serde_json::to_string(&results).unwrap());
}
} }
Ok(()) Ok(())
@ -89,8 +30,24 @@ fn main() -> Result<(), std::io::Error> {
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
struct WsData { struct WsData {
color: &'static str, name: String,
idx: u8,
focused: bool, focused: bool,
active: bool, urgent: bool,
}
impl From<Workspace> for WsData {
fn from(
Workspace {
name,
focused,
urgent,
..
}: Workspace,
) -> Self {
WsData {
name,
focused,
urgent,
}
}
} }