From 2570f39b5daf6e2a13b3973d47aa7c67fbb457fb Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Sat, 10 Dec 2022 17:46:48 +0200 Subject: refactor --- src/bar.rs | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'src/bar.rs') diff --git a/src/bar.rs b/src/bar.rs index b68aefa..90215a2 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -2,7 +2,7 @@ use std::collections::BinaryHeap; use pangocairo::cairo; use smithay_client_toolkit::{ - reexports::client::protocol::{wl_seat, wl_shm}, + reexports::client::protocol::{wl_output, wl_seat, wl_shm}, shell::layer::LayerSurface, }; @@ -20,6 +20,7 @@ use crate::{ }; pub struct Bar { + pub output: wl_output::WlOutput, pub configured: bool, pub width: u32, pub height: u32, @@ -29,6 +30,7 @@ pub struct Bar { pub river_output_status: Option, pub river_control: Option, pub layout_name: Option, + pub layout_name_computed: Option, pub tags_btns: ButtonManager, pub tags_info: TagsInfo, pub tags_computed: Vec, @@ -50,6 +52,11 @@ impl Bar { self.river_output_status.is_some() } + pub fn set_layout_name(&mut self, layout_name: Option) { + self.layout_name_computed = None; + self.layout_name = layout_name; + } + pub fn click( &mut self, ss: &mut SharedState, @@ -92,7 +99,7 @@ impl Bar { let height_f = height as f64; let (buffer, canvas) = ss - .get_pool(height as usize * stride as usize) + .pool .create_buffer( width * self.scale, height * self.scale, @@ -175,18 +182,20 @@ 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, - ); + let text = self.layout_name_computed.get_or_insert_with(|| { + 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 { -- cgit v1.3.1