summaryrefslogtreecommitdiff
path: root/src/bar.rs
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-07-29 11:31:51 +0200
committercashmere <cashmere@autistici.org>2026-07-29 11:31:51 +0200
commitde596d4fca9ca54f9248e788685eee1820bb2381 (patch)
tree4ed9f82251f45c94d28e836ede83c87f67b0f917 /src/bar.rs
parent5b77a6d8f19500eee21a497ce84db538ded05c00 (diff)
downloadi3bar-mango-de596d4fca9ca54f9248e788685eee1820bb2381.tar.gz
configurable focused window widget, tray hidden list, global coords for tray context menu
Diffstat (limited to 'src/bar.rs')
-rw-r--r--src/bar.rs52
1 files changed, 37 insertions, 15 deletions
diff --git a/src/bar.rs b/src/bar.rs
index 84bbecc..115641d 100644
--- a/src/bar.rs
+++ b/src/bar.rs
@@ -14,7 +14,7 @@ use crate::protocol::*;
use crate::shared_state::SharedState;
use crate::state::State;
use crate::text::{self, ComputedText, RenderOptions};
-use crate::tray::TrayCommand;
+use crate::tray::{TrayCommand, TrayItem};
use crate::wm_info_provider::{FocusedWindow, Tag};
pub struct Bar {
@@ -159,11 +159,17 @@ impl Bar {
let cmd = match button {
PointerBtn::Left => Some(TrayCommand::Activate { key }),
PointerBtn::Middle => Some(TrayCommand::SecondaryActivate { key }),
- PointerBtn::Right => Some(TrayCommand::ContextMenu {
- key,
- x: x as i32,
- y: y as i32,
- }),
+ PointerBtn::Right => {
+ let (ox, oy) = ss
+ .wm_info_provider
+ .get_output_position(&self.output)
+ .unwrap_or((0, 0));
+ Some(TrayCommand::ContextMenu {
+ key,
+ x: x as i32 + ox,
+ y: y as i32 + oy,
+ })
+ }
_ => None,
};
if let Some(cmd) = cmd {
@@ -333,10 +339,13 @@ impl Bar {
}
// Display focused window
- if ss.config.show_focused_window
+ let fw_cfg = &ss.config.focused_window;
+ if fw_cfg.enabled
&& let Some(focused_window) = &self.focused_window
{
- if let Some(icon) = ss.icon_cache.get(&focused_window.app_id, self.height) {
+ if fw_cfg.show_icon
+ && let Some(icon) = ss.icon_cache.get(&focused_window.app_id, self.height)
+ {
let icon_size = height_f - 4.0;
let scale = icon_size / (icon.width() as f64).max(icon.height() as f64);
let icon_w = icon.width() as f64 * scale;
@@ -353,10 +362,12 @@ impl Bar {
offset_left += icon_size + 5.0;
}
let text = self.focused_window_computed.get_or_insert_with(|| {
- let label = if focused_window.title.is_empty() {
- focused_window.app_id.clone()
- } else {
- format!("{} - {}", focused_window.app_id, focused_window.title)
+ let show_title = fw_cfg.show_title && !focused_window.title.is_empty();
+ let label = match (fw_cfg.show_app_id, show_title) {
+ (true, true) => format!("{} - {}", focused_window.app_id, focused_window.title),
+ (true, false) => focused_window.app_id.clone(),
+ (false, true) => focused_window.title.clone(),
+ (false, false) => String::new(),
};
ComputedText::new(
&label,
@@ -469,11 +480,22 @@ impl Bar {
full_height: f64,
) -> f64 {
self.tray_btns.clear();
- if ss.tray_items.is_empty() {
+
+ let cfg = &ss.config.tray;
+ let visible: Vec<&TrayItem> = ss
+ .tray_items
+ .iter()
+ .filter(|item| {
+ !cfg.hidden.iter().any(|hidden| {
+ hidden.eq_ignore_ascii_case(&item.id)
+ || hidden.eq_ignore_ascii_case(&item.title)
+ })
+ })
+ .collect();
+ if visible.is_empty() {
return 0.0;
}
- let cfg = ss.config.tray;
let expanded = ss.tray_expanded;
let icon_size = full_height - 4.0;
let spacing = 8.0;
@@ -502,7 +524,7 @@ impl Bar {
let mut rendered = Vec::new();
if expanded {
- for item in &ss.tray_items {
+ for item in &visible {
let label = match (cfg.show_name, cfg.show_description && !item.tooltip.is_empty()) {
(true, true) if item.tooltip != item.title => {
format!("{} \u{2014} {}", item.title, item.tooltip)