diff options
Diffstat (limited to 'src/state.rs')
| -rw-r--r-- | src/state.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/state.rs b/src/state.rs index ccd0d52..2853731 100644 --- a/src/state.rs +++ b/src/state.rs @@ -5,6 +5,7 @@ use crate::protocol::*; use crate::wm_info_provider; use std::fmt::Display; +use std::io; use std::os::unix::io::{AsRawFd, RawFd}; use std::path::Path; @@ -15,6 +16,9 @@ use wayrs_utils::cursor::{CursorImage, CursorShape, CursorTheme, ThemedPointer}; use wayrs_utils::seats::{SeatHandler, Seats}; use wayrs_utils::shm_alloc::ShmAlloc; +use crate::event_loop::Action; +use crate::tray::TrayHandle; + use crate::{ bar::Bar, config::Config, i3bar_protocol::Block, pointer_btn::PointerBtn, shared_state::SharedState, status_cmd::StatusCmd, @@ -83,6 +87,29 @@ impl State { let wm_info_provider = wm_info_provider::bind(conn, &config.wm); wm_info_provider.register(event_loop); + let tray = if config.tray.enabled { + match io::pipe() { + Ok((tray_read, tray_write)) => { + let tray = TrayHandle::spawn(tray_write.into()); + let fd = tray_read.as_raw_fd(); + event_loop.register_with_fd(fd, move |ctx| { + let mut buf = [0u8; 64]; + while io::Read::read(&mut &tray_read, &mut buf).is_ok_and(|n| n == 64) {} + ctx.state.tray_updated(ctx.conn); + Ok(Action::Keep) + }); + Some(tray) + } + Err(e) => { + eprintln!("tray: failed to create wake pipe: {e}"); + None + } + } + } else { + None + }; + let tray_expanded = config.tray.expanded; + let mut this = Self { wl_compositor, layer_shell: conn.bind_singleton(1..=4).unwrap(), @@ -105,6 +132,9 @@ impl State { blocks_cache: BlocksCache::default(), icon_cache: Default::default(), wm_info_provider, + tray, + tray_items: Vec::new(), + tray_expanded, }, cursor_theme, @@ -144,6 +174,13 @@ impl State { } } + pub fn tray_updated(&mut self, conn: &mut Connection<Self>) { + if let Some(tray) = &self.shared_state.tray { + self.shared_state.tray_items = tray.items(); + } + self.draw_all(conn); + } + pub fn status_cmd_fd(&self) -> Option<RawFd> { self.shared_state .status_cmd |
