summaryrefslogtreecommitdiff
path: root/src/bar.rs
diff options
context:
space:
mode:
authorMaxVerevkin <maxxverrr@gmail.com>2022-12-10 17:46:48 +0200
committerMaxVerevkin <maxxverrr@gmail.com>2022-12-10 17:46:48 +0200
commit2570f39b5daf6e2a13b3973d47aa7c67fbb457fb (patch)
treee330dee89380a94635113c1312a9dcbb0d9e5883 /src/bar.rs
parentf6727acdd4cc112c51d3dd71df61689738e31de9 (diff)
downloadi3bar-mango-2570f39b5daf6e2a13b3973d47aa7c67fbb457fb.tar.gz
refactor
Diffstat (limited to 'src/bar.rs')
-rw-r--r--src/bar.rs37
1 files changed, 23 insertions, 14 deletions
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<RiverOutputStatus>,
pub river_control: Option<RiverControlState>,
pub layout_name: Option<String>,
+ pub layout_name_computed: Option<ComputedText>,
pub tags_btns: ButtonManager,
pub tags_info: TagsInfo,
pub tags_computed: Vec<ComputedText>,
@@ -50,6 +52,11 @@ impl Bar {
self.river_output_status.is_some()
}
+ pub fn set_layout_name(&mut self, layout_name: Option<String>) {
+ 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 {