This commit is contained in:
benstrb 2026-03-21 22:00:34 +01:00
parent 9bf4c44aa2
commit 4895333ff1
5 changed files with 75 additions and 14 deletions

11
Cargo.lock generated
View file

@ -1787,6 +1787,16 @@ dependencies = [
"jni-sys",
]
[[package]]
name = "niri-ipc"
version = "25.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12bd9eb4e437f5282ce853cf66837658379cb537b4b6bae687da59246005329a"
dependencies = [
"serde",
"serde_json",
]
[[package]]
name = "num-traits"
version = "0.2.19"
@ -3310,6 +3320,7 @@ dependencies = [
"chrono",
"iced",
"iced_layershell",
"niri-ipc",
"tokio",
"winit",
"zbus",

View file

@ -7,6 +7,7 @@ edition = "2024"
chrono = "0.4.44"
iced = { version = "0.14.0", default-features = false, features = ["wgpu", "wayland", "tokio"] }
iced_layershell = { version = "0.15.0", default-features = false }
niri-ipc = "25.11.0"
tokio = { version = "1.50.0", features = ["time"] }
winit = { version = "0.30.12", default-features = false, features = ["wayland"] }
zbus = "5.14.0"

12
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1773579282,
"narHash": "sha256-LWvZj9Bvm1EuoO6zbX4yjZebwnZNfeTbmCJGS7RGQ3Y=",
"lastModified": 1773821835,
"narHash": "sha256-TJ3lSQtW0E2JrznGVm8hOQGVpXjJyXY2guAxku2O9A4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5a88de74db0e948139be4b46f9a94d64aa11391c",
"rev": "b40629efe5d6ec48dd1efba650c797ddbd39ace0",
"type": "github"
},
"original": {
@ -29,11 +29,11 @@
]
},
"locked": {
"lastModified": 1773630837,
"narHash": "sha256-zJhgAGnbVKeBMJOb9ctZm4BGS/Rnrz+5lfSXTVah4HQ=",
"lastModified": 1773975983,
"narHash": "sha256-zrRVwdfhDdohANqEhzY/ydeza6EXEi8AG6cyMRNYT9Q=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "f600ea449c7b5bb596fa1cf21c871cc5b9e31316",
"rev": "cc80954a95f6f356c303ed9f08d0b63ca86216ac",
"type": "github"
},
"original": {

View file

@ -20,4 +20,5 @@ pub enum Message {
Battery(Option<f64>),
Time,
ShutdownEvent(ShutdownEvents),
FocusChanged(Option<u64>),
}

View file

@ -1,7 +1,7 @@
use iced::{Subscription, Task};
use wayland_protocols_wlr::foreign_toplevel;
use iced::{Subscription, Task, futures::SinkExt};
use niri_ipc::{Event, Request, socket::Socket};
use crate::widget::PanelWidget;
use crate::widget::{Message, PanelWidget};
pub struct FocusedWindowWidget {
focused_window: String,
@ -10,21 +10,69 @@ pub struct FocusedWindowWidget {
impl FocusedWindowWidget {
pub fn new() -> Self {
Self {
focused_window: foreign_toplevel::v1::client::zwlr_foreign_toplevel_manager_v1::Event,
focused_window: "dsadsadsadas".into(),
}
}
}
impl PanelWidget for FocusedWindowWidget {
fn update(&mut self, _message: &crate::widget::Message) -> iced::Task<crate::widget::Message> {
fn update(&mut self, message: &Message) -> iced::Task<Message> {
let Message::FocusChanged(i) = message else {
return Task::none();
};
self.focused_window = match i {
Some(id) => id.to_string(),
None => "None".into(),
};
Task::none()
}
fn subscribe(&self) -> iced::Subscription<crate::widget::Message> {
Subscription::none()
//ain't gonna lie, I got no idea wth is going on here, the issue was that, smth smth channel
//not filled, it was not working properly
//this is entirely vibecoded
fn subscribe(&self) -> Subscription<Message> {
Subscription::run_with("niri-focus-watcher", |_| {
iced::stream::channel(16, async |mut tx| {
let (btx, brx) = std::sync::mpsc::channel::<Message>();
std::thread::spawn(move || {
let mut socket = Socket::connect().expect("failed to connect");
let _ = socket.send(Request::EventStream).expect("failed to send");
let mut read_event = socket.read_events();
loop {
match read_event() {
Ok(Event::WindowFocusChanged { id }) => {
if btx.send(Message::FocusChanged(id)).is_err() {
break;
}
}
Ok(_) => {}
Err(e) => {
eprintln!("{e}");
break;
}
}
}
});
loop {
match brx.try_recv() {
Ok(msg) => {
let _ = tx.send(msg).await;
}
Err(std::sync::mpsc::TryRecvError::Empty) => {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}
Err(std::sync::mpsc::TryRecvError::Disconnected) => break,
}
}
})
})
}
fn view(&self, _id: iced::window::Id) -> iced::Element<'_, crate::widget::Message> {
fn view(&self, _id: iced::window::Id) -> iced::Element<'_, Message> {
iced::widget::text!("{}", self.focused_window).into()
}
}