diff options
| -rw-r--r-- | README.md | 9 | ||||
| -rw-r--r-- | src/config.rs | 18 | ||||
| -rw-r--r-- | src/state.rs | 64 |
3 files changed, 76 insertions, 15 deletions
@@ -88,6 +88,15 @@ show_layout_name = true # WM-specific options [wm.river] max_tag = 9 # Show only the first nine tags + +# Per output overrides +# [output.your-output-name] +# right now only "enable" option is available +# enable = false +# +# You can have any number of overrides +# [output.eDP-1] +# enable = false ``` ## How progressive short mode and rounded corners work diff --git a/src/config.rs b/src/config.rs index 8465eee..5b657d0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,6 +3,7 @@ use crate::protocol::zwlr_layer_surface_v1; use anyhow::{Context, Result}; use pangocairo::pango::FontDescription; use serde::{de, Deserialize}; +use std::collections::HashMap; use std::fs::read_to_string; use std::ops::Deref; use std::path::PathBuf; @@ -44,6 +45,8 @@ pub struct Config { pub show_layout_name: bool, // wm-specific pub wm: WmConfig, + // overrides + pub output: HashMap<String, OutputOverrides>, } impl Default for Config { @@ -84,6 +87,8 @@ impl Default for Config { wm: WmConfig { river: RiverConfig { max_tag: 9 }, }, + + output: HashMap::new(), } } } @@ -110,6 +115,13 @@ impl Config { } }) } + + pub fn output_enabled(&self, output: &str) -> bool { + self.output + .get(output) + .and_then(|o| o.enable) + .unwrap_or(true) + } } fn config_dir() -> Option<PathBuf> { @@ -144,6 +156,12 @@ pub struct RiverConfig { pub max_tag: u8, } +#[derive(Debug, Deserialize)] +pub struct OutputOverrides { + #[serde(default)] + enable: Option<bool>, +} + #[derive(Debug)] pub struct Font(pub FontDescription); diff --git a/src/state.rs b/src/state.rs index c4d67c6..fe363d4 100644 --- a/src/state.rs +++ b/src/state.rs @@ -26,6 +26,9 @@ pub struct State { seats: Seats, pointers: Vec<Pointer>, + // Outputs that haven't yet advertised their names + pending_outputs: Vec<PendingOutput>, + pub hidden: bool, pub bars: Vec<Bar>, @@ -47,6 +50,12 @@ struct Pointer { scroll_frame: ScrollFrame, } +struct PendingOutput { + wl: WlOutput, + reg_name: u32, + scale: u32, +} + impl State { pub fn new(conn: &mut Connection<Self>, globals: &Globals) -> Self { let mut error = Ok(()); @@ -77,6 +86,8 @@ impl State { seats: Seats::bind(conn, globals), pointers: Vec::new(), + pending_outputs: Vec::new(), + hidden: false, bars: Vec::new(), @@ -135,11 +146,23 @@ impl State { } fn bind_output(&mut self, conn: &mut Connection<Self>, global: &Global) { - let output = global - .bind_with_cb(conn, 2..=4, wl_output_cb) - .expect("could not bind wl_output"); + self.pending_outputs.push(PendingOutput { + wl: global + .bind_with_cb(conn, 2..=4, wl_output_cb) + .expect("could not bind wl_output"), + reg_name: global.name, + scale: 1, + }); + } - self.shared_state.wm_info_provider.new_ouput(conn, output); + fn register_output(&mut self, conn: &mut Connection<Self>, output: PendingOutput, name: &str) { + if !self.shared_state.config.output_enabled(name) { + return; + } + + self.shared_state + .wm_info_provider + .new_ouput(conn, output.wl); let surface = self.wl_compositor.create_surface(conn); @@ -150,15 +173,15 @@ impl State { let layer_surface = self.layer_shell.get_layer_surface_with_cb( conn, surface, - Some(output), + Some(output.wl), zwlr_layer_shell_v1::Layer::Top, wayrs_client::cstr!("i3bar-river").into(), layer_surface_cb, ); let mut bar = Bar { - output, - output_reg_name: global.name, + output: output.wl, + output_reg_name: output.reg_name, hidden: self.hidden, mapped: false, frame_cb: None, @@ -256,18 +279,29 @@ fn wl_registry_cb(conn: &mut Connection<State>, state: &mut State, event: &wl_re } fn wl_output_cb( - _: &mut Connection<State>, + conn: &mut Connection<State>, state: &mut State, output: WlOutput, event: wl_output::Event, ) { - if let wl_output::Event::Scale(scale) = event { - let bar = state - .bars - .iter_mut() - .find(|bar| bar.output == output) - .unwrap(); - bar.scale = scale as u32; + match event { + wl_output::Event::Name(name) => { + let i = state + .pending_outputs + .iter() + .position(|o| o.wl == output) + .unwrap(); + let output = state.pending_outputs.swap_remove(i); + state.register_output(conn, output, name.to_str().expect("invalid output name")); + } + wl_output::Event::Scale(scale) => { + if let Some(bar) = state.bars.iter_mut().find(|bar| bar.output == output) { + bar.scale = scale as u32; + } else if let Some(output) = state.pending_outputs.iter_mut().find(|o| o.wl == output) { + output.scale = scale as u32; + } + } + _ => (), } } |
