diff options
| author | MaxVerevkin <maxxverrr@gmail.com> | 2023-03-25 21:45:10 +0200 |
|---|---|---|
| committer | MaxVerevkin <maxxverrr@gmail.com> | 2023-03-25 21:45:10 +0200 |
| commit | 246314fa5a028ebd852a5c13b3d09cf0ba63d905 (patch) | |
| tree | b5f7614a5a265d010005e1b1a9ac60a41b4ad0f5 /src | |
| parent | 703c3972bf50d7ac8521c15ae6fec603e5e279b6 (diff) | |
| download | i3bar-mango-246314fa5a028ebd852a5c13b3d09cf0ba63d905.tar.gz | |
show hide with pkill -SIGUSR1 i3bar-river
Diffstat (limited to 'src')
| -rw-r--r-- | src/bar.rs | 46 | ||||
| -rw-r--r-- | src/main.rs | 11 | ||||
| -rw-r--r-- | src/shared_state.rs | 1 | ||||
| -rw-r--r-- | src/state.rs | 65 |
4 files changed, 83 insertions, 40 deletions
@@ -3,11 +3,12 @@ use std::collections::BinaryHeap; use pangocairo::cairo; use wayrs_client::connection::Connection; +use wayrs_client::proxy::Proxy; use wayrs_utils::shm_alloc::BufferSpec; use crate::button_manager::ButtonManager; use crate::color::Color; -use crate::config::Config; +use crate::config::{Config, Position}; use crate::i3bar_protocol::{self, Block, MinWidth}; use crate::ord_adaptor::DefaultLess; use crate::pointer_btn::PointerBtn; @@ -20,7 +21,8 @@ use crate::wm_info_provider::WmInfo; pub struct Bar { pub output: WlOutput, pub output_reg_name: u32, - pub configured: bool, + pub hidden: bool, + pub mapped: bool, pub frame_cb: Option<WlCallback>, pub width: u32, pub height: u32, @@ -86,7 +88,7 @@ impl Bar { } pub fn frame(&mut self, conn: &mut Connection<State>, ss: &mut SharedState) { - assert!(self.configured); + assert!(self.mapped); let (pix_width, pix_height, scale_f) = match self.scale120 { Some(scale120) => ( @@ -242,7 +244,7 @@ impl Bar { } pub fn request_frame(&mut self, conn: &mut Connection<State>) { - if self.configured && self.frame_cb.is_none() { + if self.mapped && !self.hidden && self.frame_cb.is_none() { self.frame_cb = Some(self.surface.frame_with_cb(conn, |conn, state, cb, _| { if let Some(bar) = state.bars.iter_mut().find(|bar| bar.frame_cb == Some(cb)) { bar.frame_cb = None; @@ -252,6 +254,42 @@ impl Bar { self.surface.commit(conn); } } + + pub fn show(&mut self, conn: &mut Connection<State>, shared_state: &SharedState) { + assert!(!self.mapped); + + self.hidden = false; + + let config = &shared_state.config; + + self.layer_surface.set_size(conn, 0, config.height); + self.layer_surface.set_anchor(conn, config.position.into()); + self.layer_surface.set_margin( + conn, + config.margin_top, + config.margin_right, + config.margin_bottom, + config.margin_left, + ); + self.layer_surface.set_exclusive_zone( + conn, + (shared_state.config.height) as i32 + + if config.position == Position::Top { + shared_state.config.margin_bottom + } else { + shared_state.config.margin_top + }, + ); + + self.surface.commit(conn); + } + + pub fn hide(&mut self, conn: &mut Connection<State>) { + self.hidden = true; + self.mapped = false; + self.surface.attach(conn, WlBuffer::null(), 0, 0); + self.surface.commit(conn); + } } #[allow(clippy::too_many_arguments)] diff --git a/src/main.rs b/src/main.rs index 241cd19..d3457b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,11 @@ mod text; mod utils; mod wm_info_provider; +use signal_hook::consts::*; +use signal_hook_tokio::Signals; + +use futures::stream::StreamExt; + use wayrs_client::connection::Connection; use state::State; @@ -28,6 +33,8 @@ use state::State; async fn main() -> anyhow::Result<()> { env_logger::init(); + let mut signals = Signals::new([SIGUSR1])?; + let mut conn = Connection::connect()?; let globals = conn.async_collect_initial_globals().await?; let mut state = State::new(&mut conn, &globals); @@ -49,6 +56,10 @@ async fn main() -> anyhow::Result<()> { } conn.async_flush().await?; } + Some(signal) = signals.next() => match signal { + SIGUSR1 => state.toggle_visibility(&mut conn), + _ => unreachable!(), + } } } } diff --git a/src/shared_state.rs b/src/shared_state.rs index 7f88afa..1551f4d 100644 --- a/src/shared_state.rs +++ b/src/shared_state.rs @@ -2,6 +2,7 @@ use crate::{ config::Config, i3bar_protocol::Block, state::ComputedBlock, status_cmd::StatusCmd, wm_info_provider::WmInfoProvider, }; + use wayrs_utils::shm_alloc::ShmAlloc; pub struct SharedState { diff --git a/src/state.rs b/src/state.rs index 2cead3d..53ef4ff 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,4 +1,3 @@ -use crate::config::Position; use crate::protocol::*; use crate::wm_info_provider::*; @@ -25,6 +24,7 @@ pub struct State { seats: Seats, pointers: Vec<Pointer>, + pub hidden: bool, pub bars: Vec<Bar>, pub shared_state: SharedState, @@ -76,6 +76,7 @@ impl State { seats: Seats::bind(conn, globals), pointers: Vec::new(), + hidden: false, bars: Vec::new(), shared_state: SharedState { @@ -169,33 +170,11 @@ impl State { layer_surface_cb, ); - let config = &self.shared_state.config; - - layer_surface.set_size(conn, 0, config.height); - layer_surface.set_anchor(conn, config.position.into()); - layer_surface.set_margin( - conn, - config.margin_top, - config.margin_right, - config.margin_bottom, - config.margin_left, - ); - layer_surface.set_exclusive_zone( - conn, - (self.shared_state.config.height) as i32 - + if config.position == Position::Top { - self.shared_state.config.margin_bottom - } else { - self.shared_state.config.margin_top - }, - ); - - // Note: layer_surface is commited when we receive the scale factor of this output - - self.bars.push(Bar { + let mut bar = Bar { output, output_reg_name: global.name, - configured: false, + hidden: self.hidden, + mapped: false, frame_cb: None, width: 0, height: self.shared_state.config.height, @@ -210,7 +189,13 @@ impl State { tags_btns: Default::default(), tags_computed: Vec::new(), layout_name_computed: None, - }); + }; + + if !self.hidden { + bar.show(conn, &self.shared_state); + } + + self.bars.push(bar); } fn drop_bar(&mut self, conn: &mut Connection<Self>, bar_index: usize) { @@ -224,6 +209,17 @@ impl State { bar.output.release(conn); } } + + pub fn toggle_visibility(&mut self, conn: &mut Connection<Self>) { + self.hidden = !self.hidden; + for bar in &mut self.bars { + if self.hidden { + bar.hide(conn); + } else { + bar.show(conn, &self.shared_state); + } + } + } } impl SeatHandler for State { @@ -274,7 +270,7 @@ fn wl_registry_cb(conn: &mut Connection<State>, state: &mut State, event: &wl_re } fn wl_output_cb( - conn: &mut Connection<State>, + _: &mut Connection<State>, state: &mut State, output: WlOutput, event: wl_output::Event, @@ -286,12 +282,6 @@ fn wl_output_cb( .find(|bar| bar.output == output) .unwrap(); bar.scale = scale as u32; - // If bar is not configured yet, it is because we were waiting for the "scale" event - // before commiting the surface. Otherwise, there is no need to do any redrawing (we'll - // do that after "configure" event). - if !bar.configured { - bar.surface.commit(conn); - } } } @@ -308,13 +298,16 @@ fn layer_surface_cb( .iter_mut() .find(|bar| bar.layer_surface == layer_surface) .unwrap(); + if bar.hidden { + return; + } assert_ne!(args.width, 0); bar.width = args.width; bar.layer_surface.ack_configure(conn, args.serial); - if bar.configured { + if bar.mapped { bar.request_frame(conn); } else { - bar.configured = true; + bar.mapped = true; bar.frame(conn, &mut state.shared_state); } } |
