git.lucas.co / cce-status-interface
status bar
git clone https://git.lucas.co/cce-status-interface.git

commit16e17bdcefe159801f202ead5875814598dff88c
parent6132b2bf14
authorLucas Galante <[email protected]>
date2026-06-25 10:15
Combine window title and window layout modules into a single window module

 src/main.rs    |  21 +++++----
 src/modules.rs | 131 +++++++++++++++++++++++++--------------------------------
 2 files changed, 68 insertions(+), 84 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 0de3398..17351bd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,5 @@
 mod modules;
-use modules::{StatusModule, ViewportModule, LayoutModule, TitleModule, ClockModule, BatteryModule, VolumeModule, BrightnessModule, MemoryModule, CpuModule, TrayModule};
+use modules::{StatusModule, ViewportModule, WindowModule, ClockModule, BatteryModule, VolumeModule, BrightnessModule, MemoryModule, CpuModule, TrayModule};
 
 use std::collections::HashMap;
 use std::sync::Arc;
@@ -729,10 +729,10 @@ impl StatusApp {
         // Set active cloud source
         self.active_cloud_source = Some(switcher_source.clone());
 
-        // Get placement coords: align just below Title module if we can find it
+        // Get placement coords: align just below Window module if we can find it
         let mut target_x = 0.0;
         for mb in &self.module_bounds {
-            if mb.name == "title" {
+            if mb.name == "window" {
                 target_x = mb.x;
                 break;
             }
@@ -740,7 +740,7 @@ impl StatusApp {
 
         let bar_height = read_status_height_from_config() as i32;
 
-        // Position it under Title module
+        // Position it under Window module
         let x_pos = target_x as i32;
         let y_pos = bar_height;
 
@@ -992,8 +992,7 @@ impl cce_ui::engine::Application for StatusApp {
             module_bounds: Vec::new(),
             left_modules: vec![
                 Box::new(ViewportModule),
-                Box::new(LayoutModule),
-                Box::new(TitleModule),
+                Box::new(WindowModule),
             ],
             right_modules: vec![
                 Box::new(TrayModule),
@@ -1487,18 +1486,18 @@ impl cce_ui::engine::Application for StatusApp {
                         });
                     }
                 } else {
-                    let mut clicked_title = false;
+                    let mut clicked_window = false;
                     for mb in &self.module_bounds {
-                        if mb.name == "title" {
+                        if mb.name == "window" {
                             if lx >= mb.x && lx <= (mb.x + mb.w) {
-                                clicked_title = true;
+                                clicked_window = true;
                                 break;
                             }
                         }
                     }
 
-                    if clicked_title {
-                        eprintln!("[title-click] Title module clicked!");
+                    if clicked_window {
+                        eprintln!("[window-click] Window module clicked!");
                         self.trigger_switcher(false);
                     } else {
                         for bound in &self.viewport_bounds {
diff --git a/src/modules.rs b/src/modules.rs
index 163e99e..36e495c 100644
--- a/src/modules.rs
+++ b/src/modules.rs
@@ -141,97 +141,51 @@ impl StatusModule for ViewportModule {
     }
 }
 
-pub struct LayoutModule;
+pub struct WindowModule;
 
-impl StatusModule for LayoutModule {
-    fn name(&self) -> &'static str { "layout" }
+impl StatusModule for WindowModule {
+    fn name(&self) -> &'static str { "window" }
 
     fn width(
         &self,
         _stats: &Option<SystemStats>,
         _viewport: &str,
         layout: &str,
-        _title: &str,
+        title: &str,
         font_system: &mut FontSystem,
         font_family: &str,
         font_size: f32,
         _tray_items: &HashMap<String, TrayItem>,
         padding: f32,
     ) -> f32 {
-        if layout.is_empty() {
-            0.0
-        } else {
-            let label = Label::new_with_family(font_system, layout, font_size, [0.0, 0.0, 0.0, 1.0], font_family);
-            label.w + 2.0 * padding
-        }
-    }
+        let has_title = !title.is_empty() && title != "(none)";
+        let has_layout = !layout.is_empty();
 
-    fn render(
-        &self,
-        x: f32,
-        w: f32,
-        _stats: &Option<SystemStats>,
-        _viewport: &str,
-        layout: &str,
-        _title: &str,
-        font_system: &mut FontSystem,
-        font_family: &str,
-        font_size: f32,
-        normal_color: [f32; 4],
-        bar_h: f32,
-        _scale_factor: f64,
-        text_items: &mut Vec<TextItem>,
-        _rects: &mut Vec<RectWidget>,
-        _overlay_rects: &mut Vec<RectWidget>,
-        _viewport_bounds: &mut Vec<ViewportBounds>,
-        layout_bounds: &mut Option<LayoutBounds>,
-        _tray_items: &HashMap<String, TrayItem>,
-        _tray_item_bounds: &mut Vec<TrayIconBounds>,
-        _box_bg_color: Option<[f32; 4]>,
-        _status_box_radius: f32,
-        _rounded_boxes: &mut Vec<RoundedBox>,
-        padding: f32,
-    ) {
-        if !layout.is_empty() {
-            let label = Label::new_with_family(font_system, layout, font_size, normal_color, font_family);
-            label.draw(text_items, x + padding, (bar_h - font_size * 1.4) / 2.0);
-            *layout_bounds = Some(LayoutBounds {
-                x,
-                y: 0.0,
-                w,
-                h: bar_h,
-            });
+        if !has_title && !has_layout {
+            return 0.0;
         }
-    }
-}
 
-pub struct TitleModule;
-
-impl StatusModule for TitleModule {
-    fn name(&self) -> &'static str { "title" }
-
-    fn width(
-        &self,
-        _stats: &Option<SystemStats>,
-        _viewport: &str,
-        _layout: &str,
-        title: &str,
-        font_system: &mut FontSystem,
-        font_family: &str,
-        font_size: f32,
-        _tray_items: &HashMap<String, TrayItem>,
-        padding: f32,
-    ) -> f32 {
-        if title.is_empty() || title == "(none)" {
-            0.0
-        } else {
+        let mut total_w = 0.0;
+        if has_title {
             let mut display_title = title.to_string();
             if display_title.chars().count() > 40 {
                 display_title = display_title.chars().take(37).collect::<String>() + "...";
             }
             let label = Label::new_with_family(font_system, &display_title, font_size, [0.0, 0.0, 0.0, 1.0], font_family);
-            label.w + 2.0 * padding
+            total_w += label.w;
+        }
+
+        if has_title && has_layout {
+            let sep_label = Label::new_with_family(font_system, " - ", font_size, [0.0, 0.0, 0.0, 1.0], font_family);
+            total_w += sep_label.w;
+        }
+
+        if has_layout {
+            let layout_label = Label::new_with_family(font_system, layout, font_size, [0.0, 0.0, 0.0, 1.0], font_family);
+            total_w += layout_label.w;
         }
+
+        total_w + 2.0 * padding
     }
 
     fn render(
@@ -240,7 +194,7 @@ impl StatusModule for TitleModule {
         _w: f32,
         _stats: &Option<SystemStats>,
         _viewport: &str,
-        _layout: &str,
+        layout: &str,
         title: &str,
         font_system: &mut FontSystem,
         font_family: &str,
@@ -252,7 +206,7 @@ impl StatusModule for TitleModule {
         _rects: &mut Vec<RectWidget>,
         _overlay_rects: &mut Vec<RectWidget>,
         _viewport_bounds: &mut Vec<ViewportBounds>,
-        _layout_bounds: &mut Option<LayoutBounds>,
+        layout_bounds: &mut Option<LayoutBounds>,
         _tray_items: &HashMap<String, TrayItem>,
         _tray_item_bounds: &mut Vec<TrayIconBounds>,
         _box_bg_color: Option<[f32; 4]>,
@@ -260,13 +214,44 @@ impl StatusModule for TitleModule {
         _rounded_boxes: &mut Vec<RoundedBox>,
         padding: f32,
     ) {
-        if !title.is_empty() && title != "(none)" {
+        let has_title = !title.is_empty() && title != "(none)";
+        let has_layout = !layout.is_empty();
+
+        if !has_title && !has_layout {
+            return;
+        }
+
+        let mut cur_x = x + padding;
+        let y_pos = (bar_h - font_size * 1.4) / 2.0;
+
+        if has_title {
             let mut display_title = title.to_string();
             if display_title.chars().count() > 40 {
                 display_title = display_title.chars().take(37).collect::<String>() + "...";
             }
             let label = Label::new_with_family(font_system, &display_title, font_size, normal_color, font_family);
-            label.draw(text_items, x + padding, (bar_h - font_size * 1.4) / 2.0);
+            let w = label.w;
+            label.draw(text_items, cur_x, y_pos);
+            cur_x += w;
+        }
+
+        if has_title && has_layout {
+            let sep_label = Label::new_with_family(font_system, " - ", font_size, normal_color, font_family);
+            let w = sep_label.w;
+            sep_label.draw(text_items, cur_x, y_pos);
+            cur_x += w;
+        }
+
+        if has_layout {
+            let layout_label = Label::new_with_family(font_system, layout, font_size, normal_color, font_family);
+            let w = layout_label.w;
+            layout_label.draw(text_items, cur_x, y_pos);
+            *layout_bounds = Some(LayoutBounds {
+                x: cur_x - 2.0,
+                y: 0.0,
+                w: w + 4.0,
+                h: bar_h,
+            });
         }
     }
 }