From f6727acdd4cc112c51d3dd71df61689738e31de9 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Sun, 27 Nov 2022 22:11:08 +0200 Subject: WIP: support river-status-unstable-v1 version 3 Depends on https://github.com/riverwm/river/pull/673 --- src/bar.rs | 30 ++++++++++++++++++++++++++++++ src/river_protocols/status.rs | 14 +++++++++++++- src/state.rs | 17 +++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/bar.rs b/src/bar.rs index dfa63a3..b68aefa 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -28,6 +28,7 @@ pub struct Bar { pub blocks_btns: ButtonManager<(Option, Option)>, pub river_output_status: Option, pub river_control: Option, + pub layout_name: Option, pub tags_btns: ButtonManager, pub tags_info: TagsInfo, pub tags_computed: Vec, @@ -172,6 +173,35 @@ impl Bar { } } + // Display layout name + if let Some(layout_name) = &self.layout_name { + let text = ComputedText::new( + layout_name, + text::Attributes { + font: &ss.config.font, + padding_left: 25.0, + padding_right: 25.0, + min_width: None, + align: Default::default(), + markup: false, + }, + &cairo_ctx, + ); + text.render( + &cairo_ctx, + RenderOptions { + x_offset: offset_left, + bar_height: height_f, + fg_color: ss.config.tag_inactive_fg, + bg_color: None, + r_left: 0.0, + r_right: 0.0, + overlap: 0.0, + }, + ); + offset_left += text.width; + } + // Display the blocks render_blocks( &cairo_ctx, diff --git a/src/river_protocols/status.rs b/src/river_protocols/status.rs index 1779719..4424c58 100644 --- a/src/river_protocols/status.rs +++ b/src/river_protocols/status.rs @@ -19,7 +19,7 @@ impl RiverStatusState { where D: Dispatch + 'static, { - let status_manager = globals.bind(qh, 1..=1, ())?; + let status_manager = globals.bind(qh, 1..=3, ())?; Ok(Self { status_manager, output_statuses: Vec::new(), @@ -88,6 +88,14 @@ pub trait RiverStatusHandler: Sized { output_status: &RiverOutputStatus, tags: Vec, ); + + fn layout_name_updated( + &mut self, + conn: &Connection, + qh: &QueueHandle, + output_status: &RiverOutputStatus, + layout_name: Option, + ); } #[derive(Debug, Clone)] @@ -176,6 +184,10 @@ where .collect(); data.views_tags_updated(conn, qh, &status, tags); } + Event::LayoutName { name } => { + data.layout_name_updated(conn, qh, &status, Some(name)) + } + Event::LayoutNameClear => data.layout_name_updated(conn, qh, &status, None), } } } diff --git a/src/state.rs b/src/state.rs index ed6c3d1..e6cb421 100644 --- a/src/state.rs +++ b/src/state.rs @@ -207,6 +207,7 @@ impl OutputHandler for State { blocks_btns: Default::default(), river_output_status, river_control: self.river_control_state.clone(), + layout_name: None, tags_btns: Default::default(), tags_info: Default::default(), tags_computed: Vec::new(), @@ -437,6 +438,22 @@ impl RiverStatusHandler for State { bar.tags_info.active = tags.into_iter().fold(0, |a, b| a | b); bar.draw(&mut self.shared_state); } + + fn layout_name_updated( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + output_status: &RiverOutputStatus, + layout_name: Option, + ) { + let bar = self + .bars + .iter_mut() + .find(|b| b.river_output_status.as_ref() == Some(output_status)) + .unwrap(); + bar.layout_name = layout_name; + bar.draw(&mut self.shared_state); + } } impl RiverControlHandler for State { -- cgit v1.3.1